diff --git a/Doc/Manual/Varargs.html b/Doc/Manual/Varargs.html index ed52001e8..c27db603d 100644 --- a/Doc/Manual/Varargs.html +++ b/Doc/Manual/Varargs.html @@ -381,6 +381,26 @@ a call from the target language which does not provide the maximum number of arg will generate C code which includes the missing default values, that is, execlp("a", "b", "c", NULL, NULL). If compactdefaultargs is not used, then the generated code will be execlp("a", "b", "c"). The former is useful for helping providing a sentinel to terminate the argument list. +However, this is not guaranteed, for example when a user passes a non-NULL value for all the parameters. +When using compactdefaultargs it is possible to guarantee the NULL sentinel is passed through the, +numinputs=0 'in' typemap attribute, naming the last parameter. +For example, +
+ +
+%feature("compactdefaultargs") execlp;
+%varargs(3, char *str = NULL) execlp;
+%typemap(in, numinputs=0) char *str3 ""
+...
+int execlp(const char *path, const char *arg, ...);
+
++Note that str3 is the name of the last argument, as we have used %vargars with 3. +Now execlp("a", "b", "c", "d", "e") will result in an error as one too many arguments has been passed, +as now only 2 additional 'str' arguments can be passed with the 3rd one always using the specified default NULL.
diff --git a/Lib/swig.swg b/Lib/swig.swg index e7c01823e..a6fef0257 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -500,12 +500,6 @@ namespace std { } } -/* Typemap for variable length arguments sentinel value. Used - by the %varargs directive. */ - -%typemap(in,numinputs=0) SWIGTYPE *VARARGS_SENTINEL, SWIGTYPE VARARGS_SENTINEL ""; - - /* ----------------------------------------------------------------------------- * Overloading support * ----------------------------------------------------------------------------- */ diff --git a/Lib/typemaps/swigtype.swg b/Lib/typemaps/swigtype.swg index bd113e278..47baabf52 100644 --- a/Lib/typemaps/swigtype.swg +++ b/Lib/typemaps/swigtype.swg @@ -559,11 +559,6 @@ * --- Special typemaps --- * ------------------------------------------------------------ */ -/* VARARGS_SENTINEL typemap. Used by the %varargs directive. */ - -%typemap(in,numinputs=0) SWIGTYPE *VARARGS_SENTINEL, SWIGTYPE VARARGS_SENTINEL ""; - - /* DISOWN typemap */ %typemap(in, noblock=1) SWIGTYPE *DISOWN (int res = 0) {