This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
make sprintf("%g",...) threadsafe; only taint its result iff the
[perl5.git] / pod / perlguts.pod
index c20e8b5..af12297 100644 (file)
@@ -38,8 +38,8 @@ The six routines are:
 
     SV*  newSViv(IV);
     SV*  newSVnv(double);
-    SV*  newSVpv(char*, int);
-    SV*  newSVpvn(char*, int);
+    SV*  newSVpv(const char*, int);
+    SV*  newSVpvn(const char*, int);
     SV*  newSVpvf(const char*, ...);
     SV*  newSVsv(SV*);
 
@@ -48,8 +48,8 @@ To change the value of an *already-existing* SV, there are seven routines:
     void  sv_setiv(SV*, IV);
     void  sv_setuv(SV*, UV);
     void  sv_setnv(SV*, double);
-    void  sv_setpv(SV*, char*);
-    void  sv_setpvn(SV*, char*, int)
+    void  sv_setpv(SV*, const char*);
+    void  sv_setpvn(SV*, const char*, int)
     void  sv_setpvf(SV*, const char*, ...);
     void  sv_setpvfn(SV*, const char*, STRLEN, va_list *, SV **, I32, bool);
     void  sv_setsv(SV*, SV*);
@@ -68,7 +68,7 @@ C<sv_setpvfn> is an analogue of C<vsprintf>, but it allows you to specify
 either a pointer to a variable argument list or the address and length of
 an array of SVs.  The last argument points to a boolean; on return, if that
 boolean is true, then locale-specific information has been used to format
-the string, and the string's contents are therefore untrustworty (see
+the string, and the string's contents are therefore untrustworthy (see
 L<perlsec>).  This pointer may be NULL if that information is not
 important.  Note that this function requires you to specify the length of
 the format.
@@ -89,15 +89,28 @@ To access the actual value that an SV points to, you can use the macros:
     SvIV(SV*)
     SvNV(SV*)
     SvPV(SV*, STRLEN len)
+    SvPV_nolen(SV*)
 
 which will automatically coerce the actual scalar type into an IV, double,
 or string.
 
 In the C<SvPV> macro, the length of the string returned is placed into the
-variable C<len> (this is a macro, so you do I<not> use C<&len>).  If you do not
-care what the length of the data is, use the global variable C<na>.  Remember,
-however, that Perl allows arbitrary strings of data that may both contain
-NULs and might not be terminated by a NUL.
+variable C<len> (this is a macro, so you do I<not> use C<&len>).  If you do
+not care what the length of the data is, use the C<SvPV_nolen> macro.
+Historically the C<SvPV> macro with the global variable C<PL_na> has been
+used in this case.  But that can be quite inefficient because C<PL_na> must
+be accessed in thread-local storage in threaded Perl.  In any case, remember
+that Perl allows arbitrary strings of data that may both contain NULs and
+might not be terminated by a NUL.
+
+Also remember that C doesn't allow you to safely say C<foo(SvPV(s, len),
+len);>. It might work with your compiler, but it won't work for everyone.
+Break this sort of statement up into separate assignments:
+
+       STRLEN len;
+       char * ptr;
+       ptr = SvPV(len);
+       foo(ptr, len);
 
 If you want to know if the scalar value is TRUE, you can use:
 
@@ -137,8 +150,8 @@ But note that these last three macros are valid only if C<SvPOK()> is true.
 If you want to append something to the end of string stored in an C<SV*>,
 you can use the following functions:
 
-    void  sv_catpv(SV*, char*);
-    void  sv_catpvn(SV*, char*, int);
+    void  sv_catpv(SV*, const char*);
+    void  sv_catpvn(SV*, const char*, STRLEN);
     void  sv_catpvf(SV*, const char*, ...);
     void  sv_catpvfn(SV*, const char*, STRLEN, va_list *, SV **, I32, bool);
     void  sv_catsv(SV*, SV*);
@@ -167,14 +180,14 @@ you can call:
 
     SvOK(SV*)
 
-The scalar C<undef> value is stored in an SV instance called C<sv_undef>.  Its
+The scalar C<undef> value is stored in an SV instance called C<PL_sv_undef>.  Its
 address can be used whenever an C<SV*> is needed.
 
-There are also the two values C<sv_yes> and C<sv_no>, which contain Boolean
-TRUE and FALSE values, respectively.  Like C<sv_undef>, their addresses can
+There are also the two values C<PL_sv_yes> and C<PL_sv_no>, which contain Boolean
+TRUE and FALSE values, respectively.  Like C<PL_sv_undef>, their addresses can
 be used whenever an C<SV*> is needed.
 
-Do not be fooled into thinking that C<(SV *) 0> is the same as C<&sv_undef>.
+Do not be fooled into thinking that C<(SV *) 0> is the same as C<&PL_sv_undef>.
 Take this code:
 
     SV* sv = (SV*) 0;
@@ -186,7 +199,7 @@ Take this code:
 This code tries to return a new SV (which contains the value 42) if it should
 return a real value, or undef otherwise.  Instead it has returned a NULL
 pointer which, somewhere down the line, will cause a segmentation violation,
-bus error, or just weird results.  Change the zero to C<&sv_undef> in the first
+bus error, or just weird results.  Change the zero to C<&PL_sv_undef> in the first
 line and all will be well.
 
 To free an SV that you've created, call C<SvREFCNT_dec(SV*)>.  Normally this
@@ -262,9 +275,9 @@ return value.
 The C<av_clear> function deletes all the elements in the AV* array, but
 does not actually delete the array itself.  The C<av_undef> function will
 delete all the elements in the array plus the array itself.  The
-C<av_extend> function extends the array so that it contains C<key>
-elements.  If C<key> is less than the current length of the array, then
-nothing is done.
+C<av_extend> function extends the array so that it contains at least C<key+1>
+elements.  If C<key+1> is less than the currently allocated length of the array,
+then nothing is done.
 
 If you know the name of an array variable, you can get a pointer to its AV
 by using the following:
@@ -284,8 +297,8 @@ To create an HV, you use the following routine:
 
 Once the HV has been created, the following operations are possible on HVs:
 
