Commit graph

4,234 commits

Author SHA1 Message Date
Vadim Zeitlin
54af856d09 Fix typemaps for arrays of objects and object pointers
These typemaps never worked, but this went unnoticed until now because
the nonsensical "ctype" expansion generated by them still compiled.

With types possibly having a namespace prefix, they didn't any longer,
so define them correctly for the objects using "$resolved_type" and
define the typemap for "void*[]" separately, as "$resolved_type" can't
be used for it.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
d65d7d7df3 Make SWIGIMPORT definition more consistent with SWIGEXPORT
Use the same checks as for the definition of SWIGEXPORT in
swiglabels.swg.

Also avoid defining __DLL_IMPORT symbol with a reserved name.
2021-10-20 01:57:18 +02:00
Vadim Zeitlin
e41234c5bc Inject just the relevant part of changes.swg in generated code
Don't include the entire file, including its header comment, into the
generated code, but just the part that we want to appear there.

This looks nicer and is also more explicit and hence clear.
2021-10-15 23:16:42 +02:00
Vadim Zeitlin
e78c8f39ed Add minimal shared_ptr support
Enable the tests and support of shared_ptr in them for C (which required
disabling a previously passing, because not doing anything, attributes
test which is currently broken for unrelated reasons).
2021-10-15 01:26:22 +02:00
Vadim Zeitlin
3dd96d5b95 Allow using vector with classes without default ctor in C too
This is similar to be491506a (Java std::vector improvements for types
that do not have a default constructor., 2019-03-01) for Java, except we
don't have to bother with any compatibility constraints for this, not
yet used by anyone. module.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
5cbdae42d3 Revert "Use std/std_vector.i instead of a poor copy in c/std_vector.i"
This reverts commit d89a95a48c as,
finally, it's not worth trying to use UTL typemaps from C: this required
bad hacks for std::vector and would be even worse for std::map, so don't
bother with them and just correct the "poor" C typemaps to be slightly
less poor and use them instead.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
0706ed4d35 Add simple std::set<> typemaps too
This is similar to the previous commit for std::map<>.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
9efb508eda Fix std::map<> typemap
Use simple fixed typemap instead of trying to use the much more complex
one from the UTL which doesn't work for C.

Add a simple test case for std::map<>.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
ac4f3c78be Merge branch 'master' into C
Merge with the latest master before making more changes.
2021-10-04 16:03:36 +02:00
Anthony Heading
6c59cae799 Avoid gcc 11 misleading indentation warning in generated code
Closes https://github.com/swig/swig/pull/2074
2021-10-03 17:18:58 +02:00
Ian Lance Taylor
6ca5d5d722 swig -go: don't use crosscall2 for panicking
Instead rely only on documented and exported interfaces.
2021-09-15 17:56:01 -07:00
Ian Lance Taylor
4461c443cf remove Go -no-cgo option
It only worked for Go versions before 1.5, which is more than five
years ago and long-unsupported.
2021-09-14 13:59:21 -07:00
Olly Betts
17a294cec4 Replace remaining PHP errors with PHP exceptions
`SWIG_ErrorCode()`, `SWIG_ErrorMsg()`, `SWIG_FAIL()` and `goto thrown;`
are no longer supported (these are really all internal implementation
details and none are documented aside from brief mentions in CHANGES
for the first three).  I wasn't able to find any uses at least in FOSS
code via code search tools.

If you are using these:

Use `SWIG_PHP_Error(code,msg);` instead of `SWIG_ErrorCode(code);
SWIG_ErrorMsg(msg);` (which will throw a PHP exception in SWIG >= 4.1
and do the same as the individual calls in older SWIG).

`SWIG_FAIL();` and `goto thrown;` can typically be replaced with
`SWIG_fail;`.  This will probably also work with older SWIG, but
please test with your wrappers if this is important to you.

