Iain Buclaw avatar Iain Buclaw committed ae85241

D1/D2: _argptr is now type void*

Comments (0)

Files changed (15)

 
 # Enables correct implementation of D's va_list type (void*) as per
 # the D language specification.
-# D_EXTRA_DEFINES += -DD_VA_LIST_TYPE_VOIDPTR
+D_EXTRA_DEFINES += -DD_VA_LIST_TYPE_VOIDPTR
 
 # As with C++: (quote) OTOH, I think this means the g++ driver...
 # Note that it would be nice to move the dependency on g++
                 tree ta = TREE_VALUE(tl);
                 if (ta != void_type_node)
                 {
+                    Type * d_arg_type;
                     unsigned io = STCin;
 
                     if (TREE_CODE(ta) == REFERENCE_TYPE)
                         ta = TREE_TYPE(ta);
                         io = STCref;
                     }
-
-                    Type * d_arg_type = gcc_type_to_d_type(ta);
+#if D_VA_LIST_TYPE_VOIDPTR
+                    // C-type va_list, but require D-type void*
+                    if (ta == va_list_type_node)
+                        d_arg_type = d_gcc_builtin_va_list_d_type;
+                    else
+#endif
+                    {
+                        d_arg_type = gcc_type_to_d_type(ta);
+                    }
                     if (! d_arg_type)
                         goto Lfail;
 