-    SV**  hv_store(HV*, char* key, U32 klen, SV* val, U32 hash);
-    SV**  hv_fetch(HV*, char* key, U32 klen, I32 lval);
+    SV**  hv_store(HV*, const char* key, U32 klen, SV* val, U32 hash);
+    SV**  hv_fetch(HV*, const char* key, U32 klen, I32 lval);
 
 The C<klen> parameter is the length of the key being passed in (Note that
 you cannot pass 0 in as a value of C<klen> to tell Perl to measure the
@@ -303,8 +316,8 @@ not NULL before dereferencing it.
 
 These two functions check if a hash table entry exists, and deletes it.
 
-    bool  hv_exists(HV*, char* key, U32 klen);
-    SV*   hv_delete(HV*, char* key, U32 klen, I32 flags);
+    bool  hv_exists(HV*, const char* key, U32 klen);
+    SV*   hv_delete(HV*, const char* key, U32 klen, I32 flags);
 
 If C<flags> does not include the C<G_DISCARD> flag then C<hv_delete> will
 create and return a mortal copy of the deleted value.
@@ -350,11 +363,13 @@ This returns NULL if the variable does not exist.
 
 The hash algorithm is defined in the C<PERL_HASH(hash, key, klen)> macro:
 
-    i = klen;
     hash = 0;
-    s = key;
-    while (i--)
-       hash = hash * 33 + *s++;
+    while (klen--)
+       hash = (hash * 33) + *key++;
+    hash = hash + (hash >> 5);                 /* after 5.6 */
+
+The last step was added in version 5.6 to improve distribution of
+lower bits in the resulting hash value.
 
 See L<Understanding the Magic of Tied Hashes and Arrays> for more
 information on how to use the hash access functions on tied hashes.
@@ -472,28 +487,28 @@ Upgrades rv to reference if not already one.  Creates new SV for rv to
 point to.  If C<classname> is non-null, the SV is blessed into the specified
 class.  SV is returned.
 
-       SV* newSVrv(SV* rv, char* classname);
+       SV* newSVrv(SV* rv, const char* classname);
 
 Copies integer or double into an SV whose reference is C<rv>.  SV is blessed
 if C<classname> is non-null.
 
-       SV* sv_setref_iv(SV* rv, char* classname, IV iv);
-       SV* sv_setref_nv(SV* rv, char* classname, NV iv);
+       SV* sv_setref_iv(SV* rv, const char* classname, IV iv);
+       SV* sv_setref_nv(SV* rv, const char* classname, NV iv);
 
 Copies the pointer value (I<the address, not the string!>) into an SV whose
 reference is rv.  SV is blessed if C<classname> is non-null.
 
-       SV* sv_setref_pv(SV* rv, char* classname, PV iv);
+       SV* sv_setref_pv(SV* rv, const char* classname, PV iv);
 
 Copies string into an SV whose reference is C<rv>.  Set length to 0 to let
 Perl calculate the string length.  SV is blessed if C<classname> is non-null.
 
-       SV* sv_setref_pvn(SV* rv, char* classname, PV iv, int length);
+       SV* sv_setref_pvn(SV* rv, const char* classname, PV iv, STRLEN length);
 
 Tests whether the SV is blessed into the specified class.  It does not
 check inheritance relationships.
 
-       int  sv_isa(SV* sv, char* name);
+       int  sv_isa(SV* sv, const char* name);
 
 Tests whether the SV is a reference to a blessed object.
 
@@ -503,7 +518,7 @@ Tests whether the SV is derived from the specified class. SV can be either
 a reference to a blessed object or a string containing a class name. This
 is the function implementing the C<UNIVERSAL::isa> functionality.
 
-       bool sv_derived_from(SV* sv, char* name);
+       bool sv_derived_from(SV* sv, const char* name);
 
 To check if you've got an object derived from a specific class you have 
 to write:
@@ -618,15 +633,15 @@ including (but not limited to) the following:
     Format
     Subroutine
 
-There is a single stash called "defstash" that holds the items that exist
+There is a single stash called "PL_defstash" that holds the items that exist
 in the "main" package.  To get at the items in other packages, append the
 string "::" to the package name.  The items in the "Foo" package are in
-the stash "Foo::" in defstash.  The items in the "Bar::Baz" package are
+the stash "Foo::" in PL_defstash.  The items in the "Bar::Baz" package are
 in the stash "Baz::" in "Bar::"'s stash.
 
 To get the stash pointer for a particular package, use the function:
 
-    HV*  gv_stashpv(char* name, I32 create)
+    HV*  gv_stashpv(const char* name, I32 create)
     HV*  gv_stashsv(SV*, I32 create)
 
 The first function takes a literal string, the second uses the string stored
@@ -724,7 +739,7 @@ Note this is current as of patchlevel 0, and could change at any time.
 
 Perl adds magic to an SV using the sv_magic function:
 
-    void sv_magic(SV* sv, SV* obj, int how, char* name, I32 namlen);
+    void sv_magic(SV* sv, SV* obj, int how, const char* name, I32 namlen);
 
 The C<sv> argument is a pointer to the SV that is to acquire a new magical
 feature.
@@ -861,7 +876,20 @@ C<mg_ptr> field points to a C<ufuncs> structure:
 
 When the SV is read from or written to, the C<uf_val> or C<uf_set>
 function will be called with C<uf_index> as the first arg and a
-pointer to the SV as the second.
+pointer to the SV as the second.  A simple example of how to add 'U'
+magic is shown below.  Note that the ufuncs structure is copied by
+sv_magic, so you can safely allocate it on the stack.
+
+    void
+    Umagic(sv)
+        SV *sv;
+    PREINIT:
+        struct ufuncs uf;
+    CODE:
+        uf.uf_val   = &my_get_fn;
+        uf.uf_set   = &my_set_fn;
+        uf.uf_index = 0;
+        sv_magic(sv, 0, 'U', (char*)&uf, sizeof(uf));
 
 Note that because multiple extensions may be using '~' or 'U' magic,
 it is important for extensions to take extra care to avoid conflict.
@@ -890,7 +918,7 @@ This routine returns a pointer to the C<MAGIC> structure stored in the SV.
 If the SV does not have that magical feature, C<NULL> is returned.  Also,
 if the SV is not of type SVt_PVMG, Perl may core dump.
 
-    int mg_copy(SV* sv, SV* nsv, char* key, STRLEN klen);
+    int mg_copy(SV* sv, SV* nsv, const char* key, STRLEN klen);
 
 This routine checks to see what types of magic C<sv> has.  If the mg_type
 field is an uppercase letter, then the mg_obj is copied to C<nsv>, but
@@ -907,6 +935,33 @@ in later releases, and are bracketed with [MAYCHANGE] below. If
 you find yourself actually applying such information in this section, be
 aware that the behavior may change in the future, umm, without warning.
 
+The perl tie function associates a variable with an object that implements
+the various GET, SET etc methods.  To perform the equivalent of the perl
+tie function from an XSUB, you must mimic this behaviour.  The code below
+carries out the necessary steps - firstly it creates a new hash, and then
+creates a second hash which it blesses into the class which will implement
+the tie methods. Lastly it ties the two hashes together, and returns a
+reference to the new tied hash.  Note that the code below does NOT call the
+TIEHASH method in the MyTie class -
+see L<Calling Perl Routines from within C Programs> for details on how
+to do this.
+
+    SV*
+    mytie()
+    PREINIT:
+        HV *hash;
+        HV *stash;
+        SV *tie;
+    CODE:
+        hash = newHV();
+        tie = newRV_noinc((SV*)newHV());
+        stash = gv_stashpv("MyTie", TRUE);
+        sv_bless(tie, stash);
+        hv_magic(hash, tie, 'P');
+        RETVAL = newRV_noinc(hash);
+    OUTPUT:
+        RETVAL
+
 The C<av_store> function, when given a tied array argument, merely
 copies the magic of the array onto the value to be "stored", using
 C<mg_copy>.  It may also return NULL, indicating that the value did not
@@ -982,13 +1037,13 @@ There is a way to achieve a similar task from C via Perl API: create a
 I<pseudo-block>, and arrange for some changes to be automatically
 undone at the end of it, either explicit, or via a non-local exit (via
 die()). A I<block>-like construct is created by a pair of
-C<ENTER>/C<LEAVE> macros (see L<perlcall/EXAMPLE/"Returning a
-Scalar">).  Such a construct may be created specially for some
-important localized task, or an existing one (like boundaries of
-enclosing Perl subroutine/block, or an existing pair for freeing TMPs)
-may be used. (In the second case the overhead of additional
-localization must be almost negligible.) Note that any XSUB is
-automatically enclosed in an C<ENTER>/C<LEAVE> pair.
+C<ENTER>/C<LEAVE> macros (see L<perlcall/"Returning a Scalar">).
+Such a construct may be created specially for some important localized
+task, or an existing one (like boundaries of enclosing Perl
+subroutine/block, or an existing pair for freeing TMPs) may be
+used. (In the second case the overhead of additional localization must
+be almost negligible.) Note that any XSUB is automatically enclosed in
+an C<ENTER>/C<LEAVE> pair.
 
 Inside such a I<pseudo-block> the following service is available:
 
@@ -1041,7 +1096,7 @@ string pointed to by C<key> is Safefree()ed.  If one has a I<key> in
 short-lived storage, the corresponding string may be reallocated like
 this:
 
-  SAVEDELETE(defstash, savepv(tmpbuf), strlen(tmpbuf));
+  SAVEDELETE(PL_defstash, savepv(tmpbuf), strlen(tmpbuf));
 
 =item C<SAVEDESTRUCTOR(f,p)>
 
@@ -1158,9 +1213,9 @@ There are four routines that can be used to call a Perl subroutine from
 within a C program.  These four are:
 
     I32  perl_call_sv(SV*, I32);
-    I32  perl_call_pv(char*, I32);
-    I32  perl_call_method(char*, I32);
-    I32  perl_call_argv(char*, I32, register char**);
+    I32  perl_call_pv(const char*, I32);
+    I32  perl_call_method(const char*, I32);
+    I32  perl_call_argv(const char*, I32, register char**);
 
 The routine most often used is C<perl_call_sv>.  The C<SV*> argument
 contains either the name of the Perl subroutine to be called, or a
@@ -1193,7 +1248,12 @@ consult L<perlcall>.
 
 =head2 Memory Allocation
 
-It is suggested that you use the version of malloc that is distributed
+All memory meant to be used with the Perl API functions should be manipulated
+using the macros described in this section.  The macros provide the necessary
+transparency between differences in the actual malloc implementation that is
+used within perl.
+
+It is suggested that you enable the version of malloc that is distributed
 with Perl.  It keeps pools of various sizes of unallocated memory in
 order to satisfy allocation requests more quickly.  However, on some
 platforms, it may cause spurious malloc or free errors.
@@ -1446,13 +1506,274 @@ 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.
 
+=head1 The Perl Internal API
+
+WARNING: This information is subject to radical changes prior to
+the Perl 5.6 release.  Use with caution.
+
+=head2 Background and PERL_IMPLICIT_CONTEXT
+
+The Perl interpreter can be regarded as a closed box: it has an API
+for feeding it code or otherwise making it do things, but it also has
+functions for its own use.  This smells a lot like an object, and
+there are ways for you to build Perl so that you can have multiple
+interpreters, with one interpreter represented either as a C++ object,
+a C structure, or inside a thread.  The thread, the C structure, or
+the C++ object will contain all the context, the state of that
+interpreter.
+
+Three macros control the major Perl build flavors: MULTIPLICITY,
+USE_THREADS and PERL_OBJECT.  The MULTIPLICITY build has a C structure
+that packages all the interpreter state, there is a similar thread-specific
+data structure under USE_THREADS, and the PERL_OBJECT build has a C++
+class to maintain interpreter state.  In all three cases,
+PERL_IMPLICIT_CONTEXT is also normally defined, and enables the
+support for passing in a "hidden" first argument that represents all three
+data structures.
+
+All this obviously requires a way for the Perl internal functions to be
+C++ methods, subroutines taking some kind of structure as the first
+argument, or subroutines taking nothing as the first argument.  To
+enable these three very different ways of building the interpreter,
+the Perl source (as it does in so many other situations) makes heavy
+use of macros and subroutine naming conventions.
+
+First problem: deciding which functions will be public API functions and
+which will be private.  Those functions whose names begin C<Perl_> are
+public, and those whose names begin C<S_> are private (think "S" for
+"secret" or "static").
+
+Some functions have no prefix (e.g., restore_rsfp in toke.c).  These
+are not parts of the object or pseudo-structure because you need to
+pass pointers to them to other subroutines.
+
+Second problem: there must be a syntax so that the same subroutine
+declarations and calls can pass a structure as their first argument,
+or pass nothing.  To solve this, the subroutines are named and
+declared in a particular way.  Here's a typical start of a static
+function used within the Perl guts:
+
+  STATIC void
+  S_incline(pTHX_ char *s)
+
+STATIC becomes "static" in C, and is #define'd to nothing in C++.
+
+A public function (i.e. part of the internal API, but not necessarily
+sanctioned for use in extensions) begins like this:
+
+  void
+  Perl_sv_setsv(pTHX_ SV* dsv, SV* ssv)
+
+C<pTHX_> is one of a number of macros (in perl.h) that hide the
+details of the interpreter's context.  THX stands for "thread", "this",
+or "thingy", as the case may be.  (And no, George Lucas is not involved. :-)
+The first character could be 'p' for a B<p>rototype, 'a' for B<a>rgument,
+or 'd' for B<d>eclaration.
+
+When Perl is built without PERL_IMPLICIT_CONTEXT, there is no first
+argument containing the interpreter's context.  The trailing underscore
+in the pTHX_ macro indicates that the macro expansion needs a comma
+after the context argument because other arguments follow it.  If
+PERL_IMPLICIT_CONTEXT is not defined, pTHX_ will be ignored, and the
+subroutine is not prototyped to take the extra argument.  The form of the
+macro without the trailing underscore is used when there are no additional
+explicit arguments.
+
+When a core function calls another, it must pass the context.  This
+is normally hidden via macros.  Consider C<sv_setsv>.  It expands
+something like this:
+
+    ifdef PERL_IMPLICIT_CONTEXT
+      define sv_setsv(a,b)     Perl_sv_setsv(aTHX_ a, b)
+      /* can't do this for vararg functions, see below */
+    else
+      define sv_setsv          Perl_sv_setsv
+    endif
+
+This works well, and means that XS authors can gleefully write:
+
+    sv_setsv(foo, bar);
+
+and still have it work under all the modes Perl could have been
+compiled with.
+
+Under PERL_OBJECT in the core, that will translate to either:
+
+    CPerlObj::Perl_sv_setsv(foo,bar);  # in CPerlObj functions,
+                                       # C++ takes care of 'this'
+  or
+
+    pPerl->Perl_sv_setsv(foo,bar);     # in truly static functions,
+                                       # see objXSUB.h
+
+Under PERL_OBJECT in extensions (aka PERL_CAPI), or under
+MULTIPLICITY/USE_THREADS w/ PERL_IMPLICIT_CONTEXT in both core
+and extensions, it will be:
+
+    Perl_sv_setsv(aTHX_ foo, bar);     # the canonical Perl "API"
+                                       # for all build flavors
+
+This doesn't work so cleanly for varargs functions, though, as macros
+imply that the number of arguments is known in advance.  Instead we
+either need to spell them out fully, passing C<aTHX_> as the first
+argument (the Perl core tends to do this with functions like
+Perl_warner), or use a context-free version.
+
+The context-free version of Perl_warner is called
+Perl_warner_nocontext, and does not take the extra argument.  Instead
+it does dTHX; to get the context from thread-local storage.  We
+C<#define warner Perl_warner_nocontext> so that extensions get source
+compatibility at the expense of performance.  (Passing an arg is
+cheaper than grabbing it from thread-local storage.)
+
+You can ignore [pad]THX[xo] when browsing the Perl headers/sources.
+Those are strictly for use within the core.  Extensions and embedders
+need only be aware of [pad]THX.
+
+=head2 How do I use all this in extensions?
+
+When Perl is built with PERL_IMPLICIT_CONTEXT, extensions that call
+any functions in the Perl API will need to pass the initial context
+argument somehow.  The kicker is that you will need to write it in
+such a way that the extension still compiles when Perl hasn't been
+built with PERL_IMPLICIT_CONTEXT enabled.
+
+There are three ways to do this.  First, the easy but inefficient way,
+which is also the default, in order to maintain source compatibility
+with extensions: whenever XSUB.h is #included, it redefines the aTHX
+and aTHX_ macros to call a function that will return the context.
+Thus, something like:
+
+        sv_setsv(asv, bsv);
+
+in your extesion will translate to this when PERL_IMPLICIT_CONTEXT is
+in effect:
+
+        Perl_sv_setsv(GetPerlInterpreter(), asv, bsv);
+
+or to this otherwise:
+
+        Perl_sv_setsv(asv, bsv);
+
+You have to do nothing new in your extension to get this; since
+the Perl library provides GetPerlInterpreter(), it will all just
+work.
+
+The second, more efficient way is to use the following template for
+your Foo.xs:
+
+       #define PERL_NO_GET_CONTEXT     /* we want efficiency */
+       #include "EXTERN.h"
+       #include "perl.h"
+       #include "XSUB.h"
+
+        static my_private_function(int arg1, int arg2);
+
+       static SV *
+       my_private_function(int arg1, int arg2)
+       {
+           dTHX;       /* fetch context */
+           ... call many Perl API functions ...
+       }
+
+        [... etc ...]
+
+       MODULE = Foo            PACKAGE = Foo
+
+       /* typical XSUB */
+
+       void
+       my_xsub(arg)
+               int arg
+           CODE:
+               my_private_function(arg, 10);
+
+Note that the only two changes from the normal way of writing an
+extension is the addition of a C<#define PERL_NO_GET_CONTEXT> before
+including the Perl headers, followed by a C<dTHX;> declaration at
+the start of every function that will call the Perl API.  (You'll
+know which functions need this, because the C compiler will complain
+that there's an undeclared identifier in those functions.)  No changes
+are needed for the XSUBs themselves, because the XS() macro is
+correctly defined to pass in the implicit context if needed.
+
+The third, even more efficient way is to ape how it is done within
+the Perl guts:
+
+
+       #define PERL_NO_GET_CONTEXT     /* we want efficiency */
+       #include "EXTERN.h"
+       #include "perl.h"
+       #include "XSUB.h"
+
+        /* pTHX_ only needed for functions that call Perl API */
+        static my_private_function(pTHX_ int arg1, int arg2);
+
+       static SV *
+       my_private_function(pTHX_ int arg1, int arg2)
+       {
+           /* dTHX; not needed here, because THX is an argument */
+           ... call Perl API functions ...
+       }
+
+        [... etc ...]
+
+       MODULE = Foo            PACKAGE = Foo
+
+       /* typical XSUB */
+
+       void
+       my_xsub(arg)
+               int arg
+           CODE:
+               my_private_function(aTHX_ arg, 10);
+
+This implementation never has to fetch the context using a function
+call, since it is always passed as an extra argument.  Depending on
+your needs for simplicity or efficiency, you may mix the previous
+two approaches freely.
+
+Never add a comma after C<pTHX> yourself--always use the form of the
+macro with the underscore for functions that take explicit arguments,
+or the form without the argument for functions with no explicit arguments.
+
+=head2 Future Plans and PERL_IMPLICIT_SYS
+
+Just as PERL_IMPLICIT_CONTEXT provides a way to bundle up everything
+that the interpreter knows about itself and pass it around, so too are
+there plans to allow the interpreter to bundle up everything it knows
+about the environment it's running on.  This is enabled with the
+PERL_IMPLICIT_SYS macro.  Currently it only works with PERL_OBJECT,
+but is mostly there for MULTIPLICITY and USE_THREADS (see inside
+iperlsys.h).
+
+This allows the ability to provide an extra pointer (called the "host"
+environment) for all the system calls.  This makes it possible for
+all the system stuff to maintain their own state, broken down into
+seven C structures.  These are thin wrappers around the usual system
+calls (see win32/perllib.c) for the default perl executable, but for a
+more ambitious host (like the one that would do fork() emulation) all
+the extra work needed to pretend that different interpreters are
+actually different "processes", would be done here.
+
+The Perl engine/interpreter and the host are orthogonal entities.
+There could be one or more interpreters in a process, and one or
+more "hosts", with free association between them.
+
 =head1 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
+used by extension writers.  The interfaces of any functions that are not
+listed here are subject to change without notice.  For this reason,
+blindly using functions listed in proto.h is to be avoided when writing
 extensions.
+
+Note that all Perl API global variables must be referenced with the C<PL_>
+prefix.  Some macros are provided for compatibility with the older,
+unadorned names, but this support may be disabled in a future release.
+
 The sort order of the listing is case insensitive, with any
-occurrences of '_' ignored for the the purpose of sorting.
+occurrences of '_' ignored for the purpose of sorting.
 
 =over 8
 
@@ -1501,7 +1822,7 @@ will have a reference count of 1.
 
 =item av_pop
 
-Pops an SV off the end of the array.  Returns C<&sv_undef> if the array is
+Pops an SV off the end of the array.  Returns C<&PL_sv_undef> if the array is
 empty.
 
        SV*     av_pop (AV* ar)
@@ -1572,27 +1893,27 @@ Returns the stash of the CV.
 
        HV*     CvSTASH( SV* sv )
 
-=item DBsingle
+=item PL_DBsingle
 
 When Perl is run in debugging mode, with the B<-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 C<DBsub>.
+variable which corresponds to Perl's $DB::single variable.  See C<PL_DBsub>.
 
-=item DBsub
+=item PL_DBsub
 
 When Perl is run in debugging mode, with the B<-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 C<DBsingle>.
+variable which corresponds to Perl's $DB::sub variable.  See C<PL_DBsingle>.
 The sub name can be found by
 
-       SvPV( GvSV( DBsub ), na )
+       SvPV( GvSV( PL_DBsub ), len )
 
-=item DBtrace
+=item PL_DBtrace
 
 Trace variable used when Perl is run in debugging mode, with the B<-d>
 switch.  This is the C variable which corresponds to Perl's $DB::trace
-variable.  See C<DBsingle>.
+variable.  See C<PL_DBsingle>.
 
 =item dMARK
 
@@ -1603,7 +1924,7 @@ C<dORIGMARK>.
 
 Saves the original stack mark for the XSUB.  See C<ORIGMARK>.
 
-=item dowarn
+=item PL_dowarn
 
 The C variable which corresponds to Perl's $^W warning variable.
 
@@ -1716,14 +2037,14 @@ which is not visible to Perl code.  So when calling C<perl_call_sv>,
 you should not use the GV directly; instead, you should use the
 method's CV, which can be obtained from the GV with the C<GvCV> macro.
 
-        GV*     gv_fetchmeth (HV* stash, char* name, STRLEN len, I32 level)
+        GV*     gv_fetchmeth (HV* stash, const char* name, STRLEN len, I32 level)
 
 =item gv_fetchmethod
 
 =item gv_fetchmethod_autoload
 
 Returns the glob which contains the subroutine to call to invoke the
-method on the C<stash>.  In fact in the presense of autoloading this may
+method on the C<stash>.  In fact in the presence of autoloading this may
 be the glob for "AUTOLOAD".  In this case the corresponding variable
 $AUTOLOAD is already setup.
 
@@ -1745,8 +2066,8 @@ C<level==0>.  C<name> should be writable if contains C<':'> or C<'\''>.
 The warning against passing the GV returned by C<gv_fetchmeth> to
 C<perl_call_sv> apply equally to these functions.
 
-        GV*     gv_fetchmethod (HV* stash, char* name)
-        GV*     gv_fetchmethod_autoload (HV* stash, char* name, I32 autoload)
+        GV*     gv_fetchmethod (HV* stash, const char* name)
+        GV*     gv_fetchmethod_autoload (HV* stash, const char* name, I32 autoload)
 
 =item G_VOID
 
@@ -1758,7 +2079,7 @@ Returns a pointer to the stash for a specified package.  If C<create> is set
 then the package will be created if it does not already exist.  If C<create>
 is not set and the package does not exist then NULL is returned.
 
-       HV*     gv_stashpv (char* name, I32 create)
+       HV*     gv_stashpv (const char* name, I32 create)
 
 =item gv_stashsv
 
@@ -1806,7 +2127,8 @@ Returns the key slot of the hash entry as a C<char*> value, doing any
 necessary dereferencing of possibly C<SV*> keys.  The length of
 the string is placed in C<len> (this is a macro, so do I<not> use
 C<&len>).  If you do not care about what the length of the key is,
-you may use the global variable C<na>.  Remember though, that hash
+you may use the global variable C<PL_na>, though this is rather less
+efficient than using a local variable.  Remember though, that hash
 keys in perl are free to contain embedded nulls, so using C<strlen()>
 or similar is not a good way to find the length of hash keys.
 This is very similar to the C<SvPV()> macro described elsewhere in
@@ -1847,15 +2169,6 @@ Clears a hash, making it empty.
 
        void    hv_clear (HV* tb)
 
-=item 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 C<sv_2mortal>.  See C<hv_iternext>
-and C<hv_free_ent>.
-
-       void    hv_delayfree_ent (HV* hv, HE* entry)
-
 =item hv_delete
 
 Deletes a key/value pair in the hash.  The value SV is removed from the hash
@@ -1863,7 +2176,7 @@ and returned to the caller.  The C<klen> is the length of the key.  The
 C<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)
+       SV*     hv_delete (HV* tb, const char* key, U32 klen, I32 flags)
 
 =item hv_delete_ent
 
@@ -1879,7 +2192,7 @@ hash value, or 0 to ask for it to be computed.
 Returns a boolean indicating whether the specified hash key exists.  The
 C<klen> is the length of the key.
 
-       bool    hv_exists (HV* tb, char* key, U32 klen)
+       bool    hv_exists (HV* tb, const char* key, U32 klen)
 
 =item hv_exists_ent
 
@@ -1898,7 +2211,7 @@ dereferencing it to a C<SV*>.
 See L<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)
+       SV**    hv_fetch (HV* tb, const char* key, U32 klen, I32 lval)
 
 =item hv_fetch_ent
 
@@ -1915,13 +2228,6 @@ information on how to use this function on tied hashes.
 
        HE*     hv_fetch_ent  (HV* tb, SV* key, I32 lval, U32 hash)
 
-=item hv_free_ent
-
-Releases a hash entry, such as while iterating though the hash.  See
-C<hv_iternext> and C<hv_delayfree_ent>.
-
-       void    hv_free_ent (HV* hv, HE* entry)
-
 =item hv_iterinit
 
 Prepares a starting point to traverse a hash table.
@@ -1997,7 +2303,7 @@ before the call, and decrementing it if the function returned NULL.
 See L<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)