Fixes #2014
2021-05-26 09:39:43 +12:00
Olly Betts
cdc69f9843 php: Throw exceptions instead of using errors
Parameter type errors and some other cases in SWIG-generated wrappers
now throw a PHP exception, which is how PHP's native parameter handling
deals with similar situations.

See #2014, but not closing yet as there may be more cases to convert.
2021-05-25 16:42:12 +12:00
Olly Betts
8fb25b6a38 php: SWIG_exception now maps code to exception class
This now determines the class of the exception object where a
suitable pre-defined PHP exception class exists - for example,
SWIG_TypeError -> PHP exception class TypeError.

Exception codes which don't naturally map to a pre-defined PHP
exception class are thrown as PHP class Exception (like all
PHP exceptions raised by SWIG_exception were before this change.)
2021-05-25 16:33:01 +12:00
Olly Betts
3c168ef332 Map known PHP interfaces to zend_class_entry*
Most pre-defined interfaces are accessible via zend_class_entry*
variables declared in the PHP C API - we can use these to add
an interface at MINIT time (rather than having to wait until RINIT to
look up by name) by having a mapping from PHP interface name to them.

This will also be a little faster than looking up by name.

Closes #2013
2021-05-25 16:28:44 +12:00
Andrew Rogers
448e8d57bd Further leak fixes 2021-05-18 13:07:48 +01:00
Andrew Rogers
16123466f4 Update tests for failing Python API calls to all use '!= 0' 2021-05-18 13:05:51 +01:00
Andrew Rogers
4f453e0cde Tidy up handling of OOM exceptions - Py*_New will call PyErr_NoMemory() internally, so there is no need to call it again here, just correctly handle the NULL return value 2021-05-17 22:50:52 +01:00
Andrew Rogers
04a0b526eb Merge remote-tracking branch 'upstream/master' into memleak
# Conflicts:
#	CHANGES.current
2021-05-17 22:44:56 +01:00
Olly Betts
a54d62b22e [UFFI] Remove code for Common Lisp UFFI
We dropped support for it in SWIG 4.0.0 and nobody has stepped forward
to revive it in over 2 years.

See #2009.
2021-05-16 08:42:39 +12:00
Olly Betts
11bb422bd3 [Pike] Remove code for Pike
We dropped support for it in SWIG 4.0.0 and nobody has stepped forward
to revive it in over 2 years.

See #2009.
2021-05-16 08:42:39 +12:00
Olly Betts
12f3a85916 [Modula3] Remove code for Modula3
We dropped support for it in SWIG 4.0.0 and nobody has stepped forward
to revive it in over 2 years.

See #2009.
2021-05-16 08:42:39 +12:00
Olly Betts
f3ba54c3bb [CLISP] Remove code for GNU Common Lisp
We dropped support for it in SWIG 4.0.0 and nobody has stepped forward
to revive it in over 2 years.

See #2009.
2021-05-16 08:42:39 +12:00
Olly Betts
5f38f9cc78 [Chicken] Remove code for Chicken
We dropped support for it in SWIG 4.0.0 and nobody has stepped forward
to revive it in over 2 years.

See #2009.
2021-05-16 08:42:39 +12:00
Andrew Rogers
84ff84f4fb [Python] Fix memory leaks. 2021-05-12 23:42:32 +01:00
Olly Betts
353baebfcf [Allegrocl] Remove code for Allegro Common Lisp
We dropped support for it in SWIG 4.0.0 and nobody has stepped forward
to revive it in over 2 years.

