Commit graph

3,447 commits

Author SHA1 Message Date
Vadim Zeitlin
afc02cbc01 Remove unused f_wrappers_cxx
This variable wasn't used since a long time and removing it doesn't
affect generated code.
2021-11-19 00:08:44 +01:00
Vadim Zeitlin
0f734e1164 Don't generate empty enum declarations
They are invalid in C++ and there shouldn't actually be any in valid
input, but they do occur in SWIG test suite.

Don't generate anything for them in the output, especially because doing
this is not really more complicated than using "enum_is_empty" field
that we had previously and might even be a tad simpler, as it doesn't
split the "{" and "}" output between two different functions.
2021-11-19 00:08:43 +01:00
Vadim Zeitlin
e7fa72fc06 Don't generate invalid forward enum declarations
Such declarations are invalid without specifying the underlying type
(which is only possible since C++11) and are useless anyhow, so just
don't bother emitting them.
2021-11-19 00:08:43 +01:00
Vadim Zeitlin
e8f9bdba80 Remove wrapper aliases generation and use -namespace in the tests
The -namespace option provides a better way of using the wrapped API, so
drop the optional wrapper generation, which is useless when this option
is used and just generates many lines of unwanted junk in the header.

Update the test suite and the examples to compensate to not rely on
being able to define SWIG_DEFINE_WRAPPER_ALIASES and add -namespace
option to all C++ tests, as it's done for C# test suite, and update them
to use the correct prefix and also use the accessors for the global
variables rather than using them directly, as this is impossible when
namespace prefix is used (it would have been possible to define a
preprocessor symbol corresponding to the real variable name, but it's
arguably not worth it).

fixup! Remove wrapper aliases generation and use -namespace in the tests
2021-11-10 02:11:59 +01:00
Vadim Zeitlin
11bd97653f Inline functions used only once in functionWrapperCPPSpecific()
No real changes, just keep everything in a single function because it is
more clear than having both it and functionWrapperCPPSpecificWrapper()
doing the same thing.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
2f4a09fb21 Avoid calling getFunctionWrapperName() twice for each function
Pass the wrapper name to emit_wrapper_func_decl() to save on an extra
call to this function.

No real changes, this is just an optimization.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
fbf976768a Get rid of "c:globalfun" attribute
Use getCurrentClass() and other existing attributes to check if the
current node is inside a class or not (and hence is global), this is
more explicit and avoids confusion for static member functions that were
marked as being global in spite of being nested inside a class.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
8594a8def6 Use SWIG-specific suffix for non-overloaded %extend functions too
This avoids conflicts between functions synthesized by %extend when
adding static methods to an existing class, and the actual wrapper
functions generated by the backend.

This shouldn't result in any user-visible changes.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
70309fcb0a Refactor code in Language::staticmemberfunctionHandler()
No real changes, just move the test for "code" to the outer scope to
facilitate the upcoming changes.

This commit is best viewed ignoring whitespace-only changes.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
6833ead6ed Add -namespace option to use unique prefix for all wrappers
Using this option allows to prefix all exported symbols (functions,
enums and enum elements) with a prefix based on the given namespace.

Note that (global) variables can't be exported directly when using the
global namespace prefix, even if they are of C-compatible type.
2021-11-10 00:53:39 +01:00
Vadim Zeitlin
cda93bd903 Fix enum value translation
Don't rely on hack with checking the value length and looking it up,
just check its type instead.
2021-11-07 02:29:01 +01:00
Vadim Zeitlin
f4ee8e5369 Fix names of enums and their elements
Use the containing class name as prefix, and add the name of the enum
itself to the prefix for the scoped enums, instead of doing something
strange and semi-random that we did before, with prefixes including the
namespace (which should never be the case without "nspace" feature), but
not the scoped enum.

This also fixes renaming of enum elements, as a side effect, which
didn't work before, add run test for enum_rename unit test to prove it.
2021-11-07 02:14:16 +01:00
Vadim Zeitlin
81d1fec13c Remove code setting unused "c:retval" attribute
This became unused after the changes of fd3e76365 (Streamline and fix
returning objects by value, 2019-08-06) and allows to simplify code
further as we don't need to override static and non-static member
function handlers at all any more now.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
ec4cfd41de Return scoped_dohptr from get_wrapper_func_return_type()
Ensure that the returned pointer is deleted automatically instead of
doing it manually.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
07e7086b39 Generate wrapper function name in a single place
Rename getGlobalWrapperName() to getFunctionWrapperName() and make it
work for all functions, not just global ones.

This means that we can test whether the function is global or not in a
single place instead of doing it in two different ones.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
7e5e6a4cf0 Avoid unnecessary allocations of function name
Use maybe_owned_dohptr in function wrapper code to avoid making a copy
unnecessarily just to be able to Delete() this pointer later.