d/druntime/core/stdc/stdarg.d

 
 version( GNU )
 {
+    alias void* va_list;
+
     private import gcc.builtins;
-    alias __builtin_va_list va_list;
+    alias __builtin_va_list __va_list; // C ABI va_list
     alias __builtin_va_end va_end;
     alias __builtin_va_copy va_copy;
 

d/druntime/core/vararg.d

 
 version( GNU )
 {
-    // va_list might be a pointer, but assuming so is not portable.
-    private import gcc.builtins;
-    alias __builtin_va_list va_list;
+    alias void* va_list;
 
     T va_arg(T)( ref va_list ap )
     {

d/phobos/std/boxer.d

 
    Modified by David Friedman, May 2005
 
-   This module make not work on all GCC targets due to assumptions
+   This module may not work on all GCC targets due to assumptions
    about the type of va_list.
 */
 module std.boxer;
         args[(char[]).sizeof..length] = data;
         version (GNU)
         {
-            va_list dummy = void;
+            void* dummy = void;
             std.format.doFormatPtr(&putc, arguments, dummy, args.ptr);
         }
         else

d/phobos/std/c/stdarg.d

 
 version (GNU)
 {
+    alias void* va_list;
+
     private import gcc.builtins;
-    alias __builtin_va_list va_list;
+    alias __builtin_va_list __va_list; // C ABI va_list
     alias __builtin_va_end va_end;
     alias __builtin_va_copy va_copy;
 
     {   // TODO: implement this?
         alias __builtin_va_list __va_argsave_t;
     }
+
     // The va_start and va_arg template functions are magically
     // handled by the compiler.
     void va_start(T)(out va_list ap, inout T parmn)

d/phobos/std/format.d

     doFormatPtr(putc, arguments, argptr, null);
 }
 
-void doFormatPtr(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr,
-              void * p_args)
+void doFormatPtr(void delegate(dchar) putc, TypeInfo[] arguments, va_list argptr, void * p_args)
 {   int j;
     TypeInfo ti;
     Mangle m;
             if (comma) putc(',');
             comma = true;
             void *pkey = &fakevalue;
-            version (X86)
+            version (X86_64)
+                pkey -= 16;
+            else
                 pkey -= long.sizeof;
-            else
-                pkey -= 16;
 
             // the key comes before the value
             auto keysize = keyti.tsize();
-            version (X86)
+            version (X86_64)
+                auto keysizet = (keysize + 15) & ~(15);
+            else
                 auto keysizet = (keysize + size_t.sizeof - 1) & ~(size_t.sizeof - 1);
-            else
-                auto keysizet = (keysize + 15) & ~(15);
 
             void* pvalue = pkey + keysizet;
 
             //doFormat(putc, (&keyti)[0..1], pkey);
-             p_args = pkey;
+            p_args = pkey;
             ti = keyti;
             m = getMan(keyti);
             formatArg('s');
             case Mangle.Tfloat:
             case Mangle.Tifloat:
                 if (fc == 'x' || fc == 'X')
-                    goto Luint;
+                {
+                    version (X86_64)
+                    {   float f = va_arg!(float)(argptr);
+                        vnumber = *cast(uint*)&f;
+                        goto Lnumber;
+                    }
+                    else
+                        goto Luint;
+                }
                 vreal = va_arg!(float)(argptr);
                 goto Lreal;
 
             case Mangle.Tdouble:
             case Mangle.Tidouble:
                 if (fc == 'x' || fc == 'X')
-                    goto Lulong;
+                {
+                    version (X86_64)
+                    {   double d = va_arg!(double)(argptr);
+                        vnumber = *cast(ulong*)&d;
+                        goto Lnumber;
+                    }
+                    else
+                        goto Lulong;
+                }
                 vreal = va_arg!(double)(argptr);
                 goto Lreal;
 
             {   TypeInfo_Struct tis = cast(TypeInfo_Struct)ti;
                 if (tis.xtoString is null)
                     throw new FormatError("Can't convert " ~ tis.toString() ~ " to string: \"string toString()\" not defined");
-                static if
-                    (
-                     is( typeof(argptr): void[] ) ||
-                     is( typeof(argptr) == struct ))
+                static if (is(__va_list : void[]) || is(__va_list == struct))
                 {
                     version(PPC)
                     {
                         // Structs are pass-by-reference in V4 ABI
                         s = tis.xtoString(va_arg!(void*)(argptr));
                     }
-                    else version(X86_64)
+                    else
                     {
                         throw new FormatError("cannot portably format a struct on this target");
                     }
-                    else
-                    {
-                        static assert(0, "unimplemented");
-                    }
                 }
                 else
                 {

d/phobos/std/stdarg.d

 
 version(GNU)
 {
-    // va_list might be a pointer, but assuming so is not portable.
-    private import gcc.builtins;
-    alias __builtin_va_list va_list;
+    alias void* va_list;
 
     T va_arg(T)(inout va_list _argptr)
     {

d/phobos/std/stdio.d

 }
 
 private
-void writefx(FILE* fp, TypeInfo[] arguments, va_list argptr, int newline=false)
+void writefx(FILE* fp, TypeInfo[] arguments, void* argptr, int newline=false)
 {   int orientation;
 
     static if (Have_fwide)

d/phobos/std/stream.d

    * If EOF is reached then getc returns char.init and getcw returns wchar.init.
    */
 
-  // pushes back character c into the stream; only has
-  // effect on further calls to getc() and getcw()
   char getc();
   wchar getcw(); /// ditto
 
    */
   OutputStream writef(...);
   OutputStream writefln(...); /// ditto
-  OutputStream writefx(TypeInfo[] arguments, va_list argptr, int newline = false);  /// ditto
+  OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline = false);  /// ditto
 
   void flush(); /// Flush pending output if appropriate.
   void close(); /// Close the stream, flushing output if appropriate.
   }
 
   // writes data with optional trailing newline
-  OutputStream writefx(TypeInfo[] arguments, va_list argptr, int newline=false) {
+  OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline=false) {
     doFormat(&doFormatCallback,arguments,argptr);
     if (newline)
       writeLine("");

d/phobos2/std/boxer.d

 /* NOTE: This file has been patched from the original DMD distribution to
    work with the GDC compiler.
 
-   This module make not work on all GCC targets due to assumptions
+   This module may not work on all GCC targets due to assumptions
    about the type of va_list.
 */
 module std.boxer;
 private import std.string;
 private import std.utf;
 import std.exception;
-version (GNU) private import std.stdarg;
 
  /* These functions and types allow packing objects into generic containers
   * and recovering them later.  This comes into play in a wide spectrum of
         args[(char[]).sizeof..$] = data;
         version (GNU)
         {
-            va_list dummy = void;
+            void* dummy = void;
             std.format.doFormatPtr(&putc, arguments, dummy, args.ptr);
         }
         else

d/phobos2/std/format.d

             {
                 if (comma) putc(',');
                 comma = true;
+                void *pkey = &fakevalue; 
+                version(X86_64)
+                    pkey -= 16;
+                else
+                    pkey -= long.sizeof;
+
                 // the key comes before the value
-                ubyte* key = &fakevalue - long.sizeof;
-
-                //doFormat(putc, (&keyti)[0..1], key);
-                p_args = key;
+                auto keysize = keyti.tsize;
+                version (X86) 
+                    auto keysizet = (keysize + size_t.sizeof - 1) & ~(size_t.sizeof - 1); 
+                else 
+                    auto keysizet = (keysize + 15) & ~(15); 
+                
+                void* pvalue = pkey + keysizet; 
+                
+                //doFormat(putc, (&keyti)[0..1], pkey); 
+                p_args = pkey;
                 ti = keyti;
                 m = getMan(keyti);
                 formatArg('s');
 
                 putc(':');
-                auto keysize = keyti.tsize;
-                keysize = (keysize + 3) & ~3;
-                ubyte* value = key + keysize;
-                //doFormat(putc, (&valti)[0..1], value);
-                p_args = value;
+                //doFormat(putc, (&valti)[0..1], pvalue);
+                p_args = pvalue; 
                 ti = valti;
                 m = getMan(valti);
                 formatArg('s');
                 if (tis.xtoString is null)
                     throw new FormatError("Can't convert " ~ tis.toString()
                             ~ " to string: \"string toString()\" not defined");
-                static if (is(typeof(argptr): void[]) || is(typeof(argptr) == struct))
+                static if (is(__va_list : void[]) || is(__valist == struct))
                 {
                     version(PPC)
                     {

d/phobos2/std/math.d

  *                        Don Clugston
  * Source: $(PHOBOSSRC std/_math.d)
  */
+
+/* NOTE: This file has been patched from the original DMD distribution to
+   work with the GDC compiler.
+ */
 module std.math;
 
 import core.stdc.math;
         // and exp2 are so similar).
         return exp2(LOG2E*x);
     } else {
-        return core.stdc.math.exp(x);
+        return core.stdc.math.expl(x);
     }
 }
 /// ditto
             ret; 
         } 
     } else {
-        return core.stdc.math.expm1(x);
+        return core.stdc.math.expm1l(x);
     }
 }
 
     } else version(GNU_Need_exp2) {
         return core.stdc.math.powl(2, x);
     } else {
-        return core.stdc.math.exp2(x);
+        return core.stdc.math.exp2l(x);
     }
 }
 