+       SV**    hv_store (HV* tb, const char* key, U32 klen, SV* val, U32 hash)
 
 =item hv_store_ent
 
@@ -2097,7 +2403,7 @@ Clear something magical that the SV represents.  See C<sv_magic>.
 
 Copies the magic from one SV to another.  See C<sv_magic>.
 
-       int     mg_copy (SV *, SV *, char *, STRLEN)
+       int     mg_copy (SV *, SV *, const char *, STRLEN)
 
 =item mg_find
 
@@ -2135,6 +2441,14 @@ Do magic after a value is assigned to the SV.  See C<sv_magic>.
 
        int     mg_set (SV* sv)
 
+=item modglobal
+
+C<modglobal> is a general purpose, interpreter global HV for use by
+extensions that need to keep information on a per-interpreter basis.
+In a pinch, it can also be used as a symbol table for extensions
+to share data among each other.  It is a good idea to use keys
+prefixed by the package name of the extension that owns the data.
+
 =item Move
 
 The XSUB-writer's interface to the C C<memmove> function.  The C<s> is the
@@ -2143,10 +2457,12 @@ the type.  Can do overlapping moves.  See also C<Copy>.
 
        void    Move( s, d, n, t )
 
-=item na
+=item PL_na
 
-A variable which may be used with C<SvPV> to tell Perl to calculate the
-string length.
+A convenience variable which is typically used with C<SvPV> when one doesn't
+care about the length of the string.  It is usually more efficient to
+either declare a local variable and use that instead or to use the C<SvPV_nolen>
+macro.
 
 =item New
 
