From 8be65ec8e7d571a67715129298cfb9871232fd6f Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 7 Dec 2012 07:38:24 +0000 Subject: Add in va_list varargs workaround suggested by Antoine Mathys git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13949 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Doc/Manual/Varargs.html | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index c27db603d..13abc8cee 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -839,13 +839,13 @@ of type va_list. For example:
-int vfprintf(FILE *f, const char *fmt, va_list ap);
+int vprintf(const char *fmt, va_list ap);
 

-As far as we know, there is no obvious way to wrap these functions -with SWIG. This is because there is no documented way to assemble the +As far as we know, there is no obvious way to wrap these functions with +SWIG. This is because there is no documented way to assemble the proper va_list structure (there are no C library functions to do it and the contents of va_list are opaque). Not only that, the contents of a va_list structure are closely tied to the underlying @@ -853,6 +853,36 @@ call-stack. It's not clear that exporting a va_list would have any use or that it would work at all.

+

+A workaround can be implemented by writing a simple varargs C wrapper and then using the techniques +discussed earlier in this chapter for varargs. Below is a simple wrapper for vprintf renamed so that +it can still be called as vprintf from your target language. The %varargs +used in the example restricts the function to taking one string argument. +

+ +
+
+%{
+int vprintf(const char *fmt, va_list ap);
+%}
+
+%varargs(const char *) my_vprintf;
+%rename(vprintf) my_vprintf;
+
+%inline %{
+int my_vprintf(const char *fmt, ...) {
+  va_list ap;
+  int result;
+
+  va_start(ap, fmt);
+  result = vprintf(fmt, ap);
+  va_end(ap);
+  return result;
+}
+%}
+
+
+

13.8 C++ Issues

-- cgit v1.2.1