150
150
ki = First(zend_types);
152
152
Printf(s_oinit, "\n/* Register resource destructors for pointer types */\n");
154
if (1 /* is pointer type */ ) {
156
Node *class_node = ki.item;
157
String *human_name = key;
159
// Write out destructor function header
160
Printf(s_wrappers, "/* NEW Destructor style */\nstatic ZEND_RSRC_DTOR_FUNC(_wrap_destroy%s) {\n", key);
163
if ((class_node != NOTCLASS)) {
164
String *destructor = Getattr(class_node, "destructor");
165
human_name = Getattr(class_node, "sym:name");
167
human_name = Getattr(class_node, "name");
168
// Do we have a known destructor for this type?
170
Printf(s_wrappers, " %s(rsrc, SWIGTYPE%s->name TSRMLS_CC);\n", destructor, key);
172
Printf(s_wrappers, " /* No destructor for class %s */\n", human_name);
155
Node *class_node = ki.item;
156
String *human_name = key;
158
// Write out destructor function header
159
Printf(s_wrappers, "/* NEW Destructor style */\nstatic ZEND_RSRC_DTOR_FUNC(_wrap_destroy%s) {\n", key);
162
if ((class_node != NOTCLASS)) {
163
String *destructor = Getattr(class_node, "destructor");
164
human_name = Getattr(class_node, "sym:name");
166
human_name = Getattr(class_node, "name");
167
// Do we have a known destructor for this type?
169
Printf(s_wrappers, " %s(rsrc, SWIGTYPE%s->name TSRMLS_CC);\n", destructor, key);
175
Printf(s_wrappers, " /* No destructor for simple type %s */\n", key);
171
Printf(s_wrappers, " /* No destructor for class %s */\n", human_name);
179
Printf(s_wrappers, "}\n");
181
// declare le_swig_<mangled> to store php registration
182
Printf(s_vdecl, "static int le_swig_%s=0; /* handle for %s */\n", key, human_name);
185
Printf(s_oinit, "le_swig_%s=zend_register_list_destructors_ex" "(_wrap_destroy%s,NULL,(char *)(SWIGTYPE%s->name),module_number);\n", key, key, key);
187
// store php type in class struct
188
Printf(s_oinit, "SWIG_TypeClientData(SWIGTYPE%s,&le_swig_%s);\n", key, key);
174
Printf(s_wrappers, " /* No destructor for simple type %s */\n", key);
178
Printf(s_wrappers, "}\n");
180
// declare le_swig_<mangled> to store php registration
181
Printf(s_vdecl, "static int le_swig_%s=0; /* handle for %s */\n", key, human_name);
184
Printf(s_oinit, "le_swig_%s=zend_register_list_destructors_ex" "(_wrap_destroy%s,NULL,(char *)(SWIGTYPE%s->name),module_number);\n", key, key, key);
186
// store php type in class struct
187
Printf(s_oinit, "SWIG_TypeClientData(SWIGTYPE%s,&le_swig_%s);\n", key, key);
194
193
class PHP:public Language {
1175
1174
Setattr(n, "wrap:name", wname);
1177
1176
/* emit function call */
1177
String *actioncode = emit_action(n);
1180
if ((tm = Swig_typemap_lookup_new("out", n, "result", 0))) {
1179
if ((tm = Swig_typemap_lookup_out("out", n, "result", f, actioncode))) {
1181
1180
Replaceall(tm, "$input", "result");
1182
1181
Replaceall(tm, "$source", "result");
1183
1182
Replaceall(tm, "$target", "return_value");
1195
1194
if (native_constructor == NATIVE_CONSTRUCTOR) {
1196
1195
Printf(f->code, "add_property_zval(this_ptr,\"" SWIG_PTR "\",_cPtr);\n");
1198
String *shadowrettype = SwigToPhpType(d, iname, true);
1197
String *shadowrettype = GetShadowReturnType(n);
1199
1198
Printf(f->code, "object_init_ex(return_value,ptr_ce_swig_%s);\n", shadowrettype);
1200
1199
Delete(shadowrettype);
1201
1200
Printf(f->code, "add_property_zval(return_value,\"" SWIG_PTR "\",_cPtr);\n");
1217
1217
/* Look to see if there is any newfree cleanup code */
1218
1218
if (GetFlag(n, "feature:new")) {
1219
if ((tm = Swig_typemap_lookup_new("newfree", n, "result", 0))) {
1219
if ((tm = Swig_typemap_lookup("newfree", n, "result", 0))) {
1220
1220
Printf(f->code, "%s\n", tm);
1225
1225
/* See if there is any return cleanup code */
1226
if ((tm = Swig_typemap_lookup_new("ret", n, "result", 0))) {
1226
if ((tm = Swig_typemap_lookup("ret", n, "result", 0))) {
1227
1227
Printf(f->code, "%s\n", tm);
1911
1916
SwigType_remember(type);
1913
if ((tm = Swig_typemap_lookup_new("consttab", n, name, 0))) {
1918
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
1914
1919
Replaceall(tm, "$source", value);
1915
1920
Replaceall(tm, "$target", name);
1916
1921
Replaceall(tm, "$value", value);
2554
2559
return SWIG_OK;
2558
String * SwigToPhpType(SwigType *t, String_or_char *pname, int shadow_flag) {
2562
ptype = PhpTypeFromTypemap((char *) "pstype", t, pname, (char *) "");
2565
ptype = PhpTypeFromTypemap((char *) "ptype", t, pname, (char *) "");
2568
if (ptype) return ptype;
2562
String * GetShadowReturnType(Node *n) {
2563
SwigType *t = Getattr(n, "type");
2570
2565
/* Map type here */
2571
2566
switch (SwigType_type(t)) {
2598
Printf(stderr, "SwigToPhpType: unhandled data type: %s\n", SwigType_str(t, 0));
2593
Printf(stderr, "GetShadowReturnType: unhandled data type: %s\n", SwigType_str(t, 0));
2602
2597
return NewStringEmpty();
2605
String *PhpTypeFromTypemap(char *op, SwigType *t, String_or_char *pname, String_or_char *lname) {
2607
tms = Swig_typemap_lookup(op, t, pname, lname, (char *) "", (char *) "", NULL);
2612
char *start = Char(tms);
2613
while (isspace(*start) || *start == '{') {
2617
while (*end && *end != '}') {
2620
return NewStringWithSize(start, end - start);
2600
String *PhpTypeFromTypemap(char *op, Node *n, String_or_char *lname) {
2601
String *tms = Swig_typemap_lookup(op, n, lname, 0);
2605
return NewStringf("%s", tms);
2623
2608
int abstractConstructorHandler(Node *n) {
2679
2664
int CreateZendListDestructor(Node *n) {
2680
2665
String *name = GetChar(Swig_methodclass(n), "name");
2681
2666
String *iname = GetChar(n, "sym:name");
2682
SwigType *d = Getattr(n, "type");
2683
2667
ParmList *l = Getattr(n, "parms");
2685
2669
String *destructorname = NewStringEmpty();
2686
2670
Printf(destructorname, "_%s", Swig_name_wrapper(iname));
2687
2671
Setattr(classnode, "destructor", destructorname);
2689
Wrapper *df = NewWrapper();
2690
Printf(df->def, "/* This function is designed to be called by the zend list destructors */\n");
2691
Printf(df->def, "/* to typecast and do the actual destruction */\n");
2692
Printf(df->def, "static void %s(zend_rsrc_list_entry *rsrc, const char *type_name TSRMLS_DC) {\n", destructorname);
2694
Wrapper_add_localv(df, "value", "swig_object_wrapper *value=(swig_object_wrapper *) rsrc->ptr", NIL);
2695
Wrapper_add_localv(df, "ptr", "void *ptr=value->ptr", NIL);
2696
Wrapper_add_localv(df, "newobject", "int newobject=value->newobject", NIL);
2698
emit_args(d, l, df);
2699
emit_attach_parmmaps(l, df);
2673
Wrapper *f = NewWrapper();
2674
Printf(f->def, "/* This function is designed to be called by the zend list destructors */\n");
2675
Printf(f->def, "/* to typecast and do the actual destruction */\n");
2676
Printf(f->def, "static void %s(zend_rsrc_list_entry *rsrc, const char *type_name TSRMLS_DC) {\n", destructorname);
2678
Wrapper_add_localv(f, "value", "swig_object_wrapper *value=(swig_object_wrapper *) rsrc->ptr", NIL);
2679
Wrapper_add_localv(f, "ptr", "void *ptr=value->ptr", NIL);
2680
Wrapper_add_localv(f, "newobject", "int newobject=value->newobject", NIL);
2682
emit_parameter_variables(l, f);
2683
emit_attach_parmmaps(l, f);
2701
2685
// Get type of first arg, thing to be destructed
2702
2686
// Skip ignored arguments
2708
2692
SwigType *pt = Getattr(p, "type");
2710
Printf(df->code, " efree(value);\n");
2711
Printf(df->code, " if (! newobject) return; /* can't delete it! */\n");
2712
Printf(df->code, " arg1 = (%s)SWIG_ZTS_ConvertResourceData(ptr,type_name,SWIGTYPE%s TSRMLS_CC);\n", SwigType_lstr(pt, 0), SwigType_manglestr(pt));
2713
Printf(df->code, " if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name));
2694
Printf(f->code, " efree(value);\n");
2695
Printf(f->code, " if (! newobject) return; /* can't delete it! */\n");
2696
Printf(f->code, " arg1 = (%s)SWIG_ZTS_ConvertResourceData(ptr,type_name,SWIGTYPE%s TSRMLS_CC);\n", SwigType_lstr(pt, 0), SwigType_manglestr(pt));
2697
Printf(f->code, " if (! arg1) zend_error(E_ERROR, \"%s resource already free'd\");\n", Char(name));
2715
2699
Setattr(n, "wrap:name", destructorname);
2719
Printf(df->code, "}\n");
2721
Wrapper_print(df, s_wrappers);
2701
String *actioncode = emit_action(n);
2702
Append(f->code, actioncode);
2705
Printf(f->code, "}\n");
2707
Wrapper_print(f, s_wrappers);
2723
2709
return SWIG_OK;