summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2012-12-07 07:38:24 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2012-12-07 07:38:24 +0000
commit8be65ec8e7d571a67715129298cfb9871232fd6f (patch)
tree2c718c0a4c814cc0b628235d23672ecc5512b379
parentf38147c154e84dea7e61cf581fdd51a76d24f1a4 (diff)
downloadswig-8be65ec8e7d571a67715129298cfb9871232fd6f.tar.gz
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
-rw-r--r--Doc/Manual/Varargs.html36
1 files 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 <tt>va_list</tt>. For example:
<div class="code">
<pre>
-int vfprintf(FILE *f, const char *fmt, va_list ap);
+int vprintf(const char *fmt, va_list ap);
</pre>
</div>
<p>
-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 <tt>va_list</tt> structure are closely tied to the underlying
@@ -853,6 +853,36 @@ call-stack. It's not clear that exporting a <tt>va_list</tt> would
have any use or that it would work at all.
</p>
+<p>
+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 <tt>vprintf</tt> renamed so that
+it can still be called as <tt>vprintf</tt> from your target language. The <tt>%varargs</tt>
+used in the example restricts the function to taking one string argument.
+</p>
+
+<div class="code">
+<pre>
+%{
+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;
+}
+%}
+</pre>
+</div>
+
<H2><a name="Varargs_nn9"></a>13.8 C++ Issues</H2>