ran "beautify-file" make target over perl5.cxx patch hunks and rewrote callback and extend examples in the style of existing examples

This commit is contained in:
Robert Stone 2013-11-14 09:22:23 -08:00
commit 43aefba9ee
3 changed files with 277 additions and 260 deletions

View file

@ -1,40 +1,48 @@
#!/usr/bin/perl # file: runme.pl
use strict;
use warnings; # This file illustrates the cross language polymorphism using directors.
use example; use example;
{ {
package PerlCallback; package PlCallback;
use base 'example::Callback'; use base 'example::Callback';
sub run { sub run {
print "PerlCallback.run()\n"; print "PlCallback->run()\n";
} }
} }
# Create an Caller instance
$caller = example::Caller->new();
# Add a simple C++ callback (caller owns the callback, so
# we disown it first by clearing the .thisown flag).
print "Adding and calling a normal C++ callback\n"; print "Adding and calling a normal C++ callback\n";
print "----------------------------------------\n"; print "----------------------------------------\n";
my $caller = example::Caller->new(); $callback = example::Callback->new();
my $callback = example::Callback->new(); $callback->DISOWN();
$caller->setCallback($callback); $caller->setCallback($callback);
$caller->call(); $caller->call();
$caller->delCallback(); $caller->delCallback();
$callback = PerlCallback->new(); print
print "\n";
print "Adding and calling a Perl callback\n"; print "Adding and calling a Perl callback\n";
print "------------------------------------\n"; print "----------------------------------\n";
# Add a Perl callback (caller owns the callback, so we
# disown it first by calling DISOWN).
$callback = PlCallback->new();
$callback->DISOWN();
$caller->setCallback($callback); $caller->setCallback($callback);
$caller->call(); $caller->call();
$caller->delCallback(); $caller->delCallback();
# Note that letting go of $callback will not attempt to destroy the # All done.
# object, ownership passed to $caller in the ->setCallback() call, and
# $callback was already destroyed in ->delCallback().
undef $callback;
print "\n"; print "\n";
print "perl exit\n"; print "perl exit\n";

View file

