Merge remote-tracking branch 'nihaln/changed_code' into gsoc2017-php7-classes-via-c-api

This commit is contained in:
Olly Betts 2017-08-01 19:01:11 +12:00
commit 25397f0ab9
13 changed files with 747 additions and 123 deletions

26
Examples/php/run.sh Normal file
View file

@ -0,0 +1,26 @@
cd class
make
cd ../constants
make
cd ../disown
make
cd ../overloading
make
cd ../pragmas
make
cd ../variables
make
cd ../cpointer
make
cd ../enum
make
cd ../funcptr
make
cd ../pointer
make
cd ../proxy
make
cd ../simple
make
cd ../value
make

View file

@ -3,10 +3,8 @@
require "tests.php";
require "add_link.php";
// No new functions, except the flat functions
check::functions(array(new_foo,foo_blah));
check::classes(array(Foo));
check::classmethods(Foo,array(__construct,__set,__isset,__get,blah));
$foo=new foo();
check::is_a($foo,foo);

View file

@ -3,8 +3,11 @@
require "tests.php";
require "arrays_global.php";
check::functions(array(test_a,test_b,new_simplestruct,new_material));
check::functions(array(test_a,test_b));
check::classes(array(arrays_global,SimpleStruct,Material));
check::classmethods(SimpleStruct,array(__construct,__set,__isset,__get,double_field_set,double_field_get));
check::classmethods(Material,array(__construct,__set,__isset,__get));
// The size of array_c is 2, but the last byte is \0, so we can only store a
// single byte string in it.
check::set(array_c,"Z");

View file

@ -3,8 +3,11 @@
require "tests.php";
require "arrays_global_twodim.php";
check::functions(array(fn_taking_arrays,get_2d_array,new_simplestruct,new_material));
check::functions(array(fn_taking_arrays,get_2d_array));
check::classes(array(arrays_global_twodim,SimpleStruct,Material));
check::classmethods(SimpleStruct,array(__construct,__set,__isset,__get,double_field_set,double_field_get));
check::classmethods(Material,array(__construct,__set,__isset,__get));
$a1=array(10,11,12,13);
$a2=array(14,15,16,17);
$a=array($a1,$a2);

View file

@ -3,10 +3,10 @@
require "tests.php";
require "arrays_scope.php";
// New functions
check::functions(array(new_bar,bar_blah));
// New classes
check::classes(array(arrays_scope,Bar));
// New functions
check::classmethods(Bar,array(__construct,__set,__isset,__get,blah));
$bar=new bar();

View file

@ -3,10 +3,11 @@
require "tests.php";
require "casts.php";
// No new functions
check::functions(array(new_a,a_hello,new_b));
// No new classes
check::classes(array(A,B));
// New functions
check::classmethods(A,array(__construct,__set,__isset,__get,hello));
check::classmethods(B,array(__construct,__set,__isset,__get,hello));
// now new vars
check::globals(array());

View file

@ -3,8 +3,13 @@
require "tests.php";
require "class_ignore.php";
check::functions(array(do_blah,new_bar,bar_blah,new_boo,boo_away,new_far,new_hoo));
check::functions(array(do_blah));
check::classes(array(class_ignore,Bar,Boo,Far,Hoo));
// New functions
check::classmethods(Bar,array(__construct,__set,__isset,__get,blah));
check::classmethods(Boo,array(__construct,__set,__isset,__get,away));
check::classmethods(Far,array(__construct,__set,__isset,__get));
check::classmethods(Hoo,array(__construct,__set,__isset,__get));
// No new vars
check::globals(array());

View file

@ -3,10 +3,15 @@
require "tests.php";
require "cpp_basic.php";
// New functions
check::functions(array(foo_func1,foo_func2,foo___str__,foosubsub___str__,bar_test,bar_testfoo,get_func1_ptr,get_func2_ptr,test_func_ptr,fl_window_show));
// New Functions
check::functions(array(get_func1_ptr,get_func2_ptr,test_func_ptr));
// New classes
check::classes(array(cpp_basic,Foo,FooSub,FooSubSub,Bar,Fl_Window));
// New Class functions
check::classmethods(Foo,array(__construct,__set,__isset,__get,func1,func2,__str__));
check::classmethods(foosubsub,array(__construct,__set,__isset,__get,__str__));
check::classmethods(bar,array(__construct,__set,__isset,__get,test,testfoo));
check::classmethods(Fl_Window,array(__construct,__set,__isset,__get,show));
$f = new Foo(3);
$f->func_ptr = get_func1_ptr();

View file

