From f6e2a30bf7d787c1692b34a5884af84ca6b134bc Mon Sep 17 00:00:00 2001 From: sean Date: Tue, 25 Nov 2008 23:53:07 +0000 Subject: [PATCH] Added core.vararg for variadic argument handling. This seemed necessary, since varargs are a language feature. There should be no conflict with std.stdarg, etc, anyway. git-svn-id: http://svn.dsource.org/projects/druntime/trunk@52 4a9d5153-6564-4b3f-b5e1-7e8e9dac548f --- src/common/core/vararg.d | 84 ++++++++++++++++++++++++++++++++++++++++ src/common/posix.mak | 11 +++++- src/common/win32.mak | 11 +++++- 3 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 src/common/core/vararg.d diff --git a/src/common/core/vararg.d b/src/common/core/vararg.d new file mode 100644 index 0000000..2c22000 --- /dev/null +++ b/src/common/core/vararg.d @@ -0,0 +1,84 @@ +/** + * The vararg module is intended to facilitate vararg manipulation in D. + * It should be interface compatible with the C module "stdarg," and the + * two modules may share a common implementation if possible (as is done + * here). + * + * Copyright: Public Domain + * License: Public Domain + * Authors: Hauke Duden, Walter Bright + */ +module core.vararg; + + +version( GNU ) +{ + public import std.stdarg; +} +else +{ + /** + * The base vararg list type. + */ + alias void* va_list; + + + /** + * This function initializes the supplied argument pointer for subsequent + * use by va_arg and va_end. + * + * Params: + * ap = The argument pointer to initialize. + * paramn = The identifier of the rightmost parameter in the function + * parameter list. + */ + void va_start(T) ( out va_list ap, inout T parmn ) + { + ap = cast(va_list) ( cast(void*) &parmn + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); + } + + /** + * This function returns the next argument in the sequence referenced by + * the supplied argument pointer. The argument pointer will be adjusted + * to point to the next arggument in the sequence. + * + * Params: + * ap = The argument pointer. + * + * Returns: + * The next argument in the sequence. The result is undefined if ap + * does not point to a valid argument. + */ + T va_arg(T) ( inout va_list ap ) + { + T arg = *cast(T*) ap; + ap = cast(va_list) ( cast(void*) ap + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) ); + return arg; + } + + /** + * This function cleans up any resources allocated by va_start. It is + * currently a no-op and exists mostly for syntax compatibility with + * the variadric argument functions for C. + * + * Params: + * ap = The argument pointer. + */ + void va_end( va_list ap ) + { + + } + + + /** + * This function copied the argument pointer src to dst. + * + * Params: + * src = The source pointer. + * dst = The destination pointer. + */ + void va_copy( out va_list dst, va_list src ) + { + dst = src; + } +} diff --git a/src/common/posix.mak b/src/common/posix.mak index 22bb3a9..5f8ba4d 100644 --- a/src/common/posix.mak +++ b/src/common/posix.mak @@ -78,7 +78,8 @@ OBJ_CORE= \ core/exception.o \ core/memory_.o \ core/runtime.o \ - core/thread.o + core/thread.o \ + core/vararg.o OBJ_STDC= \ core/stdc/errno.o @@ -94,7 +95,8 @@ DOC_CORE= \ core/exception.html \ core/memory.html \ core/runtime.html \ - core/thread.html + core/thread.html \ + core/vararg.html ###################################################### @@ -139,6 +141,11 @@ core/memory_.o : core/memory.d core/thread.o : core/thread.d $(DC) -c $(DFLAGS) -d -Hf$*.di core/thread.d -of$@ +### vararg + +core/vararg.o : core/vararg.d + $(DC) -c $(TFLAGS) -Hf$*.di core/vararg.d -of$@ + ###################################################### clean : diff --git a/src/common/win32.mak b/src/common/win32.mak index b05948a..70f7ad2 100644 --- a/src/common/win32.mak +++ b/src/common/win32.mak @@ -75,7 +75,8 @@ OBJ_CORE= \ core\exception.obj \ core\memory.obj \ core\runtime.obj \ - core\thread.obj + core\thread.obj \ + core\vararg.obj OBJ_STDC= \ core\stdc\errno.obj @@ -91,7 +92,8 @@ DOC_CORE= \ core\exception.html \ core\memory.html \ core\runtime.html \ - core\thread.html + core\thread.html \ + core\vararg.html ###################################################### @@ -131,6 +133,11 @@ core\bitmanip.obj : core\bitmanip.d core\thread.obj : core\thread.d $(DC) -c $(DFLAGS) -d -Hf$*.di core\thread.d -of$@ +### vararg + +core\vararg.obj : core\vararg.d + $(DC) -c $(TFLAGS) -Hf$*.di core\vararg.d -of$@ + ###################################################### clean : -- 2.43.0