Passing them by value doesn't seem to have any advantages, as the copy
will be made internally anyhow if the original function took them by
value and doing an extra one doesn't seem necessary, but does have a big
drawback of not compiling if the class doesn't define a copy ctor.
We can't rely on the default-generated copy ctor because it simply
copies the (possibly) owned pointer, resulting in double destruction if
it's ever used, so disable it completely unless it is explicitly
declared in the original class, in which case we can wrap it using the C
function wrapper defined for it.
Note that we probably should also wrap default-generated copy ctor of
the original class, if it has any, but currently we don't do it even at
C wrappers level, and so can't do it for C++ wrappers neither.
Replace C::getProxyName() with global get_c_proxy_name() and use it in
cxx_class_wrapper rather than relying on "proxyname" attribute being
already set because this might not be the case if the base class is
defined in another SWIG module just %import'ed from the current one: in
this case, the class is known, but no wrappers had been generated for it
yet, so "proxyname" for it is not set.
Note that, unlike getProxyName(), the new function doesn't bother with
always copying the string, as we may be sure it remains valid as it's
referenced by the node, as one of its attributes.
This allows the generated code to compile when different classes depend
on each other, as the class must be forward-declared to be mentioned at
all (as either parameter or return type) and fully defined in order to
be used in either role, as we need to use its ctor or call swig_self()
on it.
No real changes, just prepare for adding more File objects to be used
for C++ wrappers generation: we can't generate all of them in a single
pass because there may be dependencies between classes.
This required slightly changing the approach used for resolving types in
emit_member_function(), as we can't resolve the type and the casts
to/from it independently any more, but need to do both at once, as this
is required when it's done indirectly due to $typemap() expansion, and
we can't make "return" part of the returned wrapper as we could end with
multiple "returns".
So replace expr_wrapper with type_desc containing both the wrappers and
the type itself and add "return" in emit_member_function() itself for
non-void functions. Also use IIFE so that we can always just prepend
this "return" in the beginning.
Also connect things up so that C++-specific type resolution function is
used while C++ wrappers are being generated.
This fixes e.g. li_boost_shared_ptr unit test, which uses Space::Klass
that should be known as just Klass (inside the outer namespace) in the
generated C++ wrappers.
Disable them for the test suite, as plenty things don't work yet, but
there is already more than enough code to not want to add even more
fixes to the same commit.
After making this mistake too many times already, make sure it doesn't
happen again by requiring gcc to give an error for any attempt to pass
a non-trivial object to vararg functions such as Printv(), Printf(),
Swig_error() etc.
Write the wrapper types and declarations directly to f_wrappers_h,
without passing by an intermediate f_wrappers_h_body which just
complicated things unnecessarily.
This means that "extern "C" { ... }" is now around the functions
declarations only, and not around the types and the declarations, but
this seems like a desirable side effect.
No real changes.
Also explain better what each of them is used for and use scoped_dohptr
instead of deleting them manually.
Stop writing everything to f_begin, which didn't make any sense, and use
a separate f_wrappers_cxx object for the contents of the cxx output file.
No real changes.
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.
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
`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
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.
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