Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

perlman:perlguts2

by gods (Initiate)
on Aug 25, 1999 at 07:31 UTC ( [id://425]=perlman: print w/replies, xml ) Need Help??

perlguts2

Current Perl documentation can be found at perldoc.perl.org.

Here is our local, out-dated (pre-5.6) version:


PerlIO

The most recent development releases of Perl has been experimenting with removing Perl's dependency on the ``normal'' standard I/O suite and allowing other stdio implementations to be used. This involves creating a new abstraction layer that then calls whichever implementation of stdio Perl was compiled with. All XSUBs should now use the functions in the PerlIO abstraction layer and not make any assumptions about what kind of stdio is being used.

For a complete description of the PerlIO abstraction, consult the perlapio manpage.


Putting a C value on Perl stack

A lot of opcodes (this is an elementary operation in the internal perl stack machine) put an SV* on the stack. However, as an optimization the corresponding SV is (usually) not recreated each time. The opcodes reuse specially assigned SVs ( targets) which are (as a corollary) not constantly freed/created.

Each of the targets is created only once (but see Scratchpads and recursion below), and when an opcode needs to put an integer, a double, or a string on stack, it just sets the corresponding parts of its target and puts the target on stack.

The macro to put this target on stack is PUSHTARG, and it is directly used in some opcodes, as well as indirectly in zillions of others, which use it via (X)PUSH[pni].


Scratchpads

The question remains on when the SVs which are targets for opcodes are created. The answer is that they are created when the current unit -- a subroutine or a file (for opcodes for statements outside of subroutines) -- is compiled. During this time a special anonymous Perl array is created, which is called a scratchpad for the current unit.

A scratchpad keeps SVs which are lexicals for the current unit and are targets for opcodes. One can deduce that an SV lives on a scratchpad by looking on its flags: lexicals have SVs_PADMY set, and targets have SVs_PADTMP set.

The correspondence between OPs and targets is not 1-to-1. Different OPs in the compile tree of the unit can use the same target, if this would not conflict with the expected life of the temporary.


Scratchpads and recursion

In fact it is not 100% true that a compiled unit contains a pointer to the scratchpad AV. In fact it contains a pointer to an AV of (initially) one element, and this element is the scratchpad AV. Why do we need an extra level of indirection?

The answer is recursion, and maybe (sometime soon) threads. Both these can create several execution pointers going into the same subroutine. For the subroutine-child not write over the temporaries for the subroutine-parent (lifespan of which covers the call to the child), the parent and the child should have different scratchpads. (And the lexicals should be separate anyway!)

So each subroutine is born with an array of scratchpads (of length 1). On each entry to the subroutine it is checked that the current depth of the recursion is not more than the length of this array, and if it is, new scratchpad is created and pushed into the array.

The targets on this scratchpad are undefs, but they are already marked with correct flags.


Compiled code


Code tree

Here we describe the internal form your code is converted to by Perl. Start with a simple example:

  $a = $b + $c;

This is converted to a tree similar to this one:

             assign-to
           /           \
          +             $a
        /   \
      $b     $c

(but slightly more complicated). This tree reflects the way Perl parsed your code, but has nothing to do with the execution order. There is an additional ``thread'' going through the nodes of the tree which shows the order of execution of the nodes. In our simplified example above it looks like:

     $b ---> $c ---> + ---> $a ---> assign-to

But with the actual compile tree for $a = $b + $c it is different: some nodes optimized away. As a corollary, though the actual tree contains more nodes than our simplified example, the execution order is the same as in our example.


Examining the tree

If you have your perl compiled for debugging (usually done with -D optimize=-g on Configure command line), you may examine the compiled tree by specifying -Dx on the Perl command line. The output takes several lines per node, and for $b+$c it looks like this:

    5           TYPE = add  ===> 6
                TARG = 1
                FLAGS = (SCALAR,KIDS)
                {
                    TYPE = null  ===> (4)
                      (was rv2sv)
                    FLAGS = (SCALAR,KIDS)
                    {
    3                   TYPE = gvsv  ===> 4
                        FLAGS = (SCALAR)
                        GV = main::b
                    }
                }
                {
                    TYPE = null  ===> (5)
                      (was rv2sv)
                    FLAGS = (SCALAR,KIDS)
                    {
    4                   TYPE = gvsv  ===> 5
                        FLAGS = (SCALAR)
                        GV = main::c
                    }
                }

This tree has 5 nodes (one per TYPE specifier), only 3 of them are not optimized away (one per number in the left column). The immediate children of the given node correspond to {} pairs on the same level of indentation, thus this listing corresponds to the tree:

                   add
                 /     \
               null    null
                |       |
               gvsv    gvsv

The execution order is indicated by ===> marks, thus it is 3 4 5 6 (node 6 is not included into above listing), i.e., gvsv gvsv add whatever.


Compile pass 1: check routines

The tree is created by the pseudo-compiler while yacc code feeds it the constructions it recognizes. Since yacc works bottom-up, so does the first pass of perl compilation.

What makes this pass interesting for perl developers is that some optimization may be performed on this pass. This is optimization by so-called check routines. The correspondence between node names and corresponding check routines is described in opcode.pl (do not forget to run make regen_headers if you modify this file).

A check routine is called when the node is fully constructed except for the execution-order thread. Since at this time there are no back-links to the currently constructed node, one can do most any operation to the top-level node, including freeing it and/or creating new nodes above/below it.

The check routine returns the node which should be inserted into the tree (if the top-level node was not modified, check routine returns its argument).

By convention, check routines have names ck_*. They are usually called from new*OP subroutines (or convert) (which in turn are called from perly.y).


Compile pass 1a: constant folding

Immediately after the check routine is called the returned node is checked for being compile-time executable. If it is (the value is judged to be constant) it is immediately executed, and a constant node with the ``return value'' of the corresponding subtree is substituted instead. The subtree is deleted.

If constant folding was not performed, the execution-order thread is created.


Compile pass 2: context propagation

When a context for a part of compile tree is known, it is propagated down through the tree. At this time the context can have 5 values (instead of 2 for runtime context): void, boolean, scalar, list, and lvalue. In contrast with the pass 1 this pass is processed from top to bottom: a node's context determines the context for its children.

Additional context-dependent optimizations are performed at this time. Since at this moment the compile tree contains back-references (via ``thread'' pointers), nodes cannot be free()d now. To allow optimized-away nodes at this stage, such nodes are null()ified instead of free()ing (i.e. their type is changed to OP_NULL).


Compile pass 3: peephole optimization

After the compile tree for a subroutine (or for an eval or a file) is created, an additional pass over the code is performed. This pass is neither top-down or bottom-up, but in the execution order (with additional complications for conditionals). These optimizations are done in the subroutine peep(). Optimizations performed at this stage are subject to the same restrictions as in the pass 2.


API LISTING

This is a listing of functions, macros, flags, and variables that may be useful to extension writers or that may be found while reading other extensions.

Note that all Perl API global variables must be referenced with the PL_ prefix. Some macros are provided for compatibility with the older, unadorned names, but this support will be removed in a future release.

It is strongly recommended that all Perl API functions that don't begin with perl be referenced with an explicit Perl_ prefix.

The sort order of the listing is case insensitive, with any occurrences of '_' ignored for the the purpose of sorting.

av_clear

Clears an array, making it empty. Does not free the memory used by the array itself.

        void    av_clear (AV* ar)
av_extend

Pre-extend an array. The key is the index to which the array should be extended.

        void    av_extend (AV* ar, I32 key)
av_fetch

Returns the SV at the specified index in the array. The key is the index. If lval is set then the fetch will be part of a store. Check that the return value is non-null before dereferencing it to a perlman:perlguts.

See Understanding the Magic of Tied Hashes and Arrays for more information on how to use this function on tied arrays.

        SV**    av_fetch (AV* ar, I32 key, I32 lval)
AvFILL

Same as perlman:perlguts. Deprecated, use perlman:perlguts instead.

av_len

Returns the highest index in the array. Returns -1 if the array is empty.

        I32     av_len (AV* ar)
av_make

Creates a new AV and populates it with a list of SVs. The SVs are copied into the array, so they may be freed after the call to av_make. The new AV will have a reference count of 1.

        AV*     av_make (I32 size, SV** svp)
av_pop

Pops an SV off the end of the array. Returns perlman:perlguts if the array is empty.

        SV*     av_pop (AV* ar)
av_push

Pushes an SV onto the end of the array. The array will grow automatically to accommodate the addition.

        void    av_push (AV* ar, SV* val)
av_shift

Shifts an SV off the beginning of the array.

        SV*     av_shift (AV* ar)
av_store

Stores an SV in an array. The array index is specified as key. The return value will be NULL if the operation failed or if the value did not need to be actually stored within the array (as in the case of tied arrays). Otherwise it can be dereferenced to get the original perlman:perlguts. Note that the caller is responsible for suitably incrementing the reference count of val before the call, and decrementing it if the function returned NULL.

See Understanding the Magic of Tied Hashes and Arrays for more information on how to use this function on tied arrays.

        SV**    av_store (AV* ar, I32 key, SV* val)
av_undef

Undefines the array. Frees the memory used by the array itself.

        void    av_undef (AV* ar)
av_unshift

Unshift the given number of undef values onto the beginning of the array. The array will grow automatically to accommodate the addition. You must then use perlman:perlguts to assign values to these new elements.

        void    av_unshift (AV* ar, I32 num)
CLASS

Variable which is setup by xsubpp to indicate the class name for a C++ XS constructor. This is always a char*. See perlman:perlguts and perlman:perlxs.

Copy

The XSUB-writer's interface to the C memcpy function. The perlman:perlop is the source, d is the destination, n is the number of items, and t is the type. May fail on overlapping copies. See also perlman:perlguts.

        void    Copy( s, d, n, t )
croak

This is the XSUB-writer's interface to Perl's die function. Use this function the same way you use the C printf function. See perlman:perlguts.

CvSTASH

Returns the stash of the CV.

        HV*     CvSTASH( SV* sv )
PL_DBsingle

When Perl is run in debugging mode, with the -d switch, this SV is a boolean which indicates whether subs are being single-stepped. Single-stepping is automatically turned on after every step. This is the C variable which corresponds to Perl's $DB::single variable. See perlman:perlguts.

PL_DBsub

When Perl is run in debugging mode, with the -d switch, this GV contains the SV which holds the name of the sub being debugged. This is the C variable which corresponds to Perl's $DB::sub variable. See perlman:perlguts. The sub name can be found by

        SvPV( GvSV( PL_DBsub ), PL_na )
PL_DBtrace

Trace variable used when Perl is run in debugging mode, with the -d switch. This is the C variable which corresponds to Perl's $DB::trace variable. See perlman:perlguts.

dMARK

Declare a stack marker variable, mark, for the XSUB. See perlman:perlguts and perlman:perlguts.

dORIGMARK

Saves the original stack mark for the XSUB. See perlman:perlguts.

PL_dowarn

The C variable which corresponds to Perl's $^W warning variable.

dSP

Declares a local copy of perl's stack pointer for the XSUB, available via the perlman:perlguts macro. See perlman:perlguts.

dXSARGS

Sets up stack and mark pointers for an XSUB, calling dSP and dMARK. This is usually handled automatically by xsubpp. Declares the perlman:perlguts variable to indicate the number of items on the stack.

dXSI32

Sets up the perlman:perlguts variable for an XSUB which has aliases. This is usually handled automatically by xsubpp.

do_binmode

Switches filehandle to binmode. iotype is what IoTYPE(io) would contain.

        do_binmode(fp, iotype, TRUE);
ENTER

Opening bracket on a callback. See perlman:perlguts and the perlcall manpage.

        ENTER;
EXTEND

Used to extend the argument stack for an XSUB's return values.

        EXTEND( sp, int x )
fbm_compile

Analyses the string in order to make fast searches on it using fbm_instr() -- the Boyer-Moore algorithm.

        void    fbm_compile(SV* sv, U32 flags)
fbm_instr

Returns the location of the SV in the string delimited by str and strend. It returns perlman:perlguts if the string can't be found. The sv does not have to be fbm_compiled, but the search will not be as fast then.

        char*   fbm_instr(char *str, char *strend, SV *sv, U32 flags)
FREETMPS

Closing bracket for temporaries on a callback. See perlman:perlguts and the perlcall manpage.

        FREETMPS;
G_ARRAY

Used to indicate array context. See perlman:perlguts, perlman:perlguts and the perlcall manpage.

G_DISCARD

Indicates that arguments returned from a callback should be discarded. See the perlcall manpage.

G_EVAL

Used to force a Perl eval wrapper around a callback. See the perlcall manpage.

GIMME

A backward-compatible version of perlman:perlguts which can only return perlman:perlguts or perlman:perlguts; in a void context, it returns perlman:perlguts.

GIMME_V

The XSUB-writer's equivalent to Perl's wantarray. Returns perlman:perlguts, perlman:perlguts or perlman:perlguts for void, scalar or array context, respectively.

G_NOARGS

Indicates that no arguments are being sent to a callback. See the perlcall manpage.

G_SCALAR

Used to indicate scalar context. See perlman:perlguts, perlman:perlguts, and the perlcall manpage.

gv_fetchmeth

Returns the glob with the given name and a defined subroutine or NULL. The glob lives in the given stash, or in the stashes accessible via @ISA and @UNIVERSAL.

The argument level should be either 0 or -1. If level==0, as a side-effect creates a glob with the given name in the given stash which in the case of success contains an alias for the subroutine, and sets up caching info for this glob. Similarly for all the searched stashes.

This function grants "SUPER" token as a postfix of the stash name.

The GV returned from perlman:perlguts may be a method cache entry, which is not visible to Perl code. So when calling perlman:perlguts, you should not use the GV directly; instead, you should use the method's CV, which can be obtained from the GV with the GvCV macro.

        GV*     gv_fetchmeth (HV* stash, char* name, STRLEN len, I32 level)
gv_fetchmethod
gv_fetchmethod_autoload

Returns the glob which contains the subroutine to call to invoke the method on the stash. In fact in the presense of autoloading this may be the glob for ``AUTOLOAD''. In this case the corresponding variable $AUTOLOAD is already setup.

The third parameter of perlman:perlguts determines whether AUTOLOAD lookup is performed if the given method is not present: non-zero means yes, look for AUTOLOAD; zero means no, don't look for AUTOLOAD. Calling perlman:perlguts is equivalent to calling perlman:perlguts with a non-zero autoload parameter.

These functions grant "SUPER" token as a prefix of the method name.

Note that if you want to keep the returned glob for a long time, you need to check for it being ``AUTOLOAD'', since at the later time the call may load a different subroutine due to $AUTOLOAD changing its value. Use the glob created via a side effect to do this.

These functions have the same side-effects and as perlman:perlguts with level==0. name should be writable if contains ':' or '\''. The warning against passing the GV returned by perlman:perlguts to perlman:perlguts apply equally to these functions.

        GV*     gv_fetchmethod (HV* stash, char* name)
        GV*     gv_fetchmethod_autoload (HV* stash, char* name, I32 autoload)
G_VOID

Used to indicate void context. See perlman:perlguts and the perlcall manpage.

gv_stashpv

Returns a pointer to the stash for a specified package. If create is set then the package will be created if it does not already exist. If create is not set and the package does not exist then NULL is returned.

        HV*     gv_stashpv (char* name, I32 create)
gv_stashsv

Returns a pointer to the stash for a specified package. See perlman:perlguts.

        HV*     gv_stashsv (SV* sv, I32 create)
GvSV

Return the SV from the GV.

HEf_SVKEY

This flag, used in the length slot of hash entries and magic structures, specifies the structure contains a perlman:perlguts pointer where a char* pointer is to be expected. (For information only--not to be used).

HeHASH

Returns the computed hash stored in the hash entry.

        U32     HeHASH(HE* he)
HeKEY

Returns the actual pointer stored in the key slot of the hash entry. The pointer may be either char* or perlman:perlguts, depending on the value of perlman:perlguts. Can be assigned to. The perlman:perlguts or perlman:perlguts macros are usually preferable for finding the value of a key.

        char*   HeKEY(HE* he)
HeKLEN

If this is negative, and amounts to perlman:perlguts, it indicates the entry holds an perlman:perlguts key. Otherwise, holds the actual length of the key. Can be assigned to. The perlman:perlguts macro is usually preferable for finding key lengths.

        int     HeKLEN(HE* he)
HePV

Returns the key slot of the hash entry as a char* value, doing any necessary dereferencing of possibly perlman:perlguts keys. The length of the string is placed in len (this is a macro, so do not use &len). If you do not care about what the length of the key is, you may use the global variable perlman:perlguts. Remember though, that hash keys in perl are free to contain embedded nulls, so using strlen() or similar is not a good way to find the length of hash keys. This is very similar to the perlman:perlguts macro described elsewhere in this document.

        char*   HePV(HE* he, STRLEN len)
HeSVKEY

Returns the key as an perlman:perlguts, or perlman:perlguts if the hash entry does not contain an perlman:perlguts key.

        HeSVKEY(HE* he)
HeSVKEY_force

Returns the key as an perlman:perlguts. Will create and return a temporary mortal perlman:perlguts if the hash entry contains only a char* key.

        HeSVKEY_force(HE* he)
HeSVKEY_set

Sets the key to a given perlman:perlguts, taking care to set the appropriate flags to indicate the presence of an perlman:perlguts key, and returns the same perlman:perlguts.

        HeSVKEY_set(HE* he, SV* sv)
HeVAL

Returns the value slot (type perlman:perlguts) stored in the hash entry.

        HeVAL(HE* he)
hv_clear

Clears a hash, making it empty.

        void    hv_clear (HV* tb)
hv_delayfree_ent

Releases a hash entry, such as while iterating though the hash, but delays actual freeing of key and value until the end of the current statement (or thereabouts) with perlman:perlguts. See perlman:perlguts and perlman:perlguts.

        void    hv_delayfree_ent (HV* hv, HE* entry)
hv_delete

Deletes a key/value pair in the hash. The value SV is removed from the hash and returned to the caller. The klen is the length of the key. The flags value will normally be zero; if set to G_DISCARD then NULL will be returned.

        SV*     hv_delete (HV* tb, char* key, U32 klen, I32 flags)
hv_delete_ent

Deletes a key/value pair in the hash. The value SV is removed from the hash and returned to the caller. The flags value will normally be zero; if set to G_DISCARD then NULL will be returned. hash can be a valid precomputed hash value, or 0 to ask for it to be computed.

        SV*     hv_delete_ent (HV* tb, SV* key, I32 flags, U32 hash)
hv_exists

Returns a boolean indicating whether the specified hash key exists. The klen is the length of the key.

        bool    hv_exists (HV* tb, char* key, U32 klen)
hv_exists_ent

Returns a boolean indicating whether the specified hash key exists. hash can be a valid precomputed hash value, or 0 to ask for it to be computed.

        bool    hv_exists_ent (HV* tb, SV* key, U32 hash)
hv_fetch

Returns the SV which corresponds to the specified key in the hash. The klen is the length of the key. If lval is set then the fetch will be part of a store. Check that the return value is non-null before dereferencing it to a perlman:perlguts.

See Understanding the Magic of Tied Hashes and Arrays for more information on how to use this function on tied hashes.

        SV**    hv_fetch (HV* tb, char* key, U32 klen, I32 lval)
hv_fetch_ent

Returns the hash entry which corresponds to the specified key in the hash. hash must be a valid precomputed hash number for the given key, or 0 if you want the function to compute it. IF lval is set then the fetch will be part of a store. Make sure the return value is non-null before accessing it. The return value when tb is a tied hash is a pointer to a static location, so be sure to make a copy of the structure if you need to store it somewhere.

See Understanding the Magic of Tied Hashes and Arrays for more information on how to use this function on tied hashes.

        HE*     hv_fetch_ent  (HV* tb, SV* key, I32 lval, U32 hash)
hv_free_ent

Releases a hash entry, such as while iterating though the hash. See perlman:perlguts and perlman:perlguts.

        void    hv_free_ent (HV* hv, HE* entry)
hv_iterinit

Prepares a starting point to traverse a hash table.

        I32     hv_iterinit (HV* tb)

Returns the number of keys in the hash (i.e. the same as HvKEYS(tb)). The return value is currently only meaningful for hashes without tie magic.

NOTE: Before version 5.004_65, perlman:perlguts used to return the number of hash buckets that happen to be in use. If you still need that esoteric value, you can get it through the macro HvFILL(tb).

hv_iterkey

Returns the key from the current position of the hash iterator. See perlman:perlguts.

        char*   hv_iterkey (HE* entry, I32* retlen)
hv_iterkeysv

Returns the key as an perlman:perlguts from the current position of the hash iterator. The return value will always be a mortal copy of the key. Also see perlman:perlguts.

        SV*     hv_iterkeysv  (HE* entry)
hv_iternext

Returns entries from a hash iterator. See perlman:perlguts.

        HE*     hv_iternext (HV* tb)
hv_iternextsv

Performs an perlman:perlguts, perlman:perlguts, and perlman:perlguts in one operation.

        SV*     hv_iternextsv (HV* hv, char** key, I32* retlen)
hv_iterval

Returns the value from the current position of the hash iterator. See perlman:perlguts.

        SV*     hv_iterval (HV* tb, HE* entry)
hv_magic

Adds magic to a hash. See perlman:perlguts.

        void    hv_magic (HV* hv, GV* gv, int how)
HvNAME

Returns the package name of a stash. See perlman:perlguts, perlman:perlguts.

        char*   HvNAME (HV* stash)
hv_store

Stores an SV in a hash. The hash key is specified as key and klen is the length of the key. The hash parameter is the precomputed hash value; if it is zero then Perl will compute it. The return value will be NULL if the operation failed or if the value did not need to be actually stored within the hash (as in the case of tied hashes). Otherwise it can be dereferenced to get the original perlman:perlguts. Note that the caller is responsible for suitably incrementing the reference count of val before the call, and decrementing it if the function returned NULL.

See Understanding the Magic of Tied Hashes and Arrays for more information on how to use this function on tied hashes.

        SV**    hv_store (HV* tb, char* key, U32 klen, SV* val, U32 hash)
hv_store_ent

Stores val in a hash. The hash key is specified as key. The hash parameter is the precomputed hash value; if it is zero then Perl will compute it. The return value is the new hash entry so created. It will be NULL if the operation failed or if the value did not need to be actually stored within the hash (as in the case of tied hashes). Otherwise the contents of the return value can be accessed using the He??? macros described here. Note that the caller is responsible for suitably incrementing the reference count of val before the call, and decrementing it if the function returned NULL.

See Understanding the Magic of Tied Hashes and Arrays for more information on how to use this function on tied hashes.

        HE*     hv_store_ent  (HV* tb, SV* key, SV* val, U32 hash)
hv_undef

Undefines the hash.

        void    hv_undef (HV* tb)
isALNUM

Returns a boolean indicating whether the C char is an ascii alphanumeric character or digit.

        int     isALNUM (char c)
isALPHA

Returns a boolean indicating whether the C char is an ascii alphabetic character.

        int     isALPHA (char c)
isDIGIT

Returns a boolean indicating whether the C char is an ascii digit.

        int     isDIGIT (char c)
isLOWER

Returns a boolean indicating whether the C char is a lowercase character.

        int     isLOWER (char c)
isSPACE

Returns a boolean indicating whether the C char is whitespace.

        int     isSPACE (char c)
isUPPER

Returns a boolean indicating whether the C char is an uppercase character.

        int     isUPPER (char c)
items

Variable which is setup by xsubpp to indicate the number of items on the stack. See perlman:perlxs.

ix

Variable which is setup by xsubpp to indicate which of an XSUB's aliases was used to invoke it. See perlman:perlxs.

LEAVE

Closing bracket on a callback. See perlman:perlguts and the perlcall manpage.

        LEAVE;
looks_like_number

Test if an the content of an SV looks like a number (or is a number).

        int     looks_like_number(SV*)
MARK

Stack marker variable for the XSUB. See perlman:perlguts.

mg_clear

Clear something magical that the SV represents. See perlman:perlguts.

        int     mg_clear (SV* sv)
mg_copy

Copies the magic from one SV to another. See perlman:perlguts.

        int     mg_copy (SV *, SV *, char *, STRLEN)
mg_find

Finds the magic pointer for type matching the SV. See perlman:perlguts.

        MAGIC*  mg_find (SV* sv, int type)
mg_free

Free any magic storage used by the SV. See perlman:perlguts.

        int     mg_free (SV* sv)
mg_get

Do magic after a value is retrieved from the SV. See perlman:perlguts.

        int     mg_get (SV* sv)
mg_len

Report on the SV's length. See perlman:perlguts.

        U32     mg_len (SV* sv)
mg_magical

Turns on the magical status of an SV. See perlman:perlguts.

        void    mg_magical (SV* sv)
mg_set

Do magic after a value is assigned to the SV. See perlman:perlguts.

        int     mg_set (SV* sv)
Move

The XSUB-writer's interface to the C memmove function. The perlman:perlop is the source, d is the destination, n is the number of items, and t is the type. Can do overlapping moves. See also perlman:perlguts.

        void    Move( s, d, n, t )
PL_na

A variable which may be used with perlman:perlguts to tell Perl to calculate the string length.

New

The XSUB-writer's interface to the C malloc function.

        void*   New( x, void *ptr, int size, type )
newAV

Creates a new AV. The reference count is set to 1.

        AV*     newAV (void)
Newc

The XSUB-writer's interface to the C malloc function, with cast.

        void*   Newc( x, void *ptr, int size, type, cast )
newCONSTSUB

Creates a constant sub equivalent to Perl sub FOO () { 123 } which is eligible for inlining at compile-time.

        void    newCONSTSUB(HV* stash, char* name, SV* sv)
newHV

Creates a new HV. The reference count is set to 1.

        HV*     newHV (void)
newRV_inc

Creates an RV wrapper for an SV. The reference count for the original SV is incremented.

        SV*     newRV_inc (SV* ref)

For historical reasons, ``newRV'' is a synonym for ``newRV_inc''.

newRV_noinc

Creates an RV wrapper for an SV. The reference count for the original SV is not incremented.

        SV*     newRV_noinc (SV* ref)
NEWSV

Creates a new SV. A non-zero len parameter indicates the number of bytes of preallocated string space the SV should have. An extra byte for a tailing NUL is also reserved. (SvPOK is not set for the SV even if string space is allocated.) The reference count for the new SV is set to 1. id is an integer id between 0 and 1299 (used to identify leaks).

        SV*     NEWSV (int id, STRLEN len)
newSViv

Creates a new SV and copies an integer into it. The reference count for the SV is set to 1.

        SV*     newSViv (IV i)
newSVnv

Creates a new SV and copies a double into it. The reference count for the SV is set to 1.

        SV*     newSVnv (NV i)
newSVpv

Creates a new SV and copies a string into it. The reference count for the SV is set to 1. If len is zero then Perl will compute the length.

        SV*     newSVpv (char* s, STRLEN len)
newSVpvf

Creates a new SV an initialize it with the string formatted like sprintf.

        SV*     newSVpvf(const char* pat, ...);
newSVpvn

Creates a new SV and copies a string into it. The reference count for the SV is set to 1. If len is zero then Perl will create a zero length string.

        SV*     newSVpvn (char* s, STRLEN len)
newSVrv

Creates a new SV for the RV, rv, to point to. If rv is not an RV then it will be upgraded to one. If classname is non-null then the new SV will be blessed in the specified package. The new SV is returned and its reference count is 1.

        SV*     newSVrv (SV* rv, char* classname)
newSVsv

Creates a new SV which is an exact duplicate of the original SV.

        SV*     newSVsv (SV* old)
newXS

Used by xsubpp to hook up XSUBs as Perl subs.

newXSproto

Used by xsubpp to hook up XSUBs as Perl subs. Adds Perl prototypes to the subs.

Newz

The XSUB-writer's interface to the C malloc function. The allocated memory is zeroed with memzero.

        void*   Newz( x, void *ptr, int size, type )
Nullav

Null AV pointer.

Nullch

Null character pointer.

Nullcv

Null CV pointer.

Nullhv

Null HV pointer.

Nullsv

Null SV pointer.

ORIGMARK

The original stack mark for the XSUB. See perlman:perlguts.

perl_alloc

Allocates a new Perl interpreter. See the perlembed manpage.

perl_call_argv

Performs a callback to the specified Perl sub. See the perlcall manpage.

        I32     perl_call_argv (char* subname, I32 flags, char** argv)
perl_call_method

Performs a callback to the specified Perl method. The blessed object must be on the stack. See the perlcall manpage.

        I32     perl_call_method (char* methname, I32 flags)
perl_call_pv

Performs a callback to the specified Perl sub. See the perlcall manpage.

        I32     perl_call_pv (char* subname, I32 flags)
perl_call_sv

Performs a callback to the Perl sub whose name is in the SV. See the perlcall manpage.

        I32     perl_call_sv (SV* sv, I32 flags)
perl_construct

Initializes a new Perl interpreter. See the perlembed manpage.

perl_destruct

Shuts down a Perl interpreter. See the perlembed manpage.

perl_eval_sv

Tells Perl to eval the string in the SV.

        I32     perl_eval_sv (SV* sv, I32 flags)
perl_eval_pv

Tells Perl to eval the given string and return an SV* result.

        SV*     perl_eval_pv (char* p, I32 croak_on_error)
perl_free

Releases a Perl interpreter. See the perlembed manpage.

perl_get_av

Returns the AV of the specified Perl array. If create is set and the Perl variable does not exist then it will be created. If create is not set and the variable does not exist then NULL is returned.

        AV*     perl_get_av (char* name, I32 create)
perl_get_cv

Returns the CV of the specified Perl sub. If create is set and the Perl variable does not exist then it will be created. If create is not set and the variable does not exist then NULL is returned.

        CV*     perl_get_cv (char* name, I32 create)
perl_get_hv

Returns the HV of the specified Perl hash. If create is set and the Perl variable does not exist then it will be created. If create is not set and the variable does not exist then NULL is returned.

        HV*     perl_get_hv (char* name, I32 create)
perl_get_sv

Returns the SV of the specified Perl scalar. If create is set and the Perl variable does not exist then it will be created. If create is not set and the variable does not exist then NULL is returned.

        SV*     perl_get_sv (char* name, I32 create)
perl_parse

Tells a Perl interpreter to parse a Perl script. See the perlembed manpage.

perl_require_pv

Tells Perl to require a module.

        void    perl_require_pv (char* pv)
perl_run

Tells a Perl interpreter to run. See the perlembed manpage.

POPi

Pops an integer off the stack.

        int     POPi()
POPl

Pops a long off the stack.

        long    POPl()
POPp

Pops a string off the stack.

        char*   POPp()
POPn

Pops a double off the stack.

        double  POPn()
POPs

Pops an SV off the stack.

        SV*     POPs()
PUSHMARK

Opening bracket for arguments on a callback. See perlman:perlguts and the perlcall manpage.

        PUSHMARK(p)
PUSHi

Push an integer onto the stack. The stack must have room for this element. Handles 'set' magic. See perlman:perlguts.

        void    PUSHi(int d)
PUSHn

Push a double onto the stack. The stack must have room for this element. Handles 'set' magic. See perlman:perlguts.

        void    PUSHn(double d)
PUSHp

Push a string onto the stack. The stack must have room for this element. The len indicates the length of the string. Handles 'set' magic. See perlman:perlguts.

        void    PUSHp(char *c, int len )
PUSHs

Push an SV onto the stack. The stack must have room for this element. Does not handle 'set' magic. See perlman:perlguts.

        void    PUSHs(sv)
PUSHu

Push an unsigned integer onto the stack. The stack must have room for this element. See perlman:perlguts.

        void    PUSHu(unsigned int d)
PUTBACK

Closing bracket for XSUB arguments. This is usually handled by xsubpp. See perlman:perlguts and the perlcall manpage for other uses.

        PUTBACK;
Renew

The XSUB-writer's interface to the C realloc function.

        void*   Renew( void *ptr, int size, type )
Renewc

The XSUB-writer's interface to the C realloc function, with cast.

        void*   Renewc( void *ptr, int size, type, cast )
RETVAL

Variable which is setup by xsubpp to hold the return value for an XSUB. This is always the proper type for the XSUB. See perlman:perlxs.

safefree

The XSUB-writer's interface to the C free function.

safemalloc

The XSUB-writer's interface to the C malloc function.

saferealloc

The XSUB-writer's interface to the C realloc function.

savepv

Copy a string to a safe spot. This does not use an SV.

        char*   savepv (char* sv)
savepvn

Copy a string to a safe spot. The len indicates number of bytes to copy. This does not use an SV.

        char*   savepvn (char* sv, I32 len)
SAVETMPS

Opening bracket for temporaries on a callback. See perlman:perlguts and the perlcall manpage.

        SAVETMPS;
SP

Stack pointer. This is usually handled by xsubpp. See perlman:perlguts and perlman:perlguts.

SPAGAIN

Refetch the stack pointer. Used after a callback. See the perlcall manpage.

        SPAGAIN;
ST

Used to access elements on the XSUB's stack.

        SV*     ST(int x)
strEQ

Test two strings to see if they are equal. Returns true or false.

        int     strEQ( char *s1, char *s2 )
strGE

Test two strings to see if the first, s1, is greater than or equal to the second, s2. Returns true or false.

        int     strGE( char *s1, char *s2 )
strGT

Test two strings to see if the first, s1, is greater than the second, s2. Returns true or false.

        int     strGT( char *s1, char *s2 )
strLE

Test two strings to see if the first, s1, is less than or equal to the second, s2. Returns true or false.

        int     strLE( char *s1, char *s2 )
strLT

Test two strings to see if the first, s1, is less than the second, s2. Returns true or false.

        int     strLT( char *s1, char *s2 )
strNE

Test two strings to see if they are different. Returns true or false.

        int     strNE( char *s1, char *s2 )
strnEQ

Test two strings to see if they are equal. The len parameter indicates the number of bytes to compare. Returns true or false.

        int     strnEQ( char *s1, char *s2 )
strnNE

Test two strings to see if they are different. The len parameter indicates the number of bytes to compare. Returns true or false.

        int     strnNE( char *s1, char *s2, int len )
sv_2mortal

Marks an SV as mortal. The SV will be destroyed when the current context ends.

        SV*     sv_2mortal (SV* sv)
sv_bless

Blesses an SV into a specified package. The SV must be an RV. The package must be designated by its stash (see perlman:perlguts). The reference count of the SV is unaffected.

        SV*     sv_bless (SV* sv, HV* stash)
sv_catpv

Concatenates the string onto the end of the string which is in the SV. Handles 'get' magic, but not 'set' magic. See perlman:perlguts.

        void    sv_catpv (SV* sv, char* ptr)
sv_catpv_mg

Like perlman:perlguts, but also handles 'set' magic.

        void    sv_catpvn (SV* sv, char* ptr)
sv_catpvn

Concatenates the string onto the end of the string which is in the SV. The len indicates number of bytes to copy. Handles 'get' magic, but not 'set' magic. See perlman:perlguts.

        void    sv_catpvn (SV* sv, char* ptr, STRLEN len)
sv_catpvn_mg

Like perlman:perlguts, but also handles 'set' magic.

        void    sv_catpvn_mg (SV* sv, char* ptr, STRLEN len)
sv_catpvf

Processes its arguments like sprintf and appends the formatted output to an SV. Handles 'get' magic, but not 'set' magic. perlman:perlguts must typically be called after calling this function to handle 'set' magic.

        void    sv_catpvf (SV* sv, const char* pat, ...)
sv_catpvf_mg

Like perlman:perlguts, but also handles 'set' magic.

        void    sv_catpvf_mg (SV* sv, const char* pat, ...)
sv_catsv

Concatenates the string from SV ssv onto the end of the string in SV dsv. Handles 'get' magic, but not 'set' magic. See perlman:perlguts.

        void    sv_catsv (SV* dsv, SV* ssv)
sv_catsv_mg

Like perlman:perlguts, but also handles 'set' magic.

        void    sv_catsv_mg (SV* dsv, SV* ssv)

More...

Return to the Library
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-12-14 00:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which IDE have you been most impressed by?













    Results (70 votes). Check out past polls.