This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Tiny code cleanup.
[perl5.git] / pod / perlapi.pod
CommitLineData
954c1994
GS
1=head1 NAME
2
3perlapi - autogenerated documentation for the perl public API
4
5=head1 DESCRIPTION
6
1c846c1f
NIS
7This file contains the documentation of the perl public API generated by
8embed.pl, specifically a listing of functions, macros, flags, and variables
9that may be used by extension writers. The interfaces of any functions that
954c1994
GS
10are not listed here are subject to change without notice. For this reason,
11blindly using functions listed in proto.h is to be avoided when writing
12extensions.
13
14Note that all Perl API global variables must be referenced with the C<PL_>
15prefix. Some macros are provided for compatibility with the older,
16unadorned names, but this support may be disabled in a future release.
17
18The listing is alphabetical, case insensitive.
19
94bdecf9
JH
20
21=head1 "Gimme" Values
22
23=over 8
24
25=item GIMME
26
27A backward-compatible version of C<GIMME_V> which can only return
28C<G_SCALAR> or C<G_ARRAY>; in a void context, it returns C<G_SCALAR>.
29Deprecated. Use C<GIMME_V> instead.
30
31 U32 GIMME
32
33=for hackers
34Found in file op.h
35
36=item GIMME_V
37
38The XSUB-writer's equivalent to Perl's C<wantarray>. Returns C<G_VOID>,
39C<G_SCALAR> or C<G_ARRAY> for void, scalar or list context,
40respectively.
41
42 U32 GIMME_V
43
44=for hackers
45Found in file op.h
46
47=item G_ARRAY
48
49Used to indicate list context. See C<GIMME_V>, C<GIMME> and
50L<perlcall>.
51
52=for hackers
53Found in file cop.h
54
55=item G_DISCARD
56
57Indicates that arguments returned from a callback should be discarded. See
58L<perlcall>.
59
60=for hackers
61Found in file cop.h
62
63=item G_EVAL
64
65Used to force a Perl C<eval> wrapper around a callback. See
66L<perlcall>.
67
68=for hackers
69Found in file cop.h
70
71=item G_NOARGS
72
73Indicates that no arguments are being sent to a callback. See
74L<perlcall>.
75
76=for hackers
77Found in file cop.h
78
79=item G_SCALAR
80
81Used to indicate scalar context. See C<GIMME_V>, C<GIMME>, and
82L<perlcall>.
83
84=for hackers
85Found in file cop.h
86
87=item G_VOID
88
89Used to indicate void context. See C<GIMME_V> and L<perlcall>.
90
91=for hackers
92Found in file cop.h
93
94
95=back
96
97=head1 Array Manipulation Functions
98
954c1994
GS
99=over 8
100
101=item AvFILL
102
103Same as C<av_len()>. Deprecated, use C<av_len()> instead.
104
105 int AvFILL(AV* av)
106
497711e7
GS
107=for hackers
108Found in file av.h
109
954c1994
GS
110=item av_clear
111
112Clears an array, making it empty. Does not free the memory used by the
113array itself.
114
115 void av_clear(AV* ar)
116
497711e7
GS
117=for hackers
118Found in file av.c
119
f3b76584
SC
120=item av_delete
121
122Deletes the element indexed by C<key> from the array. Returns the
123deleted element. C<flags> is currently ignored.
124
125 SV* av_delete(AV* ar, I32 key, I32 flags)
126
127=for hackers
128Found in file av.c
129
130=item av_exists
131
132Returns true if the element indexed by C<key> has been initialized.
133
134This relies on the fact that uninitialized array elements are set to
135C<&PL_sv_undef>.
136
137 bool av_exists(AV* ar, I32 key)
138
139=for hackers
140Found in file av.c
141
954c1994
GS
142=item av_extend
143
144Pre-extend an array. The C<key> is the index to which the array should be
145extended.
146
147 void av_extend(AV* ar, I32 key)
148
497711e7
GS
149=for hackers
150Found in file av.c
151
954c1994
GS
152=item av_fetch
153
154Returns the SV at the specified index in the array. The C<key> is the
155index. If C<lval> is set then the fetch will be part of a store. Check
156that the return value is non-null before dereferencing it to a C<SV*>.
157
96f1132b
GS
158See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for
159more information on how to use this function on tied arrays.
954c1994
GS
160
161 SV** av_fetch(AV* ar, I32 key, I32 lval)
162
497711e7
GS
163=for hackers
164Found in file av.c
165
f3b76584
SC
166=item av_fill
167
168Ensure than an array has a given number of elements, equivalent to
169Perl's C<$#array = $fill;>.
170
171 void av_fill(AV* ar, I32 fill)
172
173=for hackers
174Found in file av.c
175
954c1994
GS
176=item av_len
177
178Returns the highest index in the array. Returns -1 if the array is
179empty.
180
181 I32 av_len(AV* ar)
182
497711e7
GS
183=for hackers
184Found in file av.c
185
954c1994
GS
186=item av_make
187
188Creates a new AV and populates it with a list of SVs. The SVs are copied
189into the array, so they may be freed after the call to av_make. The new AV
190will have a reference count of 1.
191
192 AV* av_make(I32 size, SV** svp)
193
497711e7
GS
194=for hackers
195Found in file av.c
196
954c1994
GS
197=item av_pop
198
199Pops an SV off the end of the array. Returns C<&PL_sv_undef> if the array
200is empty.
201
202 SV* av_pop(AV* ar)
203
497711e7
GS
204=for hackers
205Found in file av.c
206
954c1994
GS
207=item av_push
208
209Pushes an SV onto the end of the array. The array will grow automatically
210to accommodate the addition.
211
212 void av_push(AV* ar, SV* val)
213
497711e7
GS
214=for hackers
215Found in file av.c
216
954c1994
GS
217=item av_shift
218
219Shifts an SV off the beginning of the array.
220
221 SV* av_shift(AV* ar)
222
497711e7
GS
223=for hackers
224Found in file av.c
225
954c1994
GS
226=item av_store
227
228Stores an SV in an array. The array index is specified as C<key>. The
229return value will be NULL if the operation failed or if the value did not
230need to be actually stored within the array (as in the case of tied
231arrays). Otherwise it can be dereferenced to get the original C<SV*>. Note
232that the caller is responsible for suitably incrementing the reference
233count of C<val> before the call, and decrementing it if the function
234returned NULL.
235
96f1132b 236See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for
954c1994
GS
237more information on how to use this function on tied arrays.
238
239 SV** av_store(AV* ar, I32 key, SV* val)
240
497711e7
GS
241=for hackers
242Found in file av.c
243
954c1994
GS
244=item av_undef
245
246Undefines the array. Frees the memory used by the array itself.
247
248 void av_undef(AV* ar)
249
497711e7
GS
250=for hackers
251Found in file av.c
252
954c1994
GS
253=item av_unshift
254
255Unshift the given number of C<undef> values onto the beginning of the
256array. The array will grow automatically to accommodate the addition. You
257must then use C<av_store> to assign values to these new elements.
258
259 void av_unshift(AV* ar, I32 num)
260
497711e7
GS
261=for hackers
262Found in file av.c
263
94bdecf9 264=item get_av
9f2ea798 265
94bdecf9
JH
266Returns the AV of the specified Perl array. If C<create> is set and the
267Perl variable does not exist then it will be created. If C<create> is not
268set and the variable does not exist then NULL is returned.
9f2ea798 269
94bdecf9
JH
270NOTE: the perl_ form of this function is deprecated.
271
272 AV* get_av(const char* name, I32 create)
9f2ea798
DM
273
274=for hackers
94bdecf9 275Found in file perl.c
9f2ea798 276
94bdecf9 277=item newAV
f9a63242 278
94bdecf9 279Creates a new AV. The reference count is set to 1.
f9a63242 280
94bdecf9
JH
281 AV* newAV()
282
283=for hackers
284Found in file av.c
285
286=item Nullav
287
288Null AV pointer.
f9a63242 289
f9a63242
JH
290
291=for hackers
94bdecf9 292Found in file av.h
f9a63242 293
94bdecf9 294=item sortsv
497711e7 295
94bdecf9 296Sort an array. Here is an example:
497711e7 297
94bdecf9 298 sortsv(AvARRAY(av), av_len(av)+1, Perl_sv_cmp_locale);
eebe1485 299
94bdecf9 300 void sortsv(SV ** array, size_t num_elts, SVCOMPARE_t cmp)
497711e7
GS
301
302=for hackers
94bdecf9
JH
303Found in file pp_sort.c
304
305
306=back
307
308=head1 Callback Functions
309
310=over 8
497711e7 311
954c1994
GS
312=item call_argv
313
314Performs a callback to the specified Perl sub. See L<perlcall>.
315
316NOTE: the perl_ form of this function is deprecated.
317
318 I32 call_argv(const char* sub_name, I32 flags, char** argv)
319
497711e7
GS
320=for hackers
321Found in file perl.c
322
954c1994
GS
323=item call_method
324
325Performs a callback to the specified Perl method. The blessed object must
326be on the stack. See L<perlcall>.
327
328NOTE: the perl_ form of this function is deprecated.
329
330 I32 call_method(const char* methname, I32 flags)
331
497711e7
GS
332=for hackers
333Found in file perl.c
334
954c1994
GS
335=item call_pv
336
337Performs a callback to the specified Perl sub. See L<perlcall>.
338
339NOTE: the perl_ form of this function is deprecated.
340
341 I32 call_pv(const char* sub_name, I32 flags)
342
497711e7
GS
343=for hackers
344Found in file perl.c
345
954c1994
GS
346=item call_sv
347
348Performs a callback to the Perl sub whose name is in the SV. See
349L<perlcall>.
350
351NOTE: the perl_ form of this function is deprecated.
352
353 I32 call_sv(SV* sv, I32 flags)
354
497711e7
GS
355=for hackers
356Found in file perl.c
357
94bdecf9 358=item ENTER
954c1994 359
94bdecf9 360Opening bracket on a callback. See C<LEAVE> and L<perlcall>.
954c1994 361
94bdecf9 362 ENTER;
954c1994 363
497711e7 364=for hackers
94bdecf9 365Found in file scope.h
497711e7 366
94bdecf9 367=item eval_pv
954c1994 368
94bdecf9 369Tells Perl to C<eval> the given string and return an SV* result.
954c1994 370
94bdecf9 371NOTE: the perl_ form of this function is deprecated.
954c1994 372
94bdecf9 373 SV* eval_pv(const char* p, I32 croak_on_error)
497711e7 374
94bdecf9
JH
375=for hackers
376Found in file perl.c
954c1994 377
94bdecf9 378=item eval_sv
c9d5ac95 379
94bdecf9 380Tells Perl to C<eval> the string in the SV.
c9d5ac95 381
94bdecf9 382NOTE: the perl_ form of this function is deprecated.
954c1994 383
94bdecf9 384 I32 eval_sv(SV* sv, I32 flags)
954c1994 385
497711e7 386=for hackers
94bdecf9 387Found in file perl.c
497711e7 388
94bdecf9 389=item FREETMPS
954c1994 390
94bdecf9
JH
391Closing bracket for temporaries on a callback. See C<SAVETMPS> and
392L<perlcall>.
954c1994 393
94bdecf9 394 FREETMPS;
954c1994 395
497711e7 396=for hackers
94bdecf9 397Found in file scope.h
beab0874 398
94bdecf9 399=item LEAVE
beab0874 400
94bdecf9 401Closing bracket on a callback. See C<ENTER> and L<perlcall>.
beab0874 402
94bdecf9 403 LEAVE;
beab0874
JT
404
405=for hackers
94bdecf9 406Found in file scope.h
beab0874 407
94bdecf9 408=item SAVETMPS
9f2ea798 409
94bdecf9
JH
410Opening bracket for temporaries on a callback. See C<FREETMPS> and
411L<perlcall>.
9f2ea798 412
94bdecf9 413 SAVETMPS;
9f2ea798
DM
414
415=for hackers
94bdecf9 416Found in file scope.h
9f2ea798 417
9f2ea798 418
94bdecf9 419=back
9f2ea798 420
94bdecf9 421=head1 Character classes
9f2ea798 422
94bdecf9 423=over 8
9f2ea798 424
94bdecf9 425=item isALNUM
954c1994 426
94bdecf9
JH
427Returns a boolean indicating whether the C C<char> is an ASCII alphanumeric
428character (including underscore) or digit.
954c1994 429
94bdecf9 430 bool isALNUM(char ch)
954c1994 431
497711e7 432=for hackers
94bdecf9 433Found in file handy.h
497711e7 434
94bdecf9 435=item isALPHA
954c1994 436
94bdecf9
JH
437Returns a boolean indicating whether the C C<char> is an ASCII alphabetic
438character.
954c1994 439
94bdecf9 440 bool isALPHA(char ch)
954c1994 441
497711e7 442=for hackers
94bdecf9 443Found in file handy.h
497711e7 444
94bdecf9 445=item isDIGIT
954c1994 446
94bdecf9
JH
447Returns a boolean indicating whether the C C<char> is an ASCII
448digit.
954c1994 449
94bdecf9 450 bool isDIGIT(char ch)
954c1994 451
497711e7 452=for hackers
94bdecf9 453Found in file handy.h
497711e7 454
94bdecf9 455=item isLOWER
954c1994 456
94bdecf9
JH
457Returns a boolean indicating whether the C C<char> is a lowercase
458character.
954c1994 459
94bdecf9 460 bool isLOWER(char ch)
954c1994 461
497711e7 462=for hackers
94bdecf9 463Found in file handy.h
497711e7 464
94bdecf9 465=item isSPACE
954c1994 466
94bdecf9 467Returns a boolean indicating whether the C C<char> is whitespace.
954c1994 468
94bdecf9 469 bool isSPACE(char ch)
954c1994 470
497711e7 471=for hackers
94bdecf9 472Found in file handy.h
497711e7 473
94bdecf9 474=item isUPPER
954c1994 475
94bdecf9
JH
476Returns a boolean indicating whether the C C<char> is an uppercase
477character.
954c1994 478
94bdecf9 479 bool isUPPER(char ch)
954c1994 480
497711e7 481=for hackers
94bdecf9 482Found in file handy.h
497711e7 483
94bdecf9 484=item toLOWER
954c1994 485
94bdecf9 486Converts the specified character to lowercase.
954c1994 487
94bdecf9 488 char toLOWER(char ch)
954c1994 489
94bdecf9
JH
490=for hackers
491Found in file handy.h
492
493=item toUPPER
494
495Converts the specified character to uppercase.
496
497 char toUPPER(char ch)
954c1994 498
497711e7 499=for hackers
94bdecf9 500Found in file handy.h
497711e7 501
954c1994 502
94bdecf9 503=back
954c1994 504
94bdecf9 505=head1 Cloning an interpreter
954c1994 506
94bdecf9
JH
507=over 8
508
509=item perl_clone
510
511Create and return a new interpreter by cloning the current one.
512
513 PerlInterpreter* perl_clone(PerlInterpreter* interp, UV flags)
954c1994 514
497711e7 515=for hackers
94bdecf9 516Found in file sv.c
497711e7 517
954c1994 518
94bdecf9 519=back
954c1994 520
94bdecf9
JH
521=head1 CV Manipulation Functions
522
523=over 8
524
525=item CvSTASH
526
527Returns the stash of the CV.
528
529 HV* CvSTASH(CV* cv)
954c1994 530
497711e7 531=for hackers
94bdecf9 532Found in file cv.h
497711e7 533
94bdecf9 534=item get_cv
954c1994 535
94bdecf9
JH
536Returns the CV of the specified Perl subroutine. If C<create> is set and
537the Perl subroutine does not exist then it will be declared (which has the
538same effect as saying C<sub name;>). If C<create> is not set and the
539subroutine does not exist then NULL is returned.
954c1994 540
94bdecf9
JH
541NOTE: the perl_ form of this function is deprecated.
542
543 CV* get_cv(const char* name, I32 create)
954c1994 544
497711e7 545=for hackers
94bdecf9 546Found in file perl.c
497711e7 547
94bdecf9 548=item Nullcv
954c1994 549
94bdecf9 550Null CV pointer.
954c1994 551
954c1994 552
497711e7 553=for hackers
94bdecf9 554Found in file cv.h
497711e7 555
7c9e965c 556
94bdecf9 557=back
7c9e965c 558
94bdecf9 559=head1 Embedding Functions
7c9e965c 560
94bdecf9 561=over 8
7c9e965c 562
94bdecf9 563=item load_module
7c9e965c 564
94bdecf9
JH
565Loads the module whose name is pointed to by the string part of name.
566Note that the actual module name, not its filename, should be given.
567Eg, "Foo::Bar" instead of "Foo/Bar.pm". flags can be any of
568PERL_LOADMOD_DENY, PERL_LOADMOD_NOIMPORT, or PERL_LOADMOD_IMPORT_OPS
569(or 0 for no flags). ver, if specified, provides version semantics
570similar to C<use Foo::Bar VERSION>. The optional trailing SV*
571arguments can be used to specify arguments to the module's import()
572method, similar to C<use Foo::Bar VERSION LIST>.
7c9e965c 573
94bdecf9 574 void load_module(U32 flags, SV* name, SV* ver, ...)
7c9e965c
JP
575
576=for hackers
94bdecf9 577Found in file op.c
7c9e965c 578
94bdecf9 579=item perl_alloc
954c1994 580
94bdecf9 581Allocates a new Perl interpreter. See L<perlembed>.
954c1994 582
94bdecf9 583 PerlInterpreter* perl_alloc()
954c1994 584
497711e7 585=for hackers
94bdecf9 586Found in file perl.c
497711e7 587
94bdecf9 588=item perl_construct
89423764 589
94bdecf9 590Initializes a new Perl interpreter. See L<perlembed>.
89423764 591
94bdecf9 592 void perl_construct(PerlInterpreter* interp)
89423764
GS
593
594=for hackers
94bdecf9 595Found in file perl.c
954c1994 596
94bdecf9 597=item perl_destruct
954c1994 598
94bdecf9 599Shuts down a Perl interpreter. See L<perlembed>.
954c1994 600
94bdecf9 601 int perl_destruct(PerlInterpreter* interp)
954c1994 602
497711e7
GS
603=for hackers
604Found in file perl.c
605
94bdecf9 606=item perl_free
954c1994 607
94bdecf9 608Releases a Perl interpreter. See L<perlembed>.
954c1994 609
94bdecf9 610 void perl_free(PerlInterpreter* interp)
954c1994 611
497711e7
GS
612=for hackers
613Found in file perl.c
614
94bdecf9 615=item perl_parse
954c1994 616
94bdecf9 617Tells a Perl interpreter to parse a Perl script. See L<perlembed>.
954c1994 618
94bdecf9 619 int perl_parse(PerlInterpreter* interp, XSINIT_t xsinit, int argc, char** argv, char** env)
954c1994 620
94bdecf9
JH
621=for hackers
622Found in file perl.c
623
624=item perl_run
625
626Tells a Perl interpreter to run. See L<perlembed>.
627
628 int perl_run(PerlInterpreter* interp)
954c1994 629
497711e7
GS
630=for hackers
631Found in file perl.c
632
94bdecf9 633=item require_pv
954c1994 634
94bdecf9
JH
635Tells Perl to C<require> the file named by the string argument. It is
636analogous to the Perl code C<eval "require '$file'">. It's even
637implemented that way; consider using Perl_load_module instead.
954c1994
GS
638
639NOTE: the perl_ form of this function is deprecated.
640
94bdecf9 641 void require_pv(const char* pv)
954c1994 642
497711e7
GS
643=for hackers
644Found in file perl.c
645
954c1994 646
94bdecf9 647=back
954c1994 648
94bdecf9 649=head1 Global Variables
954c1994 650
94bdecf9 651=over 8
497711e7 652
94bdecf9 653=item PL_modglobal
954c1994 654
94bdecf9
JH
655C<PL_modglobal> is a general purpose, interpreter global HV for use by
656extensions that need to keep information on a per-interpreter basis.
657In a pinch, it can also be used as a symbol table for extensions
658to share data among each other. It is a good idea to use keys
659prefixed by the package name of the extension that owns the data.
954c1994 660
94bdecf9 661 HV* PL_modglobal
954c1994 662
497711e7 663=for hackers
94bdecf9 664Found in file intrpvar.h
497711e7 665
94bdecf9 666=item PL_na
6e9d1081 667
94bdecf9
JH
668A convenience variable which is typically used with C<SvPV> when one
669doesn't care about the length of the string. It is usually more efficient
670to either declare a local variable and use that instead or to use the
671C<SvPV_nolen> macro.
6e9d1081 672
94bdecf9 673 STRLEN PL_na
6e9d1081 674
94bdecf9
JH
675=for hackers
676Found in file thrdvar.h
6e9d1081 677
94bdecf9 678=item PL_sv_no
6e9d1081 679
94bdecf9
JH
680This is the C<false> SV. See C<PL_sv_yes>. Always refer to this as
681C<&PL_sv_no>.
682
683 SV PL_sv_no
6e9d1081
NC
684
685=for hackers
94bdecf9 686Found in file intrpvar.h
6e9d1081 687
94bdecf9 688=item PL_sv_undef
6e9d1081 689
94bdecf9 690This is the C<undef> SV. Always refer to this as C<&PL_sv_undef>.
6e9d1081 691
94bdecf9 692 SV PL_sv_undef
6e9d1081 693
94bdecf9
JH
694=for hackers
695Found in file intrpvar.h
6e9d1081 696
94bdecf9 697=item PL_sv_yes
6e9d1081 698
94bdecf9
JH
699This is the C<true> SV. See C<PL_sv_no>. Always refer to this as
700C<&PL_sv_yes>.
701
702 SV PL_sv_yes
6e9d1081
NC
703
704=for hackers
94bdecf9 705Found in file intrpvar.h
6e9d1081 706
6e9d1081 707
94bdecf9 708=back
6e9d1081 709
94bdecf9 710=head1 GV Functions
6e9d1081 711
94bdecf9 712=over 8
6e9d1081 713
954c1994
GS
714=item GvSV
715
716Return the SV from the GV.
717
718 SV* GvSV(GV* gv)
719
497711e7
GS
720=for hackers
721Found in file gv.h
722
954c1994
GS
723=item gv_fetchmeth
724
725Returns the glob with the given C<name> and a defined subroutine or
726C<NULL>. The glob lives in the given C<stash>, or in the stashes
a453c169 727accessible via @ISA and UNIVERSAL::.
954c1994
GS
728
729The argument C<level> should be either 0 or -1. If C<level==0>, as a
730side-effect creates a glob with the given C<name> in the given C<stash>
731which in the case of success contains an alias for the subroutine, and sets
1c846c1f 732up caching info for this glob. Similarly for all the searched stashes.
954c1994
GS
733
734This function grants C<"SUPER"> token as a postfix of the stash name. The
735GV returned from C<gv_fetchmeth> may be a method cache entry, which is not
4929bf7b 736visible to Perl code. So when calling C<call_sv>, you should not use
954c1994 737the GV directly; instead, you should use the method's CV, which can be
1c846c1f 738obtained from the GV with the C<GvCV> macro.
954c1994
GS
739
740 GV* gv_fetchmeth(HV* stash, const char* name, STRLEN len, I32 level)
741
497711e7
GS
742=for hackers
743Found in file gv.c
744
954c1994
GS
745=item gv_fetchmethod
746
6d0f518e 747See L<gv_fetchmethod_autoload>.
954c1994
GS
748
749 GV* gv_fetchmethod(HV* stash, const char* name)
750
497711e7
GS
751=for hackers
752Found in file gv.c
753
954c1994
GS
754=item gv_fetchmethod_autoload
755
756Returns the glob which contains the subroutine to call to invoke the method
757on the C<stash>. In fact in the presence of autoloading this may be the
758glob for "AUTOLOAD". In this case the corresponding variable $AUTOLOAD is
1c846c1f 759already setup.
954c1994
GS
760
761The third parameter of C<gv_fetchmethod_autoload> determines whether
762AUTOLOAD lookup is performed if the given method is not present: non-zero
1c846c1f 763means yes, look for AUTOLOAD; zero means no, don't look for AUTOLOAD.
954c1994 764Calling C<gv_fetchmethod> is equivalent to calling C<gv_fetchmethod_autoload>
1c846c1f 765with a non-zero C<autoload> parameter.
954c1994
GS
766
767These functions grant C<"SUPER"> token as a prefix of the method name. Note
768that if you want to keep the returned glob for a long time, you need to
769check for it being "AUTOLOAD", since at the later time the call may load a
770different subroutine due to $AUTOLOAD changing its value. Use the glob
1c846c1f 771created via a side effect to do this.
954c1994
GS
772
773These functions have the same side-effects and as C<gv_fetchmeth> with
774C<level==0>. C<name> should be writable if contains C<':'> or C<'
775''>. The warning against passing the GV returned by C<gv_fetchmeth> to
1c846c1f 776C<call_sv> apply equally to these functions.
954c1994
GS
777
778 GV* gv_fetchmethod_autoload(HV* stash, const char* name, I32 autoload)
779
497711e7
GS
780=for hackers
781Found in file gv.c
782
954c1994
GS
783=item gv_stashpv
784
386d01d6
GS
785Returns a pointer to the stash for a specified package. C<name> should
786be a valid UTF-8 string. If C<create> is set then the package will be
787created if it does not already exist. If C<create> is not set and the
788package does not exist then NULL is returned.
954c1994
GS
789
790 HV* gv_stashpv(const char* name, I32 create)
791
497711e7
GS
792=for hackers
793Found in file gv.c
794
954c1994
GS
795=item gv_stashsv
796
386d01d6
GS
797Returns a pointer to the stash for a specified package, which must be a
798valid UTF-8 string. See C<gv_stashpv>.
954c1994
GS
799
800 HV* gv_stashsv(SV* sv, I32 create)
801
497711e7
GS
802=for hackers
803Found in file gv.c
804
954c1994 805
94bdecf9 806=back
954c1994 807
94bdecf9 808=head1 Handy Values
497711e7 809
94bdecf9 810=over 8
954c1994 811
94bdecf9 812=item HEf_SVKEY
954c1994 813
94bdecf9
JH
814This flag, used in the length slot of hash entries and magic structures,
815specifies the structure contains an C<SV*> pointer where a C<char*> pointer
816is to be expected. (For information only--not to be used).
497711e7 817
954c1994 818
94bdecf9
JH
819=for hackers
820Found in file hv.h
954c1994 821
94bdecf9
JH
822=item Nullch
823
824Null character pointer.
497711e7 825=for hackers
94bdecf9 826Found in file handy.h
497711e7 827
94bdecf9 828=item Nullsv
954c1994 829
94bdecf9 830Null SV pointer.
954c1994 831
497711e7 832=for hackers
94bdecf9 833Found in file handy.h
497711e7 834
954c1994 835
94bdecf9 836=back
954c1994 837
94bdecf9 838=head1 Hash Manipulation Functions
497711e7 839
94bdecf9 840=over 8
954c1994 841
94bdecf9 842=item get_hv
954c1994 843
94bdecf9
JH
844Returns the HV of the specified Perl hash. If C<create> is set and the
845Perl variable does not exist then it will be created. If C<create> is not
846set and the variable does not exist then NULL is returned.
497711e7 847
94bdecf9 848NOTE: the perl_ form of this function is deprecated.
954c1994 849
94bdecf9 850 HV* get_hv(const char* name, I32 create)
954c1994 851
497711e7 852=for hackers
94bdecf9 853Found in file perl.c
497711e7 854
954c1994
GS
855=item HeHASH
856
857Returns the computed hash stored in the hash entry.
858
859 U32 HeHASH(HE* he)
860
497711e7
GS
861=for hackers
862Found in file hv.h
863
954c1994
GS
864=item HeKEY
865
866Returns the actual pointer stored in the key slot of the hash entry. The
867pointer may be either C<char*> or C<SV*>, depending on the value of
868C<HeKLEN()>. Can be assigned to. The C<HePV()> or C<HeSVKEY()> macros are
869usually preferable for finding the value of a key.
870
871 void* HeKEY(HE* he)
872
497711e7
GS
873=for hackers
874Found in file hv.h
875
954c1994
GS
876=item HeKLEN
877
878If this is negative, and amounts to C<HEf_SVKEY>, it indicates the entry
879holds an C<SV*> key. Otherwise, holds the actual length of the key. Can
880be assigned to. The C<HePV()> macro is usually preferable for finding key
881lengths.
882
883 STRLEN HeKLEN(HE* he)
884
497711e7
GS
885=for hackers
886Found in file hv.h
887
954c1994
GS
888=item HePV
889
890Returns the key slot of the hash entry as a C<char*> value, doing any
891necessary dereferencing of possibly C<SV*> keys. The length of the string
892is placed in C<len> (this is a macro, so do I<not> use C<&len>). If you do
893not care about what the length of the key is, you may use the global
894variable C<PL_na>, though this is rather less efficient than using a local
895variable. Remember though, that hash keys in perl are free to contain
896embedded nulls, so using C<strlen()> or similar is not a good way to find
897the length of hash keys. This is very similar to the C<SvPV()> macro
898described elsewhere in this document.
899
900 char* HePV(HE* he, STRLEN len)
901
497711e7
GS
902=for hackers
903Found in file hv.h
904
954c1994
GS
905=item HeSVKEY
906
907Returns the key as an C<SV*>, or C<Nullsv> if the hash entry does not
908contain an C<SV*> key.
909
910 SV* HeSVKEY(HE* he)
911
497711e7
GS
912=for hackers
913Found in file hv.h
914
954c1994
GS
915=item HeSVKEY_force
916
917Returns the key as an C<SV*>. Will create and return a temporary mortal
918C<SV*> if the hash entry contains only a C<char*> key.
919
920 SV* HeSVKEY_force(HE* he)
921
497711e7
GS
922=for hackers
923Found in file hv.h
924
954c1994
GS
925=item HeSVKEY_set
926
927Sets the key to a given C<SV*>, taking care to set the appropriate flags to
928indicate the presence of an C<SV*> key, and returns the same
929C<SV*>.
930
931 SV* HeSVKEY_set(HE* he, SV* sv)
932
497711e7
GS
933=for hackers
934Found in file hv.h
935
954c1994
GS
936=item HeVAL
937
938Returns the value slot (type C<SV*>) stored in the hash entry.
939
940 SV* HeVAL(HE* he)
941
497711e7
GS
942=for hackers
943Found in file hv.h
944
954c1994
GS
945=item HvNAME
946
947Returns the package name of a stash. See C<SvSTASH>, C<CvSTASH>.
948
949 char* HvNAME(HV* stash)
950
497711e7
GS
951=for hackers
952Found in file hv.h
953
954c1994
GS
954=item hv_clear
955
956Clears a hash, making it empty.
957
958 void hv_clear(HV* tb)
959
497711e7
GS
960=for hackers
961Found in file hv.c
962
954c1994
GS
963=item hv_delete
964
965Deletes a key/value pair in the hash. The value SV is removed from the
1c846c1f 966hash and returned to the caller. The C<klen> is the length of the key.
954c1994
GS
967The C<flags> value will normally be zero; if set to G_DISCARD then NULL
968will be returned.
969
da58a35d 970 SV* hv_delete(HV* tb, const char* key, I32 klen, I32 flags)
954c1994 971
497711e7
GS
972=for hackers
973Found in file hv.c
974
954c1994
GS
975=item hv_delete_ent
976
977Deletes a key/value pair in the hash. The value SV is removed from the
978hash and returned to the caller. The C<flags> value will normally be zero;
979if set to G_DISCARD then NULL will be returned. C<hash> can be a valid
980precomputed hash value, or 0 to ask for it to be computed.
981
982 SV* hv_delete_ent(HV* tb, SV* key, I32 flags, U32 hash)
983
497711e7
GS
984=for hackers
985Found in file hv.c
986
954c1994
GS
987=item hv_exists
988
989Returns a boolean indicating whether the specified hash key exists. The
990C<klen> is the length of the key.
991
da58a35d 992 bool hv_exists(HV* tb, const char* key, I32 klen)
954c1994 993
497711e7
GS
994=for hackers
995Found in file hv.c
996
954c1994
GS
997=item hv_exists_ent
998
999Returns a boolean indicating whether the specified hash key exists. C<hash>
1000can be a valid precomputed hash value, or 0 to ask for it to be
1001computed.
1002
1003 bool hv_exists_ent(HV* tb, SV* key, U32 hash)
1004
497711e7
GS
1005=for hackers
1006Found in file hv.c
1007
954c1994
GS
1008=item hv_fetch
1009
1010Returns the SV which corresponds to the specified key in the hash. The
1011C<klen> is the length of the key. If C<lval> is set then the fetch will be
1012part of a store. Check that the return value is non-null before
f4758303 1013dereferencing it to an C<SV*>.
954c1994 1014
96f1132b 1015See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1016information on how to use this function on tied hashes.
1017
da58a35d 1018 SV** hv_fetch(HV* tb, const char* key, I32 klen, I32 lval)
954c1994 1019
497711e7
GS
1020=for hackers
1021Found in file hv.c
1022
954c1994
GS
1023=item hv_fetch_ent
1024
1025Returns the hash entry which corresponds to the specified key in the hash.
1026C<hash> must be a valid precomputed hash number for the given C<key>, or 0
1027if you want the function to compute it. IF C<lval> is set then the fetch
1028will be part of a store. Make sure the return value is non-null before
1029accessing it. The return value when C<tb> is a tied hash is a pointer to a
1030static location, so be sure to make a copy of the structure if you need to
1c846c1f 1031store it somewhere.
954c1994 1032
96f1132b 1033See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1034information on how to use this function on tied hashes.
1035
1036 HE* hv_fetch_ent(HV* tb, SV* key, I32 lval, U32 hash)
1037
497711e7
GS
1038=for hackers
1039Found in file hv.c
1040
954c1994
GS
1041=item hv_iterinit
1042
1043Prepares a starting point to traverse a hash table. Returns the number of
1044keys in the hash (i.e. the same as C<HvKEYS(tb)>). The return value is
1c846c1f 1045currently only meaningful for hashes without tie magic.
954c1994
GS
1046
1047NOTE: Before version 5.004_65, C<hv_iterinit> used to return the number of
1048hash buckets that happen to be in use. If you still need that esoteric
1049value, you can get it through the macro C<HvFILL(tb)>.
1050
1051 I32 hv_iterinit(HV* tb)
1052
497711e7
GS
1053=for hackers
1054Found in file hv.c
1055
954c1994
GS
1056=item hv_iterkey
1057
1058Returns the key from the current position of the hash iterator. See
1059C<hv_iterinit>.
1060
1061 char* hv_iterkey(HE* entry, I32* retlen)
1062
497711e7
GS
1063=for hackers
1064Found in file hv.c
1065
954c1994
GS
1066=item hv_iterkeysv
1067
1068Returns the key as an C<SV*> from the current position of the hash
1069iterator. The return value will always be a mortal copy of the key. Also
1070see C<hv_iterinit>.
1071
1072 SV* hv_iterkeysv(HE* entry)
1073
497711e7
GS
1074=for hackers
1075Found in file hv.c
1076
954c1994
GS
1077=item hv_iternext
1078
1079Returns entries from a hash iterator. See C<hv_iterinit>.
1080
1081 HE* hv_iternext(HV* tb)
1082
497711e7
GS
1083=for hackers
1084Found in file hv.c
1085
954c1994
GS
1086=item hv_iternextsv
1087
1088Performs an C<hv_iternext>, C<hv_iterkey>, and C<hv_iterval> in one
1089operation.
1090
1091 SV* hv_iternextsv(HV* hv, char** key, I32* retlen)
1092
497711e7
GS
1093=for hackers
1094Found in file hv.c
1095
954c1994
GS
1096=item hv_iterval
1097
1098Returns the value from the current position of the hash iterator. See
1099C<hv_iterkey>.
1100
1101 SV* hv_iterval(HV* tb, HE* entry)
1102
497711e7
GS
1103=for hackers
1104Found in file hv.c
1105
954c1994
GS
1106=item hv_magic
1107
1108Adds magic to a hash. See C<sv_magic>.
1109
1110 void hv_magic(HV* hv, GV* gv, int how)
1111
497711e7
GS
1112=for hackers
1113Found in file hv.c
1114
954c1994
GS
1115=item hv_store
1116
1117Stores an SV in a hash. The hash key is specified as C<key> and C<klen> is
1118the length of the key. The C<hash> parameter is the precomputed hash
1119value; if it is zero then Perl will compute it. The return value will be
1120NULL if the operation failed or if the value did not need to be actually
1121stored within the hash (as in the case of tied hashes). Otherwise it can
1122be dereferenced to get the original C<SV*>. Note that the caller is
1123responsible for suitably incrementing the reference count of C<val> before
1c846c1f 1124the call, and decrementing it if the function returned NULL.
954c1994 1125
96f1132b 1126See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1127information on how to use this function on tied hashes.
1128
da58a35d 1129 SV** hv_store(HV* tb, const char* key, I32 klen, SV* val, U32 hash)
954c1994 1130
497711e7
GS
1131=for hackers
1132Found in file hv.c
1133
954c1994
GS
1134=item hv_store_ent
1135
1136Stores C<val> in a hash. The hash key is specified as C<key>. The C<hash>
1137parameter is the precomputed hash value; if it is zero then Perl will
1138compute it. The return value is the new hash entry so created. It will be
1139NULL if the operation failed or if the value did not need to be actually
1140stored within the hash (as in the case of tied hashes). Otherwise the
f22d8e4b 1141contents of the return value can be accessed using the C<He?> macros
954c1994
GS
1142described here. Note that the caller is responsible for suitably
1143incrementing the reference count of C<val> before the call, and
1c846c1f 1144decrementing it if the function returned NULL.
954c1994 1145
96f1132b 1146See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1147information on how to use this function on tied hashes.
1148
1149 HE* hv_store_ent(HV* tb, SV* key, SV* val, U32 hash)
1150
497711e7
GS
1151=for hackers
1152Found in file hv.c
1153
954c1994
GS
1154=item hv_undef
1155
1156Undefines the hash.
1157
1158 void hv_undef(HV* tb)
1159
497711e7
GS
1160=for hackers
1161Found in file hv.c
1162
94bdecf9 1163=item newHV
d2cc3551 1164
94bdecf9 1165Creates a new HV. The reference count is set to 1.
d2cc3551 1166
94bdecf9 1167 HV* newHV()
d2cc3551
JH
1168
1169=for hackers
94bdecf9 1170Found in file hv.c
d2cc3551 1171
94bdecf9 1172=item Nullhv
954c1994 1173
94bdecf9 1174Null HV pointer.
954c1994 1175
954c1994 1176
497711e7 1177=for hackers
94bdecf9 1178Found in file hv.h
497711e7 1179
954c1994 1180
94bdecf9 1181=back
954c1994 1182
94bdecf9 1183=head1 Magical Functions
954c1994 1184
94bdecf9 1185=over 8
497711e7 1186
94bdecf9 1187=item mg_clear
954c1994 1188
94bdecf9 1189Clear something magical that the SV represents. See C<sv_magic>.
954c1994 1190
94bdecf9 1191 int mg_clear(SV* sv)
954c1994 1192
497711e7 1193=for hackers
94bdecf9 1194Found in file mg.c
497711e7 1195
94bdecf9 1196=item mg_copy
954c1994 1197
94bdecf9 1198Copies the magic from one SV to another. See C<sv_magic>.
954c1994 1199
94bdecf9 1200 int mg_copy(SV* sv, SV* nsv, const char* key, I32 klen)
954c1994 1201
497711e7 1202=for hackers
94bdecf9 1203Found in file mg.c
497711e7 1204
94bdecf9 1205=item mg_find
954c1994 1206
94bdecf9 1207Finds the magic pointer for type matching the SV. See C<sv_magic>.
954c1994 1208
94bdecf9 1209 MAGIC* mg_find(SV* sv, int type)
954c1994 1210
497711e7 1211=for hackers
94bdecf9 1212Found in file mg.c
497711e7 1213
94bdecf9 1214=item mg_free
954c1994 1215
94bdecf9 1216Free any magic storage used by the SV. See C<sv_magic>.
954c1994 1217
94bdecf9 1218 int mg_free(SV* sv)
954c1994 1219
497711e7 1220=for hackers
94bdecf9 1221Found in file mg.c
497711e7 1222
94bdecf9 1223=item mg_get
eebe1485 1224
94bdecf9 1225Do magic after a value is retrieved from the SV. See C<sv_magic>.
282f25c9 1226
94bdecf9 1227 int mg_get(SV* sv)
eebe1485
SC
1228
1229=for hackers
94bdecf9 1230Found in file mg.c
eebe1485 1231
94bdecf9 1232=item mg_length
eebe1485 1233
94bdecf9 1234Report on the SV's length. See C<sv_magic>.
eebe1485 1235
94bdecf9 1236 U32 mg_length(SV* sv)
eebe1485
SC
1237
1238=for hackers
94bdecf9 1239Found in file mg.c
eebe1485 1240
94bdecf9 1241=item mg_magical
954c1994 1242
94bdecf9 1243Turns on the magical status of an SV. See C<sv_magic>.
954c1994 1244
94bdecf9 1245 void mg_magical(SV* sv)
954c1994 1246
497711e7 1247=for hackers
94bdecf9 1248Found in file mg.c
497711e7 1249
94bdecf9 1250=item mg_set
954c1994 1251
94bdecf9 1252Do magic after a value is assigned to the SV. See C<sv_magic>.
954c1994 1253
94bdecf9 1254 int mg_set(SV* sv)
954c1994 1255
497711e7 1256=for hackers
94bdecf9 1257Found in file mg.c
497711e7 1258
94bdecf9 1259=item SvGETMAGIC
954c1994 1260
94bdecf9
JH
1261Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
1262argument more than once.
954c1994 1263
94bdecf9 1264 void SvGETMAGIC(SV* sv)
954c1994 1265
497711e7 1266=for hackers
94bdecf9 1267Found in file sv.h
497711e7 1268
a4f1a029
NIS
1269=item SvLOCK
1270
1271Arranges for a mutual exclusion lock to be obtained on sv if a suitable module
1272has been loaded.
1273
1274 void SvLOCK(SV* sv)
1275
1276=for hackers
1277Found in file sv.h
1278
94bdecf9 1279=item SvSETMAGIC
7d3fb230 1280
94bdecf9
JH
1281Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1282argument more than once.
7d3fb230 1283
94bdecf9 1284 void SvSETMAGIC(SV* sv)
7d3fb230
BS
1285
1286=for hackers
94bdecf9 1287Found in file sv.h
7d3fb230 1288
94bdecf9 1289=item SvSetMagicSV
954c1994 1290
94bdecf9 1291Like C<SvSetSV>, but does any set magic required afterwards.
954c1994 1292
94bdecf9 1293 void SvSetMagicSV(SV* dsb, SV* ssv)
954c1994 1294
497711e7 1295=for hackers
94bdecf9 1296Found in file sv.h
497711e7 1297
a4f1a029
NIS
1298=item SvSetMagicSV_nosteal
1299
1300Like C<SvSetMagicSV>, but does any set magic required afterwards.
1301
1302 void SvSetMagicSV_nosteal(SV* dsv, SV* ssv)
1303
1304=for hackers
1305Found in file sv.h
1306
94bdecf9 1307=item SvSetSV
954c1994 1308
94bdecf9
JH
1309Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1310more than once.
1311
1312 void SvSetSV(SV* dsb, SV* ssv)
954c1994 1313
497711e7 1314=for hackers
94bdecf9 1315Found in file sv.h
497711e7 1316
94bdecf9 1317=item SvSetSV_nosteal
954c1994 1318
94bdecf9
JH
1319Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1320ssv. May evaluate arguments more than once.
954c1994 1321
94bdecf9 1322 void SvSetSV_nosteal(SV* dsv, SV* ssv)
954c1994 1323
497711e7 1324=for hackers
94bdecf9 1325Found in file sv.h
497711e7 1326
a4f1a029
NIS
1327=item SvSHARE
1328
1329Arranges for sv to be shared between threads if a suitable module
1330has been loaded.
1331
1332 void SvSHARE(SV* sv)
1333
1334=for hackers
1335Found in file sv.h
1336
954c1994 1337
94bdecf9 1338=back
954c1994 1339
94bdecf9 1340=head1 Memory Management
954c1994 1341
94bdecf9 1342=over 8
497711e7 1343
94bdecf9 1344=item Copy
954c1994 1345
94bdecf9
JH
1346The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the
1347source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
1348the type. May fail on overlapping copies. See also C<Move>.
954c1994 1349
94bdecf9 1350 void Copy(void* src, void* dest, int nitems, type)
954c1994 1351
497711e7 1352=for hackers
94bdecf9 1353Found in file handy.h
497711e7 1354
94bdecf9 1355=item Move
954c1994 1356
94bdecf9
JH
1357The XSUB-writer's interface to the C C<memmove> function. The C<src> is the
1358source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
1359the type. Can do overlapping moves. See also C<Copy>.
954c1994 1360
94bdecf9 1361 void Move(void* src, void* dest, int nitems, type)
954c1994 1362
497711e7 1363=for hackers
94bdecf9 1364Found in file handy.h
497711e7 1365
94bdecf9 1366=item New
954c1994 1367
94bdecf9 1368The XSUB-writer's interface to the C C<malloc> function.
954c1994 1369
94bdecf9 1370 void New(int id, void* ptr, int nitems, type)
954c1994 1371
497711e7 1372=for hackers
94bdecf9 1373Found in file handy.h
497711e7 1374
94bdecf9 1375=item Newc
954c1994 1376
94bdecf9
JH
1377The XSUB-writer's interface to the C C<malloc> function, with
1378cast.
954c1994 1379
94bdecf9 1380 void Newc(int id, void* ptr, int nitems, type, cast)
954c1994 1381
497711e7 1382=for hackers
94bdecf9 1383Found in file handy.h
954c1994 1384
94bdecf9 1385=item NEWSV
497711e7 1386
94bdecf9
JH
1387Creates a new SV. A non-zero C<len> parameter indicates the number of
1388bytes of preallocated string space the SV should have. An extra byte for a
1389tailing NUL is also reserved. (SvPOK is not set for the SV even if string
1390space is allocated.) The reference count for the new SV is set to 1.
1391C<id> is an integer id between 0 and 1299 (used to identify leaks).
954c1994 1392
954c1994 1393
94bdecf9 1394 SV* NEWSV(int id, STRLEN len)
954c1994 1395
497711e7 1396=for hackers
94bdecf9 1397Found in file handy.h
497711e7 1398
94bdecf9 1399=item Newz
954c1994 1400
94bdecf9
JH
1401The XSUB-writer's interface to the C C<malloc> function. The allocated
1402memory is zeroed with C<memzero>.
954c1994 1403
94bdecf9 1404 void Newz(int id, void* ptr, int nitems, type)
954c1994 1405
497711e7
GS
1406=for hackers
1407Found in file handy.h
1408
94bdecf9 1409=item Renew
954c1994 1410
94bdecf9 1411The XSUB-writer's interface to the C C<realloc> function.
954c1994 1412
94bdecf9 1413 void Renew(void* ptr, int nitems, type)
954c1994 1414
497711e7
GS
1415=for hackers
1416Found in file handy.h
1417
94bdecf9 1418=item Renewc
954c1994 1419
94bdecf9
JH
1420The XSUB-writer's interface to the C C<realloc> function, with
1421cast.
954c1994 1422
94bdecf9 1423 void Renewc(void* ptr, int nitems, type, cast)
954c1994 1424
497711e7 1425=for hackers
94bdecf9 1426Found in file handy.h
497711e7 1427
94bdecf9 1428=item Safefree
954c1994 1429
94bdecf9 1430The XSUB-writer's interface to the C C<free> function.
954c1994 1431
94bdecf9 1432 void Safefree(void* ptr)
954c1994 1433
497711e7
GS
1434=for hackers
1435Found in file handy.h
1436
94bdecf9 1437=item savepv
954c1994 1438
94bdecf9 1439Copy a string to a safe spot. This does not use an SV.
954c1994 1440
94bdecf9 1441 char* savepv(const char* sv)
954c1994 1442
497711e7 1443=for hackers
94bdecf9 1444Found in file util.c
497711e7 1445
94bdecf9 1446=item savepvn
954c1994 1447
94bdecf9 1448Copy a string to a safe spot. The C<len> indicates number of bytes to
a4f1a029
NIS
1449copy. If pointer is NULL allocate space for a string of size specified.
1450This does not use an SV.
954c1994 1451
94bdecf9 1452 char* savepvn(const char* sv, I32 len)
954c1994 1453
497711e7 1454=for hackers
94bdecf9 1455Found in file util.c
497711e7 1456
a4f1a029
NIS
1457=item savesharedpv
1458
1459Copy a string to a safe spot in memory shared between threads.
1460This does not use an SV.
1461
1462 char* savesharedpv(const char* sv)
1463
1464=for hackers
1465Found in file util.c
1466
94bdecf9 1467=item StructCopy
954c1994 1468
94bdecf9 1469This is an architecture-independent macro to copy one structure to another.
954c1994 1470
94bdecf9 1471 void StructCopy(type src, type dest, type)
954c1994 1472
497711e7 1473=for hackers
94bdecf9 1474Found in file handy.h
497711e7 1475
94bdecf9 1476=item Zero
954c1994 1477
94bdecf9
JH
1478The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the
1479destination, C<nitems> is the number of items, and C<type> is the type.
954c1994 1480
94bdecf9 1481 void Zero(void* dest, int nitems, type)
954c1994 1482
497711e7 1483=for hackers
94bdecf9 1484Found in file handy.h
497711e7 1485
954c1994 1486
94bdecf9 1487=back
954c1994 1488
94bdecf9 1489=head1 Miscellaneous Functions
954c1994 1490
94bdecf9 1491=over 8
497711e7 1492
94bdecf9 1493=item fbm_compile
8b4ac5a4 1494
94bdecf9
JH
1495Analyses the string in order to make fast searches on it using fbm_instr()
1496-- the Boyer-Moore algorithm.
8b4ac5a4 1497
94bdecf9 1498 void fbm_compile(SV* sv, U32 flags)
8b4ac5a4
JH
1499
1500=for hackers
94bdecf9 1501Found in file util.c
8b4ac5a4 1502
94bdecf9 1503=item fbm_instr
954c1994 1504
94bdecf9
JH
1505Returns the location of the SV in the string delimited by C<str> and
1506C<strend>. It returns C<Nullch> if the string can't be found. The C<sv>
1507does not have to be fbm_compiled, but the search will not be as fast
1508then.
954c1994 1509
94bdecf9 1510 char* fbm_instr(unsigned char* big, unsigned char* bigend, SV* littlesv, U32 flags)
954c1994 1511
497711e7 1512=for hackers
94bdecf9 1513Found in file util.c
497711e7 1514
94bdecf9 1515=item form
954c1994 1516
94bdecf9
JH
1517Takes a sprintf-style format pattern and conventional
1518(non-SV) arguments and returns the formatted string.
954c1994 1519
94bdecf9 1520 (char *) Perl_form(pTHX_ const char* pat, ...)
954c1994 1521
94bdecf9 1522can be used any place a string (char *) is required:
497711e7 1523
94bdecf9 1524 char * s = Perl_form("%d.%d",major,minor);
954c1994 1525
94bdecf9
JH
1526Uses a single private buffer so if you want to format several strings you
1527must explicitly copy the earlier strings away (and free the copies when you
1528are done).
954c1994 1529
94bdecf9 1530 char* form(const char* pat, ...)
954c1994 1531
497711e7 1532=for hackers
94bdecf9 1533Found in file util.c
497711e7 1534
94bdecf9 1535=item getcwd_sv
954c1994 1536
94bdecf9 1537Fill the sv with current working directory
954c1994 1538
94bdecf9 1539 int getcwd_sv(SV* sv)
954c1994 1540
497711e7 1541=for hackers
94bdecf9 1542Found in file util.c
497711e7 1543
94bdecf9 1544=item strEQ
954c1994 1545
94bdecf9 1546Test two strings to see if they are equal. Returns true or false.
954c1994 1547
94bdecf9 1548 bool strEQ(char* s1, char* s2)
954c1994 1549
497711e7 1550=for hackers
94bdecf9 1551Found in file handy.h
497711e7 1552
94bdecf9 1553=item strGE
1c846c1f 1554
94bdecf9
JH
1555Test two strings to see if the first, C<s1>, is greater than or equal to
1556the second, C<s2>. Returns true or false.
1c846c1f 1557
94bdecf9 1558 bool strGE(char* s1, char* s2)
1c846c1f
NIS
1559
1560=for hackers
94bdecf9 1561Found in file handy.h
1c846c1f 1562
94bdecf9 1563=item strGT
954c1994 1564
94bdecf9
JH
1565Test two strings to see if the first, C<s1>, is greater than the second,
1566C<s2>. Returns true or false.
954c1994 1567
94bdecf9 1568 bool strGT(char* s1, char* s2)
954c1994 1569
497711e7 1570=for hackers
94bdecf9 1571Found in file handy.h
497711e7 1572
94bdecf9 1573=item strLE
954c1994 1574
94bdecf9
JH
1575Test two strings to see if the first, C<s1>, is less than or equal to the
1576second, C<s2>. Returns true or false.
954c1994 1577
94bdecf9 1578 bool strLE(char* s1, char* s2)
954c1994 1579
497711e7 1580=for hackers
94bdecf9 1581Found in file handy.h
497711e7 1582
94bdecf9 1583=item strLT
1a3327fb 1584
94bdecf9
JH
1585Test two strings to see if the first, C<s1>, is less than the second,
1586C<s2>. Returns true or false.
1a3327fb 1587
94bdecf9 1588 bool strLT(char* s1, char* s2)
1a3327fb 1589
497711e7 1590=for hackers
94bdecf9 1591Found in file handy.h
497711e7 1592
94bdecf9 1593=item strNE
954c1994 1594
94bdecf9
JH
1595Test two strings to see if they are different. Returns true or
1596false.
1597
1598 bool strNE(char* s1, char* s2)
954c1994 1599
497711e7 1600=for hackers
94bdecf9 1601Found in file handy.h
497711e7 1602
94bdecf9 1603=item strnEQ
954c1994 1604
94bdecf9
JH
1605Test two strings to see if they are equal. The C<len> parameter indicates
1606the number of bytes to compare. Returns true or false. (A wrapper for
1607C<strncmp>).
1608
1609 bool strnEQ(char* s1, char* s2, STRLEN len)
954c1994 1610
497711e7 1611=for hackers
94bdecf9 1612Found in file handy.h
497711e7 1613
94bdecf9 1614=item strnNE
954c1994 1615
94bdecf9
JH
1616Test two strings to see if they are different. The C<len> parameter
1617indicates the number of bytes to compare. Returns true or false. (A
1618wrapper for C<strncmp>).
954c1994 1619
94bdecf9 1620 bool strnNE(char* s1, char* s2, STRLEN len)
954c1994 1621
497711e7
GS
1622=for hackers
1623Found in file handy.h
1624
f4758303 1625
94bdecf9 1626=back
7207e29d 1627
94bdecf9 1628=head1 Numeric functions
7207e29d 1629
94bdecf9 1630=over 8
f4758303 1631
94bdecf9 1632=item grok_bin
f4758303 1633
94bdecf9
JH
1634converts a string representing a binary number to numeric form.
1635
1636On entry I<start> and I<*len> give the string to scan, I<*flags> gives
1637conversion flags, and I<result> should be NULL or a pointer to an NV.
1638The scan stops at the end of the string, or the first invalid character.
1639On return I<*len> is set to the length scanned string, and I<*flags> gives
1640output flags.
1641
1642If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
1643and nothing is written to I<*result>. If the value is > UV_MAX C<grok_bin>
1644returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
1645and writes the value to I<*result> (or the value is discarded if I<result>
1646is NULL).
1647
1648The hex number may optionally be prefixed with "0b" or "b" unless
1649C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
1650C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the binary
1651number may use '_' characters to separate digits.
1652
1653 UV grok_bin(char* start, STRLEN* len, I32* flags, NV *result)
f4758303
JP
1654
1655=for hackers
94bdecf9 1656Found in file numeric.c
f4758303 1657
94bdecf9 1658=item grok_hex
954c1994 1659
94bdecf9
JH
1660converts a string representing a hex number to numeric form.
1661
1662On entry I<start> and I<*len> give the string to scan, I<*flags> gives
1663conversion flags, and I<result> should be NULL or a pointer to an NV.
1664The scan stops at the end of the string, or the first non-hex-digit character.
1665On return I<*len> is set to the length scanned string, and I<*flags> gives
1666output flags.
1667
1668If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
1669and nothing is written to I<*result>. If the value is > UV_MAX C<grok_hex>
1670returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
1671and writes the value to I<*result> (or the value is discarded if I<result>
1672is NULL).
1673
1674The hex number may optionally be prefixed with "0x" or "x" unless
1675C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
1676C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the hex
1677number may use '_' characters to separate digits.
1678
1679 UV grok_hex(char* start, STRLEN* len, I32* flags, NV *result)
954c1994 1680
497711e7 1681=for hackers
94bdecf9 1682Found in file numeric.c
497711e7 1683
94bdecf9 1684=item grok_number
954c1994 1685
94bdecf9
JH
1686Recognise (or not) a number. The type of the number is returned
1687(0 if unrecognised), otherwise it is a bit-ORed combination of
1688IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
1689IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
1690
1691If the value of the number can fit an in UV, it is returned in the *valuep
1692IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
1693will never be set unless *valuep is valid, but *valuep may have been assigned
1694to during processing even though IS_NUMBER_IN_UV is not set on return.
1695If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
1696valuep is non-NULL, but no actual assignment (or SEGV) will occur.
1697
1698IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
1699seen (in which case *valuep gives the true value truncated to an integer), and
1700IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
1701absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
1702number is larger than a UV.
1703
1704 int grok_number(const char *pv, STRLEN len, UV *valuep)
954c1994 1705
497711e7 1706=for hackers
94bdecf9 1707Found in file numeric.c
497711e7 1708
94bdecf9 1709=item grok_numeric_radix
954c1994 1710
94bdecf9
JH
1711Scan and skip for a numeric decimal separator (radix).
1712
1713 bool grok_numeric_radix(const char **sp, const char *send)
954c1994 1714
497711e7 1715=for hackers
94bdecf9 1716Found in file numeric.c
497711e7 1717
94bdecf9 1718=item grok_oct
954c1994 1719
94bdecf9
JH
1720
1721 UV grok_oct(char* start, STRLEN* len, I32* flags, NV *result)
954c1994 1722
497711e7 1723=for hackers
94bdecf9 1724Found in file numeric.c
497711e7 1725
94bdecf9 1726=item scan_bin
954c1994 1727
94bdecf9
JH
1728For backwards compatibility. Use C<grok_bin> instead.
1729
1730 NV scan_bin(char* start, STRLEN len, STRLEN* retlen)
954c1994 1731
497711e7 1732=for hackers
94bdecf9 1733Found in file numeric.c
497711e7 1734
94bdecf9 1735=item scan_hex
954c1994 1736
94bdecf9
JH
1737For backwards compatibility. Use C<grok_hex> instead.
1738
1739 NV scan_hex(char* start, STRLEN len, STRLEN* retlen)
954c1994 1740
497711e7 1741=for hackers
94bdecf9 1742Found in file numeric.c
497711e7 1743
94bdecf9 1744=item scan_oct
954c1994 1745
94bdecf9 1746For backwards compatibility. Use C<grok_oct> instead.
954c1994 1747
94bdecf9 1748 NV scan_oct(char* start, STRLEN len, STRLEN* retlen)
954c1994 1749
497711e7 1750=for hackers
94bdecf9 1751Found in file numeric.c
497711e7 1752
645c22ef 1753
94bdecf9 1754=back
645c22ef 1755
94bdecf9
JH
1756=head1 Optree Manipulation Functions
1757
1758=over 8
1759
1760=item cv_const_sv
1761
1762If C<cv> is a constant sub eligible for inlining. returns the constant
1763value returned by the sub. Otherwise, returns NULL.
1764
1765Constant subs can be created with C<newCONSTSUB> or as described in
1766L<perlsub/"Constant Functions">.
1767
1768 SV* cv_const_sv(CV* cv)
645c22ef
DM
1769
1770=for hackers
94bdecf9 1771Found in file op.c
645c22ef 1772
94bdecf9 1773=item newCONSTSUB
954c1994 1774
94bdecf9
JH
1775Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
1776eligible for inlining at compile-time.
954c1994 1777
94bdecf9 1778 CV* newCONSTSUB(HV* stash, char* name, SV* sv)
954c1994 1779
497711e7 1780=for hackers
94bdecf9 1781Found in file op.c
497711e7 1782
94bdecf9 1783=item newXS
954c1994 1784
94bdecf9 1785Used by C<xsubpp> to hook up XSUBs as Perl subs.
954c1994 1786
94bdecf9
JH
1787=for hackers
1788Found in file op.c
1789
1790
1791=back
1792
94bdecf9
JH
1793=head1 Stack Manipulation Macros
1794
1795=over 8
1796
1797=item dMARK
954c1994 1798
94bdecf9
JH
1799Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
1800C<dORIGMARK>.
954c1994 1801
94bdecf9 1802 dMARK;
954c1994 1803
497711e7 1804=for hackers
94bdecf9 1805Found in file pp.h
497711e7 1806
94bdecf9 1807=item dORIGMARK
954c1994 1808
94bdecf9 1809Saves the original stack mark for the XSUB. See C<ORIGMARK>.
954c1994 1810
94bdecf9 1811 dORIGMARK;
954c1994 1812
497711e7 1813=for hackers
94bdecf9 1814Found in file pp.h
497711e7 1815
94bdecf9 1816=item dSP
954c1994 1817
94bdecf9
JH
1818Declares a local copy of perl's stack pointer for the XSUB, available via
1819the C<SP> macro. See C<SP>.
954c1994 1820
94bdecf9 1821 dSP;
954c1994 1822
497711e7 1823=for hackers
94bdecf9 1824Found in file pp.h
497711e7 1825
94bdecf9 1826=item EXTEND
954c1994 1827
94bdecf9
JH
1828Used to extend the argument stack for an XSUB's return values. Once
1829used, guarantees that there is room for at least C<nitems> to be pushed
1830onto the stack.
954c1994 1831
94bdecf9 1832 void EXTEND(SP, int nitems)
954c1994 1833
497711e7 1834=for hackers
94bdecf9 1835Found in file pp.h
954c1994 1836
94bdecf9 1837=item MARK
954c1994 1838
94bdecf9 1839Stack marker variable for the XSUB. See C<dMARK>.
954c1994 1840
497711e7 1841=for hackers
94bdecf9 1842Found in file pp.h
954c1994 1843
94bdecf9 1844=item ORIGMARK
954c1994 1845
94bdecf9 1846The original stack mark for the XSUB. See C<dORIGMARK>.
954c1994 1847
497711e7 1848=for hackers
94bdecf9 1849Found in file pp.h
497711e7 1850
954c1994
GS
1851=item POPi
1852
1853Pops an integer off the stack.
1854
1855 IV POPi
1856
497711e7
GS
1857=for hackers
1858Found in file pp.h
1859
954c1994
GS
1860=item POPl
1861
1862Pops a long off the stack.
1863
1864 long POPl
1865
497711e7
GS
1866=for hackers
1867Found in file pp.h
1868
954c1994
GS
1869=item POPn
1870
1871Pops a double off the stack.
1872
1873 NV POPn
1874
497711e7
GS
1875=for hackers
1876Found in file pp.h
1877
954c1994
GS
1878=item POPp
1879
fa519979
JH
1880Pops a string off the stack. Deprecated. New code should provide
1881a STRLEN n_a and use POPpx.
954c1994
GS
1882
1883 char* POPp
1884
497711e7
GS
1885=for hackers
1886Found in file pp.h
1887
fa519979
JH
1888=item POPpbytex
1889
1890Pops a string off the stack which must consist of bytes i.e. characters < 256.
1891Requires a variable STRLEN n_a in scope.
1892
1893 char* POPpbytex
1894
1895=for hackers
1896Found in file pp.h
1897
1898=item POPpx
1899
1900Pops a string off the stack.
1901Requires a variable STRLEN n_a in scope.
1902
1903 char* POPpx
1904
1905=for hackers
1906Found in file pp.h
1907
954c1994
GS
1908=item POPs
1909
1910Pops an SV off the stack.
1911
1912 SV* POPs
1913
497711e7
GS
1914=for hackers
1915Found in file pp.h
1916
954c1994
GS
1917=item PUSHi
1918
1919Push an integer onto the stack. The stack must have room for this element.
1920Handles 'set' magic. See C<XPUSHi>.
1921
1922 void PUSHi(IV iv)
1923
497711e7
GS
1924=for hackers
1925Found in file pp.h
1926
954c1994
GS
1927=item PUSHMARK
1928
1929Opening bracket for arguments on a callback. See C<PUTBACK> and
1930L<perlcall>.
1931
1932 PUSHMARK;
1933
497711e7
GS
1934=for hackers
1935Found in file pp.h
1936
954c1994
GS
1937=item PUSHn
1938
1939Push a double onto the stack. The stack must have room for this element.
1940Handles 'set' magic. See C<XPUSHn>.
1941
1942 void PUSHn(NV nv)
1943
497711e7
GS
1944=for hackers
1945Found in file pp.h
1946
954c1994
GS
1947=item PUSHp
1948
1949Push a string onto the stack. The stack must have room for this element.
1950The C<len> indicates the length of the string. Handles 'set' magic. See
1951C<XPUSHp>.
1952
1953 void PUSHp(char* str, STRLEN len)
1954
497711e7
GS
1955=for hackers
1956Found in file pp.h
1957
954c1994
GS
1958=item PUSHs
1959
1c846c1f 1960Push an SV onto the stack. The stack must have room for this element.
954c1994
GS
1961Does not handle 'set' magic. See C<XPUSHs>.
1962
1963 void PUSHs(SV* sv)
1964
497711e7
GS
1965=for hackers
1966Found in file pp.h
1967
954c1994
GS
1968=item PUSHu
1969
1970Push an unsigned integer onto the stack. The stack must have room for this
1971element. See C<XPUSHu>.
1972
1973 void PUSHu(UV uv)
1974
497711e7
GS
1975=for hackers
1976Found in file pp.h
1977
954c1994
GS
1978=item PUTBACK
1979
1980Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
1981See C<PUSHMARK> and L<perlcall> for other uses.
1982
1983 PUTBACK;
1984
497711e7
GS
1985=for hackers
1986Found in file pp.h
1987
94bdecf9 1988=item SP
d2cc3551 1989
94bdecf9
JH
1990Stack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
1991C<SPAGAIN>.
d2cc3551 1992
94bdecf9
JH
1993=for hackers
1994Found in file pp.h
1995
1996=item SPAGAIN
1997
1998Refetch the stack pointer. Used after a callback. See L<perlcall>.
1999
2000 SPAGAIN;
d2cc3551
JH
2001
2002=for hackers
94bdecf9 2003Found in file pp.h
d2cc3551 2004
94bdecf9 2005=item XPUSHi
954c1994 2006
94bdecf9
JH
2007Push an integer onto the stack, extending the stack if necessary. Handles
2008'set' magic. See C<PUSHi>.
954c1994 2009
94bdecf9 2010 void XPUSHi(IV iv)
954c1994 2011
497711e7 2012=for hackers
94bdecf9 2013Found in file pp.h
497711e7 2014
94bdecf9 2015=item XPUSHn
954c1994 2016
94bdecf9
JH
2017Push a double onto the stack, extending the stack if necessary. Handles
2018'set' magic. See C<PUSHn>.
954c1994 2019
94bdecf9 2020 void XPUSHn(NV nv)
954c1994 2021
497711e7 2022=for hackers
94bdecf9 2023Found in file pp.h
497711e7 2024
94bdecf9 2025=item XPUSHp
954c1994 2026
94bdecf9
JH
2027Push a string onto the stack, extending the stack if necessary. The C<len>
2028indicates the length of the string. Handles 'set' magic. See
2029C<PUSHp>.
954c1994 2030
94bdecf9 2031 void XPUSHp(char* str, STRLEN len)
954c1994 2032
94bdecf9
JH
2033=for hackers
2034Found in file pp.h
2035
2036=item XPUSHs
2037
2038Push an SV onto the stack, extending the stack if necessary. Does not
2039handle 'set' magic. See C<PUSHs>.
2040
2041 void XPUSHs(SV* sv)
954c1994 2042
497711e7 2043=for hackers
94bdecf9 2044Found in file pp.h
497711e7 2045
94bdecf9 2046=item XPUSHu
954c1994 2047
94bdecf9
JH
2048Push an unsigned integer onto the stack, extending the stack if necessary.
2049See C<PUSHu>.
954c1994 2050
94bdecf9
JH
2051 void XPUSHu(UV uv)
2052
2053=for hackers
2054Found in file pp.h
2055
2056=item XSRETURN
2057
2058Return from XSUB, indicating number of items on the stack. This is usually
2059handled by C<xsubpp>.
2060
2061 void XSRETURN(int nitems)
954c1994 2062
497711e7
GS
2063=for hackers
2064Found in file XSUB.h
2065
94bdecf9 2066=item XSRETURN_IV
954c1994 2067
94bdecf9 2068Return an integer from an XSUB immediately. Uses C<XST_mIV>.
954c1994 2069
94bdecf9 2070 void XSRETURN_IV(IV iv)
954c1994 2071
497711e7 2072=for hackers
94bdecf9 2073Found in file XSUB.h
497711e7 2074
94bdecf9 2075=item XSRETURN_NO
954c1994 2076
94bdecf9 2077Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
954c1994 2078
94bdecf9 2079 XSRETURN_NO;
954c1994 2080
497711e7 2081=for hackers
94bdecf9 2082Found in file XSUB.h
497711e7 2083
94bdecf9 2084=item XSRETURN_NV
954c1994 2085
94bdecf9 2086Return a double from an XSUB immediately. Uses C<XST_mNV>.
954c1994 2087
94bdecf9 2088 void XSRETURN_NV(NV nv)
954c1994 2089
497711e7 2090=for hackers
94bdecf9
JH
2091Found in file XSUB.h
2092
2093=item XSRETURN_PV
2094
2095Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
2096
2097 void XSRETURN_PV(char* str)
2098
2099=for hackers
2100Found in file XSUB.h
2101
2102=item XSRETURN_UNDEF
2103
2104Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
2105
2106 XSRETURN_UNDEF;
2107
2108=for hackers
2109Found in file XSUB.h
2110
2111=item XSRETURN_YES
2112
2113Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
2114
2115 XSRETURN_YES;
2116
2117=for hackers
2118Found in file XSUB.h
2119
2120=item XST_mIV
2121
2122Place an integer into the specified position C<pos> on the stack. The
2123value is stored in a new mortal SV.
2124
2125 void XST_mIV(int pos, IV iv)
2126
2127=for hackers
2128Found in file XSUB.h
2129
2130=item XST_mNO
2131
2132Place C<&PL_sv_no> into the specified position C<pos> on the
2133stack.
2134
2135 void XST_mNO(int pos)
2136
2137=for hackers
2138Found in file XSUB.h
2139
2140=item XST_mNV
2141
2142Place a double into the specified position C<pos> on the stack. The value
2143is stored in a new mortal SV.
2144
2145 void XST_mNV(int pos, NV nv)
2146
2147=for hackers
2148Found in file XSUB.h
2149
2150=item XST_mPV
2151
2152Place a copy of a string into the specified position C<pos> on the stack.
2153The value is stored in a new mortal SV.
2154
2155 void XST_mPV(int pos, char* str)
2156
2157=for hackers
2158Found in file XSUB.h
2159
2160=item XST_mUNDEF
2161
2162Place C<&PL_sv_undef> into the specified position C<pos> on the
2163stack.
2164
2165 void XST_mUNDEF(int pos)
2166
2167=for hackers
2168Found in file XSUB.h
2169
2170=item XST_mYES
2171
2172Place C<&PL_sv_yes> into the specified position C<pos> on the
2173stack.
2174
2175 void XST_mYES(int pos)
2176
2177=for hackers
2178Found in file XSUB.h
2179
2180
2181=back
2182
2183=head1 SV Flags
497711e7 2184
94bdecf9 2185=over 8
954c1994 2186
94bdecf9 2187=item svtype
954c1994 2188
94bdecf9
JH
2189An enum of flags for Perl types. These are found in the file B<sv.h>
2190in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
954c1994 2191
497711e7 2192=for hackers
94bdecf9 2193Found in file sv.h
6e9d1081 2194
94bdecf9 2195=item SVt_IV
6e9d1081 2196
94bdecf9 2197Integer type flag for scalars. See C<svtype>.
6e9d1081
NC
2198
2199=for hackers
94bdecf9 2200Found in file sv.h
6e9d1081 2201
94bdecf9 2202=item SVt_NV
6e9d1081 2203
94bdecf9 2204Double type flag for scalars. See C<svtype>.
6e9d1081
NC
2205
2206=for hackers
94bdecf9 2207Found in file sv.h
6e9d1081 2208
94bdecf9 2209=item SVt_PV
6e9d1081 2210
94bdecf9 2211Pointer type flag for scalars. See C<svtype>.
6e9d1081
NC
2212
2213=for hackers
94bdecf9 2214Found in file sv.h
cd1ee231 2215
94bdecf9 2216=item SVt_PVAV
cd1ee231 2217
94bdecf9 2218Type flag for arrays. See C<svtype>.
cd1ee231
JH
2219
2220=for hackers
94bdecf9 2221Found in file sv.h
cd1ee231 2222
94bdecf9 2223=item SVt_PVCV
cd1ee231 2224
94bdecf9 2225Type flag for code refs. See C<svtype>.
cd1ee231
JH
2226
2227=for hackers
94bdecf9 2228Found in file sv.h
cd1ee231 2229
94bdecf9 2230=item SVt_PVHV
cd1ee231 2231
94bdecf9 2232Type flag for hashes. See C<svtype>.
cd1ee231
JH
2233
2234=for hackers
94bdecf9 2235Found in file sv.h
cd1ee231 2236
94bdecf9 2237=item SVt_PVMG
cd1ee231 2238
94bdecf9 2239Type flag for blessed scalars. See C<svtype>.
cd1ee231
JH
2240
2241=for hackers
94bdecf9 2242Found in file sv.h
cd1ee231 2243
cd1ee231 2244
94bdecf9 2245=back
cd1ee231 2246
94bdecf9 2247=head1 SV Manipulation Functions
cd1ee231 2248
94bdecf9 2249=over 8
cd1ee231 2250
94bdecf9 2251=item get_sv
cd1ee231 2252
94bdecf9
JH
2253Returns the SV of the specified Perl scalar. If C<create> is set and the
2254Perl variable does not exist then it will be created. If C<create> is not
2255set and the variable does not exist then NULL is returned.
2256
2257NOTE: the perl_ form of this function is deprecated.
2258
2259 SV* get_sv(const char* name, I32 create)
cd1ee231
JH
2260
2261=for hackers
94bdecf9 2262Found in file perl.c
cd1ee231 2263
94bdecf9 2264=item looks_like_number
cd1ee231 2265
94bdecf9
JH
2266Test if the content of an SV looks like a number (or is a number).
2267C<Inf> and C<Infinity> are treated as numbers (so will not issue a
2268non-numeric warning), even if your atof() doesn't grok them.
cd1ee231 2269
94bdecf9 2270 I32 looks_like_number(SV* sv)
cd1ee231
JH
2271
2272=for hackers
94bdecf9 2273Found in file sv.c
2a5a0c38 2274
94bdecf9 2275=item newRV_inc
2a5a0c38 2276
94bdecf9
JH
2277Creates an RV wrapper for an SV. The reference count for the original SV is
2278incremented.
2a5a0c38 2279
94bdecf9 2280 SV* newRV_inc(SV* sv)
2a5a0c38
JH
2281
2282=for hackers
94bdecf9 2283Found in file sv.h
2a5a0c38 2284
94bdecf9 2285=item newRV_noinc
954c1994 2286
94bdecf9
JH
2287Creates an RV wrapper for an SV. The reference count for the original
2288SV is B<not> incremented.
2289
2290 SV* newRV_noinc(SV *sv)
954c1994 2291
497711e7 2292=for hackers
94bdecf9 2293Found in file sv.c
497711e7 2294
94bdecf9 2295=item newSV
954c1994 2296
94bdecf9
JH
2297Create a new null SV, or if len > 0, create a new empty SVt_PV type SV
2298with an initial PV allocation of len+1. Normally accessed via the C<NEWSV>
2299macro.
954c1994 2300
94bdecf9 2301 SV* newSV(STRLEN len)
954c1994 2302
497711e7 2303=for hackers
94bdecf9 2304Found in file sv.c
497711e7 2305
94bdecf9 2306=item newSViv
954c1994 2307
94bdecf9
JH
2308Creates a new SV and copies an integer into it. The reference count for the
2309SV is set to 1.
954c1994 2310
94bdecf9 2311 SV* newSViv(IV i)
954c1994 2312
497711e7 2313=for hackers
94bdecf9 2314Found in file sv.c
497711e7 2315
94bdecf9 2316=item newSVnv
954c1994 2317
94bdecf9
JH
2318Creates a new SV and copies a floating point value into it.
2319The reference count for the SV is set to 1.
954c1994 2320
94bdecf9 2321 SV* newSVnv(NV n)
954c1994 2322
497711e7 2323=for hackers
94bdecf9 2324Found in file sv.c
497711e7 2325
94bdecf9 2326=item newSVpv
954c1994 2327
94bdecf9
JH
2328Creates a new SV and copies a string into it. The reference count for the
2329SV is set to 1. If C<len> is zero, Perl will compute the length using
2330strlen(). For efficiency, consider using C<newSVpvn> instead.
954c1994 2331
94bdecf9 2332 SV* newSVpv(const char* s, STRLEN len)
954c1994 2333
497711e7 2334=for hackers
94bdecf9 2335Found in file sv.c
497711e7 2336
94bdecf9 2337=item newSVpvf
954c1994 2338
94bdecf9
JH
2339Creates a new SV and initializes it with the string formatted like
2340C<sprintf>.
954c1994 2341
94bdecf9 2342 SV* newSVpvf(const char* pat, ...)
954c1994 2343
497711e7 2344=for hackers
94bdecf9 2345Found in file sv.c
497711e7 2346
94bdecf9 2347=item newSVpvn
954c1994 2348
94bdecf9
JH
2349Creates a new SV and copies a string into it. The reference count for the
2350SV is set to 1. Note that if C<len> is zero, Perl will create a zero length
2351string. You are responsible for ensuring that the source string is at least
2352C<len> bytes long.
954c1994 2353
94bdecf9 2354 SV* newSVpvn(const char* s, STRLEN len)
954c1994 2355
497711e7 2356=for hackers
94bdecf9 2357Found in file sv.c
497711e7 2358
94bdecf9 2359=item newSVpvn_share
954c1994 2360
94bdecf9
JH
2361Creates a new SV with its SvPVX pointing to a shared string in the string
2362table. If the string does not already exist in the table, it is created
2363first. Turns on READONLY and FAKE. The string's hash is stored in the UV
2364slot of the SV; if the C<hash> parameter is non-zero, that value is used;
2365otherwise the hash is computed. The idea here is that as the string table
2366is used for shared hash keys these strings will have SvPVX == HeKEY and
2367hash lookup will avoid string compare.
954c1994 2368
94bdecf9 2369 SV* newSVpvn_share(const char* s, I32 len, U32 hash)
954c1994 2370
497711e7 2371=for hackers
94bdecf9 2372Found in file sv.c
497711e7 2373
94bdecf9 2374=item newSVrv
954c1994 2375
94bdecf9
JH
2376Creates a new SV for the RV, C<rv>, to point to. If C<rv> is not an RV then
2377it will be upgraded to one. If C<classname> is non-null then the new SV will
2378be blessed in the specified package. The new SV is returned and its
2379reference count is 1.
954c1994 2380
94bdecf9 2381 SV* newSVrv(SV* rv, const char* classname)
954c1994 2382
497711e7 2383=for hackers
94bdecf9 2384Found in file sv.c
497711e7 2385
94bdecf9 2386=item newSVsv
954c1994 2387
94bdecf9
JH
2388Creates a new SV which is an exact duplicate of the original SV.
2389(Uses C<sv_setsv>).
954c1994 2390
94bdecf9 2391 SV* newSVsv(SV* old)
954c1994 2392
497711e7 2393=for hackers
94bdecf9 2394Found in file sv.c
497711e7 2395
94bdecf9 2396=item newSVuv
954c1994 2397
94bdecf9
JH
2398Creates a new SV and copies an unsigned integer into it.
2399The reference count for the SV is set to 1.
954c1994 2400
94bdecf9 2401 SV* newSVuv(UV u)
954c1994 2402
497711e7 2403=for hackers
94bdecf9 2404Found in file sv.c
497711e7 2405
94bdecf9 2406=item new_vstring
954c1994 2407
94bdecf9
JH
2408Returns a pointer to the next character after the parsed
2409vstring, as well as updating the passed in sv.
954c1994 2410
94bdecf9
JH
2411Function must be called like
2412
2413 sv = NEWSV(92,5);
2414 s = new_vstring(s,sv);
2415
2416The sv must already be large enough to store the vstring
2417passed in.
2418
2419 char* new_vstring(char *vstr, SV *sv)
954c1994 2420
497711e7 2421=for hackers
94bdecf9 2422Found in file util.c
497711e7 2423
954c1994
GS
2424=item SvCUR
2425
2426Returns the length of the string which is in the SV. See C<SvLEN>.
2427
2428 STRLEN SvCUR(SV* sv)
2429
497711e7
GS
2430=for hackers
2431Found in file sv.h
2432
954c1994
GS
2433=item SvCUR_set
2434
2435Set the length of the string which is in the SV. See C<SvCUR>.
2436
2437 void SvCUR_set(SV* sv, STRLEN len)
2438
497711e7
GS
2439=for hackers
2440Found in file sv.h
2441
94bdecf9 2442=item SvEND
954c1994 2443
94bdecf9
JH
2444Returns a pointer to the last character in the string which is in the SV.
2445See C<SvCUR>. Access the character as *(SvEND(sv)).
954c1994 2446
94bdecf9 2447 char* SvEND(SV* sv)
954c1994 2448
497711e7
GS
2449=for hackers
2450Found in file sv.h
2451
954c1994
GS
2452=item SvGROW
2453
2454Expands the character buffer in the SV so that it has room for the
2455indicated number of bytes (remember to reserve space for an extra trailing
8cf8f3d1 2456NUL character). Calls C<sv_grow> to perform the expansion if necessary.
954c1994
GS
2457Returns a pointer to the character buffer.
2458
679ac26e 2459 char * SvGROW(SV* sv, STRLEN len)
954c1994 2460
497711e7
GS
2461=for hackers
2462Found in file sv.h
2463
954c1994
GS
2464=item SvIOK
2465
2466Returns a boolean indicating whether the SV contains an integer.
2467
2468 bool SvIOK(SV* sv)
2469
497711e7
GS
2470=for hackers
2471Found in file sv.h
2472
954c1994
GS
2473=item SvIOKp
2474
2475Returns a boolean indicating whether the SV contains an integer. Checks
2476the B<private> setting. Use C<SvIOK>.
2477
2478 bool SvIOKp(SV* sv)
2479
497711e7
GS
2480=for hackers
2481Found in file sv.h
2482
e331fc52
JH
2483=item SvIOK_notUV
2484
f4758303 2485Returns a boolean indicating whether the SV contains a signed integer.
e331fc52
JH
2486
2487 void SvIOK_notUV(SV* sv)
2488
2489=for hackers
2490Found in file sv.h
2491
954c1994
GS
2492=item SvIOK_off
2493
2494Unsets the IV status of an SV.
2495
2496 void SvIOK_off(SV* sv)
2497
497711e7
GS
2498=for hackers
2499Found in file sv.h
2500
954c1994
GS
2501=item SvIOK_on
2502
2503Tells an SV that it is an integer.
2504
2505 void SvIOK_on(SV* sv)
2506
497711e7
GS
2507=for hackers
2508Found in file sv.h
2509
954c1994
GS
2510=item SvIOK_only
2511
2512Tells an SV that it is an integer and disables all other OK bits.
2513
2514 void SvIOK_only(SV* sv)
2515
497711e7
GS
2516=for hackers
2517Found in file sv.h
2518
e331fc52
JH
2519=item SvIOK_only_UV
2520
2521Tells and SV that it is an unsigned integer and disables all other OK bits.
2522
2523 void SvIOK_only_UV(SV* sv)
2524
2525=for hackers
2526Found in file sv.h
2527
2528=item SvIOK_UV
2529
2530Returns a boolean indicating whether the SV contains an unsigned integer.
2531
2532 void SvIOK_UV(SV* sv)
2533
2534=for hackers
2535Found in file sv.h
2536
954c1994
GS
2537=item SvIV
2538
645c22ef
DM
2539Coerces the given SV to an integer and returns it. See C<SvIVx> for a
2540version which guarantees to evaluate sv only once.
954c1994
GS
2541
2542 IV SvIV(SV* sv)
2543
497711e7
GS
2544=for hackers
2545Found in file sv.h
2546
12b7c5c7 2547=item SvIVX
954c1994 2548
12b7c5c7
JH
2549Returns the raw value in the SV's IV slot, without checks or conversions.
2550Only use when you are sure SvIOK is true. See also C<SvIV()>.
954c1994 2551
12b7c5c7 2552 IV SvIVX(SV* sv)
954c1994 2553
497711e7
GS
2554=for hackers
2555Found in file sv.h
2556
12b7c5c7 2557=item SvIVx
645c22ef 2558
12b7c5c7
JH
2559Coerces the given SV to an integer and returns it. Guarantees to evaluate
2560sv only once. Use the more efficient C<SvIV> otherwise.
645c22ef 2561
12b7c5c7 2562 IV SvIVx(SV* sv)
645c22ef
DM
2563
2564=for hackers
2565Found in file sv.h
2566
954c1994
GS
2567=item SvLEN
2568
91e74348
JH
2569Returns the size of the string buffer in the SV, not including any part
2570attributable to C<SvOOK>. See C<SvCUR>.
954c1994
GS
2571
2572 STRLEN SvLEN(SV* sv)
2573
497711e7
GS
2574=for hackers
2575Found in file sv.h
2576
954c1994
GS
2577=item SvNIOK
2578
2579Returns a boolean indicating whether the SV contains a number, integer or
2580double.
2581
2582 bool SvNIOK(SV* sv)
2583
497711e7
GS
2584=for hackers
2585Found in file sv.h
2586
954c1994
GS
2587=item SvNIOKp
2588
2589Returns a boolean indicating whether the SV contains a number, integer or
2590double. Checks the B<private> setting. Use C<SvNIOK>.
2591
2592 bool SvNIOKp(SV* sv)
2593
497711e7
GS
2594=for hackers
2595Found in file sv.h
2596
954c1994
GS
2597=item SvNIOK_off
2598
2599Unsets the NV/IV status of an SV.
2600
2601 void SvNIOK_off(SV* sv)
2602
497711e7
GS
2603=for hackers
2604Found in file sv.h
2605
954c1994
GS
2606=item SvNOK
2607
2608Returns a boolean indicating whether the SV contains a double.
2609
2610 bool SvNOK(SV* sv)
2611
497711e7
GS
2612=for hackers
2613Found in file sv.h
2614
954c1994
GS
2615=item SvNOKp
2616
2617Returns a boolean indicating whether the SV contains a double. Checks the
2618B<private> setting. Use C<SvNOK>.
2619
2620 bool SvNOKp(SV* sv)
2621
497711e7
GS
2622=for hackers
2623Found in file sv.h
2624
954c1994
GS
2625=item SvNOK_off
2626
2627Unsets the NV status of an SV.
2628
2629 void SvNOK_off(SV* sv)
2630
497711e7
GS
2631=for hackers
2632Found in file sv.h
2633
954c1994
GS
2634=item SvNOK_on
2635
2636Tells an SV that it is a double.
2637
2638 void SvNOK_on(SV* sv)
2639
497711e7
GS
2640=for hackers
2641Found in file sv.h
2642
954c1994
GS
2643=item SvNOK_only
2644
2645Tells an SV that it is a double and disables all other OK bits.
2646
2647 void SvNOK_only(SV* sv)
2648
497711e7
GS
2649=for hackers
2650Found in file sv.h
2651
954c1994
GS
2652=item SvNV
2653
645c22ef
DM
2654Coerce the given SV to a double and return it. See C<SvNVx> for a version
2655which guarantees to evaluate sv only once.
954c1994
GS
2656
2657 NV SvNV(SV* sv)
2658
497711e7
GS
2659=for hackers
2660Found in file sv.h
2661
12b7c5c7 2662=item SvNVx
645c22ef 2663
12b7c5c7
JH
2664Coerces the given SV to a double and returns it. Guarantees to evaluate
2665sv only once. Use the more efficient C<SvNV> otherwise.
645c22ef 2666
12b7c5c7 2667 NV SvNVx(SV* sv)
645c22ef
DM
2668
2669=for hackers
2670Found in file sv.h
2671
12b7c5c7 2672=item SvNVX
954c1994 2673
12b7c5c7
JH
2674Returns the raw value in the SV's NV slot, without checks or conversions.
2675Only use when you are sure SvNOK is true. See also C<SvNV()>.
954c1994 2676
12b7c5c7 2677 NV SvNVX(SV* sv)
954c1994 2678
497711e7
GS
2679=for hackers
2680Found in file sv.h
2681
954c1994
GS
2682=item SvOK
2683
2684Returns a boolean indicating whether the value is an SV.
2685
2686 bool SvOK(SV* sv)
2687
497711e7
GS
2688=for hackers
2689Found in file sv.h
2690
954c1994
GS
2691=item SvOOK
2692
2693Returns a boolean indicating whether the SvIVX is a valid offset value for
2694the SvPVX. This hack is used internally to speed up removal of characters
2695from the beginning of a SvPV. When SvOOK is true, then the start of the
2696allocated string buffer is really (SvPVX - SvIVX).
2697
2698 bool SvOOK(SV* sv)
2699
497711e7
GS
2700=for hackers
2701Found in file sv.h
2702
954c1994
GS
2703=item SvPOK
2704
2705Returns a boolean indicating whether the SV contains a character
2706string.
2707
2708 bool SvPOK(SV* sv)
2709
497711e7
GS
2710=for hackers
2711Found in file sv.h
2712
954c1994
GS
2713=item SvPOKp
2714
2715Returns a boolean indicating whether the SV contains a character string.
2716Checks the B<private> setting. Use C<SvPOK>.
2717
2718 bool SvPOKp(SV* sv)
2719
497711e7
GS
2720=for hackers
2721Found in file sv.h
2722
954c1994
GS
2723=item SvPOK_off
2724
2725Unsets the PV status of an SV.
2726
2727 void SvPOK_off(SV* sv)
2728
497711e7
GS
2729=for hackers
2730Found in file sv.h
2731
954c1994
GS
2732=item SvPOK_on
2733
2734Tells an SV that it is a string.
2735
2736 void SvPOK_on(SV* sv)
2737
497711e7
GS
2738=for hackers
2739Found in file sv.h
2740
954c1994
GS
2741=item SvPOK_only
2742
2743Tells an SV that it is a string and disables all other OK bits.
d5ce4a7c 2744Will also turn off the UTF8 status.
954c1994
GS
2745
2746 void SvPOK_only(SV* sv)
2747
497711e7
GS
2748=for hackers
2749Found in file sv.h
2750
914184e1
JH
2751=item SvPOK_only_UTF8
2752
d5ce4a7c
GA
2753Tells an SV that it is a string and disables all other OK bits,
2754and leaves the UTF8 status as it was.
f1a1024e 2755
914184e1
JH
2756 void SvPOK_only_UTF8(SV* sv)
2757
2758=for hackers
2759Found in file sv.h
2760
954c1994
GS
2761=item SvPV
2762
12b7c5c7
JH
2763Returns a pointer to the string in the SV, or a stringified form of
2764the SV if the SV does not contain a string. The SV may cache the
2765stringified version becoming C<SvPOK>. Handles 'get' magic. See also
645c22ef 2766C<SvPVx> for a version which guarantees to evaluate sv only once.
954c1994
GS
2767
2768 char* SvPV(SV* sv, STRLEN len)
2769
497711e7
GS
2770=for hackers
2771Found in file sv.h
2772
645c22ef
DM
2773=item SvPVbyte
2774
2775Like C<SvPV>, but converts sv to byte representation first if necessary.
2776
2777 char* SvPVbyte(SV* sv, STRLEN len)
2778
2779=for hackers
2780Found in file sv.h
2781
2782=item SvPVbytex
2783
2784Like C<SvPV>, but converts sv to byte representation first if necessary.
d1be9408 2785Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>
645c22ef
DM
2786otherwise.
2787
2788
2789 char* SvPVbytex(SV* sv, STRLEN len)
2790
2791=for hackers
2792Found in file sv.h
2793
2794=item SvPVbytex_force
2795
2796Like C<SvPV_force>, but converts sv to byte representation first if necessary.
d1be9408 2797Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>
645c22ef
DM
2798otherwise.
2799
2800 char* SvPVbytex_force(SV* sv, STRLEN len)
2801
2802=for hackers
2803Found in file sv.h
2804
2805=item SvPVbyte_force
2806
2807Like C<SvPV_force>, but converts sv to byte representation first if necessary.
2808
2809 char* SvPVbyte_force(SV* sv, STRLEN len)
2810
2811=for hackers
2812Found in file sv.h
2813
2814=item SvPVbyte_nolen
2815
2816Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
2817
1fdc5aa6 2818 char* SvPVbyte_nolen(SV* sv)
645c22ef
DM
2819
2820=for hackers
2821Found in file sv.h
2822
2823=item SvPVutf8
2824
1fdc5aa6 2825Like C<SvPV>, but converts sv to utf8 first if necessary.
645c22ef
DM
2826
2827 char* SvPVutf8(SV* sv, STRLEN len)
2828
2829=for hackers
2830Found in file sv.h
2831
2832=item SvPVutf8x
2833
1fdc5aa6 2834Like C<SvPV>, but converts sv to utf8 first if necessary.
d1be9408 2835Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>
645c22ef
DM
2836otherwise.
2837
2838 char* SvPVutf8x(SV* sv, STRLEN len)
2839
2840=for hackers
2841Found in file sv.h
2842
2843=item SvPVutf8x_force
2844
1fdc5aa6 2845Like C<SvPV_force>, but converts sv to utf8 first if necessary.
d1be9408 2846Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>
645c22ef
DM
2847otherwise.
2848
2849 char* SvPVutf8x_force(SV* sv, STRLEN len)
2850
2851=for hackers
2852Found in file sv.h
2853
2854=item SvPVutf8_force
2855
1fdc5aa6 2856Like C<SvPV_force>, but converts sv to utf8 first if necessary.
645c22ef
DM
2857
2858 char* SvPVutf8_force(SV* sv, STRLEN len)
2859
2860=for hackers
2861Found in file sv.h
2862
2863=item SvPVutf8_nolen
2864
1fdc5aa6 2865Like C<SvPV_nolen>, but converts sv to utf8 first if necessary.
645c22ef 2866
1fdc5aa6 2867 char* SvPVutf8_nolen(SV* sv)
645c22ef
DM
2868
2869=for hackers
2870Found in file sv.h
2871
12b7c5c7 2872=item SvPVX
645c22ef 2873
12b7c5c7
JH
2874Returns a pointer to the physical string in the SV. The SV must contain a
2875string.
645c22ef 2876
12b7c5c7 2877 char* SvPVX(SV* sv)
645c22ef
DM
2878
2879=for hackers
2880Found in file sv.h
2881
12b7c5c7 2882=item SvPVx
954c1994 2883
12b7c5c7 2884A version of C<SvPV> which guarantees to evaluate sv only once.
954c1994 2885
12b7c5c7 2886 char* SvPVx(SV* sv, STRLEN len)
954c1994 2887
497711e7
GS
2888=for hackers
2889Found in file sv.h
2890
954c1994
GS
2891=item SvPV_force
2892
12b7c5c7
JH
2893Like C<SvPV> but will force the SV into containing just a string
2894(C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
2895directly.
954c1994
GS
2896
2897 char* SvPV_force(SV* sv, STRLEN len)
2898
497711e7
GS
2899=for hackers
2900Found in file sv.h
2901
645c22ef
DM
2902=item SvPV_force_nomg
2903
12b7c5c7
JH
2904Like C<SvPV> but will force the SV into containing just a string
2905(C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
2906directly. Doesn't process magic.
645c22ef
DM
2907
2908 char* SvPV_force_nomg(SV* sv, STRLEN len)
2909
2910=for hackers
2911Found in file sv.h
2912
954c1994
GS
2913=item SvPV_nolen
2914
12b7c5c7
JH
2915Returns a pointer to the string in the SV, or a stringified form of
2916the SV if the SV does not contain a string. The SV may cache the
2917stringified form becoming C<SvPOK>. Handles 'get' magic.
954c1994
GS
2918
2919 char* SvPV_nolen(SV* sv)
2920
497711e7
GS
2921=for hackers
2922Found in file sv.h
2923
954c1994
GS
2924=item SvREFCNT
2925
2926Returns the value of the object's reference count.
2927
2928 U32 SvREFCNT(SV* sv)
2929
497711e7
GS
2930=for hackers
2931Found in file sv.h
2932
954c1994
GS
2933=item SvREFCNT_dec
2934
2935Decrements the reference count of the given SV.
2936
2937 void SvREFCNT_dec(SV* sv)
2938
497711e7
GS
2939=for hackers
2940Found in file sv.h
2941
954c1994
GS
2942=item SvREFCNT_inc
2943
2944Increments the reference count of the given SV.
2945
2946 SV* SvREFCNT_inc(SV* sv)
2947
497711e7
GS
2948=for hackers
2949Found in file sv.h
2950
954c1994
GS
2951=item SvROK
2952
2953Tests if the SV is an RV.
2954
2955 bool SvROK(SV* sv)
2956
497711e7
GS
2957=for hackers
2958Found in file sv.h
2959
954c1994
GS
2960=item SvROK_off
2961
2962Unsets the RV status of an SV.
2963
2964 void SvROK_off(SV* sv)
2965
497711e7
GS
2966=for hackers
2967Found in file sv.h
2968
954c1994
GS
2969=item SvROK_on
2970
2971Tells an SV that it is an RV.
2972
2973 void SvROK_on(SV* sv)
2974
497711e7
GS
2975=for hackers
2976Found in file sv.h
2977
954c1994
GS
2978=item SvRV
2979
2980Dereferences an RV to return the SV.
2981
2982 SV* SvRV(SV* sv)
2983
497711e7
GS
2984=for hackers
2985Found in file sv.h
2986
954c1994
GS
2987=item SvSTASH
2988
2989Returns the stash of the SV.
2990
2991 HV* SvSTASH(SV* sv)
2992
497711e7
GS
2993=for hackers
2994Found in file sv.h
2995
954c1994
GS
2996=item SvTAINT
2997
2998Taints an SV if tainting is enabled
2999
3000 void SvTAINT(SV* sv)
3001
497711e7
GS
3002=for hackers
3003Found in file sv.h
3004
954c1994
GS
3005=item SvTAINTED
3006
3007Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
3008not.
3009
3010 bool SvTAINTED(SV* sv)
3011
497711e7
GS
3012=for hackers
3013Found in file sv.h
3014
954c1994
GS
3015=item SvTAINTED_off
3016
3017Untaints an SV. Be I<very> careful with this routine, as it short-circuits
3018some of Perl's fundamental security features. XS module authors should not
3019use this function unless they fully understand all the implications of
3020unconditionally untainting the value. Untainting should be done in the
3021standard perl fashion, via a carefully crafted regexp, rather than directly
3022untainting variables.
3023
3024 void SvTAINTED_off(SV* sv)
3025
497711e7
GS
3026=for hackers
3027Found in file sv.h
3028
954c1994
GS
3029=item SvTAINTED_on
3030
3031Marks an SV as tainted.
3032
3033 void SvTAINTED_on(SV* sv)
3034
497711e7
GS
3035=for hackers
3036Found in file sv.h
3037
954c1994
GS
3038=item SvTRUE
3039
3040Returns a boolean indicating whether Perl would evaluate the SV as true or
3041false, defined or undefined. Does not handle 'get' magic.
3042
3043 bool SvTRUE(SV* sv)
3044
497711e7
GS
3045=for hackers
3046Found in file sv.h
3047
9f4817db 3048=item SvTYPE
af3c7592 3049
9f4817db
JH
3050Returns the type of the SV. See C<svtype>.
3051
3052 svtype SvTYPE(SV* sv)
954c1994 3053
497711e7
GS
3054=for hackers
3055Found in file sv.h
3056
a4f1a029
NIS
3057=item SvUNLOCK
3058
3059Releases a mutual exclusion lock on sv if a suitable module
3060has been loaded.
3061
3062
3063 void SvUNLOCK(SV* sv)
3064
3065=for hackers
3066Found in file sv.h
3067
a8586c98
JH
3068=item SvUOK
3069
3070Returns a boolean indicating whether the SV contains an unsigned integer.
3071
3072 void SvUOK(SV* sv)
3073
3074=for hackers
3075Found in file sv.h
3076
954c1994
GS
3077=item SvUPGRADE
3078
3079Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
3080perform the upgrade if necessary. See C<svtype>.
3081
3082 void SvUPGRADE(SV* sv, svtype type)
3083
497711e7
GS
3084=for hackers
3085Found in file sv.h
3086
914184e1
JH
3087=item SvUTF8
3088
3089Returns a boolean indicating whether the SV contains UTF-8 encoded data.
3090
3091 void SvUTF8(SV* sv)
3092
3093=for hackers
3094Found in file sv.h
3095
3096=item SvUTF8_off
3097
3098Unsets the UTF8 status of an SV.
3099
3100 void SvUTF8_off(SV *sv)
3101
3102=for hackers
3103Found in file sv.h
3104
3105=item SvUTF8_on
3106
d5ce4a7c
GA
3107Turn on the UTF8 status of an SV (the data is not changed, just the flag).
3108Do not use frivolously.
914184e1
JH
3109
3110 void SvUTF8_on(SV *sv)
3111
3112=for hackers
3113Found in file sv.h
3114
954c1994
GS
3115=item SvUV
3116
645c22ef
DM
3117Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
3118for a version which guarantees to evaluate sv only once.
954c1994
GS
3119
3120 UV SvUV(SV* sv)
3121
497711e7
GS
3122=for hackers
3123Found in file sv.h
3124
a4f1a029 3125=item SvUVX
954c1994 3126
a4f1a029
NIS
3127Returns the raw value in the SV's UV slot, without checks or conversions.
3128Only use when you are sure SvIOK is true. See also C<SvUV()>.
954c1994 3129
a4f1a029 3130 UV SvUVX(SV* sv)
954c1994 3131
497711e7
GS
3132=for hackers
3133Found in file sv.h
3134
a4f1a029 3135=item SvUVx
645c22ef 3136
a4f1a029
NIS
3137Coerces the given SV to an unsigned integer and returns it. Guarantees to
3138evaluate sv only once. Use the more efficient C<SvUV> otherwise.
645c22ef 3139
a4f1a029 3140 UV SvUVx(SV* sv)
645c22ef
DM
3141
3142=for hackers
3143Found in file sv.h
3144
3145=item sv_2bool
3146
3147This function is only called on magical items, and is only used by
8cf8f3d1 3148sv_true() or its macro equivalent.
645c22ef
DM
3149
3150 bool sv_2bool(SV* sv)
3151
3152=for hackers
3153Found in file sv.c
3154
3155=item sv_2cv
3156
3157Using various gambits, try to get a CV from an SV; in addition, try if
3158possible to set C<*st> and C<*gvp> to the stash and GV associated with it.
3159
3160 CV* sv_2cv(SV* sv, HV** st, GV** gvp, I32 lref)
3161
3162=for hackers
3163Found in file sv.c
3164
3165=item sv_2io
3166
3167Using various gambits, try to get an IO from an SV: the IO slot if its a
3168GV; or the recursive result if we're an RV; or the IO slot of the symbol
3169named after the PV if we're a string.
3170
3171 IO* sv_2io(SV* sv)
3172
3173=for hackers
3174Found in file sv.c
3175
3176=item sv_2iv
3177
3178Return the integer value of an SV, doing any necessary string conversion,
3179magic etc. Normally used via the C<SvIV(sv)> and C<SvIVx(sv)> macros.
3180
3181 IV sv_2iv(SV* sv)
3182
3183=for hackers
3184Found in file sv.c
3185
954c1994
GS
3186=item sv_2mortal
3187
793edb8a
JH
3188Marks an existing SV as mortal. The SV will be destroyed "soon", either
3189by an explicit call to FREETMPS, or by an implicit call at places such as
3190statement boundaries. See also C<sv_newmortal> and C<sv_mortalcopy>.
954c1994
GS
3191
3192 SV* sv_2mortal(SV* sv)
3193
497711e7
GS
3194=for hackers
3195Found in file sv.c
3196
645c22ef
DM
3197=item sv_2nv
3198
3199Return the num value of an SV, doing any necessary string or integer
3200conversion, magic etc. Normally used via the C<SvNV(sv)> and C<SvNVx(sv)>
3201macros.
3202
3203 NV sv_2nv(SV* sv)
3204
3205=for hackers
3206Found in file sv.c
3207
451be7b1
DM
3208=item sv_2pvbyte
3209
3210Return a pointer to the byte-encoded representation of the SV, and set *lp
3211to its length. May cause the SV to be downgraded from UTF8 as a
3212side-effect.
3213
3214Usually accessed via the C<SvPVbyte> macro.
3215
3216 char* sv_2pvbyte(SV* sv, STRLEN* lp)
3217
3218=for hackers
3219Found in file sv.c
3220
645c22ef
DM
3221=item sv_2pvbyte_nolen
3222
3223Return a pointer to the byte-encoded representation of the SV.
3224May cause the SV to be downgraded from UTF8 as a side-effect.
3225
3226Usually accessed via the C<SvPVbyte_nolen> macro.
3227
3228 char* sv_2pvbyte_nolen(SV* sv)
3229
3230=for hackers
3231Found in file sv.c
3232
451be7b1
DM
3233=item sv_2pvutf8
3234
3235Return a pointer to the UTF8-encoded representation of the SV, and set *lp
3236to its length. May cause the SV to be upgraded to UTF8 as a side-effect.
3237
3238Usually accessed via the C<SvPVutf8> macro.
3239
3240 char* sv_2pvutf8(SV* sv, STRLEN* lp)
3241
3242=for hackers
3243Found in file sv.c
3244
645c22ef
DM
3245=item sv_2pvutf8_nolen
3246
3247Return a pointer to the UTF8-encoded representation of the SV.
3248May cause the SV to be upgraded to UTF8 as a side-effect.
3249
3250Usually accessed via the C<SvPVutf8_nolen> macro.
3251
3252 char* sv_2pvutf8_nolen(SV* sv)
3253
3254=for hackers
3255Found in file sv.c
3256
3257=item sv_2pv_flags
3258
ff276b08 3259Returns a pointer to the string value of an SV, and sets *lp to its length.
645c22ef
DM
3260If flags includes SV_GMAGIC, does an mg_get() first. Coerces sv to a string
3261if necessary.
3262Normally invoked via the C<SvPV_flags> macro. C<sv_2pv()> and C<sv_2pv_nomg>
3263usually end up here too.
3264
3265 char* sv_2pv_flags(SV* sv, STRLEN* lp, I32 flags)
3266
3267=for hackers
3268Found in file sv.c
3269
3270=item sv_2pv_nolen
3271
3272Like C<sv_2pv()>, but doesn't return the length too. You should usually
3273use the macro wrapper C<SvPV_nolen(sv)> instead.
3274 char* sv_2pv_nolen(SV* sv)
3275
3276=for hackers
3277Found in file sv.c
3278
3279=item sv_2uv
3280
3281Return the unsigned integer value of an SV, doing any necessary string
3282conversion, magic etc. Normally used via the C<SvUV(sv)> and C<SvUVx(sv)>
3283macros.
3284
3285 UV sv_2uv(SV* sv)
3286
3287=for hackers
3288Found in file sv.c
3289
3290=item sv_backoff
3291
3292Remove any string offset. You should normally use the C<SvOOK_off> macro
3293wrapper instead.
3294
3295 int sv_backoff(SV* sv)
3296
3297=for hackers
3298Found in file sv.c
3299
954c1994
GS
3300=item sv_bless
3301
3302Blesses an SV into a specified package. The SV must be an RV. The package
3303must be designated by its stash (see C<gv_stashpv()>). The reference count
3304of the SV is unaffected.
3305
3306 SV* sv_bless(SV* sv, HV* stash)
3307
497711e7
GS
3308=for hackers
3309Found in file sv.c
3310
954c1994
GS
3311=item sv_catpv
3312
3313Concatenates the string onto the end of the string which is in the SV.
d5ce4a7c
GA
3314If the SV has the UTF8 status set, then the bytes appended should be
3315valid UTF8. Handles 'get' magic, but not 'set' magic. See C<sv_catpv_mg>.
954c1994
GS
3316
3317 void sv_catpv(SV* sv, const char* ptr)
3318
497711e7
GS
3319=for hackers
3320Found in file sv.c
3321
954c1994
GS
3322=item sv_catpvf
3323
d5ce4a7c
GA
3324Processes its arguments like C<sprintf> and appends the formatted
3325output to an SV. If the appended data contains "wide" characters
3326(including, but not limited to, SVs with a UTF-8 PV formatted with %s,
3327and characters >255 formatted with %c), the original SV might get
3328upgraded to UTF-8. Handles 'get' magic, but not 'set' magic.
3329C<SvSETMAGIC()> must typically be called after calling this function
3330to handle 'set' magic.
954c1994
GS
3331
3332 void sv_catpvf(SV* sv, const char* pat, ...)
3333
497711e7
GS
3334=for hackers
3335Found in file sv.c
3336
954c1994
GS
3337=item sv_catpvf_mg
3338
3339Like C<sv_catpvf>, but also handles 'set' magic.
3340
3341 void sv_catpvf_mg(SV *sv, const char* pat, ...)
3342
497711e7
GS
3343=for hackers
3344Found in file sv.c
3345
954c1994
GS
3346=item sv_catpvn
3347
3348Concatenates the string onto the end of the string which is in the SV. The
d5ce4a7c
GA
3349C<len> indicates number of bytes to copy. If the SV has the UTF8
3350status set, then the bytes appended should be valid UTF8.
3351Handles 'get' magic, but not 'set' magic. See C<sv_catpvn_mg>.
954c1994
GS
3352
3353 void sv_catpvn(SV* sv, const char* ptr, STRLEN len)
3354
497711e7
GS
3355=for hackers
3356Found in file sv.c
3357
8d6d96c1
HS
3358=item sv_catpvn_flags
3359
3360Concatenates the string onto the end of the string which is in the SV. The
3361C<len> indicates number of bytes to copy. If the SV has the UTF8
3362status set, then the bytes appended should be valid UTF8.
3363If C<flags> has C<SV_GMAGIC> bit set, will C<mg_get> on C<dsv> if
3364appropriate, else not. C<sv_catpvn> and C<sv_catpvn_nomg> are implemented
3365in terms of this function.
3366
3367 void sv_catpvn_flags(SV* sv, const char* ptr, STRLEN len, I32 flags)
3368
3369=for hackers
3370Found in file sv.c
3371
954c1994
GS
3372=item sv_catpvn_mg
3373
3374Like C<sv_catpvn>, but also handles 'set' magic.
3375
3376 void sv_catpvn_mg(SV *sv, const char *ptr, STRLEN len)
3377
497711e7
GS
3378=for hackers
3379Found in file sv.c
3380
954c1994
GS
3381=item sv_catpv_mg
3382
3383Like C<sv_catpv>, but also handles 'set' magic.
3384
3385 void sv_catpv_mg(SV *sv, const char *ptr)
3386
497711e7
GS
3387=for hackers
3388Found in file sv.c
3389
954c1994
GS
3390=item sv_catsv
3391
1aa99e6b
IH
3392Concatenates the string from SV C<ssv> onto the end of the string in
3393SV C<dsv>. Modifies C<dsv> but not C<ssv>. Handles 'get' magic, but
3394not 'set' magic. See C<sv_catsv_mg>.
954c1994
GS
3395
3396 void sv_catsv(SV* dsv, SV* ssv)
3397
497711e7
GS
3398=for hackers
3399Found in file sv.c
3400
8d6d96c1
HS
3401=item sv_catsv_flags
3402
3403Concatenates the string from SV C<ssv> onto the end of the string in
3404SV C<dsv>. Modifies C<dsv> but not C<ssv>. If C<flags> has C<SV_GMAGIC>
3405bit set, will C<mg_get> on the SVs if appropriate, else not. C<sv_catsv>
3406and C<sv_catsv_nomg> are implemented in terms of this function.
3407
3408 void sv_catsv_flags(SV* dsv, SV* ssv, I32 flags)
3409
3410=for hackers
3411Found in file sv.c
3412
954c1994
GS
3413=item sv_catsv_mg
3414
3415Like C<sv_catsv>, but also handles 'set' magic.
3416
3417 void sv_catsv_mg(SV *dstr, SV *sstr)
3418
497711e7
GS
3419=for hackers
3420Found in file sv.c
3421
954c1994
GS
3422=item sv_chop
3423
1c846c1f 3424Efficient removal of characters from the beginning of the string buffer.
954c1994
GS
3425SvPOK(sv) must be true and the C<ptr> must be a pointer to somewhere inside
3426the string buffer. The C<ptr> becomes the first character of the adjusted
645c22ef 3427string. Uses the "OOK hack".
954c1994
GS
3428
3429 void sv_chop(SV* sv, char* ptr)
3430
497711e7
GS
3431=for hackers
3432Found in file sv.c
3433
c461cf8f
JH
3434=item sv_clear
3435
645c22ef
DM
3436Clear an SV: call any destructors, free up any memory used by the body,
3437and free the body itself. The SV's head is I<not> freed, although
3438its type is set to all 1's so that it won't inadvertently be assumed
3439to be live during global destruction etc.
3440This function should only be called when REFCNT is zero. Most of the time
3441you'll want to call C<sv_free()> (or its macro wrapper C<SvREFCNT_dec>)
3442instead.
c461cf8f
JH
3443
3444 void sv_clear(SV* sv)
3445
3446=for hackers
3447Found in file sv.c
3448
954c1994
GS
3449=item sv_cmp
3450
3451Compares the strings in two SVs. Returns -1, 0, or 1 indicating whether the
3452string in C<sv1> is less than, equal to, or greater than the string in
645c22ef
DM
3453C<sv2>. Is UTF-8 and 'use bytes' aware, handles get magic, and will
3454coerce its args to strings if necessary. See also C<sv_cmp_locale>.
954c1994
GS
3455
3456 I32 sv_cmp(SV* sv1, SV* sv2)
3457
497711e7
GS
3458=for hackers
3459Found in file sv.c
3460
c461cf8f
JH
3461=item sv_cmp_locale
3462
645c22ef
DM
3463Compares the strings in two SVs in a locale-aware manner. Is UTF-8 and
3464'use bytes' aware, handles get magic, and will coerce its args to strings
3465if necessary. See also C<sv_cmp_locale>. See also C<sv_cmp>.
c461cf8f
JH
3466
3467 I32 sv_cmp_locale(SV* sv1, SV* sv2)
3468
3469=for hackers
3470Found in file sv.c
3471
645c22ef
DM
3472=item sv_collxfrm
3473
3474Add Collate Transform magic to an SV if it doesn't already have it.
3475
3476Any scalar variable may carry PERL_MAGIC_collxfrm magic that contains the
3477scalar data of the variable, but transformed to such a format that a normal
3478memory comparison can be used to compare the data according to the locale
3479settings.
3480
3481 char* sv_collxfrm(SV* sv, STRLEN* nxp)