Merge branch 'master' into gsoc2017-php7-classes-via-c-api

This commit is contained in:
Olly Betts 2021-03-26 12:00:59 +13:00
commit 2ba0f82720
16 changed files with 111 additions and 65 deletions

View file

@ -126,3 +126,21 @@ struct Extending2 {};
struct ExtendingOptArgs1 {};
struct ExtendingOptArgs2 {};
%}
// Varargs
%warnfilter(SWIGWARN_LANG_VARARGS_KEYWORD) VarargConstructor::VarargConstructor; // Can't wrap varargs with keyword arguments enabled
%warnfilter(SWIGWARN_LANG_VARARGS_KEYWORD) VarargConstructor::vararg_method; // Can't wrap varargs with keyword arguments enabled
%inline %{
struct VarargConstructor {
char *str;
VarargConstructor(const char *fmt, ...) {
str = new char[strlen(fmt) + 1];
strcpy(str, fmt);
}
void vararg_method(const char *fmt, ...) {
delete [] str;
str = new char[strlen(fmt) + 1];
strcpy(str, fmt);
}
};
%}

View file

@ -122,3 +122,18 @@ try:
raise RuntimeError("missed exception")
except TypeError as e:
pass
# Varargs
f = VarargConstructor(fmt="Ciao")
f.vararg_method(fmt="Bonjour")
try:
f = VarargConstructor(nonexistent="Ciao")
raise RuntimeError("missed exception")
except TypeError as e:
pass
try:
f.vararg_method(nonexistent="Bonjour")
raise RuntimeError("missed exception")
except TypeError as e:
pass

View file

@ -3,6 +3,10 @@ import varargs
if varargs.test("Hello") != "Hello":
raise RuntimeError("Failed")
vc = varargs.VarargConstructor("Hey there")
if vc.str != "Hey there":
raise RuntimeError("Failed")
f = varargs.Foo("Greetings")
if f.str != "Greetings":
raise RuntimeError("Failed")

View file

@ -1,17 +1,31 @@
// Tests SWIG's *default* handling of varargs (function varargs, not preprocessor varargs).
// Tests SWIG's handling of varargs (function varargs, not preprocessor varargs).
// The default behavior is to simply ignore the varargs.
%module varargs
// Default handling of varargs
%inline %{
char *test(const char *fmt, ...) {
return (char *) fmt;
}
struct VarargConstructor {
char *str;
VarargConstructor(const char *fmt, ...) {
str = new char[strlen(fmt) + 1];
strcpy(str, fmt);
}
};
%}
// %varargs support
%varargs(int mode = 0) test_def;
%varargs(int mode = 0) Foo::Foo;
%varargs(int mode = 0) Foo::statictest(const char*fmt, ...);
%varargs(2, int mode = 0) test_plenty(const char*fmt, ...);
%inline %{
char *test(const char *fmt, ...) {
return (char *) fmt;
}
const char *test_def(const char *fmt, ...) {
return fmt;
}
@ -40,5 +54,4 @@ public:
const char *test_plenty(const char *fmt, ...) {
return fmt;
}
%}