Commit Graph

352 Commits

Author SHA1 Message Date
William S Fulton 22a8088a98 Fix -Wunused-variable warning in Lua and Octave wrappers
Add bool output parameter to Swig_overload_dispatch to say when it has
generated code that will use the typecheck typemap code to help Lua and
Octave to not emit unused argv[] arrays.

Alas, resorted to warning suppression for deficient cpp11_initializer_list
typecheck typemap in cpp11_std_initializer_list testcase.
2025-06-23 21:39:49 +01:00
William S Fulton 86498e46c6 Remove -xmllang option used with -xml
which had no effect on the output.
2024-10-15 08:59:51 +01:00
William S Fulton 09001ee302 Add $isvoid special variable expansion for directors
Complete the removal of Ruby's output_helper macro and replacement
with SWIG_AppendOutput for director typemaps.
Requires $isvoid special variable support in director code.
2024-10-06 15:00:37 +01:00
Olly Betts d57ba7f26d Lookup _get and _set methods more efficiently
We now avoid creating a temporary zval holding the method name of
the _get or _set method - only a temporary zend_string is needed
which is lighter weight.

See #2809
2024-09-12 09:09:29 +12:00
Olly Betts 7a8c9fdfa8 Straighten out handling of char and string constants
Fixes #904
Fixes #1907
Fixes #2579
Fixes #2990
2024-08-17 16:12:45 +12:00
William S Fulton 2c70a912a6 Add $isvoid special variable
The $isvoid special variable expands to 1 if the
wrapped function has a void return, otherwise expands to 0.

In the implementation, use a consistent variable name, returntype,
for a node's "type" attribute.

Issue #2907
2024-06-15 23:13:12 +01:00
Olly Betts 818bafcb95 [PHP] Fix memory leak accessing PHP attribute
Fix memory leak when getting or setting a PHP attribute which wraps a
C++ member variable.  Bug introduced in SWIG 4.1.0.

Fixes #2808
2024-02-21 11:01:18 +13:00
Olly Betts 32adf4b3c9 [PHP] Fix %feature(php:allowdynamicproperties, 0)
The handling of this feature now matches other boolean features.
Previously any value set was treated as on.
2023-12-22 09:37:42 +13:00
William S Fulton 84542f6b59 Replace Language::directorsEnabled() with Swig_directors_enabled()
For use outside of the target languages for forthcoming commits
which move adding default constructors/destructors from Language
to Allocate.
2023-07-12 18:44:42 +01:00
Olly Betts b1388bcbf9 Parse storage class more flexibly
Previously we had a hard-coded list of allowed combinations in the
grammar, but this suffers from combinatorial explosion, and results
in a vague `Syntax error in input` error for invalid (and missing)
combinations.

This means we now support a number of cases which are valid C++
but weren't supported.

Fixes #302
Fixes #2079 (friend constexpr)
Fixes #2474 (virtual explicit)
2023-05-11 13:54:30 +12:00
Olly Betts 0fa2ab8945 Removed unused default parameter value 2023-05-08 15:45:12 +12:00
Olly Betts 15b739d60e [PHP] Wrap method with both static and non-static overloads
We now wrap this as a non-static method in PHP, which means the static
form only callable via an object.

Previously this case could end up wrapped as static or non-static
in PHP.  If it was wrapped as static, attempting to call non-static
overloaded forms would crash with a segmentation fault.

See #2544
2023-05-08 15:44:24 +12:00
Olly Betts 9873ff107a Remove remaining traces of PHP7 support
The bulk of this was already removed in
e3b112c69c.
2023-04-20 13:45:30 +12:00
Olly Betts e3b112c69c Remove support for PHP7
PHP7 security support ended 2022-11-28 so it doesn't make sense to
include support for it in the SWIG 4.2.x release series.
2023-04-14 17:38:01 +12:00
William S Fulton 4a8f7a9c46 Visual C++ warning fixes 2022-10-24 18:43:31 +01:00
Olly Betts 747a6a264f [php] Fix handling of multi-module cases
Look up unknown base classes using SWIG_MangledTypeQueryModule().

Revert to using SWIG_TypeCheck() instead of SWIG_TypeCheckStruct()
as the latter doesn't seem to work for this case (at least for PHP
right now).