d/phobos2/std/stdio.d

     std.range, std.string, std.traits, std.typecons,
     std.typetuple, std.utf;
 
-version (GNU)
-    import core.vararg;
-
 version (DigitalMars) version (Windows)
 {
     // Specific to the way Digital Mars C does stdio
 }
 
 private
-void writefx(FILE* fps, TypeInfo[] arguments, va_list argptr, int newline=false)
+void writefx(FILE* fps, TypeInfo[] arguments, void* argptr, int newline=false)
 {
     int orientation = fwide(fps, 0);    // move this inside the lock?
 

d/phobos2/std/stream.d

    * file.readf("%d hello %f", &x, &y, "%s", &s);
    * --------------------------
    */
-  int vreadf(TypeInfo[] arguments, va_list args);
+  int vreadf(TypeInfo[] arguments, void* args);
   int readf(...); /// ditto
 
   /// Retrieve the number of bytes available for immediate reading.
    */
   OutputStream writef(...);
   OutputStream writefln(...); /// ditto
-  OutputStream writefx(TypeInfo[] arguments, va_list argptr, int newline = false);  /// ditto
+  OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline = false);  /// ditto
 
   void flush(); /// Flush pending output if appropriate.
   void close(); /// Close the stream, flushing output if appropriate.
     return c;
   }
 
-  int vreadf(TypeInfo[] arguments, va_list args) {
+  int vreadf(TypeInfo[] arguments, void* args) {
     string fmt;
     int j = 0;
     int count = 0, i = 0;
   }
 
   // writes data with optional trailing newline
-  OutputStream writefx(TypeInfo[] arguments, va_list argptr, int newline=false) {
+  OutputStream writefx(TypeInfo[] arguments, void* argptr, int newline=false) {
     doFormat(&doFormatCallback,arguments,argptr);
     if (newline)
       writeLine("");
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.