Refactor code to rename class entry variables and ConvertPtr to work with wrapped objects.
- Rename class entry variables to SWIGTYPE_class_ce - Refactor factory code to use SWIGTYPE_class_ce to create objects - Refactor ConvertPtr to work of wrapped class objects.
This commit is contained in:
parent
9fea6fc5ac
commit
4252b31f8f
4 changed files with 27 additions and 36 deletions
|
|
@ -12,18 +12,18 @@
|
||||||
unsigned char,
|
unsigned char,
|
||||||
signed char,
|
signed char,
|
||||||
enum SWIGTYPE
|
enum SWIGTYPE
|
||||||
"zend_declare_class_constant_long($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
"zend_declare_class_constant_long(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
||||||
|
|
||||||
%typemap(classconsttab) bool
|
%typemap(classconsttab) bool
|
||||||
"zend_declare_class_constant_bool($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
"zend_declare_class_constant_bool(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
||||||
|
|
||||||
%typemap(classconsttab) float,
|
%typemap(classconsttab) float,
|
||||||
double
|
double
|
||||||
"zend_declare_class_constant_double($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
"zend_declare_class_constant_double(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, $value);";
|
||||||
|
|
||||||
%typemap(classconsttab) char,
|
%typemap(classconsttab) char,
|
||||||
string
|
string
|
||||||
"zend_declare_class_constant_string($class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, \"$value\");";
|
"zend_declare_class_constant_string(SWIGTYPE_$class_ce, \"$const_name\", sizeof(\"$const_name\") - 1, \"$value\");";
|
||||||
|
|
||||||
%typemap(consttab) int,
|
%typemap(consttab) int,
|
||||||
unsigned int,
|
unsigned int,
|
||||||
|
|
|
||||||
|
|
@ -95,14 +95,7 @@ if (!dcast) {
|
||||||
Type *dobj = dynamic_cast<Type *>($1);
|
Type *dobj = dynamic_cast<Type *>($1);
|
||||||
if (dobj) {
|
if (dobj) {
|
||||||
dcast = 1;
|
dcast = 1;
|
||||||
zend_object *std = NULL;
|
zend_object *std = $descriptor(Type)##_ce->create_object($descriptor(Type)##_ce);
|
||||||
if ($newobj) {
|
|
||||||
zend_class_entry *ce = zend_lookup_class(zend_string_init("Type", sizeof("Type")-1, 0));
|
|
||||||
std = ce->create_object(ce);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std = $zend_obj;
|
|
||||||
}
|
|
||||||
SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, SWIG_as_voidptr(dobj), $descriptor(Type *), std);
|
SWIG_SetZval(return_value, $classZv, $owner, $newobj, $c_obj, SWIG_as_voidptr(dobj), $descriptor(Type *), std);
|
||||||
}
|
}
|
||||||
}%enddef
|
}%enddef
|
||||||
|
|
|
||||||
|
|
@ -196,6 +196,13 @@ SWIG_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags) {
|
||||||
return SWIG_ConvertResourceData(p, type_name, ty);
|
return SWIG_ConvertResourceData(p, type_name, ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv))
|
||||||
|
|
||||||
|
static inline
|
||||||
|
swig_object_wrapper * php_fetch_object(zend_object *obj) {
|
||||||
|
return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std));
|
||||||
|
}
|
||||||
|
|
||||||
/* We allow passing of a RESOURCE pointing to the object or an OBJECT whose
|
/* We allow passing of a RESOURCE pointing to the object or an OBJECT whose
|
||||||
_cPtr is a resource pointing to the object */
|
_cPtr is a resource pointing to the object */
|
||||||
static int
|
static int
|
||||||
|
|
@ -211,17 +218,15 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) {
|
||||||
if (ht) {
|
if (ht) {
|
||||||
zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1);
|
zval * _cPtr = zend_hash_str_find(ht, "_cPtr", sizeof("_cPtr") - 1);
|
||||||
if (_cPtr) {
|
if (_cPtr) {
|
||||||
|
if (zend_hash_str_exists(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1)) {
|
||||||
|
*ptr = SWIG_Z_FETCH_OBJ_P(z)->ptr;
|
||||||
|
return (*ptr == NULL ? -1 : 0);
|
||||||
|
}
|
||||||
if (Z_TYPE_P(_cPtr) == IS_INDIRECT) {
|
if (Z_TYPE_P(_cPtr) == IS_INDIRECT) {
|
||||||
_cPtr = Z_INDIRECT_P(_cPtr);
|
_cPtr = Z_INDIRECT_P(_cPtr);
|
||||||
}
|
}
|
||||||
if (Z_TYPE_P(_cPtr) == IS_RESOURCE) {
|
if (Z_TYPE_P(_cPtr) == IS_RESOURCE) {
|
||||||
zval *zv;
|
*ptr = SWIG_ConvertResourcePtr(_cPtr, ty, flags);
|
||||||
if (!zend_hash_str_exists(ht, "SWIG_classWrapper", sizeof("SWIG_classWrapper") - 1))
|
|
||||||
zv = _cPtr;
|
|
||||||
else
|
|
||||||
zv = z;
|
|
||||||
|
|
||||||
*ptr = SWIG_ConvertResourcePtr(zv, ty, flags);
|
|
||||||
return (*ptr == NULL ? -1 : 0);
|
return (*ptr == NULL ? -1 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -239,13 +244,6 @@ SWIG_ConvertPtr(zval *z, void **ptr, swig_type_info *ty, int flags) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SWIG_Z_FETCH_OBJ_P(zv) php_fetch_object(Z_OBJ_P(zv))
|
|
||||||
|
|
||||||
static inline
|
|
||||||
swig_object_wrapper * php_fetch_object(zend_object *obj) {
|
|
||||||
return (swig_object_wrapper *)((char *)obj - XtOffsetOf(swig_object_wrapper, std));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj ,swig_type_info *type) {
|
SWIG_generalize_object(zval *zval_obj, void *ptr, int class_obj, int userNewObj ,swig_type_info *type) {
|
||||||
swig_object_wrapper *obj = NULL;
|
swig_object_wrapper *obj = NULL;
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ static void print_creation_free_wrapper(int item_index) {
|
||||||
need_free = true;
|
need_free = true;
|
||||||
|
|
||||||
Printf(s_header, "/* class entry for %s */\n",class_name);
|
Printf(s_header, "/* class entry for %s */\n",class_name);
|
||||||
Printf(s_header, "zend_class_entry *%s_ce;\n\n",class_name);
|
Printf(s_header, "zend_class_entry *SWIGTYPE_%s_ce;\n\n",class_name);
|
||||||
Printf(s_header, "/* class object handlers for %s */\n",class_name);
|
Printf(s_header, "/* class object handlers for %s */\n",class_name);
|
||||||
Printf(s_header, "zend_object_handlers %s_object_handlers;\n\n",class_name);
|
Printf(s_header, "zend_object_handlers %s_object_handlers;\n\n",class_name);
|
||||||
|
|
||||||
|
|
@ -1213,7 +1213,7 @@ public:
|
||||||
Printf(f->code, " newSize += arg2->len + strlen(\"_get\");\nmethod_name = (char *)malloc(newSize);\n");
|
Printf(f->code, " newSize += arg2->len + strlen(\"_get\");\nmethod_name = (char *)malloc(newSize);\n");
|
||||||
Printf(f->code, " strcpy(method_name,arg2->val);\nstrcat(method_name,\"_get\");\n\n");
|
Printf(f->code, " strcpy(method_name,arg2->val);\nstrcat(method_name,\"_get\");\n\n");
|
||||||
|
|
||||||
Printf(magic_isset, "\nelse if (zend_hash_exists(&%s_ce->function_table, zend_string_init(method_name, newSize-1, 0))) {\n",class_name);
|
Printf(magic_isset, "\nelse if (zend_hash_exists(&SWIGTYPE_%s_ce->function_table, zend_string_init(method_name, newSize-1, 0))) {\n",class_name);
|
||||||
Printf(magic_isset, "RETVAL_TRUE;\n}\n");
|
Printf(magic_isset, "RETVAL_TRUE;\n}\n");
|
||||||
|
|
||||||
Printf(f->code, "if (!arg2) {\n RETVAL_FALSE;\n}\n",magic_set);
|
Printf(f->code, "if (!arg2) {\n RETVAL_FALSE;\n}\n",magic_set);
|
||||||
|
|
@ -1645,7 +1645,7 @@ public:
|
||||||
Replaceall(tm, "$classZv", constructor ? "getThis()" : "NULL");
|
Replaceall(tm, "$classZv", constructor ? "getThis()" : "NULL");
|
||||||
if (retType_class) {
|
if (retType_class) {
|
||||||
String *retZend_obj = NewStringEmpty();
|
String *retZend_obj = NewStringEmpty();
|
||||||
Printf(retZend_obj, "%s_object_new(%s_ce)", retType_class, retType_class);
|
Printf(retZend_obj, "%s_object_new(SWIGTYPE_%s_ce)", retType_class, retType_class);
|
||||||
Replaceall(tm, "$zend_obj", retType_valid ? (constructor ? "NULL" : (valid_wrapped_class ? retZend_obj : "NULL")) : "NULL");
|
Replaceall(tm, "$zend_obj", retType_valid ? (constructor ? "NULL" : (valid_wrapped_class ? retZend_obj : "NULL")) : "NULL");
|
||||||
}
|
}
|
||||||
Replaceall(tm, "$zend_obj", "NULL");
|
Replaceall(tm, "$zend_obj", "NULL");
|
||||||
|
|
@ -2749,13 +2749,13 @@ done:
|
||||||
Append(class_types, class_type);
|
Append(class_types, class_type);
|
||||||
Append(class_need_free, "0");
|
Append(class_need_free, "0");
|
||||||
|
|
||||||
Printf(s_oinit, "\nzend_class_entry %s_internal_ce;\n", class_name);
|
Printf(s_oinit, "\nzend_class_entry SWIGTYPE_%s_internal_ce;\n", class_name);
|
||||||
|
|
||||||
// namespace code to introduce namespaces into wrapper classes.
|
// namespace code to introduce namespaces into wrapper classes.
|
||||||
//if (nameSpace != NULL)
|
//if (nameSpace != NULL)
|
||||||
//Printf(s_oinit, "INIT_CLASS_ENTRY(%s_internal_ce, \"%s\\\\%s\", class_%s_functions);\n", class_name, nameSpace ,class_name, class_name);
|
//Printf(s_oinit, "INIT_CLASS_ENTRY(%s_internal_ce, \"%s\\\\%s\", class_%s_functions);\n", class_name, nameSpace ,class_name, class_name);
|
||||||
//else
|
//else
|
||||||
Printf(s_oinit, "INIT_CLASS_ENTRY(%s_internal_ce, \"%s\", class_%s_functions);\n", class_name, class_name, class_name);
|
Printf(s_oinit, "INIT_CLASS_ENTRY(SWIGTYPE_%s_internal_ce, \"%s\", class_%s_functions);\n", class_name, class_name, class_name);
|
||||||
|
|
||||||
if (shadow) {
|
if (shadow) {
|
||||||
char *rename = GetChar(n, "sym:name");
|
char *rename = GetChar(n, "sym:name");
|
||||||
|
|
@ -2802,15 +2802,15 @@ done:
|
||||||
baseClassExtend = NewString(class_name);
|
baseClassExtend = NewString(class_name);
|
||||||
Append(baseClassExtend, "_Exception");
|
Append(baseClassExtend, "_Exception");
|
||||||
|
|
||||||
Printf(s_oinit, "zend_class_entry *%s_ce = zend_lookup_class(zend_string_init(\"Exception\", sizeof(\"Exception\") - 1, 0));\n", baseClassExtend);
|
Printf(s_oinit, "zend_class_entry *SWIGTYPE_%s_ce = zend_lookup_class(zend_string_init(\"Exception\", sizeof(\"Exception\") - 1, 0));\n", baseClassExtend);
|
||||||
exceptionClassFlag = true;
|
exceptionClassFlag = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseClassExtend && (exceptionClassFlag || is_class_wrapped(baseClassExtend))) {
|
if (baseClassExtend && (exceptionClassFlag || is_class_wrapped(baseClassExtend))) {
|
||||||
Printf(s_oinit, "%s_ce = zend_register_internal_class_ex(&%s_internal_ce, %s_ce);\n", class_name , class_name, baseClassExtend);
|
Printf(s_oinit, "SWIGTYPE_%s_ce = zend_register_internal_class_ex(&SWIGTYPE_%s_internal_ce, SWIGTYPE_%s_ce);\n", class_name , class_name, baseClassExtend);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Printf(s_oinit, "%s_ce = zend_register_internal_class(&%s_internal_ce);\n", class_name , class_name);
|
Printf(s_oinit, "SWIGTYPE_%s_ce = zend_register_internal_class(&SWIGTYPE_%s_internal_ce);\n", class_name , class_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
@ -2834,11 +2834,11 @@ done:
|
||||||
}
|
}
|
||||||
Chop(append_interface);
|
Chop(append_interface);
|
||||||
Replaceall(append_interface, " ", ",");
|
Replaceall(append_interface, " ", ",");
|
||||||
Printf(s_oinit, "zend_class_implements(%s_ce, %d, %s);\n", class_name, num_interfaces, append_interface);
|
Printf(s_oinit, "zend_class_implements(SWIGTYPE_%s_ce, %d, %s);\n", class_name, num_interfaces, append_interface);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Printf(s_oinit, "%s_ce->create_object = %s_object_new;\n", class_name, class_name);
|
Printf(s_oinit, "SWIGTYPE_%s_ce->create_object = %s_object_new;\n", class_name, class_name);
|
||||||
Printf(s_oinit, "memcpy(&%s_object_handlers,zend_get_std_object_handlers(), sizeof(zend_object_handlers));\n", class_name);
|
Printf(s_oinit, "memcpy(&%s_object_handlers,zend_get_std_object_handlers(), sizeof(zend_object_handlers));\n", class_name);
|
||||||
Printf(s_oinit, "%s_object_handlers.clone_obj = NULL;\n\n", class_name);
|
Printf(s_oinit, "%s_object_handlers.clone_obj = NULL;\n\n", class_name);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue