diff --git a/Examples/test-suite/char_strings.i b/Examples/test-suite/char_strings.i index 9a87df4e3..aa3b125ce 100644 --- a/Examples/test-suite/char_strings.i +++ b/Examples/test-suite/char_strings.i @@ -11,6 +11,7 @@ below. %{ #include +#include #define OTHERLAND_MSG "Little message from the safe world." #define CPLUSPLUS_MSG "A message from the deep dark world of C++, where anything is possible." @@ -150,11 +151,11 @@ const char global_const_char_array2[sizeof(CPLUSPLUS_MSG)+1] = CPLUSPLUS_MSG; %inline { struct Formatpos; struct OBFormat; - + static int GetNextFormat(Formatpos& itr, const char*& str,OBFormat*& pFormat) { return 0; } - + } diff --git a/Examples/test-suite/default_args.i b/Examples/test-suite/default_args.i index 6b680f561..2f8fdbbd2 100644 --- a/Examples/test-suite/default_args.i +++ b/Examples/test-suite/default_args.i @@ -18,6 +18,7 @@ %{ #define TESTCASE_THROW1(T1) #define TESTCASE_THROW2(T1, T2) +#include %} %include @@ -71,7 +72,7 @@ class EnumClass { public: enum speed { FAST, SLOW }; - // Note: default values should be EnumClass::FAST and SWEET + // Note: default values should be EnumClass::FAST and SWEET bool blah(speed s = FAST, flavor f = SWEET) { return (s == FAST && f == SWEET); }; }; @@ -83,16 +84,16 @@ // casts const char * casts1(const char *m = (const char *) NULL) { - char *ret = NULL; - if (m) { + char *ret = NULL; + if (m) { ret = new char[strlen(m)+1]; strcpy(ret, m); } return ret; } const char * casts2(const char *m = (const char *) "Hello") { - char *ret = NULL; - if (m) { + char *ret = NULL; + if (m) { ret = new char[strlen(m)+1]; strcpy(ret, m); } @@ -108,16 +109,16 @@ char chartest6(char c = '\x43') { return c; } // 'C' // namespaces - namespace AType { - enum AType { NoType }; - } + namespace AType { + enum AType { NoType }; + } void dummy(AType::AType aType = AType::NoType) {} - namespace A { - namespace B { - int CONST_NUM = 10; - } + namespace A { + namespace B { + int CONST_NUM = 10; + } int afunction(int i = B::CONST_NUM) { return i; } - } + } // references int reftest1(const int &x = 42) { return x; } @@ -131,7 +132,7 @@ void test(int x = Oak + Fir + Cedar) {} }; enum Tree::types chops(enum Tree::types type) { return type; } - + %} // Rename a class member @@ -155,11 +156,11 @@ static int spam; Foo(){} - + Foo(int x, int y = 0, int z = 0){} void meth(int x, int y = 0, int z = 0){} - + // Use a renamed member as a default argument. SWIG has to resolve // bar to Foo::bar and not Foo::spam. SWIG-1.3.11 got this wrong. // (Different default parameter wrapping in SWIG-1.3.23 ensures SWIG doesn't have to resolve these symbols). @@ -189,20 +190,20 @@ // tests valuewrapper %feature("compactdefaultargs") MyClass2::set; %inline %{ - enum MyType { Val1, Val2 }; + enum MyType { Val1, Val2 }; - class MyClass1 - { - public: + class MyClass1 + { + public: MyClass1(MyType myType) {} - }; + }; - class MyClass2 - { - public : + class MyClass2 + { + public : void set(MyClass1 cl1 = Val1) {} - // This could have been written : set(MyClass1 cl1 = MyClass1(Val1)) - // But it works in C++ since there is a "conversion" constructor in MyClass1. + // This could have been written : set(MyClass1 cl1 = MyClass1(Val1)) + // But it works in C++ since there is a "conversion" constructor in MyClass1. void set2(MyClass1 cl1 = Val1) {} }; %} @@ -281,7 +282,7 @@ struct ConstMethods { }; %} -// const methods +// const methods // runtime test needed to check that the const method is called struct ConstMethods { int coo(double d = 0.0) const; @@ -305,8 +306,8 @@ struct ConstMethods { return(x+p); } - typedef struct Pointf { - double x,y; + typedef struct Pointf { + double x,y; } Pointf; } %} diff --git a/Examples/test-suite/director_thread.i b/Examples/test-suite/director_thread.i index 105eb4e54..ac48060ed 100644 --- a/Examples/test-suite/director_thread.i +++ b/Examples/test-suite/director_thread.i @@ -20,7 +20,6 @@ #ifdef _WIN32 #include #include -#include #else #include #include @@ -30,6 +29,7 @@ #endif #include +#include #include "swig_examples_lock.h" class Foo; diff --git a/Examples/test-suite/li_cdata.i b/Examples/test-suite/li_cdata.i index 2180af96e..4e1a01e4e 100644 --- a/Examples/test-suite/li_cdata.i +++ b/Examples/test-suite/li_cdata.i @@ -5,4 +5,8 @@ %cdata(int); %cdata(double); +%{ +#include +%} + void *malloc(size_t size); diff --git a/Examples/test-suite/li_cdata_cpp.i b/Examples/test-suite/li_cdata_cpp.i index 2d7d300e4..80ff2932b 100644 --- a/Examples/test-suite/li_cdata_cpp.i +++ b/Examples/test-suite/li_cdata_cpp.i @@ -5,4 +5,8 @@ %cdata(int); %cdata(double); +%{ +#include +%} + void *malloc(size_t size); diff --git a/Examples/test-suite/li_std_except.i b/Examples/test-suite/li_std_except.i index 60bce999d..9bf70cd3f 100644 --- a/Examples/test-suite/li_std_except.i +++ b/Examples/test-suite/li_std_except.i @@ -9,6 +9,8 @@ %} %inline %{ + #include + #include struct E1 : public std::exception { }; diff --git a/Examples/test-suite/memberin_extend.i b/Examples/test-suite/memberin_extend.i index c6eb10526..43251973f 100644 --- a/Examples/test-suite/memberin_extend.i +++ b/Examples/test-suite/memberin_extend.i @@ -11,6 +11,7 @@ struct ExtendMe { %{ #include +#include std::map ExtendMeStringMap; void ExtendMe_thing_set(ExtendMe *self, const char *val) { char *old_val = ExtendMeStringMap[self]; diff --git a/Examples/test-suite/mod.h b/Examples/test-suite/mod.h index aae629850..60eb36b77 100644 --- a/Examples/test-suite/mod.h +++ b/Examples/test-suite/mod.h @@ -1,4 +1,4 @@ - +#include class C; diff --git a/Examples/test-suite/namespace_typemap.i b/Examples/test-suite/namespace_typemap.i index 42edd2844..2571b5a81 100644 --- a/Examples/test-suite/namespace_typemap.i +++ b/Examples/test-suite/namespace_typemap.i @@ -2,6 +2,7 @@ %module namespace_typemap %{ +#include namespace test { /* A minimalistic string class */ class string_class { diff --git a/Examples/test-suite/nested_extend_c.i b/Examples/test-suite/nested_extend_c.i index f1d7ff2c8..67ca86578 100644 --- a/Examples/test-suite/nested_extend_c.i +++ b/Examples/test-suite/nested_extend_c.i @@ -12,6 +12,10 @@ #endif +%{ +#include "stdlib.h" +%} + #if !defined(SWIGOCTAVE) && !defined(SWIG_JAVASCRIPT_V8) %extend hiA { hiA() { diff --git a/Examples/test-suite/operator_overload_break.i b/Examples/test-suite/operator_overload_break.i index a948f2d49..809498fa7 100644 --- a/Examples/test-suite/operator_overload_break.i +++ b/Examples/test-suite/operator_overload_break.i @@ -18,6 +18,7 @@ %{ #include +#include using namespace std; %} diff --git a/Examples/test-suite/operator_pointer_ref.i b/Examples/test-suite/operator_pointer_ref.i index 84182da0d..cd4ed2db0 100644 --- a/Examples/test-suite/operator_pointer_ref.i +++ b/Examples/test-suite/operator_pointer_ref.i @@ -4,6 +4,8 @@ #if defined(_MSC_VER) #pragma warning(disable: 4996) // 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details. #endif +#include +#include %} %rename(AsCharStarRef) operator char*&; diff --git a/Examples/test-suite/smart_pointer_const_overload.i b/Examples/test-suite/smart_pointer_const_overload.i index 75a137b73..526bcc9bd 100644 --- a/Examples/test-suite/smart_pointer_const_overload.i +++ b/Examples/test-suite/smart_pointer_const_overload.i @@ -3,6 +3,10 @@ %warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar::operator->; // Overloaded method Bar::operator ->() ignored %warnfilter(SWIGWARN_LANG_OVERLOAD_IGNORED) Bar2::operator->; // Overloaded method Bar2::operator ->() ignored +%{ +#include +%} + %inline %{ int CONST_ACCESS = 1; int MUTABLE_ACCESS = 2; diff --git a/Examples/test-suite/special_variable_macros.i b/Examples/test-suite/special_variable_macros.i index ca2edaa98..98d108b6b 100644 --- a/Examples/test-suite/special_variable_macros.i +++ b/Examples/test-suite/special_variable_macros.i @@ -9,6 +9,8 @@ #if defined(_MSC_VER) #pragma warning(disable: 4996) // 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _strdup. See online help for details. #endif +#include +#include %} %ignore Name::operator=; diff --git a/Examples/test-suite/string_simple.i b/Examples/test-suite/string_simple.i index 537daa570..55cb950b0 100644 --- a/Examples/test-suite/string_simple.i +++ b/Examples/test-suite/string_simple.i @@ -3,6 +3,7 @@ %newobject copy_str; %inline %{ +#include #include const char* copy_str(const char* str) { size_t len = strlen(str); diff --git a/Examples/test-suite/testdir/inctest/subdir2/hello.i b/Examples/test-suite/testdir/inctest/subdir2/hello.i index ed172b1fd..e87b43759 100644 --- a/Examples/test-suite/testdir/inctest/subdir2/hello.i +++ b/Examples/test-suite/testdir/inctest/subdir2/hello.i @@ -3,6 +3,7 @@ %{ typedef char * TypedefString; +#include %} diff --git a/Examples/test-suite/threads.i b/Examples/test-suite/threads.i index 7c6b09be0..28c55945e 100644 --- a/Examples/test-suite/threads.i +++ b/Examples/test-suite/threads.i @@ -9,6 +9,7 @@ %inline %{ #include + #include struct Kerfuffle { std::string StdString(std::string str) { return str; diff --git a/Examples/test-suite/threads_exception.i b/Examples/test-suite/threads_exception.i index 4708633db..776e84231 100644 --- a/Examples/test-suite/threads_exception.i +++ b/Examples/test-suite/threads_exception.i @@ -13,6 +13,7 @@ %} %{ +#include struct A {}; %} diff --git a/Examples/test-suite/typedef_struct.i b/Examples/test-suite/typedef_struct.i index 185e81105..b9a670cf5 100644 --- a/Examples/test-suite/typedef_struct.i +++ b/Examples/test-suite/typedef_struct.i @@ -31,6 +31,7 @@ #define MS_NOOVERRIDE -1111 +#include %} diff --git a/Examples/test-suite/varargs.i b/Examples/test-suite/varargs.i index 68c7a1714..c1aee229e 100644 --- a/Examples/test-suite/varargs.i +++ b/Examples/test-suite/varargs.i @@ -4,6 +4,10 @@ // Default handling of varargs +%{ +#include +%} + %inline %{ char *test(const char *fmt, ...) { return (char *) fmt; diff --git a/Lib/carrays.i b/Lib/carrays.i index 3a9c3cfee..0aa3eee89 100644 --- a/Lib/carrays.i +++ b/Lib/carrays.i @@ -5,6 +5,12 @@ * pointers as arrays. * ----------------------------------------------------------------------------- */ +#ifndef __cplusplus +// C uses free/calloc/malloc +%include "swigfragments.swg" +%fragment(""); +#endif + /* ----------------------------------------------------------------------------- * %array_functions(TYPE,NAME) * diff --git a/Lib/cdata.i b/Lib/cdata.i index cd1526643..8736de1c2 100644 --- a/Lib/cdata.i +++ b/Lib/cdata.i @@ -4,6 +4,8 @@ * SWIG library file containing macros for manipulating raw C data as strings. * ----------------------------------------------------------------------------- */ +%include + %{ typedef struct SWIGCDATA { char *data; @@ -60,7 +62,7 @@ static jbyteArray SWIG_JavaArrayOutCDATA(JNIEnv *jenv, char *result, jsize sz) { /* ----------------------------------------------------------------------------- - * %cdata(TYPE [, NAME]) + * %cdata(TYPE [, NAME]) * * Convert raw C data to a binary string. * ----------------------------------------------------------------------------- */ @@ -99,6 +101,8 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements); %cdata(void); +%fragment(""); + /* Memory move function. Due to multi-argument typemaps this appears to be wrapped as void memmove(void *data, const char *s); */ void memmove(void *data, const void *indata, int inlen); diff --git a/Lib/cpointer.i b/Lib/cpointer.i index 6eb509d7e..a04de3d67 100644 --- a/Lib/cpointer.i +++ b/Lib/cpointer.i @@ -5,6 +5,12 @@ * pointer objects. * ----------------------------------------------------------------------------- */ +#ifndef __cplusplus +// C uses free/calloc/malloc +%include "swigfragments.swg" +%fragment(""); +#endif + /* ----------------------------------------------------------------------------- * %pointer_class(type,name) * diff --git a/Lib/swig.swg b/Lib/swig.swg index 6dc215dcf..d719a139c 100644 --- a/Lib/swig.swg +++ b/Lib/swig.swg @@ -453,7 +453,7 @@ namespace std { /* Default typemap for handling char * members */ #ifdef __cplusplus -%typemap(memberin) char * { +%typemap(memberin,fragment="") char * { delete [] $1; if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); @@ -462,7 +462,7 @@ namespace std { $1 = 0; } } -%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); strcpy((char *)$1, (const char *)$input); @@ -470,7 +470,7 @@ namespace std { $1 = 0; } } -%typemap(globalin) char * { +%typemap(globalin,fragment="") char * { delete [] $1; if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); @@ -479,7 +479,7 @@ namespace std { $1 = 0; } } -%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) (new char[strlen((const char *)$input)+1]); strcpy((char *)$1, (const char *)$input); @@ -488,7 +488,7 @@ namespace std { } } #else -%typemap(memberin) char * { +%typemap(memberin,fragment="") char * { free($1); if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); @@ -497,7 +497,7 @@ namespace std { $1 = 0; } } -%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(memberin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); strcpy((char *)$1, (const char *)$input); @@ -505,7 +505,7 @@ namespace std { $1 = 0; } } -%typemap(globalin) char * { +%typemap(globalin,fragment="") char * { free($1); if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); @@ -514,7 +514,7 @@ namespace std { $1 = 0; } } -%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG) const char * { +%typemap(globalin,warning=SWIGWARN_TYPEMAP_CHARLEAK_MSG,fragment="") const char * { if ($input) { $1 = ($1_type) malloc(strlen((const char *)$input)+1); strcpy((char *)$1, (const char *)$input); @@ -527,7 +527,7 @@ namespace std { /* Character array handling */ -%typemap(memberin) char [ANY] { +%typemap(memberin,fragment="") char [ANY] { if($input) { strncpy((char*)$1, (const char *)$input, $1_dim0-1); $1[$1_dim0-1] = 0; @@ -536,7 +536,7 @@ namespace std { } } -%typemap(globalin) char [ANY] { +%typemap(globalin,fragment="") char [ANY] { if($input) { strncpy((char*)$1, (const char *)$input, $1_dim0-1); $1[$1_dim0-1] = 0; @@ -545,25 +545,25 @@ namespace std { } } -%typemap(memberin) char [] { +%typemap(memberin,fragment="") char [] { if ($input) strcpy((char *)$1, (const char *)$input); else $1[0] = 0; } -%typemap(globalin) char [] { +%typemap(globalin,fragment="") char [] { if ($input) strcpy((char *)$1, (const char *)$input); else $1[0] = 0; } /* memberin/globalin typemap for arrays. */ -%typemap(memberin) SWIGTYPE [ANY] { +%typemap(memberin,fragment="") SWIGTYPE [ANY] { size_t ii; $1_basetype *b = ($1_basetype *) $1; for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); } -%typemap(globalin) SWIGTYPE [ANY] { +%typemap(globalin,fragment="") SWIGTYPE [ANY] { size_t ii; $1_basetype *b = ($1_basetype *) $1; for (ii = 0; ii < (size_t)$1_size; ii++) b[ii] = *(($1_basetype *) $input + ii); @@ -571,7 +571,7 @@ namespace std { /* memberin/globalin typemap for double arrays. */ -%typemap(memberin) SWIGTYPE [ANY][ANY] { +%typemap(memberin,fragment="") SWIGTYPE [ANY][ANY] { $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); size_t ii = 0; @@ -583,7 +583,7 @@ namespace std { } } -%typemap(globalin) SWIGTYPE [ANY][ANY] { +%typemap(globalin,fragment="") SWIGTYPE [ANY][ANY] { $basetype (*inp)[$1_dim1] = ($basetype (*)[$1_dim1])($input); $basetype (*dest)[$1_dim1] = ($basetype (*)[$1_dim1])($1); size_t ii = 0; diff --git a/Lib/swigfragments.swg b/Lib/swigfragments.swg index 2cbef7cce..28aa1180f 100644 --- a/Lib/swigfragments.swg +++ b/Lib/swigfragments.swg @@ -29,6 +29,10 @@ #include %} +%fragment("", "header") %{ +#include +%} + %fragment("", "header") %{ #include %}