@@ -2223,24 +2539,26 @@ SV is set to 1.
 =item newSVpv
 
 Creates a new SV and copies a string into it.  The reference count for the
-SV is set to 1.  If C<len> is zero then Perl will compute the length.
+SV is set to 1.  If C<len> is zero, Perl will compute the length using
+strlen().  For efficiency, consider using C<newSVpvn> instead.
 
-       SV*     newSVpv (char* s, STRLEN len)
+       SV*     newSVpv (const char* s, STRLEN len)
 
 =item newSVpvf
 
 Creates a new SV an initialize it with the string formatted like
 C<sprintf>.
 
-       SV*     newSVpvf(const char* pat, ...);
+       SV*     newSVpvf(const char* pat, ...)
 
 =item newSVpvn
 
 Creates a new SV and copies a string into it.  The reference count for the
-SV is set to 1.  If C<len> is zero then Perl will create a zero length 
-string.
+SV is set to 1.  Note that if C<len> is zero, Perl will create a zero length 
+string.  You are responsible for ensuring that the source string is at least
+C<len> bytes long.
 
-       SV*     newSVpvn (char* s, STRLEN len)
+       SV*     newSVpvn (const char* s, STRLEN len)
 
 =item newSVrv
 
@@ -2249,7 +2567,7 @@ it will be upgraded to one.  If C<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)
+       SV*     newSVrv (SV* rv, const char* classname)
 
 =item newSVsv
 
