Dean Roehrich writes:
>
> Andy, Ilya, Andreas,
> I've sent a few MM5.06 patches to the makemaker list today that I made
> while working with C++. With Ilya's c_plus_plus-0.1 patch, MM5.06, xsubpp
> 1.922, I can call C++ constructors, destructors, and methods with dynamic
> objects from Perl. I did this with 5.001m.
>
> So... Ilya: I'd like to see your patch fitted to 5.001n. I'd like to see
> this stuff, along with my MM5.06 patches, (xsubpp 1.922 is in patch.1n) go
> into patch.1o--and on to 5.002.
>
> It was pretty much a snap to interface C++ and Perl. I see no reason to
> hold back on this. So Andy, if you were waiting for second opinions--now
> you have it :)
>
> Dean
>
Thanks, even if my main work does not give a lot of fruits recently,
it is very pleasant to see the hobby rewarding.
I sent a newer patch to Andy privately. If you are interested, it
is below.
Btw, here is how I feel about h2xs now: my patches to xsubpp-2.0a
allow literal copies of C declarations for structs (with typedefs and
comments) to be used in .xs files. I feel that h2xs should have
options to extract the struct/union/class declarations into .xs file
(optionally recursively - maybe to a different file to get reed of
noise), and an option for extraction of function declarations (I have
(recursive) extraction of typedefs in one of my Perl files, and
extraction of externs in another, so prototyping should be
easy). After this getting Direct-To-Perl (name modelled after
Direct-To-SOM: compiling C++ into CORBA) should be pretty easy.
Ilya
*** writemain.SH~ Wed Feb 08 16:44:20 1995
--- writemain.SH Tue Oct 10 17:02:48 1995
***************
*** 51,56 ****
--- 51,76 ----
sed '/Do not delete this line--writemain depends on it/q' miniperlmain.c
+
+
+ if test X"$args" != "X" ; then
+ for ext in $args ; do
+ : $ext will either be 'Name' or 'Name1/Name2' etc
+ : convert ext into cname and mname
+ mname=`echo $ext | sed 's!/!::!g'`
+ cname=`echo $mname | sed 's!:!_!g'`
+
+ echo "EXTERN_C void boot_${cname} _((CV* cv));"
+ done
+ fi
+
+ cat << 'EOP'
+
+ static void
+ xs_init()
+ {
+ EOP
+
if test X"$args" != "X" ; then
echo " char *file = __FILE__;"
ai=''
***************
*** 62,68 ****
mname=`echo $ext | sed 's!/!::!g'`
cname=`echo $mname | sed 's!:!_!g'`
! echo " { extern void boot_${cname} _((CV* cv));"
if test "$ext" = "DynaLoader"; then
: Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
: boot_DynaLoader is called directly in DynaLoader.pm
--- 82,88 ----
mname=`echo $ext | sed 's!/!::!g'`
cname=`echo $mname | sed 's!:!_!g'`
! echo " {"
if test "$ext" = "DynaLoader"; then
: Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
: boot_DynaLoader is called directly in DynaLoader.pm
*** miniperlmain.c~ Thu Sep 28 00:00:28 1995
--- miniperlmain.c Tue Oct 10 16:55:34 1995
***************
*** 2,18 ****
--- 2,33 ----
* "The Road goes ever on and on, down from the door where it began."
*/
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
#include "EXTERN.h"
#include "perl.h"
+ #ifdef __cplusplus
+ }
+ # define EXTERN_C extern "C"
+ #else
+ # define EXTERN_C extern
+ #endif
+
static void xs_init _((void));
static PerlInterpreter *my_perl;
int
+ #ifndef CAN_PROTOTYPE
main(argc, argv, env)
int argc;
char **argv;
char **env;
+ #else /* def(CAN_PROTOTYPE) */
+ main(int argc, char **argv, char **env)
+ #endif /* def(CAN_PROTOTYPE) */
{
int exitstatus;
***************
*** 46,53 ****
/* Register any extra external extensions */
static void
xs_init()
{
- /* Do not delete this line--writemain depends on it */
}
--- 61,69 ----
/* Register any extra external extensions */
+ /* Do not delete this line--writemain depends on it */
+
static void
xs_init()
{
}
*** lib/ExtUtils/xsubpp~ Thu Jun 22 07:25:32 1995
--- lib/ExtUtils/xsubpp Tue Oct 10 18:53:10 1995
***************
*** 312,318 ****
sub Q {
my($text) = @_;
! $text =~ tr/#//d;
$text =~ s/\[\[/{/g;
$text =~ s/\]\]/}/g;
$text;
--- 312,318 ----
sub Q {
my($text) = @_;
! $text =~ s/^\#//gm;
$text =~ s/\[\[/{/g;
$text =~ s/\]\]/}/g;
$text;
***************
*** 783,788 ****
--- 783,791 ----
# print initialization routine
print qq/extern "C"\n/ if $cplusplus;
print Q<<"EOF";
+ ##ifdef __cplusplus
+ #extern "C"
+ ##endif
#XS(boot_$Module_cname)
#[[
# dXSARGS;
*** h2xs.SH~ Thu Sep 28 00:00:18 1995
--- h2xs.SH Tue Oct 10 18:34:02 1995
***************
*** 294,302 ****
--- 294,308 ----
warn "Writing $ext$modpname/$modfname.xs\n";
print XS <<"END";
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
+ #ifdef __cplusplus
+ }
+ #endif
END
if( $path_h ){
*** minimod.PL.orig Tue Oct 31 08:12:28 1995
--- minimod.PL Thu Nov 02 22:57:48 1995
***************
*** 53,65 ****
my($pname);
my($dl) = canon('/','DynaLoader');
print $head;
print " char *file = __FILE__;\n";
foreach $_ (@exts){
my($pname) = canon('/', $_);
my($mname, $cname, $ccode);
($mname = $pname) =~ s!/!::!g;
($cname = $pname) =~ s!/!__!g;
! print "\t{ extern void boot_${cname} _((CV* cv));\n";
if ($pname eq $dl){
# Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
# boot_DynaLoader is called directly in DynaLoader.pm
--- 53,77 ----
my($pname);
my($dl) = canon('/','DynaLoader');
print $head;
+
+ foreach $_ (@exts){
+ my($pname) = canon('/', $_);
+ my($mname, $cname);
+ ($mname = $pname) =~ s!/!::!g;
+ ($cname = $pname) =~ s!/!__!g;
+ print "EXTERN_C void boot_${cname} _((CV* cv));\n";
+ }
+
+ my ($tail1,$tail2) = ( $tail =~ /\A(.*\n)(\s*\}.*)\Z/s );
+ print $tail1;
+
print " char *file = __FILE__;\n";
foreach $_ (@exts){
my($pname) = canon('/', $_);
my($mname, $cname, $ccode);
($mname = $pname) =~ s!/!::!g;
($cname = $pname) =~ s!/!__!g;
! print "\t{\n";
if ($pname eq $dl){
# Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
# boot_DynaLoader is called directly in DynaLoader.pm
***************
*** 72,78 ****
}
print "\t}\n";
}
! print $tail;
}
sub canon{
--- 84,90 ----
}
print "\t}\n";
}
! print $tail2;
}
sub canon{
>
> Andy, Ilya, Andreas,
> I've sent a few MM5.06 patches to the makemaker list today that I made
> while working with C++. With Ilya's c_plus_plus-0.1 patch, MM5.06, xsubpp
> 1.922, I can call C++ constructors, destructors, and methods with dynamic
> objects from Perl. I did this with 5.001m.
>
> So... Ilya: I'd like to see your patch fitted to 5.001n. I'd like to see
> this stuff, along with my MM5.06 patches, (xsubpp 1.922 is in patch.1n) go
> into patch.1o--and on to 5.002.
>
> It was pretty much a snap to interface C++ and Perl. I see no reason to
> hold back on this. So Andy, if you were waiting for second opinions--now
> you have it :)
>
> Dean
>
Thanks, even if my main work does not give a lot of fruits recently,
it is very pleasant to see the hobby rewarding.
I sent a newer patch to Andy privately. If you are interested, it
is below.
Btw, here is how I feel about h2xs now: my patches to xsubpp-2.0a
allow literal copies of C declarations for structs (with typedefs and
comments) to be used in .xs files. I feel that h2xs should have
options to extract the struct/union/class declarations into .xs file
(optionally recursively - maybe to a different file to get reed of
noise), and an option for extraction of function declarations (I have
(recursive) extraction of typedefs in one of my Perl files, and
extraction of externs in another, so prototyping should be
easy). After this getting Direct-To-Perl (name modelled after
Direct-To-SOM: compiling C++ into CORBA) should be pretty easy.
Ilya
*** writemain.SH~ Wed Feb 08 16:44:20 1995
--- writemain.SH Tue Oct 10 17:02:48 1995
***************
*** 51,56 ****
--- 51,76 ----
sed '/Do not delete this line--writemain depends on it/q' miniperlmain.c
+
+
+ if test X"$args" != "X" ; then
+ for ext in $args ; do
+ : $ext will either be 'Name' or 'Name1/Name2' etc
+ : convert ext into cname and mname
+ mname=`echo $ext | sed 's!/!::!g'`
+ cname=`echo $mname | sed 's!:!_!g'`
+
+ echo "EXTERN_C void boot_${cname} _((CV* cv));"
+ done
+ fi
+
+ cat << 'EOP'
+
+ static void
+ xs_init()
+ {
+ EOP
+
if test X"$args" != "X" ; then
echo " char *file = __FILE__;"
ai=''
***************
*** 62,68 ****
mname=`echo $ext | sed 's!/!::!g'`
cname=`echo $mname | sed 's!:!_!g'`
! echo " { extern void boot_${cname} _((CV* cv));"
if test "$ext" = "DynaLoader"; then
: Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
: boot_DynaLoader is called directly in DynaLoader.pm
--- 82,88 ----
mname=`echo $ext | sed 's!/!::!g'`
cname=`echo $mname | sed 's!:!_!g'`
! echo " {"
if test "$ext" = "DynaLoader"; then
: Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
: boot_DynaLoader is called directly in DynaLoader.pm
*** miniperlmain.c~ Thu Sep 28 00:00:28 1995
--- miniperlmain.c Tue Oct 10 16:55:34 1995
***************
*** 2,18 ****
--- 2,33 ----
* "The Road goes ever on and on, down from the door where it began."
*/
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+
#include "EXTERN.h"
#include "perl.h"
+ #ifdef __cplusplus
+ }
+ # define EXTERN_C extern "C"
+ #else
+ # define EXTERN_C extern
+ #endif
+
static void xs_init _((void));
static PerlInterpreter *my_perl;
int
+ #ifndef CAN_PROTOTYPE
main(argc, argv, env)
int argc;
char **argv;
char **env;
+ #else /* def(CAN_PROTOTYPE) */
+ main(int argc, char **argv, char **env)
+ #endif /* def(CAN_PROTOTYPE) */
{
int exitstatus;
***************
*** 46,53 ****
/* Register any extra external extensions */
static void
xs_init()
{
- /* Do not delete this line--writemain depends on it */
}
--- 61,69 ----
/* Register any extra external extensions */
+ /* Do not delete this line--writemain depends on it */
+
static void
xs_init()
{
}
*** lib/ExtUtils/xsubpp~ Thu Jun 22 07:25:32 1995
--- lib/ExtUtils/xsubpp Tue Oct 10 18:53:10 1995
***************
*** 312,318 ****
sub Q {
my($text) = @_;
! $text =~ tr/#//d;
$text =~ s/\[\[/{/g;
$text =~ s/\]\]/}/g;
$text;
--- 312,318 ----
sub Q {
my($text) = @_;
! $text =~ s/^\#//gm;
$text =~ s/\[\[/{/g;
$text =~ s/\]\]/}/g;
$text;
***************
*** 783,788 ****
--- 783,791 ----
# print initialization routine
print qq/extern "C"\n/ if $cplusplus;
print Q<<"EOF";
+ ##ifdef __cplusplus
+ #extern "C"
+ ##endif
#XS(boot_$Module_cname)
#[[
# dXSARGS;
*** h2xs.SH~ Thu Sep 28 00:00:18 1995
--- h2xs.SH Tue Oct 10 18:34:02 1995
***************
*** 294,302 ****
--- 294,308 ----
warn "Writing $ext$modpname/$modfname.xs\n";
print XS <<"END";
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
+ #ifdef __cplusplus
+ }
+ #endif
END
if( $path_h ){
*** minimod.PL.orig Tue Oct 31 08:12:28 1995
--- minimod.PL Thu Nov 02 22:57:48 1995
***************
*** 53,65 ****
my($pname);
my($dl) = canon('/','DynaLoader');
print $head;
print " char *file = __FILE__;\n";
foreach $_ (@exts){
my($pname) = canon('/', $_);
my($mname, $cname, $ccode);
($mname = $pname) =~ s!/!::!g;
($cname = $pname) =~ s!/!__!g;
! print "\t{ extern void boot_${cname} _((CV* cv));\n";
if ($pname eq $dl){
# Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
# boot_DynaLoader is called directly in DynaLoader.pm
--- 53,77 ----
my($pname);
my($dl) = canon('/','DynaLoader');
print $head;
+
+ foreach $_ (@exts){
+ my($pname) = canon('/', $_);
+ my($mname, $cname);
+ ($mname = $pname) =~ s!/!::!g;
+ ($cname = $pname) =~ s!/!__!g;
+ print "EXTERN_C void boot_${cname} _((CV* cv));\n";
+ }
+
+ my ($tail1,$tail2) = ( $tail =~ /\A(.*\n)(\s*\}.*)\Z/s );
+ print $tail1;
+
print " char *file = __FILE__;\n";
foreach $_ (@exts){
my($pname) = canon('/', $_);
my($mname, $cname, $ccode);
($mname = $pname) =~ s!/!::!g;
($cname = $pname) =~ s!/!__!g;
! print "\t{\n";
if ($pname eq $dl){
# Must NOT install 'DynaLoader::boot_DynaLoader' as 'bootstrap'!
# boot_DynaLoader is called directly in DynaLoader.pm
***************
*** 72,78 ****
}
print "\t}\n";
}
! print $tail;
}
sub canon{
--- 84,90 ----
}
print "\t}\n";
}
! print $tail2;
}
sub canon{