📄 perl.h
字号:
/* perl.h
*
* Copyright (c) 1987-1997, Larry Wall
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
#ifndef H_PERL
#define H_PERL 1
#define OVERLOAD
#ifdef PERL_FOR_X2P
/*
* This file is being used for x2p stuff.
* Above symbol is defined via -D in 'x2p/Makefile.SH'
* Decouple x2p stuff from some of perls more extreme eccentricities.
*/
#undef EMBED
#undef NO_EMBED
#define NO_EMBED
#undef MULTIPLICITY
#undef USE_STDIO
#define USE_STDIO
#endif /* PERL_FOR_X2P */
#ifdef PERL_OBJECT
/* PERL_OBJECT explained - DickH and DougL @ ActiveState.com
Defining PERL_OBJECT turns on creation of a C++ object that
contains all writable core perl global variables and functions.
Stated another way, all necessary global variables and functions
are members of a big C++ object. This object's class is CPerlObj.
This allows a Perl Host to have multiple, independent perl
interpreters in the same process space. This is very important on
Win32 systems as the overhead of process creation is quite high --
this could be even higher than the script compile and execute time
for small scripts.
The perl executable implementation on Win32 is composed of perl.exe
(the Perl Host) and perlX.dll. (the Perl Core). This allows the
same Perl Core to easily be embedded in other applications that use
the perl interpreter.
+-----------+
| Perl Host |
+-----------+
^
|
v
+-----------+ +-----------+
| Perl Core |<->| Extension |
+-----------+ +-----------+ ...
Defining PERL_OBJECT has the following effects:
PERL CORE
1. CPerlObj is defined (this is the PERL_OBJECT)
2. all static functions that needed to access either global
variables or functions needed are made member functions
3. all writable static variables are made member variables
4. all global variables and functions are defined as:
#define var CPerlObj::Perl_var
#define func CPerlObj::Perl_func
* these are in objpp.h
This necessitated renaming some local variables and functions that
had the same name as a global variable or function. This was
probably a _good_ thing anyway.
EXTENSIONS
1. Access to global variables and perl functions is through a
pointer to the PERL_OBJECT. This pointer type is CPerlObj*. This is
made transparent to extension developers by the following macros:
#define var pPerl->Perl_var
#define func pPerl->Perl_func
* these are done in objXSUB.h
This requires that the extension be compiled as C++, which means
that the code must be ANSI C and not K&R C. For K&R extensions,
please see the C API notes located in Win32/GenCAPI.pl. This script
creates a perlCAPI.lib that provides a K & R compatible C interface
to the PERL_OBJECT.
2. Local variables and functions cannot have the same name as perl's
variables or functions since the macros will redefine these. Look for
this if you get some strange error message and it does not look like
the code that you had written. This often happens with variables that
are local to a function.
PERL HOST
1. The perl host is linked with perlX.lib to get perl_alloc. This
function will return a pointer to CPerlObj (the PERL_OBJECT). It
takes pointers to the various PerlXXX_YYY interfaces (see iperlsys.h
for more information on this).
2. The perl host calls the same functions as normally would be
called in setting up and running a perl script, except that the
functions are now member functions of the PERL_OBJECT.
*/
class CPerlObj;
#define STATIC
#define CPERLscope(x) CPerlObj::x
#define CPERLproto CPerlObj *
#define _CPERLproto ,CPERLproto
#define CPERLarg CPerlObj *pPerl
#define CPERLarg_ CPERLarg,
#define _CPERLarg ,CPERLarg
#define PERL_OBJECT_THIS this
#define _PERL_OBJECT_THIS ,this
#define PERL_OBJECT_THIS_ this,
#define CALLRUNOPS (this->*PL_runops)
#define CALLREGCOMP (this->*PL_regcompp)
#define CALLREGEXEC (this->*PL_regexecp)
#else /* !PERL_OBJECT */
#define STATIC static
#define CPERLscope(x) x
#define CPERLproto
#define _CPERLproto
#define CPERLarg void
#define CPERLarg_
#define _CPERLarg
#define PERL_OBJECT_THIS
#define _PERL_OBJECT_THIS
#define PERL_OBJECT_THIS_
#define CALLRUNOPS PL_runops
#define CALLREGCOMP (*PL_regcompp)
#define CALLREGEXEC (*PL_regexecp)
#endif /* PERL_OBJECT */
#define VOIDUSED 1
#include "config.h"
#include "embed.h"
#undef START_EXTERN_C
#undef END_EXTERN_C
#undef EXTERN_C
#ifdef __cplusplus
# define START_EXTERN_C extern "C" {
# define END_EXTERN_C }
# define EXTERN_C extern "C"
#else
# define START_EXTERN_C
# define END_EXTERN_C
# define EXTERN_C
#endif
#ifdef OP_IN_REGISTER
# ifdef __GNUC__
# define stringify_immed(s) #s
# define stringify(s) stringify_immed(s)
#ifdef EMBED
register struct op *Perl_op asm(stringify(OP_IN_REGISTER));
#else
register struct op *op asm(stringify(OP_IN_REGISTER));
#endif
# endif
#endif
/*
* STMT_START { statements; } STMT_END;
* can be used as a single statement, as in
* if (x) STMT_START { ... } STMT_END; else ...
*
* Trying to select a version that gives no warnings...
*/
#if !(defined(STMT_START) && defined(STMT_END))
# if defined(__GNUC__) && !defined(__STRICT_ANSI__) && !defined(__cplusplus)
# define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */
# define STMT_END )
# else
/* Now which other defined()s do we need here ??? */
# if (VOIDFLAGS) && (defined(sun) || defined(__sun__))
# define STMT_START if (1)
# define STMT_END else (void)0
# else
# define STMT_START do
# define STMT_END while (0)
# endif
# endif
#endif
#define NOOP (void)0
#define WITH_THR(s) STMT_START { dTHR; s; } STMT_END
/*
* SOFT_CAST can be used for args to prototyped functions to retain some
* type checking; it only casts if the compiler does not know prototypes.
*/
#if defined(CAN_PROTOTYPE) && defined(DEBUGGING_COMPILE)
#define SOFT_CAST(type)
#else
#define SOFT_CAST(type) (type)
#endif
#ifndef BYTEORDER /* Should never happen -- byteorder is in config.h */
# define BYTEORDER 0x1234
#endif
/* Overall memory policy? */
#ifndef CONSERVATIVE
# define LIBERAL 1
#endif
/*
* The following contortions are brought to you on behalf of all the
* standards, semi-standards, de facto standards, not-so-de-facto standards
* of the world, as well as all the other botches anyone ever thought of.
* The basic theory is that if we work hard enough here, the rest of the
* code can be a lot prettier. Well, so much for theory. Sorry, Henry...
*/
/* define this once if either system, instead of cluttering up the src */
#if defined(MSDOS) || defined(atarist) || defined(WIN32)
#define DOSISH 1
#endif
#if defined(__STDC__) || defined(vax11c) || defined(_AIX) || defined(__stdc__) || defined(__cplusplus)
# define STANDARD_C 1
#endif
#if defined(__cplusplus) || defined(WIN32) || defined(__sgi) || defined(OS2) || defined(__DGUX)
# define DONT_DECLARE_STD 1
#endif
#if defined(HASVOLATILE) || defined(STANDARD_C)
# ifdef __cplusplus
# define VOL // to temporarily suppress warnings
# else
# define VOL volatile
# endif
#else
# define VOL
#endif
#define TAINT (PL_tainted = TRUE)
#define TAINT_NOT (PL_tainted = FALSE)
#define TAINT_IF(c) if (c) { PL_tainted = TRUE; }
#define TAINT_ENV() if (PL_tainting) { taint_env(); }
#define TAINT_PROPER(s) if (PL_tainting) { taint_proper(no_security, s); }
/* XXX All process group stuff is handled in pp_sys.c. Should these
defines move there? If so, I could simplify this a lot. --AD 9/96.
*/
/* Process group stuff changed from traditional BSD to POSIX.
perlfunc.pod documents the traditional BSD-style syntax, so we'll
try to preserve that, if possible.
*/
#ifdef HAS_SETPGID
# define BSD_SETPGRP(pid, pgrp) setpgid((pid), (pgrp))
#else
# if defined(HAS_SETPGRP) && defined(USE_BSD_SETPGRP)
# define BSD_SETPGRP(pid, pgrp) setpgrp((pid), (pgrp))
# else
# ifdef HAS_SETPGRP2 /* DG/UX */
# define BSD_SETPGRP(pid, pgrp) setpgrp2((pid), (pgrp))
# endif
# endif
#endif
#if defined(BSD_SETPGRP) && !defined(HAS_SETPGRP)
# define HAS_SETPGRP /* Well, effectively it does . . . */
#endif
/* getpgid isn't POSIX, but at least Solaris and Linux have it, and it makes
our life easier :-) so we'll try it.
*/
#ifdef HAS_GETPGID
# define BSD_GETPGRP(pid) getpgid((pid))
#else
# if defined(HAS_GETPGRP) && defined(USE_BSD_GETPGRP)
# define BSD_GETPGRP(pid) getpgrp((pid))
# else
# ifdef HAS_GETPGRP2 /* DG/UX */
# define BSD_GETPGRP(pid) getpgrp2((pid))
# endif
# endif
#endif
#if defined(BSD_GETPGRP) && !defined(HAS_GETPGRP)
# define HAS_GETPGRP /* Well, effectively it does . . . */
#endif
/* These are not exact synonyms, since setpgrp() and getpgrp() may
have different behaviors, but perl.h used to define USE_BSDPGRP
(prior to 5.003_05) so some extension might depend on it.
*/
#if defined(USE_BSD_SETPGRP) || defined(USE_BSD_GETPGRP)
# ifndef USE_BSDPGRP
# define USE_BSDPGRP
# endif
#endif
#ifndef _TYPES_ /* If types.h defines this it's easy. */
# ifndef major /* Does everyone's types.h define this? */
# include <sys/types.h>
# endif
#endif
#ifdef __cplusplus
# ifndef I_STDARG
# define I_STDARG 1
# endif
#endif
#ifdef I_STDARG
# include <stdarg.h>
#else
# ifdef I_VARARGS
# include <varargs.h>
# endif
#endif
#include "iperlsys.h"
#ifdef USE_NEXT_CTYPE
#if NX_CURRENT_COMPILER_RELEASE >= 400
#include <objc/NXCType.h>
#else /* NX_CURRENT_COMPILER_RELEASE < 400 */
#include <appkit/NXCType.h>
#endif /* NX_CURRENT_COMPILER_RELEASE >= 400 */
#else /* !USE_NEXT_CTYPE */
#include <ctype.h>
#endif /* USE_NEXT_CTYPE */
#ifdef METHOD /* Defined by OSF/1 v3.0 by ctype.h */
#undef METHOD
#endif
#ifdef I_LOCALE
# include <locale.h>
#endif
#if !defined(NO_LOCALE) && defined(HAS_SETLOCALE)
# define USE_LOCALE
# if !defined(NO_LOCALE_COLLATE) && defined(LC_COLLATE) \
&& defined(HAS_STRXFRM)
# define USE_LOCALE_COLLATE
# endif
# if !defined(NO_LOCALE_CTYPE) && defined(LC_CTYPE)
# define USE_LOCALE_CTYPE
# endif
# if !defined(NO_LOCALE_NUMERIC) && defined(LC_NUMERIC)
# define USE_LOCALE_NUMERIC
# endif
#endif /* !NO_LOCALE && HAS_SETLOCALE */
#include <setjmp.h>
#ifdef I_SYS_PARAM
# ifdef PARAM_NEEDS_TYPES
# include <sys/types.h>
# endif
# include <sys/param.h>
#endif
/* Use all the "standard" definitions? */
#if defined(STANDARD_C) && defined(I_STDLIB)
# include <stdlib.h>
#endif
#define MEM_SIZE Size_t
/* This comes after <stdlib.h> so we don't try to change the standard
* library prototypes; we'll use our own in proto.h instead. */
#ifdef MYMALLOC
# ifdef HIDEMYMALLOC
# define malloc Mymalloc
# define calloc Mycalloc
# define realloc Myrealloc
# define free Myfree
Malloc_t Mymalloc _((MEM_SIZE nbytes));
Malloc_t Mycalloc _((MEM_SIZE elements, MEM_SIZE size));
Malloc_t Myrealloc _((Malloc_t where, MEM_SIZE nbytes));
Free_t Myfree _((Malloc_t where));
# endif
# ifdef EMBEDMYMALLOC
# define malloc Perl_malloc
# define calloc Perl_calloc
# define realloc Perl_realloc
/* VMS' external symbols are case-insensitive, and there's already a */
/* perl_free in perl.h */
#ifdef VMS
# define free Perl_myfree
#else
# define free Perl_free
#endif
Malloc_t Perl_malloc _((MEM_SIZE nbytes));
Malloc_t Perl_calloc _((MEM_SIZE elements, MEM_SIZE size));
Malloc_t Perl_realloc _((Malloc_t where, MEM_SIZE nbytes));
#ifdef VMS
Free_t Perl_myfree _((Malloc_t where));
#else
Free_t Perl_free _((Malloc_t where));
#endif
# endif
# undef safemalloc
# undef safecalloc
# undef saferealloc
# undef safefree
# define safemalloc malloc
# define safecalloc calloc
# define saferealloc realloc
# define safefree free
#endif /* MYMALLOC */
#if defined(STANDARD_C) && defined(I_STDDEF)
# include <stddef.h>
# define STRUCT_OFFSET(s,m) offsetof(s,m)
#else
# define STRUCT_OFFSET(s,m) (Size_t)(&(((s *)0)->m))
#endif
#if defined(I_STRING) || defined(__cplusplus)
# include <string.h>
#else
# include <strings.h>
#endif
#if !defined(HAS_STRCHR) && defined(HAS_INDEX) && !defined(strchr)
#define strchr index
#define strrchr rindex
#endif
#ifdef I_MEMORY
# include <memory.h>
#endif
#ifdef HAS_MEMCPY
# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
# ifndef memcpy
extern char * memcpy _((char*, char*, int));
# endif
# endif
#else
# ifndef memcpy
# ifdef HAS_BCOPY
# define memcpy(d,s,l) bcopy(s,d,l)
# else
# define memcpy(d,s,l) my_bcopy(s,d,l)
# endif
# endif
#endif /* HAS_MEMCPY */
#ifdef HAS_MEMSET
# if !defined(STANDARD_C) && !defined(I_STRING) && !defined(I_MEMORY)
# ifndef memset
extern char *memset _((char*, int, int));
# endif
# endif
#else
# define memset(d,c,l) my_memset(d,c,l)
#endif /* HAS_MEMSET */
#if !defined(HAS_MEMMOVE) && !defined(memmove)
# if defined(HAS_BCOPY) && defined(HAS_SAFE_BCOPY)
# define memmove(d,s,l) bcopy(s,d,l)
# else
# if defined(HAS_MEMCPY) && defined(HAS_SAFE_MEMCPY)
# define memmove(d,s,l) memcpy(d,s,l)
# else
# define memmove(d,s,l) my_bcopy(s,d,l)
# endif
# endif
#endif
#if defined(mips) && defined(ultrix) && !defined(__STDC__)
# undef HAS_MEMCMP
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -