Commit graph

4,326 commits

Author SHA1 Message Date
Vadim Zeitlin
f919896306 Merge branch 'master' into C 2016-09-15 01:30:49 +02:00
Vadim Zeitlin
9204e57cc1 Fix $typemap() expansion for "ctype" typemap
This didn't work correctly before because we need to override the base class
replaceSpecialVariables() method to expand $resolved_type, which appears
during the expansion, using the type supplied as $typemap() argument instead
of doing it later using it the type to which the typemap containing the macro
is attached.

This is a prerequisite for implementing smart pointers support.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
2f4eb2d412 Replace output_target parameter with global current_output
This will allow implementing replaceSpecialVariables(): as it is called from
inside the typemap lookup code, we can't pass any parameters to it directly,
but we can use a class language-global member variable to it indirectly.

No real changes yet.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
dcda566ce6 Remove unnecessary memory allocation from substituteResolvedType()
Don't allocate memory just to leak it, SwigType_typedef_resolve_all() already
returns a copy we can use.
2016-09-15 01:27:42 +02:00
Vadim Zeitlin
bf71891197 Just get rid of an unnecessary variable
Simplify the code by avoiding a superfluous extra variable.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
0353317a21 Remove substituteResolvedType() return value as it is unused
It doesn't matter if this function did anything or not as its output parameter
is always used anyhow by the caller.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
ad5de803b5 Avoid unnecessary allocation in get_wrapper_func_return_type()
Don't call NewString() just to overwrite it with another pointer (and leak the
one allocated by NewString()).
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
11426ac1cd Drop code dealing with tmap:ctype:out which is never used
This typemap attribute is not used with C (so far), there is no point in
checking for it in the code.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
6e0e728a14 Refactor node copying in C::classHandler()
Don't create a new node just to delete it if we don't need it, but rather only
create it if we do need it.

Also copy as much as can be copied in copy_node() helper, it was confusing to
copy part of the attributes in it and part in the caller. And one of them
("c:inherited_from") was even copied twice, it was first created in the
function and then unconditionally overwritten by the caller -- don't do this
any more.

No real changes.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
2ce15d3e6a Don't leak a Node in C::classHandler()
Delete the copied node if we end up not using it.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
65d9cad1ca Don't force inheritance of ignored methods
If a symbol is ignored in the base class, it shouldn't appear in the derived
class neither.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
8eba14c6e0 Resolve typedefs in parameter types after applying ctype typemap
Typedefs were not resolved for non-object types in spite of
SwigType_typedef_resolve_all() call as it didn't affect "c_parm_type".

Actually it is not even clear if resolving typedefs is a good idea as using
them probably makes the generated code more clear, but at least in the case of
nested typedefs we do need to do it as "Class::Type" can't appear in C code.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
8fa28e0ce9 Don't lose the correct sym:name when inheriting base class methods
For some reason, the copy of the function made in the derived class used the
"name" attribute instead of "sym:name", which means that any %renames attached
to it were lost and didn't affect the derived class version.

Fix this and also a problem uncovered by doing it in the operator_overload
unit test as the assignment operator shouldn't be inherited at all, the
compiler-generated operator is used instead if the derived class doesn't
define its own one.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
0c936d9089 Simplify and inline functionWrapperAddCPPResult()
This function seemed to be doing a few unnecessary things, e.g. it resolved
the typedefs which doesn't seem to be necessary and the test for member
pointer seems to be useless too.

Just add a local "cppresult" directly in the caller instead of using a
separate function to do all this.
2016-09-15 01:27:41 +02:00
Vadim Zeitlin
d3412499bb Use the original function name in C code wrappers
Using "sym:name" in the wrapping code is wrong, it is different from "name" if
the function has been renamed and we need to call the original C function, not
whichever name it is exported under.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
10d25c7327 Drop longjmp-based exception handling approach
Using longjmp was incompatible with using C++ objects in the code using the
wrappers, and using this C API from C++ to avoid ABI incompatibilities between
different C++ compilers is one of the main reasons for using this module.

Also, this required using a separate SwigObj instead of just using the real
object pointer which inevitably resulted in memory leaks whenever a non owned
object was returned from anywhere, e.g. from a member accessor or any method
returning pointer or reference.

