Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1007 (closed defect: fixed)

Opened 5 months ago

Last modified 5 months ago

stdin stdout stderr are not initialized on mac 10.4.11

Reported by: fawzi Assigned to: sean
Priority: major Milestone: 0.99.6
Component: Core Functionality Version: trunk
Keywords: darwin stdout UNIX03 Cc: fawzi@gmx.ch

Description

This can be seen by the following program that doesn't print anything

import tango.stdc.stdio;
void main(char [][] argv) 
{ 
    fprintf(stdout,"lll\n");
    fflush(stdout);
} 

a patch for it is

Index: stdio.d
===================================================================
--- stdio.d     (revision 3400)
+++ stdio.d     (working copy)
@@ -271,10 +271,17 @@
 }
 else version( darwin )
 {
-    extern FILE[3] __sF;
-    const FILE* stdin  = &__sF[0];
-    const FILE* stdout = &__sF[1];
-    const FILE* stderr = &__sF[2];
+    extern FILE *__stdinp;
+    extern FILE *__stdoutp;
+    extern FILE *__stderrp;
+    const FILE* stdin ;
+    const FILE* stdout;
+    const FILE* stderr;
+    static this(){
+        stdin  = __stdinp;
+        stdout = __stdoutp;
+        stderr = __stderrp;
+    }
 }
 else version( freebsd )
 {

This is based on the assumption that one has UNIX03 conformance. This seems to be the case in 10.4.11 (and likely in 10.5 that is officially UNIX03 conformant). The following c program can be used to check what is the case (please note that a developer can change the conformance level of his installation using the compat command, but it is unclear if the constant defined would change).

#include <stdio.h>

int main(int argc,char *argv[]){
#ifdef __DARWIN_UNIX03
    printf("new\n");
#else
    printf("old\n");
#endif
}

Change History

04/17/08 00:02:46 changed by sean

  • status changed from new to closed.
  • resolution set to fixed.

(In [3437]) Changed stdio file handles for darwin. It seems these are valid from at least 10.4.x onward, so I opted to not bother with preserving the older handles as well. If anyone really needs them, please reopen the ticket and say so. This closes #1007

04/18/08 08:27:07 changed by fawzi

  • status changed from closed to reopened.
  • resolution deleted.

Unfortunately the static this in the patch although ugly is needed, the actual version gives an error

tango/stdc/stdio.d:282: Error: non-constant expression __stdinp
tango/stdc/stdio.d:283: Error: non-constant expression __stdoutp
tango/stdc/stdio.d:284: Error: non-constant expression __stdoutp

04/22/08 00:23:43 changed by sean

  • status changed from reopened to closed.
  • resolution set to fixed.

(In [3452]) Added static ctor. This fixes #1007