summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2021-12-19 13:03:48 +1300
committerOlly Betts <olly@survex.com>2021-12-19 13:45:25 +1300
commit69b580dfb6e39b5463213908b443a86265bdb23c (patch)
treea50752302231098c7c6a8891afad5ee0408fcde3
parenta7f2c3d19b898d9c1d6e836164cb69df567aa7ff (diff)
downloadswig-69b580dfb6e39b5463213908b443a86265bdb23c.tar.gz
[php] Use SWIG_TypeCheckStruct to check types
We have the swig_type_info available and SWIG_TypeCheckStruct is more efficient because it uses a pointer comparison instead of the string comparison SWIG_TypeCheck uses (this change speeds up `make check-php-test-suite` by about 10%).
-rw-r--r--Lib/php/phprun.swg54
-rw-r--r--Lib/swigrun.swg2
2 files changed, 18 insertions, 38 deletions
diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg
index 426efe104..69b00bc4b 100644
--- a/Lib/php/phprun.swg
+++ b/Lib/php/phprun.swg
@@ -122,42 +122,6 @@ SWIG_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject) {
}
}
-/* This pointer conversion routine takes the native pointer p (along with
- its type name) and converts it by calling appropriate casting functions
- according to ty. The resultant pointer is returned, or NULL is returned
- if the pointer can't be cast.
-
- This is called by SWIG_ConvertPtr which gets the type name from the
- swig_object_wrapper. */
-static void *
-SWIG_ConvertPtrData(void * p, const char *type_name, swig_type_info *ty, int *own) {
- swig_cast_info *tc;
- void *result = 0;
-
- if (!ty) {
- /* They don't care about the target type, so just pass on the pointer! */
- return p;
- }
-
- if (! type_name) {
- /* can't convert p to ptr type ty if we don't know what type p is */
- return NULL;
- }
-
- /* convert and cast p from type_name to ptr as ty. */
- tc = SWIG_TypeCheck(type_name, ty);
- if (tc) {
- int newmemory = 0;
- result = SWIG_TypeCast(tc, p, &newmemory);
- if (newmemory == SWIG_CAST_NEW_MEMORY) {
- assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
- if (own)
- *own |= SWIG_CAST_NEW_MEMORY;
- }
- }
- return result;
-}
-
/* We wrap C/C++ pointers as PHP objects. */
static int
SWIG_ConvertPtrAndOwn(zval *z, void **ptr, swig_type_info *ty, int flags, swig_owntype *own) {
@@ -172,7 +136,23 @@ SWIG_ConvertPtrAndOwn(zval *z, void **ptr, swig_type_info *ty, int flags, swig_o
switch (Z_TYPE_P(z)) {
case IS_OBJECT: {
swig_object_wrapper *value = SWIG_Z_FETCH_OBJ_P(z);
- *ptr = SWIG_ConvertPtrData(value->ptr, value->type->name, ty, own);
+ if (!ty) {
+ /* They don't care about the target type, so just pass on the pointer! */
+ *ptr = value->ptr;
+ } else {
+ swig_cast_info *tc = SWIG_TypeCheckStruct(value->type, ty);
+ if (tc) {
+ int newmemory = 0;
+ *ptr = SWIG_TypeCast(tc, value->ptr, &newmemory);
+ if (newmemory == SWIG_CAST_NEW_MEMORY) {
+ assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
+ if (own)
+ *own |= SWIG_CAST_NEW_MEMORY;
+ }
+ } else {
+ *ptr = NULL;
+ }
+ }
if (*ptr == NULL) return SWIG_ERROR;
if (flags & SWIG_POINTER_DISOWN) {
value->newobject = 0;
diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg
index 5f3159916..de0db2dc3 100644
--- a/Lib/swigrun.swg
+++ b/Lib/swigrun.swg
@@ -290,7 +290,7 @@ SWIG_TypeCheck(const char *c, swig_type_info *ty) {
Identical to SWIG_TypeCheck, except strcmp is replaced with a pointer comparison
*/
SWIGRUNTIME swig_cast_info *
-SWIG_TypeCheckStruct(swig_type_info *from, swig_type_info *ty) {
+SWIG_TypeCheckStruct(const swig_type_info *from, swig_type_info *ty) {
if (ty) {
swig_cast_info *iter = ty->cast;
while (iter) {