Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

ppport.h

00001 /* This file is Based on output from 
00002  * Perl/Pollution/Portability Version 2.0000 */
00003 
00004 #ifndef _P_P_PORTABILITY_H_
00005 #define _P_P_PORTABILITY_H_
00006 
00007 #ifndef PERL_REVISION
00008 #   ifndef __PATCHLEVEL_H_INCLUDED__
00009 #       include "patchlevel.h"
00010 #   endif
00011 #   ifndef PERL_REVISION
00012 #       define PERL_REVISION    (5)
00013         /* Replace: 1 */
00014 #       define PERL_VERSION     PATCHLEVEL
00015 #       define PERL_SUBVERSION  SUBVERSION
00016         /* Replace PERL_PATCHLEVEL with PERL_VERSION */
00017         /* Replace: 0 */
00018 #   endif
00019 #endif
00020 
00021 #define PERL_BCDVERSION ((PERL_REVISION * 0x1000000L) + (PERL_VERSION * 0x1000L) + PERL_SUBVERSION)
00022 
00023 #ifndef ERRSV
00024 #       define ERRSV perl_get_sv("@",FALSE)
#endif

#if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION <= 5))
/* Replace: 1 */
#       define PL_Sv            Sv
#       define PL_compiling     compiling
#       define PL_copline       copline
#       define PL_curcop        curcop
#       define PL_curstash      curstash
#       define PL_defgv         defgv
#       define PL_dirty         dirty
#       define PL_hints         hints
#       define PL_na            na
#       define PL_perldb        perldb
#       define PL_rsfp_filters  rsfp_filters
#       define PL_rsfp          rsfp
#       define PL_stdingv       stdingv
#       define PL_sv_no         sv_no
#       define PL_sv_undef      sv_undef
#       define PL_sv_yes        sv_yes
/* Replace: 0 */
#endif

#ifndef pTHX
#    define pTHX
#    define pTHX_
#    define aTHX
#    define aTHX_
#endif         

#ifndef PTR2IV
#    define PTR2IV(d)   (IV)(d)
#endif
 
#ifndef INT2PTR
#    define INT2PTR(any,d)      (any)(d)
#endif

#ifndef dTHR
#  ifdef WIN32
#       define dTHR extern int Perl___notused
#  else
#       define dTHR extern int errno
#  endif
#endif

#ifndef boolSV
#       define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no)
#endif

#ifndef gv_stashpvn
#       define gv_stashpvn(str,len,flags) gv_stashpv(str,flags)
#endif

#ifndef newSVpvn
#       define newSVpvn(data,len) ((len) ? newSVpv ((data), (len)) : newSVpv ("", 0))
#endif

#ifndef newRV_inc
/* Replace: 1 */
#       define newRV_inc(sv) newRV(sv)
/* Replace: 0 */
#endif

/* DEFSV appears first in 5.004_56 */
#ifndef DEFSV
#  define DEFSV GvSV(PL_defgv)
#endif

#ifndef SAVE_DEFSV
#    define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv))
#endif

#ifndef newRV_noinc
#  ifdef __GNUC__
#    define newRV_noinc(sv)               \
      ({                                  \
          SV *nsv = (SV*)newRV(sv);       \
          SvREFCNT_dec(sv);               \
          nsv;                            \
      })
#  else
#    if defined(CRIPPLED_CC) || defined(USE_THREADS)
static SV * newRV_noinc (SV * sv)
{
          SV *nsv = (SV*)newRV(sv);       
          SvREFCNT_dec(sv);               
          return nsv;                     
}
#    else
#      define newRV_noinc(sv)    \
        ((PL_Sv=(SV*)newRV(sv), SvREFCNT_dec(sv), (SV*)PL_Sv)
#    endif
#  endif
#endif

/* Provide: newCONSTSUB */

/* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */
#if (PERL_VERSION < 4) || ((PERL_VERSION == 4) && (PERL_SUBVERSION < 63))

#if defined(NEED_newCONSTSUB)
static
#else
extern void newCONSTSUB _((HV * stash, char * name, SV *sv));
#endif

#if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL)
void
newCONSTSUB(stash,name,sv)
HV *stash;
char *name;
SV *sv;
{
        U32 oldhints = PL_hints;
        HV *old_cop_stash = PL_curcop->cop_stash;
        HV *old_curstash = PL_curstash;
        line_t oldline = PL_curcop->cop_line;
        PL_curcop->cop_line = PL_copline;

        PL_hints &= ~HINT_BLOCK_SCOPE;
        if (stash)
                PL_curstash = PL_curcop->cop_stash = stash;

        newSUB(

#if (PERL_VERSION < 3) || ((PERL_VERSION == 3) && (PERL_SUBVERSION < 22))
     /* before 5.003_22 */
                start_subparse(),
#else
#  if (PERL_VERSION == 3) && (PERL_SUBVERSION == 22)
     /* 5.003_22 */
                start_subparse(0),
#  else
     /* 5.003_23  onwards */
                start_subparse(FALSE, 0),
#  endif
#endif

                newSVOP(OP_CONST, 0, newSVpv(name,0)),
                newSVOP(OP_CONST, 0, &PL_sv_no),   /* SvPV(&PL_sv_no) == "" -- GMB */
                newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv))
        );

        PL_hints = oldhints;
        PL_curcop->cop_stash = old_cop_stash;
        PL_curstash = old_curstash;
        PL_curcop->cop_line = oldline;
}
#endif

