Merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@13053 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Vincent Couvert 2012-05-09 14:28:04 +00:00
commit 7444913fda
59 changed files with 955 additions and 692 deletions

View file

@ -1,8 +1,8 @@
*** ANNOUNCE: SWIG 2.0.5 (in progress) ***
*** ANNOUNCE: SWIG 2.0.6 (30 April 2012) ***
http://www.swig.org
We're pleased to announce SWIG-2.0.5, the latest SWIG release.
We're pleased to announce SWIG-2.0.6, the latest SWIG release.
What is SWIG?
=============
@ -21,11 +21,11 @@ Availability
============
The release is available for download on Sourceforge at
http://prdownloads.sourceforge.net/swig/swig-2.0.5.tar.gz
http://prdownloads.sourceforge.net/swig/swig-2.0.6.tar.gz
A Windows version is also available at
http://prdownloads.sourceforge.net/swig/swigwin-2.0.5.zip
http://prdownloads.sourceforge.net/swig/swigwin-2.0.6.zip
Please report problems with this release to the swig-devel mailing list,
details at http://www.swig.org/mail.html.

440
CHANGES
View file

@ -3,6 +3,446 @@ SWIG (Simplified Wrapper and Interface Generator)
See the CHANGES.current file for changes in the current version.
See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.5 (19 April 2012)
=============================
2012-04-14: wsfulton
[Lua] Apply patch #3517435 from Miles Bader - prefer to use Lua_pushglobaltable
2012-04-14: wsfulton
[Ruby] Apply patch #3517769 from Robin Stocker to fix compile error on MacRuby using RSTRING_PTR.
2012-04-13: wsfulton
Apply patch #3511009 from Leif Middelschulte for slightly optimised char * variable wrappers.
2012-04-13: wsfulton
[Lua] Apply #3219676 from Shane Liesegang which adds:
- support for %factory
- a __tostring method
- a __disown method
2012-04-13: wsfulton
[Xml] Apply #3513569 which adds a catchlist to the xml output.
2012-04-05: olly
[Lua] Add support for Lua 5.2 (patch SF#3514593 from Miles Bader)
2012-03-26: xavier98
[octave] Apply patch #3425993 from jgillis: add extra logic to the octave_swig_type::dims(void) method: it checks if the user has defined a __dims__ method and uses this in stead of returning (1,1)
[octave] Apply patch #3424833 from jgillis: make is_object return true for swig types
2012-03-24: wsfulton
[D] Apply #3502431 to fix duplicate symbols in multiple modules.
2012-03-21: wsfulton
Fix #3494791 - %$isglobal for %rename matching.
2012-03-20: wsfulton
Fix #3487706 and #3391906 - missing stddef.h include for ptrdiff_t when using %import
for STL containers and compiling with g++-4.6. An include of stddef.h is now only
generated when SWIG generates STL helper templates which require ptrdiff_t. If you
were previously relying on "#include <stddef.h>" always being generated when using a
%include of an STL header, you may now need to add this in manually.
2012-03-16: wsfulton
Apply patch #3392264 from Sebastien Bine to parse (unsigned) long long types in enum value assignment.
2012-03-16: wsfulton
Apply patch #3505530 from Karl Wette to allow custom allocators in STL string classes for the UTL languages.
2012-03-13: wsfulton
Apply patch #3468362 from Karl Wette to fix %include inside %define.
2012-03-13: wsfulton
[Python, Ruby, Octave, R] Fix #3475492 - iterating through std::vector wrappers of enumerations.
2012-02-27: xavier98 (patches from Karl Wette)
[Octave] Use -globals . to load global variables in module namespace
[Octave] Comment declaration of unimplemented function swig_register_director
[Octave] Fix OCTAVE_PATH in octave Makefiles
[Octave] Add support for std::list - fix li_std_containers_int test
[Octave] Fix imports test
2012-02-16: wsfulton
[Java] Make generated support functions in arrays_java.i static so that generated code
from multiple instances of SWIG can be compiled and linked together - problem reported by
Evan Krause.
2012-01-24: wsfulton
Fix crash with bad regex - bug #3474250.
2012-01-24: wsfulton
[Python] Add Python stepped slicing support to the STL wrappers (std::vector, std::list).
Assigning to a slice, reading a slice and deleting a slice with steps now work.
For example:
%template(vector_i) std::vector<int>
vi = vector_i(range(10))
print list(vi)
vi[1:4:2] = [111, 333]
print list(vi)
del vi[3:10:3]
print list(vi)
print list(vi[::-1])
gives (same behaviour as native Python sequences such as list):
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 111, 2, 333, 4, 5, 6, 7, 8, 9]
[0, 111, 2, 4, 5, 7, 8]
[8, 7, 5, 4, 2, 111, 0]
2012-01-23: klickverbot
[D] Correctly annotate function pointers with C linkage.
[D] Exception and Error have become blessed names; removed d_exception_name test case.
2012-01-20: wsfulton
[Python] Fix some indexing bugs in Python STL wrappers when the index is negative, eg:
%template(vector_i) std::vector<int>
iv=vector_i([0,1,2,3,4,5])
iv[-7:]
now returns [0, 1, 2, 3, 4, 5] instead of [5].
vv[7:9] = [22,33]
now returns [0, 1, 2, 3, 4, 5, 22, 33] instead of "index out range" error.
Also fix some segfaults when replacing ranges, eg when il is a std::list wrapper:
il[0:2] = [11]
2012-01-17: wsfulton
[Go] Fix forward class declaration within a class when used as a base.
2012-01-07: wsfulton
[C#] Add support for %nspace when using directors.
2012-01-06: wsfulton
[Java] Patch #3452560 from Brant Kyser - add support for %nspace when using directors.
2011-12-21: wsfulton
The 'directorin' typemap now accepts $1, $2 etc expansions instead of having to use workarounds -
$1_name, $2_name etc.
2011-12-20: wsfulton
[Java] Add (char *STRING, size_t LENGTH) director typemaps.
2011-12-20: wsfulton
[C#, Go, Java, D] Add support for the 'directorargout' typemap.
2011-12-20: wsfulton
[Ocaml, Octave, PHP, Python, Ruby] Correct special variables in 'directorargout' typemap.
This change will break any 'directorargout' typemaps you may have written. Please change:
$result to $1
$input to $result
Also fix the named 'directorargout' DIRECTOROUT typemaps for these languages which didn't
previously compile and add in $1, $2 etc expansion.
*** POTENTIAL INCOMPATIBILITY ***
2011-12-10: talby
[perl5] SWIG_error() now gets decorated with perl source file/line number.
[perl5] error handling now conforms to public XS api (fixes perl v5.14 issue).
2011-12-10: wsfulton
[Android/Java] Fix directors to compile on Android.
Added documentation and examples for Android.
2011-12-08: vadz
Bug fix: Handle methods renamed or ignored in the base class correctly in the derived classes
(they could be sometimes mysteriously not renamed or ignored there before).
2011-12-03: klickverbot
[D] Fix exception glue code for newer DMD 2 versions.
[D] Do not default to 32 bit glue code for DMD anymore.
[D] Use stdc.config.c_long/c_ulong to represent C long types.
2011-12-01: szager
[python] Fixed bug 3447426: memory leak in vector.__getitem__.
2011-11-30: wsfulton
[R] Remove C++ comments from generated C code.
2011-11-27: olly
[Python] Fix some warnings when compiling generated wrappers with
certain GCC warning options (Debian bug #650246).
2011-11-28: wsfulton
Fix #3433541 %typemap(in, numinputs=0) with 10+ arguments.
2011-11-28: olly
[Perl] Fix warnings when compiling generated wrappers with certain
GCC warning options (Debian bug #436711).
2011-11-28: olly
[PHP] Update keyword list to include keywords added in PHP releases up to 5.3.
2011-11-25: wsfulton
[C#] Provide an easy way to override the default visibility for the proxy class pointer
constructors and getCPtr() method. The visibility is 'internal' by default and if multiple
SWIG modules are being used and compiled into different assemblies, then they need to be
'public' in order to use the constructor or getCPtr() method from a different assembly.
Use the following macros to change the visibilities in the proxy and type wrapper class:
SWIG_CSBODY_PROXY(public, public, SWIGTYPE)
SWIG_CSBODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
[Java] Provide an easy way to override the default visibility for the proxy class pointer
constructors and getCPtr() method. The visibility is 'protected' by default and if multiple
SWIG modules are being used and compiled into different packages, then they need to be
'public' in order to use the constructor or getCPtr() method from a different package.
Use the following macros to change the visibilities in the proxy and type wrapper class:
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
The default for Java has changed from public to protected for the proxy classes. Use the
SWIG_JAVABODY_PROXY macro above to restore to the previous visibilities.
*** POTENTIAL INCOMPATIBILITY ***
2011-11-22: szager
[python] Bug 3440044: #ifdef out SWIG_Python_NonDynamicSetAttr if -builtin
isn't being used, to avoid unnecessary binary incompatibilities between
python installations.
2011-11-17: wsfulton
Bug fix: Remove root directory from directory search list in Windows.
2011-11-13: wsfulton
[Ruby] Apply patch #3421876 from Robin Stocker to fix #3416818 - same class name in
different namespaces confusion when using multiple modules.
2011-11-11: wsfulton
Fix pcre-build.sh to work with non-compressed tarballs - problem reported by Adrian Blakely.
2011-11-03: wsfulton
Expand special variables in typemap warnings, eg:
%typemap(in, warning="1000:Test warning for 'in' typemap for $1_type $1_name") int "..."
2011-11-01: wsfulton
Fix named output typemaps not being used when the symbol uses a qualifier and contains
a number, eg:
%typemap(out) double ABC::m1 "..."
2011-10-24: talby
[perl5] SF bug #3423119 - overload dispatch stack corruption fix. Better, but more research
is needed on a stable path for tail calls in XS.
Also, fix for large long longs in 32 bit perl.
2011-10-13: xavier98
[octave] Allow Octave modules to be re-loaded after a "clear all".
2011-09-19: wsfulton
Fix regression introduced in swig-2.0.1 reported by Teemu Ikonone leading to uncompilable code
when using typedef and function pointer references, for example:
typedef int FN(const int &a, int b);
void *typedef_call1(FN *& precallback, FN * postcallback);
2011-09-14: wsfulton
[Lua] Patch #3408012 from Raman Gopalan - add support for embedded Lua (eLua)
including options for targeting Lua Tiny RAM (LTR).
2011-09-14: wsfulton
[C#] Add boost_intrusive_ptr.i library contribution from patch #3401571.
2011-09-13: wsfulton
Add warnings for badly named destructors, eg:
struct KStruct {
~NOT_KStruct() {}
};
cpp_extend_destructors.i:92: Warning 521: Illegal destructor name ~NOT_KStruct. Ignored.
2011-09-13: wsfulton
Fix %extend and destructors for templates. The destructor in %extend was not always wrapped,
for example:
%extend FooT {
~FooT() { delete $self; } // was not wrapped as expected
};
template<class T> class FooT {};
%template(FooTi) FooT<int>;
2011-09-13: wsfulton
Fix special variables such as "$decl" and "$fulldecl" in destructors to include the ~ character.
2011-09-10: talby
[perl5] SF bug #1481958 - Improve range checking for integer types.
Enhance li_typemaps_runme.pl
2011-09-08: wsfulton
Fix %extend on typedef classes in a namespace using the typedef name, for example:
namespace Space {
%extend CStruct {
...
}
typedef struct tagCStruct { ... } CStruct;
}
2011-08-31: xavier98
[octave] patches from Karl Wette: improvements to module loading behavior;
added example of friend operator to operator example; fixed octave panic/crash in 3.0.5;
documentation improvements
2011-08-30: szager
[python] Bug 3400486, fix error signalling for built-in constructors.
2011-08-26: wsfulton
[Go] Fix file/line number display for "gotype" when using typemap debugging options
-tmsearch and -tmused.
2011-08-26: wsfulton
[C#, D] Fix %callback which was generating uncompileable code.
2011-08-25: wsfulton
Fix constructors in named typedef class declarations as reported by Gregory Bronner:
typedef struct A {
A(){} // Constructor which was not accepted by SWIG
B(){} // NOT a constructor --illegal, but was accepted by SWIG
} B;
For C code, the fix now results in the use of 'struct A *' instead of just 'B *' in
the generated code when wrapping members in A, but ultimately this does not matter, as
they are the same thing.
2011-08-23: wsfulton
Fix %newobject when used in conjunction with %feature("ref") as reported by Jan Becker. The
code from the "ref" feature was not always being generated for the function specified by %newobject.
Documentation for "ref" and "unref" moved from Python to the C++ chapter.
2011-08-22: szager
[python] Fixed memory leak with --builtin option (bug 3385089).
2011-08-22: wsfulton
[Lua] SF patch #3394339 from Torsten Landschoff - new option -nomoduleglobal to disable installing
the module table into the global namespace. Require call also returns the module table instead
of a string.
2011-08-09: xavier98
Fix bug 3387394; Octave patches for 3.4.0 compatibility, etc. (from Karl Wette)
2011-08-04: wsfulton
Add in $symname expansion for director methods.
2011-07-29: olly
[PHP] Don't generate "return $r;" in cases where $r hasn't been set.
This was basically harmless, except it generated a PHP E_NOTICE if
the calling code had enabled them.
2011-07-26: wsfulton
Fix scoping of forward class declarations nested within a class (for C++). Previously the symbol
was incorrectly put into the outer namespace, eg
namespace std {
template<class Key, class T> struct map {
class iterator;
}
}
iterator was scoped as std::iterator, but now it is correctly std::map<Key, T>::iterator;
Also fixed is %template and template parameters that are a typedef when the template contains
default template parameters, eg:
namespace Std {
template<class Key, class T, class C = int> struct Map {
typedef Key key_type;
typedef T mapped_type;
}
}
tyepdef double DOUBLE;
%typemap(MM) Std::Map<int, DOUBLE>;
All symbols within Map will be resolved correctly, eg key_type and mapped_type no matter if the
wrapped code uses Std::Map<int, double> or std::Map<int, DOUBLE> or Std::Map<int, double, int>
Also fixes bug #3378145 - regression introduced in 2.0.4 - %template using traits.
2011-07-20 szager
[python] Fix closure for tp_call slot.
2011-07-16: wsfulton
[python] Fix director typemap using PyObject *.
2011-07-13: szager
[python] SF patch #3365908 - Add all template parameters to map support code in std_map.i
2011-07-13: szager
[python] Fix for bug 3324753: %rename member variables with -builtin.
2011-07-01: wsfulton
Fix some scope and symbol lookup problems when template default parameters are being
used with typedef. For example:
template<typename XX, typename TT = SomeType> struct Foo {
typedef XX X;
typedef TT T;
};
template<typename TT> struct UsesFoo {
void x(typename Foo<TT>::T, typename Foo<TT>::X);
};
Also fixes use of std::vector<int>::size_type for Python as reported by Aubrey Barnard.
2011-06-23: olly
[PHP] Fix director code to work when PHP is built with ZTS enabled,
which is the standard configuration on Microsoft Windows.
2011-06-21: mutandiz
[allegrocl]
- various small tweaks and bug fixes.
- Avoid name conflicts between smart pointer wrappers and the wrappers for
the actual class.
- Fix default typemaps for C bindings, which were incorrectly attempting to
call non-existent destructors on user-defined types.
- New feature, feature:aclmixins, for adding superclass to the foreign class
wrappers.
- Improve longlong typemaps.
2011-06-19: wsfulton
Fix incorrect typemaps being used for a symbol within a templated type, eg:
A<int>::value_type would incorrectly use a typemap for type A.
2011-06-18: olly
[Tcl] Fix variable declarations in middle of blocks which isn't
permitted in C90 (issue probably introduced in 2.0.3 by patch #3224663).
Reported by Paul Obermeier in SF#3288586.
2011-06-17: wsfulton
[Java] SF #3312505 - slightly easier to wrap char[] or char[ANY] with a Java byte[]
using arrays_java.i.
2011-06-13: wsfulton
[Ruby, Octave] SF #3310528 Autodoc fixes similar to those described below for Python.
2011-06-10: wsfulton
[Python] Few subtle bugfixes in autodoc documentation generation,
- Unnamed argument names fix for autodoc levels > 0.
- Display of template types fixed for autodoc levels > 1.
- Fix SF #3310528 - display of typedef structs for autodoc levels > 1.
- Add missing type for self for autodoc levels 1 and 3.
- autodoc levels 2 and 3 documented.
- Minor tweaks to autodoc style to conform with PEP8.
2011-05-30: olly
[PHP] Fix handling of directors when -prefix is used.
2011-05-24: olly
[PHP] Fix handling of methods of classes with a virtual base class (SF#3124665).
Version 2.0.4 (21 May 2011)
===========================

View file

@ -2,430 +2,16 @@ Below are the changes for the current release.
See the CHANGES file for changes in older releases.
See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.5 (in progress)
===========================
Version 2.0.6 (30 April 2012)
=============================
2012-04-05: olly
[Lua] Add support for Lua 5.2 (patch SF#3514593 from Miles Bader)
2012-04-25: wsfulton
[Lua] Fix uninitialised variable in SWIGTYPE **OUTPUT typemaps as reported by Jim Anderson.
2012-03-26: xavier98
[octave] Apply patch #3425993 from jgillis: add extra logic to the octave_swig_type::dims(void) method: it checks if the user has defined a __dims__ method and uses this in stead of returning (1,1)
[octave] Apply patch #3424833 from jgillis: make is_object return true for swig types
2012-04-28: wsfulton
[Python] Fix compilation errors when wrapping STL containers on Mac OSX and possibly other systems.
2012-03-24: wsfulton
[D] Apply #3502431 to fix duplicate symbols in multiple modules and compiler errors due to lack
of const in some methods taking char*.
2012-03-21: wsfulton
Fix #3494791 - %$isglobal for %rename matching.
2012-03-20: wsfulton
Fix #3487706 and #3391906 - missing stddef.h include for ptrdiff_t when using %import
for STL containers and compiling with g++-4.6. An include of stddef.h is now only
generated when SWIG generates STL helper templates which require ptrdiff_t. If you
were previously relying on "#include <stddef.h>" always being generated when using a
%include of an STL header, you may now need to add this in manually.
2012-03-16: wsfulton
Apply patch #3392264 from Sebastien Bine to parse (unsigned) long long types in enum value assignment.
2012-03-16: wsfulton
Apply patch #3505530 from Karl Wette to allow custom allocators in STL string classes for the UTL languages.
2012-03-13: wsfulton
Apply patch #3468362 from Karl Wette to fix %include inside %define.
2012-03-13: wsfulton
[Python, Ruby, Octave] Fix #3475492 - iterating through std::vector wrappers of enumerations.
2012-02-27: xavier98 (patches from Karl Wette)
[Octave] Use -globals . to load global variables in module namespace
[Octave] Comment declaration of unimplemented function swig_register_director
[Octave] Fix OCTAVE_PATH in octave Makefiles
[Octave] Add support for nspace feature - fix director_nspace test
[Octave] Add support for std::list - fix li_std_containers_int test
[Octave] Fix imports test
2012-02-16: wsfulton
[Java] Make generated support functions in arrays_java.i static so that generated code
from multiple instances of SWIG can be compiled and linked together - problem reported by
Evan Krause.
2012-01-24: wsfulton
Fix crash with bad regex - bug #3474250.
2012-01-24: wsfulton
[Python] Add Python stepped slicing support to the STL wrappers (std::vector, std::list).
Assigning to a slice, reading a slice and deleting a slice with steps now work.
For example:
%template(vector_i) std::vector<int>
vi = vector_i(range(10))
print list(vi)
vi[1:4:2] = [111, 333]
print list(vi)
del vi[3:10:3]
print list(vi)
print list(vi[::-1])
gives (same behaviour as native Python sequences such as list):
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 111, 2, 333, 4, 5, 6, 7, 8, 9]
[0, 111, 2, 4, 5, 7, 8]
[8, 7, 5, 4, 2, 111, 0]
2012-01-23: klickverbot
[D] Correctly annotate function pointers with C linkage.
[D] Exception and Error have become blessed names; removed d_exception_name test case.
2012-01-20: wsfulton
[Python] Fix some indexing bugs in Python STL wrappers when the index is negative, eg:
%template(vector_i) std::vector<int>
iv=vector_i([0,1,2,3,4,5])
iv[-7:]
now returns [0, 1, 2, 3, 4, 5] instead of [5].
vv[7:9] = [22,33]
now returns [0, 1, 2, 3, 4, 5, 22, 33] instead of "index out range" error.
Also fix some segfaults when replacing ranges, eg when il is a std::list wrapper:
il[0:2] = [11]
2012-01-17: wsfulton
[Go] Fix forward class declaration within a class when used as a base.
2012-01-07: wsfulton
[C#] Add support for %nspace when using directors.
2012-01-06: wsfulton
[Java] Patch #3452560 from Brant Kyser - add support for %nspace when using directors.
2011-12-21: wsfulton
The 'directorin' typemap now accepts $1, $2 etc expansions instead of having to use workarounds -
$1_name, $2_name etc.
2011-12-20: wsfulton
[Java] Add (char *STRING, size_t LENGTH) director typemaps.
2011-12-20: wsfulton
[C#, Go, Java, D] Add support for the 'directorargout' typemap.
2011-12-20: wsfulton
[Ocaml, Octave, PHP, Python, Ruby] Correct special variables in 'directorargout' typemap.
This change will break any 'directorargout' typemaps you may have written. Please change:
$result to $1
$input to $result
Also fix the named 'directorargout' DIRECTOROUT typemaps for these languages which didn't
previously compile and add in $1, $2 etc expansion.
*** POTENTIAL INCOMPATIBILITY ***
2011-12-10: talby
[perl5] SWIG_error() now gets decorated with perl source file/line number.
[perl5] error handling now conforms to public XS api (fixes perl v5.14 issue).
2011-12-10: wsfulton
[Android/Java] Fix directors to compile on Android.
Added documentation and examples for Android.
2011-12-08: vadz
Bug fix: Handle methods renamed or ignored in the base class correctly in the derived classes
(they could be sometimes mysteriously not renamed or ignored there before).
2011-12-03: klickverbot
[D] Fix exception glue code for newer DMD 2 versions.
[D] Do not default to 32 bit glue code for DMD anymore.
[D] Use stdc.config.c_long/c_ulong to represent C long types.
2011-12-01: szager
[python] Fixed bug 3447426: memory leak in vector.__getitem__.
2011-11-30: wsfulton
[R] Remove C++ comments from generated C code.
2011-11-27: olly
[Python] Fix some warnings when compiling generated wrappers with
certain GCC warning options (Debian bug #650246).
2011-11-28: wsfulton
Fix #3433541 %typemap(in, numinputs=0) with 10+ arguments.
2011-11-28: olly
[Perl] Fix warnings when compiling generated wrappers with certain
GCC warning options (Debian bug #436711).
2011-11-28: olly
[PHP] Update keyword list to include keywords added in PHP releases up to 5.3.
2011-11-25: wsfulton
[C#] Provide an easy way to override the default visibility for the proxy class pointer
constructors and getCPtr() method. The visibility is 'internal' by default and if multiple
SWIG modules are being used and compiled into different assemblies, then they need to be
'public' in order to use the constructor or getCPtr() method from a different assembly.
Use the following macros to change the visibilities in the proxy and type wrapper class:
SWIG_CSBODY_PROXY(public, public, SWIGTYPE)
SWIG_CSBODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
[Java] Provide an easy way to override the default visibility for the proxy class pointer
constructors and getCPtr() method. The visibility is 'protected' by default and if multiple
SWIG modules are being used and compiled into different packages, then they need to be
'public' in order to use the constructor or getCPtr() method from a different package.
Use the following macros to change the visibilities in the proxy and type wrapper class:
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
SWIG_JAVABODY_TYPEWRAPPER(public, public, public, SWIGTYPE)
The default for Java has changed from public to protected for the proxy classes. Use the
SWIG_JAVABODY_PROXY macro above to restore to the previous visibilities.
*** POTENTIAL INCOMPATIBILITY ***
2011-11-22: szager
[python] Bug 3440044: #ifdef out SWIG_Python_NonDynamicSetAttr if -builtin
isn't being used, to avoid unnecessary binary incompatibilities between
python installations.
2011-11-17: wsfulton
Bug fix: Remove root directory from directory search list in Windows.
2011-11-13: wsfulton
[Ruby] Apply patch #3421876 from Robin Stocker to fix #3416818 - same class name in
different namespaces confusion when using multiple modules.
2011-11-11: wsfulton
Fix pcre-build.sh to work with non-compressed tarballs - problem reported by Adrian Blakely.
2011-11-04: szager
[python] Bug 3429388: python unsigned integer handling on 32-bit architectures.
2011-11-03: wsfulton
Expand special variables in typemap warnings, eg:
%typemap(in, warning="1000:Test warning for 'in' typemap for $1_type $1_name") int "..."
2011-11-01: wsfulton
Fix named output typemaps not being used when the symbol uses a qualifier and contains
a number, eg:
%typemap(out) double ABC::m1 "..."
2011-10-24: talby
[perl5] SF bug #3423119 - overload dispatch stack corruption fix. Better, but more research
is needed on a stable path for tail calls in XS.
Also, fix for large long longs in 32 bit perl.
2011-10-13: xavier98
[octave] Allow Octave modules to be re-loaded after a "clear all".
2011-09-19: wsfulton
Fix regression introduced in swig-2.0.1 reported by Teemu Ikonone leading to uncompilable code
when using typedef and function pointer references, for example:
typedef int FN(const int &a, int b);
void *typedef_call1(FN *& precallback, FN * postcallback);
2011-09-14: wsfulton
[Lua] Patch #3408012 from Raman Gopalan - add support for embedded Lua (eLua)
including options for targeting Lua Tiny RAM (LTR).
2011-09-14: wsfulton
[C#] Add boost_intrusive_ptr.i library contribution from patch #3401571.
2011-09-13: wsfulton
Add warnings for badly named destructors, eg:
struct KStruct {
~NOT_KStruct() {}
};
cpp_extend_destructors.i:92: Warning 521: Illegal destructor name ~NOT_KStruct. Ignored.
2011-09-13: wsfulton
Fix %extend and destructors for templates. The destructor in %extend was not always wrapped,
for example:
%extend FooT {
~FooT() { delete $self; } // was not wrapped as expected
};
template<class T> class FooT {};
%template(FooTi) FooT<int>;
2011-09-13: wsfulton
Fix special variables such as "$decl" and "$fulldecl" in destructors to include the ~ character.
2011-09-10: talby
[perl5] SF bug #1481958 - Improve range checking for integer types.
Enhance li_typemaps_runme.pl
2011-09-08: wsfulton
Fix %extend on typedef classes in a namespace using the typedef name, for example:
namespace Space {
%extend CStruct {
...
}
typedef struct tagCStruct { ... } CStruct;
}
2011-08-31: xavier98
[octave] patches from Karl Wette: improvements to module loading behavior;
added example of friend operator to operator example; fixed octave panic/crash in 3.0.5;
documentation improvements
2011-08-30: szager
[python] Bug 3400486, fix error signalling for built-in constructors.
2011-08-26: wsfulton
[Go] Fix file/line number display for "gotype" when using typemap debugging options
-tmsearch and -tmused.
2011-08-26: wsfulton
[C#, D] Fix %callback which was generating uncompileable code.
2011-08-25: wsfulton
Fix constructors in named typedef class declarations as reported by Gregory Bronner:
typedef struct A {
A(){} // Constructor which was not accepted by SWIG
B(){} // NOT a constructor --illegal, but was accepted by SWIG
} B;
For C code, the fix now results in the use of 'struct A *' instead of just 'B *' in
the generated code when wrapping members in A, but ultimately this does not matter, as
they are the same thing.
2011-08-23: wsfulton
Fix %newobject when used in conjunction with %feature("ref") as reported by Jan Becker. The
code from the "ref" feature was not always being generated for the function specified by %newobject.
Documentation for "ref" and "unref" moved from Python to the C++ chapter.
2011-08-22: szager
[python] Fixed memory leak with --builtin option (bug 3385089).
2011-08-22: wsfulton
[Lua] SF patch #3394339 from Torsten Landschoff - new option -nomoduleglobal to disable installing
the module table into the global namespace. Require call also returns the module table instead
of a string.
2011-08-09: xavier98
Fix bug 3387394; Octave patches for 3.4.0 compatibility, etc. (from Karl Wette)
2011-08-04: wsfulton
Add in $symname expansion for director methods.
2011-07-29: olly
[PHP] Don't generate "return $r;" in cases where $r hasn't been set.
This was basically harmless, except it generated a PHP E_NOTICE if
the calling code had enabled them.
2011-07-26: wsfulton
Fix scoping of forward class declarations nested within a class (for C++). Previously the symbol
was incorrectly put into the outer namespace, eg
namespace std {
template<class Key, class T> struct map {
class iterator;
}
}
iterator was scoped as std::iterator, but now it is correctly std::map<Key, T>::iterator;
Also fixed is %template and template parameters that are a typedef when the template contains
default template parameters, eg:
namespace Std {
template<class Key, class T, class C = int> struct Map {
typedef Key key_type;
typedef T mapped_type;
}
}
tyepdef double DOUBLE;
%typemap(MM) Std::Map<int, DOUBLE>;
All symbols within Map will be resolved correctly, eg key_type and mapped_type no matter if the
wrapped code uses Std::Map<int, double> or std::Map<int, DOUBLE> or Std::Map<int, double, int>
Also fixes bug #3378145 - regression introduced in 2.0.4 - %template using traits.
2011-07-20 szager
[python] Fix closure for tp_call slot.
2011-07-16: wsfulton
[python] Fix director typemap using PyObject *.
2011-07-13: szager
[python] SF patch #3365908 - Add all template parameters to map support code in std_map.i
2011-07-13: szager
[python] Fix for bug 3324753: %rename member variables with -builtin.
2011-07-01: wsfulton
Fix some scope and symbol lookup problems when template default parameters are being
used with typedef. For example:
template<typename XX, typename TT = SomeType> struct Foo {
typedef XX X;
typedef TT T;
};
template<typename TT> struct UsesFoo {
void x(typename Foo<TT>::T, typename Foo<TT>::X);
};
Also fixes use of std::vector<int>::size_type for Python as reported by Aubrey Barnard.
2011-06-23: olly
[PHP] Fix director code to work when PHP is built with ZTS enabled,
which is the standard configuration on Microsoft Windows.
2011-06-21: mutandiz
[allegrocl]
- various small tweaks and bug fixes.
- Avoid name conflicts between smart pointer wrappers and the wrappers for
the actual class.
- Fix default typemaps for C bindings, which were incorrectly attempting to
call non-existent destructors on user-defined types.
- New feature, feature:aclmixins, for adding superclass to the foreign class
wrappers.
- Improve longlong typemaps.
2011-06-19: wsfulton
Fix incorrect typemaps being used for a symbol within a templated type, eg:
A<int>::value_type would incorrectly use a typemap for type A.
2011-06-18: olly
[Tcl] Fix variable declarations in middle of blocks which isn't
permitted in C90 (issue probably introduced in 2.0.3 by patch #3224663).
Reported by Paul Obermeier in SF#3288586.
2011-06-17: wsfulton
[Java] SF #3312505 - slightly easier to wrap char[] or char[ANY] with a Java byte[]
using arrays_java.i.
2011-06-13: wsfulton
[Ruby, Octave] SF #3310528 Autodoc fixes similar to those described below for Python.
2011-06-10: wsfulton
[Python] Few subtle bugfixes in autodoc documentation generation,
- Unnamed argument names fix for autodoc levels > 0.
- Display of template types fixed for autodoc levels > 1.
- Fix SF #3310528 - display of typedef structs for autodoc levels > 1.
- Add missing type for self for autodoc levels 1 and 3.
- autodoc levels 2 and 3 documented.
- Minor tweaks to autodoc style to conform with PEP8.
2011-05-30: olly
[PHP] Fix handling of directors when -prefix is used.
2011-05-24: olly
[PHP] Fix handling of methods of classes with a virtual base class (SF#3124665).
2012-04-28: wsfulton
[Java] Patch 3521811 from Leo Davis - char **STRING_ARRAY typemaps fixed to handle
null pointers.

View file

@ -263,8 +263,11 @@
<li><a href="Preprocessor.html#Preprocessor_nn5">Macro Expansion</a>
<li><a href="Preprocessor.html#Preprocessor_nn6">SWIG Macros</a>
<li><a href="Preprocessor.html#Preprocessor_nn7">C99 and GNU Extensions</a>
<li><a href="Preprocessor.html#Preprocessor_delimiters">Preprocessing and delimiters</a>
<ul>
<li><a href="Preprocessor.html#Preprocessor_nn8">Preprocessing and %{ ... %} &amp; " ... " delimiters</a>
<li><a href="Preprocessor.html#Preprocessor_nn9">Preprocessing and { ... } delimiters</a>
</ul>
<li><a href="Preprocessor.html#Preprocessor_typemap_delimiters">Preprocessor and Typemaps</a>
<li><a href="Preprocessor.html#Preprocessor_nn10">Viewing preprocessor output</a>
<li><a href="Preprocessor.html#Preprocessor_warning_error">The #error and #warning directives</a>

View file

@ -102,8 +102,8 @@ swig -go -help
<tr>
<td>-gccgo-46</td>
<td>Generate code for gccgo 4.6. The default is set by the configure
script.</td> This generates code that does not use some facilities
that are only available in gccgo 4.7 and later.
script. This generates code that does not use some facilities
that are only available in gccgo 4.7 and later.</td>
</tr>
<tr>

View file

@ -67,7 +67,7 @@
<p>
Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight configuration language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++). Its also a <em>really</em> tiny language, less than 6000 lines of code, which compiles to &lt;100 kilobytes of binary code. It can be found at <a href="http://www.lua.org">http://www.lua.org</a>
Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight configuration language for any program that needs one. Lua is implemented as a library, written in clean C (that is, in the common subset of ANSI C and C++). It's also a <em>really</em> tiny language, less than 6000 lines of code, which compiles to &lt;100 kilobytes of binary code. It can be found at <a href="http://www.lua.org">http://www.lua.org</a>
</p>
<p>
eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers the full implementation of the Lua programming language to the embedded world, extending it with specific features for efficient and portable software embedded development. eLua runs on smaller devices like microcontrollers and provides the full features of the regular Lua desktop version. More information on eLua can be found here: <a href="http://www.eluaproject.net">http://www.eluaproject.net</a>
@ -75,12 +75,14 @@ eLua stands for Embedded Lua (can be thought of as a flavor of Lua) and offers t
<H2><a name="Lua_nn2"></a>26.1 Preliminaries</H2>
<p>
The current SWIG implementation is designed to work with Lua 5.0.x, 5.1.x and 5.2.x. It should work with later versions of Lua, but certainly not with Lua 4.0 due to substantial API changes. It is possible to either static link or dynamic link a Lua module into the interpreter (normally Lua static links its libraries, as dynamic linking is not available on all platforms). SWIG also supports eLua and works with eLua 0.8. SWIG generated code for eLua has been tested on Stellaris ARM Cortex-M3 LM3S and Infineon TriCore.
</p>
<H2><a name="Lua_nn3"></a>26.2 Running SWIG</H2>
<p>
Suppose that you defined a SWIG module such as the following:
</p>
@ -108,7 +110,7 @@ $ swig -c++ -lua example.i
This creates a C/C++ source file <tt>example_wrap.c</tt> or <tt>example_wrap.cxx</tt>. The generated C source file contains the low-level wrappers that need to be compiled and linked with the rest of your C/C++ application to create an extension module.
</p>
<p>
The name of the wrapper file is derived from the name of the input file. For example, if the input file is <tt>example.i</tt>, the name of the wrapper file is <tt>example_wrap.c</tt>. To change this, you can use the -o option. The wrappered module will export one function <tt>"int luaopen_example(lua_State* L)"</tt> which must be called to register the module with the Lua interpreter. The name "luaopen_example" depends upon the name of the module.
The name of the wrapper file is derived from the name of the input file. For example, if the input file is <tt>example.i</tt>, the name of the wrapper file is <tt>example_wrap.c</tt>. To change this, you can use the -o option. The wrapped module will export one function <tt>"int luaopen_example(lua_State* L)"</tt> which must be called to register the module with the Lua interpreter. The name "luaopen_example" depends upon the name of the module.
</p>
<p>
To build an eLua module, run SWIG using <tt>-lua</tt> and add either <tt>-elua</tt> or <tt>-eluac</tt>.
@ -183,7 +185,7 @@ int main(int argc,char* argv[])
}
L=lua_open();
luaopen_base(L); // load basic libs (eg. print)
luaopen_example(L); // load the wrappered module
luaopen_example(L); // load the wrapped module
if (luaL_loadfile(L,argv[1])==0) // load and run the file
lua_pcall(L,0,0,0);
else
@ -216,8 +218,7 @@ For eLua, the source must be built along with the wrappers generated by SWIG. Ma
_ROM( AUXLIB_MOD, luaopen_mod, mod_map )\
....
</pre></div>
<p>
</p>
<div class="code"><pre>
/* Sample auxmods.h */
#define AUXLIB_PIO "pio"
@ -276,10 +277,10 @@ print(a,b,c)
</pre></div>
<p>
Note: for Lua 5.0:<br>
The loadlib() function is in the global namespace, not in package. So its just loadlib().
The loadlib() function is in the global namespace, not in a package. So it's just loadlib().
</p>
<p>
if 'a' is a function, this its all working fine, all you need to do is call it
if 'a' is a function, this is all working fine, all you need to do is call it
</p>
<div class="targetlang"><pre>
a()
@ -288,7 +289,7 @@ if 'a' is a function, this its all working fine, all you need to do is call it
to load your library which will add a table 'example' with all the functions added.
</p>
<p>
If it doesn't work, look at the error messages, in particular mesage 'b'<br>
If it doesn't work, look at the error messages, in particular message 'b'<br>
<tt> The specified module could not be found.</tt><br>
Means that is cannot find the module, check your the location and spelling of the module.<br>
<tt> The specified procedure could not be found.</tt><br>
@ -393,7 +394,7 @@ SWIG will effectively generate two functions <tt>example.Foo_set()</tt> and <tt>
4 5
</pre></div>
<p>
Its is therefore not possible to 'move' the global variable into the global namespace as it is with functions. It is however, possible to rename the module with an assignment, to make it more convenient.
It is therefore not possible to 'move' the global variable into the global namespace as it is with functions. It is however, possible to rename the module with an assignment, to make it more convenient.
</p>
<div class="targetlang"><pre>
&gt; e=example
@ -404,7 +405,7 @@ Its is therefore not possible to 'move' the global variable into the global name
4
</pre></div>
<p>
If a variable is marked with the %immutable directive then any attempts to set this variable will cause an Lua error. Given a global variable:
If a variable is marked with the %immutable directive then any attempts to set this variable will cause a Lua error. Given a global variable:
</p>
<div class="code"><pre>%module example
@ -510,13 +511,13 @@ When wrapped, you will be able to use the functions in a natural way from Lua. F
&gt; example.fclose(f)
</pre></div>
<p>
Unlike many scripting languages, Lua has had support for pointers to C/C++ object built in for a long time. They are called 'userdata'. Unlike many other SWIG versions which use some kind of encoded character string, all objects will be represented as a userdata. The SWIG-Lua bindings provides a special function <tt>swig_type()</tt>, which if given a userdata object will return the type of object pointed to as a string (assuming it was a SWIG wrappered object).
Unlike many scripting languages, Lua has had support for pointers to C/C++ object built in for a long time. They are called 'userdata'. Unlike many other SWIG versions which use some kind of encoded character string, all objects will be represented as a userdata. The SWIG-Lua bindings provides a special function <tt>swig_type()</tt>, which if given a userdata object will return the type of object pointed to as a string (assuming it was a SWIG wrapped object).
</p>
<div class="targetlang"><pre>
&gt; print(f)
userdata: 003FDA80
&gt; print(swig_type(f))
FILE * -- its a FILE*
FILE * -- it's a FILE*
</pre></div>
<p>
Lua enforces the integrity of its userdata, so it is virtually impossible to corrupt the data. But as the user of the pointer, you are responsible for freeing it, or closing any resources associated with it (just as you would in a C program). This does not apply so strictly to classes &amp; structs (see below). One final note: if a function returns a NULL pointer, this is not encoded as a userdata, but as a Lua nil.
@ -560,10 +561,10 @@ If you print out the value of p in the above example, you will see something lik
userdata: 003FA320
</pre></div>
<p>
Like the pointer in the previous section, this is held as a userdata. However, additional features have been added to make this more usable. SWIG effectivly creates some accessor/mutator functions to get and set the data. These functions will be added to the userdata's metatable. This provides the natural access to the member variables that were shown above (see end of the document for full details).
Like the pointer in the previous section, this is held as a userdata. However, additional features have been added to make this more usable. SWIG effectively creates some accessor/mutator functions to get and set the data. These functions will be added to the userdata's metatable. This provides the natural access to the member variables that were shown above (see end of the document for full details).
</p>
<p>
<tt>const</tt> members of a structure are read-only. Data members can also be forced to be read-only using the immutable directive. As with other immutable's, setting attempts will be cause an error. For example:
<tt>const</tt> members of a structure are read-only. Data members can also be forced to be read-only using the immutable directive. As with other immutables, setting attempts will be cause an error. For example:
</p>
<div class="code"><pre>struct Foo {
...
@ -686,7 +687,7 @@ In Lua, the static members can be accessed as follows:
It is not (currently) possible to access static members of an instance:
</p>
<div class="targetlang"><pre>
&gt; s=example.Spam() -- s is a Spam instance
&gt; s=example.Spam() -- s is a Spam instance
&gt; s.foo() -- Spam::foo() via an instance
-- does NOT work
</pre></div>
@ -1183,7 +1184,7 @@ void throw_A() throw(A*) {
}
</pre></div>
<p>
SWIG will just convert it (poorly) to a string and use that as its error. (This is not that useful, but it always works).
SWIG will just convert it (poorly) to a string and use that as its error. (This is not that useful, but it always works).
</p>
<div class="targetlang"><pre>
@ -1259,7 +1260,7 @@ add exception specification to functions or globally (respectively).
<H2><a name="Lua_nn24"></a>26.4 Typemaps</H2>
<p>This section explains what typemaps are and the usage of them. The default wrapping behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrapping. This section will be explaining how to use typemaps to best effect</p>
<p>This section explains what typemaps are and how to use them. The default wrapping behaviour of SWIG is enough in most cases. However sometimes SWIG may need a little additional assistance to know which typemap to apply to provide the best wrapping. This section will be explaining how to use typemaps to best effect</p>
<H3><a name="Lua_nn25"></a>26.4.1 What is a typemap?</H3>
@ -1355,8 +1356,8 @@ extern void sort_double(double* arr, int len);
</pre></div>
<p>There are basically two ways that SWIG can deal with this. The first way, uses the <tt>&lt;carrays.i&gt;</tt> library
to create an array in C/C++ then this can be filled within Lua and passed into the function. It works, but its a bit tedious.
More details can be found in the <a href="Library.html#Library_carrays">carrays.i</a> documention.</p>
to create an array in C/C++ then this can be filled within Lua and passed into the function. It works, but it's a bit tedious.
More details can be found in the <a href="Library.html#Library_carrays">carrays.i</a> documentation.</p>
<p>The second and more intuitive way, would be to pass a Lua table directly into the function, and have SWIG automatically convert between Lua-table and C-array. Within the <tt>&lt;typemaps.i&gt;</tt> file there are typemaps ready written to perform this task. To use them is again a matter of using %appy in the correct manner.</p>
@ -1376,7 +1377,7 @@ extern void sort_int(int* arr, int len); // the function to wrap
extern void sort_double(double* arr, int len); // the function to wrap
</pre></div>
<p>Once wrappered, the functions can both be called, though with different ease of use:</p>
<p>Once wrapped, the functions can both be called, though with different ease of use:</p>
<div class="targetlang"><pre>require "example"
ARRAY_SIZE=10
@ -1428,7 +1429,7 @@ free(ptr); // dispose of iMath
<p>SWIG has a ready written typemap to deal with such a kind of function in &lt;typemaps.i&gt;. It provides the correct wrapping as well as setting the flag to inform Lua that the object in question should be garbage collected. Therefore the code is simply:</p>
<div class="code"><pre>%include &lt;typemaps.i&gt;
%apply SWIGTYPE** OUTPUT{iMath **pptr }; // tell SWIG its an output
%apply SWIGTYPE** OUTPUT{iMath **pptr }; // tell SWIG it's an output
struct iMath; // some structure
int Create_Math(iMath** pptr); // its creator (assume it mallocs)
@ -1436,7 +1437,7 @@ int Create_Math(iMath** pptr); // its creator (assume it mallocs)
<p>The usage is as follows:</p>
<div class="targetlang"><pre>ok,ptr=Create_Math() -- ptr is a iMath* which is returned with the int (ok)
<div class="targetlang"><pre>ok,ptr=Create_Math() -- ptr is an iMath* which is returned with the int (ok)
ptr=nil -- the iMath* will be GC'ed as normal
</pre></div>
@ -1447,7 +1448,7 @@ ptr=nil -- the iMath* will be GC'ed as normal
<p>Before proceeding, it should be stressed that writing typemaps is rarely needed unless you want to change some aspect of the wrapping, or to achieve an effect which in not available with the default bindings.</p>
<p>Before proceeding, you should read the previous section on using typemaps, as well as read the ready written typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you a idea to base your worn on).</p>
<p>Before proceeding, you should read the previous section on using typemaps, and look at the existing typemaps found in luatypemaps.swg and typemaps.i. These are both well documented and fairly easy to read. You should not attempt to write your own typemaps until you have read and can understand both of these files (they may well also give you an idea to base your work on).</p>
<H3><a name="Lua_nn30"></a>26.5.1 Typemaps you can write</H3>
@ -1543,7 +1544,7 @@ The <tt>%native</tt> directive in the above example, tells SWIG that there is a
<p>
As well as adding additional C/C++ code, its also possible to add your own Lua code to the module as well.
As well as adding additional C/C++ code, it's also possible to add your own Lua code to the module as well.
This code is executed once all other initialisation, including the %init code has been called.
</p>
<p>
@ -1568,7 +1569,7 @@ module name added.
</p>
<p>
Should there be an error in the Lua code, this will <em>not</em> stop loading of the module.
The default behaviour of SWIG is to print a error message to stderr and then continue.
The default behaviour of SWIG is to print an error message to stderr and then continue.
It is possible to change this behaviour by using a <tt>#define SWIG_DOSTRING_FAIL(STR)</tt> to
define a different behaviour should the code fail.
</p>
@ -1655,7 +1656,7 @@ That way when you call '<tt>a=example.Foo</tt>', the interpreter looks at the ta
As mentioned earlier, classes and structures, are all held as pointer, using the Lua 'userdata' structure. This structure is actually a pointer to a C structure 'swig_lua_userdata', which contains the pointer to the data, a pointer to the swig_type_info (an internal SWIG struct) and a flag which marks if the object is to be disposed of when the interpreter no longer needs it. The actual accessing of the object is done via the metatable attached to this userdata.
</p>
<p>
The metatable is a Lua 5.0 feature (which is also why SWIG cannot wrap Lua 4.0). Its a table which holds a list of functions, operators and attributes. This is what gives the userdata the feeling that it is a real object and not just a hunk of memory.
The metatable is a Lua 5.0 feature (which is also why SWIG cannot wrap Lua 4.0). It's a table which holds a list of functions, operators and attributes. This is what gives the userdata the feeling that it is a real object and not just a hunk of memory.
</p>
<p>
Given a class
@ -1672,10 +1673,10 @@ public:
};
</pre></div>
<p>
SWIG will create a module excpp, with all the various function inside. However to allow the intuitive use of the userdata is also creates up a set of metatables. As seen in the above section on global variables, use of the metatables allows for wrappers to be used intuitively. To save effort, the code creates one metatable per class and stores it inside Lua's registry. Then when an new object is instantiated, the metatable is found in the registry and the userdata associated to the metatable. Currently derived classes make a complete copy of the base classes table and then add on their own additional function.
SWIG will create a module excpp, with all the various functions inside. However to allow the intuitive use of the userdata, SWIG also creates up a set of metatables. As seen in the above section on global variables, use of the metatables allows for wrappers to be used intuitively. To save effort, the code creates one metatable per class and stores it inside Lua's registry. Then when a new object is instantiated, the metatable is found in the registry and the userdata associated with the metatable. Currently, derived classes make a complete copy of the base class' table and then add on their own additional functions.
</p>
<p>
Some of the internals can be seen by looking at a classes metatable.
Some of the internals can be seen by looking at the metatable of a class:
</p>
<div class="targetlang"><pre>
&gt; p=excpp.Point()
@ -1692,7 +1693,7 @@ __index function: 003FB698
.fn table: 003FB528
</pre></div>
<p>
The '.type' attribute is the name of the class. The '.get' and '.set' tables work in a similar manner to the modules, the main difference is the '.fn' table which also holds all the member functions. (The '__gc' function is the classes destructor function)
The '.type' attribute is the name of the class. The '.get' and '.set' tables work in a similar manner to the modules, the main difference is the '.fn' table which also holds all the member functions. (The '__gc' function is the class' destructor function)
</p>
<p>
The Lua equivalent of the code for enabling functions looks a little like this
@ -1706,7 +1707,7 @@ function __index(obj,name)
local f=g[name] -- looks for the get_attribute function
-- calls it &amp; returns the value
if type(f)=="function" then return f() end
-- ok, so it not an attribute, maybe its a function
-- ok, so it not an attribute, maybe it's a function
local fn=m['.fn'] -- gets the function table
if not fn then return nil end
local f=fn[name] -- looks for the function
@ -1726,7 +1727,7 @@ In theory, you can play with this usertable &amp; add new features, but remember
Note: Both the opaque structures (like the FILE*) and normal wrapped classes/structs use the same 'swig_lua_userdata' structure. Though the opaque structures has do not have a metatable attached, or any information on how to dispose of them when the interpreter has finished with them.
</p>
<p>
Note: Operator overloads are basically done in the same way, by adding functions such as '__add' &amp; '__call' to the classes metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.
Note: Operator overloads are basically done in the same way, by adding functions such as '__add' &amp; '__call' to the class' metatable. The current implementation is a bit rough as it will add any member function beginning with '__' into the metatable too, assuming its an operator overload.
</p>
<H3><a name="Lua_nn38"></a>26.7.3 Memory management</H3>
@ -1738,7 +1739,7 @@ Lua is very helpful with the memory management. The 'swig_lua_userdata' is fully
It is currently not recommended to edit this field or add some user code, to change the behaviour. Though for those who wish to try, here is where to look.
</p>
<p>
It is also currently not possible to change the ownership flag on the data (unlike most other scripting languages, Lua does not permit access to the data from within the interpreter)
It is also currently not possible to change the ownership flag on the data (unlike most other scripting languages, Lua does not permit access to the data from within the interpreter).
</p>
</body>
</html>

View file

@ -16,8 +16,11 @@
<li><a href="#Preprocessor_nn5">Macro Expansion</a>
<li><a href="#Preprocessor_nn6">SWIG Macros</a>
<li><a href="#Preprocessor_nn7">C99 and GNU Extensions</a>
<li><a href="#Preprocessor_delimiters">Preprocessing and delimiters</a>
<ul>
<li><a href="#Preprocessor_nn8">Preprocessing and %{ ... %} &amp; " ... " delimiters</a>
<li><a href="#Preprocessor_nn9">Preprocessing and { ... } delimiters</a>
</ul>
<li><a href="#Preprocessor_typemap_delimiters">Preprocessor and Typemaps</a>
<li><a href="#Preprocessor_nn10">Viewing preprocessor output</a>
<li><a href="#Preprocessor_warning_error">The #error and #warning directives</a>
@ -306,7 +309,14 @@ interface building. However, they are used internally to implement a number of
SWIG directives and are provided to make SWIG more compatible with C99 code.
</p>
<H2><a name="Preprocessor_nn8"></a>7.7 Preprocessing and %{ ... %} &amp; " ... " delimiters</H2>
<H2><a name="Preprocessor_delimiters"></a>7.7 Preprocessing and delimiters</H2>
<p>
The preprocessor handles { }, " " and %{ %} delimiters differently.
</p>
<H3><a name="Preprocessor_nn8"></a>7.7.1 Preprocessing and %{ ... %} &amp; " ... " delimiters</H3>
<p>
@ -331,7 +341,7 @@ the contents of the <tt>%{ ... %}</tt> block are copied without
modification to the output (including all preprocessor directives).
</p>
<H2><a name="Preprocessor_nn9"></a>7.8 Preprocessing and { ... } delimiters</H2>
<H3><a name="Preprocessor_nn9"></a>7.7.2 Preprocessing and { ... } delimiters</H3>
<p>
@ -373,7 +383,7 @@ to actually go into the wrapper file, prefix the preprocessor directives with <t
SWIG will strip the extra <tt>%</tt> and leave the preprocessor directive in the code.
</p>
<H2><a name="Preprocessor_typemap_delimiters"></a>7.9 Preprocessor and Typemaps</H2>
<H2><a name="Preprocessor_typemap_delimiters"></a>7.8 Preprocessor and Typemaps</H2>
<p>
@ -444,7 +454,7 @@ would generate
</div>
<H2><a name="Preprocessor_nn10"></a>7.10 Viewing preprocessor output</H2>
<H2><a name="Preprocessor_nn10"></a>7.9 Viewing preprocessor output</H2>
<p>
@ -454,7 +464,7 @@ Instead the results after the preprocessor has run are displayed.
This might be useful as an aid to debugging and viewing the results of macro expansions.
</p>
<H2><a name="Preprocessor_warning_error"></a>7.11 The #error and #warning directives</H2>
<H2><a name="Preprocessor_warning_error"></a>7.10 The #error and #warning directives</H2>
<p>

View file

@ -6,7 +6,7 @@
<body bgcolor="#ffffff">
<H1><a name="Sections"></a>SWIG-2.0 Documentation</H1>
Last update : SWIG-2.0.5 (in progress)
Last update : SWIG-2.0.6 (30 April 2012)
<H2>Sections</H2>

View file

@ -3673,17 +3673,21 @@ generated into the wrapper code before any typemap code that calls it.
<p>
To define a fragment you need a fragment name, a section name for generating the fragment code into, and the code itself.
See <a href="SWIG.html#SWIG_nn42">Code insertion blocks</a> for a full list of section names.
Usually the section name used is "header". Both string and curly braces can be used:
Usually the section name used is "header". Different delimiters can be used:
</p>
<div class="code">
<pre>
%fragment("my_name", "header") %{ ... %}
%fragment("my_name", "header") { ... }
%fragment("my_name", "header") " ... "
</pre>
</div>
<p>
and these follow the usual preprocessing rules mentioned in the
<a href="Preprocessor.html#Preprocessor_delimiters">Preprocessing delimiters</a>
section.
The following are some rules and guidelines for using fragments:
</p>
@ -3761,8 +3765,8 @@ A fragment can use one or more additional fragments, for example:
<div class="code">
<pre>
%fragment("&lt;limits.h&gt;", "header") {
#include &lt;limits.h&gt;
%fragment("&lt;limits.h&gt;", "header") {
%#include &lt;limits.h&gt;
}

View file

@ -1142,20 +1142,21 @@ R_CFLAGS=-fPIC
# need to compile .cxx files outside of R build system to make sure that
# we get -fPIC
# CMD SHLIB stdout is piped to /dev/null to prevent echo of compiler command
r: $(SRCS)
$(SWIG) -r $(SWIGOPT) $(INTERFACEPATH)
ifneq ($(SRCS),)
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(SRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) )
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(ISRCS) $(OBJS) > /dev/null )
r_cpp: $(CXXSRCS)
$(SWIG) -c++ -r $(SWIGOPT) -o $(RCXXSRCS) $(INTERFACEPATH)
ifneq ($(CXXSRCS),)
$(CXX) -g -c $(CFLAGS) $(R_CFLAGS) $(CXXSRCS) $(INCLUDES)
endif
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) )
+( PKG_CPPFLAGS="$(INCLUDES)" $(COMPILETOOL) $(R) CMD SHLIB -o $(LIBPREFIX)$(TARGET)$(SO) $(RCXXSRCS) $(OBJS) > /dev/null )
r_clean:
rm -f *_wrap* *~ .~*

View file

@ -277,6 +277,7 @@ CPP_TEST_CASES += \
operbool \
ordering \
overload_copy \
overload_method \
overload_extend \
overload_rename \
overload_return_type \
@ -466,7 +467,6 @@ CPP_STD_TEST_CASES += \
director_string \
ignore_template_constructor \
li_std_combinations \
li_std_containers_int \
li_std_deque \
li_std_except \
li_std_map \

View file

@ -29,12 +29,12 @@ public:
void delCallback() { delete _callback; _callback = 0; }
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
int call() {
int sum = 0;
if (_callback) {
char* aa = (char*)malloc(BUFFER_SIZE_AA);
memset(aa, 9, BUFFER_SIZE_AA);
char* bb = (char*)malloc(BUFFER_SIZE_BB);
memset(bb, 13, BUFFER_SIZE_BB);
int sum = 0;
_callback->run(aa, BUFFER_SIZE_AA, bb, BUFFER_SIZE_BB);
for (int i = 0; i < BUFFER_SIZE_AA; i++)
sum += aa[i];
@ -42,8 +42,8 @@ public:
sum += bb[i];
free(aa);
free(bb);
return sum;
}
return sum;
}
};

View file

@ -36,8 +36,13 @@ namespace Bar
%include <std_string.i>
// nspace feature only supported by these languages
#if defined(SWIGJAVA) || defined(SWIGCSHARP) || defined(SWIGD)
%nspace Bar::Foo;
%nspace Bar::FooBar;
#else
#warning nspace feature not yet supported in this target language
#endif
%feature("director") Bar::Foo;

View file

@ -42,6 +42,12 @@
_a = disown;
return 5;
}
int remove(A *remove)
{
delete remove;
return 5;
}
};
}

View file

@ -45,6 +45,11 @@ public class java_lib_various_runme {
if ( !langs[i].equals(newLangs[i]) )
throw new RuntimeException("Languages verify failed " + i + " " + langs[i] + "|" + newLangs[i]);
// STRING_ARRAY null
java_lib_various.setLanguages(null);
if (java_lib_various.getLanguages() != null)
throw new RuntimeException("languages should be null");
// STRING_RET test
{
String stringOutArray[] = { "" };

View file

@ -12,3 +12,9 @@ for x=0,100 do
b:acquire(a)
end
collectgarbage() -- this will double delete unless the memory is managed properly
a=disown.A()
a:__disown()
b:remove(a)
a=nil
collectgarbage() -- this will double delete unless the manual disown call worked

View file

@ -0,0 +1,16 @@
require("import") -- the import fn
import("li_factory") -- import code
-- moving to global
for k,v in pairs(li_factory) do _G[k]=v end
-- catch "undefined" global variables
setmetatable(getfenv(),{__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
circle = Geometry_create(Geometry_CIRCLE)
r = circle:radius()
assert(r == 1.5)
point = Geometry_create(Geometry_POINT)
w = point:width()
assert(w == 1.0)

View file

@ -103,5 +103,7 @@ struct GlobalClass {
void test_classes(Outer::SomeClass c, Outer::Inner2::Color cc) {}
%}
#else
#warning nspace feature not yet supported in this target language
#endif

View file

@ -49,5 +49,7 @@ namespace Outer {
const Outer::Inner2::Color& col2c) {}
}
#else
#warning nspace feature not yet supported in this target language
#endif

View file

@ -127,7 +127,7 @@ public:
class Baz5 {
public:
Array<octave_idx_type> __dims__() const {
Array<octave_idx_type> c(2,1);
Array<octave_idx_type> c(dim_vector(2,1));
c(0) = 3;
c(1) = 4;
return c;
@ -137,7 +137,7 @@ public:
class Baz6 {
public:
Array<octave_idx_type> __dims__() const {
Array<octave_idx_type> c(1,2);
Array<octave_idx_type> c(dim_vector(1,2));
c(0) = 3;
c(1) = 4;
return c;

View file

@ -1,5 +1,11 @@
%module operator_pointer_ref
%{
#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
%}
%rename(AsCharStarRef) operator char*&;
%inline %{

View file

@ -0,0 +1,20 @@
/* This test confirms the fix to sourceforge bug #3478922 for R */
%module overload_method
%inline %{
class Base
{
public:
Base() : x(42) {}
int method() const { return x; }
void overloaded_method(int aArg) { x = aArg; }
int overloaded_method() const { return x; }
private:
int x;
};
%}

View file

@ -1,99 +1,74 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 631;
use Test::More tests => 415;
BEGIN { use_ok('li_typemaps') }
require_ok('li_typemaps');
my @tests = qw(
in inr
out outr
inout inoutr
);
sub should_pass { my($type, @values) = @_;
# verify that each value passes cleanly
for my $test (@tests) {
my $name = "${test}_${type}";
my $func = li_typemaps->can($name);
for my $val (@values) {
my $rv = eval { $func->($val) };
is($rv, $val, "$name $val");
sub batch { my($type, @values) = @_;
# this is a little ugly because I'm trying to be clever and save my
# wrists from hammering out all these tests.
for my $val (@values) {
for my $tst (qw(
in inr
out outr
inout inoutr
)) {
my $func = $tst . '_' . $type;
is(eval { li_typemaps->can($func)->($val) }, $val, "$func $val");
if($@) {
my $err = $@;
$err =~ s/^/#\$\@# /mg;
print $err;
}
}
}
}
sub should_fail { my($type, @values) = @_;
# verify that all values trigger runtime errors
for my $test (@tests) {
my $name = "${test}_${type}";
my $func = li_typemaps->can($name);
for my $val (@values) {
my $rv = eval { $func->($val) };
like($@, qr/\b(?:Overflow|Type)Error\b/, "overflow $name $val");
}
}
}
batch('bool', '', 1);
# let's assume we're at least on a 32 bit machine
batch('int', -0x80000000, -1, 0, 1, 12, 0x7fffffff);
# long could be bigger, but it's at least this big
batch('long', -0x80000000, -1, 0, 1, 12, 0x7fffffff);
batch('short', -0x8000, -1, 0, 1, 12, 0x7fff);
batch('uint', 0, 1, 12, 0xffffffff);
batch('ushort', 0, 1, 12, 0xffff);
batch('ulong', 0, 1, 12, 0xffffffff);
batch('uchar', 0, 1, 12, 0xff);
batch('schar', -0x80, 0, 1, 12, 0x7f);
sub pad { my($t, $s, $f) = @_;
my $nbytes = length pack $t, 0;
return unpack $t, $s . ($f x ($nbytes - 1));
{
use Math::BigInt qw();
# the pack dance is to get plain old NVs out of the
# Math::BigInt objects.
my $inf = unpack 'd', pack 'd', Math::BigInt->binf();
my $nan = unpack 'd', pack 'd', Math::BigInt->bnan();
batch('float',
-(2 - 2 ** -23) * 2 ** 127,
-1, -2 ** -149, 0, 2 ** -149, 1,
(2 - 2 ** -23) * 2 ** 127,
$nan);
{ local $TODO = "float typemaps don't pass infinity";
# it seems as though SWIG is unwilling to pass infinity around
# because that value always fails bounds checking. I think that
# is a bug.
batch('float', $inf);
}
batch('double',
-(2 - 2 ** -53) ** 1023,
-1, -2 ** -1074, 0, 2 ** 1074,
(2 - 2 ** -53) ** 1023,
$nan, $inf);
}
# some edge case values:
my $nan = unpack 'f>', "\x7f\xc0\x00\x00";
my $inf = unpack 'f>', "\x7f\x80\x00\x00";
my $char_min = pad 'c', "\x80";
my $char_max = pad 'c', "\x7f";
my $char_umax = pad 'C', "\xff";
my $short_min = pad 's!>', "\x80", "\x00";
my $short_max = pad 's!>', "\x7f", "\xff";
my $short_umax = pad 'S!>', "\xff", "\xff";
my $int_min = pad 'i!>', "\x80", "\x00";
my $int_max = pad 'i!>', "\x7f", "\xff";
my $int_umax = pad 'I!>', "\xff", "\xff";
my $long_min = pad 'l!>', "\x80", "\x00";
my $long_max = pad 'l!>', "\x7f", "\xff";
my $long_umax = pad 'L!>', "\xff", "\xff";
should_pass('bool', '', 1);
should_pass('int', $int_min, -1, 0, 1, 12, $int_max);
should_fail('int', $int_min - 1000, $int_max + 1000, $inf, $nan);
should_pass('long', $long_min, -1, 0, 1, 12, $long_max);
should_fail('long', $long_min - 8000, $long_max + 8000, $inf, $nan);
should_pass('short', $short_min, -1, 0, 1, 12, $short_max);
should_fail('short', $short_min - 1, $short_max + 1, $inf, $nan);
should_pass('uint', 0, 1, 12, $int_umax);
should_fail('uint', -1, $int_umax + 1000, $inf, $nan);
should_pass('ushort', 0, 1, 12, $short_umax);
should_fail('ushort', -1, $short_umax + 1, $inf, $nan);
should_pass('ulong', 0, 1, 12, $long_umax);
should_fail('ulong', -1, $long_umax + 8000, $inf, $nan);
should_pass('uchar', 0, 1, 12, $char_umax);
should_fail('uchar', -1, $char_umax + 1, $inf, $nan);
should_pass('schar', $char_min, -1, 0, 1, 12, $char_max);
should_fail('schar', $char_min - 1, $char_max + 1, $inf, $nan);
should_pass('float', -1, 0, 1, $nan);
TODO: {
local $TODO = "typemaps don't allow float infinity";
should_pass('float', -$inf, $inf);
}
should_pass('double', -$inf, -1, 0, 1, $inf, $nan);
should_pass('longlong', -1, 0, 1, 12);
should_fail('longlong', $inf, $nan);
should_pass('ulonglong', 0, 1, 12);
should_fail('ulonglong', -1, $inf, $nan);
batch('longlong', -1, 0, 1, 12);
batch('ulonglong', 0, 1, 12);
SKIP: {
my $llong_min = eval { pad 'q>', "\x80", "\x00" };
my $llong_max = eval { pad 'q>', "\x7f", "\xff" };
my $llong_umax = eval { pad 'Q>', "\xff", "\xff" };
skip 'not a 64 bit perl', 6 * 6 unless defined $llong_min;
should_pass('longlong', $llong_min, $llong_max);
should_fail('longlong', $llong_min - 8000, $llong_max + 8000);
should_pass('ulonglong', $llong_umax);
should_fail('ulonglong', $llong_umax + 8000);
my $a = "8000000000000000";
my $b = "7fffffffffffffff";
my $c = "ffffffffffffffff";
skip "not a 64bit Perl", 18 unless eval { pack 'q', 1 };
batch('longlong', -hex($a), hex($b));
batch('ulonglong', hex($c));
}
my($foo, $int) = li_typemaps::out_foo(10);
@ -104,3 +79,4 @@ is($int, 20);
my($a, $b) = li_typemaps::inoutr_int2(13, 31);
is($a, 13);
is($b, 31);

View file

@ -46,6 +46,7 @@ CPP_TEST_CASES += \
li_cwstring \
li_factory \
li_implicit \
li_std_containers_int \
li_std_map_member \
li_std_multimap \
li_std_pair_extra \

View file

@ -2,7 +2,7 @@ from autodoc import *
def check(got, expected):
if expected != got:
raise RuntimeError("\n" + "Expected: [" + expected + "]\n" + "Got : [" + got + "]")
raise RuntimeError("\n" + "Expected: [" + str(expected) + "]\n" + "Got : [" + str(got) + "]")
check(A.__doc__, "Proxy of C++ A class")
check(A.funk.__doc__, "just a string")

View file

@ -8,8 +8,9 @@ if d.bar() != 2:
raise RuntimeError
if bar_getter(b) != 1:
raise RuntimeError
if bar_getter(d) != 2:
raise RuntimeError
# Fix reverted in rev 12953
#if bar_getter(d) != 2:
# raise RuntimeError
b = BaseDefaultInt()
d = DerivedDefaultInt()
@ -22,7 +23,8 @@ if d2.bar2() != 4:
raise RuntimeError
if bar2_getter(b) != 3:
raise RuntimeError
if bar2_getter(d) != 4:
raise RuntimeError
if bar2_getter(d2) != 4:
raise RuntimeError
# Fix reverted in rev 12953
#if bar2_getter(d) != 4:
# raise RuntimeError
#if bar2_getter(d2) != 4:
# raise RuntimeError

View file

@ -26,7 +26,7 @@ except threads_exception.Exc,e:
if e.code != 42:
raise RuntimeError
if e.msg != "Hosed":
raise RuntimeError
raise RuntimeError, "bad... msg: %s" % e.msg
for i in range(1,4):
try:

View file

@ -10,8 +10,13 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
C_TEST_CASES = r_copy_struct r_legacy
CPP_TEST_CASES = r_double_delete r_overload_array
C_TEST_CASES += \
r_copy_struct \
r_legacy
CPP_TEST_CASES += \
r_double_delete \
r_overload_array
include $(srcdir)/../common.mk

View file

@ -0,0 +1,13 @@
source("unittest.R")
dyn.load(paste("overload_method", .Platform$dynlib.ext, sep=""))
source("overload_method.R")
cacheMetaData(1)
b <- Base()
Base_method(b)
Base_overloaded_method(b)
Base_overloaded_method(b, 43)
Base_overloaded_method(b)
b$method()
b$overloaded_method()

View file

@ -97,7 +97,7 @@
RCPtr<A> _a;
};
class B* global_create(A* a)
struct B* global_create(A* a)
{
return new B(a);
}

View file

@ -5,6 +5,12 @@
%warnfilter(SWIGWARN_GO_NAME_CONFLICT); /* Ignoring 'NewName' due to Go name ('NewName') conflict with 'Name' */
%{
#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
%}
%ignore Name::operator=;
%inline %{

View file

@ -21,16 +21,16 @@ namespace Space {
C method(C c, D d, E e) { return c; }
// Use typedef with classname qualifiers
Bar(bool, Bar::C c, Bar::D d, Bar::E e) {}
Bar::C method_1(Bar::C c, Bar::D d, Bar::E e) { return c; }
Bar(bool, typename Bar::C c, typename Bar::D d, typename Bar::E e) {}
typename Bar::C method_1(typename Bar::C c, typename Bar::D d, typename Bar::E e) { return c; }
// Use typedef with classname and full template parameter qualifiers
Bar(bool, bool, Bar<CC, DD, EE>::C c, Bar<CC, DD, EE>::D d, Bar<CC, DD, EE>::E e) {}
Bar<CC, DD, EE>::C method_2(Bar<CC, DD, EE>::C c, Bar<CC, DD, EE>::D d, Bar<CC, DD, EE>::E e) { return c; }
Bar(bool, bool, typename Bar<CC, DD, EE>::C c, typename Bar<CC, DD, EE>::D d, typename Bar<CC, DD, EE>::E e) {}
typename Bar<CC, DD, EE>::C method_2(typename Bar<CC, DD, EE>::C c, typename Bar<CC, DD, EE>::D d, typename Bar<CC, DD, EE>::E e) { return c; }
// Use typedef with namespace and classname and full template parameter qualifiers
Bar(bool, bool, bool, Space::Bar<CC, DD, EE>::C c, Space::Bar<CC, DD, EE>::D d, Space::Bar<CC, DD, EE>::E e) {}
Space::Bar<CC, DD, EE>::C method_3(Space::Bar<CC, DD, EE>::C c, Space::Bar<CC, DD, EE>::D d, Space::Bar<CC, DD, EE>::E e) { return c; }
Bar(bool, bool, bool, typename Space::Bar<CC, DD, EE>::C c, typename Space::Bar<CC, DD, EE>::D d, typename Space::Bar<CC, DD, EE>::E e) {}
typename Space::Bar<CC, DD, EE>::C method_3(typename Space::Bar<CC, DD, EE>::C c, typename Space::Bar<CC, DD, EE>::D d, typename Space::Bar<CC, DD, EE>::E e) { return c; }
};
template<typename TT = SomeType> class Foo {
public:
@ -43,15 +43,15 @@ namespace Space {
// Use typedef with classname qualifiers
Foo(const T &, T t) {}
Foo::T method_A(Foo::T t) { return t; }
typename Foo::T method_A(typename Foo::T t) { return t; }
// Use typedef with classname and full template parameter qualifiers
Foo(const Foo<TT>::T &, const Foo<TT>::T &, Foo<TT>::T t) {}
Foo<TT>::T method_B(Foo<TT>::T t) { return t; }
Foo(const typename Foo<TT>::T &, const typename Foo<TT>::T &, typename Foo<TT>::T t) {}
typename Foo<TT>::T method_B(typename Foo<TT>::T t) { return t; }
// Use typedef with namespace and classname and full template parameter qualifiers
Foo(const Foo<TT>::T &, const Foo<TT>::T &, const Foo<TT>::T &, Foo<TT>::T t) {}
Foo<TT>::T method_C(Foo<TT>::T t) { return t; }
Foo(const typename Foo<TT>::T &, const typename Foo<TT>::T &, const typename Foo<TT>::T &, typename Foo<TT>::T t) {}
typename Foo<TT>::T method_C(typename Foo<TT>::T t) { return t; }
};
template<typename T = int> class ATemplate {};

View file

@ -24,8 +24,8 @@ template<class Key, class T> class Multimap {
class const_iterator {};
// test usage of a typedef of a nested class in a template
Standard::Pair<iterator,iterator> equal_range_1(const key_type& kt1) {}
Standard::Pair<const_iterator,const_iterator> equal_range_2(const key_type& kt2) const {}
Standard::Pair<iterator,iterator> equal_range_1(const key_type& kt1) { return Standard::Pair<iterator,iterator>(); }
Standard::Pair<const_iterator,const_iterator> equal_range_2(const key_type& kt2) const { return Standard::Pair<const_iterator,const_iterator>(); }
};
}
%}

View file

@ -3,6 +3,7 @@
%typemap(in) Integer1
{
$1 = 0;
/* do nothing */
}
@ -13,6 +14,7 @@
%typemap(in) Integer2
{
$1 = 0;
/* do nothing */
}

View file

@ -45,10 +45,18 @@ B_t make_b() {
%inline %{
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _Foo {
enum { NONAME1, NONAME2 } enumvar;
int foovar;
void (*fptr)(int);
} Foo;
#ifdef __cplusplus
}
#endif
%}

View file

@ -58,17 +58,17 @@ void foo2(Foo<short> f, const Foo<short>& ff) {}
// Test obscure bug where named typemaps where not being applied when symbol name contained a number
%typemap(out) double "_typemap_for_double_no_compile_"
%typemap(out) double ABC::meth "$1 = 0.0;"
%typemap(out) double ABC::m1 "$1 = 0.0;"
%typemap(out) double ABC::_x2 "$1 = 0.0;"
%typemap(out) double ABC::y_ "$1 = 0.0;"
%typemap(out) double ABC::_3 "$1 = 0.0;"
%typemap(out) double ABCD::meth "$1 = 0.0;"
%typemap(out) double ABCD::m1 "$1 = 0.0;"
%typemap(out) double ABCD::_x2 "$1 = 0.0;"
%typemap(out) double ABCD::y_ "$1 = 0.0;"
%typemap(out) double ABCD::_3 "$1 = 0.0;"
%inline %{
struct ABC {
double meth() {}
double m1() {}
double _x2() {}
double y_() {}
double _3() {}
struct ABCD {
double meth() { return 0.0; }
double m1() { return 0.0; }
double _x2() { return 0.0; }
double y_() { return 0.0; }
double _3() { return 0.0; }
};
%}

View file

@ -91,31 +91,31 @@ private class SwigExceptionHelper {
&setNoSuchElementException);
}
static void setException(const char* message) {
static void setException(char* message) {
auto exception = new object.Exception(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIllegalArgumentException(const char* message) {
static void setIllegalArgumentException(char* message) {
auto exception = new tango.core.Exception.IllegalArgumentException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIllegalElementException(const char* message) {
static void setIllegalElementException(char* message) {
auto exception = new tango.core.Exception.IllegalElementException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setIOException(const char* message) {
static void setIOException(char* message) {
auto exception = new tango.core.Exception.IOException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
}
static void setNoSuchElementException(const char* message) {
static void setNoSuchElementException(char* message) {
auto exception = new tango.core.Exception.NoSuchElementException(tango.stdc.stringz.fromStringz(message).dup);
exception.next = SwigPendingException.retrieve();
SwigPendingException.set(exception);
@ -174,7 +174,7 @@ private:
alias tango.core.Thread.ThreadLocal!(object.Exception) ThreadLocalData;
static ThreadLocalData m_sPendingException;
}
alias void function(const char* message) SwigExceptionCallback;
alias void function(char* message) SwigExceptionCallback;
%}
#else
%pragma(d) imdmoduleimports=%{

View file

@ -23,7 +23,8 @@
%typemap(jtype) char **STRING_ARRAY "String[]"
%typemap(jstype) char **STRING_ARRAY "String[]"
%typemap(in) char **STRING_ARRAY (jint size) {
int i = 0;
int i = 0;
if ($input) {
size = JCALL1(GetArrayLength, jenv, $input);
#ifdef __cplusplus
$1 = new char*[size+1];
@ -31,51 +32,56 @@
$1 = (char **)calloc(size+1, sizeof(char *));
#endif
for (i = 0; i<size; i++) {
jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
jstring j_string = (jstring)JCALL2(GetObjectArrayElement, jenv, $input, i);
const char *c_string = JCALL2(GetStringUTFChars, jenv, j_string, 0);
#ifdef __cplusplus
$1[i] = new char [strlen(c_string)+1];
$1[i] = new char [strlen(c_string)+1];
#else
$1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
$1[i] = (char *)calloc(strlen(c_string)+1, sizeof(const char *));
#endif
strcpy($1[i], c_string);
JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
JCALL1(DeleteLocalRef, jenv, j_string);
strcpy($1[i], c_string);
JCALL2(ReleaseStringUTFChars, jenv, j_string, c_string);
JCALL1(DeleteLocalRef, jenv, j_string);
}
$1[i] = 0;
} else {
$1 = 0;
}
}
%typemap(freearg) char **STRING_ARRAY {
int i;
for (i=0; i<size$argnum-1; i++)
int i;
for (i=0; i<size$argnum-1; i++)
#ifdef __cplusplus
delete[] $1[i];
delete[] $1;
delete[] $1[i];
delete[] $1;
#else
free($1[i]);
free($1);
free($1[i]);
free($1);
#endif
}
%typemap(out) char **STRING_ARRAY {
if ($1) {
int i;
int len=0;
jstring temp_string;
const jclass clazz = JCALL1(FindClass, jenv, "java/lang/String");
while ($1[len]) len++;
jresult = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
while ($1[len]) len++;
$result = JCALL3(NewObjectArray, jenv, len, clazz, NULL);
/* exception checking omitted */
for (i=0; i<len; i++) {
temp_string = JCALL1(NewStringUTF, jenv, *$1++);
JCALL3(SetObjectArrayElement, jenv, jresult, i, temp_string);
JCALL3(SetObjectArrayElement, jenv, $result, i, temp_string);
JCALL1(DeleteLocalRef, jenv, temp_string);
}
}
}
%typemap(javain) char **STRING_ARRAY "$javainput"
%typemap(javaout) char **STRING_ARRAY {
%typemap(javaout) char **STRING_ARRAY {
return $jnicall;
}
@ -111,7 +117,7 @@
%typemap(argout) char **STRING_OUT {
jstring jnewstring = NULL;
if($1) {
if ($1) {
jnewstring = JCALL1(NewStringUTF, jenv, *$1);
}
JCALL3(SetObjectArrayElement, jenv, $input, 0, jnewstring);
@ -134,11 +140,11 @@
%typemap(jtype) char *BYTE "byte[]"
%typemap(jstype) char *BYTE "byte[]"
%typemap(in) char *BYTE {
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
$1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
}
%typemap(argout) char *BYTE {
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *) $1, 0);
}
%typemap(javain) char *BYTE "$javainput"

23
Lib/lua/factory.i Normal file
View file

@ -0,0 +1,23 @@
/*
A modification of factory.swg from the generic UTL library.
*/
%include <typemaps/swigmacros.swg>
%define %_factory_dispatch(Type)
if (!dcast) {
Type *dobj = dynamic_cast<Type *>($1);
if (dobj) {
dcast = 1;
SWIG_NewPointerObj(L, dobj, $descriptor(Type *), $owner); SWIG_arg++;
}
}%enddef
%define %factory(Method,Types...)
%typemap(out) Method {
int dcast = 0;
%formacro(%_factory_dispatch, Types)
if (!dcast) {
SWIG_NewPointerObj(L, $1, $descriptor, $owner); SWIG_arg++;
}
}%enddef

View file

@ -33,6 +33,15 @@ extern "C" {
# define lua_rawlen lua_objlen
#endif
/* lua_pushglobaltable is the recommended "future-proof" way to get
the global table for Lua 5.2 and later. Here we define
lua_pushglobaltable ourselves for Lua versions before 5.2. */
#if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
# define lua_pushglobaltable(L) lua_pushvalue(L, LUA_GLOBALSINDEX)
#endif
/* -----------------------------------------------------------------------------
* global swig types
* ----------------------------------------------------------------------------- */
@ -469,6 +478,39 @@ SWIGINTERN int SWIG_Lua_class_destruct(lua_State* L)
return 0;
}
/* the class.__tostring method called by the interpreter and print */
SWIGINTERN int SWIG_Lua_class_tostring(lua_State* L)
{
/* there should be 1 param passed in
(1) userdata (not the metatable) */
assert(lua_isuserdata(L,1)); /* just in case */
unsigned long userData = (unsigned long)lua_touserdata(L,1); /* get the userdata address for later */
lua_getmetatable(L,1); /* get the meta table */
assert(lua_istable(L,-1)); /* just in case */
lua_getfield(L, -1, ".type");
const char* className = lua_tostring(L, -1);
char output[256];
sprintf(output, "<%s userdata: %lX>", className, userData);
lua_pushstring(L, (const char*)output);
return 1;
}
/* to manually disown some userdata */
SWIGINTERN int SWIG_Lua_class_disown(lua_State* L)
{
/* there should be 1 params passed in
(1) userdata (not the meta table) */
swig_lua_userdata* usr;
assert(lua_isuserdata(L,-1)); /* just in case */
usr=(swig_lua_userdata*)lua_touserdata(L,-1); /* get it */
usr->own = 0; /* clear our ownership */
return 0;
}
/* gets the swig class registry (or creates it) */
SWIGINTERN void SWIG_Lua_get_class_registry(lua_State* L)
{
@ -594,11 +636,15 @@ SWIGINTERN void SWIG_Lua_class_register(lua_State* L,swig_lua_class* clss)
/* add a table called ".fn" */
lua_pushstring(L,".fn");
lua_newtable(L);
/* add manual disown method */
SWIG_Lua_add_function(L,"__disown",SWIG_Lua_class_disown);
lua_rawset(L,-3);
/* add accessor fns for using the .get,.set&.fn */
SWIG_Lua_add_function(L,"__index",SWIG_Lua_class_get);
SWIG_Lua_add_function(L,"__newindex",SWIG_Lua_class_set);
SWIG_Lua_add_function(L,"__gc",SWIG_Lua_class_destruct);
/* add tostring method for better output */
SWIG_Lua_add_function(L,"__tostring",SWIG_Lua_class_tostring);
/* add it */
lua_rawset(L,-3); /* metatable into registry */
lua_pop(L,1); /* tidy stack (remove registry) */

View file

@ -30,11 +30,7 @@ SWIGEXPORT int SWIG_init(lua_State* L) /* default Lua action */
#if (SWIG_LUA_TARGET != SWIG_LUA_FLAVOR_ELUAC) /* valid for both Lua and eLua */
int i;
/* start with global table */
#ifdef LUA_RIDX_GLOBALS
lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);
#else
lua_pushvalue(L,LUA_GLOBALSINDEX);
#endif
lua_pushglobaltable (L);
/* SWIG's internal initalisation */
SWIG_InitializeModule((void*)L);
SWIG_PropagateClientData();

View file

@ -557,7 +557,8 @@ ptr=nil -- the iMath* will be GC'ed as normal
*/
%typemap(in,numinputs=0) SWIGTYPE** OUTPUT ($*ltype temp)
%{ $1 = &temp; %}
%{ temp = ($*ltype)0;
$1 = &temp; %}
%typemap(argout) SWIGTYPE** OUTPUT
%{SWIG_NewPointerObj(L,*$1,$*descriptor,1); SWIG_arg++; %}

View file

@ -424,7 +424,8 @@ namespace Swig {
if (ndim==1 && c.columns()!=1) ndim = c.columns();
dim_vector d;
d.resize(ndim);
d.resize(ndim < 2 ? 2 : ndim);
d(0) = d(1) = 1;
// Fill in dim_vector
for (int k=0;k<ndim;k++) {
@ -440,7 +441,8 @@ namespace Swig {
Array<int> a = out.int_vector_value();
if (error_state) return dim_vector(1,1);
dim_vector d;
d.resize(a.numel());
d.resize(a.numel() < 2 ? 2 : a.numel());
d(0) = d(1) = 1;
for (int k=0;k<a.numel();k++) {
d.elem(k) = a(k);
}

View file

@ -171,7 +171,9 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
// exiting without explicitly clearing the variable causes octave to segfault.
#if OCTAVE_API_VERSION_NUMBER>=37
octave_value_list SWIG_atexit_func(const octave_value_list &args, int nargout) {
symbol_table::clear_global_pattern("*");
string_vector vars = symbol_table::global_variable_names();
for (int i = 0; i < vars.length(); i++)
symbol_table::clear_global(vars[i]);
symbol_table::clear_functions();
return octave_value();
}

View file

@ -23,7 +23,7 @@ SWIG_AsVal_dec(bool)(SV *obj, bool* val)
if (val) *val = false;
return SWIG_OK;
} else {
if (val) *val = SvTRUE(obj);
if (val) *val = SvTRUE(obj) ? true : false;
return SWIG_AddCast(SWIG_OK);
}
}
@ -171,7 +171,7 @@ SWIG_From_dec(long long)(long long value)
{
SV *sv;
if (value >= IV_MIN && value <= IV_MAX)
sv = newSViv(value);
sv = newSViv((IV)(value));
else {
//sv = newSVpvf("%lld", value); doesn't work in non 64bit Perl
char temp[256];
@ -248,7 +248,7 @@ SWIG_From_dec(unsigned long long)(unsigned long long value)
{
SV *sv;
if (value <= UV_MAX)
sv = newSVuv(value);
sv = newSVuv((UV)(value));
else {
//sv = newSVpvf("%llu", value); doesn't work in non 64bit Perl
char temp[256];

View file

@ -188,8 +188,9 @@ namespace swig {
}
namespace swig {
template <class Difference>
inline size_t
check_index(ptrdiff_t i, size_t size, bool insert = false) {
check_index(Difference i, size_t size, bool insert = false) {
if ( i < 0 ) {
if ((size_t) (-i) <= size)
return (size_t) (i + size);
@ -201,37 +202,38 @@ namespace swig {
throw std::out_of_range("index out of range");
}
template <class Difference>
void
slice_adjust(ptrdiff_t i, ptrdiff_t j, ptrdiff_t step, size_t size, ptrdiff_t &ii, ptrdiff_t &jj, bool insert = false) {
slice_adjust(Difference i, Difference j, Py_ssize_t step, size_t size, Difference &ii, Difference &jj, bool insert = false) {
if (step == 0) {
throw std::invalid_argument("slice step cannot be zero");
} else if (step > 0) {
// Required range: 0 <= i < size, 0 <= j < size
if (i < 0) {
ii = 0;
} else if (i < (ptrdiff_t)size) {
} else if (i < (Difference)size) {
ii = i;
} else if (insert && (i >= (ptrdiff_t)size)) {
ii = (ptrdiff_t)size;
} else if (insert && (i >= (Difference)size)) {
ii = (Difference)size;
}
if ( j < 0 ) {
jj = 0;
} else {
jj = (j < (ptrdiff_t)size) ? j : (ptrdiff_t)size;
jj = (j < (Difference)size) ? j : (Difference)size;
}
} else {
// Required range: -1 <= i < size-1, -1 <= j < size-1
if (i < -1) {
ii = -1;
} else if (i < (ptrdiff_t) size) {
} else if (i < (Difference) size) {
ii = i;
} else if (i >= (ptrdiff_t)(size-1)) {
ii = (ptrdiff_t)(size-1);
} else if (i >= (Difference)(size-1)) {
ii = (Difference)(size-1);
}
if (j < -1) {
jj = -1;
} else {
jj = (j < (ptrdiff_t)size ) ? j : (ptrdiff_t)(size-1);
jj = (j < (Difference)size ) ? j : (Difference)(size-1);
}
}
}
@ -272,7 +274,7 @@ namespace swig {
typename Sequence::const_iterator it = sb;
while (it!=se) {
sequence->push_back(*it);
for (typename Sequence::size_type c=0; c<step && it!=se; ++c)
for (Py_ssize_t c=0; c<step && it!=se; ++c)
it++;
}
return sequence;
@ -287,7 +289,7 @@ namespace swig {
typename Sequence::const_reverse_iterator it = sb;
while (it!=se) {
sequence->push_back(*it);
for (typename Sequence::size_type c=0; c<-step && it!=se; ++c)
for (Py_ssize_t c=0; c<-step && it!=se; ++c)
it++;
}
}
@ -329,7 +331,7 @@ namespace swig {
size_t replacecount = (jj - ii + step - 1) / step;
if (is.size() != replacecount) {
char msg[1024];
sprintf(msg, "attempt to assign sequence of size %d to extended slice of size %d", is.size(), replacecount);
sprintf(msg, "attempt to assign sequence of size %lu to extended slice of size %lu", (unsigned long)is.size(), (unsigned long)replacecount);
throw std::invalid_argument(msg);
}
typename Sequence::const_iterator isit = is.begin();
@ -337,7 +339,7 @@ namespace swig {
std::advance(it,ii);
for (size_t rc=0; rc<replacecount; ++rc) {
*it++ = *isit++;
for (typename Sequence::size_type c=0; c<(step-1); ++c)
for (Py_ssize_t c=0; c<(step-1); ++c)
it++;
}
}
@ -347,7 +349,7 @@ namespace swig {
size_t replacecount = (ii - jj - step - 1) / -step;
if (is.size() != replacecount) {
char msg[1024];
sprintf(msg, "attempt to assign sequence of size %d to extended slice of size %d", is.size(), replacecount);
sprintf(msg, "attempt to assign sequence of size %lu to extended slice of size %lu", (unsigned long)is.size(), (unsigned long)replacecount);
throw std::invalid_argument(msg);
}
typename Sequence::const_iterator isit = is.begin();
@ -355,7 +357,7 @@ namespace swig {
std::advance(it,size-ii-1);
for (size_t rc=0; rc<replacecount; ++rc) {
*it++ = *isit++;
for (typename Sequence::size_type c=0; c<(-step-1); ++c)
for (Py_ssize_t c=0; c<(-step-1); ++c)
it++;
}
}
@ -383,7 +385,7 @@ namespace swig {
it = self->erase(it);
if (it==self->end())
break;
for (typename Sequence::size_type c=0; c<(step-1); ++c)
for (Py_ssize_t c=0; c<(step-1); ++c)
it++;
delcount--;
}
@ -399,7 +401,7 @@ namespace swig {
self->erase((++it).base());
if (it==self->rend())
break;
for (typename Sequence::size_type c=0; c<(-step-1); ++c)
for (Py_ssize_t c=0; c<(-step-1); ++c)
it++;
delcount--;
}
@ -797,8 +799,7 @@ namespace swig
return swig::getslice(self, i, j, 1);
}
void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence())
throw (std::out_of_range, std::invalid_argument) {
void __setslice__(difference_type i, difference_type j, const Sequence& v = Sequence()) throw (std::out_of_range, std::invalid_argument) {
swig::setslice(self, i, j, 1, v);
}
@ -821,41 +822,46 @@ namespace swig
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return NULL;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
return swig::getslice(self, i, j, step);
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
return swig::getslice(self, id, jd, step);
}
void __setitem__(PySliceObject *slice, const Sequence& v)
throw (std::out_of_range, std::invalid_argument) {
void __setitem__(PySliceObject *slice, const Sequence& v) throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
swig::setslice(self, i, j, step, v);
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
swig::setslice(self, id, jd, step, v);
}
void __setitem__(PySliceObject *slice)
throw (std::out_of_range, std::invalid_argument) {
void __setitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
swig::delslice(self, i, j, step);
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
swig::delslice(self, id, jd, step);
}
void __delitem__(PySliceObject *slice)
throw (std::out_of_range, std::invalid_argument) {
void __delitem__(PySliceObject *slice) throw (std::out_of_range, std::invalid_argument) {
Py_ssize_t i, j, step;
if( !PySlice_Check(slice) ) {
SWIG_Error(SWIG_TypeError, "Slice object expected.");
return;
}
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), self->size(), &i, &j, &step);
swig::delslice(self, i, j, step);
PySlice_GetIndices(SWIGPY_SLICE_ARG(slice), (Py_ssize_t)self->size(), &i, &j, &step);
Sequence::difference_type id = i;
Sequence::difference_type jd = j;
swig::delslice(self, id, jd, step);
}
}

View file

@ -4,7 +4,6 @@
#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type)
#define PyInt_Check(x) PyLong_Check(x)
#define PyInt_AsLong(x) PyLong_AsLong(x)
#define PyInt_AsUnsignedLongMask(x) PyLong_AsUnsignedLongMask(x)
#define PyInt_FromLong(x) PyLong_FromLong(x)
#define PyString_Check(name) PyBytes_Check(name)
#define PyString_FromString(x) PyUnicode_FromString(x)

View file

@ -100,12 +100,13 @@ SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
{
if (PyInt_Check(obj)) {
unsigned long v = PyInt_AsUnsignedLongMask(obj);
if (!PyErr_Occurred()) {
long v = PyInt_AsLong(obj);
if (v >= 0) {
if (val) *val = v;
return SWIG_OK;
} else {
return SWIG_OverflowError;
}
PyErr_Clear();
} else if (PyLong_Check(obj)) {
unsigned long v = PyLong_AsUnsignedLong(obj);
if (!PyErr_Occurred()) {

View file

@ -1,11 +1,16 @@
%include <rstdcommon.swg>
%include <std/std_common.i>
/*
Generate the traits for a 'primitive' type, such as 'double',
for which the SWIG_AsVal and SWIG_From methods are already defined.
*/
%define %traits_ptypen(Type...)
%fragment(SWIG_Traits_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type),
fragment=SWIG_From_frag(Type),
fragment="StdTraits") {
fragment=SWIG_AsVal_frag(Type),
fragment=SWIG_From_frag(Type),
fragment="StdTraits") {
namespace swig {
template <> struct traits<Type > {
typedef value_category category;
@ -27,6 +32,39 @@ namespace swig {
}
%enddef
/* Traits for enums. This is bit of a sneaky trick needed because a generic template specialization of enums
is not possible (unless using template meta-programming which SWIG doesn't support because of the explicit
instantiations required using %template). The STL containers define the 'front' method and the typemap
below is used whenever the front method is wrapped returning an enum. This typemap simply picks up the
standard enum typemap, but additionally drags in a fragment containing the traits_asval and traits_from
required in the generated code for enums. */
%define %traits_enum(Type...)
%fragment("SWIG_Traits_enum_"{Type},"header",
fragment=SWIG_AsVal_frag(int),
fragment=SWIG_From_frag(int),
fragment="StdTraits") {
namespace swig {
template <> struct traits_asval<Type > {
typedef Type value_type;
static int asval(SEXP obj, value_type *val) {
return SWIG_AsVal(int)(obj, (int *)val);
}
};
template <> struct traits_from<Type > {
typedef Type value_type;
static SEXP from(const value_type& val) {
return SWIG_From(int)((int)val);
}
};
}
}
%typemap(out, fragment="SWIG_Traits_enum_"{Type}) const enum SWIGTYPE& front %{$typemap(out, const enum SWIGTYPE&)%}
%enddef
%include <std/std_common.i>
//
// Generates the traits for all the known primitive
// C++ types (int, double, ...)

View file

@ -192,7 +192,6 @@
struct traits_asptr < std::vector<T> > {
static int asptr(SEXP obj, std::vector<T> **val) {
std::vector<T> *p;
Rprintf("my asptr\n");
int res = SWIG_R_ConvertPtr(obj, (void**)&p, type_info< std::vector<T> >(), 0);
if (SWIG_IsOK(res)) {
if (val) *val = p;

View file

@ -189,7 +189,7 @@ SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
downcast methods. */
if (obj != Qnil) {
VALUE value = rb_iv_get(obj, "@__swigtype__");
char* type_name = RSTRING_PTR(value);
const char* type_name = RSTRING_PTR(value);
if (strcmp(type->name, type_name) == 0) {
return obj;

View file

@ -359,7 +359,7 @@ namespace std {
#ifdef __cplusplus
%typemap(memberin) char * {
if ($1) delete [] $1;
delete [] $1;
if ($input) {
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
strcpy((char *)$1, (const char *)$input);
@ -376,7 +376,7 @@ namespace std {
}
}
%typemap(globalin) char * {
if ($1) delete [] $1;
delete [] $1;
if ($input) {
$1 = ($1_type) (new char[strlen((const char *)$input)+1]);
strcpy((char *)$1, (const char *)$input);
@ -394,7 +394,7 @@ namespace std {
}
#else
%typemap(memberin) char * {
if ($1) free((char *)$1);
free($1);
if ($input) {
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
strcpy((char *)$1, (const char *)$input);
@ -411,7 +411,7 @@ namespace std {
}
}
%typemap(globalin) char * {
if ($1) free((char *)$1);
free($1);
if ($input) {
$1 = ($1_type) malloc(strlen((const char *)$input)+1);
strcpy((char *)$1, (const char *)$input);

2
README
View file

@ -1,6 +1,6 @@
SWIG (Simplified Wrapper and Interface Generator)
Version: 2.0.5 (in progress)
Version: 2.0.6 (30 April 2012)
Tagline: SWIG is a compiler that integrates C and C++ with languages
including Perl, Python, Tcl, Ruby, PHP, Java, Ocaml, Lua,

View file

@ -4,6 +4,22 @@ and CHANGES files.
Release Notes
=============
SWIG-2.0.6 summary:
- Regression fix for Python STL wrappers on some systems.
SWIG-2.0.5 summary:
- Official Android support added including documentation and examples.
- Improvements involving templates:
1) Various fixes with templates and typedef types.
2) Some template lookup problems fixed.
3) Templated type fixes to use correct typemaps.
- Autodoc documentation generation improvements.
- Python STL container wrappers improvements including addition of
stepped slicing.
- Approximately 70 fixes and minor enhancements for the following
target languages: AllegroCL, C#, D, Go, Java, Lua, Ocaml, Octave,
Perl, PHP, Python, R, Ruby, Tcl, Xml.
SWIG-2.0.4 summary:
- This is mainly a Python oriented release including support for Python
built-in types for superior performance with the new -builtin option.

View file

@ -259,7 +259,7 @@ int DohEqual(const DOH *obj1, const DOH *obj2) {
if (!b1info) {
return obj1 == obj2;
} else if ((b1info == b2info)) {
} else if (b1info == b2info) {
return b1info->doh_equal ? (b1info->doh_equal) (b1, b2) : (b1info->doh_cmp ? (b1info->doh_cmp) (b1, b2) == 0 : (b1 == b2));
} else {
return 0;

View file

@ -4602,7 +4602,7 @@ private:
co = c + Len(nspace);
while (*c && (c != co)) {
if ((*c == '.')) {
if (*c == '.') {
break;
}
c++;

View file

@ -144,6 +144,8 @@ public:
Xml_print_kwargs(Getattr(obj, k));
} else if (Cmp(k, "parms") == 0 || Cmp(k, "pattern") == 0) {
Xml_print_parmlist(Getattr(obj, k));
} else if (Cmp(k, "catchlist") == 0) {
Xml_print_parmlist(Getattr(obj, k), "catchlist");
} else {
DOH *o;
print_indent(0);
@ -198,10 +200,10 @@ public:
}
void Xml_print_parmlist(ParmList *p) {
void Xml_print_parmlist(ParmList *p, const char* markup = "parmlist") {
print_indent(0);
Printf(out, "<parmlist id=\"%ld\" addr=\"%x\" >\n", ++id, p);
Printf(out, "<%s id=\"%ld\" addr=\"%x\" >\n", markup, ++id, p);
indent_level += 4;
while (p) {
print_indent(0);
@ -213,7 +215,7 @@ public:
}
indent_level -= 4;
print_indent(0);
Printf(out, "</parmlist >\n");
Printf(out, "</%s >\n", markup);
}
void Xml_print_baselist(List *p) {

View file

@ -298,16 +298,16 @@ int Preprocessor_expr(DOH *s, int *error) {
stack[sp++].op = EXPR_OP;
stack[sp].op = EXPR_TOP;
stack[sp].svalue = 0;
} else if ((token == SWIG_TOKEN_LPAREN)) {
} else if (token == SWIG_TOKEN_LPAREN) {
stack[sp++].op = EXPR_GROUP;
stack[sp].op = EXPR_TOP;
stack[sp].value = 0;
stack[sp].svalue = 0;
} else if (token == SWIG_TOKEN_ENDLINE) {
} else if ((token == SWIG_TOKEN_STRING)) {
} else if (token == SWIG_TOKEN_STRING) {
stack[sp].svalue = NewString(Scanner_text(scan));
stack[sp].op = EXPR_VALUE;
} else if ((token == SWIG_TOKEN_ID)) {
} else if (token == SWIG_TOKEN_ID) {
stack[sp].value = 0;
stack[sp].svalue = 0;
stack[sp].op = EXPR_VALUE;

View file

@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script.
dnl The macros which aren't shipped with the autotools are stored in the
dnl Tools/config directory in .m4 files.
AC_INIT([swig],[2.0.5],[http://www.swig.org])
AC_INIT([swig],[2.0.6],[http://www.swig.org])
dnl NB: When this requirement is increased to 2.60 or later, AC_PROG_SED
dnl definition below can be removed