No real changes.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
4801a3154e Delete never used variables in function wrapper code
No real changes, just don't bother allocating and deleting strings that
are never used at all.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
ad3db88e44 Add maybe_owned_dohptr helper
This class allows to avoid allocating a new DOH object unnecessarily if
we can reuse an existing one.

It is not used yet, but will be soon.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
ca56f14aa5 Refactor scoped_dohptr() to reuse its reset()
No real changes, just avoid some code duplication and add an optional
argument to reset() to make it more compatible with std::unique_ptr<>
and also more flexible.
2021-11-04 01:31:06 +01:00
Vadim Zeitlin
080d3075e3 Rename getNamespacedName() to getProxyName()
This is a more logical name for this function, as it caches its return
value in "proxyname" attribute and doesn't really have much to do with
namespaces.

No real changes.
2021-10-30 21:11:02 +02:00
Vadim Zeitlin
0434b93cc9 Rename getProxyName() to getClassProxyName()
Show that this function only returns non-null result for classes, as
this was not at all obvious before.

No real changes.
2021-10-30 21:09:41 +02:00
Vadim Zeitlin
d7f06c3721 Reuse Swig_string_mangle() instead of using Replaceall()
Use the same function in getNamespacedName() which was already used in
getGlobalWrapperName() just below, this is more readable and more clear
than just replacing dots with underscores as we did before.

Also use scoped_dohptr instead of manual Delete() calls.

No real changes.
2021-10-30 18:51:19 +02:00
Vadim Zeitlin
1fb0de9e00 Don't call Swig_scopename_prefix() unnecessarily
No real changes, just make the code do what the comment said it did and
only use the namespace as prefix when "nspace" feature is on instead of
always trying to use it as prefix and then resetting it.

This required adding default ctor and assignment operator from raw
pointer to scoped_dohptr, but they can be useful elsewhere too, while
the actual code in getGlobalWrapperName() is simpler and more readable
now.

No real changes.
2021-10-30 18:47:12 +02:00
Vadim Zeitlin
2f6f6df211 Generate wrapper aliases only if requested and not by default
Defining the aliases by default results in conflicts when including
headers from multiple modules as e.g. SWIG_PendingException_get() is
defined in all of them, and could also easily result in other unwanted
clashes, so make this opt-in and update the examples and tests relying
on using the wrappers without the module prefix to define
SWIG_DEFINE_WRAPPER_ALIASES explicitly.
2021-10-20 01:57:20 +02:00
Vadim Zeitlin
45bb179407 Expand "$null" in typemaps in C backend too
This is used in some exception-related typemaps, both in SWIG itself
(although they're not used with C backend currently) and outside of it.
2021-10-07 22:03:47 +02:00
Vadim Zeitlin
b5a8ccffa3 Explicitly refuse to wrap vararg functions
They were not supported currently, but processing them resulted in just
a warning about missing ctype typemap and generated uncompilable code.

Give an error and don't generate any code at all now, which is more
clear and helpful.

Also exclude the part of kwargs_feature test using varargs from C test
suite.
2021-10-04 22:09:12 +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
Olly Betts
561a1d843d Fix ODR violations
Detected by compiling with GCC flags `-flto -Wodr`.
2021-09-20 15:04:51 +12:00
Ian Lance Taylor
45ebd33698 swig -go: improve _cgo_panic implementation 2021-09-16 10:29:48 -07: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
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
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
b7a99f22f5 [S-EXP] Remove code for Common Lisp S-Exp
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
Olly Betts
3f78ea64c0 Remove bogus reference to allegrocl:old-sym:name
It'll never be set under -cffi.  Looking at the history it looks like
this is just a remnant from this file being originally created by
copying allegrocl.cxx.
2021-05-13 10:41:01 +12: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
8dadbcc744 [php] Simplify naming of overloaded method wrappers
The underlying wrapper function is now always named using
ZEND_NAMED_FUNCTION even if it's a method (in PHP a function and
a method only differ in how they're used).
2021-05-12 15:05:09 +12:00
Olly Betts
ead90be779 [php] Fix -prefix when there are subclasses
The calls to the parent class' magic __get, __set and __isset methods
weren't getting the prefix.
2021-05-12 15:04:31 +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
e59d34481d Improve comment 2021-05-05 10:34:20 +12:00
Olly Betts
32283991c5 Don't generate a .php wrapper file by default
It's now only generated if something to put in it is specified via:

%pragma(php) include=...

or

%pragma(php) code=...
2021-05-04 14:14:56 +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
592f230295 Remove CG(active_class_entry) = NULL;
This has been in the code for a really long time, and doesn't seem
to be required now.  It's not documented by PHP as something we
need to do, and the value seems to always be NULL at this point
already.
2021-05-04 11:36:24 +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