@@ -2305,20 +2623,20 @@ Allocates a new Perl interpreter.  See L<perlembed>.
 
 Performs a callback to the specified Perl sub.  See L<perlcall>.
 
-       I32     perl_call_argv (char* subname, I32 flags, char** argv)
+       I32     perl_call_argv (const char* subname, I32 flags, char** argv)
 
 =item perl_call_method
 
 Performs a callback to the specified Perl method.  The blessed object must
 be on the stack.  See L<perlcall>.
 
-       I32     perl_call_method (char* methname, I32 flags)
+       I32     perl_call_method (const char* methname, I32 flags)
 
 =item perl_call_pv
 
 Performs a callback to the specified Perl sub.  See L<perlcall>.
 
-       I32     perl_call_pv (char* subname, I32 flags)
+       I32     perl_call_pv (const char* subname, I32 flags)
 
 =item perl_call_sv
 
@@ -2345,7 +2663,7 @@ Tells Perl to C<eval> the string in the SV.
 
 Tells Perl to C<eval> the given string and return an SV* result.
 
-       SV*     perl_eval_pv (char* p, I32 croak_on_error)
+       SV*     perl_eval_pv (const char* p, I32 croak_on_error)
 
 =item perl_free
 
@@ -2357,15 +2675,16 @@ Returns the AV of the specified Perl array.  If C<create> is set and the
 Perl variable does not exist then it will be created.  If C<create> is not
 set and the variable does not exist then NULL is returned.
 
