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