Commit graph

222 commits

Author SHA1 Message Date
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
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
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
04bacf689b Implement director-disown for PHP 2021-05-03 16:00:30 +12: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
c705ef8f32 Use PHP objects instead of resources to wrap pointers
Pointer to member is currently still wrapped as a resource.
2021-04-21 15:40:35 +12:00
Olly Betts
26f218327b Don't special case NULL in the REF in typemap
PHP doesn't accept literal NULL for a parameter passed by reference;
passing a variable with a value of NULL is just like passing a
variable with a different value - we get a PHP reference to the
variable, not NULL.
2021-04-20 16:24:18 +12:00
Olly Betts
8d09b1263b Fix GCC -Wsign-compare warning 2021-04-19 17:54:21 +12:00
Olly Betts
175b8d8542 Fix -Wimplicit-fallthrough warnings
We already have the magic comment to do this, but they weren't in
quite the right place.
2021-04-19 16:54:36 +12:00
Olly Betts
90e65e17fc Remote Lib/php/globalvar.i
It's unused since 2629764e3f but it
seems I failed to actually remove it there.
2021-04-19 16:54:36 +12:00
Olly Betts
2f888a851e Fix GCC -Wempty-body warning 2021-04-19 16:54:36 +12:00
Olly Betts
2629764e3f Remove remnants of attempts to wrap to PHP global vars
This isn't really workable since PHP doesn't support intercepting
accesses to global variables (nor to static class properties, so
we can't wrap C/C++ global variables that way either).

The _get() and _set() function wrappers actually work and have
been generated for a very long time.
2021-04-17 05:59:18 +12:00
Olly Betts
dcdaaba7ba Eliminate $zend_obj typemap variable
We can just get the zend_class_entry from the swig_type_info when
we need it.
2021-04-16 13:13:24 +12:00
Olly Betts
97733543e2 Fix directorout typemap for const TYPE &
Previous we were returning a pointer or reference to a local
variable.
2021-04-15 12:50:32 +12:00
Olly Betts
451998f27b Fix in typemap for void** and void*&
Mark the parameter as "byref" and write back through the reference
after the call.

Adjust testcase argout to uncomment the part that's meant to test this,
and to remove lingering traces of PHP's old call-time pass-by-reference
(which was completely removed before PHP 7).

Fixes #1457
2021-04-14 17:05:19 +12:00
Olly Betts
836258b9d3 Fix some cases of converting PHP NULL to C++ NULL
Fixes testcase overload_null for PHP 8.0
2021-04-13 16:53:52 +12:00
Olly Betts
3b43a7bf9b Refactor to eliminate SWIG_ConvertResourcePtr() 2021-04-13 13:22:03 +12:00
Olly Betts
762a309373 Fix typemap formatting incosistencies 2021-04-13 10:31:22 +12:00
Olly Betts
0a72bfc630 Eliminate tempPointer variable 2021-04-13 10:18:47 +12:00
Olly Betts
60e7deda2c Eliminate non-standard $lower_param typemap variable 2021-04-13 10:03:03 +12:00
Olly Betts
d2eb06fbc0 Merge 2 functionally identical typemaps
The only difference is code formatting.
2021-04-13 09:53:14 +12:00
Olly Betts
5161acdd24 Eliminate direct reference to c_result in typemap
Typemaps should use $result.
2021-04-13 09:07:31 +12:00
Olly Betts
9987d7168a Implement type-checking of wrapped objects
The testsuite now all passes (with PHP 7.4 at least)
2021-04-12 17:29:39 +12:00
Olly Betts
8fd2a1cb75 Fix mixed declarations and code
SWIG still aims to generate C90-compatible code.
2021-04-05 17:35:58 +12:00
Olly Betts
f0e0f7e391 Rename userNewObj to newobject
Better to use the same name we use elsewhere.
2021-04-05 17:30:43 +12:00
Olly Betts
40da8bcbb6 php: Wrap classes using only swig_object_wrapper
We no longer use PHP resources to wrap classes, and the proxy classes no
longer has a _cPtr property.
2021-04-04 07:45:20 +12:00
Olly Betts
e0cffb81dd Eliminate SWIG_classWrapper property
Instead set the _cPtr property to PHP NULL to signal that this object
uses swig_object_wrapper.
2021-04-01 15:10:10 +13:00
Olly Betts
5838f10aa0 wrap fake class constants via C API 2021-04-01 14:40:32 +13:00
Olly Betts
c863ca8b1f Use zstring access macros
These are likely to be more future-proof than accessing struct members
directly.
2021-03-29 18:18:37 +13:00
Olly Betts
f56d8ce103 Fix memory leak in director upcall check 2021-03-29 18:17:19 +13:00
Olly Betts
5482a02dd4 Fix handling of strongly-typed enums
Testcase cpp11_strongly_typed_enumerations.cpptest now passes.
2021-03-29 17:53:05 +13:00
Olly Betts
3f1286ba4f Use standard SWIG overload dispatch
Instead of having a slightly modified PHP-specific variant of
Swig_overload_dispatch we now advance the ParmList over the this
pointer.
2021-03-29 17:41:01 +13:00
Olly Betts
4b055c343d Fix compatibility with PHP8 2021-03-28 19:46:51 +13:00
Olly Betts
b45bd65dbc Add compatibility for PHP 7.3 and earlier 2021-03-28 06:58:46 +13:00