@ -1,48 +1,56 @@
#!/usr/bin/perl # file: runme.pl
use strict;
use warnings;
use example;
# This file illustrates the cross language polymorphism using directors. # This file illustrates the cross language polymorphism using directors.
use example;
# CEO class, which overrides Employee::getPosition().
{ {
# CEO class, which overrides Employee::getPosition().
package CEO; package CEO;
use base 'example::Manager'; use base 'example::Manager';
sub getPosition { sub getPosition {
return 'CEO'; return "CEO";
} }
} }
# Create an instance of CEO, a class derived from the Java proxy of the # Create an instance of our employee extension class, CEO. The calls to
# underlying C++ class. The calls to getName() and getPosition() are standard, # getName() and getPosition() are standard, the call to getTitle() uses
# the call to getTitle() uses the director wrappers to call CEO.getPosition(). # the director wrappers to call CEO->getPosition. $e = CEO->new("Alice")
my $e = CEO->new('Alice');
print "${\ $e->getName } is a ${\ $e->getPosition() }\n"; $e = CEO->new("Alice");
print "Just call her \"${\ $e->getTitle() }\"\n"; print $e->getName(), " is a ", $e->getPosition(), "\n";
printf "Just call her \"%s\"\n", $e->getTitle();
print "----------------------\n"; print "----------------------\n";
# Create a new EmployeeList instance. This class does not have a C++ # Create a new EmployeeList instance. This class does not have a C++
# director wrapper, but can be used freely with other classes that do. # director wrapper, but can be used freely with other classes that do.
my $list = example::EmployeeList->new(); $list = example::EmployeeList->new();
# EmployeeList owns its items, so we must surrender ownership of objects
# we add. This involves calling the DISOWN method to tell the
# C++ director to start reference counting.
$e->DISOWN();
$list->addEmployee($e); $list->addEmployee($e);
print "----------------------\n"; print "----------------------\n";
# Now we access the first four items in list (three are C++ objects that # Now we access the first four items in list (three are C++ objects that
# EmployeeList's constructor adds, the last is our CEO). The virtual # EmployeeList's constructor adds, the last is our CEO). The virtual
# methods of all these instances are treated the same. For items 0, 1, and # methods of all these instances are treated the same. For items 0, 1, and
# 2, all methods resolve in C++. For item 3, our CEO, getTitle calls # 2, both all methods resolve in C++. For item 3, our CEO, getTitle calls
# getPosition which resolves in Perl. The call to getPosition is # getPosition which resolves in Perl. The call to getPosition is
# slightly different, however, because of the overidden getPosition() call, since # slightly different, however, from the $e->getPosition() call above, since
# now the object reference has been "laundered" by passing through # now the object reference has been "laundered" by passing through
# EmployeeList as an Employee*. Previously, Perl resolved the call # EmployeeList as an Employee*. Previously, Perl resolved the call
# immediately in CEO, but now Perl thinks the object is an instance of # immediately in CEO, but now Perl thinks the object is an instance of
# class Employee. So the call passes through the # class Employee (actually EmployeePtr). So the call passes through the
# Employee proxy class and on to the C wrappers and C++ director, # Employee proxy class and on to the C wrappers and C++ director,
# eventually ending up back at the Perl CEO implementation of getPosition(). # eventually ending up back at the CEO implementation of getPosition().
# The call to getTitle() for item 3 runs the C++ Employee::getTitle() # The call to getTitle() for item 3 runs the C++ Employee::getTitle()
# method, which in turn calls getPosition(). This virtual method call # method, which in turn calls getPosition(). This virtual method call
# passes down through the C++ director class to the Perl implementation # passes down through the C++ director class to the Perl implementation
@ -50,16 +58,22 @@ print "----------------------\n";
print "(position, title) for items 0-3:\n"; print "(position, title) for items 0-3:\n";
print " ${\ $list->get_item(0)->getPosition() }, \"${\ $list->get_item(0)->getTitle() }\"\n"; printf " %s, \"%s\"\n", $list->get_item(0)->getPosition(), $list->get_item(0)->getTitle();
print " ${\ $list->get_item(1)->getPosition() }, \"${\ $list->get_item(1)->getTitle() }\"\n"; printf " %s, \"%s\"\n", $list->get_item(1)->getPosition(), $list->get_item(1)->getTitle();
print " ${\ $list->get_item(2)->getPosition() }, \"${\ $list->get_item(2)->getTitle() }\"\n"; printf " %s, \"%s\"\n", $list->get_item(2)->getPosition(), $list->get_item(2)->getTitle();
print " ${\ $list->get_item(3)->getPosition() }, \"${\ $list->get_item(3)->getTitle() }\"\n"; printf " %s, \"%s\"\n", $list->get_item(3)->getPosition(), $list->get_item(3)->getTitle();
print "----------------------\n"; print "----------------------\n";
# Time to delete the EmployeeList, which will delete all the Employee* # Time to delete the EmployeeList, which will delete all the Employee*
# items it contains. The last item is our CEO, which gets destroyed as well. # items it contains. The last item is our CEO, which gets destroyed as its
# reference count goes to zero. The Perl destructor runs, and is still
# able to call self.getName() since the underlying C++ object still
# exists. After this destructor runs the remaining C++ destructors run as
# usual to destroy the object.
undef $list; undef $list;
print "----------------------\n"; print "----------------------\n";
# All done. # All done.
print "perl exit\n"; print "perl exit\n";

View file