Add mod_runme.php as a regression test for this.

Adjust the PHP test harness not to set up reflection for the module
unless it's actually needed for a testcase.  Currently the approach
to find the module name doesn't work for multi-module testcases.

See #2126
2022-10-18 10:28:17 +13:00
William S Fulton 46f7501d94 Cleanup SWIG_VERSION definition
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.

Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this

Closes #1050
2022-10-13 19:47:43 +01:00
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
Olly Betts abc1c59c4e [php] Fix emitted PHP type declarations in corner cases
See #2151
2022-10-04 16:09:02 +13:00
Olly Betts c7e1e64538 Prefer !Equal() to Cmp() != 0 2022-10-03 12:44:14 +13:00
Olly Betts 9a4dea06c8 [php] Add php:allowdynamicproperties feature
This follows PHP 8.2 deprecating dynamic features.

The new feature also provides a clean way to fix the remaining PHP
test case failure under PHP 8.2.
2022-09-29 18:16:51 +13:00
Olly Betts cb9c96011a [php] Suppress -Wdeclaration-after-statement in php.h
In PHP 8.2 zend_operators.h contains inline code which triggers this
warning and our testsuite uses with option and -Werror.

I don't see a good way to only do this within our testsuite, but
disabling it globally like this shouldn't be problematic.
2022-09-29 11:06:56 +13:00
Olly Betts 246dd2d787 [php] Workaround PHP 8.2 header problem
We need to include php.h before stdio.h (and probably before most
other libc headers).
2022-09-28 19:01:01 +13:00
Olly Betts 55c95d475c [php] Adapt swig_ptr_cast_object for PHP 8.2
The required return type has changed from int to an enum, which
gives a compiler warning when we assign a function pointer.
2022-09-28 18:59:31 +13:00
Olly Betts dce4254377 [php] Fix handling of friend functions
We were incorrectly considering them as methods of the class they
are a friend of for the purposes of calculate PHP type declarations.
2022-07-29 16:37:22 +12:00
Olly Betts 64fa88c0eb [php] Omit incompatible return type declaraction
Under %feature("php:type", "compat") we don't generate return type
declaration for virtual methods if directors are enabled for that class.
However if a base class of the class has a method of the same name which
isn't directed this was still getting a return type declaration which
caused PHP to give an error when it tried to load the module.

Now we detect this situation and suppress the base class method's
return type declaration too.

Re-enable testcase director_redefined which now works again (it was
failing under PHP8 due to this issue).

See #2151
2022-07-13 16:01:59 +12:00
Olly Betts cfc3888cba [php] Emit arginfo after all the code
Another step in preparation for a fix for the incompatible overridden
method problem discussed in #2151.
2022-07-13 15:21:12 +12:00
Olly Betts 7cf91c12dc php: Move ME and FE generation back out of PHPTypes
It's more natural to leave it where it was, and will work better
when we delay the arginfo generation.
2022-07-11 17:38:34 +12:00
Olly Betts 6503200684 php: Encapsulate arginfo generation
Encapsulate the code to generate arginfo in the PHPTypes class.
By itself this should result in no functional changes, but it's
a step towards being able to delay arginfo generation which I
think is necessary to address the incompatible overridden
method problem discussed in #2151.
2022-07-11 17:23:20 +12:00
Olly Betts cf9422b4d9 [php] Stop setting unused php:proxy attribute
This is no longer used since we changed how classes are wrapped.
2022-07-11 15:32:43 +12:00
Olly Betts f5e2d044df Remove set but not used variables
Highlighted by clang-15 warnings such as:

warning: variable 'index' set but not used [-Wunused-but-set-variable]
2022-06-30 12:52:37 +12:00
Olly Betts 9cdf46e8c8 [php] Adjust #required params for subclass methods
If the same method name is implemented in a parent class then the
subclass can't have more required parameters than that or else we
get a compatibility error when the module is loaded.

The testsuite wasn't catching this problem because it was no longer
trying to load the modules for testcases without _runme.php, because
the mechanism to do that relied on there being a generated .php
wrapper, which we no longer have by default.  Fix that to provide a
regression test for this fix.

