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;
+}
+%}
+
+