diff --git a/CHANGES.current b/CHANGES.current index 7d1b70ca7..56a385d57 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,9 +1,6 @@ Version 1.3.37 (in progress) ============================= -2008-08-09: talby - [Perl5] Unify Perl and C portions of constructor wrappers. - 2008-08-02: wuzzeb [Chicken,Allegro] Commit Patch 2019314 Fixes a build error in chicken, and several build errors and other errors diff --git a/Examples/test-suite/perl5/imports_runme.pl b/Examples/test-suite/perl5/imports_runme.pl index 13ca08a1c..fd730fedf 100644 --- a/Examples/test-suite/perl5/imports_runme.pl +++ b/Examples/test-suite/perl5/imports_runme.pl @@ -1,5 +1,5 @@ use imports_b; use imports_a; -$x = imports_b::B->new(); +$x = imports_bc::new_B(); imports_ac::A_hello($x); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 2e714efe5..6e706fc8d 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -100,6 +100,8 @@ static int have_constructor = 0; static int have_destructor = 0; static int have_data_members = 0; static String *class_name = 0; /* Name of the class (what Perl thinks it is) */ +static String *real_classname = 0; /* Real name of C/C++ class */ +static String *fullclassname = 0; static String *pcode = 0; /* Perl code associated with each class */ /* static String *blessedmembers = 0; *//* Member data associated with each class */ @@ -556,7 +558,6 @@ public: String *iname = Getattr(n, "sym:name"); SwigType *d = Getattr(n, "type"); ParmList *l = Getattr(n, "parms"); - ParmList *outer = Getattr(n, "perl5:implicits"); String *overname = 0; Parm *p; @@ -566,7 +567,7 @@ public: String *tm; String *cleanup, *outarg; int num_saved = 0; - int num_arguments, num_required, num_implicits; + int num_arguments, num_required; int varargs = 0; if (Getattr(n, "sym:overloaded")) { @@ -588,19 +589,6 @@ public: Printv(f->def, "XS(", wname, ") {\n", "{\n", /* scope to destroy C++ objects before croaking */ NIL); - num_implicits = 0; - if (outer) { - Parm *tmp = outer; - Parm *tail; - while(tmp) { - tail = tmp; - num_implicits++; - tmp = nextSibling(tmp); - } - /* link the outer with inner parms */ - set_nextSibling(tail, l); - } - emit_parameter_variables(l, f); emit_attach_parmmaps(l, f); Setattr(n, "wrap:parms", l); @@ -613,29 +601,13 @@ public: /* Check the number of arguments */ if (!varargs) { - Printf(f->code, " if ((items < %d) || (items > %d)) {\n", - num_required + num_implicits, num_arguments + num_implicits); + Printf(f->code, " if ((items < %d) || (items > %d)) {\n", num_required, num_arguments); } else { - Printf(f->code, " if (items < %d) {\n", - num_required + num_implicits); + Printf(f->code, " if (items < %d) {\n", num_required); } - Printf(f->code, " SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname), d, outer, l)); + Printf(f->code, " SWIG_croak(\"Usage: %s\");\n", usage_func(Char(iname), d, l)); Printf(f->code, "}\n"); - if (num_implicits) { - /* TODO: support implicits of types other than SVs */ - Parm *p = outer; - for(i = 0; i < num_implicits; i++) { - String *pname = Getattr(p, "name"); - String *pinit = SwigType_str(Getattr(p, "type"), pname); - Wrapper_add_local(f, pname, pinit); - Delete(pinit); - Printf(f->code, "%s = ST(%d);\n", pname, i++); - p = nextSibling(p); - } - if (l) - Printf(f->code, "ax += %d;\n", num_implicits); - } /* Write code to extract parameters. */ i = 0; for (i = 0, p = l; i < num_arguments; i++) { @@ -748,9 +720,6 @@ public: Wrapper_add_localv(f, "_saved", "SV *", temp, NIL); } - if (num_implicits && l) - Printf(f->code, "ax -= %d;\n", num_implicits); - /* Now write code to make the function call */ Swig_director_emit_dynamic_cast(n, f); @@ -797,11 +766,6 @@ public: Printf(f->code, "%s\n", tm); } - if (blessed && Equal(nodeType(n), "constructor")) { - Append(f->code, - "if (SvOK(ST(0))) sv_bless(ST(0), gv_stashsv(proto, 0));\n"); - } - Printv(f->code, "XSRETURN(argvi);\n", "fail:\n", cleanup, "SWIG_croak_null();\n" "}\n" "}\n", NIL); /* Add the dXSARGS last */ @@ -833,10 +797,6 @@ public: Printv(df->def, "XS(", dname, ") {\n", NIL); Wrapper_add_local(df, "dXSARGS", "dXSARGS"); - if (num_implicits) { - Printf(df->code, "ax += %d;\n", num_implicits); - Printf(df->code, "items -= %d;\n", num_implicits); - } Printv(df->code, dispatch, "\n", NIL); Printf(df->code, "croak(\"No matching function for overloaded '%s'\");\n", iname); Printf(df->code, "XSRETURN(0);\n"); @@ -1073,7 +1033,7 @@ public: /* ------------------------------------------------------------ * usage_func() * ------------------------------------------------------------ */ - char *usage_func(char *iname, SwigType *, ParmList *il, ParmList *l) { + char *usage_func(char *iname, SwigType *, ParmList *l) { static String *temp = 0; Parm *p; int i; @@ -1083,17 +1043,13 @@ public: Clear(temp); Printf(temp, "%s(", iname); - i = 0; - /* Print implicit parameters */ - for(p = il; p; p = nextSibling(p)) - Printv(temp, (i > 0 ? "," : ""), Getattr(p, "name"), NIL); - /* Now go through and print normal parameters */ + /* Now go through and print parameters */ p = l; + i = 0; while (p != 0) { SwigType *pt = Getattr(p, "type"); String *pn = Getattr(p, "name"); if (!checkAttribute(p,"tmap:in:numinputs","0")) { - if (i > 0) Append(temp, ","); /* If parameter has been named, use that. Otherwise, just print a type */ if (SwigType_type(pt) != T_VOID) { if (Len(pn) > 0) { @@ -1103,8 +1059,16 @@ public: } } i++; + p = nextSibling(p); + if (p) + if (!checkAttribute(p,"tmap:in:numinputs","0")) + Putc(',', temp); + } else { + p = nextSibling(p); + if (p) + if ((i > 0) && (!checkAttribute(p,"tmap:in:numinputs","0"))) + Putc(',', temp); } - p = nextSibling(p); } Printf(temp, ");"); return Char(temp); @@ -1222,8 +1186,6 @@ public: * ------------------------------------------------------------ */ virtual int classHandler(Node *n) { - String *name = 0; /* Real name of C/C++ class */ - String *fullclassname = 0; if (blessed) { have_constructor = 0; @@ -1243,7 +1205,7 @@ public: } else { fullclassname = NewString(class_name); } - name = Getattr(n, "name"); + real_classname = Getattr(n, "name"); pcode = NewString(""); // blessedmembers = NewString(""); } @@ -1255,7 +1217,7 @@ public: /* Finish the rest of the class */ if (blessed) { /* Generate a client-data entry */ - SwigType *ct = NewStringf("p.%s", name); + SwigType *ct = NewStringf("p.%s", real_classname); Printv(f_init, "SWIG_TypeClientData(SWIGTYPE", SwigType_manglestr(ct), ", (void*) \"", fullclassname, "\");\n", NIL); SwigType_remember(ct); Delete(ct); @@ -1528,15 +1490,6 @@ public: String *symname = Getattr(n, "sym:name"); - { - String *type = NewString("SV"); - SwigType_add_pointer(type); - Parm *p = NewParm(type, "proto"); - Delete(type); - Setattr(n, "perl5:implicits", p); - Delete(p); - } - member_func = 1; Language::constructorHandler(n); @@ -1548,16 +1501,17 @@ public: Delete(plaction); Printv(pcode, plcode, NIL); } else { - /* Emit a blessed constructor */ - String *cname = Swig_name_construct(symname); - char *pname; - /* override Class->Class to be Class->new */ - if (Cmp(symname, class_name) == 0) - pname = "new"; - else - pname = Char(cname); - Printf(pcode, "*%s = *%s::%s;\n", pname, cmodule, cname); - Delete(cname); + if ((Cmp(symname, class_name) == 0)) { + /* Emit a blessed constructor */ + Printf(pcode, "sub new {\n"); + } else { + /* Constructor doesn't match classname so we'll just use the normal name */ + Printv(pcode, "sub ", Swig_name_construct(symname), " () {\n", NIL); + } + + Printv(pcode, + tab4, "my $pkg = shift;\n", + tab4, "my $self = ", cmodule, "::", Swig_name_construct(symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL); have_constructor = 1; }