See #2151
2022-06-14 16:00:46 +12:00
Olly Betts c95df57976 [php] Fix missing parameter type declarations
In some cases of overloaded functions the parameter type information was
missing for some or all parameters.

See #2151
2022-06-12 09:22:27 +12:00
Olly Betts 2df27036b7 [php] Skip directorout typemap if PHP exception pending
Otherwise can end up with a second PHP exception if the directorout
typemap doesn't accept PHP Null.  `SWIG_fail` in this case results
in us returning to PHP which then propagates the pending exception.

This commit fixes a failure in smoketest.php in Xapian's PHP bindings,
but I've not managed to come up with a reproducer which works for
SWIG's testsuite.
2022-06-10 16:01:05 +12:00
Olly Betts 2de2efb0bb Fix PHP parameter type declarations compatibility
Ensure PHP parameter type declarations are compatible with those for
the same method in any classes we inherit from.

See #2151
2022-06-10 11:12:54 +12:00
Olly Betts d43d62cd7a Revert "Fix PHP parameter type declarations compatibility"
I missed that this change breaks cpp_static, which seems to be to do
with handling the combined getter and setter we emit for static
member variables.  Reverting while I figure out how to handle that.

This reverts commit a277748870.
2022-06-09 17:55:09 +12:00
Olly Betts a277748870 Fix PHP parameter type declarations compatibility
Ensure PHP parameter type declarations are compatible with those for
the same method in any classes we inherit from.

See #2151
2022-06-09 17:36:11 +12:00
Olly Betts a8994d4186 Rename zend_types to be clearer
It's actually tracking pointer types which aren't wrapped as classes.
2022-06-09 12:49:30 +12:00
Olly Betts d7ed1a8b97 [php] Eliminate sprintf to temp buffer to create ZVAL
Use zend_strpprintf() which handles this more cleanly without risk of
buffer overflow and without a fixed length limit.
2022-06-09 09:06:12 +12:00
Olly Betts 97a109ecc9 WIP: Refactor pararent class tracking 2022-06-08 17:41:00 +12:00
William S Fulton 6939d91e4c Header file tidyup
Fix Visual C++ warning in scilab.cxx:
  warning C4996: 'strtok': This function or variable may be unsafe.
2022-05-07 11:56:06 +01:00
Olly Betts 55377bdc08 Add DOH Exit() and SetExitHandler()
Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.

This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.

This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).

Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms.  Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.

Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
2022-03-06 12:33:54 +13:00
Olly Betts 1707d6b89b [PHP] Fix cleanup code handling issues
Fix to call cleanup code in exception situations and not to invoke
the freearg typemap twice in certain situations.

Fixes https://sourceforge.net/p/swig/bugs/1211/
2022-02-17 13:52:44 +13:00
Olly Betts 66488e677d [php] Make zend_function_entry arrays const 2022-01-24 14:09:36 +13:00
Olly Betts 7b929dce82 [php] Fix director upcall check
This resolves an issue uncovered by adding a _runme.php for testcase
director_alternating.
2022-01-22 20:01:00 +13:00
Olly Betts 9b10534879 [php] Make internal function wrappers static 2022-01-22 13:03:58 +13:00
Olly Betts 1c76000e38 [php] Add type declarations for optional params too
See #2151
2022-01-21 16:34:59 +13:00
Olly Betts 91470ca62d [php] Actually generate parameter type declarations 2022-01-21 13:27:54 +13:00
Olly Betts d43f28a666 [php] Use -prefix setting in type declarations 2022-01-21 11:08:24 +13:00
Olly Betts c417250b4e [php] Allow testing if an object is SWIG-wrapped
Since the switch to wrapping classes using PHP's C API, we now
internally need to be able to tell if a PHP object is of or derived
from a class that is wrapped by SWIG so we know if we can offset the
zend_object pointer to get to the swig_object_wrapper.  If we try to
do this to an object which isn't wrapped by SWIG then we invoke C/C++
undefined behaviour (and typically get a segmentation fault).

This check is implemented by having a SWIG\wrapped empty interface which
we make all SWIG-wrapped classes implement simply so we can test for it
to detect such classes.

Fixes #2125
2022-01-20 14:42:02 +13:00