@ -238,47 +238,42 @@ public:
{ {
Node *mod = Getattr(n, "module"); Node *mod = Getattr(n, "module");
if (mod) { if (mod) {
Node *options = Getattr(mod, "options"); Node *options = Getattr(mod, "options");
if (options) { if (options) {
int dirprot = 0; int dirprot = 0;
if (Getattr(options, "dirprot")) if (Getattr(options, "dirprot"))
dirprot = 1; dirprot = 1;
if (Getattr(options, "nodirprot")) if (Getattr(options, "nodirprot"))
dirprot = 0; dirprot = 0;
if (Getattr(options, "directors")) { if (Getattr(options, "directors")) {
int allow = 1; int allow = 1;
if (export_all) { if (export_all) {
Printv(stderr, Printv(stderr, "*** directors are not supported with -exportall\n", NIL);
"*** directors are not supported with -exportall\n", NIL); allow = 0;
allow = 0; }
} if (staticoption) {
if (staticoption) { Printv(stderr, "*** directors are not supported with -static\n", NIL);
Printv(stderr, allow = 0;
"*** directors are not supported with -static\n", NIL); }
allow = 0; if (!blessed) {
} Printv(stderr, "*** directors are not supported with -noproxy\n", NIL);
if (!blessed) { allow = 0;
Printv(stderr, }
"*** directors are not supported with -noproxy\n", NIL); if (no_pmfile) {
allow = 0; Printv(stderr, "*** directors are not supported with -nopm\n", NIL);
} allow = 0;
if (no_pmfile) { }
Printv(stderr, if (compat) {
"*** directors are not supported with -nopm\n", NIL); Printv(stderr, "*** directors are not supported with -compat\n", NIL);
allow = 0; allow = 0;
} }
if (compat) { if (allow) {
Printv(stderr, allow_directors();
"*** directors are not supported with -compat\n", NIL); if (dirprot)
allow = 0; allow_dirprot();
} }
if (allow) { }
allow_directors(); }
if (dirprot)
allow_dirprot();
}
}
}
} }
} }
@ -301,8 +296,8 @@ public:
if (directorsEnabled()) { if (directorsEnabled()) {
f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files()); f_runtime_h = NewFile(outfile_h, "w", SWIG_output_files());
if (!f_runtime_h) { if (!f_runtime_h) {
FileErrorDisplay(outfile_h); FileErrorDisplay(outfile_h);
SWIG_exit(EXIT_FAILURE); SWIG_exit(EXIT_FAILURE);
} }
} }
@ -1477,8 +1472,7 @@ public:
String *director_disown; String *director_disown;
if (Getattr(n, "perl5:directordisown")) { if (Getattr(n, "perl5:directordisown")) {
director_disown = NewStringf("%s%s($self);\n", director_disown = NewStringf("%s%s($self);\n", tab4, Getattr(n, "perl5:directordisown"));
tab4, Getattr(n, "perl5:directordisown"));
} else { } else {
director_disown = NewString(""); director_disown = NewString("");
} }
@ -1511,7 +1505,8 @@ public:
type = NewString("SV"); type = NewString("SV");
SwigType_add_pointer(type); SwigType_add_pointer(type);
String *action = NewString(""); String *action = NewString("");
Printv(action, "{\n", " Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n", " result = sv_newmortal();\n" " if (director) sv_setsv(result, director->swig_get_self());\n", "}\n", NIL); Printv(action, "{\n", " Swig::Director *director = SWIG_DIRECTOR_CAST(arg1);\n",
" result = sv_newmortal();\n" " if (director) sv_setsv(result, director->swig_get_self());\n", "}\n", NIL);
Setfile(get_attr, Getfile(n)); Setfile(get_attr, Getfile(n));
Setline(get_attr, Getline(n)); Setline(get_attr, Getline(n));
Setattr(get_attr, "wrap:action", action); Setattr(get_attr, "wrap:action", action);
@ -1534,7 +1529,7 @@ public:
"my $member_func = \"swig_${field}_set\";\n", tab4, "if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename, "my $member_func = \"swig_${field}_set\";\n", tab4, "if (not $self->can($member_func)) {\n", tab8, "my $h = ", cmodule, "::", mrename,
"($self);\n", tab8, "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL); "($self);\n", tab8, "return $h->{$field} = $newval if $h;\n", tab4, "}\n", tab4, "return $self->$member_func($newval);\n", "}\n", NIL);
Delete(mrename); Delete(mrename);
} }
} }
return SWIG_OK; return SWIG_OK;
@ -1707,8 +1702,8 @@ public:
String *saved_nc = none_comparison; String *saved_nc = none_comparison;
none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name); none_comparison = NewStringf("strcmp(SvPV_nolen(ST(0)), \"%s::%s\") != 0", module, class_name);
String *saved_director_prot_ctor_code = director_prot_ctor_code; String *saved_director_prot_ctor_code = director_prot_ctor_code;
director_prot_ctor_code = NewStringf( "if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n" director_prot_ctor_code = NewStringf("if ($comparison) { /* subclassed */\n" " $director_new\n" "} else {\n"
"SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n"); "SWIG_exception_fail(SWIG_RuntimeError, \"accessing abstract class or protected constructor\");\n" "}\n");
Language::constructorHandler(n); Language::constructorHandler(n);
Delete(none_comparison); Delete(none_comparison);
none_comparison = saved_nc; none_comparison = saved_nc;
@ -1732,7 +1727,7 @@ public:
Printv(pcode, "sub ", Swig_name_construct(NSPACE_TODO, symname), " {\n", NIL); Printv(pcode, "sub ", Swig_name_construct(NSPACE_TODO, symname), " {\n", NIL);
} }
const char *pkg = getCurrentClass() && Swig_directorclass(getCurrentClass()) ? "$_[0]" : "shift"; const char *pkg = getCurrentClass() && Swig_directorclass(getCurrentClass())? "$_[0]" : "shift";
Printv(pcode, Printv(pcode,
tab4, "my $pkg = ", pkg, ";\n", tab4, "my $pkg = ", pkg, ";\n",
tab4, "my $self = ", cmodule, "::", Swig_name_construct(NSPACE_TODO, symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL); tab4, "my $self = ", cmodule, "::", Swig_name_construct(NSPACE_TODO, symname), "(@_);\n", tab4, "bless $self, $pkg if defined($self);\n", "}\n\n", NIL);
@ -2083,7 +2078,7 @@ public:
if (Cmp(storage, "virtual") == 0) { if (Cmp(storage, "virtual") == 0) {
if (Cmp(value, "0") == 0) { if (Cmp(value, "0") == 0) {
pure_virtual = true; pure_virtual = true;
} }
} }
@ -2116,18 +2111,18 @@ public:
Append(declaration, " throw("); Append(declaration, " throw(");
if (throw_parm_list) if (throw_parm_list)
Swig_typemap_attach_parms("throws", throw_parm_list, 0); Swig_typemap_attach_parms("throws", throw_parm_list, 0);
for (p = throw_parm_list; p; p = nextSibling(p)) { for (p = throw_parm_list; p; p = nextSibling(p)) {
if (Getattr(p, "tmap:throws")) { if (Getattr(p, "tmap:throws")) {
if (gencomma++) { if (gencomma++) {
Append(w->def, ", "); Append(w->def, ", ");
Append(declaration, ", "); Append(declaration, ", ");
} }
String *str = SwigType_str(Getattr(p, "type"), 0); String *str = SwigType_str(Getattr(p, "type"), 0);
Append(w->def, str); Append(w->def, str);
Append(declaration, str); Append(declaration, str);
Delete(str); Delete(str);
} }
} }
Append(w->def, ")"); Append(w->def, ")");
@ -2143,9 +2138,9 @@ public:
*/ */
if (!is_void) { if (!is_void) {
if (!(ignored_method && !pure_virtual)) { if (!(ignored_method && !pure_virtual)) {
String *cres = SwigType_lstr(returntype, "c_result"); String *cres = SwigType_lstr(returntype, "c_result");
Printf(w->code, "%s;\n", cres); Printf(w->code, "%s;\n", cres);
Delete(cres); Delete(cres);
String *pres = NewStringf("SV *%s", Swig_cresult_name()); String *pres = NewStringf("SV *%s", Swig_cresult_name());
Wrapper_add_local(w, Swig_cresult_name(), pres); Wrapper_add_local(w, Swig_cresult_name(), pres);
Delete(pres); Delete(pres);
@ -2154,14 +2149,14 @@ public:
if (ignored_method) { if (ignored_method) {
if (!pure_virtual) { if (!pure_virtual) {
if (!is_void) if (!is_void)
Printf(w->code, "return "); Printf(w->code, "return ");
String *super_call = Swig_method_call(super, l); String *super_call = Swig_method_call(super, l);
Printf(w->code, "%s;\n", super_call); Printf(w->code, "%s;\n", super_call);
Delete(super_call); Delete(super_call);
} else { } else {
Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname), Printf(w->code, "Swig::DirectorPureVirtualException::raise(\"Attempted to invoke pure virtual method %s::%s\");\n", SwigType_namestr(c_classname),
SwigType_namestr(name)); SwigType_namestr(name));
} }
} else { } else {
/* attach typemaps to arguments (C/C++ -> Perl) */ /* attach typemaps to arguments (C/C++ -> Perl) */
@ -2195,32 +2190,32 @@ public:
int outputs = 0; int outputs = 0;
if (!is_void) if (!is_void)
outputs++; outputs++;
/* build argument list and type conversion string */ /* build argument list and type conversion string */
idx = 0; idx = 0;
p = l; p = l;
while (p) { while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) { if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next"); p = Getattr(p, "tmap:in:next");
continue; continue;
} }
/* old style? caused segfaults without the p!=0 check /* old style? caused segfaults without the p!=0 check
in the for() condition, and seems dangerous in the in the for() condition, and seems dangerous in the
while loop as well. while loop as well.
while (Getattr(p, "tmap:ignore")) { while (Getattr(p, "tmap:ignore")) {
p = Getattr(p, "tmap:ignore:next"); p = Getattr(p, "tmap:ignore:next");
} }
*/ */
if (Getattr(p, "tmap:directorargout") != 0) if (Getattr(p, "tmap:directorargout") != 0)
outputs++; outputs++;
String *pname = Getattr(p, "name"); String *pname = Getattr(p, "name");
String *ptype = Getattr(p, "type"); String *ptype = Getattr(p, "type");
if ((tm = Getattr(p, "tmap:directorin")) != 0) { if ((tm = Getattr(p, "tmap:directorin")) != 0) {
sprintf(source, "obj%d", idx++); sprintf(source, "obj%d", idx++);
String *input = NewString(source); String *input = NewString(source);
Setattr(p, "emit:directorinput", input); Setattr(p, "emit:directorinput", input);
@ -2234,74 +2229,74 @@ public:
Printv(wrap_args, tm, "\n", NIL); Printv(wrap_args, tm, "\n", NIL);
Putc('O', parse_args); Putc('O', parse_args);
Printv(pstack, "XPUSHs(", source, ");\n", NIL); Printv(pstack, "XPUSHs(", source, ");\n", NIL);
p = Getattr(p, "tmap:directorin:next"); p = Getattr(p, "tmap:directorin:next");
continue; continue;
} else if (Cmp(ptype, "void")) { } else if (Cmp(ptype, "void")) {
/* special handling for pointers to other C++ director classes. /* special handling for pointers to other C++ director classes.
* ideally this would be left to a typemap, but there is currently no * ideally this would be left to a typemap, but there is currently no
* way to selectively apply the dynamic_cast<> to classes that have * way to selectively apply the dynamic_cast<> to classes that have
* directors. in other words, the type "SwigDirector_$1_lname" only exists * directors. in other words, the type "SwigDirector_$1_lname" only exists
* for classes with directors. we avoid the problem here by checking * for classes with directors. we avoid the problem here by checking
* module.wrap::directormap, but it's not clear how to get a typemap to * module.wrap::directormap, but it's not clear how to get a typemap to
* do something similar. perhaps a new default typemap (in addition * do something similar. perhaps a new default typemap (in addition
* to SWIGTYPE) called DIRECTORTYPE? * to SWIGTYPE) called DIRECTORTYPE?
*/ */
if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) { if (SwigType_ispointer(ptype) || SwigType_isreference(ptype)) {
Node *module = Getattr(parent, "module"); Node *module = Getattr(parent, "module");
Node *target = Swig_directormap(module, ptype); Node *target = Swig_directormap(module, ptype);
sprintf(source, "obj%d", idx++); sprintf(source, "obj%d", idx++);
String *nonconst = 0; String *nonconst = 0;
/* strip pointer/reference --- should move to Swig/stype.c */ /* strip pointer/reference --- should move to Swig/stype.c */
String *nptype = NewString(Char(ptype) + 2); String *nptype = NewString(Char(ptype) + 2);
/* name as pointer */ /* name as pointer */
String *ppname = Copy(pname); String *ppname = Copy(pname);
if (SwigType_isreference(ptype)) { if (SwigType_isreference(ptype)) {
Insert(ppname, 0, "&"); Insert(ppname, 0, "&");
} }
/* if necessary, cast away const since Python doesn't support it! */ /* if necessary, cast away const since Python doesn't support it! */
if (SwigType_isconst(nptype)) { if (SwigType_isconst(nptype)) {
nonconst = NewStringf("nc_tmp_%s", pname); nonconst = NewStringf("nc_tmp_%s", pname);
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname); String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL); Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
Delete(nonconst_i); Delete(nonconst_i);
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number, Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
"Target language argument '%s' discards const in director method %s::%s.\n", "Target language argument '%s' discards const in director method %s::%s.\n",
SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name)); SwigType_str(ptype, pname), SwigType_namestr(c_classname), SwigType_namestr(name));
} else { } else {
nonconst = Copy(ppname); nonconst = Copy(ppname);
} }
Delete(nptype); Delete(nptype);
Delete(ppname); Delete(ppname);
String *mangle = SwigType_manglestr(ptype); String *mangle = SwigType_manglestr(ptype);
if (target) { if (target) {
String *director = NewStringf("director_%s", mangle); String *director = NewStringf("director_%s", mangle);
Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL); Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL);
Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director); Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Append(wrap_args, "} else {\n"); Append(wrap_args, "} else {\n");
Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
Printf(wrap_args, "SvREFCNT_inc((SV *)%s);\n", source); Printf(wrap_args, "SvREFCNT_inc((SV *)%s);\n", source);
Append(wrap_args, "}\n"); Append(wrap_args, "}\n");
Delete(director); Delete(director);
} else { } else {
Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL); Wrapper_add_localv(w, source, "SV *", source, "= 0", NIL);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source); Printf(pstack, "XPUSHs(sv_2mortal(%s));\n", source);
} }
Putc('O', parse_args); Putc('O', parse_args);
Delete(mangle); Delete(mangle);
Delete(nonconst); Delete(nonconst);
} else { } else {
Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_DIRECTORIN_UNDEF, input_file, line_number,
"Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0), "Unable to use type %s as a function argument in director method %s::%s (skipping method).\n", SwigType_str(ptype, 0),
SwigType_namestr(c_classname), SwigType_namestr(name)); SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_NOWRAP; status = SWIG_NOWRAP;
break; break;
} }
} }
p = nextSibling(p); p = nextSibling(p);
} }
/* add the method name as a PyString */ /* add the method name as a PyString */
@ -2312,7 +2307,7 @@ public:
/* pass the method call on to the Python object */ /* pass the method call on to the Python object */
if (dirprot_mode() && !is_public(n)) { if (dirprot_mode() && !is_public(n)) {
Printf(w->code, "swig_set_inner(\"%s\", true);\n", name); Printf(w->code, "swig_set_inner(\"%s\", true);\n", name);
} }
Append(w->code, "ENTER;\n"); Append(w->code, "ENTER;\n");
@ -2324,22 +2319,22 @@ public:
Printf(w->code, "call_method(\"%s\", G_EVAL | G_SCALAR);\n", pyname); Printf(w->code, "call_method(\"%s\", G_EVAL | G_SCALAR);\n", pyname);
if (dirprot_mode() && !is_public(n)) if (dirprot_mode() && !is_public(n))
Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
/* exception handling */ /* exception handling */
tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0); tm = Swig_typemap_lookup("director:except", n, Swig_cresult_name(), 0);
if (!tm) { if (!tm) {
tm = Getattr(n, "feature:director:except"); tm = Getattr(n, "feature:director:except");
if (tm) if (tm)
tm = Copy(tm); tm = Copy(tm);
} }
Append(w->code, "if (SvTRUE(ERRSV)) {\n"); Append(w->code, "if (SvTRUE(ERRSV)) {\n");
Append(w->code, " PUTBACK;\n FREETMPS;\n LEAVE;\n"); Append(w->code, " PUTBACK;\n FREETMPS;\n LEAVE;\n");
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Replaceall(tm, "$error", "ERRSV"); Replaceall(tm, "$error", "ERRSV");
Printv(w->code, Str(tm), "\n", NIL); Printv(w->code, Str(tm), "\n", NIL);
} else { } else {
Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname); Printf(w->code, " Swig::DirectorMethodException::raise(ERRSV);\n", classname, pyname);
} }
Append(w->code, "}\n"); Append(w->code, "}\n");
Delete(tm); Delete(tm);
@ -2357,62 +2352,62 @@ public:
String *outarg = NewString(""); String *outarg = NewString("");
if (outputs > 1) { if (outputs > 1) {
Wrapper_add_local(w, "output", "SV *output"); Wrapper_add_local(w, "output", "SV *output");
Printf(w->code, "if (count != %d) {\n", outputs); Printf(w->code, "if (count != %d) {\n", outputs);
Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Perl method %s.%sfailed to return a list.\");\n", classname, pyname); Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Perl method %s.%sfailed to return a list.\");\n", classname, pyname);
Append(w->code, "}\n"); Append(w->code, "}\n");
} }
idx = 0; idx = 0;
/* marshal return value */ /* marshal return value */
if (!is_void) { if (!is_void) {
Append(w->code, "SPAGAIN;\n"); Append(w->code, "SPAGAIN;\n");
Printf(w->code, "%s = POPs;\n", Swig_cresult_name()); Printf(w->code, "%s = POPs;\n", Swig_cresult_name());
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w); tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
if (tm != 0) { if (tm != 0) {
if (outputs > 1) { if (outputs > 1) {
Printf(w->code, "output = POPs;\n"); Printf(w->code, "output = POPs;\n");
Replaceall(tm, "$input", "output"); Replaceall(tm, "$input", "output");
} else { } else {
Replaceall(tm, "$input", Swig_cresult_name()); Replaceall(tm, "$input", Swig_cresult_name());
} }
char temp[24]; char temp[24];
sprintf(temp, "%d", idx); sprintf(temp, "%d", idx);
Replaceall(tm, "$argnum", temp); Replaceall(tm, "$argnum", temp);
/* TODO check this */ /* TODO check this */
if (Getattr(n, "wrap:disown")) { if (Getattr(n, "wrap:disown")) {
Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN"); Replaceall(tm, "$disown", "SWIG_POINTER_DISOWN");
} else { } else {
Replaceall(tm, "$disown", "0"); Replaceall(tm, "$disown", "0");
} }
Replaceall(tm, "$result", "c_result"); Replaceall(tm, "$result", "c_result");
Printv(w->code, tm, "\n", NIL); Printv(w->code, tm, "\n", NIL);
Delete(tm); Delete(tm);
} else { } else {
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number, Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname), "Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0),
SwigType_namestr(name)); SwigType_namestr(c_classname), SwigType_namestr(name));
status = SWIG_ERROR; status = SWIG_ERROR;
} }
} }
/* marshal outputs */ /* marshal outputs */
for (p = l; p;) { for (p = l; p;) {
if ((tm = Getattr(p, "tmap:directorargout")) != 0) { if ((tm = Getattr(p, "tmap:directorargout")) != 0) {
if (outputs > 1) { if (outputs > 1) {
Printf(w->code, "output = POPs;\n"); Printf(w->code, "output = POPs;\n");
Replaceall(tm, "$result", "output"); Replaceall(tm, "$result", "output");
} else { } else {
Replaceall(tm, "$result", Swig_cresult_name()); Replaceall(tm, "$result", Swig_cresult_name());
} }
Replaceall(tm, "$input", Getattr(p, "emit:directorinput")); Replaceall(tm, "$input", Getattr(p, "emit:directorinput"));
Printv(w->code, tm, "\n", NIL); Printv(w->code, tm, "\n", NIL);
p = Getattr(p, "tmap:directorargout:next"); p = Getattr(p, "tmap:directorargout:next");
} else { } else {
p = nextSibling(p); p = nextSibling(p);
} }
} }
Delete(parse_args); Delete(parse_args);
@ -2428,13 +2423,13 @@ public:
if (!is_void) { if (!is_void) {
if (!(ignored_method && !pure_virtual)) { if (!(ignored_method && !pure_virtual)) {
String *rettype = SwigType_str(returntype, 0); String *rettype = SwigType_str(returntype, 0);
if (!SwigType_isreference(returntype)) { if (!SwigType_isreference(returntype)) {
Printf(w->code, "return (%s) c_result;\n", rettype); Printf(w->code, "return (%s) c_result;\n", rettype);
} else { } else {
Printf(w->code, "return (%s) *c_result;\n", rettype); Printf(w->code, "return (%s) *c_result;\n", rettype);
} }
Delete(rettype); Delete(rettype);
} }
} }
@ -2448,7 +2443,7 @@ public:
Replaceall(inline_extra_method, name, extra_method_name); Replaceall(inline_extra_method, name, extra_method_name);
Replaceall(inline_extra_method, ";\n", " {\n "); Replaceall(inline_extra_method, ";\n", " {\n ");
if (!is_void) if (!is_void)
Printf(inline_extra_method, "return "); Printf(inline_extra_method, "return ");
String *methodcall = Swig_method_call(super, l); String *methodcall = Swig_method_call(super, l);
Printv(inline_extra_method, methodcall, ";\n }\n", NIL); Printv(inline_extra_method, methodcall, ";\n }\n", NIL);
Delete(methodcall); Delete(methodcall);
@ -2458,10 +2453,10 @@ public:
/* emit the director method */ /* emit the director method */
if (status == SWIG_OK) { if (status == SWIG_OK) {
if (!Getattr(n, "defaultargs")) { if (!Getattr(n, "defaultargs")) {
Replaceall(w->code, "$symname", symname); Replaceall(w->code, "$symname", symname);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
Printv(f_directors_h, declaration, NIL); Printv(f_directors_h, declaration, NIL);
Printv(f_directors_h, inline_extra_method, NIL); Printv(f_directors_h, inline_extra_method, NIL);
} }
} }
@ -2476,7 +2471,7 @@ public:
member_func = 1; member_func = 1;
rv = Language::classDirectorDisown(n); rv = Language::classDirectorDisown(n);
member_func = 0; member_func = 0;
if(rv == SWIG_OK && Swig_directorclass(n)) { if (rv == SWIG_OK && Swig_directorclass(n)) {
String *symname = Getattr(n, "sym:name"); String *symname = Getattr(n, "sym:name");
String *disown = Swig_name_disown(NSPACE_TODO, symname); String *disown = Swig_name_disown(NSPACE_TODO, symname);
Setattr(n, "perl5:directordisown", NewStringf("%s::%s", cmodule, disown)); Setattr(n, "perl5:directordisown", NewStringf("%s::%s", cmodule, disown));