Simon,
Here (finally) is that list of SV functions. I ran out of time to
trawl through the pp*.c files, so this is based only on what I found
in sv.c.
Dave M.
This a grouping and summary of the functions in sv.c (ignoring the
strictly local ones). The grouping scheme is probably a bit arbitrary.
(The numbers before the functions are their relative positions in the
file).
----------------------------------------------------------------------
MEMORY ALLOCATION
HEAD
grab a new empty SV head
(macro) new_SV(p)
return empty SV head to free list
1 S_del_sv(pTHX_ SV *p)
add a new arena to SV free list
2 Perl_sv_add_arena(pTHX_ char *ptr, U32 size, U32 flags)
3 S_more_sv(pTHX)
BODY
grab an empty foo body from the relevant free list;
return an empty foo to the relevant free list;
add a new arena to the foo free list
10 S_new_xiv(pTHX)
11 S_del_xiv(pTHX_ XPVIV *p)
12 S_more_xiv(pTHX)
13 S_new_xnv(pTHX)
14 S_del_xnv(pTHX_ XPVNV *p)
15 S_more_xnv(pTHX)
16 S_new_xrv(pTHX)
17 S_del_xrv(pTHX_ XRV *p)
18 S_more_xrv(pTHX)
19 S_new_xpv(pTHX)
20 S_del_xpv(pTHX_ XPV *p)
21 S_more_xpv(pTHX)
22 S_new_xpviv(pTHX)
23 S_del_xpviv(pTHX_ XPVIV *p)
24 S_more_xpviv(pTHX)
25 S_new_xpvnv(pTHX)
26 S_del_xpvnv(pTHX_ XPVNV *p)
27 S_more_xpvnv(pTHX)
28 S_new_xpvcv(pTHX)
29 S_del_xpvcv(pTHX_ XPVCV *p)
30 S_more_xpvcv(pTHX)
31 S_new_xpvav(pTHX)
32 S_del_xpvav(pTHX_ XPVAV *p)
33 S_more_xpvav(pTHX)
34 S_new_xpvhv(pTHX)
35 S_del_xpvhv(pTHX_ XPVHV *p)
36 S_more_xpvhv(pTHX)
37 S_new_xpvmg(pTHX)
38 S_del_xpvmg(pTHX_ XPVMG *p)
39 S_more_xpvmg(pTHX)
40 S_new_xpvlv(pTHX)
41 S_del_xpvlv(pTHX_ XPVLV *p)
42 S_more_xpvlv(pTHX)
43 S_new_xpvbm(pTHX)
44 S_del_xpvbm(pTHX_ XPVBM *p)
45 S_more_xpvbm(pTHX)
STRING
allocate or reallocate string space
48 Perl_sv_grow(pTHX_ register SV *sv, register STRLEN newlen)
MISC
deallocate all arenas:
8 Perl_sv_free_arenas(pTHX)
----------------------------------------------------------------------
CREATE
Create a null SV, or if len > 0, an SVt_PV SV with an initial string
allocation.
98 Perl_newSV(pTHX_ STRLEN len)
Create a null SV, add it to the tmps stack, and mark as mortal.
121 Perl_sv_newmortal(pTHX)
Change the physical type of an SV - deallocate the old body, allocate
a new body, and copy across as much of the value(s) as possible.
46 Perl_sv_upgrade(pTHX_ register SV *sv, U32 mt)
Create new SVs of a suitable type with initialised values.
123 Perl_newSVpv(pTHX_ const char *s, STRLEN len)
124 Perl_newSVpvn(pTHX_ const char *s, STRLEN len)
(uses shared string pool:)
125 Perl_newSVpvn_share(pTHX_ const char *src, I32 len, U32 hash)
127 Perl_newSVpvf(pTHX_ const char* pat, ...)
129 Perl_newSVnv(pTHX_ NV n)
130 Perl_newSViv(pTHX_ IV i)
131 Perl_newSVuv(pTHX_ UV u)
Create a new SV then copy an existing SV to it; in the second case,
add it to the tmps stack too. (Uses sv_setsv.)
134 Perl_newSVsv(pTHX_ register SV *old)
120 Perl_sv_mortalcopy(pTHX_ SV *oldstr)
Create a new RV and point it at an existing SV
132 Perl_newRV_noinc(pTHX_ SV *tmpRef)
133 Perl_newRVinc(pTHX_ SV *tmpRef)
Create a new null SV (optionally blessing it), and make an existing RV
point to it. Then (apart from newSVrv), set an initial value for the SV.
155 Perl_newSVrv(pTHX_ SV *rv, const char *classname)
156 Perl_sv_setref_pv(pTHX_ SV *rv, const char *classname, void *pv)
157 Perl_sv_setref_iv(pTHX_ SV *rv, const char *classname, IV iv)
158 Perl_sv_setref_uv(pTHX_ SV *rv, const char *classname, UV uv)
159 Perl_sv_setref_nv(pTHX_ SV *rv, const char *classname, NV nv)
160 Perl_sv_setref_pvn(pTHX_ SV *rv, const char *classname, char *pv, STRLEN n)
Clone a new interpreter. The important thing about this is that
it calls lots of private functions in sv.c like sv_dup() that exactly
duplicate existing SVs etc, adjusting pointers and everything using
mapping tables. Any PMC implementaion will need to be able to do
something similar.
202 perl_clone(PerlInterpreter *proto_perl, UV flags)
----------------------------------------------------------------------
DESTROY
for an SV whose refnt has reached zero, call any destuctors, free
up any resources used by the body, then deallocate the body. The head
is marked as unused, but is not returned to the free list - thus it is
safe to use with non-arena SVs like PL_sv_yes and the like.
106 Perl_sv_clear(pTHX_ register SV *sv)
Decrement refcnt, and if reaches zero, sv_clear() it, then return head
to freelist. Handles special cases such as refcnt being artifically
low during global destruction.
(usually known by macro alias SvREFCNT_dec)
108 Perl_sv_free(pTHX_ SV *sv)
call function f() for each still-alive SV in the arena
4 S_visit(pTHX_ SVFUNC_t f)
use visit() to, dump contents of remining SVs, call destructors
on any remaining objects, or simply free all remaining SVs.
5 Perl_sv_report_used(pTHX)
6 Perl_sv_clean_objs(pTHX)
7 Perl_sv_clean_all(pTHX)
----------------------------------------------------------------------
COPY
Copy-by-value an SV.
$b = $a essentially does
1 mg_get($a): give $a a chance to magically refresh its value
2 the type of $b is changed to be suitable to hold a value of type $a
3 the value of $a is copied to $b
4 mg_set($b): $b is given a chance to do something with its
new value
setsv() does the initial mg_get(), and skips the final mg_set()
setsv_flags() optionally does the initial mg_get(), and skips the final
mg_set()
setsv_mg() does both get and set
78 Perl_sv_setsv(pTHX_ SV *dstr, register SV *sstr)
79 Perl_sv_setsv_flags(pTHX_ SV *dstr, register SV *sstr, I32 flags)
80 Perl_sv_setsv_mg(pTHX_ SV *dstr, register SV *sstr)
'donate' the body, type and flags of one SV to another SV, then dispose
of the old SV. The new SV keeps its own magic. Only used (AFAIK) in
leave_scope() to restore a SAVEt_ITEM.
105 Perl_sv_replace(pTHX_ register SV *sv, register SV *nsv)
Clone an SV (or AV, HV etc). Only used by perl_clone.
197 Perl_sv_dup(pTHX_ SV *sstr)
----------------------------------------------------------------------
GET
return boolean value of SV
138 Perl_sv_true(pTHX_ register SV *sv)
convert to an IV,UV or NV if necessary, then return the value
59 Perl_sv_2iv(pTHX_ register SV *sv)
60 Perl_sv_2uv(pTHX_ register SV *sv)
61 Perl_sv_2nv(pTHX_ register SV *sv)
get strings, lengths etc, converting to string and byte/uft8 if necessary
64 Perl_sv_2pv_nolen(pTHX_ register SV *sv)
66 Perl_sv_2pv(pTHX_ register SV *sv, STRLEN *lp)
67 Perl_sv_2pv_flags(pTHX_ register SV *sv, STRLEN *lp, I32 flags)
68 Perl_sv_2pvbyte_nolen(pTHX_ register SV *sv)
69 Perl_sv_2pvbyte(pTHX_ register SV *sv, STRLEN *lp)
70 Perl_sv_2pvutf8_nolen(pTHX_ register SV *sv)
71 Perl_sv_2pvutf8(pTHX_ register SV *sv, STRLEN *lp)
109 Perl_sv_len(pTHX_ register SV *sv)
110 Perl_sv_len_utf8(pTHX_ register SV *sv)
----------------------------------------------------------------------
SET
Set an SV to a an IV/UV/NV value and, for the _mg versions, do
mg_set() afterwards.
49 Perl_sv_setiv(pTHX_ register SV *sv, IV i)
50 Perl_sv_setiv_mg(pTHX_ register SV *sv, IV i)
51 Perl_sv_setuv(pTHX_ register SV *sv, UV u)
52 Perl_sv_setuv_mg(pTHX_ register SV *sv, UV u)
53 Perl_sv_setnv(pTHX_ register SV *sv, NV num)
54 Perl_sv_setnv_mg(pTHX_ register SV *sv, NV num)
Set the int, but also convert to a string and set that too.
168 Perl_sv_setpviv(pTHX_ SV *sv, IV iv)
169 Perl_sv_setpviv_mg(pTHX_ SV *sv, IV iv)
Set a string value, possibly specifying the string length explicitly
(setpvn*), possibly calling mg_set() afterwards (*_mg), possibly
copying the string pointer rather than copying the whole string
(*use*), or doing an sprintf (setpvf*).
81 Perl_sv_setpvn(pTHX_ register SV *sv, register const char *ptr, register
STRLEN len)
82 Perl_sv_setpvn_mg(pTHX_ register SV *sv, register const char *ptr,
register STRLEN len)
83 Perl_sv_setpv(pTHX_ register SV *sv, register const char *ptr)
84 Perl_sv_setpv_mg(pTHX_ register SV *sv, register const char *ptr)
85 Perl_sv_usepvn(pTHX_ register SV *sv, register char *ptr, register STRLEN
len)
86 Perl_sv_usepvn_mg(pTHX_ register SV *sv, register char *ptr, register
STRLEN len)
172 Perl_sv_setpvf(pTHX_ SV *sv, const char* pat, ...)
174 Perl_sv_setpvf_mg(pTHX_ SV *sv, const char* pat, ...)
----------------------------------------------------------------------
UPDATE
Do ++$v, --$v
118 Perl_sv_inc(pTHX_ register SV *sv)
119 Perl_sv_dec(pTHX_ register SV *sv)
Remove chars from beginning of string.
89 Perl_sv_chop(pTHX_ register SV *sv, register char *ptr)
Like sv_setpv*, but append rather than set:
90 Perl_sv_catpvn(pTHX_ SV *dsv, const char* sstr, STRLEN slen)
91 Perl_sv_catpvn_flags(pTHX_ register SV *dsv, register const char *sstr,
register STRLEN slen, I32 flags)
92 Perl_sv_catpvn_mg(pTHX_ register SV *sv, register const char *ptr,
register STRLEN len)
93 Perl_sv_catsv(pTHX_ SV *dstr, register SV *sstr)
94 Perl_sv_catsv_flags(pTHX_ SV *dsv, register SV *ssv, I32 flags)
95 Perl_sv_catsv_mg(pTHX_ SV *dsv, register SV *ssv)
96 Perl_sv_catpv(pTHX_ register SV *sv, register const char *ptr)
97 Perl_sv_catpv_mg(pTHX_ register SV *sv, register const char *ptr)
178 Perl_sv_catpvf(pTHX_ SV *sv, const char* pat, ...)
180 Perl_sv_catpvf_mg(pTHX_ SV *sv, const char* pat, ...)
these 2 accept a va_list as a parameter - mainly used as backends for
the catpvf's above and variants thereof
182 Perl_sv_vsetpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list
*args, SV **svargs, I32 svmax, bool *maybe_tainted)
184 Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list
*args, SV **svargs, I32 svmax, bool *maybe_tainted)
Similar to Perl's substr()
104 Perl_sv_insert(pTHX_ SV *bigstr, STRLEN offset, STRLEN len, char *little,
STRLEN littlelen)
----------------------------------------------------------------------
OPS
string compares
113 Perl_sv_eq(pTHX_ register SV *sv1, register SV *sv2)
114 Perl_sv_cmp(pTHX_ register SV *sv1, register SV *sv2)
115 Perl_sv_cmp_locale(pTHX_ register SV *sv1, register SV *sv2)
----------------------------------------------------------------------
CONVERSION
Remove any initial string offset.
47 Perl_sv_backoff(pTHX_ register SV *sv)
Convert from byte to utf8 and vice versa.
73 Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
74 Perl_sv_utf8_upgrade_flags(pTHX_ register SV *sv, I32 flags)
75 Perl_sv_utf8_downgrade(pTHX_ register SV* sv, bool fail_ok)
76 Perl_sv_utf8_encode(pTHX_ register SV *sv)
77 Perl_sv_utf8_decode(pTHX_ register SV *sv)
Convert to string.
145 Perl_sv_pvn_force_flags(pTHX_ SV *sv, STRLEN *lp, I32 flags)
----------------------------------------------------------------------
MISC
See if string looks like a valid number.
57 Perl_looks_like_number(pTHX_ SV *sv)
Remove various types of specialness, such as SvFAKE, shared string,
deref, glob to mg downgrade.
87 Perl_sv_force_normal_flags(pTHX_ register SV *sv, U32 flags)
88 Perl_sv_force_normal(pTHX_ register SV *sv)
Set/unset magic.
99 Perl_sv_magic(pTHX_ register SV *sv, SV *obj, int how, const char *name,
I32 namlen)
100 Perl_sv_unmagic(pTHX_ SV *sv, int type)
Add SV to tmps stack and mark as mortal.
122 Perl_sv_2mortal(pTHX_ register SV *sv)
Implement the Perl-level reset() function. (Deprecated).
135 Perl_sv_reset(pTHX_ register char *s, HV *stash)
Try to extract out an IO from an SV in various ways: mirrors the
Perl-level use of various expression types to represent file handles.
136 Perl_sv_2io(pTHX_ SV *sv)
Try to get a CV from an SV in various ways: mirrors the Perl-level
use of various ways of referring to a function.
137 Perl_sv_2cv(pTHX_ SV *sv, HV **st, GV **gvp, I32 lref)
Convert utf8 to byte offsets in a string and vice-versa.
111 Perl_sv_pos_u2b(pTHX_ register SV *sv, I32* offsetp, I32* lenp)
112 Perl_sv_pos_b2u(pTHX_ register SV *sv, I32* offsetp)
Add Collate Transform magic to a string.
116 Perl_sv_collxfrm(pTHX_ SV *sv, STRLEN *nxp)
Set, unset, or test for taintedness.
165 Perl_sv_taint(pTHX_ SV *sv)
166 Perl_sv_untaint(pTHX_ SV *sv)
167 Perl_sv_tainted(pTHX_ SV *sv)
Read a line from a file.
117 Perl_sv_gets(pTHX_ register SV *sv, register PerlIO *fp, I32 append)
Perl-level ref()
152 Perl_sv_reftype(pTHX_ SV *sv, int ob)
Test for blessedness
153 Perl_sv_isobject(pTHX_ SV *sv)
Is this object direct in this class (doesnt do inheritance)
154 Perl_sv_isa(pTHX_ SV *sv, const char *name)
Perl-level bless()
161 Perl_sv_bless(pTHX_ SV *sv, HV *stash)
Inc refcnt (usuually use SvREFCNT_inc wrapper instead)
107 Perl_sv_newref(pTHX_ SV *sv)
Stop this RV from being an RV, and decrement the refcnt of the thing
being referenced
163 Perl_sv_unref_flags(pTHX_ SV *sv, U32 flags)
164 Perl_sv_unref(pTHX_ SV *sv)
Make this reference as weak and add backref magic to the item being
reffed that points back to us.
101 Perl_sv_rvweaken(pTHX_ SV *sv)