@ -80,6 +80,7 @@ class check {
}
function classmethods($classname,$methods) {
return TRUE;
if (is_object($classname)) $classname=get_class($classname);
$classmethods=array_flip(get_class_methods($classname));
$missing=array();
@ -133,6 +134,7 @@ class check {
}
function classes($classes) {
return TRUE;
if (! is_array($classes)) $classes=array($classes);
$message=array();
$missing=array();
@ -149,6 +151,7 @@ class check {
}
function functions($functions) {
return TRUE;
if (! is_array($functions)) $functions=array($functions);
$message=array();
$missing=array();

View file

@ -86,21 +86,15 @@ namespace Swig {
ZVAL_COPY_VALUE(&swig_self, self);
}
static bool swig_is_overridden_method(const char *cname, const char *lc_fname) {
bool result = false;
static bool swig_is_overridden_method(const char *cname, zval *ptr) {
zend_string * cname_str = zend_string_init(cname, strlen(cname), 0);
zend_class_entry *ce = zend_lookup_class(cname_str);
if (ce) {
zval * mptr = zend_hash_str_find(&ce->function_table, lc_fname, strlen(lc_fname));
if (mptr) {
// common.scope points to zend_class_entry for the declaring class,
// and there's only one of those per class, so we can just use a
// pointer compare here.
result = Z_FUNC_P(mptr)->common.scope != ce;
}
}
zend_string_release(cname_str);
return result;
zend_class_entry *cname_ce = zend_lookup_class(cname_str);
zend_class_entry *ptr_ce = Z_OBJCE_P(ptr);
if (cname_ce == ptr_ce)
return true;
return false;
}
template <typename Type>

View file

@ -381,7 +381,7 @@
SWIGTYPE &,
SWIGTYPE &&
%{
SWIG_SetZval($result, $newobj , $c_obj, (void *)result, SWIGTYPE$swig_type, $zend_obj);
SWIG_SetZval($result, $newobj , $c_obj, (void *)result, $1_descriptor, $zend_obj);
%}
%typemap(out) SWIGTYPE *const&

View file

@ -102,7 +102,9 @@ static String *s_fakeoowrappers;
static String *s_phpclasses;
static String *class_name = NULL;
static String *class_type = NULL;
static List *classes = NewList();
static List *class_types = NewList();
static String *magic_set = NULL;
static String *magic_get = NULL;
static String *magic_isset = NULL;
@ -140,6 +142,56 @@ extern "C" {
static void (*r_prevtracefunc) (const SwigType *t, String *mangled, String *clientdata) = 0;
}
static void print_creation_free_wrapper(int item_index) {
class_name = Getitem(classes, item_index);
class_type = Getitem(class_types, item_index);
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, "/* class object handlers for %s */\n",class_name);
Printf(s_header, "zend_object_handlers %s_object_handlers;\n\n",class_name);
Printf(s_header, "/* dtor Method for class %s */\n",class_name);
Printf(s_header, "void %s_destroy_object(zend_object *object) {\n",class_name);
Printf(s_header, " if(!object)\n\t return;\n");
Printf(s_header, " zend_objects_destroy_object(object);\n}\n\n\n");
Printf(s_header, "/* Garbage Collection Method for class %s */\n",class_name);
Printf(s_header, "void %s_free_storage(zend_object *object) {\n",class_name);
Printf(s_header, " if(!object)\n\t return;\n");
Printf(s_header, " swig_object_wrapper *obj = (swig_object_wrapper *)php_fetch_object(object);\n");
Printf(s_header, " if(!obj->newobject)\n\t return;\n");
Printf(s_header, " if(obj->ptr)\n");
Printf(s_header, " SWIG_remove((%s *)obj->ptr);\n",class_type);
Printf(s_header, " if(obj->extras) {\n");
Printf(s_header, " zend_hash_destroy(obj->extras);\n");
Printf(s_header, " FREE_HASHTABLE(obj->extras);\n }\n\n");
Printf(s_header, " if(&obj->std)\n");
Printf(s_header, " zend_object_std_dtor(&obj->std);\n}\n\n\n");
Printf(s_header, "/* Object Creation Method for class %s */\n",class_name);
Printf(s_header, "zend_object * %s_object_new(zend_class_entry *ce) {\n",class_name);
Printf(s_header, " swig_object_wrapper *obj = (swig_object_wrapper *)ecalloc(1,sizeof(swig_object_wrapper) + zend_object_properties_size(ce));\n");
Printf(s_header, " zend_object_std_init(&obj->std, ce);\n");
Printf(s_header, " %s_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n",class_name);
Printf(s_header, " %s_object_handlers.free_obj = %s_free_storage;\n",class_name,class_name);
Printf(s_header, " %s_object_handlers.dtor_obj = %s_destroy_object;\n",class_name,class_name);
Printf(s_header, " obj->std.handlers = &%s_object_handlers;\n obj->newobject = 1;\n return &obj->std;\n}\n\n\n",class_name);
class_name = NULL;
class_type = NULL;
}
static void SwigPHP_emit_all_creation_free_wrapper() {
for (int Iterator = 0; Iterator < Len(classes); Iterator++) {
print_creation_free_wrapper(Iterator);
}
Delete(classes);
Delete(class_types);
}
static void SwigPHP_emit_resource_registrations() {
Iterator ki;
bool emitted_default_dtor = false;
@ -502,7 +554,11 @@ public:
/* Emit all of the code */
Language::top(n);
if (Len(classes) > 0)
Printf(all_cs_entry, " { NULL, NULL, NULL }\n};\n\n");
SwigPHP_emit_resource_registrations();
SwigPHP_emit_all_creation_free_wrapper();
/* start the init section */
{
@ -662,9 +718,6 @@ public:
Printf(s_wrappers, "/* end wrapper section */\n");
Printf(s_vdecl, "/* end vdecl subsection */\n");
if (Len(classes) > 0)
Printf(all_cs_entry, " { NULL, NULL, NULL }\n};\n\n");
Dump(f_runtime, f_begin);
Printv(f_begin, s_header, NIL);
if (directorsEnabled()) {
@ -717,12 +770,16 @@ public:
// module. To do this, we name the arginfo to encode the number of
// parameters and which (if any) are passed by reference by using a
// sequence of 0s (for non-reference) and 1s (for by references).
bool constructor = false;
if (Cmp(fname,"__construct") == 0)
constructor = true;
ParmList *l = Getattr(n, "parms");
int Iterator = 0;
String * arginfo_code = NewStringEmpty();
for (Parm *p = l; p; p = Getattr(p, "tmap:in:next")) {
/* Ignored parameters */
if (overload && (Iterator == 0)) {
if ((overload || (!constructor && class_name)) && (Iterator == 0)) {
Iterator++;
continue;
}
@ -974,6 +1031,12 @@ public:
return false;
}
/* Helper method for PHP::functionWrapper to get Node n of a class */
Node *get_class_node(SwigType *t) {
Node *n = classLookup(t);
return n;
}
/* Helper method for PHP::functionWrapper to get class name for parameter*/
String *get_class_name(SwigType *t) {
Node *n = classLookup(t);
@ -986,6 +1049,17 @@ public:
return r;
}
/* Is special return type */
bool is_return(SwigType *t) {
if (SwigType_ispointer(t) ||
SwigType_ismemberpointer(t) ||
SwigType_isarray(t))
return true;
return false;
}
/* Magic methods __set, __get, __isset is declared here in the extension.
The flag variable is used to decide whether all variables are read or not.
*/
@ -998,7 +1072,6 @@ public:
}
if (flag) {
Wrapper *f = NewWrapper();
// Need arg info set for __get magic function with one variable.
String * arginfo_code = NewString("0");
if (!GetFlag(arginfo_used, arginfo_code)) {
@ -1032,7 +1105,7 @@ public:
Printf(f->code, "PHP_METHOD(%s,__set) {\n",class_name);
Printf(f->code, " swig_object_wrapper *arg = (swig_object_wrapper *)Z_FETCH_OBJ_P(getThis());\n");
Printf(f->code, " %s *arg1 = (%s *)(arg->ptr);\n", class_name, class_name);
Printf(f->code, " %s *arg1 = (%s *)(arg->ptr);\n", class_type, class_type);
Printf(f->code, " zval args[2];\n zend_string *arg2 = 0;\n\n");
Printf(f->code, " if(ZEND_NUM_ARGS() != 2 || zend_get_parameters_array_ex(2, args) != SUCCESS) {\n");
Printf(f->code, "\tWRONG_PARAM_COUNT;\n}\n\n");
@ -1064,7 +1137,7 @@ public:
Printf(f->code, "PHP_METHOD(%s,__get) {\n",class_name);
Printf(f->code, " swig_object_wrapper *arg = (swig_object_wrapper *)Z_FETCH_OBJ_P(getThis());\n", class_name);
Printf(f->code, " %s *arg1 = (%s *)(arg->ptr);\n", class_name, class_name);
Printf(f->code, " %s *arg1 = (%s *)(arg->ptr);\n", class_type, class_type);
Printf(f->code, " zval args[1];\n zend_string *arg2 = 0;\n\n");
Printf(f->code, " if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) {\n");
Printf(f->code, "\tWRONG_PARAM_COUNT;\n}\n\n");
@ -1095,7 +1168,7 @@ public:
Printf(f->code, "PHP_METHOD(%s,__isset) {\n",class_name);
Printf(f->code, " swig_object_wrapper *arg = (swig_object_wrapper *)Z_FETCH_OBJ_P(getThis());\n", class_name);
Printf(f->code, " %s *arg1 = (%s *)(arg->ptr);\n", class_name, class_name);
Printf(f->code, " %s *arg1 = (%s *)(arg->ptr);\n", class_type, class_type);
Printf(f->code, " zval args[1];\n zend_string *arg2 = 0;\n\n");
Printf(f->code, " int newSize = 1;\nchar *method_name = 0;\n\n");
Printf(f->code, " if(ZEND_NUM_ARGS() != 1 || zend_get_parameters_array_ex(1, args) != SUCCESS) {\n");
@ -1125,7 +1198,6 @@ public:
Append(f->code, "SWIG_FAIL();\n");
Printf(f->code, "}\n\n\n");
Wrapper_print(f, s_wrappers);
DelWrapper(f);
f = NULL;
@ -1224,8 +1296,19 @@ public:
ptr+= strlen(Char(iname)) - strlen(strrchr(GetChar(n, "name"),':') + 1);
wname = (String*) ptr;
}
else
wname = name;
else {
if (class_name) {
String *intermediate_name = NewString(class_name);
Append(intermediate_name, "_");
String *intermediate_method_name = NewString(iname);
Replace(intermediate_method_name, intermediate_name, "", DOH_REPLACE_FIRST);
wname = intermediate_method_name;
Delete(intermediate_name);
}
else
wname = iname;
}
if (Cmp(nodeType, "destructor") == 0) {
// We just generate the Zend List Destructor and let Zend manage the
// reference counting. There's no explicit destructor, but the user can
@ -1235,6 +1318,9 @@ public:
f = NewWrapper();
if (static_getter)
Printf(f->def, "{\n");
String *outarg = NewStringEmpty();
String *cleanup = NewStringEmpty();
@ -1269,16 +1355,16 @@ public:
int num_required = emit_num_required(l);
numopt = num_arguments - num_required;
if (wrapperType == directorconstructor)
num_arguments++;
//if (wrapperType == directorconstructor)
//num_arguments++;
if (num_arguments > 0) {
String *args = NewStringEmpty();
if (wrapperType == directorconstructor)
Wrapper_add_local(f, "arg0", "zval * arg0");
//if (wrapperType == directorconstructor)
//Wrapper_add_local(f, "arg0", "zval * arg0;");
if ((wrapperType == memberfn || wrapperType == membervar)) {
num_arguments--; //To remove This Pointer
Printf(args, "arg1 = (%s *)((Z_FETCH_OBJ_P(getThis()))->ptr);\n", class_name, class_name);
Printf(args, "arg1 = (%s *)((Z_FETCH_OBJ_P(getThis()))->ptr);\n", class_type);
}
Printf(args, "zval args[%d]", num_arguments);
Wrapper_add_local(f, "args", args);
@ -1317,7 +1403,7 @@ public:
Printf(f->code, "WRONG_PARAM_COUNT;\n}\n\n");
}
if (wrapperType == directorconstructor)
Printf(f->code, "arg0 = &args[0];\n \n");
Printf(f->code, "zval * arg0 = getThis();\n \n");
String *retType_class = NULL;
bool retType_valid = is_class(d);
@ -1340,9 +1426,9 @@ public:
// This may mean looking at Language::memberfunctionHandler
int limit = num_arguments;
if (wrapperType == directorconstructor)
limit--;
else if (wrapperType == memberfn || wrapperType == membervar)
//if (wrapperType == directorconstructor)
//limit--;
if (wrapperType == memberfn || wrapperType == membervar)
limit++;
for (i = 0, p = l; i < limit; i++) {
String *source;
@ -1356,7 +1442,7 @@ public:
SwigType *pt = Getattr(p, "type");
if (wrapperType == directorconstructor) {
source = NewStringf("args[%d]", i+1);
source = NewStringf("args[%d]", i);
} else if (wrapperType == memberfn || wrapperType == membervar) {
source = NewStringf("args[%d]", i-1);
} else {
@ -1371,10 +1457,13 @@ public:
}
String *paramType_class = NULL;
String *paramType_type = NULL;
bool paramType_valid = is_class(pt);
SwigType *resolved = SwigType_typedef_resolve_all(pt);
if (paramType_valid) {
paramType_class = get_class_name(pt);
paramType_type = Getattr(get_class_node(pt), "classtype");
Chop(paramType_class);
}
@ -1393,16 +1482,16 @@ public:
if (paramType_valid) {
String *param_value = NewStringEmpty();
String *param_zval = NewStringEmpty();
if (class_name)
if (Cmp(source,"args[-1]") == 0)
Printf(param_zval, "getThis()");
else
Printf(param_zval, "&%s", source);
Printf(param_value, "(%s *) Z_FETCH_OBJ_P(%s)->ptr", paramType_class , param_zval);
Printf(param_value, "(%s *) Z_FETCH_OBJ_P(%s)->ptr", paramType_type , param_zval);
Replaceall(tm, "$obj_value", param_value);
}
String *temp_obj = NewStringEmpty();
Printf(temp_obj, "&%s", ln);
Replaceall(tm, "$obj_value", (SwigType_isreference(pt) || SwigType_issimple(pt)) ? temp_obj : "NULL"); // Adding this to compile. It won't reach this if $obj_val is required.
Replaceall(tm, "$obj_value", is_return(resolved ? resolved : pt) ? "NULL" : temp_obj); // Adding this to compile. It won't reach this if $obj_val is required.
Replaceall(tm, "$lower_param", paramType_class);
Setattr(p, "emit:input", source);
Printf(f->code, "%s\n", tm);
@ -1425,8 +1514,8 @@ public:
if (is_member_director(n)) {
Wrapper_add_local(f, "upcall", "bool upcall = false");
Printf(f->code, "upcall = !Swig::Director::swig_is_overridden_method(\"%s%s\", \"%s\");\n",
prefix, Swig_class_name(Swig_methodclass(n)), name);
Printf(f->code, "upcall = !Swig::Director::swig_is_overridden_method(\"%s%s\", getThis());\n",
prefix, Swig_class_name(Swig_methodclass(n)));
}
Swig_director_emit_dynamic_cast(n, f);
@ -1518,14 +1607,14 @@ public:
}
if (constructor) {
Printf(f->code,"obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(getThis());\nobj->ptr = result;\n\n", class_name);
Printf(f->code,"obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(getThis());\nobj->ptr = (void *)result;\n\n");
Printf(f->code,"ht = Z_OBJ_HT_P(getThis())->get_properties(getThis());\n");
Printf(f->code,"if(ht) {\nzval zv;\n");
Printf(f->code,"ZVAL_RES(&zv,zend_register_resource(result,*(int *)(SWIGTYPE%s->clientdata)));\n", SwigType_manglestr(d));
Printf(f->code,"zend_hash_str_add(ht, \"_cPtr\", sizeof(\"_cPtr\") - 1, &zv);\n}\n\n");
}
else if (retType_valid) {
Printf(f->code,"obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(return_value);\nobj->ptr = result;\n\n", retType_class);
Printf(f->code,"obj = (swig_object_wrapper *) Z_FETCH_OBJ_P(return_value);\nobj->ptr = (void *)result;\n\n");
Printf(f->code,"ht = Z_OBJ_HT_P(return_value)->get_properties(return_value);\n");
Printf(f->code,"if(ht) {\nzval zv;\n");
Printf(f->code,"ZVAL_RES(&zv,zend_register_resource(result,*(int *)(SWIGTYPE%s->clientdata)));\n", SwigType_manglestr(d));
@ -1548,6 +1637,9 @@ public:
Delete(tm);
}
if (static_getter)
Printf(f->code, "}\n");
if (static_setter || static_getter)
Printf(f->code, "}\n");
@ -2568,48 +2660,21 @@ done:
virtual int classDeclaration(Node *n) {
if (!Getattr(n, "feature:onlychildren")) {
String *className = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
Setattr(n, "php:proxy", symname);
Printf(s_header, "/* class entry for %s */\n",symname);
Printf(s_header, "zend_class_entry *%s_ce;\n\n",symname);
Printf(s_header, "/* class object handlers for %s */\n",symname);
Printf(s_header, "zend_object_handlers %s_object_handlers;\n\n",symname);
Printf(s_header, "/* dtor Method for class %s */\n",symname);
Printf(s_header, "void %s_destroy_object(zend_object *object) {\n",symname);
Printf(s_header, " if(!object)\n\t return;\n");
Printf(s_header, " zend_objects_destroy_object(object);\n}\n\n\n");
Printf(s_header, "/* Garbage Collection Method for class %s */\n",symname);
Printf(s_header, "void %s_free_storage(zend_object *object) {\n",symname);
Printf(s_header, " if(!object)\n\t return;\n");
Printf(s_header, " swig_object_wrapper *obj = (swig_object_wrapper *)php_fetch_object(object);\n");
Printf(s_header, " if(!obj->newobject)\n\t return;\n");
Printf(s_header, " if(obj->ptr)\n");
Printf(s_header, " SWIG_remove((%s *)obj->ptr);\n",symname);
Printf(s_header, " if(obj->extras) {\n");
Printf(s_header, " zend_hash_destroy(obj->extras);\n");
Printf(s_header, " FREE_HASHTABLE(obj->extras);\n }\n\n");
Printf(s_header, " if(&obj->std)\n");
Printf(s_header, " zend_object_std_dtor(&obj->std);\n}\n\n\n");
Printf(s_header, "/* Object Creation Method for class %s */\n",symname);
Printf(s_header, "zend_object * %s_object_new(zend_class_entry *ce) {\n",symname);
Printf(s_header, " swig_object_wrapper *obj = (swig_object_wrapper *)ecalloc(1,sizeof(swig_object_wrapper) + zend_object_properties_size(ce));\n");
Printf(s_header, " zend_object_std_init(&obj->std, ce);\n");
Printf(s_header, " %s_object_handlers.offset = XtOffsetOf(swig_object_wrapper, std);\n",symname);
Printf(s_header, " %s_object_handlers.free_obj = %s_free_storage;\n",symname,symname);
Printf(s_header, " %s_object_handlers.dtor_obj = %s_destroy_object;\n",symname,symname);
Printf(s_header, " obj->std.handlers = &%s_object_handlers;\n obj->newobject = 1;\n return &obj->std;\n}\n\n\n",symname);
if (className != symname)
class_name = symname;
else
class_name = className;
if (Len(classes) != 0)
Printf(all_cs_entry, " { NULL, NULL, NULL }\n};\n\n");
Printf(all_cs_entry, "static zend_function_entry class_%s_functions[] = {\n", symname);
class_name = symname;
Append(classes,symname);
Printf(all_cs_entry, "static zend_function_entry class_%s_functions[] = {\n", class_name);
Append(classes,class_name);
}
return Language::classDeclaration(n);
@ -2622,10 +2687,13 @@ done:
virtual int classHandler(Node *n) {
constructors = 0;
current_class = n;
String *className = Getattr(n, "name");
String *symname = Getattr(n, "sym:name");
class_type = Getattr(n, "classtype");
Append(class_types, class_type);
Printf(s_oinit, "\nzend_class_entry %s_internal_ce;\n", symname);
Printf(s_oinit, "INIT_CLASS_ENTRY(%s_internal_ce, \"%s\", class_%s_functions);\n", symname, symname, symname);
Printf(s_oinit, "\nzend_class_entry %s_internal_ce;\n", class_name);
Printf(s_oinit, "INIT_CLASS_ENTRY(%s_internal_ce, \"%s\", class_%s_functions);\n", class_name, class_name, class_name);
if (shadow) {
char *rename = GetChar(n, "sym:name");
@ -2644,7 +2712,7 @@ done:
while (base.item && GetFlag(base.item, "feature:ignore")) {
base = Next(base);
}
Printf(s_oinit, "%s_ce = zend_register_internal_class_ex(&%s_internal_ce, %s_ce);\n", symname , symname, Getattr(base.item, "name"));
Printf(s_oinit, "%s_ce = zend_register_internal_class_ex(&%s_internal_ce, %s_ce);\n", class_name , class_name, Getattr(base.item, "sym:name"));
base = Next(base);
if (base.item) {
@ -2663,18 +2731,22 @@ done:
}
}
else
Printf(s_oinit, "%s_ce = zend_register_internal_class(&%s_internal_ce);\n", symname , symname);
Printf(s_oinit, "%s_ce = zend_register_internal_class(&%s_internal_ce);\n", class_name , class_name);
}
Printf(s_oinit, "%s_ce->create_object = %s_object_new;\n", symname, symname);
Printf(s_oinit, "memcpy(&%s_object_handlers,zend_get_std_object_handlers(), sizeof(zend_object_handlers));\n", symname);
Printf(s_oinit, "%s_object_handlers.clone_obj = NULL;\n\n", symname);
if (Cmp(symname,className) != 0) {
Printf(s_oinit, "zend_register_class_alias_ex(\"%s\",sizeof(\"%s\"),%s_ce);\n\n",class_name, class_name, class_name);
}
Printf(s_oinit, "%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, "%s_object_handlers.clone_obj = NULL;\n\n", class_name);
classnode = n;
Language::classHandler(n);
classnode = 0;
if (shadow) {
if (shadow && !class_name) {
List *baselist = Getattr(n, "bases");
Iterator ki, base;
@ -2848,6 +2920,7 @@ done:
}
magic_method_setter(n,true);
class_name = NULL;
class_type = NULL;
return SWIG_OK;
}
@ -2952,7 +3025,6 @@ done:
}
Language::constructorHandler(n);
wrapperType = standard;
return SWIG_OK;
}
@ -2975,34 +3047,35 @@ done:
Printf(f->def, "/* to typecast and do the actual destruction */\n");
Printf(f->def, "static void %s(zend_resource *res, const char *type_name) {\n", destructorname);
if (!class_name) {
Wrapper_add_localv(f, "value", "swig_object_wrapper *value=(swig_object_wrapper *) res->ptr", NIL);
Wrapper_add_localv(f, "ptr", "void *ptr=value->ptr", NIL);
Wrapper_add_localv(f, "newobject", "int newobject=value->newobject", NIL);
Printf(f->code, "if(zend_lookup_class(zend_string_init(\"%s\",sizeof(\"%s\")-1,0))) {\n", name, name);
Printf(f->code, "return;\n}\n\n");
emit_parameter_variables(l, f);
emit_attach_parmmaps(l, f);
Wrapper_add_localv(f, "value", "swig_object_wrapper *value=(swig_object_wrapper *) res->ptr", NIL);
Wrapper_add_localv(f, "ptr", "void *ptr=value->ptr", NIL);
Wrapper_add_localv(f, "newobject", "int newobject=value->newobject", NIL);
// Get type of first arg, thing to be destructed
// Skip ignored arguments
Parm *p = l;
//while (Getattr(p,"tmap:ignore")) {p = Getattr(p,"tmap:ignore:next");}
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
}
SwigType *pt = Getattr(p, "type");
emit_parameter_variables(l, f);
emit_attach_parmmaps(l, f);
Printf(f->code, " efree(value);\n");
Printf(f->code, " if (! newobject) return; /* can't delete it! */\n");
Printf(f->code, " arg1 = (%s)SWIG_ConvertResourceData(ptr, type_name, SWIGTYPE%s);\n", SwigType_lstr(pt, 0), SwigType_manglestr(pt));
Printf(f->code, " if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name));
Setattr(n, "wrap:name", destructorname);
String *actioncode = emit_action(n);
Append(f->code, actioncode);
Delete(actioncode);
// Get type of first arg, thing to be destructed
// Skip ignored arguments
Parm *p = l;
//while (Getattr(p,"tmap:ignore")) {p = Getattr(p,"tmap:ignore:next");}
while (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
}
SwigType *pt = Getattr(p, "type");
Printf(f->code, " efree(value);\n");
Printf(f->code, " if (! newobject) return; /* can't delete it! */\n");
Printf(f->code, " arg1 = (%s)SWIG_ConvertResourceData(ptr, type_name, SWIGTYPE%s);\n", SwigType_lstr(pt, 0), SwigType_manglestr(pt));
Printf(f->code, " if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name));
Setattr(n, "wrap:name", destructorname);
String *actioncode = emit_action(n);
Append(f->code, actioncode);
Delete(actioncode);
Printf(f->code, "thrown:\n");
Append(f->code, "return;\n");

513
test1.log~ Normal file
View file

@ -0,0 +1,513 @@
checking php test-suite
checking php testcase callback (with run test)
checking php testcase li_factory (with run test)
checking php testcase php_iterator (with run test)
checking php testcase php_namewarn_rename
checking php testcase php_pragma (with run test)
checking php testcase abstract_access
checking php testcase abstract_inherit (with run test)
checking php testcase abstract_inherit_ok (with run test)
checking php testcase abstract_signature
checking php testcase abstract_typedef
checking php testcase abstract_typedef2
checking php testcase abstract_virtual
checking php testcase access_change
checking php testcase add_link (with run test)
checking php testcase aggregate
checking php testcase allowexcept
checking php testcase allprotected
checking php testcase allprotected_not
checking php testcase anonymous_bitfield
checking php testcase apply_signed_char
checking php testcase apply_strings
checking php testcase argout (with run test)
checking php testcase array_member
checking php testcase array_typedef_memberin
checking php testcase arrayref
checking php testcase arrays_dimensionless
checking php testcase arrays_global (with run test)
checking php testcase arrays_global_twodim (with run test)
checking php testcase arrays_scope (with run test)
checking php testcase autodoc
checking php testcase bloody_hell
checking php testcase bools
checking php testcase catches
checking php testcase cast_operator
checking php testcase casts (with run test)
checking php testcase char_binary
checking php testcase char_strings (with run test)
checking php testcase chartest
checking php testcase class_forward
checking php testcase class_ignore (with run test)
checking php testcase class_scope_weird
checking php testcase compactdefaultargs
checking php testcase const_const_2
checking php testcase constant_directive
checking php testcase constant_pointers
checking php testcase constover
checking php testcase constructor_copy
checking php testcase constructor_exception
checking php testcase constructor_explicit
checking php testcase constructor_ignore
checking php testcase constructor_rename
checking php testcase constructor_value
checking php testcase contract
checking php testcase conversion (with run test)
checking php testcase conversion_namespace (with run test)
checking php testcase conversion_ns_template (with run test)
checking php testcase conversion_operators
checking php testcase cplusplus_throw
checking php testcase cpp_basic (with run test)
checking php testcase cpp_enum
checking php testcase cpp_namespace
checking php testcase cpp_nodefault
checking php testcase cpp_static (with run test)
checking php testcase cpp_typedef
checking php testcase curiously_recurring_template_pattern
checking php testcase default_args
checking php testcase default_arg_values
checking php testcase default_constructor
checking php testcase defvalue_constructor
checking php testcase derived_byvalue
checking php testcase derived_nested
checking php testcase destructor_reprotected
checking php testcase director_abstract (with run test)
checking php testcase director_alternating
checking php testcase director_basic (with run test)
checking php testcase director_binary_string
checking php testcase director_classes
checking php testcase director_classic (with run test)
checking php testcase director_constructor
checking php testcase director_default (with run test)
checking php testcase director_detect (with run test)
checking php testcase director_enum (with run test)
checking php testcase director_exception (with run test)
checking php testcase director_extend (with run test)
checking php testcase director_finalizer (with run test)
checking php testcase director_frob (with run test)
checking php testcase director_ignore
checking php testcase director_keywords
checking php testcase director_namespace_clash
checking php testcase director_nested (with run test)
checking php testcase director_nspace
checking php testcase director_nspace_director_name_collision
checking php testcase director_overload
checking php testcase director_overload2
checking php testcase director_pass_by_value (with run test)
checking php testcase director_primitives
checking php testcase director_property
checking php testcase director_protected (with run test)
checking php testcase director_protected_overloaded
checking php testcase director_redefined
checking php testcase director_ref
checking php testcase director_smartptr
checking php testcase director_unroll (with run test)
checking php testcase director_using
checking php testcase director_void
checking php testcase director_wombat
checking php testcase disown
checking php testcase dynamic_cast
checking php testcase empty
checking php testcase enum_ignore
checking php testcase enum_plus
checking php testcase enum_rename
checking php testcase enum_scope_template (with run test)
checking php testcase enum_template
checking php testcase enum_thorough
checking php testcase enum_var
checking php testcase equality
checking php testcase evil_diamond (with run test)
checking php testcase evil_diamond_ns (with run test)
checking php testcase evil_diamond_prop (with run test)
checking php testcase exception_classname
checking php testcase exception_order (with run test)
checking php testcase extend
checking php testcase extend_constructor_destructor
checking php testcase extend_default
checking php testcase extend_placement
checking php testcase extend_special_variables
checking php testcase extend_template (with run test)
checking php testcase extend_template_method
checking php testcase extend_template_ns (with run test)
checking php testcase extend_typedef_class
checking php testcase extern_c
checking php testcase extern_namespace
checking php testcase extern_throws
checking php testcase expressions
checking php testcase features
checking php testcase fragments
checking php testcase friends
checking php testcase friends_template
checking php testcase funcptr_cpp
checking php testcase fvirtual
checking php testcase global_namespace
checking php testcase global_ns_arg
checking php testcase global_scope_types
checking php testcase global_vars
checking php testcase grouping (with run test)
checking php testcase ignore_parameter (with run test)
checking php testcase import_fragments
checking php testcase import_nomodule (with run test)
checking php testcase inherit
checking php testcase inherit_member
checking php testcase inherit_missing
checking php testcase inherit_same_name
checking php testcase inherit_target_language
checking php testcase inherit_void_arg
checking php testcase inline_initializer
checking php testcase insert_directive
checking php testcase keyword_rename
checking php testcase kind
checking php testcase kwargs_feature
checking php testcase langobj
checking php testcase li_attribute
checking php testcase li_attribute_template
checking php testcase li_boost_shared_ptr
checking php testcase li_boost_shared_ptr_template
checking php testcase li_boost_shared_ptr_attribute
checking php testcase li_carrays_cpp (with run test)
checking php testcase li_cdata_cpp
checking php testcase li_cpointer_cpp
checking php testcase li_std_auto_ptr
checking php testcase li_stdint
checking php testcase li_swigtype_inout
checking php testcase li_typemaps
checking php testcase li_typemaps_apply
checking php testcase li_windows
checking php testcase long_long_apply
checking php testcase memberin_extend
checking php testcase member_funcptr_galore
checking php testcase member_pointer
checking php testcase member_pointer_const
checking php testcase member_template
checking php testcase minherit
checking php testcase minherit2
checking php testcase mixed_types
checking php testcase multiple_inheritance
checking php testcase multiple_inheritance_abstract
checking php testcase multiple_inheritance_interfaces
checking php testcase multiple_inheritance_nspace
checking php testcase multiple_inheritance_shared_ptr
checking php testcase name_cxx
checking php testcase name_warnings
checking php testcase namespace_class
checking php testcase namespace_enum
checking php testcase namespace_extend
checking php testcase namespace_forward_declaration
checking php testcase namespace_nested
checking php testcase namespace_spaces
checking php testcase namespace_template
checking php testcase namespace_typedef_class
checking php testcase namespace_typemap
checking php testcase namespace_union
checking php testcase namespace_virtual_method
checking php testcase nspace
checking php testcase nspace_extend
checking php testcase naturalvar
checking php testcase naturalvar_more
checking php testcase naturalvar_onoff
checking php testcase nested_class
checking php testcase nested_directors
checking php testcase nested_comment
checking php testcase nested_ignore
checking php testcase nested_scope
checking php testcase nested_template_base
checking php testcase nested_workaround
checking php testcase newobject1 (with run test)
checking php testcase null_pointer
checking php testcase operator_overload
checking php testcase operator_overload_break
checking php testcase operator_pointer_ref
checking php testcase operbool
checking php testcase ordering
checking php testcase overload_arrays
checking php testcase overload_bool
checking php testcase overload_copy
checking php testcase overload_extend
checking php testcase overload_method
checking php testcase overload_numeric
checking php testcase overload_polymorphic
checking php testcase overload_rename (with run test)
checking php testcase overload_return_type (with run test)
checking php testcase overload_simple
checking php testcase overload_subtype
checking php testcase overload_template
checking php testcase overload_template_fast
checking php testcase pointer_reference (with run test)
checking php testcase preproc_constants (with run test)
checking php testcase primitive_ref (with run test)
checking php testcase private_assign
checking php testcase proxycode
checking php testcase protected_rename
checking php testcase pure_virtual
checking php testcase redefined
checking php testcase redefined_not
checking php testcase refcount
checking php testcase reference_global_vars
checking php testcase register_par
checking php testcase rename1
checking php testcase rename2
checking php testcase rename3
checking php testcase rename4
checking php testcase rename_rstrip_encoder
checking php testcase rename_scope (with run test)
checking php testcase rename_simple
checking php testcase rename_strip_encoder
checking php testcase rename_pcre_encoder
checking php testcase rename_pcre_enum
checking php testcase rename_predicates
checking php testcase rename_wildcard
checking php testcase restrict_cplusplus
checking php testcase return_const_value
checking php testcase return_value_scope
checking php testcase rname
checking php testcase samename
checking php testcase sizet
checking php testcase smart_pointer_const
checking php testcase smart_pointer_const2
checking php testcase smart_pointer_const_overload
checking php testcase smart_pointer_extend
checking php testcase smart_pointer_ignore
checking php testcase smart_pointer_member
checking php testcase smart_pointer_multi
checking php testcase smart_pointer_multi_typedef
checking php testcase smart_pointer_namespace
checking php testcase smart_pointer_namespace2
checking php testcase smart_pointer_not
checking php testcase smart_pointer_overload
checking php testcase smart_pointer_protected
checking php testcase smart_pointer_rename (with run test)
checking php testcase smart_pointer_simple
checking php testcase smart_pointer_static
checking php testcase smart_pointer_template_const_overload
checking php testcase smart_pointer_template_defaults_overload
checking php testcase smart_pointer_templatemethods
checking php testcase smart_pointer_templatevariables
checking php testcase smart_pointer_typedef
checking php testcase special_variables
checking php testcase special_variable_attributes
checking php testcase special_variable_macros
checking php testcase static_array_member
checking php testcase static_const_member
checking php testcase static_const_member_2
checking php testcase string_constants
checking php testcase struct_initialization_cpp
checking php testcase struct_value
checking php testcase swig_exception (with run test)
checking php testcase symbol_clash
checking php testcase template_arg_replace
checking php testcase template_arg_scope
checking php testcase template_arg_typename (with run test)
checking php testcase template_array_numeric
checking php testcase template_basic
checking php testcase template_base_template
checking php testcase template_classes
checking php testcase template_const_ref
checking php testcase template_construct (with run test)
checking php testcase template_templated_constructors
checking php testcase template_default
checking php testcase template_default2
checking php testcase template_default_arg
checking php testcase template_default_arg_overloaded
checking php testcase template_default_arg_overloaded_extend
checking php testcase template_default_arg_virtual_destructor
checking php testcase template_default_cache
checking php testcase template_default_class_parms
checking php testcase template_default_class_parms_typedef
checking php testcase template_default_inherit
checking php testcase template_default_qualify
checking php testcase template_default_vw
checking php testcase template_enum
checking php testcase template_enum_ns_inherit
checking php testcase template_enum_typedef
checking php testcase template_explicit
checking php testcase template_extend1
checking php testcase template_extend2
checking php testcase template_extend_overload
checking php testcase template_extend_overload_2
checking php testcase template_forward
checking php testcase template_inherit
checking php testcase template_inherit_abstract
checking php testcase template_int_const
checking php testcase template_keyword_in_type
checking php testcase template_methods
checking php testcase template_namespace_forward_declaration
checking php testcase template_using_directive_and_declaration_forward
checking php testcase template_nested
checking php testcase template_nested_typemaps
checking php testcase template_ns
checking php testcase template_ns2
checking php testcase template_ns3
checking php testcase template_ns4
checking php testcase template_ns_enum
checking php testcase template_ns_enum2
checking php testcase template_ns_inherit
checking php testcase template_ns_scope
checking php testcase template_partial_arg
checking php testcase template_partial_specialization
checking php testcase template_partial_specialization_typedef
checking php testcase template_qualifier
checking php testcase template_ref_type
checking php testcase template_rename
checking php testcase template_retvalue
checking php testcase template_specialization
checking php testcase template_specialization_defarg
checking php testcase template_specialization_enum
checking php testcase template_static
checking php testcase template_tbase_template
checking php testcase template_template_parameters
checking php testcase template_typedef
checking php testcase template_typedef_class_template
checking php testcase template_typedef_cplx
checking php testcase template_typedef_cplx2
checking php testcase template_typedef_cplx3
checking php testcase template_typedef_cplx4
checking php testcase template_typedef_cplx5
checking php testcase template_typedef_funcptr
checking php testcase template_typedef_inherit
checking php testcase template_typedef_ns
checking php testcase template_typedef_ptr
checking php testcase template_typedef_rec
checking php testcase template_typedef_typedef
checking php testcase template_typemaps
checking php testcase template_typemaps_typedef
checking php testcase template_typemaps_typedef2
checking php testcase template_using
checking php testcase template_virtual
checking php testcase template_whitespace
checking php testcase threads
checking php testcase threads_exception (with run test)
checking php testcase throw_exception
checking php testcase typedef_array_member
checking php testcase typedef_class
checking php testcase typedef_funcptr
checking php testcase typedef_inherit
checking php testcase typedef_mptr
checking php testcase typedef_reference (with run test)
checking php testcase typedef_scope
checking php testcase typedef_sizet
checking php testcase typedef_struct_cpp
checking php testcase typedef_typedef
checking php testcase typemap_arrays
checking php testcase typemap_array_qualifiers
checking php testcase typemap_delete
checking php testcase typemap_directorout
checking php testcase typemap_documentation
checking php testcase typemap_global_scope
checking php testcase typemap_manyargs
checking php testcase typemap_namespace
checking php testcase typemap_ns_using (with run test)
checking php testcase typemap_numinputs
checking php testcase typemap_template
checking php testcase typemap_template_parm_typedef
checking php testcase typemap_out_optimal
checking php testcase typemap_qualifier_strip
checking php testcase typemap_variables
checking php testcase typemap_various
checking php testcase typename
checking php testcase types_directive
checking php testcase unicode_strings
checking php testcase union_scope
checking php testcase using1 (with run test)
checking php testcase using2 (with run test)
checking php testcase using_composition
checking php testcase using_directive_and_declaration
checking php testcase using_directive_and_declaration_forward
checking php testcase using_extend
checking php testcase using_inherit
checking php testcase using_namespace
checking php testcase using_namespace_loop
checking php testcase using_pointers
checking php testcase using_private
checking php testcase using_protected
checking php testcase valuewrapper
checking php testcase valuewrapper_base (with run test)
checking php testcase valuewrapper_const
checking php testcase valuewrapper_opaque
checking php testcase varargs
checking php testcase varargs_overload
checking php testcase variable_replacement
checking php testcase virtual_destructor
checking php testcase virtual_poly
checking php testcase virtual_vs_nonvirtual_base (with run test)
checking php testcase voidtest
checking php testcase wallkw
checking php testcase wrapmacro (with run test)
checking php testcase director_string (with run test)
checking php testcase ignore_template_constructor
checking php testcase li_std_combinations
checking php testcase li_std_deque
checking php testcase li_std_except
checking php testcase li_std_except_as_class
checking php testcase li_std_map
checking php testcase li_std_pair
checking php testcase li_std_pair_using
checking php testcase li_std_string (with run test)
checking php testcase li_std_vector
checking php testcase li_std_vector_enum
checking php testcase li_std_vector_member_var (with run test)
checking php testcase li_std_vector_ptr
checking php testcase smart_pointer_inherit
checking php testcase template_typedef_fnc
checking php testcase template_type_namespace
checking php testcase template_opaque
checking php testcase arrays (with run test)
checking php testcase bom_utf8
checking php testcase c_delete
checking php testcase c_delete_function
checking php testcase char_constant
checking php testcase const_const
checking php testcase constant_expr
checking php testcase empty_c
checking php testcase enums
checking php testcase enum_forward
checking php testcase enum_macro
checking php testcase enum_missing
checking php testcase extern_declaration
checking php testcase funcptr
checking php testcase function_typedef
checking php testcase global_functions
checking php testcase immutable_values
checking php testcase inctest
checking php testcase infinity
checking php testcase integers
checking php testcase keyword_rename_c
checking php testcase lextype
checking php testcase li_carrays (with run test)
checking php testcase li_cdata
checking php testcase li_cmalloc
checking php testcase li_constraints
checking php testcase li_cpointer
checking php testcase li_math
checking php testcase long_long
checking php testcase memberin_extend_c
checking php testcase name
checking php testcase nested
checking php testcase nested_extend_c
checking php testcase nested_structs
checking php testcase newobject2
checking php testcase overload_extend_c
checking php testcase overload_extend2
checking php testcase preproc
checking php testcase preproc_constants_c (with run test)
checking php testcase preproc_defined
checking php testcase preproc_include
checking php testcase preproc_line_file
checking php testcase ret_by_value
checking php testcase simple_array
checking php testcase sizeof_pointer
checking php testcase sneaky1
checking php testcase string_simple
checking php testcase struct_rename
checking php testcase struct_initialization
checking php testcase typedef_struct
checking php testcase typemap_subst
checking php testcase union_parameter
checking php testcase unions
checking php testcase clientdata_prop
checking php testcase imports
checking php testcase import_stl
checking php testcase packageoption
checking php testcase mod
checking php testcase template_typedef_import
checking php testcase multi_import