-       AV*     perl_get_av (char* name, I32 create)
+       AV*     perl_get_av (const char* name, I32 create)
 
 =item perl_get_cv
 
-Returns the CV of the specified Perl sub.  If C<create> is set and the Perl
-variable does not exist then it will be created.  If C<create> is not
-set and the variable does not exist then NULL is returned.
+Returns the CV of the specified Perl subroutine.  If C<create> is set and
+the Perl subroutine does not exist then it will be declared (which has
+the same effect as saying C<sub name;>).  If C<create> is not
+set and the subroutine does not exist then NULL is returned.
 
-       CV*     perl_get_cv (char* name, I32 create)
+       CV*     perl_get_cv (const char* name, I32 create)
 
 =item perl_get_hv
 
@@ -2373,7 +2692,7 @@ Returns the HV of the specified Perl hash.  If C<create> is set and the Perl
 variable does not exist then it will be created.  If C<create> is not
 set and the variable does not exist then NULL is returned.
 
-       HV*     perl_get_hv (char* name, I32 create)
+       HV*     perl_get_hv (const char* name, I32 create)
 
 =item perl_get_sv
 
@@ -2381,7 +2700,7 @@ Returns the SV of the specified Perl scalar.  If C<create> is set and the
 Perl variable does not exist then it will be created.  If C<create> is not
 set and the variable does not exist then NULL is returned.
 
-       SV*     perl_get_sv (char* name, I32 create)
+       SV*     perl_get_sv (const char* name, I32 create)
 
 =item perl_parse
 
@@ -2391,7 +2710,7 @@ Tells a Perl interpreter to parse a Perl script.  See L<perlembed>.
 
 Tells Perl to C<require> a module.
 
-       void    perl_require_pv (char* pv)
+       void    perl_require_pv (const char* pv)
 
 =item perl_run
 
@@ -2511,14 +2830,14 @@ The XSUB-writer's interface to the C C<realloc> function.
 
 Copy a string to a safe spot.  This does not use an SV.
 
-       char*   savepv (char* sv)
+       char*   savepv (const char* sv)
 
 =item savepvn
 
 Copy a string to a safe spot.  The C<len> indicates number of bytes to
 copy.  This does not use an SV.
 
-       char*   savepvn (char* sv, I32 len)
+       char*   savepvn (const char* sv, I32 len)
 
 =item SAVETMPS
 
@@ -2618,13 +2937,13 @@ of the SV is unaffected.
 Concatenates the string onto the end of the string which is in the SV.
 Handles 'get' magic, but not 'set' magic.  See C<sv_catpv_mg>.
 
-       void    sv_catpv (SV* sv, char* ptr)
+       void    sv_catpv (SV* sv, const char* ptr)
 
 =item sv_catpv_mg
 
 Like C<sv_catpv>, but also handles 'set' magic.
 
-       void    sv_catpvn (SV* sv, char* ptr)
+       void    sv_catpvn (SV* sv, const char* ptr)
 
 =item sv_catpvn
 
@@ -2632,13 +2951,13 @@ Concatenates the string onto the end of the string which is in the SV.  The
 C<len> indicates number of bytes to copy.  Handles 'get' magic, but not
 'set' magic.  See C<sv_catpvn_mg>.
 
-       void    sv_catpvn (SV* sv, char* ptr, STRLEN len)
+       void    sv_catpvn (SV* sv, const char* ptr, STRLEN len)
 
 =item sv_catpvn_mg
 
 Like C<sv_catpvn>, but also handles 'set' magic.
 
-       void    sv_catpvn_mg (SV* sv, char* ptr, STRLEN len)
+       void    sv_catpvn_mg (SV* sv, const char* ptr, STRLEN len)
 
 =item sv_catpvf
 
@@ -2674,7 +2993,7 @@ buffer.  SvPOK(sv) must be true and the C<ptr> must be a pointer to
 somewhere inside the string buffer.  The C<ptr> becomes the first
 character of the adjusted string.
 
-       void    sv_chop(SV* sv, char *ptr)
+       void    sv_chop(SV* sv, const char *ptr)
 
 
 =item sv_cmp
@@ -2695,7 +3014,7 @@ Returns the length of the string which is in the SV.  See C<SvLEN>.
 
 Set the length of the string which is in the SV.  See C<SvCUR>.
 
-       void    SvCUR_set (SV* sv, int val )
+       void    SvCUR_set (SV* sv, int val)
 
 =item sv_dec
 
@@ -2705,18 +3024,11 @@ Auto-decrement of the value in the SV.
 
 =item sv_derived_from
 
-Returns a boolean indicating whether the SV is a subclass of the
-specified class.
-
-       int     sv_derived_from(SV* sv, char* class)
-
-=item sv_derived_from
-
 Returns a boolean indicating whether the SV is derived from the specified
 class.  This is the function that implements C<UNIVERSAL::isa>.  It works
 for class names as well as for objects.
 
-       bool    sv_derived_from _((SV* sv, char* name));
+       bool    sv_derived_from (SV* sv, const char* name);
 
 =item SvEND
 
@@ -2737,7 +3049,7 @@ identical.
 Invokes C<mg_get> on an SV if it has 'get' magic.  This macro evaluates
 its argument more than once.
 
-       void    SvGETMAGIC( SV *sv )
+       void    SvGETMAGIC(SV *sv)
 
 =item SvGROW
 
@@ -2746,7 +3058,7 @@ indicated number of bytes (remember to reserve space for an extra
 trailing NUL character).  Calls C<sv_grow> to perform the expansion if
 necessary.  Returns a pointer to the character buffer.
 
-       char*   SvGROW( SV* sv, int len )
+       char*   SvGROW(SV* sv, STRLEN len)
 
 =item sv_grow
 
@@ -2817,13 +3129,13 @@ will return false.
 
 =item SvIV
 
-Returns the integer which is in the SV.
+Coerces the given SV to an integer and returns it.
 
        int SvIV (SV* sv)
 
 =item SvIVX
 
-Returns the integer which is stored in the SV.
+Returns the integer which is stored in the SV, assuming SvIOK is true.
 
        int     SvIVX (SV* sv)
 
@@ -2843,7 +3155,7 @@ Returns the length of the string in the SV.  Use C<SvCUR>.
 
 Adds magic to an SV.
 
-       void    sv_magic (SV* sv, SV* obj, int how, char* name, I32 namlen)
+       void    sv_magic (SV* sv, SV* obj, int how, const char* name, I32 namlen)
 
 =item sv_mortalcopy
 
@@ -2878,9 +3190,9 @@ double.  Checks the B<private> setting.  Use C<SvNIOK>.
 
        int     SvNIOKp (SV* SV)
 
-=item sv_no
+=item PL_sv_no
 
-This is the C<false> SV.  See C<sv_yes>.  Always refer to this as C<&sv_no>.
+This is the C<false> SV.  See C<PL_sv_yes>.  Always refer to this as C<&PL_sv_no>.
 
 =item SvNOK
 
@@ -2915,13 +3227,13 @@ B<private> setting.  Use C<SvNOK>.
 
 =item SvNV
 
-Returns the double which is stored in the SV.
+Coerce the given SV to a double and return it.
 
        double  SvNV (SV* sv)
 
 =item SvNVX
 
-Returns the double which is stored in the SV.
+Returns the double which is stored in the SV, assuming SvNOK is true.
 
        double  SvNVX (SV* sv)
 
@@ -2938,7 +3250,7 @@ for the SvPVX.  This hack is used internally to speed up removal of
 characters from the beginning of a SvPV.  When SvOOK is true, then the
 start of the allocated string buffer is really (SvPVX - SvIVX).
 
-       int     SvOOK(Sv* sv)
+       int     SvOOK(SV* sv)
 
 =item SvPOK
 
@@ -2974,18 +3286,23 @@ Checks the B<private> setting.  Use C<SvPOK>.
 =item SvPV
 
 Returns a pointer to the string in the SV, or a stringified form of the SV
-if the SV does not contain a string.  If C<len> is C<na> then Perl will
-handle the length on its own.  Handles 'get' magic.
+if the SV does not contain a string.  Handles 'get' magic.
 
-       char*   SvPV (SV* sv, int len )
+       char*   SvPV (SV* sv, STRLEN len)
 
 =item SvPV_force
 
 Like <SvPV> but will force the SV into becoming a string (SvPOK).  You
 want force if you are going to update the SvPVX directly.
 
-       char*   SvPV_force(SV* sv, int len)
+       char*   SvPV_force(SV* sv, STRLEN len)
+
+=item SvPV_nolen
+
+Returns a pointer to the string in the SV, or a stringified form of the SV
+if the SV does not contain a string.  Handles 'get' magic.
 
+       char*   SvPV_nolen (SV* sv)
 
 =item SvPVX
 
@@ -3073,13 +3390,13 @@ Like C<sv_setnv>, but also handles 'set' magic.
 Copies a string into an SV.  The string must be null-terminated.
 Does not handle 'set' magic.  See C<sv_setpv_mg>.
 
-       void    sv_setpv (SV* sv, char* ptr)
+       void    sv_setpv (SV* sv, const char* ptr)
 
 =item sv_setpv_mg
 
 Like C<sv_setpv>, but also handles 'set' magic.
 
-       void    sv_setpv_mg (SV* sv, char* ptr)
+       void    sv_setpv_mg (SV* sv, const char* ptr)
 
 =item sv_setpviv
 
@@ -3099,13 +3416,13 @@ Like C<sv_setpviv>, but also handles 'set' magic.
 Copies a string into an SV.  The C<len> parameter indicates the number of
 bytes to be copied.  Does not handle 'set' magic.  See C<sv_setpvn_mg>.
 
-       void    sv_setpvn (SV* sv, char* ptr, STRLEN len)
+       void    sv_setpvn (SV* sv, const char* ptr, STRLEN len)
 
 =item sv_setpvn_mg
 
 Like C<sv_setpvn>, but also handles 'set' magic.
 
-       void    sv_setpvn_mg (SV* sv, char* ptr, STRLEN len)
+       void    sv_setpvn_mg (SV* sv, const char* ptr, STRLEN len)
 
 =item sv_setpvf
 
@@ -3144,7 +3461,7 @@ will be returned and will have a reference count of 1.
 
 Copies a pointer into a new SV, optionally blessing the SV.  The C<rv>
 argument will be upgraded to an RV.  That RV will be modified to point to
-the new SV.  If the C<pv> argument is NULL then C<sv_undef> will be placed
+the new SV.  If the C<pv> argument is NULL then C<PL_sv_undef> will be placed
 into the SV.  The C<classname> argument indicates the package for the
 blessing.  Set C<classname> to C<Nullch> to avoid the blessing.  The new SV
 will be returned and will have a reference count of 1.
@@ -3291,9 +3608,9 @@ Returns the type of the SV.  See C<svtype>.
 An enum of flags for Perl types.  These are found in the file B<sv.h> in the
 C<svtype> enum.  Test these flags with the C<SvTYPE> macro.
 
-=item sv_undef
+=item PL_sv_undef
 
-This is the C<undef> SV.  Always refer to this as C<&sv_undef>.
+This is the C<undef> SV.  Always refer to this as C<&PL_sv_undef>.
 
 =item sv_unref
 
@@ -3332,40 +3649,42 @@ Like C<sv_usepvn>, but also handles 'set' magic.
 
        void    sv_usepvn_mg (SV* sv, char* ptr, STRLEN len)
 
-=item sv_vcatpvfn(sv, pat, patlen, args, svargs, svmax, used_locale)
+=item sv_vcatpvfn
 
 Processes its arguments like C<vsprintf> and appends the formatted output
 to an SV.  Uses an array of SVs if the C style variable argument list is
-missing (NULL).  Indicates if locale information has been used for formatting.
+missing (NULL).  When running with taint checks enabled, indicates via
+C<maybe_tainted> if results are untrustworthy (often due to the use of
+locales).
 
-       void    sv_catpvfn _((SV* sv, const char* pat, STRLEN patlen,
-                             va_list *args, SV **svargs, I32 svmax,
-                             bool *used_locale));
+       void    sv_catpvfn (SV* sv, const char* pat, STRLEN patlen,
+                           va_list *args, SV **svargs, I32 svmax,
+                           bool *maybe_tainted);
 
-=item sv_vsetpvfn(sv, pat, patlen, args, svargs, svmax, used_locale)
+=item sv_vsetpvfn
 
 Works like C<vcatpvfn> but copies the text into the SV instead of
 appending it.
 
-       void    sv_setpvfn _((SV* sv, const char* pat, STRLEN patlen,
-                             va_list *args, SV **svargs, I32 svmax,
-                             bool *used_locale));
+       void    sv_setpvfn (SV* sv, const char* pat, STRLEN patlen,
+                           va_list *args, SV **svargs, I32 svmax,
+                           bool *maybe_tainted);
 
 =item SvUV
 
-Returns the unsigned integer which is in the SV.
+Coerces the given SV to an unsigned integer and returns it.
 
        UV      SvUV(SV* sv)
 
 =item SvUVX
 
-Returns the unsigned integer which is stored in the SV.
+Returns the unsigned integer which is stored in the SV, assuming SvIOK is true.
 
        UV      SvUVX(SV* sv)
 
-=item sv_yes
+=item PL_sv_yes
 
-This is the C<true> SV.  See C<sv_no>.  Always refer to this as C<&sv_yes>.
+This is the C<true> SV.  See C<PL_sv_no>.  Always refer to this as C<&PL_sv_yes>.
 
 =item THIS
 
@@ -3449,7 +3768,7 @@ Return an integer from an XSUB immediately.  Uses C<XST_mIV>.
 
 =item XSRETURN_NO
 
-Return C<&sv_no> from an XSUB immediately.  Uses C<XST_mNO>.
+Return C<&PL_sv_no> from an XSUB immediately.  Uses C<XST_mNO>.
 
        XSRETURN_NO;
 
@@ -3467,13 +3786,13 @@ Return a copy of a string from an XSUB immediately.  Uses C<XST_mPV>.
 
 =item XSRETURN_UNDEF
 
-Return C<&sv_undef> from an XSUB immediately.  Uses C<XST_mUNDEF>.
+Return C<&PL_sv_undef> from an XSUB immediately.  Uses C<XST_mUNDEF>.
 
        XSRETURN_UNDEF;
 
 =item XSRETURN_YES
 
-Return C<&sv_yes> from an XSUB immediately.  Uses C<XST_mYES>.
+Return C<&PL_sv_yes> from an XSUB immediately.  Uses C<XST_mYES>.
 
        XSRETURN_YES;
 
@@ -3493,7 +3812,7 @@ stored in a new mortal SV.
 
 =item XST_mNO
 
-Place C<&sv_no> into the specified position C<i> on the stack.
+Place C<&PL_sv_no> into the specified position C<i> on the stack.
 
        XST_mNO( int i )
 
@@ -3506,13 +3825,13 @@ value is stored in a new mortal SV.
 
 =item XST_mUNDEF
 
-Place C<&sv_undef> into the specified position C<i> on the stack.
+Place C<&PL_sv_undef> into the specified position C<i> on the stack.
 
        XST_mUNDEF( int i )
 
 =item XST_mYES
 
-Place C<&sv_yes> into the specified position C<i> on the stack.
+Place C<&PL_sv_yes> into the specified position C<i> on the stack.
 
        XST_mYES( int i )