473,606 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Experts on embedding Perl in C wanted: Weird problem on RH7.3/Perl 5.6.1

Hi,

I'm tearing my hair out on this one. I'm trying to embed a Perl
interpreter into a C program. I need to be able to create and destroy
the interpreter periodically, but will never actually have two interpreters
at the same time.

On Red Hat Linux 7.3 with Perl 5.6.1, the attached program segfaults. On
Red Hat 9 with Perl 5.8.0, it works perfectly. Save the program code
as "test-embed-perl.c" and the build script as "buildte". Then run:

sh buildte
./te

to see the behaviour. Enlightenment is appreciated! :-(

A gdb stacktrace shows this:

$ gdb ./te
(gdb) run
Program received signal SIGSEGV, Segmentation fault.
0x080a098b in Perl_sv_upgrade ()
(gdb) where
#0 0x080a098b in Perl_sv_upgrade ()
#1 0x080a4244 in Perl_sv_setpvn ()
#2 0x080a708d in Perl_newSVpvn ()
#3 0x0805abb9 in S_parse_body ()
#4 0x0805a993 in perl_parse ()
#5 0x08059a77 in make_embedded_i nterpreter () at test-embed-perl.c:30
#6 0x08059aa1 in main () at test-embed-perl.c:39
#7 0x400841c4 in __libc_start_ma in () from /lib/libc.so.6

Thanks,

David.

========= buildte =============
#!/bin/sh
echo cc -g `perl -MExtUtils::Embe d -e ccopts` -c -o test-embed-perl.o
test-embed-perl.c
cc -g `perl -MExtUtils::Embe d -e ccopts` -c -o test-embed-perl.o test-embed-perl.c
echo cc -g `perl -MExtUtils::Embe d -e ldopts` -o te test-embed-perl.o -lperl
cc -g `perl -MExtUtils::Embe d -e ldopts` -o te test-embed-perl.o -lperl

======== test-embed-perl.c =========
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl = NULL;

int
make_embedded_i nterpreter()
{
char *argv[5];
int argc;

if (my_perl != NULL) {
perl_destruct(m y_perl);
perl_free(my_pe rl);
my_perl = NULL;
}
my_perl = perl_alloc();
if (!my_perl) {
return -1;
}
PERL_SET_CONTEX T(my_perl);
/* If you leave out the PL_perl_destruc t_level lines, it "works",
but leaks memory like crazy! */
PL_perl_destruc t_level = 1;
perl_construct( my_perl);
PL_perl_destruc t_level = 1;
argv[0] = "";
argv[1] = "-e";
argv[2] = "print(\"foo\\n \");";
argv[3] = NULL;
argc = 3;
perl_parse(my_p erl, NULL, argc, argv, NULL);
perl_run(my_per l);
return 0;
}

int
main()
{
while(1) {
make_embedded_i nterpreter();
}
}

============= Output of perl -V on system where it fails ============
Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
Platform:
osname=linux, osvers=2.4.17-0.13smp, archname=i386-linux
uname='linux daffy.perf.redh at.com 2.4.17-0.13smp #1 smp fri feb 1 10:30:48 est 2002 i686 unknown '
config_args='-des -Doptimize=-O2 -march=i386 -mcpu=i686 -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dcccdlflags=-fPIC -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Uusethreads -Uuseithreads -Uuselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Di_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm'
hint=recommende d, useposix=true, d_sigaction=def ine
usethreads=unde f use5005threads= undef useithreads=und ef usemultiplicity =undef
useperlio=undef d_sfio=undef uselargefiles=u ndef usesocks=undef
use64bitint=und ef use64bitall=und ef uselongdouble=u ndef
Compiler:
cc='gcc', ccflags ='-fno-strict-aliasing -I/usr/local/include',
optimize='-O2 -march=i386 -mcpu=i686',
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='2.9 6 20000731 (Red Hat Linux 7.2 2.96-109)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=defi ne, longlongsize=8, d_longdbl=defin e, longdblsize=12
ivtype='long', ivsize=4, nvtype='double' , nvsize=8, Off_t='off_t', lseeksize=4
alignbytes=4, usemymalloc=n, prototype=defin e
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib
libs=-lnsl -ldl -lm -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
libc=/lib/libc-2.2.5.so, so=so, useshrplib=fals e, libperl=libperl .a
Dynamic Linking:
dlsrc=dl_dlopen .xs, dlext=so, d_dlsymun=undef , ccdlflags='-rdynamic'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options:
Built under linux
Compiled at Apr 1 2002 12:23:22
@INC:
/usr/lib/perl5/5.6.1/i386-linux
/usr/lib/perl5/5.6.1
/usr/lib/perl5/site_perl/5.6.1/i386-linux
/usr/lib/perl5/site_perl/5.6.1
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.6.1/i386-linux
/usr/lib/perl5/vendor_perl/5.6.1
/usr/lib/perl5/vendor_perl
Jul 19 '05 #1
3 3448
Am new to perl but know C alright. Perhaps you
need to allocate some memory to char *argv[]
before you put values into it? Good luck.

Ray

======== test-embed-perl.c =========
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl = NULL;

int
make_embedded_i nterpreter()
{
char *argv[5];
int argc;

if (my_perl != NULL) {
perl_destruct(m y_perl);
perl_free(my_pe rl);
my_perl = NULL;
}
my_perl = perl_alloc();
if (!my_perl) {
return -1;
}
PERL_SET_CONTEX T(my_perl);
/* If you leave out the PL_perl_destruc t_level lines, it "works",
but leaks memory like crazy! */
PL_perl_destruc t_level = 1;
perl_construct( my_perl);
PL_perl_destruc t_level = 1;
argv[0] = "";
argv[1] = "-e";
argv[2] = "print(\"foo\\n \");";
argv[3] = NULL;
argc = 3;
perl_parse(my_p erl, NULL, argc, argv, NULL);
perl_run(my_per l);
return 0;

Jul 19 '05 #2
dinser wrote:
Am new to perl but know C alright. Perhaps you
need to allocate some memory to char *argv[]
before you put values into it? Good luck.


Nope; that's not it. I guess you're not as familiar with C as you think. :-)

Anyone else?

Regards,

David.
======== test-embed-perl.c =========
#include <EXTERN.h>
#include <perl.h>

static PerlInterpreter *my_perl = NULL;

int
make_embedded_i nterpreter()
{
char *argv[5];
int argc;

if (my_perl != NULL) {
perl_destruct(m y_perl);
perl_free(my_pe rl);
my_perl = NULL;
}
my_perl = perl_alloc();
if (!my_perl) {
return -1;
}
PERL_SET_CONTEX T(my_perl);
/* If you leave out the PL_perl_destruc t_level lines, it "works",
but leaks memory like crazy! */
PL_perl_destruc t_level = 1;
perl_construct( my_perl);
PL_perl_destruc t_level = 1;
argv[0] = "";
argv[1] = "-e";
argv[2] = "print(\"foo\\n \");";
argv[3] = NULL;
argc = 3;
perl_parse(my_p erl, NULL, argc, argv, NULL);
perl_run(my_per l);

Jul 19 '05 #3
jpulpiano
1 New Member
Hi,

I am experimenting the same problem on Windows.
I need to do the same and I get the following error:

perl_parse
gdb: kernel event for pid=5488 tid=2148 code=EXCEPTION_ DEBUG_EVENT)
gdb: Target exception EXCEPTION_ACCES S_VIOLATION at 0x28065fbc

Program received signal SIGSEGV, Segmentation fault.
0x28065fbc in perl58!Perl_sv_ setpvn () from c:\Perl\bin\per l58.dll
(gdb) where
#0 0x28065fbc in perl58!Perl_sv_ setpvn () from c:\Perl\bin\per l58.dll
#1 0x28024851 in perl_parse () from c:\Perl\bin\per l58.dll


The only solution I see in my case is to switch on:
Maintaining a persistent interpreter described in
man perlembed or
http://www.linuxonlinehelp.com/man/perlembed.html

Kind regards,

Jean-Philippe
Apr 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4489
by: Wenning Qiu | last post by:
I am researching issues related to emdedding Python in C++ for a project. My project will be running on an SMP box and requires scalability. However, my test shows that Python threading has very poor performance in terms of scaling. In fact it doesn't scale at all. I wrote a simple test program to complete given number of iterations of a simple loop. The total number of iterations can be divided evenly among a number of threads. My...
0
1323
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify: - if Python correctly supports multiple sub-interpreters (Py_NewInterpreter) ?
0
1417
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application runnig on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify:
1
2804
by: Kris De Schutter | last post by:
Hello everyone, I'm looking for a document which shows me how to set up a C application with an embedded Perl engine in such a way that the Perl engine can call back to the parent application. I've figured out how to embed Perl and do calls from C to Perl. It's the callback part I'm having trouble with. Can anyone point me in the right direction ? It would be greatly
1
1829
by: Tommy Nordgren | last post by:
I want to write an application that embeds and extends (at least) the Python and Perl interpreters. Now i want to find as much as possible about the Python tools used for extending and embedding Python. To be more specific: My app should: 1. Parse an input file. 2. Call a script in some scripting language, to generate an output file, for example in C++. For task 2 I need to call an embedded interpreter, and also provide call backs from...
4
1674
by: adsheehan | last post by:
Hi, I am embedding Python into a multi-threaded C++ application running on Solaris and need urgent clarification on the embedding architecture and its correct usage (as I am experience weird behaviors). Can anyone clarify:
3
1382
by: PerlPhi | last post by:
hi! i have a Perl code in here that when ran the program accepts any Perl codes from the user input (<STDIN>, of course use no syntax errors), then after breaking the multiline input, the inputs will be part of the program codes and well executed simoultaneously after breaking the multiline input. my novice codes as follows: #!/perl/bin/perl use strict; if (-e "sign.me") { unlink "sign.me";
2
1969
by: IvanIV | last post by:
Hi All, I have trouble with embedding a Perl interpreter into a C program. I would like to replace some subroutine in a Perl script without changing this script from my C program. I need replace (override build-in function): print() and exit() functions. I know that in Perl script I can’t override print(), but for exit() function I can: use subs ‘exit’; sub exit { CORE::print “Overriding exit”; } exit(1);
3
3899
by: happyse27 | last post by:
Hi All, I am creating the perl script using html form(with embedded javascript inside). When using this html form with javascript alone, it works where the form validation will pop up javascript windows to say the field is not keyed into properly. However, when i convert this html(with javascript inside) into perl script, the perl script did not validate when i keyed incorrect data in the form and it straight away executed perl script...
0
8045
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8467
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8462
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8127
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5994
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3952
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4011
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2458
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1315
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.