Abandon the attempts to recreate C++ exceptions in C and just use a very
simple approach allowing to pass an error message out of band after any
function call in a global variable. An alternative could be to add a special
"out" error parameter to each and every function, but this risked being too
verbose, especially for the functions which don't really throw, and the calls
to SWIG_PendingException_get() won't need to be made explicitly when using a
C++ wrapper around the generated C API in the future.

This simplifies both the module and the generated code, in particular we don't
need any runtime code at all any more and there is no need for an extra level
of indirection for every object.

It also makes a couple more tests pass.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
bda731cd8f Change naming convention for wrapped ctors and dtor
Use Foo_{new,delete}() instead of {new,delete}_Foo() to ensure that all
methods of the class Foo start with the corresponding prefix.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
b24665fa6a Add names of the functions being wrapped to symbol table
At the very least this results in clear error messages when running SWIG if
the symbol is encountered twice instead of errors given only when compiling
the generated code later.
2016-09-15 01:27:40 +02:00
Vadim Zeitlin
7f4549a0f3 Ensure that we define bool before using it for variables
It would have been better to hook into the fragment machinery, but for now do
it directly to make sure the generated code compiles.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
5fd1f28477 Do not export static global variables at all
They shouldn't be exported and can't be when using shared libraries.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
97fc60ef51 Get rid of c:objstruct attribute
The only remaining use of this attribute is to test for whether we're wrapping
a ctor and it is simpler and more clear to just check the node type directly
in this case.

This attribute was pretty confusing as it was used for parameters and entire
declarations, so removing it makes things more clear and simpler.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
0480694a7a Remove the now unused functionWrapperCPPSpecificMarkFirstParam()
There is no need to set c:objstruct for the first parameter of the methods now
that we take care of it for disambiguating between overloads explicitly and
this function doesn't seem to be useful for anything else, simply drop it.
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
8e30abf7ab Don't use "this" method parameter for disambiguating overloads
When building the unique suffix for each member of the overloaded functions
set, don't use the first "this" parameter of the object methods in it as it's
the same for all of them and so is completely useless for disambiguation
purposes and just results in unnecessarily long and ugly names.

Use "_const" suffix for the methods differing by their const-ness only, this
is necessary now that we don't use "_pFoo" or "_pcFoo" in their names.

This makes it superfluous to check for c:objstruct in
functionWrapperAppendOverloaded() (and checking for it there was not enough
neither, as the changes in the test suite show, sometimes the "this" parameter
type still found its way into the generated wrappers).
2016-09-15 01:27:39 +02:00
Vadim Zeitlin
e068aa8cc9 Simplify ctors/dtor handling by reusing base class code
Just use our custom object creation/destruction code, but let the base class
do everything else.

This uncovered complete lack of support for ctors/dtors defined using %extend,
but this is not new and will have to remain broken for now.
2016-09-15 01:27:39 +02:00
Olly Betts
849f157efa [Python] Fix import in frozen app for Python 2.6 (#784)
Fix import handling for Python 2.6 to work in a frozen application.
Fixes #145, reported by Thomas Kluyver.
2016-09-12 08:11:47 +12:00
William S Fulton
5b7c08c214 Make Python builtin types hashable by default
Default hash is the underlying C/C++ pointer.
This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare)
which compares the pointers.
2016-08-23 19:06:36 +01:00
William S Fulton
1cef6b7440 Merge branch 'builtin-tweaks'
* builtin-tweaks:
  Python builtin minor tweaks
  Cosmetic code formatting corrections
  Further additional Python builtin slots as features for user customization
  Add additional Python builtin slots as features for user customization
  Correct notes on customising Python builtin comparison operators
  Set tp_new statically rather than during initialisation
  Customize slots tp_basicsize tp_methods tp_getset
  Additional Python builtin slot overrides and slightly better formatted Python generated code
  Add Python builtin tp_dealloc override test
  Python getSlot() refactor
  Add Python builtin closure method in comment
  Update Python docs on builtin slots
  Python builtin hashfunc closure fix
