[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
This commit is contained in:
Olly Betts 2022-01-20 14:42:02 +13:00
commit c417250b4e
3 changed files with 35 additions and 4 deletions

View file

@ -187,8 +187,9 @@ check("' 11 '", 'char *');
# Check TypeError is thrown when the wrong type is passed.
check("array()", NULL);
# FIXME: These need fixing
#check("function(){}", NULL);
#check("new stdClass()", NULL);
check("function(){}", NULL);
check("new stdClass()", NULL);
class NotASwigWrappedClass { };
check("new NotASwigWrappedClass()", NULL);
check::done();