This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline
[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
94bdecf9 1269=item SvSETMAGIC
7d3fb230 1270
94bdecf9
JH
1271Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
1272argument more than once.
7d3fb230 1273
94bdecf9 1274 void SvSETMAGIC(SV* sv)
7d3fb230
BS
1275
1276=for hackers
94bdecf9 1277Found in file sv.h
7d3fb230 1278
94bdecf9 1279=item SvSetMagicSV
954c1994 1280
94bdecf9 1281Like C<SvSetSV>, but does any set magic required afterwards.
954c1994 1282
94bdecf9 1283 void SvSetMagicSV(SV* dsb, SV* ssv)
954c1994 1284
497711e7 1285=for hackers
94bdecf9 1286Found in file sv.h
497711e7 1287
94bdecf9 1288=item SvSetSV
954c1994 1289
94bdecf9
JH
1290Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
1291more than once.
1292
1293 void SvSetSV(SV* dsb, SV* ssv)
954c1994 1294
497711e7 1295=for hackers
94bdecf9 1296Found in file sv.h
497711e7 1297
94bdecf9 1298=item SvSetSV_nosteal
954c1994 1299
94bdecf9
JH
1300Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
1301ssv. May evaluate arguments more than once.
954c1994 1302
94bdecf9 1303 void SvSetSV_nosteal(SV* dsv, SV* ssv)
954c1994 1304
497711e7 1305=for hackers
94bdecf9 1306Found in file sv.h
497711e7 1307
954c1994 1308
94bdecf9 1309=back
954c1994 1310
94bdecf9 1311=head1 Memory Management
954c1994 1312
94bdecf9 1313=over 8
497711e7 1314
94bdecf9 1315=item Copy
954c1994 1316
94bdecf9
JH
1317The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the
1318source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
1319the type. May fail on overlapping copies. See also C<Move>.
954c1994 1320
94bdecf9 1321 void Copy(void* src, void* dest, int nitems, type)
954c1994 1322
497711e7 1323=for hackers
94bdecf9 1324Found in file handy.h
497711e7 1325
94bdecf9 1326=item Move
954c1994 1327
94bdecf9
JH
1328The XSUB-writer's interface to the C C<memmove> function. The C<src> is the
1329source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
1330the type. Can do overlapping moves. See also C<Copy>.
954c1994 1331
94bdecf9 1332 void Move(void* src, void* dest, int nitems, type)
954c1994 1333
497711e7 1334=for hackers
94bdecf9 1335Found in file handy.h
497711e7 1336
94bdecf9 1337=item New
954c1994 1338
94bdecf9 1339The XSUB-writer's interface to the C C<malloc> function.
954c1994 1340
94bdecf9 1341 void New(int id, void* ptr, int nitems, type)
954c1994 1342
497711e7 1343=for hackers
94bdecf9 1344Found in file handy.h
497711e7 1345
94bdecf9 1346=item Newc
954c1994 1347
94bdecf9
JH
1348The XSUB-writer's interface to the C C<malloc> function, with
1349cast.
954c1994 1350
94bdecf9 1351 void Newc(int id, void* ptr, int nitems, type, cast)
954c1994 1352
497711e7 1353=for hackers
94bdecf9 1354Found in file handy.h
954c1994 1355
94bdecf9 1356=item NEWSV
497711e7 1357
94bdecf9
JH
1358Creates a new SV. A non-zero C<len> parameter indicates the number of
1359bytes of preallocated string space the SV should have. An extra byte for a
1360tailing NUL is also reserved. (SvPOK is not set for the SV even if string
1361space is allocated.) The reference count for the new SV is set to 1.
1362C<id> is an integer id between 0 and 1299 (used to identify leaks).
954c1994 1363
954c1994 1364
94bdecf9 1365 SV* NEWSV(int id, STRLEN len)
954c1994 1366
497711e7 1367=for hackers
94bdecf9 1368Found in file handy.h
497711e7 1369
94bdecf9 1370=item Newz
954c1994 1371
94bdecf9
JH
1372The XSUB-writer's interface to the C C<malloc> function. The allocated
1373memory is zeroed with C<memzero>.
954c1994 1374
94bdecf9 1375 void Newz(int id, void* ptr, int nitems, type)
954c1994 1376
497711e7
GS
1377=for hackers
1378Found in file handy.h
1379
94bdecf9 1380=item Renew
954c1994 1381
94bdecf9 1382The XSUB-writer's interface to the C C<realloc> function.
954c1994 1383
94bdecf9 1384 void Renew(void* ptr, int nitems, type)
954c1994 1385
497711e7
GS
1386=for hackers
1387Found in file handy.h
1388
94bdecf9 1389=item Renewc
954c1994 1390
94bdecf9
JH
1391The XSUB-writer's interface to the C C<realloc> function, with
1392cast.
954c1994 1393
94bdecf9 1394 void Renewc(void* ptr, int nitems, type, cast)
954c1994 1395
497711e7 1396=for hackers
94bdecf9 1397Found in file handy.h
497711e7 1398
94bdecf9 1399=item Safefree
954c1994 1400
94bdecf9 1401The XSUB-writer's interface to the C C<free> function.
954c1994 1402
94bdecf9 1403 void Safefree(void* ptr)
954c1994 1404
497711e7
GS
1405=for hackers
1406Found in file handy.h
1407
94bdecf9 1408=item savepv
954c1994 1409
94bdecf9 1410Copy a string to a safe spot. This does not use an SV.
954c1994 1411
94bdecf9 1412 char* savepv(const char* sv)
954c1994 1413
497711e7 1414=for hackers
94bdecf9 1415Found in file util.c
497711e7 1416
94bdecf9 1417=item savepvn
954c1994 1418
94bdecf9
JH
1419Copy a string to a safe spot. The C<len> indicates number of bytes to
1420copy. This does not use an SV.
954c1994 1421
94bdecf9 1422 char* savepvn(const char* sv, I32 len)
954c1994 1423
497711e7 1424=for hackers
94bdecf9 1425Found in file util.c
497711e7 1426
94bdecf9 1427=item StructCopy
954c1994 1428
94bdecf9 1429This is an architecture-independent macro to copy one structure to another.
954c1994 1430
94bdecf9 1431 void StructCopy(type src, type dest, type)
954c1994 1432
497711e7 1433=for hackers
94bdecf9 1434Found in file handy.h
497711e7 1435
94bdecf9 1436=item Zero
954c1994 1437
94bdecf9
JH
1438The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the
1439destination, C<nitems> is the number of items, and C<type> is the type.
954c1994 1440
94bdecf9 1441 void Zero(void* dest, int nitems, type)
954c1994 1442
497711e7 1443=for hackers
94bdecf9 1444Found in file handy.h
497711e7 1445
954c1994 1446
94bdecf9 1447=back
954c1994 1448
94bdecf9 1449=head1 Miscellaneous Functions
954c1994 1450
94bdecf9 1451=over 8
497711e7 1452
94bdecf9 1453=item fbm_compile
8b4ac5a4 1454
94bdecf9
JH
1455Analyses the string in order to make fast searches on it using fbm_instr()
1456-- the Boyer-Moore algorithm.
8b4ac5a4 1457
94bdecf9 1458 void fbm_compile(SV* sv, U32 flags)
8b4ac5a4
JH
1459
1460=for hackers
94bdecf9 1461Found in file util.c
8b4ac5a4 1462
94bdecf9 1463=item fbm_instr
954c1994 1464
94bdecf9
JH
1465Returns the location of the SV in the string delimited by C<str> and
1466C<strend>. It returns C<Nullch> if the string can't be found. The C<sv>
1467does not have to be fbm_compiled, but the search will not be as fast
1468then.
954c1994 1469
94bdecf9 1470 char* fbm_instr(unsigned char* big, unsigned char* bigend, SV* littlesv, U32 flags)
954c1994 1471
497711e7 1472=for hackers
94bdecf9 1473Found in file util.c
497711e7 1474
94bdecf9 1475=item form
954c1994 1476
94bdecf9
JH
1477Takes a sprintf-style format pattern and conventional
1478(non-SV) arguments and returns the formatted string.
954c1994 1479
94bdecf9 1480 (char *) Perl_form(pTHX_ const char* pat, ...)
954c1994 1481
94bdecf9 1482can be used any place a string (char *) is required:
497711e7 1483
94bdecf9 1484 char * s = Perl_form("%d.%d",major,minor);
954c1994 1485
94bdecf9
JH
1486Uses a single private buffer so if you want to format several strings you
1487must explicitly copy the earlier strings away (and free the copies when you
1488are done).
954c1994 1489
94bdecf9 1490 char* form(const char* pat, ...)
954c1994 1491
497711e7 1492=for hackers
94bdecf9 1493Found in file util.c
497711e7 1494
94bdecf9 1495=item getcwd_sv
954c1994 1496
94bdecf9 1497Fill the sv with current working directory
954c1994 1498
94bdecf9 1499 int getcwd_sv(SV* sv)
954c1994 1500
497711e7 1501=for hackers
94bdecf9 1502Found in file util.c
497711e7 1503
94bdecf9 1504=item strEQ
954c1994 1505
94bdecf9 1506Test two strings to see if they are equal. Returns true or false.
954c1994 1507
94bdecf9 1508 bool strEQ(char* s1, char* s2)
954c1994 1509
497711e7 1510=for hackers
94bdecf9 1511Found in file handy.h
497711e7 1512
94bdecf9 1513=item strGE
1c846c1f 1514
94bdecf9
JH
1515Test two strings to see if the first, C<s1>, is greater than or equal to
1516the second, C<s2>. Returns true or false.
1c846c1f 1517
94bdecf9 1518 bool strGE(char* s1, char* s2)
1c846c1f
NIS
1519
1520=for hackers
94bdecf9 1521Found in file handy.h
1c846c1f 1522
94bdecf9 1523=item strGT
954c1994 1524
94bdecf9
JH
1525Test two strings to see if the first, C<s1>, is greater than the second,
1526C<s2>. Returns true or false.
954c1994 1527
94bdecf9 1528 bool strGT(char* s1, char* s2)
954c1994 1529
497711e7 1530=for hackers
94bdecf9 1531Found in file handy.h
497711e7 1532
94bdecf9 1533=item strLE
954c1994 1534
94bdecf9
JH
1535Test two strings to see if the first, C<s1>, is less than or equal to the
1536second, C<s2>. Returns true or false.
954c1994 1537
94bdecf9 1538 bool strLE(char* s1, char* s2)
954c1994 1539
497711e7 1540=for hackers
94bdecf9 1541Found in file handy.h
497711e7 1542
94bdecf9 1543=item strLT
1a3327fb 1544
94bdecf9
JH
1545Test two strings to see if the first, C<s1>, is less than the second,
1546C<s2>. Returns true or false.
1a3327fb 1547
94bdecf9 1548 bool strLT(char* s1, char* s2)
1a3327fb 1549
497711e7 1550=for hackers
94bdecf9 1551Found in file handy.h
497711e7 1552
94bdecf9 1553=item strNE
954c1994 1554
94bdecf9
JH
1555Test two strings to see if they are different. Returns true or
1556false.
1557
1558 bool strNE(char* s1, char* s2)
954c1994 1559
497711e7 1560=for hackers
94bdecf9 1561Found in file handy.h
497711e7 1562
94bdecf9 1563=item strnEQ
954c1994 1564
94bdecf9
JH
1565Test two strings to see if they are equal. The C<len> parameter indicates
1566the number of bytes to compare. Returns true or false. (A wrapper for
1567C<strncmp>).
1568
1569 bool strnEQ(char* s1, char* s2, STRLEN len)
954c1994 1570
497711e7 1571=for hackers
94bdecf9 1572Found in file handy.h
497711e7 1573
94bdecf9 1574=item strnNE
954c1994 1575
94bdecf9
JH
1576Test two strings to see if they are different. The C<len> parameter
1577indicates the number of bytes to compare. Returns true or false. (A
1578wrapper for C<strncmp>).
954c1994 1579
94bdecf9 1580 bool strnNE(char* s1, char* s2, STRLEN len)
954c1994 1581
497711e7
GS
1582=for hackers
1583Found in file handy.h
1584
f4758303 1585
94bdecf9 1586=back
7207e29d 1587
94bdecf9 1588=head1 Numeric functions
7207e29d 1589
94bdecf9 1590=over 8
f4758303 1591
94bdecf9 1592=item grok_bin
f4758303 1593
94bdecf9
JH
1594converts a string representing a binary number to numeric form.
1595
1596On entry I<start> and I<*len> give the string to scan, I<*flags> gives
1597conversion flags, and I<result> should be NULL or a pointer to an NV.
1598The scan stops at the end of the string, or the first invalid character.
1599On return I<*len> is set to the length scanned string, and I<*flags> gives
1600output flags.
1601
1602If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
1603and nothing is written to I<*result>. If the value is > UV_MAX C<grok_bin>
1604returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
1605and writes the value to I<*result> (or the value is discarded if I<result>
1606is NULL).
1607
1608The hex number may optionally be prefixed with "0b" or "b" unless
1609C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
1610C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the binary
1611number may use '_' characters to separate digits.
1612
1613 UV grok_bin(char* start, STRLEN* len, I32* flags, NV *result)
f4758303
JP
1614
1615=for hackers
94bdecf9 1616Found in file numeric.c
f4758303 1617
94bdecf9 1618=item grok_hex
954c1994 1619
94bdecf9
JH
1620converts a string representing a hex number to numeric form.
1621
1622On entry I<start> and I<*len> give the string to scan, I<*flags> gives
1623conversion flags, and I<result> should be NULL or a pointer to an NV.
1624The scan stops at the end of the string, or the first non-hex-digit character.
1625On return I<*len> is set to the length scanned string, and I<*flags> gives
1626output flags.
1627
1628If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
1629and nothing is written to I<*result>. If the value is > UV_MAX C<grok_hex>
1630returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
1631and writes the value to I<*result> (or the value is discarded if I<result>
1632is NULL).
1633
1634The hex number may optionally be prefixed with "0x" or "x" unless
1635C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
1636C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the hex
1637number may use '_' characters to separate digits.
1638
1639 UV grok_hex(char* start, STRLEN* len, I32* flags, NV *result)
954c1994 1640
497711e7 1641=for hackers
94bdecf9 1642Found in file numeric.c
497711e7 1643
94bdecf9 1644=item grok_number
954c1994 1645
94bdecf9
JH
1646Recognise (or not) a number. The type of the number is returned
1647(0 if unrecognised), otherwise it is a bit-ORed combination of
1648IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
1649IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
1650
1651If the value of the number can fit an in UV, it is returned in the *valuep
1652IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
1653will never be set unless *valuep is valid, but *valuep may have been assigned
1654to during processing even though IS_NUMBER_IN_UV is not set on return.
1655If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
1656valuep is non-NULL, but no actual assignment (or SEGV) will occur.
1657
1658IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
1659seen (in which case *valuep gives the true value truncated to an integer), and
1660IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
1661absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
1662number is larger than a UV.
1663
1664 int grok_number(const char *pv, STRLEN len, UV *valuep)
954c1994 1665
497711e7 1666=for hackers
94bdecf9 1667Found in file numeric.c
497711e7 1668
94bdecf9 1669=item grok_numeric_radix
954c1994 1670
94bdecf9
JH
1671Scan and skip for a numeric decimal separator (radix).
1672
1673 bool grok_numeric_radix(const char **sp, const char *send)
954c1994 1674
497711e7 1675=for hackers
94bdecf9 1676Found in file numeric.c
497711e7 1677
94bdecf9 1678=item grok_oct
954c1994 1679
94bdecf9
JH
1680
1681 UV grok_oct(char* start, STRLEN* len, I32* flags, NV *result)
954c1994 1682
497711e7 1683=for hackers
94bdecf9 1684Found in file numeric.c
497711e7 1685
94bdecf9 1686=item scan_bin
954c1994 1687
94bdecf9
JH
1688For backwards compatibility. Use C<grok_bin> instead.
1689
1690 NV scan_bin(char* start, STRLEN len, STRLEN* retlen)
954c1994 1691
497711e7 1692=for hackers
94bdecf9 1693Found in file numeric.c
497711e7 1694
94bdecf9 1695=item scan_hex
954c1994 1696
94bdecf9
JH
1697For backwards compatibility. Use C<grok_hex> instead.
1698
1699 NV scan_hex(char* start, STRLEN len, STRLEN* retlen)
954c1994 1700
497711e7 1701=for hackers
94bdecf9 1702Found in file numeric.c
497711e7 1703
94bdecf9 1704=item scan_oct
954c1994 1705
94bdecf9 1706For backwards compatibility. Use C<grok_oct> instead.
954c1994 1707
94bdecf9 1708 NV scan_oct(char* start, STRLEN len, STRLEN* retlen)
954c1994 1709
497711e7 1710=for hackers
94bdecf9 1711Found in file numeric.c
497711e7 1712
645c22ef 1713
94bdecf9 1714=back
645c22ef 1715
94bdecf9
JH
1716=head1 Optree Manipulation Functions
1717
1718=over 8
1719
1720=item cv_const_sv
1721
1722If C<cv> is a constant sub eligible for inlining. returns the constant
1723value returned by the sub. Otherwise, returns NULL.
1724
1725Constant subs can be created with C<newCONSTSUB> or as described in
1726L<perlsub/"Constant Functions">.
1727
1728 SV* cv_const_sv(CV* cv)
645c22ef
DM
1729
1730=for hackers
94bdecf9 1731Found in file op.c
645c22ef 1732
94bdecf9 1733=item newCONSTSUB
954c1994 1734
94bdecf9
JH
1735Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
1736eligible for inlining at compile-time.
954c1994 1737
94bdecf9 1738 CV* newCONSTSUB(HV* stash, char* name, SV* sv)
954c1994 1739
497711e7 1740=for hackers
94bdecf9 1741Found in file op.c
497711e7 1742
94bdecf9 1743=item newXS
954c1994 1744
94bdecf9 1745Used by C<xsubpp> to hook up XSUBs as Perl subs.
954c1994 1746
94bdecf9
JH
1747=for hackers
1748Found in file op.c
1749
1750
1751=back
1752
1753=head1 Shared SV Functions
1754
1755=over 8
1756
1757=item sharedsv_find
1758
1759Tries to find if a given SV has a shared backend, either by
1760looking at magic, or by checking if it is tied again threads::shared.
1761
1762 shared_sv* sharedsv_find(SV* sv)
954c1994 1763
497711e7 1764=for hackers
94bdecf9 1765Found in file sharedsv.c
497711e7 1766
94bdecf9 1767=item sharedsv_init
954c1994 1768
94bdecf9
JH
1769Saves a space for keeping SVs wider than an interpreter,
1770currently only stores a pointer to the first interpreter.
954c1994 1771
94bdecf9 1772 void sharedsv_init()
954c1994 1773
497711e7 1774=for hackers
94bdecf9 1775Found in file sharedsv.c
497711e7 1776
94bdecf9 1777=item sharedsv_lock
954c1994 1778
94bdecf9
JH
1779Recursive locks on a sharedsv.
1780Locks are dynamically scoped at the level of the first lock.
1781 void sharedsv_lock(shared_sv* ssv)
954c1994 1782
94bdecf9
JH
1783=for hackers
1784Found in file sharedsv.c
1785
1786=item sharedsv_new
1787
1788Allocates a new shared sv struct, you must yourself create the SV/AV/HV.
1789 shared_sv* sharedsv_new()
954c1994 1790
497711e7 1791=for hackers
94bdecf9 1792Found in file sharedsv.c
497711e7 1793
94bdecf9
JH
1794=item sharedsv_thrcnt_dec
1795
1796Decrements the threadcount of a shared sv. When a threads frontend is freed
1797this function should be called.
1798
1799 void sharedsv_thrcnt_dec(shared_sv* ssv)
1800
1801=for hackers
1802Found in file sharedsv.c
1803
1804=item sharedsv_thrcnt_inc
1805
1806Increments the threadcount of a sharedsv.
1807 void sharedsv_thrcnt_inc(shared_sv* ssv)
1808
1809=for hackers
1810Found in file sharedsv.c
1811
1812=item sharedsv_unlock
1813
1814Recursively unlocks a shared sv.
1815
1816 void sharedsv_unlock(shared_sv* ssv)
1817
1818=for hackers
1819Found in file sharedsv.c
1820
1821
1822=back
1823
1824=head1 Stack Manipulation Macros
1825
1826=over 8
1827
1828=item dMARK
954c1994 1829
94bdecf9
JH
1830Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
1831C<dORIGMARK>.
954c1994 1832
94bdecf9 1833 dMARK;
954c1994 1834
497711e7 1835=for hackers
94bdecf9 1836Found in file pp.h
497711e7 1837
94bdecf9 1838=item dORIGMARK
954c1994 1839
94bdecf9 1840Saves the original stack mark for the XSUB. See C<ORIGMARK>.
954c1994 1841
94bdecf9 1842 dORIGMARK;
954c1994 1843
497711e7 1844=for hackers
94bdecf9 1845Found in file pp.h
497711e7 1846
94bdecf9 1847=item dSP
954c1994 1848
94bdecf9
JH
1849Declares a local copy of perl's stack pointer for the XSUB, available via
1850the C<SP> macro. See C<SP>.
954c1994 1851
94bdecf9 1852 dSP;
954c1994 1853
497711e7 1854=for hackers
94bdecf9 1855Found in file pp.h
497711e7 1856
94bdecf9 1857=item EXTEND
954c1994 1858
94bdecf9
JH
1859Used to extend the argument stack for an XSUB's return values. Once
1860used, guarantees that there is room for at least C<nitems> to be pushed
1861onto the stack.
954c1994 1862
94bdecf9 1863 void EXTEND(SP, int nitems)
954c1994 1864
497711e7 1865=for hackers
94bdecf9 1866Found in file pp.h
954c1994 1867
94bdecf9 1868=item MARK
954c1994 1869
94bdecf9 1870Stack marker variable for the XSUB. See C<dMARK>.
954c1994 1871
497711e7 1872=for hackers
94bdecf9 1873Found in file pp.h
954c1994 1874
94bdecf9 1875=item ORIGMARK
954c1994 1876
94bdecf9 1877The original stack mark for the XSUB. See C<dORIGMARK>.
954c1994 1878
497711e7 1879=for hackers
94bdecf9 1880Found in file pp.h
497711e7 1881
954c1994
GS
1882=item POPi
1883
1884Pops an integer off the stack.
1885
1886 IV POPi
1887
497711e7
GS
1888=for hackers
1889Found in file pp.h
1890
954c1994
GS
1891=item POPl
1892
1893Pops a long off the stack.
1894
1895 long POPl
1896
497711e7
GS
1897=for hackers
1898Found in file pp.h
1899
954c1994
GS
1900=item POPn
1901
1902Pops a double off the stack.
1903
1904 NV POPn
1905
497711e7
GS
1906=for hackers
1907Found in file pp.h
1908
954c1994
GS
1909=item POPp
1910
fa519979
JH
1911Pops a string off the stack. Deprecated. New code should provide
1912a STRLEN n_a and use POPpx.
954c1994
GS
1913
1914 char* POPp
1915
497711e7
GS
1916=for hackers
1917Found in file pp.h
1918
fa519979
JH
1919=item POPpbytex
1920
1921Pops a string off the stack which must consist of bytes i.e. characters < 256.
1922Requires a variable STRLEN n_a in scope.
1923
1924 char* POPpbytex
1925
1926=for hackers
1927Found in file pp.h
1928
1929=item POPpx
1930
1931Pops a string off the stack.
1932Requires a variable STRLEN n_a in scope.
1933
1934 char* POPpx
1935
1936=for hackers
1937Found in file pp.h
1938
954c1994
GS
1939=item POPs
1940
1941Pops an SV off the stack.
1942
1943 SV* POPs
1944
497711e7
GS
1945=for hackers
1946Found in file pp.h
1947
954c1994
GS
1948=item PUSHi
1949
1950Push an integer onto the stack. The stack must have room for this element.
1951Handles 'set' magic. See C<XPUSHi>.
1952
1953 void PUSHi(IV iv)
1954
497711e7
GS
1955=for hackers
1956Found in file pp.h
1957
954c1994
GS
1958=item PUSHMARK
1959
1960Opening bracket for arguments on a callback. See C<PUTBACK> and
1961L<perlcall>.
1962
1963 PUSHMARK;
1964
497711e7
GS
1965=for hackers
1966Found in file pp.h
1967
954c1994
GS
1968=item PUSHn
1969
1970Push a double onto the stack. The stack must have room for this element.
1971Handles 'set' magic. See C<XPUSHn>.
1972
1973 void PUSHn(NV nv)
1974
497711e7
GS
1975=for hackers
1976Found in file pp.h
1977
954c1994
GS
1978=item PUSHp
1979
1980Push a string onto the stack. The stack must have room for this element.
1981The C<len> indicates the length of the string. Handles 'set' magic. See
1982C<XPUSHp>.
1983
1984 void PUSHp(char* str, STRLEN len)
1985
497711e7
GS
1986=for hackers
1987Found in file pp.h
1988
954c1994
GS
1989=item PUSHs
1990
1c846c1f 1991Push an SV onto the stack. The stack must have room for this element.
954c1994
GS
1992Does not handle 'set' magic. See C<XPUSHs>.
1993
1994 void PUSHs(SV* sv)
1995
497711e7
GS
1996=for hackers
1997Found in file pp.h
1998
954c1994
GS
1999=item PUSHu
2000
2001Push an unsigned integer onto the stack. The stack must have room for this
2002element. See C<XPUSHu>.
2003
2004 void PUSHu(UV uv)
2005
497711e7
GS
2006=for hackers
2007Found in file pp.h
2008
954c1994
GS
2009=item PUTBACK
2010
2011Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
2012See C<PUSHMARK> and L<perlcall> for other uses.
2013
2014 PUTBACK;
2015
497711e7
GS
2016=for hackers
2017Found in file pp.h
2018
94bdecf9 2019=item SP
d2cc3551 2020
94bdecf9
JH
2021Stack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
2022C<SPAGAIN>.
d2cc3551 2023
94bdecf9
JH
2024=for hackers
2025Found in file pp.h
2026
2027=item SPAGAIN
2028
2029Refetch the stack pointer. Used after a callback. See L<perlcall>.
2030
2031 SPAGAIN;
d2cc3551
JH
2032
2033=for hackers
94bdecf9 2034Found in file pp.h
d2cc3551 2035
94bdecf9 2036=item XPUSHi
954c1994 2037
94bdecf9
JH
2038Push an integer onto the stack, extending the stack if necessary. Handles
2039'set' magic. See C<PUSHi>.
954c1994 2040
94bdecf9 2041 void XPUSHi(IV iv)
954c1994 2042
497711e7 2043=for hackers
94bdecf9 2044Found in file pp.h
497711e7 2045
94bdecf9 2046=item XPUSHn
954c1994 2047
94bdecf9
JH
2048Push a double onto the stack, extending the stack if necessary. Handles
2049'set' magic. See C<PUSHn>.
954c1994 2050
94bdecf9 2051 void XPUSHn(NV nv)
954c1994 2052
497711e7 2053=for hackers
94bdecf9 2054Found in file pp.h
497711e7 2055
94bdecf9 2056=item XPUSHp
954c1994 2057
94bdecf9
JH
2058Push a string onto the stack, extending the stack if necessary. The C<len>
2059indicates the length of the string. Handles 'set' magic. See
2060C<PUSHp>.
954c1994 2061
94bdecf9 2062 void XPUSHp(char* str, STRLEN len)
954c1994 2063
94bdecf9
JH
2064=for hackers
2065Found in file pp.h
2066
2067=item XPUSHs
2068
2069Push an SV onto the stack, extending the stack if necessary. Does not
2070handle 'set' magic. See C<PUSHs>.
2071
2072 void XPUSHs(SV* sv)
954c1994 2073
497711e7 2074=for hackers
94bdecf9 2075Found in file pp.h
497711e7 2076
94bdecf9 2077=item XPUSHu
954c1994 2078
94bdecf9
JH
2079Push an unsigned integer onto the stack, extending the stack if necessary.
2080See C<PUSHu>.
954c1994 2081
94bdecf9
JH
2082 void XPUSHu(UV uv)
2083
2084=for hackers
2085Found in file pp.h
2086
2087=item XSRETURN
2088
2089Return from XSUB, indicating number of items on the stack. This is usually
2090handled by C<xsubpp>.
2091
2092 void XSRETURN(int nitems)
954c1994 2093
497711e7
GS
2094=for hackers
2095Found in file XSUB.h
2096
94bdecf9 2097=item XSRETURN_IV
954c1994 2098
94bdecf9 2099Return an integer from an XSUB immediately. Uses C<XST_mIV>.
954c1994 2100
94bdecf9 2101 void XSRETURN_IV(IV iv)
954c1994 2102
497711e7 2103=for hackers
94bdecf9 2104Found in file XSUB.h
497711e7 2105
94bdecf9 2106=item XSRETURN_NO
954c1994 2107
94bdecf9 2108Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
954c1994 2109
94bdecf9 2110 XSRETURN_NO;
954c1994 2111
497711e7 2112=for hackers
94bdecf9 2113Found in file XSUB.h
497711e7 2114
94bdecf9 2115=item XSRETURN_NV
954c1994 2116
94bdecf9 2117Return a double from an XSUB immediately. Uses C<XST_mNV>.
954c1994 2118
94bdecf9 2119 void XSRETURN_NV(NV nv)
954c1994 2120
497711e7 2121=for hackers
94bdecf9
JH
2122Found in file XSUB.h
2123
2124=item XSRETURN_PV
2125
2126Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
2127
2128 void XSRETURN_PV(char* str)
2129
2130=for hackers
2131Found in file XSUB.h
2132
2133=item XSRETURN_UNDEF
2134
2135Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
2136
2137 XSRETURN_UNDEF;
2138
2139=for hackers
2140Found in file XSUB.h
2141
2142=item XSRETURN_YES
2143
2144Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
2145
2146 XSRETURN_YES;
2147
2148=for hackers
2149Found in file XSUB.h
2150
2151=item XST_mIV
2152
2153Place an integer into the specified position C<pos> on the stack. The
2154value is stored in a new mortal SV.
2155
2156 void XST_mIV(int pos, IV iv)
2157
2158=for hackers
2159Found in file XSUB.h
2160
2161=item XST_mNO
2162
2163Place C<&PL_sv_no> into the specified position C<pos> on the
2164stack.
2165
2166 void XST_mNO(int pos)
2167
2168=for hackers
2169Found in file XSUB.h
2170
2171=item XST_mNV
2172
2173Place a double into the specified position C<pos> on the stack. The value
2174is stored in a new mortal SV.
2175
2176 void XST_mNV(int pos, NV nv)
2177
2178=for hackers
2179Found in file XSUB.h
2180
2181=item XST_mPV
2182
2183Place a copy of a string into the specified position C<pos> on the stack.
2184The value is stored in a new mortal SV.
2185
2186 void XST_mPV(int pos, char* str)
2187
2188=for hackers
2189Found in file XSUB.h
2190
2191=item XST_mUNDEF
2192
2193Place C<&PL_sv_undef> into the specified position C<pos> on the
2194stack.
2195
2196 void XST_mUNDEF(int pos)
2197
2198=for hackers
2199Found in file XSUB.h
2200
2201=item XST_mYES
2202
2203Place C<&PL_sv_yes> into the specified position C<pos> on the
2204stack.
2205
2206 void XST_mYES(int pos)
2207
2208=for hackers
2209Found in file XSUB.h
2210
2211
2212=back
2213
2214=head1 SV Flags
497711e7 2215
94bdecf9 2216=over 8
954c1994 2217
94bdecf9 2218=item svtype
954c1994 2219
94bdecf9
JH
2220An enum of flags for Perl types. These are found in the file B<sv.h>
2221in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
954c1994 2222
497711e7 2223=for hackers
94bdecf9 2224Found in file sv.h
6e9d1081 2225
94bdecf9 2226=item SVt_IV
6e9d1081 2227
94bdecf9 2228Integer type flag for scalars. See C<svtype>.
6e9d1081
NC
2229
2230=for hackers
94bdecf9 2231Found in file sv.h
6e9d1081 2232
94bdecf9 2233=item SVt_NV
6e9d1081 2234
94bdecf9 2235Double type flag for scalars. See C<svtype>.
6e9d1081
NC
2236
2237=for hackers
94bdecf9 2238Found in file sv.h
6e9d1081 2239
94bdecf9 2240=item SVt_PV
6e9d1081 2241
94bdecf9 2242Pointer type flag for scalars. See C<svtype>.
6e9d1081
NC
2243
2244=for hackers
94bdecf9 2245Found in file sv.h
cd1ee231 2246
94bdecf9 2247=item SVt_PVAV
cd1ee231 2248
94bdecf9 2249Type flag for arrays. See C<svtype>.
cd1ee231
JH
2250
2251=for hackers
94bdecf9 2252Found in file sv.h
cd1ee231 2253
94bdecf9 2254=item SVt_PVCV
cd1ee231 2255
94bdecf9 2256Type flag for code refs. See C<svtype>.
cd1ee231
JH
2257
2258=for hackers
94bdecf9 2259Found in file sv.h
cd1ee231 2260
94bdecf9 2261=item SVt_PVHV
cd1ee231 2262
94bdecf9 2263Type flag for hashes. See C<svtype>.
cd1ee231
JH
2264
2265=for hackers
94bdecf9 2266Found in file sv.h
cd1ee231 2267
94bdecf9 2268=item SVt_PVMG
cd1ee231 2269
94bdecf9 2270Type flag for blessed scalars. See C<svtype>.
cd1ee231
JH
2271
2272=for hackers
94bdecf9 2273Found in file sv.h
cd1ee231 2274
cd1ee231 2275
94bdecf9 2276=back
cd1ee231 2277
94bdecf9 2278=head1 SV Manipulation Functions
cd1ee231 2279
94bdecf9 2280=over 8
cd1ee231 2281
94bdecf9 2282=item get_sv
cd1ee231 2283
94bdecf9
JH
2284Returns the SV of the specified Perl scalar. If C<create> is set and the
2285Perl variable does not exist then it will be created. If C<create> is not
2286set and the variable does not exist then NULL is returned.
2287
2288NOTE: the perl_ form of this function is deprecated.
2289
2290 SV* get_sv(const char* name, I32 create)
cd1ee231
JH
2291
2292=for hackers
94bdecf9 2293Found in file perl.c
cd1ee231 2294
94bdecf9 2295=item looks_like_number
cd1ee231 2296
94bdecf9
JH
2297Test if the content of an SV looks like a number (or is a number).
2298C<Inf> and C<Infinity> are treated as numbers (so will not issue a
2299non-numeric warning), even if your atof() doesn't grok them.
cd1ee231 2300
94bdecf9 2301 I32 looks_like_number(SV* sv)
cd1ee231
JH
2302
2303=for hackers
94bdecf9 2304Found in file sv.c
2a5a0c38 2305
94bdecf9 2306=item newRV_inc
2a5a0c38 2307
94bdecf9
JH
2308Creates an RV wrapper for an SV. The reference count for the original SV is
2309incremented.
2a5a0c38 2310
94bdecf9 2311 SV* newRV_inc(SV* sv)
2a5a0c38
JH
2312
2313=for hackers
94bdecf9 2314Found in file sv.h
2a5a0c38 2315
94bdecf9 2316=item newRV_noinc
954c1994 2317
94bdecf9
JH
2318Creates an RV wrapper for an SV. The reference count for the original
2319SV is B<not> incremented.
2320
2321 SV* newRV_noinc(SV *sv)
954c1994 2322
497711e7 2323=for hackers
94bdecf9 2324Found in file sv.c
497711e7 2325
94bdecf9 2326=item newSV
954c1994 2327
94bdecf9
JH
2328Create a new null SV, or if len > 0, create a new empty SVt_PV type SV
2329with an initial PV allocation of len+1. Normally accessed via the C<NEWSV>
2330macro.
954c1994 2331
94bdecf9 2332 SV* newSV(STRLEN len)
954c1994 2333
497711e7 2334=for hackers
94bdecf9 2335Found in file sv.c
497711e7 2336
94bdecf9 2337=item newSViv
954c1994 2338
94bdecf9
JH
2339Creates a new SV and copies an integer into it. The reference count for the
2340SV is set to 1.
954c1994 2341
94bdecf9 2342 SV* newSViv(IV i)
954c1994 2343
497711e7 2344=for hackers
94bdecf9 2345Found in file sv.c
497711e7 2346
94bdecf9 2347=item newSVnv
954c1994 2348
94bdecf9
JH
2349Creates a new SV and copies a floating point value into it.
2350The reference count for the SV is set to 1.
954c1994 2351
94bdecf9 2352 SV* newSVnv(NV n)
954c1994 2353
497711e7 2354=for hackers
94bdecf9 2355Found in file sv.c
497711e7 2356
94bdecf9 2357=item newSVpv
954c1994 2358
94bdecf9
JH
2359Creates a new SV and copies a string into it. The reference count for the
2360SV is set to 1. If C<len> is zero, Perl will compute the length using
2361strlen(). For efficiency, consider using C<newSVpvn> instead.
954c1994 2362
94bdecf9 2363 SV* newSVpv(const char* s, STRLEN len)
954c1994 2364
497711e7 2365=for hackers
94bdecf9 2366Found in file sv.c
497711e7 2367
94bdecf9 2368=item newSVpvf
954c1994 2369
94bdecf9
JH
2370Creates a new SV and initializes it with the string formatted like
2371C<sprintf>.
954c1994 2372
94bdecf9 2373 SV* newSVpvf(const char* pat, ...)
954c1994 2374
497711e7 2375=for hackers
94bdecf9 2376Found in file sv.c
497711e7 2377
94bdecf9 2378=item newSVpvn
954c1994 2379
94bdecf9
JH
2380Creates a new SV and copies a string into it. The reference count for the
2381SV is set to 1. Note that if C<len> is zero, Perl will create a zero length
2382string. You are responsible for ensuring that the source string is at least
2383C<len> bytes long.
954c1994 2384
94bdecf9 2385 SV* newSVpvn(const char* s, STRLEN len)
954c1994 2386
497711e7 2387=for hackers
94bdecf9 2388Found in file sv.c
497711e7 2389
94bdecf9 2390=item newSVpvn_share
954c1994 2391
94bdecf9
JH
2392Creates a new SV with its SvPVX pointing to a shared string in the string
2393table. If the string does not already exist in the table, it is created
2394first. Turns on READONLY and FAKE. The string's hash is stored in the UV
2395slot of the SV; if the C<hash> parameter is non-zero, that value is used;
2396otherwise the hash is computed. The idea here is that as the string table
2397is used for shared hash keys these strings will have SvPVX == HeKEY and
2398hash lookup will avoid string compare.
954c1994 2399
94bdecf9 2400 SV* newSVpvn_share(const char* s, I32 len, U32 hash)
954c1994 2401
497711e7 2402=for hackers
94bdecf9 2403Found in file sv.c
497711e7 2404
94bdecf9 2405=item newSVrv
954c1994 2406
94bdecf9
JH
2407Creates a new SV for the RV, C<rv>, to point to. If C<rv> is not an RV then
2408it will be upgraded to one. If C<classname> is non-null then the new SV will
2409be blessed in the specified package. The new SV is returned and its
2410reference count is 1.
954c1994 2411
94bdecf9 2412 SV* newSVrv(SV* rv, const char* classname)
954c1994 2413
497711e7 2414=for hackers
94bdecf9 2415Found in file sv.c
497711e7 2416
94bdecf9 2417=item newSVsv
954c1994 2418
94bdecf9
JH
2419Creates a new SV which is an exact duplicate of the original SV.
2420(Uses C<sv_setsv>).
954c1994 2421
94bdecf9 2422 SV* newSVsv(SV* old)
954c1994 2423
497711e7 2424=for hackers
94bdecf9 2425Found in file sv.c
497711e7 2426
94bdecf9 2427=item newSVuv
954c1994 2428
94bdecf9
JH
2429Creates a new SV and copies an unsigned integer into it.
2430The reference count for the SV is set to 1.
954c1994 2431
94bdecf9 2432 SV* newSVuv(UV u)
954c1994 2433
497711e7 2434=for hackers
94bdecf9 2435Found in file sv.c
497711e7 2436
94bdecf9 2437=item new_vstring
954c1994 2438
94bdecf9
JH
2439Returns a pointer to the next character after the parsed
2440vstring, as well as updating the passed in sv.
954c1994 2441
94bdecf9
JH
2442Function must be called like
2443
2444 sv = NEWSV(92,5);
2445 s = new_vstring(s,sv);
2446
2447The sv must already be large enough to store the vstring
2448passed in.
2449
2450 char* new_vstring(char *vstr, SV *sv)
954c1994 2451
497711e7 2452=for hackers
94bdecf9 2453Found in file util.c
497711e7 2454
954c1994
GS
2455=item SvCUR
2456
2457Returns the length of the string which is in the SV. See C<SvLEN>.
2458
2459 STRLEN SvCUR(SV* sv)
2460
497711e7
GS
2461=for hackers
2462Found in file sv.h
2463
954c1994
GS
2464=item SvCUR_set
2465
2466Set the length of the string which is in the SV. See C<SvCUR>.
2467
2468 void SvCUR_set(SV* sv, STRLEN len)
2469
497711e7
GS
2470=for hackers
2471Found in file sv.h
2472
94bdecf9 2473=item SvEND
954c1994 2474
94bdecf9
JH
2475Returns a pointer to the last character in the string which is in the SV.
2476See C<SvCUR>. Access the character as *(SvEND(sv)).
954c1994 2477
94bdecf9 2478 char* SvEND(SV* sv)
954c1994 2479
497711e7
GS
2480=for hackers
2481Found in file sv.h
2482
954c1994
GS
2483=item SvGROW
2484
2485Expands the character buffer in the SV so that it has room for the
2486indicated number of bytes (remember to reserve space for an extra trailing
8cf8f3d1 2487NUL character). Calls C<sv_grow> to perform the expansion if necessary.
954c1994
GS
2488Returns a pointer to the character buffer.
2489
679ac26e 2490 char * SvGROW(SV* sv, STRLEN len)
954c1994 2491
497711e7
GS
2492=for hackers
2493Found in file sv.h
2494
954c1994
GS
2495=item SvIOK
2496
2497Returns a boolean indicating whether the SV contains an integer.
2498
2499 bool SvIOK(SV* sv)
2500
497711e7
GS
2501=for hackers
2502Found in file sv.h
2503
954c1994
GS
2504=item SvIOKp
2505
2506Returns a boolean indicating whether the SV contains an integer. Checks
2507the B<private> setting. Use C<SvIOK>.
2508
2509 bool SvIOKp(SV* sv)
2510
497711e7
GS
2511=for hackers
2512Found in file sv.h
2513
e331fc52
JH
2514=item SvIOK_notUV
2515
f4758303 2516Returns a boolean indicating whether the SV contains a signed integer.
e331fc52
JH
2517
2518 void SvIOK_notUV(SV* sv)
2519
2520=for hackers
2521Found in file sv.h
2522
954c1994
GS
2523=item SvIOK_off
2524
2525Unsets the IV status of an SV.
2526
2527 void SvIOK_off(SV* sv)
2528
497711e7
GS
2529=for hackers
2530Found in file sv.h
2531
954c1994
GS
2532=item SvIOK_on
2533
2534Tells an SV that it is an integer.
2535
2536 void SvIOK_on(SV* sv)
2537
497711e7
GS
2538=for hackers
2539Found in file sv.h
2540
954c1994
GS
2541=item SvIOK_only
2542
2543Tells an SV that it is an integer and disables all other OK bits.
2544
2545 void SvIOK_only(SV* sv)
2546
497711e7
GS
2547=for hackers
2548Found in file sv.h
2549
e331fc52
JH
2550=item SvIOK_only_UV
2551
2552Tells and SV that it is an unsigned integer and disables all other OK bits.
2553
2554 void SvIOK_only_UV(SV* sv)
2555
2556=for hackers
2557Found in file sv.h
2558
2559=item SvIOK_UV
2560
2561Returns a boolean indicating whether the SV contains an unsigned integer.
2562
2563 void SvIOK_UV(SV* sv)
2564
2565=for hackers
2566Found in file sv.h
2567
954c1994
GS
2568=item SvIV
2569
645c22ef
DM
2570Coerces the given SV to an integer and returns it. See C<SvIVx> for a
2571version which guarantees to evaluate sv only once.
954c1994
GS
2572
2573 IV SvIV(SV* sv)
2574
497711e7
GS
2575=for hackers
2576Found in file sv.h
2577
94bdecf9 2578=item SvIVx
954c1994 2579
94bdecf9
JH
2580Coerces the given SV to an integer and returns it. Guarantees to evaluate
2581sv only once. Use the more efficient C<SvIV> otherwise.
954c1994 2582
94bdecf9 2583 IV SvIVx(SV* sv)
954c1994 2584
497711e7
GS
2585=for hackers
2586Found in file sv.h
2587
94bdecf9 2588=item SvIVX
645c22ef 2589
94bdecf9
JH
2590Returns the raw value in the SV's IV slot, without checks or conversions.
2591Only use when you are sure SvIOK is true. See also C<SvIV()>.
645c22ef 2592
94bdecf9 2593 IV SvIVX(SV* sv)
645c22ef
DM
2594
2595=for hackers
2596Found in file sv.h
2597
954c1994
GS
2598=item SvLEN
2599
91e74348
JH
2600Returns the size of the string buffer in the SV, not including any part
2601attributable to C<SvOOK>. See C<SvCUR>.
954c1994
GS
2602
2603 STRLEN SvLEN(SV* sv)
2604
497711e7
GS
2605=for hackers
2606Found in file sv.h
2607
954c1994
GS
2608=item SvNIOK
2609
2610Returns a boolean indicating whether the SV contains a number, integer or
2611double.
2612
2613 bool SvNIOK(SV* sv)
2614
497711e7
GS
2615=for hackers
2616Found in file sv.h
2617
954c1994
GS
2618=item SvNIOKp
2619
2620Returns a boolean indicating whether the SV contains a number, integer or
2621double. Checks the B<private> setting. Use C<SvNIOK>.
2622
2623 bool SvNIOKp(SV* sv)
2624
497711e7
GS
2625=for hackers
2626Found in file sv.h
2627
954c1994
GS
2628=item SvNIOK_off
2629
2630Unsets the NV/IV status of an SV.
2631
2632 void SvNIOK_off(SV* sv)
2633
497711e7
GS
2634=for hackers
2635Found in file sv.h
2636
954c1994
GS
2637=item SvNOK
2638
2639Returns a boolean indicating whether the SV contains a double.
2640
2641 bool SvNOK(SV* sv)
2642
497711e7
GS
2643=for hackers
2644Found in file sv.h
2645
954c1994
GS
2646=item SvNOKp
2647
2648Returns a boolean indicating whether the SV contains a double. Checks the
2649B<private> setting. Use C<SvNOK>.
2650
2651 bool SvNOKp(SV* sv)
2652
497711e7
GS
2653=for hackers
2654Found in file sv.h
2655
954c1994
GS
2656=item SvNOK_off
2657
2658Unsets the NV status of an SV.
2659
2660 void SvNOK_off(SV* sv)
2661
497711e7
GS
2662=for hackers
2663Found in file sv.h
2664
954c1994
GS
2665=item SvNOK_on
2666
2667Tells an SV that it is a double.
2668
2669 void SvNOK_on(SV* sv)
2670
497711e7
GS
2671=for hackers
2672Found in file sv.h
2673
954c1994
GS
2674=item SvNOK_only
2675
2676Tells an SV that it is a double and disables all other OK bits.
2677
2678 void SvNOK_only(SV* sv)
2679
497711e7
GS
2680=for hackers
2681Found in file sv.h
2682
954c1994
GS
2683=item SvNV
2684
645c22ef
DM
2685Coerce the given SV to a double and return it. See C<SvNVx> for a version
2686which guarantees to evaluate sv only once.
954c1994
GS
2687
2688 NV SvNV(SV* sv)
2689
497711e7
GS
2690=for hackers
2691Found in file sv.h
2692
94bdecf9 2693=item SvNVX
645c22ef 2694
94bdecf9
JH
2695Returns the raw value in the SV's NV slot, without checks or conversions.
2696Only use when you are sure SvNOK is true. See also C<SvNV()>.
645c22ef 2697
94bdecf9 2698 NV SvNVX(SV* sv)
645c22ef
DM
2699
2700=for hackers
2701Found in file sv.h
2702
94bdecf9 2703=item SvNVx
954c1994 2704
94bdecf9
JH
2705Coerces the given SV to a double and returns it. Guarantees to evaluate
2706sv only once. Use the more efficient C<SvNV> otherwise.
954c1994 2707
94bdecf9 2708 NV SvNVx(SV* sv)
954c1994 2709
497711e7
GS
2710=for hackers
2711Found in file sv.h
2712
954c1994
GS
2713=item SvOK
2714
2715Returns a boolean indicating whether the value is an SV.
2716
2717 bool SvOK(SV* sv)
2718
497711e7
GS
2719=for hackers
2720Found in file sv.h
2721
954c1994
GS
2722=item SvOOK
2723
2724Returns a boolean indicating whether the SvIVX is a valid offset value for
2725the SvPVX. This hack is used internally to speed up removal of characters
2726from the beginning of a SvPV. When SvOOK is true, then the start of the
2727allocated string buffer is really (SvPVX - SvIVX).
2728
2729 bool SvOOK(SV* sv)
2730
497711e7
GS
2731=for hackers
2732Found in file sv.h
2733
954c1994
GS
2734=item SvPOK
2735
2736Returns a boolean indicating whether the SV contains a character
2737string.
2738
2739 bool SvPOK(SV* sv)
2740
497711e7
GS
2741=for hackers
2742Found in file sv.h
2743
954c1994
GS
2744=item SvPOKp
2745
2746Returns a boolean indicating whether the SV contains a character string.
2747Checks the B<private> setting. Use C<SvPOK>.
2748
2749 bool SvPOKp(SV* sv)
2750
497711e7
GS
2751=for hackers
2752Found in file sv.h
2753
954c1994
GS
2754=item SvPOK_off
2755
2756Unsets the PV status of an SV.
2757
2758 void SvPOK_off(SV* sv)
2759
497711e7
GS
2760=for hackers
2761Found in file sv.h
2762
954c1994
GS
2763=item SvPOK_on
2764
2765Tells an SV that it is a string.
2766
2767 void SvPOK_on(SV* sv)
2768
497711e7
GS
2769=for hackers
2770Found in file sv.h
2771
954c1994
GS
2772=item SvPOK_only
2773
2774Tells an SV that it is a string and disables all other OK bits.
d5ce4a7c 2775Will also turn off the UTF8 status.
954c1994
GS
2776
2777 void SvPOK_only(SV* sv)
2778
497711e7
GS
2779=for hackers
2780Found in file sv.h
2781
914184e1
JH
2782=item SvPOK_only_UTF8
2783
d5ce4a7c
GA
2784Tells an SV that it is a string and disables all other OK bits,
2785and leaves the UTF8 status as it was.
f1a1024e 2786
914184e1
JH
2787 void SvPOK_only_UTF8(SV* sv)
2788
2789=for hackers
2790Found in file sv.h
2791
954c1994
GS
2792=item SvPV
2793
2794Returns a pointer to the string in the SV, or a stringified form of the SV
645c22ef
DM
2795if the SV does not contain a string. Handles 'get' magic. See also
2796C<SvPVx> for a version which guarantees to evaluate sv only once.
954c1994
GS
2797
2798 char* SvPV(SV* sv, STRLEN len)
2799
497711e7
GS
2800=for hackers
2801Found in file sv.h
2802
645c22ef
DM
2803=item SvPVbyte
2804
2805Like C<SvPV>, but converts sv to byte representation first if necessary.
2806
2807 char* SvPVbyte(SV* sv, STRLEN len)
2808
2809=for hackers
2810Found in file sv.h
2811
2812=item SvPVbytex
2813
2814Like C<SvPV>, but converts sv to byte representation first if necessary.
d1be9408 2815Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>
645c22ef
DM
2816otherwise.
2817
2818
2819 char* SvPVbytex(SV* sv, STRLEN len)
2820
2821=for hackers
2822Found in file sv.h
2823
2824=item SvPVbytex_force
2825
2826Like C<SvPV_force>, but converts sv to byte representation first if necessary.
d1be9408 2827Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>
645c22ef
DM
2828otherwise.
2829
2830 char* SvPVbytex_force(SV* sv, STRLEN len)
2831
2832=for hackers
2833Found in file sv.h
2834
2835=item SvPVbyte_force
2836
2837Like C<SvPV_force>, but converts sv to byte representation first if necessary.
2838
2839 char* SvPVbyte_force(SV* sv, STRLEN len)
2840
2841=for hackers
2842Found in file sv.h
2843
2844=item SvPVbyte_nolen
2845
2846Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
2847
1fdc5aa6 2848 char* SvPVbyte_nolen(SV* sv)
645c22ef
DM
2849
2850=for hackers
2851Found in file sv.h
2852
2853=item SvPVutf8
2854
1fdc5aa6 2855Like C<SvPV>, but converts sv to utf8 first if necessary.
645c22ef
DM
2856
2857 char* SvPVutf8(SV* sv, STRLEN len)
2858
2859=for hackers
2860Found in file sv.h
2861
2862=item SvPVutf8x
2863
1fdc5aa6 2864Like C<SvPV>, but converts sv to utf8 first if necessary.
d1be9408 2865Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>
645c22ef
DM
2866otherwise.
2867
2868 char* SvPVutf8x(SV* sv, STRLEN len)
2869
2870=for hackers
2871Found in file sv.h
2872
2873=item SvPVutf8x_force
2874
1fdc5aa6 2875Like C<SvPV_force>, but converts sv to utf8 first if necessary.
d1be9408 2876Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>
645c22ef
DM
2877otherwise.
2878
2879 char* SvPVutf8x_force(SV* sv, STRLEN len)
2880
2881=for hackers
2882Found in file sv.h
2883
2884=item SvPVutf8_force
2885
1fdc5aa6 2886Like C<SvPV_force>, but converts sv to utf8 first if necessary.
645c22ef
DM
2887
2888 char* SvPVutf8_force(SV* sv, STRLEN len)
2889
2890=for hackers
2891Found in file sv.h
2892
2893=item SvPVutf8_nolen
2894
1fdc5aa6 2895Like C<SvPV_nolen>, but converts sv to utf8 first if necessary.
645c22ef 2896
1fdc5aa6 2897 char* SvPVutf8_nolen(SV* sv)
645c22ef
DM
2898
2899=for hackers
2900Found in file sv.h
2901
9f4817db 2902=item SvPVX
645c22ef 2903
9f4817db
JH
2904Returns a pointer to the physical string in the SV. The SV must contain a
2905string.
645c22ef 2906
9f4817db 2907 char* SvPVX(SV* sv)
645c22ef
DM
2908
2909=for hackers
2910Found in file sv.h
2911
9f4817db 2912=item SvPVx
954c1994 2913
9f4817db 2914A version of C<SvPV> which guarantees to evaluate sv only once.
954c1994 2915
9f4817db 2916 char* SvPVx(SV* sv, STRLEN len)
954c1994 2917
497711e7
GS
2918=for hackers
2919Found in file sv.h
2920
954c1994
GS
2921=item SvPV_force
2922
2923Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
2924force if you are going to update the SvPVX directly.
2925
2926 char* SvPV_force(SV* sv, STRLEN len)
2927
497711e7
GS
2928=for hackers
2929Found in file sv.h
2930
645c22ef
DM
2931=item SvPV_force_nomg
2932
2933Like <SvPV> but will force the SV into becoming a string (SvPOK). You want
2934force if you are going to update the SvPVX directly. Doesn't process magic.
2935
2936 char* SvPV_force_nomg(SV* sv, STRLEN len)
2937
2938=for hackers
2939Found in file sv.h
2940
954c1994
GS
2941=item SvPV_nolen
2942
2943Returns a pointer to the string in the SV, or a stringified form of the SV
2944if the SV does not contain a string. Handles 'get' magic.
2945
2946 char* SvPV_nolen(SV* sv)
2947
497711e7
GS
2948=for hackers
2949Found in file sv.h
2950
954c1994
GS
2951=item SvREFCNT
2952
2953Returns the value of the object's reference count.
2954
2955 U32 SvREFCNT(SV* sv)
2956
497711e7
GS
2957=for hackers
2958Found in file sv.h
2959
954c1994
GS
2960=item SvREFCNT_dec
2961
2962Decrements the reference count of the given SV.
2963
2964 void SvREFCNT_dec(SV* sv)
2965
497711e7
GS
2966=for hackers
2967Found in file sv.h
2968
954c1994
GS
2969=item SvREFCNT_inc
2970
2971Increments the reference count of the given SV.
2972
2973 SV* SvREFCNT_inc(SV* sv)
2974
497711e7
GS
2975=for hackers
2976Found in file sv.h
2977
954c1994
GS
2978=item SvROK
2979
2980Tests if the SV is an RV.
2981
2982 bool SvROK(SV* sv)
2983
497711e7
GS
2984=for hackers
2985Found in file sv.h
2986
954c1994
GS
2987=item SvROK_off
2988
2989Unsets the RV status of an SV.
2990
2991 void SvROK_off(SV* sv)
2992
497711e7
GS
2993=for hackers
2994Found in file sv.h
2995
954c1994
GS
2996=item SvROK_on
2997
2998Tells an SV that it is an RV.
2999
3000 void SvROK_on(SV* sv)
3001
497711e7
GS
3002=for hackers
3003Found in file sv.h
3004
954c1994
GS
3005=item SvRV
3006
3007Dereferences an RV to return the SV.
3008
3009 SV* SvRV(SV* sv)
3010
497711e7
GS
3011=for hackers
3012Found in file sv.h
3013
645c22ef
DM
3014=item SvSetMagicSV_nosteal
3015
3016Like C<SvSetMagicSV>, but does any set magic required afterwards.
3017
954c1994 3018
94bdecf9 3019 void SvSetMagicSV_nosteal(SV* dsv, SV* ssv)
954c1994 3020
497711e7
GS
3021=for hackers
3022Found in file sv.h
3023
954c1994
GS
3024=item SvSTASH
3025
3026Returns the stash of the SV.
3027
3028 HV* SvSTASH(SV* sv)
3029
497711e7
GS
3030=for hackers
3031Found in file sv.h
3032
954c1994
GS
3033=item SvTAINT
3034
3035Taints an SV if tainting is enabled
3036
3037 void SvTAINT(SV* sv)
3038
497711e7
GS
3039=for hackers
3040Found in file sv.h
3041
954c1994
GS
3042=item SvTAINTED
3043
3044Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
3045not.
3046
3047 bool SvTAINTED(SV* sv)
3048
497711e7
GS
3049=for hackers
3050Found in file sv.h
3051
954c1994
GS
3052=item SvTAINTED_off
3053
3054Untaints an SV. Be I<very> careful with this routine, as it short-circuits
3055some of Perl's fundamental security features. XS module authors should not
3056use this function unless they fully understand all the implications of
3057unconditionally untainting the value. Untainting should be done in the
3058standard perl fashion, via a carefully crafted regexp, rather than directly
3059untainting variables.
3060
3061 void SvTAINTED_off(SV* sv)
3062
497711e7
GS
3063=for hackers
3064Found in file sv.h
3065
954c1994
GS
3066=item SvTAINTED_on
3067
3068Marks an SV as tainted.
3069
3070 void SvTAINTED_on(SV* sv)
3071
497711e7
GS
3072=for hackers
3073Found in file sv.h
3074
954c1994
GS
3075=item SvTRUE
3076
3077Returns a boolean indicating whether Perl would evaluate the SV as true or
3078false, defined or undefined. Does not handle 'get' magic.
3079
3080 bool SvTRUE(SV* sv)
3081
497711e7
GS
3082=for hackers
3083Found in file sv.h
3084
9f4817db 3085=item SvTYPE
af3c7592 3086
9f4817db
JH
3087Returns the type of the SV. See C<svtype>.
3088
3089 svtype SvTYPE(SV* sv)
954c1994 3090
497711e7
GS
3091=for hackers
3092Found in file sv.h
3093
a8586c98
JH
3094=item SvUOK
3095
3096Returns a boolean indicating whether the SV contains an unsigned integer.
3097
3098 void SvUOK(SV* sv)
3099
3100=for hackers
3101Found in file sv.h
3102
954c1994
GS
3103=item SvUPGRADE
3104
3105Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
3106perform the upgrade if necessary. See C<svtype>.
3107
3108 void SvUPGRADE(SV* sv, svtype type)
3109
497711e7
GS
3110=for hackers
3111Found in file sv.h
3112
914184e1
JH
3113=item SvUTF8
3114
3115Returns a boolean indicating whether the SV contains UTF-8 encoded data.
3116
3117 void SvUTF8(SV* sv)
3118
3119=for hackers
3120Found in file sv.h
3121
3122=item SvUTF8_off
3123
3124Unsets the UTF8 status of an SV.
3125
3126 void SvUTF8_off(SV *sv)
3127
3128=for hackers
3129Found in file sv.h
3130
3131=item SvUTF8_on
3132
d5ce4a7c
GA
3133Turn on the UTF8 status of an SV (the data is not changed, just the flag).
3134Do not use frivolously.
914184e1
JH
3135
3136 void SvUTF8_on(SV *sv)
3137
3138=for hackers
3139Found in file sv.h
3140
954c1994
GS
3141=item SvUV
3142
645c22ef
DM
3143Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
3144for a version which guarantees to evaluate sv only once.
954c1994
GS
3145
3146 UV SvUV(SV* sv)
3147
497711e7
GS
3148=for hackers
3149Found in file sv.h
3150
8b4ac5a4 3151=item SvUVx
954c1994 3152
8b4ac5a4
JH
3153Coerces the given SV to an unsigned integer and returns it. Guarantees to
3154evaluate sv only once. Use the more efficient C<SvUV> otherwise.
954c1994 3155
8b4ac5a4 3156 UV SvUVx(SV* sv)
954c1994 3157
497711e7
GS
3158=for hackers
3159Found in file sv.h
3160
8b4ac5a4 3161=item SvUVX
645c22ef 3162
8b4ac5a4
JH
3163Returns the raw value in the SV's UV slot, without checks or conversions.
3164Only use when you are sure SvIOK is true. See also C<SvUV()>.
645c22ef 3165
8b4ac5a4 3166 UV SvUVX(SV* sv)
645c22ef
DM
3167
3168=for hackers
3169Found in file sv.h
3170
3171=item sv_2bool
3172
3173This function is only called on magical items, and is only used by
8cf8f3d1 3174sv_true() or its macro equivalent.
645c22ef
DM
3175
3176 bool sv_2bool(SV* sv)
3177
3178=for hackers
3179Found in file sv.c
3180
3181=item sv_2cv
3182
3183Using various gambits, try to get a CV from an SV; in addition, try if
3184possible to set C<*st> and C<*gvp> to the stash and GV associated with it.
3185
3186 CV* sv_2cv(SV* sv, HV** st, GV** gvp, I32 lref)
3187
3188=for hackers
3189Found in file sv.c
3190
3191=item sv_2io
3192
3193Using various gambits, try to get an IO from an SV: the IO slot if its a
3194GV; or the recursive result if we're an RV; or the IO slot of the symbol
3195named after the PV if we're a string.
3196
3197 IO* sv_2io(SV* sv)
3198
3199=for hackers
3200Found in file sv.c
3201
3202=item sv_2iv
3203
3204Return the integer value of an SV, doing any necessary string conversion,
3205magic etc. Normally used via the C<SvIV(sv)> and C<SvIVx(sv)> macros.
3206
3207 IV sv_2iv(SV* sv)
3208
3209=for hackers
3210Found in file sv.c
3211
954c1994
GS
3212=item sv_2mortal
3213
793edb8a
JH
3214Marks an existing SV as mortal. The SV will be destroyed "soon", either
3215by an explicit call to FREETMPS, or by an implicit call at places such as
3216statement boundaries. See also C<sv_newmortal> and C<sv_mortalcopy>.
954c1994
GS
3217
3218 SV* sv_2mortal(SV* sv)
3219
497711e7
GS
3220=for hackers
3221Found in file sv.c
3222
645c22ef
DM
3223=item sv_2nv
3224
3225Return the num value of an SV, doing any necessary string or integer
3226conversion, magic etc. Normally used via the C<SvNV(sv)> and C<SvNVx(sv)>
3227macros.
3228
3229 NV sv_2nv(SV* sv)
3230
3231=for hackers
3232Found in file sv.c
3233
451be7b1
DM
3234=item sv_2pvbyte
3235
3236Return a pointer to the byte-encoded representation of the SV, and set *lp
3237to its length. May cause the SV to be downgraded from UTF8 as a
3238side-effect.
3239
3240Usually accessed via the C<SvPVbyte> macro.
3241
3242 char* sv_2pvbyte(SV* sv, STRLEN* lp)
3243
3244=for hackers
3245Found in file sv.c
3246
645c22ef
DM
3247=item sv_2pvbyte_nolen
3248
3249Return a pointer to the byte-encoded representation of the SV.
3250May cause the SV to be downgraded from UTF8 as a side-effect.
3251
3252Usually accessed via the C<SvPVbyte_nolen> macro.
3253
3254 char* sv_2pvbyte_nolen(SV* sv)
3255
3256=for hackers
3257Found in file sv.c
3258
451be7b1
DM
3259=item sv_2pvutf8
3260
3261Return a pointer to the UTF8-encoded representation of the SV, and set *lp
3262to its length. May cause the SV to be upgraded to UTF8 as a side-effect.
3263
3264Usually accessed via the C<SvPVutf8> macro.
3265
3266 char* sv_2pvutf8(SV* sv, STRLEN* lp)
3267
3268=for hackers
3269Found in file sv.c
3270
645c22ef
DM
3271=item sv_2pvutf8_nolen
3272
3273Return a pointer to the UTF8-encoded representation of the SV.
3274May cause the SV to be upgraded to UTF8 as a side-effect.
3275
3276Usually accessed via the C<SvPVutf8_nolen> macro.
3277
3278 char* sv_2pvutf8_nolen(SV* sv)
3279
3280=for hackers
3281Found in file sv.c
3282
3283=item sv_2pv_flags
3284
ff276b08 3285Returns a pointer to the string value of an SV, and sets *lp to its length.
645c22ef
DM
3286If flags includes SV_GMAGIC, does an mg_get() first. Coerces sv to a string
3287if necessary.
3288Normally invoked via the C<SvPV_flags> macro. C<sv_2pv()> and C<sv_2pv_nomg>
3289usually end up here too.
3290
3291 char* sv_2pv_flags(SV* sv, STRLEN* lp, I32 flags)
3292
3293=for hackers
3294Found in file sv.c
3295
3296=item sv_2pv_nolen
3297
3298Like C<sv_2pv()>, but doesn't return the length too. You should usually
3299use the macro wrapper C<SvPV_nolen(sv)> instead.
3300 char* sv_2pv_nolen(SV* sv)
3301
3302=for hackers
3303Found in file sv.c
3304
3305=item sv_2uv
3306
3307Return the unsigned integer value of an SV, doing any necessary string
3308conversion, magic etc. Normally used via the C<SvUV(sv)> and C<SvUVx(sv)>
3309macros.
3310
3311 UV sv_2uv(SV* sv)
3312
3313=for hackers
3314Found in file sv.c
3315
3316=item sv_backoff
3317
3318Remove any string offset. You should normally use the C<SvOOK_off> macro
3319wrapper instead.
3320
3321 int sv_backoff(SV* sv)
3322
3323=for hackers
3324Found in file sv.c
3325
954c1994
GS
3326=item sv_bless
3327
3328Blesses an SV into a specified package. The SV must be an RV. The package
3329must be designated by its stash (see C<gv_stashpv()>). The reference count
3330of the SV is unaffected.
3331
3332 SV* sv_bless(SV* sv, HV* stash)
3333
497711e7
GS
3334=for hackers
3335Found in file sv.c
3336
954c1994
GS
3337=item sv_catpv
3338
3339Concatenates the string onto the end of the string which is in the SV.
d5ce4a7c
GA
3340If the SV has the UTF8 status set, then the bytes appended should be
3341valid UTF8. Handles 'get' magic, but not 'set' magic. See C<sv_catpv_mg>.
954c1994
GS
3342
3343 void sv_catpv(SV* sv, const char* ptr)
3344
497711e7
GS
3345=for hackers
3346Found in file sv.c
3347
954c1994
GS
3348=item sv_catpvf
3349
d5ce4a7c
GA
3350Processes its arguments like C<sprintf> and appends the formatted
3351output to an SV. If the appended data contains "wide" characters
3352(including, but not limited to, SVs with a UTF-8 PV formatted with %s,
3353and characters >255 formatted with %c), the original SV might get
3354upgraded to UTF-8. Handles 'get' magic, but not 'set' magic.
3355C<SvSETMAGIC()> must typically be called after calling this function
3356to handle 'set' magic.
954c1994
GS
3357
3358 void sv_catpvf(SV* sv, const char* pat, ...)
3359
497711e7
GS
3360=for hackers
3361Found in file sv.c
3362
954c1994
GS
3363=item sv_catpvf_mg
3364
3365Like C<sv_catpvf>, but also handles 'set' magic.
3366
3367 void sv_catpvf_mg(SV *sv, const char* pat, ...)
3368
497711e7
GS
3369=for hackers
3370Found in file sv.c
3371
954c1994
GS
3372=item sv_catpvn
3373
3374Concatenates the string onto the end of the string which is in the SV. The
d5ce4a7c
GA
3375C<len> indicates number of bytes to copy. If the SV has the UTF8
3376status set, then the bytes appended should be valid UTF8.
3377Handles 'get' magic, but not 'set' magic. See C<sv_catpvn_mg>.
954c1994
GS
3378
3379 void sv_catpvn(SV* sv, const char* ptr, STRLEN len)
3380
497711e7
GS
3381=for hackers
3382Found in file sv.c
3383
8d6d96c1
HS
3384=item sv_catpvn_flags
3385
3386Concatenates the string onto the end of the string which is in the SV. The
3387C<len> indicates number of bytes to copy. If the SV has the UTF8
3388status set, then the bytes appended should be valid UTF8.
3389If C<flags> has C<SV_GMAGIC> bit set, will C<mg_get> on C<dsv> if
3390appropriate, else not. C<sv_catpvn> and C<sv_catpvn_nomg> are implemented
3391in terms of this function.
3392
3393 void sv_catpvn_flags(SV* sv, const char* ptr, STRLEN len, I32 flags)
3394
3395=for hackers
3396Found in file sv.c
3397
954c1994
GS
3398=item sv_catpvn_mg
3399
3400Like C<sv_catpvn>, but also handles 'set' magic.
3401
3402 void sv_catpvn_mg(SV *sv, const char *ptr, STRLEN len)
3403
497711e7
GS
3404=for hackers
3405Found in file sv.c
3406
954c1994
GS
3407=item sv_catpv_mg
3408
3409Like C<sv_catpv>, but also handles 'set' magic.
3410
3411 void sv_catpv_mg(SV *sv, const char *ptr)
3412
497711e7
GS
3413=for hackers
3414Found in file sv.c
3415
954c1994
GS
3416=item sv_catsv
3417
1aa99e6b
IH
3418Concatenates the string from SV C<ssv> onto the end of the string in
3419SV C<dsv>. Modifies C<dsv> but not C<ssv>. Handles 'get' magic, but
3420not 'set' magic. See C<sv_catsv_mg>.
954c1994
GS
3421
3422 void sv_catsv(SV* dsv, SV* ssv)
3423
497711e7
GS
3424=for hackers
3425Found in file sv.c
3426
8d6d96c1
HS
3427=item sv_catsv_flags
3428
3429Concatenates the string from SV C<ssv> onto the end of the string in
3430SV C<dsv>. Modifies C<dsv> but not C<ssv>. If C<flags> has C<SV_GMAGIC>
3431bit set, will C<mg_get> on the SVs if appropriate, else not. C<sv_catsv>
3432and C<sv_catsv_nomg> are implemented in terms of this function.
3433
3434 void sv_catsv_flags(SV* dsv, SV* ssv, I32 flags)
3435
3436=for hackers
3437Found in file sv.c
3438
954c1994
GS
3439=item sv_catsv_mg
3440
3441Like C<sv_catsv>, but also handles 'set' magic.
3442
3443 void sv_catsv_mg(SV *dstr, SV *sstr)
3444
497711e7
GS
3445=for hackers
3446Found in file sv.c
3447
954c1994
GS
3448=item sv_chop
3449
1c846c1f 3450Efficient removal of characters from the beginning of the string buffer.
954c1994
GS
3451SvPOK(sv) must be true and the C<ptr> must be a pointer to somewhere inside
3452the string buffer. The C<ptr> becomes the first character of the adjusted
645c22ef 3453string. Uses the "OOK hack".
954c1994
GS
3454
3455 void sv_chop(SV* sv, char* ptr)
3456
497711e7
GS
3457=for hackers
3458Found in file sv.c
3459
c461cf8f
JH
3460=item sv_clear
3461
645c22ef
DM
3462Clear an SV: call any destructors, free up any memory used by the body,
3463and free the body itself. The SV's head is I<not> freed, although
3464its type is set to all 1's so that it won't inadvertently be assumed
3465to be live during global destruction etc.
3466This function should only be called when REFCNT is zero. Most of the time
3467you'll want to call C<sv_free()> (or its macro wrapper C<SvREFCNT_dec>)
3468instead.
c461cf8f
JH
3469
3470 void sv_clear(SV* sv)
3471
3472=for hackers
3473Found in file sv.c
3474
954c1994
GS
3475=item sv_cmp
3476
3477Compares the strings in two SVs. Returns -1, 0, or 1 indicating whether the
3478string in C<sv1> is less than, equal to, or greater than the string in