Mailing List Archive

C++ perl
The following patch enables compiling perlmain.c in C++ mode. What is
missing is Configure support, and (maybe?) xsubpp support for
conditional extern "C" on boot_Ext:

#ifdef __cplusplus
extern "C"
#endif


Enjoy,
Ilya

PS To have C++ capable perl I just edited a line in cflags (with gcc):

perlmain) cc="$cc -x c++";;

*** 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()
{
}
Re: C++ perl [ In reply to ]
> From: Ilya Zakharevich <ilya@math.ohio-state.edu>
>
> > The following patch enables compiling perlmain.c in C++ mode. What is
> > missing is Configure support, and (maybe?) xsubpp support for
> > conditional extern "C" on boot_Ext:
> .....
> > PS To have C++ capable perl I just edited a line in cflags (with gcc):
> >
> > perlmain) cc="$cc -x c++";;
>
> Now I have a complete patch (except Configure issue) and a test
> extension running. The extension (together with the patch) is on
> ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
>
> It is tested with dynamic loading under OS/2.
>
> The patch is below,

I hope this makes it into Perl5.002. It'll be important for CORBA work.

Tim.
Re: C++ perl [ In reply to ]
From: Ilya Zakharevich <ilya@math.ohio-state.edu>

...

> *** 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;

I don't have a problem rolling the spirit of your patch into the latest
copies of xsubpp, Ilya. A questions though.

Does the construct below work will *all* C++ compilers?

#ifdef __cplusplus
extern "C"
#endif

If so, then I can drop the line

print qq/extern "C"\n/ if $cplusplus;

which is still left by your patch. It also means I can also drop the -C++
command line option.



Paul
Re: C++ perl [ In reply to ]
Paul Marquess writes:
> Does the construct below work will *all* C++ compilers?
>
> #ifdef __cplusplus
> extern "C"
> #endif
>

Well, I have never seen it documented, but I took it from the files
setup for both C and C++ compile. You may always -D__cplusplus, right?

> If so, then I can drop the line
>
> print qq/extern "C"\n/ if $cplusplus;
>
> which is still left by your patch. It also means I can also drop the -C++
> command line option.
>

I did not find it in my copy. I think it is introduced after 5.001m,
right?

[CRY OF DESPAIR]

Since I need to maintain OS/2 patches as well, I did modify
5.001m.

Ilya
Re: C++ perl [ In reply to ]
> But do they all have __cplusplus defined?

I've seen code which says `#ifdef c_plusplus' -- probably from before
ANSI times, when implementations did not need to start internal symbols
with `__'.


Regards,

Hallvard
Re: C++ perl [ In reply to ]
%% Regarding Re: C++ perl; you wrote:

pm> From: Ilya Zakharevich <ilya@math.ohio-state.edu>
>>
>> Paul Marquess writes:
>> > Does the construct below work will *all* C++ compilers?
>> >
>> > #ifdef __cplusplus
>> > extern "C"
>> > #endif
>> >
>>
>> Well, I have never seen it documented, but I took it from the files
>> setup for both C and C++ compile. You may always -D__cplusplus, right?

I don't know if this fixes your problem but the standard suggests

#ifdef __cplusplus
extern "C" {
#endif

<c linkage stuff>

#ifdef __cplusplus
} /* extern "C" */
#endif

I believe I got this from the ANSI draft standard so this should be
supported by all compilers.

maybe the bracket appears later in your example above but I have always
seen it on the same line.

-GSM
Re: C++ perl [ In reply to ]
Paul Marquess writes:
>
> Nope, the C++ option has been in xsubpp since 5.000.
>

Sorry, pilot error. I was thinking about h2xs :-(.

>
> Are your OS/2 patches for xsubpp capable of being merged back into the
> official release?
>

Patches touch a lot of files, but not xsubpp. Nevertheless, I need
a virgin distribution to be able to 'diff -cr' it on demand.

Ilya
Re: C++ perl [ In reply to ]
Joe Marzot writes:
> I don't know if this fixes your problem but the standard suggests
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
> <c linkage stuff>
>
> #ifdef __cplusplus
> } /* extern "C" */
> #endif
>
> I believe I got this from the ANSI draft standard so this should be
> supported by all compilers.
>
> maybe the bracket appears later in your example above but I have always
> seen it on the same line.
>

You do not need bracket to modify linkage of one function.

Ilya
Re: C++ perl [ In reply to ]
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
>
> Paul Marquess writes:
> > Does the construct below work will *all* C++ compilers?
> >
> > #ifdef __cplusplus
> > extern "C"
> > #endif
> >
>
> Well, I have never seen it documented, but I took it from the files
> setup for both C and C++ compile. You may always -D__cplusplus, right?

Sorry, I'm not a C++ person. Can someone who knows for sure please give
a ruling on this.

> > If so, then I can drop the line
> >
> > print qq/extern "C"\n/ if $cplusplus;
> >
> > which is still left by your patch. It also means I can also drop the -C++
> > command line option.
> >
>
> I did not find it in my copy. I think it is introduced after 5.001m,
> right?

Nope, the C++ option has been in xsubpp since 5.000.

I'm a bit confused as to how it isn't in your copy of xsubpp, but does
show up in your patch.


> [CRY OF DESPAIR]
>
> Since I need to maintain OS/2 patches as well, I did modify
> 5.001m.

Are your OS/2 patches for xsubpp capable of being merged back into the
official release?


Paul
Re: C++ perl [ In reply to ]
On Fri, 13 Oct 1995, Ilya Zakharevich wrote:

> You do not need bracket to modify linkage of one function.

Doesn't hurt to put the brackets in, though.

> Ilya


--
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)
Re: C++ perl [ In reply to ]
From: Aaron Sherman <ajs@vorlon.ajs.com>

>
>
> In general C++ compilers want:
>
> extern "C" {
> /* c-code, includes, etc */
> }

But do they all have __cplusplus defined?

Paul