#endif /* newCONSTSUB */


#ifndef START_MY_CXT

/*
 * Boilerplate macros for initializing and accessing interpreter-local
 * data from C.  All statics in extensions should be reworked to use
 * this, if you want to make the extension thread-safe.  See ext/re/re.xs
 * for an example of the use of these macros.
 *
 * Code that uses these macros is responsible for the following:
 * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts"
00025  * 2. Declare a typedef named my_cxt_t that is a structure that contains
00026  *    all the data that needs to be interpreter-local.
00027  * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t.
00028  * 4. Use the MY_CXT_INIT macro such that it is called exactly once
00029  *    (typically put in the BOOT: section).
00030  * 5. Use the members of the my_cxt_t structure everywhere as
00031  *    MY_CXT.member.
00032  * 6. Use the dMY_CXT macro (a declaration) in all the functions that
00033  *    access MY_CXT.
00034  */
00035 
00036 #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \
00037     defined(PERL_CAPI)    || defined(PERL_IMPLICIT_CONTEXT)
00038 
00039 /* This must appear in all extensions that define a my_cxt_t structure,
00040  * right after the definition (i.e. at file scope).  The non-threads
00041  * case below uses it to declare the data as static. */
00042 #define START_MY_CXT
00043 
00044 #if PERL_REVISION == 5 && \
00045     (PERL_VERSION < 4 || (PERL_VERSION == 4 && PERL_SUBVERSION < 68 ))
00046 /* Fetches the SV that keeps the per-interpreter data. */
00047 #define dMY_CXT_SV \
00048         SV *my_cxt_sv = perl_get_sv(MY_CXT_KEY, FALSE)
00049 #else /* >= perl5.004_68 */
00050 #define dMY_CXT_SV \
00051         SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY,             \
00052                                   sizeof(MY_CXT_KEY)-1, TRUE)
00053 #endif /* < perl5.004_68 */
00054 
00055 /* This declaration should be used within all functions that use the
00056  * interpreter-local data. */
00057 #define dMY_CXT \
00058         dMY_CXT_SV;                                                     \
00059         my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv))
00060 
00061 /* Creates and zeroes the per-interpreter data.
00062  * (We allocate my_cxtp in a Perl SV so that it will be released when
00063  * the interpreter goes away.) */
00064 #define MY_CXT_INIT \
00065         dMY_CXT_SV;                                                     \
00066         /* newSV() allocates one more than needed */                    \
00067         my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\
00068         Zero(my_cxtp, 1, my_cxt_t);                                     \
00069         sv_setuv(my_cxt_sv, PTR2UV(my_cxtp))
00070 
00071 /* This macro must be used to access members of the my_cxt_t structure.
00072  * e.g. MYCXT.some_data */
00073 #define MY_CXT          (*my_cxtp)
00074 
00075 /* Judicious use of these macros can reduce the number of times dMY_CXT
00076  * is used.  Use is similar to pTHX, aTHX etc. */
00077 #define pMY_CXT         my_cxt_t *my_cxtp
00078 #define pMY_CXT_        pMY_CXT,
00079 #define _pMY_CXT        ,pMY_CXT
00080 #define aMY_CXT         my_cxtp
00081 #define aMY_CXT_        aMY_CXT,
00082 #define _aMY_CXT        ,aMY_CXT
00083 
00084 #else /* single interpreter */
00085 
00086 #ifndef NOOP
00087 #  define NOOP (void)0
00088 #endif
00089 
00090 #ifdef HASATTRIBUTE
00091 #  define PERL_UNUSED_DECL __attribute__((unused))
00092 #else
00093 #  define PERL_UNUSED_DECL
00094 #endif    
00095 
00096 #ifndef dNOOP
00097 #  define dNOOP extern int Perl___notused PERL_UNUSED_DECL
00098 #endif
00099 
00100 #define START_MY_CXT    static my_cxt_t my_cxt;
00101 #define dMY_CXT_SV      dNOOP
00102 #define dMY_CXT         dNOOP
00103 #define MY_CXT_INIT     NOOP
00104 #define MY_CXT          my_cxt
00105 
00106 #define pMY_CXT         void
00107 #define pMY_CXT_
00108 #define _pMY_CXT
00109 #define aMY_CXT
00110 #define aMY_CXT_
00111 #define _aMY_CXT
00112 
00113 #endif 
00114 
00115 #endif /* START_MY_CXT */
00116 
00117 #ifdef SvPVbyte
00118 #   if PERL_REVISION == 5 && PERL_VERSION < 7
00119        /* SvPVbyte does not work in perl-5.6.1, borrowed version for 5.7.3 */
00120 #       undef SvPVbyte
00121 #       define SvPVbyte(sv, lp) \
00122           ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \
00123            ? ((lp = SvCUR(sv)), SvPVX(sv)) : my_sv_2pvbyte(aTHX_ sv, &lp))
00124        static char *
00125        my_sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
00126        {
00127            sv_utf8_downgrade(sv,0);
00128            return SvPV(sv,*lp);
00129        }
00130 #   endif
00131 #else
00132 #   define SvPVbyte SvPV
00133 #endif
00134         
00135 #ifndef SvUTF8_off
00136 #    define SvUTF8_off(s)
00137 #endif
00138 
00139 #if 1
00140 #ifdef DBM_setFilter
00141 #undef DBM_setFilter
00142 #undef DBM_ckFilter
00143 #endif
00144 #endif
00145         
00146 #ifndef DBM_setFilter
00147 
00148 /* 
00149    The DBM_setFilter & DBM_ckFilter macros are only used by 
00150    the *DB*_File modules 
00151 */
00152 
00153 #define DBM_setFilter(db_type,code)                             \
00154         {                                                       \
00155             if (db_type)                                        \
00156                 RETVAL = sv_mortalcopy(db_type) ;               \
00157             ST(0) = RETVAL ;                                    \
00158             if (db_type && (code == &PL_sv_undef)) {            \
00159                 SvREFCNT_dec(db_type) ;                         \
00160                 db_type = NULL ;                                \
00161             }                                                   \
00162             else if (code) {                                    \
00163                 if (db_type)                                    \
00164                     sv_setsv(db_type, code) ;                   \
00165                 else                                            \
00166                     db_type = newSVsv(code) ;                   \
00167             }                                                   \
00168         }
00169 
00170 #define DBM_ckFilter(arg,type,name)                             \
00171         if (db->type) {                                         \
00172             /*printf("ckFilter %s\n", name);*/                  \
00173             if (db->filtering) {                                \
00174                 croak("recursion detected in %s", name) ;       \
00175             }                                                   \
00176             ENTER ;                                             \
00177             SAVETMPS ;                                          \
00178             SAVEINT(db->filtering) ;                            \
00179             db->filtering = TRUE ;                              \
00180             SAVESPTR(DEFSV) ;                                   \
00181             if (name[7] == 's')                                 \
00182                 arg = newSVsv(arg);                             \
00183             DEFSV = arg ;                                       \
00184             SvTEMP_off(arg) ;                                   \
00185             PUSHMARK(SP) ;                                      \
00186             PUTBACK ;                                           \
00187             (void) perl_call_sv(db->type, G_DISCARD);           \
00188             SPAGAIN ;                                           \
00189             PUTBACK ;                                           \
00190             FREETMPS ;                                          \
00191             LEAVE ;                                             \
00192             if (name[7] == 's'){                                \
00193                 arg = sv_2mortal(arg);                          \
00194             }                                                   \
00195             SvOKp(arg);                                         \
00196         }
00197 
00198 #endif /* DBM_setFilter */
00199 
00200 #endif /* _P_P_PORTABILITY_H_ */
00201 

Generated on Sun Dec 25 12:14:43 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2