2016-08-22 19:37:10 +01:00
William S Fulton
ae32fb4f9a Python builtin minor tweaks
Remove internal Python struct names from generated code
Cosmetic code formatting
2016-08-22 19:28:52 +01:00
William S Fulton
ad452edf3e Cosmetic code formatting corrections 2016-08-22 08:48:04 +01:00
William S Fulton
bf4174d121 Further additional Python builtin slots as features for user customization
Added:
- tp_flags
- was_sq_slice
- was_sq_ass_slice
2016-08-22 08:39:24 +01:00
William S Fulton
e5a09c4141 Add additional Python builtin slots as features for user customization
Added:
- tp_is_gc
- tp_bases
- tp_mro
- tp_cache
- tp_subclasses
- tp_weaklist
- tp_del
- tp_allocs
- tp_frees
- tp_maxalloc
- tp_prev
- tp_next
2016-08-22 07:51:42 +01:00
William S Fulton
3b6f4af15c Set tp_new statically rather than during initialisation 2016-08-21 14:29:27 +01:00
William S Fulton
3744c45082 Customize slots tp_basicsize tp_methods tp_getset 2016-08-19 23:46:50 +01:00
William S Fulton
239785ce7d Additional Python builtin slot overrides and slightly better formatted Python generated code
The following slots can now be overidden by users if they know what they
are doing:
- tp_dictoffset
- tp_init
- tp_new
- tp_as_number
- tp_as_sequence
- tp_as_mapping
- tp_as_buffer
2016-08-19 23:16:32 +01:00
William S Fulton
67ece1d2bf Python getSlot() refactor
getSlot() now takes a default that can override "0" default - simpler
code and for future commits to override some currently non-overridable
slots.
2016-08-19 08:43:40 +01:00
William S Fulton
a3fc743f32 Add Python builtin closure method in comment
For less mystifying code and easier code searching
2016-08-18 08:41:07 +01:00
Olly Betts
a950d1309b [xml] Fix how the output filename is built
Avoid problems when it contains the embedded strings ".c", ".cpp" or ".cxx".
Fixes #540 reported by djack42.
2016-08-05 11:52:35 +12:00
Simon Marchetto
d0a45be1eb scilab: fix issue #746 2016-07-29 16:56:30 +02:00
Simon Marchetto
95a5def328 scilab: fix issue #755 2016-07-29 11:52:26 +02:00
William S Fulton
b24e970a28 Merge branch 'wkalinin-nested-ignore-fix'
* wkalinin-nested-ignore-fix:
  renamed test module, in accordance with other tests
  function body fixed
  added foo() definition to satisfy some test linking fails
  func() renamed to foo() for 'go'
  fixed test-suite/nested_ignore.i
  test for #662
  fix for nested ignored types

Closes #662
2016-06-26 00:33:19 +01:00
William S Fulton
2da7e066b3 Merge branch 'avalluri-leaks'
* avalluri-leaks:
  whitespace fix
  memory leak improvements - delete at end of scope
  CCache: Fix typo in null check
  CCache: Fix memory/file descriptor leaks
  scilab.cxx: Fix memory leaks
  Fix leaked file descriptor
  Lua: Fix possible memory leaks
  go.cxx: Fix use of a freed variable

Closes #710
Closes #712
Closes #713
Closes #715
Closes #716
2016-06-26 00:16:30 +01:00
William S Fulton
7ec7cc63da memory leak improvements - delete at end of scope 2016-06-26 00:06:01 +01:00
William S Fulton
91a79c8df2 Merge branch 'ahnolds-implicittest'
* ahnolds-implicittest:
  Fixing implicitconv handling for fastdispatch and castmode
2016-06-25 20:46:58 +01:00
Alec Cooper
4f1c491090 Fixing implicitconv handling for fastdispatch and castmode 2016-06-23 08:06:14 -04:00
Lior Goldberg
c363a93d69 Added support for type alias 2016-06-22 23:13:28 +03:00
William S Fulton
38cda92938 smartptr inheritance fix when using templates and typedefs
Fixes SF bug 3333549 - %shared_ptr fixes when the type is a template using
template parameters that are typedef'd to another type.

Also fixes python -O optimization where the smart pointer conversion to the
base class needs to work because of the virtual methods that have been
optimized away.
2016-06-21 07:00:56 +01:00
Amarnath Valluri
9b371b48d1 scilab.cxx: Fix memory leaks
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2016-06-16 15:59:21 +03:00
Amarnath Valluri
030a3b08bf Fix leaked file descriptor
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2016-06-16 15:53:22 +03:00
Amarnath Valluri
08d5e19e6e Lua: Fix possible memory leaks
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2016-06-16 15:51:50 +03:00
Amarnath Valluri
11b971f405 go.cxx: Fix use of a freed variable
Signed-off-by: Amarnath Valluri <amarnath.valluri@intel.com>
2016-06-16 15:47:12 +03:00