Mailing List Archive

xsubpp 1.924 patch
Alright, let's get the C++ stuff straight :) I don't know why, but it
occurred to me that someone may actually care if they get a C++ static or
dynamic object.

When we use the following XSUB we want a dynamic C++ object:

color *
color::new()

We want the C++ 'new' to be called to create a dynamic object (which is
given as an argument to the C++ 'delete' function by DESTROY), and we want
the XSUB to expect an implied argument called CLASS, of type char*. So
it'll look like this (I have a typemap which expects the CLASS variable for
the blessing in sv_setref_pv):

XS(XS_CookBook__Ex7_new)
{
dXSARGS;
if (items != 1)
croak("Usage: CookBook::Ex7::new(CLASS)");
{
char * CLASS = (char *)SvPV(ST(0),na);
color * RETVAL;

RETVAL = new color();
ST(0) = sv_newmortal();
sv_setref_pv( ST(0), CLASS, (void*)RETVAL );

}
XSRETURN(1);
}

On the other hand, the following XSUB should create a static object (I don't
understand the rationale behind this yet--why use a static object if it's
going to be passed out of its scope? Shouldn't a dynamic object be used
instead?):

static color
color::new()

and this makes my head spin (I'm winging it, mostly--I need to borrow a C++
book again). My patch attempts to handle this, but I suspect it's wrong,
I'm sure.

So, I have the dynamic object stuff working, and methods and destructors for
it, too. The static object constructor stuff is all there, and doesn't
appear to be interfering with progress so I figure it can stay as-is until
one of us has a need for it :)


Dean


*** lib/ExtUtils/xsubpp Wed Nov 29 22:12:10 1995
--- ../patches/xsubpp Wed Nov 29 22:10:53 1995
***************
*** 573,579 ****

@args = split(/\s*,\s*/, $orig_args);
if (defined($class)) {
! my $arg0 = (defined($static) ? "CLASS" : "THIS");
unshift(@args, $arg0);
($orig_args = "$arg0, $orig_args") =~ s/^$arg0, $/$arg0/;
}
--- 573,579 ----

@args = split(/\s*,\s*/, $orig_args);
if (defined($class)) {
! my $arg0 = ((defined($static) or $func_name =~ /^new/) ? "CLASS" : "THIS");
unshift(@args, $arg0);
($orig_args = "$arg0, $orig_args") =~ s/^$arg0, $/$arg0/;
}
***************
*** 672,678 ****
if ($kwd eq 'PREINIT') { &print_section; } else { &INPUT_handler; }
}
if (!$thisdone && defined($class)) {
! if (defined($static)) {
print "\tchar *";
$var_types{"CLASS"} = "char *";
&generate_init("char *", 1, "CLASS");
--- 672,678 ----
if ($kwd eq 'PREINIT') { &print_section; } else { &INPUT_handler; }
}
if (!$thisdone && defined($class)) {
! if (defined($static) or $func_name =~ /^new/) {
print "\tchar *";
$var_types{"CLASS"} = "char *";
&generate_init("char *", 1, "CLASS");
***************
*** 723,734 ****
}
if (defined($static)) {
if ($func_name =~ /^new/) {
! $func_name .= " $class";
} else {
print "${class}::";
}
} elsif (defined($class)) {
print "THIS->";
}
$func_name =~ s/^($spat)//
if defined($spat);
--- 723,738 ----
}
if (defined($static)) {
if ($func_name =~ /^new/) {
! $func_name = "$class";
} else {
print "${class}::";
}
} elsif (defined($class)) {
+ if ($func_name =~ /^new/) {
+ $func_name .= " $class";
+ } else {
print "THIS->";
+ }
}
$func_name =~ s/^($spat)//
if defined($spat);