See #2009.
2021-05-13 10:38:40 +12:00
Olly Betts
b671a37e89 [php] Fix reserved class names TRUE, FALSE, NULL
PHPCN(x) does a string compare of x with the lower-cased class name,
so x needs to be in lowercase or else the entry has no effect.  The
entries for TRUE, FALSE and NULL weren't working as a result.
2021-05-12 16:45:42 +12:00
Olly Betts
853c511057 [php] Update keyword list
Add some missing entries, remove some long obsolete entries (from
the "ming" extension for generating SWF files, which was split
out from PHP core in 2008), and entry for "static" as a reserved class
name (`static::` is used for late static bindings, but attempting to
name a PHP class `static` fails because `static` is a keyword and we
also list it as such).
2021-05-12 16:43:32 +12:00
Olly Betts
542f6ca440 Fix uses of uninitialised zval
SWIG_SetPointerZval() now checks if the passed zval is an object,
so use ZVAL_UNDEF() before in cases where we create a zval to pass.
2021-05-05 11:55:07 +12:00
Olly Betts
228b04974d Clean up includes of PHP API headers
Eliminate redundant and unused includes.

Only include the minimum headers needed before the PHP_MAJOR_VERSION
check in case future PHP versions remove some of the headers we
include.
2021-05-05 10:58:07 +12:00
Olly Betts
82b244c1d3 [php] Remove redundant conditional include
We always include zend_exceptions.h via phprun.swg.
2021-05-05 09:35:52 +12:00
Olly Betts
6e6d720d88 Fix segfault in exception class creation
We can't safely lookup the Exception class entry at MINIT time, but we
can just use zend_ce_exception instead, which will be a bit faster too.
2021-05-04 13:12:15 +12:00
Olly Betts
586eb24efe php: Stop using dl()
With modern PHP it only works with the CLI version of PHP, so it's
better to direct users to load the extension via "extension=" in
php.ini.

Suggested by ferdynator in #1529.
2021-05-03 18:42:28 +12:00
Olly Betts
c87047fd39 Merge branch 'master' into gsoc2017-php7-classes-via-c-api 2021-05-03 16:17:02 +12:00
Olly Betts
04bacf689b Implement director-disown for PHP 2021-05-03 16:00:30 +12:00
William S Fulton
429288fa1c Fix Java %interface family of macros
when returning by const pointer reference

Closes #1987
2021-04-27 23:37:18 +01:00
William S Fulton
13158bda9a Member function pointer typemap tweaks
Use sizeof variable name rather than variable type.
Workaround Visual C++ unable to parse some complex C++11 types, such as
  sizeof(short (Funcs::*)(bool) const &&)
2021-04-26 22:32:52 +01:00
Olly Betts
837dfa1e7e Fix directorout SWIGTYPE typemaps 2021-04-22 17:51:14 +12:00
Olly Betts
a6a52f2f79 Eliminate remaining use of $needNewFlow 2021-04-22 15:14:38 +12:00
Olly Betts
50426aae20 Make PHP directors work more like other languages
A PHP exception now gets translated to a C++ exception to skips over C++
code to get back to PHP, avoiding the need to gate every directorout
typemap on EG(exception).
2021-04-22 14:40:21 +12:00
Olly Betts
10d87100ea Whitespace tweaks 2021-04-22 12:25:13 +12:00
Olly Betts
ad61e33e22 Wrap pointer to member as object not resource 2021-04-22 07:56:25 +12:00
Olly Betts
50b13275dc Fix mixed declarations and code 2021-04-22 07:42:39 +12:00
Olly Betts
2920ba1cf6 Use malloc() not emalloc() when free() gets used 2021-04-21 18:18:59 +12:00
Olly Betts
49d5909b08 Use $1 instead of result in out typemaps 2021-04-21 18:16:08 +12:00
Olly Betts
33feca7527 Eliminate SWIG_SetZval()
$needNewFlow is now only used for a different hack in a directorout
typemap.
2021-04-21 18:16:08 +12:00
Olly Betts
5577257301 Eliminate $needNewFlow from factory.i
$needNewFlow in an output typemap is now only relevant when wrapping
to a PHP __construct method, and there the return type is known so
factory.i isn't useful.
2021-04-21 16:32:56 +12:00
Olly Betts
2804e3b208 Fix mixed declarations and code 2021-04-21 16:05:41 +12:00
Olly Betts
3e8373b09a Merge branch 'master' into gsoc2017-php7-classes-via-c-api 2021-04-21 16:05:24 +12:00