[prev in list] [next in list] [prev in thread] [next in thread]
List: netsaintplug-devel
Subject: [Netsaintplug-devel] Re: Corrected embedded Perl Netsaint simulator - #ifdef for Perl build (thread
From: Stanley Hopcroft <Stanley.Hopcroft () IPAustralia ! gov ! au>
Date: 2001-11-09 5:35:19
[Download RAW message or body]
Dear Ladies and Gentlemen,
If the macro named 'THREADED_PERL' in the embedded Perl Netsaint
simulator, is replaced by the Perl standard macro 'USE_THREADS', then I
think there is __no__ need to define a macro indicating whether or not
Perl is built to use threads.
The standard include file (in path to Perl/lib/perl_version/arch_name/)
config.h defines the macro 'USE_THREADS' depending on whether or not
Perl is built with threads.
config.h is included by perl.h (and perl.h is included by all programs
that want to embed the Perl interpreter).
So, I think that all the Perl build dependent defines in Netsaint and
the simulator can test
#ifdef USE_THREADS
.. nada ..
#endif
#else
.. yack yack ..
#endif
without having to use 'configure' to determine the Perl build, and
setting a macro in the compiler command line.
However there are some extra warnings from the compiler.
I am not sure of the implications of the extra warnings.
Thank you,
Yours sincerely.
--
------------------------------------------------------------------------
Stanley Hopcroft IP Australia
Network Specialist
+61 2 6283 3189 +61 2 6281 1353 (FAX) Stanley.Hopcroft@IPAustralia.Gov.AU
------------------------------------------------------------------------
Famous last words:
(1) Don't unplug it, it will just take a moment to fix.
(2) Let's take the shortcut, he can't see us from there.
(3) What happens if you touch these two wires tog--
(4) We won't need reservations.
(5) It's always sunny there this time of the year.
(6) Don't worry, it's not loaded.
(7) They'd never (be stupid enough to) make him a manager.
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
#include <string.h>
#ifdef USE_THREADS
/* include PERL xs_init code for module and C library support */
EXTERN_C void xs_init (pTHX);
EXTERN_C void boot_DynaLoader (pTHX_ CV* cv);
EXTERN_C void
xs_init(pTHXo)
{
char *file = __FILE__;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}
#else
# if defined(__cplusplus) && !defined(PERL_OBJECT)
# define is_cplusplus
# endif
# ifdef is_cplusplus
extern "C" {
# endif
# ifdef PERL_OBJECT
# define NO_XSLOCKS
# include "win32iop.h"
# include <fcntl.h>
# include <perlhost.h>
# endif
# ifdef is_cplusplus
}
# ifndef EXTERN_C
# define EXTERN_C extern "C"
# endif
# else
# ifndef EXTERN_C
# define EXTERN_C extern
# endif
# endif
EXTERN_C void xs_init _((void));
EXTERN_C void boot_DynaLoader _((CV* cv));
EXTERN_C void
xs_init(void)
{
char *file = __FILE__;
dXSUB_SYS;
/* DynaLoader is a special case */
newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
}
#endif
static PerlInterpreter *perl = NULL;
int main(int argc, char **argv, char **env){
#ifdef THREADED_PERL
dTHX;
#endif
char *embedding[] = { "", "p1.pl" };
char plugin_output[1024];
char buffer[512];
char tmpfname[32];
char fname[32];
char *args[] = {"","0", "", "", NULL };
FILE *fp;
char command_line[80];
int exitstatus;
int pclose_result;
if((perl=perl_alloc())==NULL){
snprintf(buffer,sizeof(buffer),"Error: Could not allocate memory for embedded Perl interpreter!\n");
buffer[sizeof(buffer)-1]='\x0';
printf("%s\n", buffer);
exit(1);
}
perl_construct(perl);
exitstatus=perl_parse(perl,xs_init,2,embedding,NULL);
if(!exitstatus) {
exitstatus=perl_run(perl);
while(printf("Enter file name: ") && fgets(command_line, 80, stdin)) {
dSP;
/* call the subroutine, passing it the filename as an argument */
command_line[strlen(command_line) -1] = '\0';
strncpy(fname,command_line,strcspn(command_line," "));
fname[strcspn(command_line," ")] = '\x0';
args[0] = fname ;
args[3] = command_line + strlen(fname) + 1 ;
/* generate a temporary filename to which stdout can be redirected. */
sprintf(tmpfname,"/tmp/embedded%d",getpid());
args[2] = tmpfname;
/* call our perl interpreter to compile and optionally cache the command */
perl_call_argv("Embed::Persistent::eval_file", G_DISCARD | G_EVAL, args);
ENTER;
SAVETMPS;
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(args[0],0)));
XPUSHs(sv_2mortal(newSVpv(args[1],0)));
XPUSHs(sv_2mortal(newSVpv(args[2],0)));
XPUSHs(sv_2mortal(newSVpv(args[3],0)));
PUTBACK;
perl_call_pv("Embed::Persistent::run_package", G_EVAL);
SPAGAIN;
pclose_result=POPi;
PUTBACK;
FREETMPS;
LEAVE;
/* check return status */
if(SvTRUE(ERRSV)){
pclose_result=-2;
printf("embedded perl ran %s with error %s\n",fname,SvPV(ERRSV,PL_na));
}
/* read back stdout from script */
fp=fopen(tmpfname, "r");
/* default return string in case nothing was returned */
strcpy(plugin_output,"(No output!)");
fgets(plugin_output,sizeof(plugin_output)-1,fp);
plugin_output[sizeof(plugin_output)-1]='\x0';
fclose(fp);
unlink(tmpfname);
printf("embedded perl plugin return code and output was: %d & '%s'\n",pclose_result, plugin_output);
}
}
PL_perl_destruct_level = 0;
perl_destruct(perl);
perl_free(perl);
exit(exitstatus);
}
pc09011> grep USE_THREADS c52.c
#ifdef USE_THREADS
pc09011> /opt/perl/bin/perl -v | head -2
This is perl, v5.6.1 built for i386-freebsd-thread-multi
pc09011> gcc -Wall -o c52 c52.c `/opt/perl/bin/perl -MExtUtils::Embed -e
ccopts -e ldopts`
c52.c: In function `xs_init':
c52.c:59: warning: passing arg 3 of `Perl_newXS' from incompatible
pointer type
c52.c: In function `main':
c52.c:91: warning: passing arg 2 of `perl_parse' from incompatible
pointer type
pc09011> ./c52
Enter file name: ap
embedded perl plugin return code and output was: 0 & 'In the beginning
was the word and the word was with God
'
Enter file name: ap
embedded perl plugin return code and output was: 0 & 'In the beginning
was the word and the word was with God
'
Enter file name: ap
embedded perl plugin return code and output was: 0 & 'In the beginning
was the word and the word was with God
'
Enter file name: ^C
pc09011>
_______________________________________________
Netsaintplug-devel mailing list
Netsaintplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/netsaintplug-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic