perlintern.html

来自「perl教程」· HTML 代码 · 共 986 行 · 第 1/3 页

HTML
986
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>perlintern - autogenerated documentation of purely B&lt;internal&gt; 		 Perl functions</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>perlintern - autogenerated documentation of purely B&lt;internal&gt; 		 Perl functions</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#cv_reference_counts_and_cvoutside">CV reference counts and CvOUTSIDE</a></li>
	<li><a href="#functions_in_file_pad_h">Functions in file pad.h</a></li>
	<li><a href="#functions_in_file_pp_ctl_c">Functions in file pp_ctl.c</a></li>
	<li><a href="#global_variables">Global Variables</a></li>
	<li><a href="#gv_functions">GV Functions</a></li>
	<li><a href="#io_functions">IO Functions</a></li>
	<li><a href="#pad_data_structures">Pad Data Structures</a></li>
	<li><a href="#stack_manipulation_macros">Stack Manipulation Macros</a></li>
	<li><a href="#sv_manipulation_functions">SV Manipulation Functions</a></li>
	<li><a href="#authors">AUTHORS</a></li>
	<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p><table cellspacing="0" cellpadding="0"><tr><td>perlintern - autogenerated documentation of purely <strong>internal</strong>
<tr><td><td> Perl functions</table></p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This file is the autogenerated documentation of functions in the
Perl interpreter that are documented using Perl's internal documentation
format but are not marked as part of the Perl API. In other words,
<strong>they are not for use in extensions</strong>!</p>
<p>
</p>
<hr />
<h1><a name="cv_reference_counts_and_cvoutside">CV reference counts and CvOUTSIDE</a></h1>
<dl>
<dt><strong><a name="item_cvweakoutside">CvWEAKOUTSIDE</a></strong>

<dd>
<p>Each CV has a pointer, <code>CvOUTSIDE()</code>, to its lexically enclosing
CV (if any). Because pointers to anonymous sub prototypes are
stored in <code>&amp;</code> pad slots, it is a possible to get a circular reference,
with the parent pointing to the child and vice-versa. To avoid the
ensuing memory leak, we do not increment the reference count of the CV
pointed to by <code>CvOUTSIDE</code> in the <em>one specific instance</em> that the parent
has a <code>&amp;</code> pad slot pointing back to us. In this case, we set the
<a href="#item_cvweakoutside"><code>CvWEAKOUTSIDE</code></a> flag in the child. This allows us to determine under what
circumstances we should decrement the refcount of the parent when freeing
the child.</p>
</dd>
<dd>
<p>There is a further complication with non-closure anonymous subs (i.e. those
that do not refer to any lexicals outside that sub). In this case, the
anonymous prototype is shared rather than being cloned. This has the
consequence that the parent may be freed while there are still active
children, eg</p>
</dd>
<dd>
<pre>
    <span class="keyword">BEGIN</span> <span class="operator">{</span> <span class="variable">$a</span> <span class="operator">=</span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span> <span class="keyword">eval</span> <span class="string">'$x'</span> <span class="operator">}</span> <span class="operator">}</span>
</pre>
</dd>
<dd>
<p>In this case, the BEGIN is freed immediately after execution since there
are no active references to it: the anon sub prototype has
<a href="#item_cvweakoutside"><code>CvWEAKOUTSIDE</code></a> set since it's not a closure, and $a points to the same
CV, so it doesn't contribute to BEGIN's refcount either.  When $a is
executed, the <code>eval '$x'</code> causes the chain of <code>CvOUTSIDE</code>s to be followed,
and the freed BEGIN is accessed.</p>
</dd>
<dd>
<p>To avoid this, whenever a CV and its associated pad is freed, any
<code>&amp;</code> entries in the pad are explicitly removed from the pad, and if the
refcount of the pointed-to anon sub is still positive, then that
child's <code>CvOUTSIDE</code> is set to point to its grandparent. This will only
occur in the single specific case of a non-closure anon prototype
having one or more active references (such as <a href="../../lib/Pod/perlvar.html#item__a"><code>$a</code></a> above).</p>
</dd>
<dd>
<p>One other thing to consider is that a CV may be merely undefined
rather than freed, eg <code>undef &amp;foo</code>. In this case, its refcount may
not have reached zero, but we still delete its pad and its <code>CvROOT</code> etc.
Since various children may still have their <code>CvOUTSIDE</code> pointing at this
undefined CV, we keep its own <code>CvOUTSIDE</code> for the time being, so that
the chain of lexical scopes is unbroken. For example, the following
should print 123:</p>
</dd>
<dd>
<pre>
    <span class="keyword">my</span> <span class="variable">$x</span> <span class="operator">=</span> <span class="number">123</span><span class="operator">;</span>
    <span class="keyword">sub</span><span class="variable"> tmp </span><span class="operator">{</span> <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span> <span class="keyword">eval</span> <span class="string">'$x'</span> <span class="operator">}</span> <span class="operator">}</span>
    <span class="keyword">my</span> <span class="variable">$a</span> <span class="operator">=</span> <span class="variable">tmp</span><span class="operator">();</span>
    <span class="keyword">undef</span> <span class="operator">&amp;</span><span class="variable">tmp</span><span class="operator">;</span>
    <span class="keyword">print</span>  <span class="variable">$a</span><span class="operator">-&gt;();</span>
</pre>
</dd>
<dd>
<pre>
        bool    CvWEAKOUTSIDE(CV *cv)</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="functions_in_file_pad_h">Functions in file pad.h</a></h1>
<dl>
<dt><strong><a name="item_cx_curpad_save">CX_CURPAD_SAVE</a></strong>

<dd>
<p>Save the current pad in the given context block structure.</p>
</dd>
<dd>
<pre>
        void    CX_CURPAD_SAVE(struct context)</pre>
</dd>
</li>
<dt><strong><a name="item_cx_curpad_sv">CX_CURPAD_SV</a></strong>

<dd>
<p>Access the SV at offset po in the saved current pad in the given
context block structure (can be used as an lvalue).</p>
</dd>
<dd>
<pre>
        SV *    CX_CURPAD_SV(struct context, PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_base_sv">PAD_BASE_SV</a></strong>

<dd>
<p>Get the value from slot <code>po</code> in the base (DEPTH=1) pad of a padlist</p>
</dd>
<dd>
<pre>
        SV *    PAD_BASE_SV(PADLIST padlist, PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_clone_vars">PAD_CLONE_VARS</a></strong>

<dd>
<p>|CLONE_PARAMS* param
Clone the state variables associated with running and compiling pads.</p>
</dd>
<dd>
<pre>
        void    PAD_CLONE_VARS(PerlInterpreter *proto_perl \)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_compname_flags">PAD_COMPNAME_FLAGS</a></strong>

<dd>
<p>Return the flags for the current compiling pad name
at offset <code>po</code>. Assumes a valid slot entry.</p>
</dd>
<dd>
<pre>
        U32     PAD_COMPNAME_FLAGS(PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_compname_gen">PAD_COMPNAME_GEN</a></strong>

<dd>
<p>The generation number of the name at offset <code>po</code> in the current
compiling pad (lvalue). Note that <code>SvCUR</code> is hijacked for this purpose.</p>
</dd>
<dd>
<pre>
        STRLEN  PAD_COMPNAME_GEN(PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_compname_gen_set">PAD_COMPNAME_GEN_set</a></strong>

<dd>
<p>Sets the generation number of the name at offset <code>po</code> in the current
ling pad (lvalue) to <code>gen</code>.  Note that <code>SvCUR_set</code> is hijacked for this purpose.</p>
</dd>
<dd>
<pre>
        STRLEN  PAD_COMPNAME_GEN_set(PADOFFSET po, int gen)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_compname_ourstash">PAD_COMPNAME_OURSTASH</a></strong>

<dd>
<p>Return the stash associated with an <a href="../../lib/Pod/perlfunc.html#item_our"><code>our</code></a> variable.
Assumes the slot entry is a valid <a href="../../lib/Pod/perlfunc.html#item_our"><code>our</code></a> lexical.</p>
</dd>
<dd>
<pre>
        HV *    PAD_COMPNAME_OURSTASH(PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_compname_pv">PAD_COMPNAME_PV</a></strong>

<dd>
<p>Return the name of the current compiling pad name
at offset <code>po</code>. Assumes a valid slot entry.</p>
</dd>
<dd>
<pre>
        char *  PAD_COMPNAME_PV(PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_compname_type">PAD_COMPNAME_TYPE</a></strong>

<dd>
<p>Return the type (stash) of the current compiling pad name at offset
<code>po</code>. Must be a valid name. Returns null if not typed.</p>
</dd>
<dd>
<pre>
        HV *    PAD_COMPNAME_TYPE(PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_dup">PAD_DUP</a></strong>

<dd>
<p>Clone a padlist.</p>
</dd>
<dd>
<pre>
        void    PAD_DUP(PADLIST dstpad, PADLIST srcpad, CLONE_PARAMS* param)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_restore_local">PAD_RESTORE_LOCAL</a></strong>

<dd>
<p>Restore the old pad saved into the local variable opad by <a href="#item_pad_save_local"><code>PAD_SAVE_LOCAL()</code></a></p>
</dd>
<dd>
<pre>
        void    PAD_RESTORE_LOCAL(PAD *opad)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_save_local">PAD_SAVE_LOCAL</a></strong>

<dd>
<p>Save the current pad to the local variable opad, then make the
current pad equal to npad</p>
</dd>
<dd>
<pre>
        void    PAD_SAVE_LOCAL(PAD *opad, PAD *npad)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_save_setnullpad">PAD_SAVE_SETNULLPAD</a></strong>

<dd>
<p>Save the current pad then set it to null.</p>
</dd>
<dd>
<pre>
        void    PAD_SAVE_SETNULLPAD()</pre>
</dd>
</li>
<dt><strong><a name="item_pad_setsv">PAD_SETSV</a></strong>

<dd>
<p>Set the slot at offset <code>po</code> in the current pad to <code>sv</code></p>
</dd>
<dd>
<pre>
        SV *    PAD_SETSV(PADOFFSET po, SV* sv)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_set_cur">PAD_SET_CUR</a></strong>

<dd>
<p>Set the current pad to be pad <a href="../../lib/Pod/perlguts.html#item_n"><code>n</code></a> in the padlist, saving
the previous current pad. NB currently this macro expands to a string too
long for some compilers, so it's best to replace it with</p>
</dd>
<dd>
<pre>
    <span class="variable">SAVECOMPPAD</span><span class="operator">();</span>
    <span class="variable">PAD_SET_CUR_NOSAVE</span><span class="operator">(</span><span class="variable">padlist</span><span class="operator">,</span><span class="variable">n</span><span class="operator">);</span>
</pre>
</dd>
<dd>
<pre>
        void    PAD_SET_CUR(PADLIST padlist, I32 n)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_set_cur_nosave">PAD_SET_CUR_NOSAVE</a></strong>

<dd>
<p>like PAD_SET_CUR, but without the save</p>
</dd>
<dd>
<pre>
        void    PAD_SET_CUR_NOSAVE(PADLIST padlist, I32 n)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_sv">PAD_SV</a></strong>

<dd>
<p>Get the value at offset <code>po</code> in the current pad</p>
</dd>
<dd>
<pre>
        void    PAD_SV(PADOFFSET po)</pre>
</dd>
</li>
<dt><strong><a name="item_pad_svl">PAD_SVl</a></strong>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?