This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Typo spotted by Jarkko.
[perl5.git] / pod / perlapi.pod
CommitLineData
e0492643
NC
1-*- buffer-read-only: t -*-
2
3!!!!!!! DO NOT EDIT THIS FILE !!!!!!!
4This file is built by autodoc.pl extracting documentation from the C source
5files.
6
954c1994
GS
7=head1 NAME
8
9perlapi - autogenerated documentation for the perl public API
10
11=head1 DESCRIPTION
d8c40edc 12X<Perl API> X<API> X<api>
954c1994 13
1c846c1f
NIS
14This file contains the documentation of the perl public API generated by
15embed.pl, specifically a listing of functions, macros, flags, and variables
16that may be used by extension writers. The interfaces of any functions that
954c1994
GS
17are not listed here are subject to change without notice. For this reason,
18blindly using functions listed in proto.h is to be avoided when writing
19extensions.
20
21Note that all Perl API global variables must be referenced with the C<PL_>
22prefix. Some macros are provided for compatibility with the older,
23unadorned names, but this support may be disabled in a future release.
24
25The listing is alphabetical, case insensitive.
26
94bdecf9
JH
27
28=head1 "Gimme" Values
29
30=over 8
31
32=item GIMME
d8c40edc 33X<GIMME>
94bdecf9
JH
34
35A backward-compatible version of C<GIMME_V> which can only return
36C<G_SCALAR> or C<G_ARRAY>; in a void context, it returns C<G_SCALAR>.
37Deprecated. Use C<GIMME_V> instead.
38
39 U32 GIMME
40
41=for hackers
42Found in file op.h
43
44=item GIMME_V
d8c40edc 45X<GIMME_V>
94bdecf9
JH
46
47The XSUB-writer's equivalent to Perl's C<wantarray>. Returns C<G_VOID>,
48C<G_SCALAR> or C<G_ARRAY> for void, scalar or list context,
49respectively.
50
51 U32 GIMME_V
52
53=for hackers
54Found in file op.h
55
56=item G_ARRAY
d8c40edc 57X<G_ARRAY>
94bdecf9
JH
58
59Used to indicate list context. See C<GIMME_V>, C<GIMME> and
60L<perlcall>.
61
62=for hackers
63Found in file cop.h
64
65=item G_DISCARD
d8c40edc 66X<G_DISCARD>
94bdecf9
JH
67
68Indicates that arguments returned from a callback should be discarded. See
69L<perlcall>.
70
71=for hackers
72Found in file cop.h
73
74=item G_EVAL
d8c40edc 75X<G_EVAL>
94bdecf9
JH
76
77Used to force a Perl C<eval> wrapper around a callback. See
78L<perlcall>.
79
80=for hackers
81Found in file cop.h
82
83=item G_NOARGS
d8c40edc 84X<G_NOARGS>
94bdecf9
JH
85
86Indicates that no arguments are being sent to a callback. See
87L<perlcall>.
88
89=for hackers
90Found in file cop.h
91
92=item G_SCALAR
d8c40edc 93X<G_SCALAR>
94bdecf9
JH
94
95Used to indicate scalar context. See C<GIMME_V>, C<GIMME>, and
96L<perlcall>.
97
98=for hackers
99Found in file cop.h
100
101=item G_VOID
d8c40edc 102X<G_VOID>
94bdecf9
JH
103
104Used to indicate void context. See C<GIMME_V> and L<perlcall>.
105
106=for hackers
107Found in file cop.h
108
109
110=back
111
112=head1 Array Manipulation Functions
113
954c1994
GS
114=over 8
115
116=item AvFILL
d8c40edc 117X<AvFILL>
954c1994
GS
118
119Same as C<av_len()>. Deprecated, use C<av_len()> instead.
120
121 int AvFILL(AV* av)
122
497711e7
GS
123=for hackers
124Found in file av.h
125
954c1994 126=item av_clear
d8c40edc 127X<av_clear>
954c1994
GS
128
129Clears an array, making it empty. Does not free the memory used by the
130array itself.
131
132 void av_clear(AV* ar)
133
497711e7
GS
134=for hackers
135Found in file av.c
136
bcdf7404
YO
137=item av_create_and_push
138X<av_create_and_push>
139
140Push an SV onto the end of the array, creating the array if necessary.
141A small internal helper function to remove a commonly duplicated idiom.
142
143NOTE: this function is experimental and may change or be
144removed without notice.
145
146 void av_create_and_push(AV **const avp, SV *const val)
147
148=for hackers
149Found in file av.c
150
151=item av_create_and_unshift_one
152X<av_create_and_unshift_one>
153
154Unshifts an SV onto the beginning of the array, creating the array if
155necessary.
156A small internal helper function to remove a commonly duplicated idiom.
157
158NOTE: this function is experimental and may change or be
159removed without notice.
160
161 SV** av_create_and_unshift_one(AV **const avp, SV *const val)
162
163=for hackers
164Found in file av.c
165
f3b76584 166=item av_delete
d8c40edc 167X<av_delete>
f3b76584
SC
168
169Deletes the element indexed by C<key> from the array. Returns the
b9381830
JP
170deleted element. If C<flags> equals C<G_DISCARD>, the element is freed
171and null is returned.
f3b76584
SC
172
173 SV* av_delete(AV* ar, I32 key, I32 flags)
174
175=for hackers
176Found in file av.c
177
178=item av_exists
d8c40edc 179X<av_exists>
f3b76584
SC
180
181Returns true if the element indexed by C<key> has been initialized.
182
183This relies on the fact that uninitialized array elements are set to
184C<&PL_sv_undef>.
185
186 bool av_exists(AV* ar, I32 key)
187
188=for hackers
189Found in file av.c
190
954c1994 191=item av_extend
d8c40edc 192X<av_extend>
954c1994
GS
193
194Pre-extend an array. The C<key> is the index to which the array should be
195extended.
196
197 void av_extend(AV* ar, I32 key)
198
497711e7
GS
199=for hackers
200Found in file av.c
201
954c1994 202=item av_fetch
d8c40edc 203X<av_fetch>
954c1994
GS
204
205Returns the SV at the specified index in the array. The C<key> is the
206index. If C<lval> is set then the fetch will be part of a store. Check
207that the return value is non-null before dereferencing it to a C<SV*>.
208
96f1132b
GS
209See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for
210more information on how to use this function on tied arrays.
954c1994
GS
211
212 SV** av_fetch(AV* ar, I32 key, I32 lval)
213
497711e7
GS
214=for hackers
215Found in file av.c
216
f3b76584 217=item av_fill
d8c40edc 218X<av_fill>
f3b76584 219
1d51329b 220Set the highest index in the array to the given number, equivalent to
f3b76584
SC
221Perl's C<$#array = $fill;>.
222
1d51329b
RGS
223The number of elements in the an array will be C<fill + 1> after
224av_fill() returns. If the array was previously shorter then the
225additional elements appended are set to C<PL_sv_undef>. If the array
226was longer, then the excess elements are freed. C<av_fill(av, -1)> is
227the same as C<av_clear(av)>.
228
f3b76584
SC
229 void av_fill(AV* ar, I32 fill)
230
231=for hackers
232Found in file av.c
233
954c1994 234=item av_len
d8c40edc 235X<av_len>
954c1994 236
1d51329b
RGS
237Returns the highest index in the array. The number of elements in the
238array is C<av_len(av) + 1>. Returns -1 if the array is empty.
954c1994 239
35a4481c 240 I32 av_len(const AV* ar)
954c1994 241
497711e7
GS
242=for hackers
243Found in file av.c
244
954c1994 245=item av_make
d8c40edc 246X<av_make>
954c1994
GS
247
248Creates a new AV and populates it with a list of SVs. The SVs are copied
249into the array, so they may be freed after the call to av_make. The new AV
250will have a reference count of 1.
251
252 AV* av_make(I32 size, SV** svp)
253
497711e7
GS
254=for hackers
255Found in file av.c
256
954c1994 257=item av_pop
d8c40edc 258X<av_pop>
954c1994
GS
259
260Pops an SV off the end of the array. Returns C<&PL_sv_undef> if the array
261is empty.
262
263 SV* av_pop(AV* ar)
264
497711e7
GS
265=for hackers
266Found in file av.c
267
954c1994 268=item av_push
d8c40edc 269X<av_push>
954c1994
GS
270
271Pushes an SV onto the end of the array. The array will grow automatically
272to accommodate the addition.
273
274 void av_push(AV* ar, SV* val)
275
497711e7
GS
276=for hackers
277Found in file av.c
278
954c1994 279=item av_shift
d8c40edc 280X<av_shift>
954c1994
GS
281
282Shifts an SV off the beginning of the array.
283
284 SV* av_shift(AV* ar)
285
497711e7
GS
286=for hackers
287Found in file av.c
288
954c1994 289=item av_store
d8c40edc 290X<av_store>
954c1994
GS
291
292Stores an SV in an array. The array index is specified as C<key>. The
293return value will be NULL if the operation failed or if the value did not
294need to be actually stored within the array (as in the case of tied
295arrays). Otherwise it can be dereferenced to get the original C<SV*>. Note
296that the caller is responsible for suitably incrementing the reference
297count of C<val> before the call, and decrementing it if the function
298returned NULL.
299
96f1132b 300See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for
954c1994
GS
301more information on how to use this function on tied arrays.
302
303 SV** av_store(AV* ar, I32 key, SV* val)
304
497711e7
GS
305=for hackers
306Found in file av.c
307
954c1994 308=item av_undef
d8c40edc 309X<av_undef>
954c1994
GS
310
311Undefines the array. Frees the memory used by the array itself.
312
313 void av_undef(AV* ar)
314
497711e7
GS
315=for hackers
316Found in file av.c
317
954c1994 318=item av_unshift
d8c40edc 319X<av_unshift>
954c1994
GS
320
321Unshift the given number of C<undef> values onto the beginning of the
322array. The array will grow automatically to accommodate the addition. You
323must then use C<av_store> to assign values to these new elements.
324
325 void av_unshift(AV* ar, I32 num)
326
497711e7
GS
327=for hackers
328Found in file av.c
329
94bdecf9 330=item get_av
d8c40edc 331X<get_av>
9f2ea798 332
94bdecf9
JH
333Returns the AV of the specified Perl array. If C<create> is set and the
334Perl variable does not exist then it will be created. If C<create> is not
335set and the variable does not exist then NULL is returned.
9f2ea798 336
94bdecf9
JH
337NOTE: the perl_ form of this function is deprecated.
338
339 AV* get_av(const char* name, I32 create)
9f2ea798
DM
340
341=for hackers
94bdecf9 342Found in file perl.c
9f2ea798 343
94bdecf9 344=item newAV
d8c40edc 345X<newAV>
f9a63242 346
94bdecf9 347Creates a new AV. The reference count is set to 1.
f9a63242 348
94bdecf9
JH
349 AV* newAV()
350
351=for hackers
6fc9eaaa 352Found in file av.h
94bdecf9 353
94bdecf9 354=item sortsv
d8c40edc 355X<sortsv>
497711e7 356
94bdecf9 357Sort an array. Here is an example:
497711e7 358
94bdecf9 359 sortsv(AvARRAY(av), av_len(av)+1, Perl_sv_cmp_locale);
eebe1485 360
7b9ef140
RH
361Currently this always uses mergesort. See sortsv_flags for a more
362flexible routine.
641d4181 363
aa924a5a 364 void sortsv(SV** array, size_t num_elts, SVCOMPARE_t cmp)
497711e7
GS
365
366=for hackers
94bdecf9
JH
367Found in file pp_sort.c
368
7b9ef140
RH
369=item sortsv_flags
370X<sortsv_flags>
371
372Sort an array, with various options.
373
374 void sortsv_flags(SV** array, size_t num_elts, SVCOMPARE_t cmp, U32 flags)
375
376=for hackers
377Found in file pp_sort.c
378
94bdecf9
JH
379
380=back
381
382=head1 Callback Functions
383
384=over 8
497711e7 385
954c1994 386=item call_argv
d8c40edc 387X<call_argv>
954c1994
GS
388
389Performs a callback to the specified Perl sub. See L<perlcall>.
390
391NOTE: the perl_ form of this function is deprecated.
392
8f42b153 393 I32 call_argv(const char* sub_name, I32 flags, char** argv)
954c1994 394
497711e7
GS
395=for hackers
396Found in file perl.c
397
954c1994 398=item call_method
d8c40edc 399X<call_method>
954c1994
GS
400
401Performs a callback to the specified Perl method. The blessed object must
402be on the stack. See L<perlcall>.
403
404NOTE: the perl_ form of this function is deprecated.
405
406 I32 call_method(const char* methname, I32 flags)
407
497711e7
GS
408=for hackers
409Found in file perl.c
410
954c1994 411=item call_pv
d8c40edc 412X<call_pv>
954c1994
GS
413
414Performs a callback to the specified Perl sub. See L<perlcall>.
415
416NOTE: the perl_ form of this function is deprecated.
417
418 I32 call_pv(const char* sub_name, I32 flags)
419
497711e7
GS
420=for hackers
421Found in file perl.c
422
954c1994 423=item call_sv
d8c40edc 424X<call_sv>
954c1994
GS
425
426Performs a callback to the Perl sub whose name is in the SV. See
427L<perlcall>.
428
429NOTE: the perl_ form of this function is deprecated.
430
431 I32 call_sv(SV* sv, I32 flags)
432
497711e7
GS
433=for hackers
434Found in file perl.c
435
94bdecf9 436=item ENTER
d8c40edc 437X<ENTER>
954c1994 438
94bdecf9 439Opening bracket on a callback. See C<LEAVE> and L<perlcall>.
954c1994 440
94bdecf9 441 ENTER;
954c1994 442
497711e7 443=for hackers
94bdecf9 444Found in file scope.h
497711e7 445
94bdecf9 446=item eval_pv
d8c40edc 447X<eval_pv>
954c1994 448
94bdecf9 449Tells Perl to C<eval> the given string and return an SV* result.
954c1994 450
94bdecf9 451NOTE: the perl_ form of this function is deprecated.
954c1994 452
94bdecf9 453 SV* eval_pv(const char* p, I32 croak_on_error)
497711e7 454
94bdecf9
JH
455=for hackers
456Found in file perl.c
954c1994 457
94bdecf9 458=item eval_sv
d8c40edc 459X<eval_sv>
c9d5ac95 460
94bdecf9 461Tells Perl to C<eval> the string in the SV.
c9d5ac95 462
94bdecf9 463NOTE: the perl_ form of this function is deprecated.
954c1994 464
94bdecf9 465 I32 eval_sv(SV* sv, I32 flags)
954c1994 466
497711e7 467=for hackers
94bdecf9 468Found in file perl.c
497711e7 469
94bdecf9 470=item FREETMPS
d8c40edc 471X<FREETMPS>
954c1994 472
94bdecf9
JH
473Closing bracket for temporaries on a callback. See C<SAVETMPS> and
474L<perlcall>.
954c1994 475
94bdecf9 476 FREETMPS;
954c1994 477
497711e7 478=for hackers
94bdecf9 479Found in file scope.h
beab0874 480
94bdecf9 481=item LEAVE
d8c40edc 482X<LEAVE>
beab0874 483
94bdecf9 484Closing bracket on a callback. See C<ENTER> and L<perlcall>.
beab0874 485
94bdecf9 486 LEAVE;
beab0874
JT
487
488=for hackers
94bdecf9 489Found in file scope.h
beab0874 490
94bdecf9 491=item SAVETMPS
d8c40edc 492X<SAVETMPS>
9f2ea798 493
94bdecf9
JH
494Opening bracket for temporaries on a callback. See C<FREETMPS> and
495L<perlcall>.
9f2ea798 496
94bdecf9 497 SAVETMPS;
9f2ea798
DM
498
499=for hackers
94bdecf9 500Found in file scope.h
9f2ea798 501
9f2ea798 502
94bdecf9 503=back
9f2ea798 504
94bdecf9 505=head1 Character classes
9f2ea798 506
94bdecf9 507=over 8
9f2ea798 508
94bdecf9 509=item isALNUM
d8c40edc 510X<isALNUM>
954c1994 511
94bdecf9
JH
512Returns a boolean indicating whether the C C<char> is an ASCII alphanumeric
513character (including underscore) or digit.
954c1994 514
94bdecf9 515 bool isALNUM(char ch)
954c1994 516
497711e7 517=for hackers
94bdecf9 518Found in file handy.h
497711e7 519
94bdecf9 520=item isALPHA
d8c40edc 521X<isALPHA>
954c1994 522
94bdecf9
JH
523Returns a boolean indicating whether the C C<char> is an ASCII alphabetic
524character.
954c1994 525
94bdecf9 526 bool isALPHA(char ch)
954c1994 527
497711e7 528=for hackers
94bdecf9 529Found in file handy.h
497711e7 530
94bdecf9 531=item isDIGIT
d8c40edc 532X<isDIGIT>
954c1994 533
94bdecf9
JH
534Returns a boolean indicating whether the C C<char> is an ASCII
535digit.
954c1994 536
94bdecf9 537 bool isDIGIT(char ch)
954c1994 538
497711e7 539=for hackers
94bdecf9 540Found in file handy.h
497711e7 541
94bdecf9 542=item isLOWER
d8c40edc 543X<isLOWER>
954c1994 544
94bdecf9
JH
545Returns a boolean indicating whether the C C<char> is a lowercase
546character.
954c1994 547
94bdecf9 548 bool isLOWER(char ch)
954c1994 549
497711e7 550=for hackers
94bdecf9 551Found in file handy.h
497711e7 552
94bdecf9 553=item isSPACE
d8c40edc 554X<isSPACE>
954c1994 555
94bdecf9 556Returns a boolean indicating whether the C C<char> is whitespace.
954c1994 557
94bdecf9 558 bool isSPACE(char ch)
954c1994 559
497711e7 560=for hackers
94bdecf9 561Found in file handy.h
497711e7 562
94bdecf9 563=item isUPPER
d8c40edc 564X<isUPPER>
954c1994 565
94bdecf9
JH
566Returns a boolean indicating whether the C C<char> is an uppercase
567character.
954c1994 568
94bdecf9 569 bool isUPPER(char ch)
954c1994 570
497711e7 571=for hackers
94bdecf9 572Found in file handy.h
497711e7 573
94bdecf9 574=item toLOWER
d8c40edc 575X<toLOWER>
954c1994 576
94bdecf9 577Converts the specified character to lowercase.
954c1994 578
94bdecf9 579 char toLOWER(char ch)
954c1994 580
94bdecf9
JH
581=for hackers
582Found in file handy.h
583
584=item toUPPER
d8c40edc 585X<toUPPER>
94bdecf9
JH
586
587Converts the specified character to uppercase.
588
589 char toUPPER(char ch)
954c1994 590
497711e7 591=for hackers
94bdecf9 592Found in file handy.h
497711e7 593
954c1994 594
94bdecf9 595=back
954c1994 596
94bdecf9 597=head1 Cloning an interpreter
954c1994 598
94bdecf9
JH
599=over 8
600
601=item perl_clone
d8c40edc 602X<perl_clone>
94bdecf9
JH
603
604Create and return a new interpreter by cloning the current one.
605
4be49ee6 606perl_clone takes these flags as parameters:
c78c2b74 607
b0bc38e6
NC
608CLONEf_COPY_STACKS - is used to, well, copy the stacks also,
609without it we only clone the data and zero the stacks,
610with it we copy the stacks and the new perl interpreter is
611ready to run at the exact same point as the previous one.
612The pseudo-fork code uses COPY_STACKS while the
878090d5 613threads->create doesn't.
c78c2b74
HS
614
615CLONEf_KEEP_PTR_TABLE
b0bc38e6
NC
616perl_clone keeps a ptr_table with the pointer of the old
617variable as a key and the new variable as a value,
618this allows it to check if something has been cloned and not
619clone it again but rather just use the value and increase the
620refcount. If KEEP_PTR_TABLE is not set then perl_clone will kill
621the ptr_table using the function
622C<ptr_table_free(PL_ptr_table); PL_ptr_table = NULL;>,
623reason to keep it around is if you want to dup some of your own
624variable who are outside the graph perl scans, example of this
c78c2b74
HS
625code is in threads.xs create
626
627CLONEf_CLONE_HOST
b0bc38e6
NC
628This is a win32 thing, it is ignored on unix, it tells perls
629win32host code (which is c++) to clone itself, this is needed on
630win32 if you want to run two threads at the same time,
631if you just want to do some stuff in a separate perl interpreter
632and then throw it away and return to the original one,
c78c2b74
HS
633you don't need to do anything.
634
94bdecf9 635 PerlInterpreter* perl_clone(PerlInterpreter* interp, UV flags)
954c1994 636
497711e7 637=for hackers
94bdecf9 638Found in file sv.c
497711e7 639
954c1994 640
94bdecf9 641=back
954c1994 642
94bdecf9
JH
643=head1 CV Manipulation Functions
644
645=over 8
646
647=item CvSTASH
d8c40edc 648X<CvSTASH>
94bdecf9
JH
649
650Returns the stash of the CV.
651
652 HV* CvSTASH(CV* cv)
954c1994 653
497711e7 654=for hackers
94bdecf9 655Found in file cv.h
497711e7 656
94bdecf9 657=item get_cv
d8c40edc 658X<get_cv>
954c1994 659
36dfb072 660Uses C<strlen> to get the length of C<name>, then calls C<get_cvn_flags>.
954c1994 661
94bdecf9
JH
662NOTE: the perl_ form of this function is deprecated.
663
36dfb072
NC
664 CV* get_cv(const char* name, I32 flags)
665
666=for hackers
667Found in file perl.c
668
669=item get_cvn_flags
670X<get_cvn_flags>
671
672Returns the CV of the specified Perl subroutine. C<flags> are passed to
673C<gv_fetchpvn_flags>. If C<GV_ADD> is set and the Perl subroutine does not
674exist then it will be declared (which has the same effect as saying
675C<sub name;>). If C<GV_ADD> is not set and the subroutine does not exist
676then NULL is returned.
677
678NOTE: the perl_ form of this function is deprecated.
679
680 CV* get_cvn_flags(const char* name, STRLEN len, I32 flags)
954c1994 681
497711e7 682=for hackers
94bdecf9 683Found in file perl.c
497711e7 684
7c9e965c 685
94bdecf9 686=back
7c9e965c 687
94bdecf9 688=head1 Embedding Functions
7c9e965c 689
94bdecf9 690=over 8
7c9e965c 691
7dafbf52 692=item cv_undef
d8c40edc 693X<cv_undef>
7dafbf52
DM
694
695Clear out all the active components of a CV. This can happen either
696by an explicit C<undef &foo>, or by the reference count going to zero.
697In the former case, we keep the CvOUTSIDE pointer, so that any anonymous
698children can still follow the full lexical scope chain.
699
700 void cv_undef(CV* cv)
701
702=for hackers
703Found in file op.c
704
94bdecf9 705=item load_module
d8c40edc 706X<load_module>
7c9e965c 707
94bdecf9
JH
708Loads the module whose name is pointed to by the string part of name.
709Note that the actual module name, not its filename, should be given.
710Eg, "Foo::Bar" instead of "Foo/Bar.pm". flags can be any of
711PERL_LOADMOD_DENY, PERL_LOADMOD_NOIMPORT, or PERL_LOADMOD_IMPORT_OPS
712(or 0 for no flags). ver, if specified, provides version semantics
713similar to C<use Foo::Bar VERSION>. The optional trailing SV*
714arguments can be used to specify arguments to the module's import()
715method, similar to C<use Foo::Bar VERSION LIST>.
7c9e965c 716
94bdecf9 717 void load_module(U32 flags, SV* name, SV* ver, ...)
7c9e965c
JP
718
719=for hackers
94bdecf9 720Found in file op.c
7c9e965c 721
62375a60 722=item nothreadhook
d8c40edc 723X<nothreadhook>
62375a60
NIS
724
725Stub that provides thread hook for perl_destruct when there are
726no threads.
727
728 int nothreadhook()
729
730=for hackers
731Found in file perl.c
732
94bdecf9 733=item perl_alloc
d8c40edc 734X<perl_alloc>
954c1994 735
94bdecf9 736Allocates a new Perl interpreter. See L<perlembed>.
954c1994 737
94bdecf9 738 PerlInterpreter* perl_alloc()
954c1994 739
497711e7 740=for hackers
94bdecf9 741Found in file perl.c
497711e7 742
94bdecf9 743=item perl_construct
d8c40edc 744X<perl_construct>
89423764 745
94bdecf9 746Initializes a new Perl interpreter. See L<perlembed>.
89423764 747
94bdecf9 748 void perl_construct(PerlInterpreter* interp)
89423764
GS
749
750=for hackers
94bdecf9 751Found in file perl.c
954c1994 752
94bdecf9 753=item perl_destruct
d8c40edc 754X<perl_destruct>
954c1994 755
94bdecf9 756Shuts down a Perl interpreter. See L<perlembed>.
954c1994 757
94bdecf9 758 int perl_destruct(PerlInterpreter* interp)
954c1994 759
497711e7
GS
760=for hackers
761Found in file perl.c
762
94bdecf9 763=item perl_free
d8c40edc 764X<perl_free>
954c1994 765
94bdecf9 766Releases a Perl interpreter. See L<perlembed>.
954c1994 767
94bdecf9 768 void perl_free(PerlInterpreter* interp)
954c1994 769
497711e7
GS
770=for hackers
771Found in file perl.c
772
94bdecf9 773=item perl_parse
d8c40edc 774X<perl_parse>
954c1994 775
94bdecf9 776Tells a Perl interpreter to parse a Perl script. See L<perlembed>.
954c1994 777
94bdecf9 778 int perl_parse(PerlInterpreter* interp, XSINIT_t xsinit, int argc, char** argv, char** env)
954c1994 779
94bdecf9
JH
780=for hackers
781Found in file perl.c
782
783=item perl_run
d8c40edc 784X<perl_run>
94bdecf9
JH
785
786Tells a Perl interpreter to run. See L<perlembed>.
787
788 int perl_run(PerlInterpreter* interp)
954c1994 789
497711e7
GS
790=for hackers
791Found in file perl.c
792
94bdecf9 793=item require_pv
d8c40edc 794X<require_pv>
954c1994 795
94bdecf9
JH
796Tells Perl to C<require> the file named by the string argument. It is
797analogous to the Perl code C<eval "require '$file'">. It's even
2307c6d0 798implemented that way; consider using load_module instead.
954c1994
GS
799
800NOTE: the perl_ form of this function is deprecated.
801
94bdecf9 802 void require_pv(const char* pv)
954c1994 803
497711e7
GS
804=for hackers
805Found in file perl.c
806
954c1994 807
94bdecf9 808=back
954c1994 809
3df15adc
YO
810=head1 Functions in file dump.c
811
812
813=over 8
814
815=item pv_display
816X<pv_display>
817
818 char *pv_display(SV *dsv, const char *pv, STRLEN cur, STRLEN len,
819 STRLEN pvlim, U32 flags)
820
821Similar to
822
823 pv_escape(dsv,pv,cur,pvlim,PERL_PV_ESCAPE_QUOTE);
824
825except that an additional "\0" will be appended to the string when
826len > cur and pv[cur] is "\0".
827
828Note that the final string may be up to 7 chars longer than pvlim.
829
830 char* pv_display(SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim)
831
832=for hackers
833Found in file dump.c
834
835=item pv_escape
836X<pv_escape>
837
ddc5bc0f
YO
838 |const STRLEN count|const STRLEN max
839 |STRLEN const *escaped, const U32 flags
840
3df15adc 841Escapes at most the first "count" chars of pv and puts the results into
ddc5bc0f 842dsv such that the size of the escaped string will not exceed "max" chars
3df15adc
YO
843and will not contain any incomplete escape sequences.
844
ddc5bc0f
YO
845If flags contains PERL_PV_ESCAPE_QUOTE then any double quotes in the string
846will also be escaped.
3df15adc
YO
847
848Normally the SV will be cleared before the escaped string is prepared,
ddc5bc0f
YO
849but when PERL_PV_ESCAPE_NOCLEAR is set this will not occur.
850
38a44b82 851If PERL_PV_ESCAPE_UNI is set then the input string is treated as Unicode,
ddc5bc0f 852if PERL_PV_ESCAPE_UNI_DETECT is set then the input string is scanned
38a44b82 853using C<is_utf8_string()> to determine if it is Unicode.
ddc5bc0f
YO
854
855If PERL_PV_ESCAPE_ALL is set then all input chars will be output
856using C<\x01F1> style escapes, otherwise only chars above 255 will be
857escaped using this style, other non printable chars will use octal or
858common escaped patterns like C<\n>. If PERL_PV_ESCAPE_NOBACKSLASH
859then all chars below 255 will be treated as printable and
860will be output as literals.
861
862If PERL_PV_ESCAPE_FIRSTCHAR is set then only the first char of the
863string will be escaped, regardles of max. If the string is utf8 and
864the chars value is >255 then it will be returned as a plain hex
865sequence. Thus the output will either be a single char,
866an octal escape sequence, a special escape like C<\n> or a 3 or
867more digit hex value.
868
44a2ac75
YO
869If PERL_PV_ESCAPE_RE is set then the escape char used will be a '%' and
870not a '\\'. This is because regexes very often contain backslashed
871sequences, whereas '%' is not a particularly common character in patterns.
872
ddc5bc0f 873Returns a pointer to the escaped text as held by dsv.
3df15adc 874
ddc5bc0f
YO
875NOTE: the perl_ form of this function is deprecated.
876
877 char* pv_escape(SV *dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags)
878
879=for hackers
880Found in file dump.c
3df15adc 881
ddc5bc0f
YO
882=item pv_pretty
883X<pv_pretty>
884
885 |const STRLEN count|const STRLEN max\
886 |const char const *start_color| const char const *end_color\
887 |const U32 flags
888
889Converts a string into something presentable, handling escaping via
95b611b0 890pv_escape() and supporting quoting and ellipses.
ddc5bc0f
YO
891
892If the PERL_PV_PRETTY_QUOTE flag is set then the result will be
893double quoted with any double quotes in the string escaped. Otherwise
894if the PERL_PV_PRETTY_LTGT flag is set then the result be wrapped in
895angle brackets.
896
95b611b0
RGS
897If the PERL_PV_PRETTY_ELLIPSES flag is set and not all characters in
898string were output then an ellipsis C<...> will be appended to the
ddc5bc0f
YO
899string. Note that this happens AFTER it has been quoted.
900
901If start_color is non-null then it will be inserted after the opening
902quote (if there is one) but before the escaped text. If end_color
903is non-null then it will be inserted after the escaped text but before
95b611b0 904any quotes or ellipses.
ddc5bc0f
YO
905
906Returns a pointer to the prettified text as held by dsv.
907
3df15adc
YO
908NOTE: the perl_ form of this function is deprecated.
909
ddc5bc0f 910 char* pv_pretty(SV *dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags)
3df15adc
YO
911
912=for hackers
913Found in file dump.c
914
915
916=back
917
9244d4ad
RGS
918=head1 Functions in file mathoms.c
919
920
921=over 8
922
923=item gv_fetchmethod
924X<gv_fetchmethod>
925
926See L<gv_fetchmethod_autoload>.
927
928 GV* gv_fetchmethod(HV* stash, const char* name)
929
930=for hackers
931Found in file mathoms.c
932
b47163a2
NC
933=item pack_cat
934X<pack_cat>
935
936The engine implementing pack() Perl function. Note: parameters next_in_list and
937flags are not used. This call should not be used; use packlist instead.
938
939 void pack_cat(SV *cat, const char *pat, const char *patend, SV **beglist, SV **endlist, SV ***next_in_list, U32 flags)
940
941=for hackers
942Found in file mathoms.c
943
9244d4ad
RGS
944=item sv_2pvbyte_nolen
945X<sv_2pvbyte_nolen>
946
947Return a pointer to the byte-encoded representation of the SV.
948May cause the SV to be downgraded from UTF-8 as a side-effect.
949
950Usually accessed via the C<SvPVbyte_nolen> macro.
951
952 char* sv_2pvbyte_nolen(SV* sv)
953
954=for hackers
955Found in file mathoms.c
956
957=item sv_2pvutf8_nolen
958X<sv_2pvutf8_nolen>
959
960Return a pointer to the UTF-8-encoded representation of the SV.
961May cause the SV to be upgraded to UTF-8 as a side-effect.
962
963Usually accessed via the C<SvPVutf8_nolen> macro.
964
965 char* sv_2pvutf8_nolen(SV* sv)
966
967=for hackers
968Found in file mathoms.c
969
970=item sv_2pv_nolen
971X<sv_2pv_nolen>
972
973Like C<sv_2pv()>, but doesn't return the length too. You should usually
974use the macro wrapper C<SvPV_nolen(sv)> instead.
975 char* sv_2pv_nolen(SV* sv)
976
977=for hackers
978Found in file mathoms.c
979
980=item sv_catpvn_mg
981X<sv_catpvn_mg>
982
983Like C<sv_catpvn>, but also handles 'set' magic.
984
985 void sv_catpvn_mg(SV *sv, const char *ptr, STRLEN len)
986
987=for hackers
988Found in file mathoms.c
989
990=item sv_catsv_mg
991X<sv_catsv_mg>
992
993Like C<sv_catsv>, but also handles 'set' magic.
994
995 void sv_catsv_mg(SV *dstr, SV *sstr)
996
997=for hackers
998Found in file mathoms.c
999
1000=item sv_force_normal
1001X<sv_force_normal>
1002
1003Undo various types of fakery on an SV: if the PV is a shared string, make
1004a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
1005an xpvmg. See also C<sv_force_normal_flags>.
1006
1007 void sv_force_normal(SV *sv)
1008
1009=for hackers
1010Found in file mathoms.c
1011
1012=item sv_iv
1013X<sv_iv>
1014
1015A private implementation of the C<SvIVx> macro for compilers which can't
1016cope with complex macro expressions. Always use the macro instead.
1017
1018 IV sv_iv(SV* sv)
1019
1020=for hackers
1021Found in file mathoms.c
1022
1023=item sv_nolocking
1024X<sv_nolocking>
1025
1026Dummy routine which "locks" an SV when there is no locking module present.
1027Exists to avoid test for a NULL function pointer and because it could
1028potentially warn under some level of strict-ness.
1029
1030"Superseded" by sv_nosharing().
1031
c48640ec 1032 void sv_nolocking(SV *sv)
9244d4ad
RGS
1033
1034=for hackers
1035Found in file mathoms.c
1036
1037=item sv_nounlocking
1038X<sv_nounlocking>
1039
1040Dummy routine which "unlocks" an SV when there is no locking module present.
1041Exists to avoid test for a NULL function pointer and because it could
1042potentially warn under some level of strict-ness.
1043
1044"Superseded" by sv_nosharing().
1045
c48640ec 1046 void sv_nounlocking(SV *sv)
9244d4ad
RGS
1047
1048=for hackers
1049Found in file mathoms.c
1050
1051=item sv_nv
1052X<sv_nv>
1053
1054A private implementation of the C<SvNVx> macro for compilers which can't
1055cope with complex macro expressions. Always use the macro instead.
1056
1057 NV sv_nv(SV* sv)
1058
1059=for hackers
1060Found in file mathoms.c
1061
1062=item sv_pv
1063X<sv_pv>
1064
1065Use the C<SvPV_nolen> macro instead
1066
1067 char* sv_pv(SV *sv)
1068
1069=for hackers
1070Found in file mathoms.c
1071
1072=item sv_pvbyte
1073X<sv_pvbyte>
1074
1075Use C<SvPVbyte_nolen> instead.
1076
1077 char* sv_pvbyte(SV *sv)
1078
1079=for hackers
1080Found in file mathoms.c
1081
1082=item sv_pvbyten
1083X<sv_pvbyten>
1084
1085A private implementation of the C<SvPVbyte> macro for compilers
1086which can't cope with complex macro expressions. Always use the macro
1087instead.
1088
1089 char* sv_pvbyten(SV *sv, STRLEN *len)
1090
1091=for hackers
1092Found in file mathoms.c
1093
1094=item sv_pvn
1095X<sv_pvn>
1096
1097A private implementation of the C<SvPV> macro for compilers which can't
1098cope with complex macro expressions. Always use the macro instead.
1099
1100 char* sv_pvn(SV *sv, STRLEN *len)
1101
1102=for hackers
1103Found in file mathoms.c
1104
1105=item sv_pvutf8
1106X<sv_pvutf8>
1107
1108Use the C<SvPVutf8_nolen> macro instead
1109
1110 char* sv_pvutf8(SV *sv)
1111
1112=for hackers
1113Found in file mathoms.c
1114
1115=item sv_pvutf8n
1116X<sv_pvutf8n>
1117
1118A private implementation of the C<SvPVutf8> macro for compilers
1119which can't cope with complex macro expressions. Always use the macro
1120instead.
1121
1122 char* sv_pvutf8n(SV *sv, STRLEN *len)
1123
1124=for hackers
1125Found in file mathoms.c
1126
1127=item sv_taint
1128X<sv_taint>
1129
1130Taint an SV. Use C<SvTAINTED_on> instead.
1131 void sv_taint(SV* sv)
1132
1133=for hackers
1134Found in file mathoms.c
1135
1136=item sv_unref
1137X<sv_unref>
1138
1139Unsets the RV status of the SV, and decrements the reference count of
1140whatever was being referenced by the RV. This can almost be thought of
1141as a reversal of C<newSVrv>. This is C<sv_unref_flags> with the C<flag>
1142being zero. See C<SvROK_off>.
1143
1144 void sv_unref(SV* sv)
1145
1146=for hackers
1147Found in file mathoms.c
1148
fed01289
SP
1149=item sv_usepvn
1150X<sv_usepvn>
1151
1152Tells an SV to use C<ptr> to find its string value. Implemented by
1153calling C<sv_usepvn_flags> with C<flags> of 0, hence does not handle 'set'
1154magic. See C<sv_usepvn_flags>.
1155
1156 void sv_usepvn(SV* sv, char* ptr, STRLEN len)
1157
1158=for hackers
1159Found in file mathoms.c
1160
1161=item sv_usepvn_mg
1162X<sv_usepvn_mg>
1163
1164Like C<sv_usepvn>, but also handles 'set' magic.
1165
1166 void sv_usepvn_mg(SV *sv, char *ptr, STRLEN len)
1167
1168=for hackers
1169Found in file mathoms.c
1170
9244d4ad
RGS
1171=item sv_uv
1172X<sv_uv>
1173
1174A private implementation of the C<SvUVx> macro for compilers which can't
1175cope with complex macro expressions. Always use the macro instead.
1176
1177 UV sv_uv(SV* sv)
1178
1179=for hackers
1180Found in file mathoms.c
1181
95be277c
NC
1182=item unpack_str
1183X<unpack_str>
1184
1185The engine implementing unpack() Perl function. Note: parameters strbeg, new_s
1186and ocnt are not used. This call should not be used, use unpackstring instead.
1187
1188 I32 unpack_str(const char *pat, const char *patend, const char *s, const char *strbeg, const char *strend, char **new_s, I32 ocnt, U32 flags)
1189
1190=for hackers
1191Found in file mathoms.c
1192
9244d4ad
RGS
1193
1194=back
1195
daad78fc
RGS
1196=head1 Functions in file pp_ctl.c
1197
1198
1199=over 8
1200
1201=item find_runcv
1202X<find_runcv>
1203
1204Locate the CV corresponding to the currently executing sub or eval.
1205If db_seqp is non_null, skip CVs that are in the DB package and populate
1206*db_seqp with the cop sequence number at the point that the DB:: code was
1207entered. (allows debuggers to eval in the scope of the breakpoint rather
1208than in the scope of the debugger itself).
1209
1210 CV* find_runcv(U32 *db_seqp)
1211
1212=for hackers
1213Found in file pp_ctl.c
1214
1215
1216=back
1217
6050d10e
JP
1218=head1 Functions in file pp_pack.c
1219
1220
1221=over 8
1222
7accc089 1223=item packlist
d8c40edc 1224X<packlist>
6050d10e
JP
1225
1226The engine implementing pack() Perl function.
1227
f7fe979e 1228 void packlist(SV *cat, const char *pat, const char *patend, SV **beglist, SV **endlist)
7accc089
JH
1229
1230=for hackers
1231Found in file pp_pack.c
1232
7accc089 1233=item unpackstring
d8c40edc 1234X<unpackstring>
6050d10e 1235
608d3aed
WL
1236The engine implementing unpack() Perl function. C<unpackstring> puts the
1237extracted list items on the stack and returns the number of elements.
1238Issue C<PUTBACK> before and C<SPAGAIN> after the call to this function.
6050d10e 1239
f7fe979e 1240 I32 unpackstring(const char *pat, const char *patend, const char *s, const char *strend, U32 flags)
7accc089
JH
1241
1242=for hackers
1243Found in file pp_pack.c
1244
6050d10e
JP
1245
1246=back
1247
94bdecf9 1248=head1 GV Functions
6e9d1081 1249
94bdecf9 1250=over 8
6e9d1081 1251
954c1994 1252=item GvSV
d8c40edc 1253X<GvSV>
954c1994
GS
1254
1255Return the SV from the GV.
1256
1257 SV* GvSV(GV* gv)
1258
497711e7
GS
1259=for hackers
1260Found in file gv.h
1261
9f435386
RGS
1262=item gv_const_sv
1263X<gv_const_sv>
1264
1265If C<gv> is a typeglob whose subroutine entry is a constant sub eligible for
1266inlining, or C<gv> is a placeholder reference that would be promoted to such
1267a typeglob, then returns the value returned by the sub. Otherwise, returns
1268NULL.
1269
1270 SV* gv_const_sv(GV* gv)
1271
1272=for hackers
1273Found in file gv.c
1274
954c1994 1275=item gv_fetchmeth
d8c40edc 1276X<gv_fetchmeth>
954c1994
GS
1277
1278Returns the glob with the given C<name> and a defined subroutine or
1279C<NULL>. The glob lives in the given C<stash>, or in the stashes
a453c169 1280accessible via @ISA and UNIVERSAL::.
954c1994
GS
1281
1282The argument C<level> should be either 0 or -1. If C<level==0>, as a
1283side-effect creates a glob with the given C<name> in the given C<stash>
1284which in the case of success contains an alias for the subroutine, and sets
e1a479c5 1285up caching info for this glob.
954c1994
GS
1286
1287This function grants C<"SUPER"> token as a postfix of the stash name. The
1288GV returned from C<gv_fetchmeth> may be a method cache entry, which is not
4929bf7b 1289visible to Perl code. So when calling C<call_sv>, you should not use
954c1994 1290the GV directly; instead, you should use the method's CV, which can be
1c846c1f 1291obtained from the GV with the C<GvCV> macro.
954c1994
GS
1292
1293 GV* gv_fetchmeth(HV* stash, const char* name, STRLEN len, I32 level)
1294
497711e7
GS
1295=for hackers
1296Found in file gv.c
1297
954c1994 1298=item gv_fetchmethod_autoload
d8c40edc 1299X<gv_fetchmethod_autoload>
954c1994
GS
1300
1301Returns the glob which contains the subroutine to call to invoke the method
1302on the C<stash>. In fact in the presence of autoloading this may be the
1303glob for "AUTOLOAD". In this case the corresponding variable $AUTOLOAD is
1c846c1f 1304already setup.
954c1994
GS
1305
1306The third parameter of C<gv_fetchmethod_autoload> determines whether
1307AUTOLOAD lookup is performed if the given method is not present: non-zero
1c846c1f 1308means yes, look for AUTOLOAD; zero means no, don't look for AUTOLOAD.
954c1994 1309Calling C<gv_fetchmethod> is equivalent to calling C<gv_fetchmethod_autoload>
1c846c1f 1310with a non-zero C<autoload> parameter.
954c1994
GS
1311
1312These functions grant C<"SUPER"> token as a prefix of the method name. Note
1313that if you want to keep the returned glob for a long time, you need to
1314check for it being "AUTOLOAD", since at the later time the call may load a
1315different subroutine due to $AUTOLOAD changing its value. Use the glob
1c846c1f 1316created via a side effect to do this.
954c1994
GS
1317
1318These functions have the same side-effects and as C<gv_fetchmeth> with
1319C<level==0>. C<name> should be writable if contains C<':'> or C<'
1320''>. The warning against passing the GV returned by C<gv_fetchmeth> to
1c846c1f 1321C<call_sv> apply equally to these functions.
954c1994
GS
1322
1323 GV* gv_fetchmethod_autoload(HV* stash, const char* name, I32 autoload)
1324
497711e7
GS
1325=for hackers
1326Found in file gv.c
1327
0c81b680 1328=item gv_fetchmeth_autoload
d8c40edc 1329X<gv_fetchmeth_autoload>
0c81b680
JH
1330
1331Same as gv_fetchmeth(), but looks for autoloaded subroutines too.
1332Returns a glob for the subroutine.
1333
1334For an autoloaded subroutine without a GV, will create a GV even
1335if C<level < 0>. For an autoloaded subroutine without a stub, GvCV()
1336of the result may be zero.
1337
1338 GV* gv_fetchmeth_autoload(HV* stash, const char* name, STRLEN len, I32 level)
1339
1340=for hackers
1341Found in file gv.c
1342
954c1994 1343=item gv_stashpv
d8c40edc 1344X<gv_stashpv>
954c1994 1345
da51bb9b 1346Returns a pointer to the stash for a specified package. Uses C<strlen> to
75c442e4 1347determine the length of C<name>, then calls C<gv_stashpvn()>.
bc96cb06 1348
da51bb9b 1349 HV* gv_stashpv(const char* name, I32 flags)
bc96cb06
SH
1350
1351=for hackers
1352Found in file gv.c
1353
1354=item gv_stashpvn
d8c40edc 1355X<gv_stashpvn>
bc96cb06 1356
da51bb9b
NC
1357Returns a pointer to the stash for a specified package. The C<namelen>
1358parameter indicates the length of the C<name>, in bytes. C<flags> is passed
1359to C<gv_fetchpvn_flags()>, so if set to C<GV_ADD> then the package will be
1360created if it does not already exist. If the package does not exist and
1361C<flags> is 0 (or any other setting that does not create packages) then NULL
1362is returned.
954c1994 1363
da51bb9b
NC
1364
1365 HV* gv_stashpvn(const char* name, U32 namelen, I32 flags)
954c1994 1366
497711e7
GS
1367=for hackers
1368Found in file gv.c
1369
3fe05580
MHM
1370=item gv_stashpvs
1371X<gv_stashpvs>
1372
1373Like C<gv_stashpvn>, but takes a literal string instead of a string/length pair.
1374
1375 HV* gv_stashpvs(const char* name, I32 create)
1376
1377=for hackers
1378Found in file handy.h
1379
954c1994 1380=item gv_stashsv
d8c40edc 1381X<gv_stashsv>
954c1994 1382
da51bb9b 1383Returns a pointer to the stash for a specified package. See C<gv_stashpvn>.
954c1994 1384
da51bb9b 1385 HV* gv_stashsv(SV* sv, I32 flags)
954c1994 1386
497711e7
GS
1387=for hackers
1388Found in file gv.c
1389
954c1994 1390
94bdecf9 1391=back
954c1994 1392
94bdecf9 1393=head1 Handy Values
497711e7 1394
94bdecf9 1395=over 8
954c1994 1396
e509e693 1397=item Nullav
d8c40edc 1398X<Nullav>
497711e7 1399
e509e693 1400Null AV pointer.
954c1994 1401
94bdecf9 1402=for hackers
e509e693 1403Found in file av.h
954c1994 1404
dd2155a4 1405=item Nullch
d8c40edc 1406X<Nullch>
94bdecf9 1407
24792b8d 1408Null character pointer. (No longer available when C<PERL_CORE> is defined.)
2307c6d0 1409
497711e7 1410=for hackers
94bdecf9 1411Found in file handy.h
497711e7 1412
e509e693 1413=item Nullcv
d8c40edc 1414X<Nullcv>
e509e693
SH
1415
1416Null CV pointer.
1417
1418=for hackers
1419Found in file cv.h
1420
1421=item Nullhv
d8c40edc 1422X<Nullhv>
e509e693
SH
1423
1424Null HV pointer.
1425
1426=for hackers
1427Found in file hv.h
1428
94bdecf9 1429=item Nullsv
d8c40edc 1430X<Nullsv>
954c1994 1431
24792b8d 1432Null SV pointer. (No longer available when C<PERL_CORE> is defined.)
954c1994 1433
497711e7 1434=for hackers
94bdecf9 1435Found in file handy.h
497711e7 1436
954c1994 1437
94bdecf9 1438=back
954c1994 1439
94bdecf9 1440=head1 Hash Manipulation Functions
497711e7 1441
94bdecf9 1442=over 8
954c1994 1443
94bdecf9 1444=item get_hv
d8c40edc 1445X<get_hv>
954c1994 1446
94bdecf9
JH
1447Returns the HV of the specified Perl hash. If C<create> is set and the
1448Perl variable does not exist then it will be created. If C<create> is not
1449set and the variable does not exist then NULL is returned.
497711e7 1450
94bdecf9 1451NOTE: the perl_ form of this function is deprecated.
954c1994 1452
94bdecf9 1453 HV* get_hv(const char* name, I32 create)
954c1994 1454
497711e7 1455=for hackers
94bdecf9 1456Found in file perl.c
497711e7 1457
e509e693 1458=item HEf_SVKEY
d8c40edc 1459X<HEf_SVKEY>
e509e693
SH
1460
1461This flag, used in the length slot of hash entries and magic structures,
1462specifies the structure contains an C<SV*> pointer where a C<char*> pointer
1463is to be expected. (For information only--not to be used).
1464
1465=for hackers
1466Found in file hv.h
1467
954c1994 1468=item HeHASH
d8c40edc 1469X<HeHASH>
954c1994
GS
1470
1471Returns the computed hash stored in the hash entry.
1472
1473 U32 HeHASH(HE* he)
1474
497711e7
GS
1475=for hackers
1476Found in file hv.h
1477
954c1994 1478=item HeKEY
d8c40edc 1479X<HeKEY>
954c1994
GS
1480
1481Returns the actual pointer stored in the key slot of the hash entry. The
1482pointer may be either C<char*> or C<SV*>, depending on the value of
1483C<HeKLEN()>. Can be assigned to. The C<HePV()> or C<HeSVKEY()> macros are
1484usually preferable for finding the value of a key.
1485
1486 void* HeKEY(HE* he)
1487
497711e7
GS
1488=for hackers
1489Found in file hv.h
1490
954c1994 1491=item HeKLEN
d8c40edc 1492X<HeKLEN>
954c1994
GS
1493
1494If this is negative, and amounts to C<HEf_SVKEY>, it indicates the entry
1495holds an C<SV*> key. Otherwise, holds the actual length of the key. Can
1496be assigned to. The C<HePV()> macro is usually preferable for finding key
1497lengths.
1498
1499 STRLEN HeKLEN(HE* he)
1500
497711e7
GS
1501=for hackers
1502Found in file hv.h
1503
954c1994 1504=item HePV
d8c40edc 1505X<HePV>
954c1994
GS
1506
1507Returns the key slot of the hash entry as a C<char*> value, doing any
1508necessary dereferencing of possibly C<SV*> keys. The length of the string
1509is placed in C<len> (this is a macro, so do I<not> use C<&len>). If you do
1510not care about what the length of the key is, you may use the global
1511variable C<PL_na>, though this is rather less efficient than using a local
1512variable. Remember though, that hash keys in perl are free to contain
1513embedded nulls, so using C<strlen()> or similar is not a good way to find
1514the length of hash keys. This is very similar to the C<SvPV()> macro
1515described elsewhere in this document.
1516
1517 char* HePV(HE* he, STRLEN len)
1518
497711e7
GS
1519=for hackers
1520Found in file hv.h
1521
954c1994 1522=item HeSVKEY
d8c40edc 1523X<HeSVKEY>
954c1994 1524
458cb9d2 1525Returns the key as an C<SV*>, or C<NULL> if the hash entry does not
954c1994
GS
1526contain an C<SV*> key.
1527
1528 SV* HeSVKEY(HE* he)
1529
497711e7
GS
1530=for hackers
1531Found in file hv.h
1532
954c1994 1533=item HeSVKEY_force
d8c40edc 1534X<HeSVKEY_force>
954c1994
GS
1535
1536Returns the key as an C<SV*>. Will create and return a temporary mortal
1537C<SV*> if the hash entry contains only a C<char*> key.
1538
1539 SV* HeSVKEY_force(HE* he)
1540
497711e7
GS
1541=for hackers
1542Found in file hv.h
1543
954c1994 1544=item HeSVKEY_set
d8c40edc 1545X<HeSVKEY_set>
954c1994
GS
1546
1547Sets the key to a given C<SV*>, taking care to set the appropriate flags to
1548indicate the presence of an C<SV*> key, and returns the same
1549C<SV*>.
1550
1551 SV* HeSVKEY_set(HE* he, SV* sv)
1552
497711e7
GS
1553=for hackers
1554Found in file hv.h
1555
954c1994 1556=item HeVAL
d8c40edc 1557X<HeVAL>
954c1994
GS
1558
1559Returns the value slot (type C<SV*>) stored in the hash entry.
1560
1561 SV* HeVAL(HE* he)
1562
497711e7
GS
1563=for hackers
1564Found in file hv.h
1565
954c1994 1566=item HvNAME
d8c40edc 1567X<HvNAME>
954c1994 1568
9282b5fd
SH
1569Returns the package name of a stash, or NULL if C<stash> isn't a stash.
1570See C<SvSTASH>, C<CvSTASH>.
954c1994
GS
1571
1572 char* HvNAME(HV* stash)
1573
497711e7
GS
1574=for hackers
1575Found in file hv.h
1576
ecae49c0 1577=item hv_assert
d8c40edc 1578X<hv_assert>
ecae49c0
NC
1579
1580Check that a hash is in an internally consistent state.
1581
1582 void hv_assert(HV* tb)
1583
1584=for hackers
1585Found in file hv.c
1586
954c1994 1587=item hv_clear
d8c40edc 1588X<hv_clear>
954c1994
GS
1589
1590Clears a hash, making it empty.
1591
1592 void hv_clear(HV* tb)
1593
497711e7
GS
1594=for hackers
1595Found in file hv.c
1596
3540d4ce 1597=item hv_clear_placeholders
d8c40edc 1598X<hv_clear_placeholders>
3540d4ce
AB
1599
1600Clears any placeholders from a hash. If a restricted hash has any of its keys
1601marked as readonly and the key is subsequently deleted, the key is not actually
1602deleted but is marked by assigning it a value of &PL_sv_placeholder. This tags
1603it so it will be ignored by future operations such as iterating over the hash,
fa11829f 1604but will still allow the hash to have a value reassigned to the key at some
3540d4ce
AB
1605future point. This function clears any such placeholder keys from the hash.
1606See Hash::Util::lock_keys() for an example of its use.
1607
1608 void hv_clear_placeholders(HV* hb)
1609
1610=for hackers
1611Found in file hv.c
1612
954c1994 1613=item hv_delete
d8c40edc 1614X<hv_delete>
954c1994
GS
1615
1616Deletes a key/value pair in the hash. The value SV is removed from the
1c846c1f 1617hash and returned to the caller. The C<klen> is the length of the key.
954c1994
GS
1618The C<flags> value will normally be zero; if set to G_DISCARD then NULL
1619will be returned.
1620
da58a35d 1621 SV* hv_delete(HV* tb, const char* key, I32 klen, I32 flags)
954c1994 1622
497711e7
GS
1623=for hackers
1624Found in file hv.c
1625
954c1994 1626=item hv_delete_ent
d8c40edc 1627X<hv_delete_ent>
954c1994
GS
1628
1629Deletes a key/value pair in the hash. The value SV is removed from the
1630hash and returned to the caller. The C<flags> value will normally be zero;
1631if set to G_DISCARD then NULL will be returned. C<hash> can be a valid
1632precomputed hash value, or 0 to ask for it to be computed.
1633
1634 SV* hv_delete_ent(HV* tb, SV* key, I32 flags, U32 hash)
1635
497711e7
GS
1636=for hackers
1637Found in file hv.c
1638
954c1994 1639=item hv_exists
d8c40edc 1640X<hv_exists>
954c1994
GS
1641
1642Returns a boolean indicating whether the specified hash key exists. The
1643C<klen> is the length of the key.
1644
da58a35d 1645 bool hv_exists(HV* tb, const char* key, I32 klen)
954c1994 1646
497711e7
GS
1647=for hackers
1648Found in file hv.c
1649
954c1994 1650=item hv_exists_ent
d8c40edc 1651X<hv_exists_ent>
954c1994
GS
1652
1653Returns a boolean indicating whether the specified hash key exists. C<hash>
1654can be a valid precomputed hash value, or 0 to ask for it to be
1655computed.
1656
1657 bool hv_exists_ent(HV* tb, SV* key, U32 hash)
1658
497711e7
GS
1659=for hackers
1660Found in file hv.c
1661
954c1994 1662=item hv_fetch
d8c40edc 1663X<hv_fetch>
954c1994
GS
1664
1665Returns the SV which corresponds to the specified key in the hash. The
1666C<klen> is the length of the key. If C<lval> is set then the fetch will be
1667part of a store. Check that the return value is non-null before
f4758303 1668dereferencing it to an C<SV*>.
954c1994 1669
96f1132b 1670See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1671information on how to use this function on tied hashes.
1672
da58a35d 1673 SV** hv_fetch(HV* tb, const char* key, I32 klen, I32 lval)
954c1994 1674
497711e7
GS
1675=for hackers
1676Found in file hv.c
1677
3fe05580
MHM
1678=item hv_fetchs
1679X<hv_fetchs>
1680
1681Like C<hv_fetch>, but takes a literal string instead of a string/length pair.
1682
1683 SV** hv_fetchs(HV* tb, const char* key, I32 lval)
1684
1685=for hackers
1686Found in file handy.h
1687
954c1994 1688=item hv_fetch_ent
d8c40edc 1689X<hv_fetch_ent>
954c1994
GS
1690
1691Returns the hash entry which corresponds to the specified key in the hash.
1692C<hash> must be a valid precomputed hash number for the given C<key>, or 0
1693if you want the function to compute it. IF C<lval> is set then the fetch
1694will be part of a store. Make sure the return value is non-null before
1695accessing it. The return value when C<tb> is a tied hash is a pointer to a
1696static location, so be sure to make a copy of the structure if you need to
1c846c1f 1697store it somewhere.
954c1994 1698
96f1132b 1699See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1700information on how to use this function on tied hashes.
1701
1702 HE* hv_fetch_ent(HV* tb, SV* key, I32 lval, U32 hash)
1703
497711e7
GS
1704=for hackers
1705Found in file hv.c
1706
954c1994 1707=item hv_iterinit
d8c40edc 1708X<hv_iterinit>
954c1994
GS
1709
1710Prepares a starting point to traverse a hash table. Returns the number of
1711keys in the hash (i.e. the same as C<HvKEYS(tb)>). The return value is
1c846c1f 1712currently only meaningful for hashes without tie magic.
954c1994
GS
1713
1714NOTE: Before version 5.004_65, C<hv_iterinit> used to return the number of
1715hash buckets that happen to be in use. If you still need that esoteric
1716value, you can get it through the macro C<HvFILL(tb)>.
1717
641d4181 1718
954c1994
GS
1719 I32 hv_iterinit(HV* tb)
1720
497711e7
GS
1721=for hackers
1722Found in file hv.c
1723
954c1994 1724=item hv_iterkey
d8c40edc 1725X<hv_iterkey>
954c1994
GS
1726
1727Returns the key from the current position of the hash iterator. See
1728C<hv_iterinit>.
1729
1730 char* hv_iterkey(HE* entry, I32* retlen)
1731
497711e7
GS
1732=for hackers
1733Found in file hv.c
1734
954c1994 1735=item hv_iterkeysv
d8c40edc 1736X<hv_iterkeysv>
954c1994
GS
1737
1738Returns the key as an C<SV*> from the current position of the hash
1739iterator. The return value will always be a mortal copy of the key. Also
1740see C<hv_iterinit>.
1741
1742 SV* hv_iterkeysv(HE* entry)
1743
497711e7
GS
1744=for hackers
1745Found in file hv.c
1746
954c1994 1747=item hv_iternext
d8c40edc 1748X<hv_iternext>
954c1994
GS
1749
1750Returns entries from a hash iterator. See C<hv_iterinit>.
1751
641d4181
JH
1752You may call C<hv_delete> or C<hv_delete_ent> on the hash entry that the
1753iterator currently points to, without losing your place or invalidating your
1754iterator. Note that in this case the current entry is deleted from the hash
1755with your iterator holding the last reference to it. Your iterator is flagged
1756to free the entry on the next call to C<hv_iternext>, so you must not discard
1757your iterator immediately else the entry will leak - call C<hv_iternext> to
1758trigger the resource deallocation.
1759
954c1994
GS
1760 HE* hv_iternext(HV* tb)
1761
497711e7
GS
1762=for hackers
1763Found in file hv.c
1764
954c1994 1765=item hv_iternextsv
d8c40edc 1766X<hv_iternextsv>
954c1994
GS
1767
1768Performs an C<hv_iternext>, C<hv_iterkey>, and C<hv_iterval> in one
1769operation.
1770
1771 SV* hv_iternextsv(HV* hv, char** key, I32* retlen)
1772
497711e7
GS
1773=for hackers
1774Found in file hv.c
1775
641d4181 1776=item hv_iternext_flags
d8c40edc 1777X<hv_iternext_flags>
641d4181
JH
1778
1779Returns entries from a hash iterator. See C<hv_iterinit> and C<hv_iternext>.
1780The C<flags> value will normally be zero; if HV_ITERNEXT_WANTPLACEHOLDERS is
1781set the placeholders keys (for restricted hashes) will be returned in addition
1782to normal keys. By default placeholders are automatically skipped over.
384679aa
RGS
1783Currently a placeholder is implemented with a value that is
1784C<&Perl_sv_placeholder>. Note that the implementation of placeholders and
641d4181
JH
1785restricted hashes may change, and the implementation currently is
1786insufficiently abstracted for any change to be tidy.
1787
1788NOTE: this function is experimental and may change or be
1789removed without notice.
1790
1791 HE* hv_iternext_flags(HV* tb, I32 flags)
1792
1793=for hackers
1794Found in file hv.c
1795
954c1994 1796=item hv_iterval
d8c40edc 1797X<hv_iterval>
954c1994
GS
1798
1799Returns the value from the current position of the hash iterator. See
1800C<hv_iterkey>.
1801
1802 SV* hv_iterval(HV* tb, HE* entry)
1803
497711e7
GS
1804=for hackers
1805Found in file hv.c
1806
954c1994 1807=item hv_magic
d8c40edc 1808X<hv_magic>
954c1994
GS
1809
1810Adds magic to a hash. See C<sv_magic>.
1811
1812 void hv_magic(HV* hv, GV* gv, int how)
1813
497711e7
GS
1814=for hackers
1815Found in file hv.c
1816
a3bcc51e 1817=item hv_scalar
d8c40edc 1818X<hv_scalar>
a3bcc51e
TP
1819
1820Evaluates the hash in scalar context and returns the result. Handles magic when the hash is tied.
1821
1822 SV* hv_scalar(HV* hv)
1823
1824=for hackers
1825Found in file hv.c
1826
954c1994 1827=item hv_store
d8c40edc 1828X<hv_store>
954c1994
GS
1829
1830Stores an SV in a hash. The hash key is specified as C<key> and C<klen> is
1831the length of the key. The C<hash> parameter is the precomputed hash
1832value; if it is zero then Perl will compute it. The return value will be
1833NULL if the operation failed or if the value did not need to be actually
1834stored within the hash (as in the case of tied hashes). Otherwise it can
1835be dereferenced to get the original C<SV*>. Note that the caller is
1836responsible for suitably incrementing the reference count of C<val> before
7e8c5dac
HS
1837the call, and decrementing it if the function returned NULL. Effectively
1838a successful hv_store takes ownership of one reference to C<val>. This is
1839usually what you want; a newly created SV has a reference count of one, so
1840if all your code does is create SVs then store them in a hash, hv_store
1841will own the only reference to the new SV, and your code doesn't need to do
1842anything further to tidy up. hv_store is not implemented as a call to
1843hv_store_ent, and does not create a temporary SV for the key, so if your
1844key data is not already in SV form then use hv_store in preference to
1845hv_store_ent.
954c1994 1846
96f1132b 1847See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1848information on how to use this function on tied hashes.
1849
da58a35d 1850 SV** hv_store(HV* tb, const char* key, I32 klen, SV* val, U32 hash)
954c1994 1851
497711e7
GS
1852=for hackers
1853Found in file hv.c
1854
3fe05580
MHM
1855=item hv_stores
1856X<hv_stores>
1857
1858Like C<hv_store>, but takes a literal string instead of a string/length pair
1859and omits the hash parameter.
1860
1861 SV** hv_stores(HV* tb, const char* key, NULLOK SV* val)
1862
1863=for hackers
1864Found in file handy.h
1865
954c1994 1866=item hv_store_ent
d8c40edc 1867X<hv_store_ent>
954c1994
GS
1868
1869Stores C<val> in a hash. The hash key is specified as C<key>. The C<hash>
1870parameter is the precomputed hash value; if it is zero then Perl will
1871compute it. The return value is the new hash entry so created. It will be
1872NULL if the operation failed or if the value did not need to be actually
1873stored within the hash (as in the case of tied hashes). Otherwise the
f22d8e4b 1874contents of the return value can be accessed using the C<He?> macros
954c1994
GS
1875described here. Note that the caller is responsible for suitably
1876incrementing the reference count of C<val> before the call, and
7e8c5dac
HS
1877decrementing it if the function returned NULL. Effectively a successful
1878hv_store_ent takes ownership of one reference to C<val>. This is
1879usually what you want; a newly created SV has a reference count of one, so
1880if all your code does is create SVs then store them in a hash, hv_store
1881will own the only reference to the new SV, and your code doesn't need to do
1882anything further to tidy up. Note that hv_store_ent only reads the C<key>;
1883unlike C<val> it does not take ownership of it, so maintaining the correct
1884reference count on C<key> is entirely the caller's responsibility. hv_store
1885is not implemented as a call to hv_store_ent, and does not create a temporary
1886SV for the key, so if your key data is not already in SV form then use
1887hv_store in preference to hv_store_ent.
954c1994 1888
96f1132b 1889See L<perlguts/"Understanding the Magic of Tied Hashes and Arrays"> for more
954c1994
GS
1890information on how to use this function on tied hashes.
1891
1892 HE* hv_store_ent(HV* tb, SV* key, SV* val, U32 hash)
1893
497711e7
GS
1894=for hackers
1895Found in file hv.c
1896
954c1994 1897=item hv_undef
d8c40edc 1898X<hv_undef>
954c1994
GS
1899
1900Undefines the hash.
1901
1902 void hv_undef(HV* tb)
1903
497711e7
GS
1904=for hackers
1905Found in file hv.c
1906
94bdecf9 1907=item newHV
d8c40edc 1908X<newHV>
d2cc3551 1909
94bdecf9 1910Creates a new HV. The reference count is set to 1.
d2cc3551 1911
94bdecf9 1912 HV* newHV()
d2cc3551
JH
1913
1914=for hackers
6fc9eaaa 1915Found in file hv.h
d2cc3551 1916
954c1994 1917
94bdecf9 1918=back
954c1994 1919
94bdecf9 1920=head1 Magical Functions
954c1994 1921
94bdecf9 1922=over 8
497711e7 1923
94bdecf9 1924=item mg_clear
d8c40edc 1925X<mg_clear>
954c1994 1926
94bdecf9 1927Clear something magical that the SV represents. See C<sv_magic>.
954c1994 1928
94bdecf9 1929 int mg_clear(SV* sv)
954c1994 1930
497711e7 1931=for hackers
94bdecf9 1932Found in file mg.c
497711e7 1933
94bdecf9 1934=item mg_copy
d8c40edc 1935X<mg_copy>
954c1994 1936
94bdecf9 1937Copies the magic from one SV to another. See C<sv_magic>.
954c1994 1938
94bdecf9 1939 int mg_copy(SV* sv, SV* nsv, const char* key, I32 klen)
954c1994 1940
497711e7 1941=for hackers
94bdecf9 1942Found in file mg.c
497711e7 1943
94bdecf9 1944=item mg_find
d8c40edc 1945X<mg_find>
954c1994 1946
94bdecf9 1947Finds the magic pointer for type matching the SV. See C<sv_magic>.
954c1994 1948
35a4481c 1949 MAGIC* mg_find(const SV* sv, int type)
954c1994 1950
497711e7 1951=for hackers
94bdecf9 1952Found in file mg.c
497711e7 1953
94bdecf9 1954=item mg_free
d8c40edc 1955X<mg_free>
954c1994 1956
94bdecf9 1957Free any magic storage used by the SV. See C<sv_magic>.
954c1994 1958
94bdecf9 1959 int mg_free(SV* sv)
954c1994 1960
497711e7 1961=for hackers
94bdecf9 1962Found in file mg.c
497711e7 1963
94bdecf9 1964=item mg_get
d8c40edc 1965X<mg_get>
eebe1485 1966
94bdecf9 1967Do magic after a value is retrieved from the SV. See C<sv_magic>.
282f25c9 1968
94bdecf9 1969 int mg_get(SV* sv)
eebe1485
SC
1970
1971=for hackers
94bdecf9 1972Found in file mg.c
eebe1485 1973
94bdecf9 1974=item mg_length
d8c40edc 1975X<mg_length>
eebe1485 1976
94bdecf9 1977Report on the SV's length. See C<sv_magic>.
eebe1485 1978
94bdecf9 1979 U32 mg_length(SV* sv)
eebe1485
SC
1980
1981=for hackers
94bdecf9 1982Found in file mg.c
eebe1485 1983
94bdecf9 1984=item mg_magical
d8c40edc 1985X<mg_magical>
954c1994 1986
94bdecf9 1987Turns on the magical status of an SV. See C<sv_magic>.
954c1994 1988
94bdecf9 1989 void mg_magical(SV* sv)
954c1994 1990
497711e7 1991=for hackers
94bdecf9 1992Found in file mg.c
497711e7 1993
94bdecf9 1994=item mg_set
d8c40edc 1995X<mg_set>
954c1994 1996
94bdecf9 1997Do magic after a value is assigned to the SV. See C<sv_magic>.
954c1994 1998
94bdecf9 1999 int mg_set(SV* sv)
954c1994 2000
497711e7 2001=for hackers
94bdecf9 2002Found in file mg.c
497711e7 2003
94bdecf9 2004=item SvGETMAGIC
d8c40edc 2005X<SvGETMAGIC>
954c1994 2006
94bdecf9
JH
2007Invokes C<mg_get> on an SV if it has 'get' magic. This macro evaluates its
2008argument more than once.
954c1994 2009
94bdecf9 2010 void SvGETMAGIC(SV* sv)
954c1994 2011
497711e7 2012=for hackers
94bdecf9 2013Found in file sv.h
497711e7 2014
a4f1a029 2015=item SvLOCK
d8c40edc 2016X<SvLOCK>
a4f1a029
NIS
2017
2018Arranges for a mutual exclusion lock to be obtained on sv if a suitable module
2019has been loaded.
2020
2021 void SvLOCK(SV* sv)
2022
2023=for hackers
2024Found in file sv.h
2025
94bdecf9 2026=item SvSETMAGIC
d8c40edc 2027X<SvSETMAGIC>
7d3fb230 2028
94bdecf9
JH
2029Invokes C<mg_set> on an SV if it has 'set' magic. This macro evaluates its
2030argument more than once.
7d3fb230 2031
94bdecf9 2032 void SvSETMAGIC(SV* sv)
7d3fb230
BS
2033
2034=for hackers
94bdecf9 2035Found in file sv.h
7d3fb230 2036
94bdecf9 2037=item SvSetMagicSV
d8c40edc 2038X<SvSetMagicSV>
954c1994 2039
94bdecf9 2040Like C<SvSetSV>, but does any set magic required afterwards.
954c1994 2041
94bdecf9 2042 void SvSetMagicSV(SV* dsb, SV* ssv)
954c1994 2043
497711e7 2044=for hackers
94bdecf9 2045Found in file sv.h
497711e7 2046
a4f1a029 2047=item SvSetMagicSV_nosteal
d8c40edc 2048X<SvSetMagicSV_nosteal>
a4f1a029 2049
80663158 2050Like C<SvSetSV_nosteal>, but does any set magic required afterwards.
a4f1a029
NIS
2051
2052 void SvSetMagicSV_nosteal(SV* dsv, SV* ssv)
2053
2054=for hackers
2055Found in file sv.h
2056
94bdecf9 2057=item SvSetSV
d8c40edc 2058X<SvSetSV>
954c1994 2059
94bdecf9
JH
2060Calls C<sv_setsv> if dsv is not the same as ssv. May evaluate arguments
2061more than once.
2062
2063 void SvSetSV(SV* dsb, SV* ssv)
954c1994 2064
497711e7 2065=for hackers
94bdecf9 2066Found in file sv.h
497711e7 2067
94bdecf9 2068=item SvSetSV_nosteal
d8c40edc 2069X<SvSetSV_nosteal>
954c1994 2070
94bdecf9
JH
2071Calls a non-destructive version of C<sv_setsv> if dsv is not the same as
2072ssv. May evaluate arguments more than once.
954c1994 2073
94bdecf9 2074 void SvSetSV_nosteal(SV* dsv, SV* ssv)
954c1994 2075
497711e7 2076=for hackers
94bdecf9 2077Found in file sv.h
497711e7 2078
a4f1a029 2079=item SvSHARE
d8c40edc 2080X<SvSHARE>
a4f1a029
NIS
2081
2082Arranges for sv to be shared between threads if a suitable module
2083has been loaded.
2084
2085 void SvSHARE(SV* sv)
2086
2087=for hackers
2088Found in file sv.h
2089
e509e693 2090=item SvUNLOCK
d8c40edc 2091X<SvUNLOCK>
e509e693
SH
2092
2093Releases a mutual exclusion lock on sv if a suitable module
2094has been loaded.
2095
2096 void SvUNLOCK(SV* sv)
2097
2098=for hackers
2099Found in file sv.h
2100
954c1994 2101
94bdecf9 2102=back
954c1994 2103
94bdecf9 2104=head1 Memory Management
954c1994 2105
94bdecf9 2106=over 8
497711e7 2107
94bdecf9 2108=item Copy
d8c40edc 2109X<Copy>
954c1994 2110
94bdecf9
JH
2111The XSUB-writer's interface to the C C<memcpy> function. The C<src> is the
2112source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
2113the type. May fail on overlapping copies. See also C<Move>.
954c1994 2114
94bdecf9 2115 void Copy(void* src, void* dest, int nitems, type)
954c1994 2116
497711e7 2117=for hackers
94bdecf9 2118Found in file handy.h
497711e7 2119
e90e2364 2120=item CopyD
d8c40edc 2121X<CopyD>
e90e2364
NC
2122
2123Like C<Copy> but returns dest. Useful for encouraging compilers to tail-call
2124optimise.
2125
2126 void * CopyD(void* src, void* dest, int nitems, type)
2127
2128=for hackers
2129Found in file handy.h
2130
94bdecf9 2131=item Move
d8c40edc 2132X<Move>
954c1994 2133
94bdecf9
JH
2134The XSUB-writer's interface to the C C<memmove> function. The C<src> is the
2135source, C<dest> is the destination, C<nitems> is the number of items, and C<type> is
2136the type. Can do overlapping moves. See also C<Copy>.
954c1994 2137
94bdecf9 2138 void Move(void* src, void* dest, int nitems, type)
954c1994 2139
497711e7 2140=for hackers
94bdecf9 2141Found in file handy.h
497711e7 2142
e90e2364 2143=item MoveD
d8c40edc 2144X<MoveD>
e90e2364
NC
2145
2146Like C<Move> but returns dest. Useful for encouraging compilers to tail-call
2147optimise.
2148
2149 void * MoveD(void* src, void* dest, int nitems, type)
2150
2151=for hackers
2152Found in file handy.h
2153
a02a5408 2154=item Newx
d8c40edc 2155X<Newx>
954c1994 2156
94bdecf9 2157The XSUB-writer's interface to the C C<malloc> function.
954c1994 2158
c5008215
JC
2159In 5.9.3, Newx() and friends replace the older New() API, and drops
2160the first parameter, I<x>, a debug aid which allowed callers to identify
37b8b4c9 2161themselves. This aid has been superseded by a new build option,
c5008215
JC
2162PERL_MEM_LOG (see L<perlhack/PERL_MEM_LOG>). The older API is still
2163there for use in XS modules supporting older perls.
2164
a02a5408 2165 void Newx(void* ptr, int nitems, type)
954c1994 2166
497711e7 2167=for hackers
94bdecf9 2168Found in file handy.h
497711e7 2169
a02a5408 2170=item Newxc
d8c40edc 2171X<Newxc>
954c1994 2172
94bdecf9 2173The XSUB-writer's interface to the C C<malloc> function, with
c5008215 2174cast. See also C<Newx>.
954c1994 2175
a02a5408 2176 void Newxc(void* ptr, int nitems, type, cast)
954c1994 2177
497711e7 2178=for hackers
94bdecf9 2179Found in file handy.h
954c1994 2180
a02a5408 2181=item Newxz
d8c40edc 2182X<Newxz>
954c1994 2183
94bdecf9 2184The XSUB-writer's interface to the C C<malloc> function. The allocated
c5008215 2185memory is zeroed with C<memzero>. See also C<Newx>.
a02a5408
JC
2186
2187 void Newxz(void* ptr, int nitems, type)
954c1994 2188
497711e7
GS
2189=for hackers
2190Found in file handy.h
2191
9965345d 2192=item Poison
d8c40edc 2193X<Poison>
9965345d 2194
7e337ee0 2195PoisonWith(0xEF) for catching access to freed memory.
9965345d
JH
2196
2197 void Poison(void* dest, int nitems, type)
2198
2199=for hackers
2200Found in file handy.h
2201
3fe05580
MHM
2202=item PoisonFree
2203X<PoisonFree>
2204
2205PoisonWith(0xEF) for catching access to freed memory.
2206
2207 void PoisonFree(void* dest, int nitems, type)
2208
2209=for hackers
2210Found in file handy.h
2211
7e337ee0
JH
2212=item PoisonNew
2213X<PoisonNew>
2214
2215PoisonWith(0xAB) for catching access to allocated but uninitialized memory.
2216
2217 void PoisonNew(void* dest, int nitems, type)
2218
2219=for hackers
2220Found in file handy.h
2221
2222=item PoisonWith
2223X<PoisonWith>
2224
2225Fill up memory with a byte pattern (a byte repeated over and over
2226again) that hopefully catches attempts to access uninitialized memory.
2227
2228 void PoisonWith(void* dest, int nitems, type, U8 byte)
2229
2230=for hackers
2231Found in file handy.h
2232
94bdecf9 2233=item Renew
d8c40edc 2234X<Renew>
954c1994 2235
94bdecf9 2236The XSUB-writer's interface to the C C<realloc> function.
954c1994 2237
94bdecf9 2238 void Renew(void* ptr, int nitems, type)
954c1994 2239
497711e7
GS
2240=for hackers
2241Found in file handy.h
2242
94bdecf9 2243=item Renewc
d8c40edc 2244X<Renewc>
954c1994 2245
94bdecf9
JH
2246The XSUB-writer's interface to the C C<realloc> function, with
2247cast.
954c1994 2248
94bdecf9 2249 void Renewc(void* ptr, int nitems, type, cast)
954c1994 2250
497711e7 2251=for hackers
94bdecf9 2252Found in file handy.h
497711e7 2253
94bdecf9 2254=item Safefree
d8c40edc 2255X<Safefree>
954c1994 2256
94bdecf9 2257The XSUB-writer's interface to the C C<free> function.
954c1994 2258
94bdecf9 2259 void Safefree(void* ptr)
954c1994 2260
497711e7
GS
2261=for hackers
2262Found in file handy.h
2263
94bdecf9 2264=item savepv
d8c40edc 2265X<savepv>
954c1994 2266
641d4181
JH
2267Perl's version of C<strdup()>. Returns a pointer to a newly allocated
2268string which is a duplicate of C<pv>. The size of the string is
2269determined by C<strlen()>. The memory allocated for the new string can
2270be freed with the C<Safefree()> function.
954c1994 2271
641d4181 2272 char* savepv(const char* pv)
954c1994 2273
497711e7 2274=for hackers
94bdecf9 2275Found in file util.c
497711e7 2276
94bdecf9 2277=item savepvn
d8c40edc 2278X<savepvn>
954c1994 2279
641d4181
JH
2280Perl's version of what C<strndup()> would be if it existed. Returns a
2281pointer to a newly allocated string which is a duplicate of the first
cbf82dd0
NC
2282C<len> bytes from C<pv>, plus a trailing NUL byte. The memory allocated for
2283the new string can be freed with the C<Safefree()> function.
954c1994 2284
641d4181 2285 char* savepvn(const char* pv, I32 len)
954c1994 2286
497711e7 2287=for hackers
94bdecf9 2288Found in file util.c
497711e7 2289
3fe05580
MHM
2290=item savepvs
2291X<savepvs>
2292
2293Like C<savepvn>, but takes a literal string instead of a string/length pair.
2294
2295 char* savepvs(const char* s)
2296
2297=for hackers
2298Found in file handy.h
2299
a4f1a029 2300=item savesharedpv
d8c40edc 2301X<savesharedpv>
a4f1a029 2302
641d4181
JH
2303A version of C<savepv()> which allocates the duplicate string in memory
2304which is shared between threads.
a4f1a029 2305
641d4181 2306 char* savesharedpv(const char* pv)
a4f1a029
NIS
2307
2308=for hackers
2309Found in file util.c
2310
d9095cec
NC
2311=item savesharedpvn
2312X<savesharedpvn>
2313
2314A version of C<savepvn()> which allocates the duplicate string in memory
2315which is shared between threads. (With the specific difference that a NULL
2316pointer is not acceptable)
2317
2318 char* savesharedpvn(const char *const pv, const STRLEN len)
2319
2320=for hackers
2321Found in file util.c
2322
766f8916 2323=item savesvpv
d8c40edc 2324X<savesvpv>
766f8916 2325
9c2fe30c 2326A version of C<savepv()>/C<savepvn()> which gets the string to duplicate from
766f8916
MHM
2327the passed in SV using C<SvPV()>
2328
2329 char* savesvpv(SV* sv)
2330
2331=for hackers
2332Found in file util.c
2333
94bdecf9 2334=item StructCopy
d8c40edc 2335X<StructCopy>
954c1994 2336
94bdecf9 2337This is an architecture-independent macro to copy one structure to another.
954c1994 2338
94bdecf9 2339 void StructCopy(type src, type dest, type)
954c1994 2340
497711e7 2341=for hackers
94bdecf9 2342Found in file handy.h
497711e7 2343
94bdecf9 2344=item Zero
d8c40edc 2345X<Zero>
954c1994 2346
94bdecf9
JH
2347The XSUB-writer's interface to the C C<memzero> function. The C<dest> is the
2348destination, C<nitems> is the number of items, and C<type> is the type.
954c1994 2349
94bdecf9 2350 void Zero(void* dest, int nitems, type)
954c1994 2351
497711e7 2352=for hackers
94bdecf9 2353Found in file handy.h
497711e7 2354
e90e2364 2355=item ZeroD
d8c40edc 2356X<ZeroD>
e90e2364
NC
2357
2358Like C<Zero> but returns dest. Useful for encouraging compilers to tail-call
2359optimise.
2360
2361 void * ZeroD(void* dest, int nitems, type)
2362
2363=for hackers
2364Found in file handy.h
2365
954c1994 2366
94bdecf9 2367=back
954c1994 2368
94bdecf9 2369=head1 Miscellaneous Functions
954c1994 2370
94bdecf9 2371=over 8
497711e7 2372
94bdecf9 2373=item fbm_compile
d8c40edc 2374X<fbm_compile>
8b4ac5a4 2375
94bdecf9
JH
2376Analyses the string in order to make fast searches on it using fbm_instr()
2377-- the Boyer-Moore algorithm.
8b4ac5a4 2378
94bdecf9 2379 void fbm_compile(SV* sv, U32 flags)
8b4ac5a4
JH
2380
2381=for hackers
94bdecf9 2382Found in file util.c
8b4ac5a4 2383
94bdecf9 2384=item fbm_instr
d8c40edc 2385X<fbm_instr>
954c1994 2386
94bdecf9 2387Returns the location of the SV in the string delimited by C<str> and
bd61b366 2388C<strend>. It returns C<NULL> if the string can't be found. The C<sv>
94bdecf9
JH
2389does not have to be fbm_compiled, but the search will not be as fast
2390then.
954c1994 2391
94bdecf9 2392 char* fbm_instr(unsigned char* big, unsigned char* bigend, SV* littlesv, U32 flags)
954c1994 2393
497711e7 2394=for hackers
94bdecf9 2395Found in file util.c
497711e7 2396
94bdecf9 2397=item form
d8c40edc 2398X<form>
954c1994 2399
94bdecf9
JH
2400Takes a sprintf-style format pattern and conventional
2401(non-SV) arguments and returns the formatted string.
954c1994 2402
94bdecf9 2403 (char *) Perl_form(pTHX_ const char* pat, ...)
954c1994 2404
94bdecf9 2405can be used any place a string (char *) is required:
497711e7 2406
94bdecf9 2407 char * s = Perl_form("%d.%d",major,minor);
954c1994 2408
94bdecf9
JH
2409Uses a single private buffer so if you want to format several strings you
2410must explicitly copy the earlier strings away (and free the copies when you
2411are done).
954c1994 2412
94bdecf9 2413 char* form(const char* pat, ...)
954c1994 2414
497711e7 2415=for hackers
94bdecf9 2416Found in file util.c
497711e7 2417
94bdecf9 2418=item getcwd_sv
d8c40edc 2419X<getcwd_sv>
954c1994 2420
94bdecf9 2421Fill the sv with current working directory
954c1994 2422
94bdecf9 2423 int getcwd_sv(SV* sv)
954c1994 2424
497711e7 2425=for hackers
94bdecf9 2426Found in file util.c
497711e7 2427
d9fad198
JH
2428=item my_snprintf
2429X<my_snprintf>
2430
2431The C library C<snprintf> functionality, if available and
5b692037 2432standards-compliant (uses C<vsnprintf>, actually). However, if the
d9fad198 2433C<vsnprintf> is not available, will unfortunately use the unsafe
5b692037
JH
2434C<vsprintf> which can overrun the buffer (there is an overrun check,
2435but that may be too late). Consider using C<sv_vcatpvf> instead, or
2436getting C<vsnprintf>.
d9fad198
JH
2437
2438 int my_snprintf(char *buffer, const Size_t len, const char *format, ...)
2439
2440=for hackers
2441Found in file util.c
2442
9244d4ad
RGS
2443=item my_sprintf
2444X<my_sprintf>
2445
2446The C library C<sprintf>, wrapped if necessary, to ensure that it will return
2447the length of the string written to the buffer. Only rare pre-ANSI systems
2448need the wrapper function - usually this is a direct call to C<sprintf>.
2449
2450 int my_sprintf(char *buffer, const char *pat, ...)
2451
2452=for hackers
2453Found in file util.c
2454
d9fad198
JH
2455=item my_vsnprintf
2456X<my_vsnprintf>
2457
5b692037
JH
2458The C library C<vsnprintf> if available and standards-compliant.
2459However, if if the C<vsnprintf> is not available, will unfortunately
2460use the unsafe C<vsprintf> which can overrun the buffer (there is an
2461overrun check, but that may be too late). Consider using
2462C<sv_vcatpvf> instead, or getting C<vsnprintf>.
d9fad198
JH
2463
2464 int my_vsnprintf(char *buffer, const Size_t len, const char *format, va_list ap)
2465
2466=for hackers
2467Found in file util.c
2468
f333445c 2469=item new_version
d8c40edc 2470X<new_version>
f333445c
JP
2471
2472Returns a new version object based on the passed in SV:
2473
2474 SV *sv = new_version(SV *ver);
2475
2476Does not alter the passed in ver SV. See "upg_version" if you
2477want to upgrade the SV.
2478
2479 SV* new_version(SV *ver)
2480
2481=for hackers
2482Found in file util.c
2483
2484=item scan_version
d8c40edc 2485X<scan_version>
f333445c
JP
2486
2487Returns a pointer to the next character after the parsed
2488version string, as well as upgrading the passed in SV to
2489an RV.
2490
2491Function must be called with an already existing SV like
2492
137d6fc0 2493 sv = newSV(0);
8a0be661 2494 s = scan_version(s, SV *sv, bool qv);
f333445c
JP
2495
2496Performs some preprocessing to the string to ensure that
2497it has the correct characteristics of a version. Flags the
2498object if it contains an underscore (which denotes this
8a0be661 2499is an alpha version). The boolean qv denotes that the version
137d6fc0
JP
2500should be interpreted as if it had multiple decimals, even if
2501it doesn't.
f333445c 2502
9137345a 2503 const char* scan_version(const char *vstr, SV *sv, bool qv)
f333445c
JP
2504
2505=for hackers
2506Found in file util.c
2507
94bdecf9 2508=item strEQ
d8c40edc 2509X<strEQ>
954c1994 2510
94bdecf9 2511Test two strings to see if they are equal. Returns true or false.
954c1994 2512
94bdecf9 2513 bool strEQ(char* s1, char* s2)
954c1994 2514
497711e7 2515=for hackers
94bdecf9 2516Found in file handy.h
497711e7 2517
94bdecf9 2518=item strGE
d8c40edc 2519X<strGE>
1c846c1f 2520
94bdecf9
JH
2521Test two strings to see if the first, C<s1>, is greater than or equal to
2522the second, C<s2>. Returns true or false.
1c846c1f 2523
94bdecf9 2524 bool strGE(char* s1, char* s2)
1c846c1f
NIS
2525
2526=for hackers
94bdecf9 2527Found in file handy.h
1c846c1f 2528
94bdecf9 2529=item strGT
d8c40edc 2530X<strGT>
954c1994 2531
94bdecf9
JH
2532Test two strings to see if the first, C<s1>, is greater than the second,
2533C<s2>. Returns true or false.
954c1994 2534
94bdecf9 2535 bool strGT(char* s1, char* s2)
954c1994 2536
497711e7 2537=for hackers
94bdecf9 2538Found in file handy.h
497711e7 2539
94bdecf9 2540=item strLE
d8c40edc 2541X<strLE>
954c1994 2542
94bdecf9
JH
2543Test two strings to see if the first, C<s1>, is less than or equal to the
2544second, C<s2>. Returns true or false.
954c1994 2545
94bdecf9 2546 bool strLE(char* s1, char* s2)
954c1994 2547
497711e7 2548=for hackers
94bdecf9 2549Found in file handy.h
497711e7 2550
94bdecf9 2551=item strLT
d8c40edc 2552X<strLT>
1a3327fb 2553
94bdecf9
JH
2554Test two strings to see if the first, C<s1>, is less than the second,
2555C<s2>. Returns true or false.
1a3327fb 2556
94bdecf9 2557 bool strLT(char* s1, char* s2)
1a3327fb 2558
497711e7 2559=for hackers
94bdecf9 2560Found in file handy.h
497711e7 2561
94bdecf9 2562=item strNE
d8c40edc 2563X<strNE>
954c1994 2564
94bdecf9
JH
2565Test two strings to see if they are different. Returns true or
2566false.
2567
2568 bool strNE(char* s1, char* s2)
954c1994 2569
497711e7 2570=for hackers
94bdecf9 2571Found in file handy.h
497711e7 2572
94bdecf9 2573=item strnEQ
d8c40edc 2574X<strnEQ>
954c1994 2575
94bdecf9
JH
2576Test two strings to see if they are equal. The C<len> parameter indicates
2577the number of bytes to compare. Returns true or false. (A wrapper for
2578C<strncmp>).
2579
2580 bool strnEQ(char* s1, char* s2, STRLEN len)
954c1994 2581
497711e7 2582=for hackers
94bdecf9 2583Found in file handy.h
497711e7 2584
94bdecf9 2585=item strnNE
d8c40edc 2586X<strnNE>
954c1994 2587
94bdecf9
JH
2588Test two strings to see if they are different. The C<len> parameter
2589indicates the number of bytes to compare. Returns true or false. (A
2590wrapper for C<strncmp>).
954c1994 2591
94bdecf9 2592 bool strnNE(char* s1, char* s2, STRLEN len)
954c1994 2593
497711e7
GS
2594=for hackers
2595Found in file handy.h
2596
eba16661
JH
2597=item sv_destroyable
2598X<sv_destroyable>
2599
2600Dummy routine which reports that object can be destroyed when there is no
2601sharing module present. It ignores its single SV argument, and returns
2602'true'. Exists to avoid test for a NULL function pointer and because it
2603could potentially warn under some level of strict-ness.
2604
2605 bool sv_destroyable(SV *sv)
2606
2607=for hackers
2608Found in file util.c
2609
f333445c 2610=item sv_nosharing
d8c40edc 2611X<sv_nosharing>
f333445c
JP
2612
2613Dummy routine which "shares" an SV when there is no sharing module present.
9244d4ad
RGS
2614Or "locks" it. Or "unlocks" it. In other words, ignores its single SV argument.
2615Exists to avoid test for a NULL function pointer and because it could
2616potentially warn under some level of strict-ness.
f333445c 2617
c48640ec 2618 void sv_nosharing(SV *sv)
f333445c
JP
2619
2620=for hackers
2621Found in file util.c
2622
f333445c 2623=item upg_version
d8c40edc 2624X<upg_version>
f333445c
JP
2625
2626In-place upgrade of the supplied SV to a version object.
2627
ac0e6a2f 2628 SV *sv = upg_version(SV *sv, bool qv);
f333445c 2629
ac0e6a2f
RGS
2630Returns a pointer to the upgraded SV. Set the boolean qv if you want
2631to force this SV to be interpreted as an "extended" version.
f333445c 2632
ac0e6a2f 2633 SV* upg_version(SV *ver, bool qv)
f333445c
JP
2634
2635=for hackers
2636Found in file util.c
2637
2638=item vcmp
d8c40edc 2639X<vcmp>
f333445c
JP
2640
2641Version object aware cmp. Both operands must already have been
2642converted into version objects.
2643
2644 int vcmp(SV *lvs, SV *rvs)
2645
2646=for hackers
2647Found in file util.c
2648
b9381830 2649=item vnormal
d8c40edc 2650X<vnormal>
b9381830
JP
2651
2652Accepts a version object and returns the normalized string
2653representation. Call like:
2654
2655 sv = vnormal(rv);
2656
2657NOTE: you can pass either the object directly or the SV
2658contained within the RV.
2659
2660 SV* vnormal(SV *vs)
2661
2662=for hackers
2663Found in file util.c
2664
f333445c 2665=item vnumify
d8c40edc 2666X<vnumify>
f333445c
JP
2667
2668Accepts a version object and returns the normalized floating
2669point representation. Call like:
2670
2671 sv = vnumify(rv);
2672
2673NOTE: you can pass either the object directly or the SV
2674contained within the RV.
2675
2676 SV* vnumify(SV *vs)
2677
2678=for hackers
2679Found in file util.c
2680
2681=item vstringify
d8c40edc 2682X<vstringify>
f333445c 2683
b9381830
JP
2684In order to maintain maximum compatibility with earlier versions
2685of Perl, this function will return either the floating point
2686notation or the multiple dotted notation, depending on whether
2687the original version contained 1 or more dots, respectively
f333445c
JP
2688
2689 SV* vstringify(SV *vs)
2690
2691=for hackers
2692Found in file util.c
2693
e0218a61 2694=item vverify
d8c40edc 2695X<vverify>
e0218a61
JP
2696
2697Validates that the SV contains a valid version object.
2698
2699 bool vverify(SV *vobj);
2700
2701Note that it only confirms the bare minimum structure (so as not to get
2702confused by derived classes which may contain additional hash entries):
2703
2704 bool vverify(SV *vs)
2705
2706=for hackers
2707Found in file util.c
2708
f4758303 2709
94bdecf9 2710=back
7207e29d 2711
47c9dd14
BB
2712=head1 MRO Functions
2713
2714=over 8
2715
2716=item mro_get_linear_isa
2717X<mro_get_linear_isa>
2718
2719Returns either C<mro_get_linear_isa_c3> or
2720C<mro_get_linear_isa_dfs> for the given stash,
2721dependant upon which MRO is in effect
2722for that stash. The return value is a
2723read-only AV*.
2724
2725You are responsible for C<SvREFCNT_inc()> on the
2726return value if you plan to store it anywhere
2727semi-permanently (otherwise it might be deleted
2728out from under you the next time the cache is
2729invalidated).
2730
2731 AV* mro_get_linear_isa(HV* stash)
2732
2733=for hackers
2734Found in file mro.c
2735
47c9dd14
BB
2736=item mro_method_changed_in
2737X<mro_method_changed_in>
2738
2739Invalidates method caching on any child classes
2740of the given stash, so that they might notice
2741the changes in this one.
2742
2743Ideally, all instances of C<PL_sub_generation++> in
dd69841b
BB
2744perl source outside of C<mro.c> should be
2745replaced by calls to this.
2746
2747Perl automatically handles most of the common
2748ways a method might be redefined. However, there
2749are a few ways you could change a method in a stash
2750without the cache code noticing, in which case you
2751need to call this method afterwards:
2752
27531) Directly manipulating the stash HV entries from
2754XS code.
2755
27562) Assigning a reference to a readonly scalar
2757constant into a stash entry in order to create
2758a constant subroutine (like constant.pm
2759does).
2760
2761This same method is available from pure perl
2762via, C<mro::method_changed_in(classname)>.
47c9dd14
BB
2763
2764 void mro_method_changed_in(HV* stash)
2765
2766=for hackers
2767Found in file mro.c
2768
2769
2770=back
2771
cd299c6e
RGS
2772=head1 Multicall Functions
2773
2774=over 8
2775
2776=item dMULTICALL
2777X<dMULTICALL>
2778
2779Declare local variables for a multicall. See L<perlcall/Lightweight Callbacks>.
2780
2781 dMULTICALL;
2782
2783=for hackers
2784Found in file cop.h
2785
2786=item MULTICALL
2787X<MULTICALL>
2788
2789Make a lightweight callback. See L<perlcall/Lightweight Callbacks>.
2790
2791 MULTICALL;
2792
2793=for hackers
2794Found in file cop.h
2795
2796=item POP_MULTICALL
2797X<POP_MULTICALL>
2798
2799Closing bracket for a lightweight callback.
2800See L<perlcall/Lightweight Callbacks>.
2801
2802 POP_MULTICALL;
2803
2804=for hackers
2805Found in file cop.h
2806
2807=item PUSH_MULTICALL
2808X<PUSH_MULTICALL>
2809
2810Opening bracket for a lightweight callback.
2811See L<perlcall/Lightweight Callbacks>.
2812
2813 PUSH_MULTICALL;
2814
2815=for hackers
2816Found in file cop.h
2817
2818
2819=back
2820
94bdecf9 2821=head1 Numeric functions
7207e29d 2822
94bdecf9 2823=over 8
f4758303 2824
94bdecf9 2825=item grok_bin
d8c40edc 2826X<grok_bin>
f4758303 2827
94bdecf9
JH
2828converts a string representing a binary number to numeric form.
2829
2830On entry I<start> and I<*len> give the string to scan, I<*flags> gives
2831conversion flags, and I<result> should be NULL or a pointer to an NV.
2832The scan stops at the end of the string, or the first invalid character.
7b667b5f
MHM
2833Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
2834invalid character will also trigger a warning.
2835On return I<*len> is set to the length of the scanned string,
2836and I<*flags> gives output flags.
94bdecf9 2837
7fc63493 2838If the value is <= C<UV_MAX> it is returned as a UV, the output flags are clear,
94bdecf9
JH
2839and nothing is written to I<*result>. If the value is > UV_MAX C<grok_bin>
2840returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
2841and writes the value to I<*result> (or the value is discarded if I<result>
2842is NULL).
2843
7b667b5f 2844The binary number may optionally be prefixed with "0b" or "b" unless
94bdecf9
JH
2845C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
2846C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the binary
2847number may use '_' characters to separate digits.
2848
a3b680e6 2849 UV grok_bin(const char* start, STRLEN* len_p, I32* flags, NV *result)
f4758303
JP
2850
2851=for hackers
94bdecf9 2852Found in file numeric.c
f4758303 2853
94bdecf9 2854=item grok_hex
d8c40edc 2855X<grok_hex>
954c1994 2856
94bdecf9
JH
2857converts a string representing a hex number to numeric form.
2858
2859On entry I<start> and I<*len> give the string to scan, I<*flags> gives
2860conversion flags, and I<result> should be NULL or a pointer to an NV.
7b667b5f
MHM
2861The scan stops at the end of the string, or the first invalid character.
2862Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
2863invalid character will also trigger a warning.
2864On return I<*len> is set to the length of the scanned string,
2865and I<*flags> gives output flags.
94bdecf9
JH
2866
2867If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
2868and nothing is written to I<*result>. If the value is > UV_MAX C<grok_hex>
2869returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
2870and writes the value to I<*result> (or the value is discarded if I<result>
2871is NULL).
2872
2873The hex number may optionally be prefixed with "0x" or "x" unless
2874C<PERL_SCAN_DISALLOW_PREFIX> is set in I<*flags> on entry. If
2875C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the hex
2876number may use '_' characters to separate digits.
2877
a3b680e6 2878 UV grok_hex(const char* start, STRLEN* len_p, I32* flags, NV *result)
954c1994 2879
497711e7 2880=for hackers
94bdecf9 2881Found in file numeric.c
497711e7 2882
94bdecf9 2883=item grok_number
d8c40edc 2884X<grok_number>
954c1994 2885
94bdecf9
JH
2886Recognise (or not) a number. The type of the number is returned
2887(0 if unrecognised), otherwise it is a bit-ORed combination of
2888IS_NUMBER_IN_UV, IS_NUMBER_GREATER_THAN_UV_MAX, IS_NUMBER_NOT_INT,
2889IS_NUMBER_NEG, IS_NUMBER_INFINITY, IS_NUMBER_NAN (defined in perl.h).
2890
2891If the value of the number can fit an in UV, it is returned in the *valuep
2892IS_NUMBER_IN_UV will be set to indicate that *valuep is valid, IS_NUMBER_IN_UV
2893will never be set unless *valuep is valid, but *valuep may have been assigned
2894to during processing even though IS_NUMBER_IN_UV is not set on return.
2895If valuep is NULL, IS_NUMBER_IN_UV will be set for the same cases as when
2896valuep is non-NULL, but no actual assignment (or SEGV) will occur.
2897
2898IS_NUMBER_NOT_INT will be set with IS_NUMBER_IN_UV if trailing decimals were
2899seen (in which case *valuep gives the true value truncated to an integer), and
2900IS_NUMBER_NEG if the number is negative (in which case *valuep holds the
2901absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the
2902number is larger than a UV.
2903
2904 int grok_number(const char *pv, STRLEN len, UV *valuep)
954c1994 2905
497711e7 2906=for hackers
94bdecf9 2907Found in file numeric.c
497711e7 2908
94bdecf9 2909=item grok_numeric_radix
d8c40edc 2910X<grok_numeric_radix>
954c1994 2911
94bdecf9
JH
2912Scan and skip for a numeric decimal separator (radix).
2913
2914 bool grok_numeric_radix(const char **sp, const char *send)
954c1994 2915
497711e7 2916=for hackers
94bdecf9 2917Found in file numeric.c
497711e7 2918
94bdecf9 2919=item grok_oct
d8c40edc 2920X<grok_oct>
954c1994 2921
7b667b5f
MHM
2922converts a string representing an octal number to numeric form.
2923
2924On entry I<start> and I<*len> give the string to scan, I<*flags> gives
2925conversion flags, and I<result> should be NULL or a pointer to an NV.
2926The scan stops at the end of the string, or the first invalid character.
2927Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in I<*flags>, encountering an
2928invalid character will also trigger a warning.
2929On return I<*len> is set to the length of the scanned string,
2930and I<*flags> gives output flags.
2931
2932If the value is <= UV_MAX it is returned as a UV, the output flags are clear,
2933and nothing is written to I<*result>. If the value is > UV_MAX C<grok_oct>
2934returns UV_MAX, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
2935and writes the value to I<*result> (or the value is discarded if I<result>
2936is NULL).
2937
2938If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in I<*flags> then the octal
2939number may use '_' characters to separate digits.
94bdecf9 2940
a3b680e6 2941 UV grok_oct(const char* start, STRLEN* len_p, I32* flags, NV *result)
954c1994 2942
497711e7 2943=for hackers
94bdecf9 2944Found in file numeric.c
497711e7 2945
ed140128
AD
2946=item Perl_signbit
2947X<Perl_signbit>
2948
2949Return a non-zero integer if the sign bit on an NV is set, and 0 if
2950it is not.
2951
2952If Configure detects this system has a signbit() that will work with
2953our NVs, then we just use it via the #define in perl.h. Otherwise,
2954fall back on this implementation. As a first pass, this gets everything
2955right except -0.0. Alas, catching -0.0 is the main use for this function,
2956so this is not too helpful yet. Still, at least we have the scaffolding
2957in place to support other systems, should that prove useful.
2958
2959
2960Configure notes: This function is called 'Perl_signbit' instead of a
2961plain 'signbit' because it is easy to imagine a system having a signbit()
2962function or macro that doesn't happen to work with our particular choice
2963of NVs. We shouldn't just re-#define signbit as Perl_signbit and expect
2964the standard system headers to be happy. Also, this is a no-context
2965function (no pTHX_) because Perl_signbit() is usually re-#defined in
2966perl.h as a simple macro call to the system's signbit().
2967Users should just always call Perl_signbit().
2968
2969NOTE: this function is experimental and may change or be
2970removed without notice.
2971
2972 int Perl_signbit(NV f)
2973
2974=for hackers
2975Found in file numeric.c
2976
94bdecf9 2977=item scan_bin
d8c40edc 2978X<scan_bin>
954c1994 2979
94bdecf9
JH
2980For backwards compatibility. Use C<grok_bin> instead.
2981
73d840c0 2982 NV scan_bin(const char* start, STRLEN len, STRLEN* retlen)
954c1994 2983
497711e7 2984=for hackers
94bdecf9 2985Found in file numeric.c
497711e7 2986
94bdecf9 2987=item scan_hex
d8c40edc 2988X<scan_hex>
954c1994 2989
94bdecf9
JH
2990For backwards compatibility. Use C<grok_hex> instead.
2991
73d840c0 2992 NV scan_hex(const char* start, STRLEN len, STRLEN* retlen)
954c1994 2993
497711e7 2994=for hackers
94bdecf9 2995Found in file numeric.c
497711e7 2996
94bdecf9 2997=item scan_oct
d8c40edc 2998X<scan_oct>
954c1994 2999
94bdecf9 3000For backwards compatibility. Use C<grok_oct> instead.
954c1994 3001
73d840c0 3002 NV scan_oct(const char* start, STRLEN len, STRLEN* retlen)
954c1994 3003
497711e7 3004=for hackers
94bdecf9 3005Found in file numeric.c
497711e7 3006
645c22ef 3007
94bdecf9 3008=back
645c22ef 3009
94bdecf9
JH
3010=head1 Optree Manipulation Functions
3011
3012=over 8
3013
3014=item cv_const_sv
d8c40edc 3015X<cv_const_sv>
94bdecf9
JH
3016
3017If C<cv> is a constant sub eligible for inlining. returns the constant
3018value returned by the sub. Otherwise, returns NULL.
3019
3020Constant subs can be created with C<newCONSTSUB> or as described in
3021L<perlsub/"Constant Functions">.
3022
3023 SV* cv_const_sv(CV* cv)
645c22ef
DM
3024
3025=for hackers
94bdecf9 3026Found in file op.c
645c22ef 3027
94bdecf9 3028=item newCONSTSUB
d8c40edc 3029X<newCONSTSUB>
954c1994 3030
94bdecf9
JH
3031Creates a constant sub equivalent to Perl C<sub FOO () { 123 }> which is
3032eligible for inlining at compile-time.
954c1994 3033
e1ec3a88 3034 CV* newCONSTSUB(HV* stash, const char* name, SV* sv)
954c1994 3035
497711e7 3036=for hackers
94bdecf9 3037Found in file op.c
497711e7 3038
94bdecf9 3039=item newXS
d8c40edc 3040X<newXS>
954c1994 3041
77004dee
NC
3042Used by C<xsubpp> to hook up XSUBs as Perl subs. I<filename> needs to be
3043static storage, as it is used directly as CvFILE(), without a copy being made.
954c1994 3044
94bdecf9
JH
3045=for hackers
3046Found in file op.c
3047
3048
3049=back
3050
dd2155a4
DM
3051=head1 Pad Data Structures
3052
3053=over 8
3054
3055=item pad_sv
d8c40edc 3056X<pad_sv>
dd2155a4
DM
3057
3058Get the value at offset po in the current pad.
3059Use macro PAD_SV instead of calling this function directly.
3060
3061 SV* pad_sv(PADOFFSET po)
3062
3063=for hackers
3064Found in file pad.c
3065
3066
3067=back
907b3e23
DM
3068
3069=head1 Per-Interpreter Variables
3070
3071=over 8
3072
3073=item PL_modglobal
3074X<PL_modglobal>
3075
3076C<PL_modglobal> is a general purpose, interpreter global HV for use by
3077extensions that need to keep information on a per-interpreter basis.
3078In a pinch, it can also be used as a symbol table for extensions
3079to share data among each other. It is a good idea to use keys
3080prefixed by the package name of the extension that owns the data.
3081
3082 HV* PL_modglobal
3083
3084=for hackers
3085Found in file intrpvar.h
3086
3087=item PL_na
3088X<PL_na>
3089
3090A convenience variable which is typically used with C<SvPV> when one
3091doesn't care about the length of the string. It is usually more efficient
3092to either declare a local variable and use that instead or to use the
3093C<SvPV_nolen> macro.
3094
3095 STRLEN PL_na
3096
3097=for hackers
3098Found in file intrpvar.h
3099
3100=item PL_sv_no
3101X<PL_sv_no>
3102
3103This is the C<false> SV. See C<PL_sv_yes>. Always refer to this as
3104C<&PL_sv_no>.
3105
3106 SV PL_sv_no
3107
3108=for hackers
3109Found in file intrpvar.h
3110
3111=item PL_sv_undef
3112X<PL_sv_undef>
3113
3114This is the C<undef> SV. Always refer to this as C<&PL_sv_undef>.
3115
3116 SV PL_sv_undef
3117
3118=for hackers
3119Found in file intrpvar.h
3120
3121=item PL_sv_yes
3122X<PL_sv_yes>
3123
3124This is the C<true> SV. See C<PL_sv_no>. Always refer to this as
3125C<&PL_sv_yes>.
3126
3127 SV PL_sv_yes
3128
3129=for hackers
3130Found in file intrpvar.h
3131
3132
3133=back
f7e71195
AB
3134
3135=head1 REGEXP Functions
3136
3137=over 8
3138
3139=item SvRX
3140X<SvRX>
3141
3142Convenience macro to get the REGEXP from a SV. This is approximately
3143equivalent to the following snippet:
3144
3145 if (SvMAGICAL(sv))
3146 mg_get(sv);
3147 if (SvROK(sv) &&
3148 (tmpsv = (SV*)SvRV(sv)) &&
3149 SvTYPE(tmpsv) == SVt_PVMG &&
3150 (tmpmg = mg_find(tmpsv, PERL_MAGIC_qr)))
3151 {
3152 return (REGEXP *)tmpmg->mg_obj;
3153 }
3154
3155NULL will be returned if a REGEXP* is not found.
3156
3157 REGEXP * SvRX(SV *sv)
3158
3159=for hackers
3160Found in file regexp.h
3161
3162=item SvRXOK
3163X<SvRXOK>
3164
3165Returns a boolean indicating whether the SV contains qr magic
3166(PERL_MAGIC_qr).
3167
3168If you want to do something with the REGEXP* later use SvRX instead
3169and check for NULL.
3170
3171 bool SvRXOK(SV* sv)
3172
3173=for hackers
3174Found in file regexp.h
3175
3176
3177=back
dd2155a4 3178
59887a99
MHM
3179=head1 Simple Exception Handling Macros
3180
3181=over 8
3182
3183=item dXCPT
d8c40edc 3184X<dXCPT>
59887a99 3185
2dfe1b17 3186Set up necessary local variables for exception handling.
59887a99
MHM
3187See L<perlguts/"Exception Handling">.
3188
3189 dXCPT;
3190
3191=for hackers
3192Found in file XSUB.h
3193
3194=item XCPT_CATCH
d8c40edc 3195X<XCPT_CATCH>
59887a99
MHM
3196
3197Introduces a catch block. See L<perlguts/"Exception Handling">.
3198
3199=for hackers
3200Found in file XSUB.h
3201
3202=item XCPT_RETHROW
d8c40edc 3203X<XCPT_RETHROW>
59887a99
MHM
3204
3205Rethrows a previously caught exception. See L<perlguts/"Exception Handling">.
3206
3207 XCPT_RETHROW;
3208
3209=for hackers
3210Found in file XSUB.h
3211
3212=item XCPT_TRY_END
d8c40edc 3213X<XCPT_TRY_END>
59887a99
MHM
3214
3215Ends a try block. See L<perlguts/"Exception Handling">.
3216
3217=for hackers
3218Found in file XSUB.h
3219
3220=item XCPT_TRY_START
d8c40edc 3221X<XCPT_TRY_START>
59887a99
MHM
3222
3223Starts a try block. See L<perlguts/"Exception Handling">.
3224
3225=for hackers
3226Found in file XSUB.h
3227
3228
3229=back
3230
94bdecf9
JH
3231=head1 Stack Manipulation Macros
3232
3233=over 8
3234
3235=item dMARK
d8c40edc 3236X<dMARK>
954c1994 3237
94bdecf9
JH
3238Declare a stack marker variable, C<mark>, for the XSUB. See C<MARK> and
3239C<dORIGMARK>.
954c1994 3240
94bdecf9 3241 dMARK;
954c1994 3242
497711e7 3243=for hackers
94bdecf9 3244Found in file pp.h
497711e7 3245
94bdecf9 3246=item dORIGMARK
d8c40edc 3247X<dORIGMARK>
954c1994 3248
94bdecf9 3249Saves the original stack mark for the XSUB. See C<ORIGMARK>.
954c1994 3250
94bdecf9 3251 dORIGMARK;
954c1994 3252
497711e7 3253=for hackers
94bdecf9 3254Found in file pp.h
497711e7 3255
94bdecf9 3256=item dSP
d8c40edc 3257X<dSP>
954c1994 3258
94bdecf9
JH
3259Declares a local copy of perl's stack pointer for the XSUB, available via
3260the C<SP> macro. See C<SP>.
954c1994 3261
94bdecf9 3262 dSP;
954c1994 3263
497711e7 3264=for hackers
94bdecf9 3265Found in file pp.h
497711e7 3266
94bdecf9 3267=item EXTEND
d8c40edc 3268X<EXTEND>
954c1994 3269
94bdecf9
JH
3270Used to extend the argument stack for an XSUB's return values. Once
3271used, guarantees that there is room for at least C<nitems> to be pushed
3272onto the stack.
954c1994 3273
94bdecf9 3274 void EXTEND(SP, int nitems)
954c1994 3275
497711e7 3276=for hackers
94bdecf9 3277Found in file pp.h
954c1994 3278
94bdecf9 3279=item MARK
d8c40edc 3280X<MARK>
954c1994 3281
94bdecf9 3282Stack marker variable for the XSUB. See C<dMARK>.
954c1994 3283
497711e7 3284=for hackers
94bdecf9 3285Found in file pp.h
954c1994 3286
d82b684c 3287=item mPUSHi
d8c40edc 3288X<mPUSHi>
d82b684c
SH
3289
3290Push an integer onto the stack. The stack must have room for this element.
de4f2208
RGS
3291Handles 'set' magic. Does not use C<TARG>. See also C<PUSHi>, C<mXPUSHi>
3292and C<XPUSHi>.
d82b684c
SH
3293
3294 void mPUSHi(IV iv)
3295
3296=for hackers
3297Found in file pp.h
3298
3299=item mPUSHn
d8c40edc 3300X<mPUSHn>
d82b684c
SH
3301
3302Push a double onto the stack. The stack must have room for this element.
de4f2208
RGS
3303Handles 'set' magic. Does not use C<TARG>. See also C<PUSHn>, C<mXPUSHn>
3304and C<XPUSHn>.
d82b684c
SH
3305
3306 void mPUSHn(NV nv)
3307
3308=for hackers
3309Found in file pp.h
3310
3311=item mPUSHp
d8c40edc 3312X<mPUSHp>
d82b684c
SH
3313
3314Push a string onto the stack. The stack must have room for this element.
de4f2208
RGS
3315The C<len> indicates the length of the string. Handles 'set' magic. Does
3316not use C<TARG>. See also C<PUSHp>, C<mXPUSHp> and C<XPUSHp>.
d82b684c
SH
3317
3318 void mPUSHp(char* str, STRLEN len)
3319
3320=for hackers
3321Found in file pp.h
3322
3323=item mPUSHu
d8c40edc 3324X<mPUSHu>
d82b684c
SH
3325
3326Push an unsigned integer onto the stack. The stack must have room for this
de4f2208
RGS
3327element. Handles 'set' magic. Does not use C<TARG>. See also C<PUSHu>,
3328C<mXPUSHu> and C<XPUSHu>.
d82b684c
SH
3329
3330 void mPUSHu(UV uv)
3331
3332=for hackers
3333Found in file pp.h
3334
3335=item mXPUSHi
d8c40edc 3336X<mXPUSHi>
d82b684c 3337
de4f2208
RGS
3338Push an integer onto the stack, extending the stack if necessary. Handles
3339'set' magic. Does not use C<TARG>. See also C<XPUSHi>, C<mPUSHi> and
3340C<PUSHi>.
d82b684c
SH
3341
3342 void mXPUSHi(IV iv)
3343
3344=for hackers
3345Found in file pp.h
3346
3347=item mXPUSHn
d8c40edc 3348X<mXPUSHn>
d82b684c 3349
de4f2208
RGS
3350Push a double onto the stack, extending the stack if necessary. Handles
3351'set' magic. Does not use C<TARG>. See also C<XPUSHn>, C<mPUSHn> and
3352C<PUSHn>.
d82b684c
SH
3353
3354 void mXPUSHn(NV nv)
3355
3356=for hackers
3357Found in file pp.h
3358
3359=item mXPUSHp
d8c40edc 3360X<mXPUSHp>
d82b684c
SH
3361
3362Push a string onto the stack, extending the stack if necessary. The C<len>
de4f2208
RGS
3363indicates the length of the string. Handles 'set' magic. Does not use
3364C<TARG>. See also C<XPUSHp>, C<mPUSHp> and C<PUSHp>.
d82b684c
SH
3365
3366 void mXPUSHp(char* str, STRLEN len)
3367
3368=for hackers
3369Found in file pp.h
3370
3371=item mXPUSHu
d8c40edc 3372X<mXPUSHu>
d82b684c
SH
3373
3374Push an unsigned integer onto the stack, extending the stack if necessary.
de4f2208
RGS
3375Handles 'set' magic. Does not use C<TARG>. See also C<XPUSHu>, C<mPUSHu>
3376and C<PUSHu>.
d82b684c
SH
3377
3378 void mXPUSHu(UV uv)
3379
3380=for hackers
3381Found in file pp.h
3382
94bdecf9 3383=item ORIGMARK
d8c40edc 3384X<ORIGMARK>
954c1994 3385
94bdecf9 3386The original stack mark for the XSUB. See C<dORIGMARK>.
954c1994 3387
497711e7 3388=for hackers
94bdecf9 3389Found in file pp.h
497711e7 3390
954c1994 3391=item POPi
d8c40edc 3392X<POPi>
954c1994
GS
3393
3394Pops an integer off the stack.
3395
3396 IV POPi
3397
497711e7
GS
3398=for hackers
3399Found in file pp.h
3400
954c1994 3401=item POPl
d8c40edc 3402X<POPl>
954c1994
GS
3403
3404Pops a long off the stack.
3405
3406 long POPl
3407
497711e7
GS
3408=for hackers
3409Found in file pp.h
3410
954c1994 3411=item POPn
d8c40edc 3412X<POPn>
954c1994
GS
3413
3414Pops a double off the stack.
3415
3416 NV POPn
3417
497711e7
GS
3418=for hackers
3419Found in file pp.h
3420
954c1994 3421=item POPp
d8c40edc 3422X<POPp>
954c1994 3423
184499a4 3424Pops a string off the stack. Deprecated. New code should use POPpx.
954c1994
GS
3425
3426 char* POPp
3427
497711e7
GS
3428=for hackers
3429Found in file pp.h
3430
fa519979 3431=item POPpbytex
d8c40edc 3432X<POPpbytex>
fa519979
JH
3433
3434Pops a string off the stack which must consist of bytes i.e. characters < 256.
fa519979
JH
3435
3436 char* POPpbytex
3437
3438=for hackers
3439Found in file pp.h
3440
3441=item POPpx
d8c40edc 3442X<POPpx>
fa519979
JH
3443
3444Pops a string off the stack.
fa519979
JH
3445
3446 char* POPpx
3447
3448=for hackers
3449Found in file pp.h
3450
954c1994 3451=item POPs
d8c40edc 3452X<POPs>
954c1994
GS
3453
3454Pops an SV off the stack.
3455
3456 SV* POPs
3457
497711e7
GS
3458=for hackers
3459Found in file pp.h
3460
954c1994 3461=item PUSHi
d8c40edc 3462X<PUSHi>
954c1994
GS
3463
3464Push an integer onto the stack. The stack must have room for this element.
d82b684c
SH
3465Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
3466called to declare it. Do not call multiple C<TARG>-oriented macros to
3467return lists from XSUB's - see C<mPUSHi> instead. See also C<XPUSHi> and
3468C<mXPUSHi>.
954c1994
GS
3469
3470 void PUSHi(IV iv)
3471
497711e7
GS
3472=for hackers
3473Found in file pp.h
3474
954c1994 3475=item PUSHMARK
d8c40edc 3476X<PUSHMARK>
954c1994
GS
3477
3478Opening bracket for arguments on a callback. See C<PUTBACK> and
3479L<perlcall>.
3480
c578083c 3481 void PUSHMARK(SP)
954c1994 3482
497711e7
GS
3483=for hackers
3484Found in file pp.h
3485
d82b684c 3486=item PUSHmortal
d8c40edc 3487X<PUSHmortal>
d82b684c
SH
3488
3489Push a new mortal SV onto the stack. The stack must have room for this
3490element. Does not handle 'set' magic. Does not use C<TARG>. See also
3491C<PUSHs>, C<XPUSHmortal> and C<XPUSHs>.
3492
3493 void PUSHmortal()
3494
3495=for hackers
3496Found in file pp.h
3497
954c1994 3498=item PUSHn
d8c40edc 3499X<PUSHn>
954c1994
GS
3500
3501Push a double onto the stack. The stack must have room for this element.
d82b684c
SH
3502Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
3503called to declare it. Do not call multiple C<TARG>-oriented macros to
3504return lists from XSUB's - see C<mPUSHn> instead. See also C<XPUSHn> and
3505C<mXPUSHn>.
954c1994
GS
3506
3507 void PUSHn(NV nv)
3508
497711e7
GS
3509=for hackers
3510Found in file pp.h
3511
954c1994 3512=item PUSHp
d8c40edc 3513X<PUSHp>
954c1994
GS
3514
3515Push a string onto the stack. The stack must have room for this element.
d82b684c
SH
3516The C<len> indicates the length of the string. Handles 'set' magic. Uses
3517C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to declare it. Do not
3518call multiple C<TARG>-oriented macros to return lists from XSUB's - see
3519C<mPUSHp> instead. See also C<XPUSHp> and C<mXPUSHp>.
954c1994
GS
3520
3521 void PUSHp(char* str, STRLEN len)
3522
497711e7
GS
3523=for hackers
3524Found in file pp.h
3525
954c1994 3526=item PUSHs
d8c40edc 3527X<PUSHs>
954c1994 3528
1c846c1f 3529Push an SV onto the stack. The stack must have room for this element.
d82b684c
SH
3530Does not handle 'set' magic. Does not use C<TARG>. See also C<PUSHmortal>,
3531C<XPUSHs> and C<XPUSHmortal>.
954c1994
GS
3532
3533 void PUSHs(SV* sv)
3534
497711e7
GS
3535=for hackers
3536Found in file pp.h
3537
954c1994 3538=item PUSHu
d8c40edc 3539X<PUSHu>
954c1994
GS
3540
3541Push an unsigned integer onto the stack. The stack must have room for this
d82b684c
SH
3542element. Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG>
3543should be called to declare it. Do not call multiple C<TARG>-oriented
3544macros to return lists from XSUB's - see C<mPUSHu> instead. See also
3545C<XPUSHu> and C<mXPUSHu>.
954c1994
GS
3546
3547 void PUSHu(UV uv)
3548
497711e7
GS
3549=for hackers
3550Found in file pp.h
3551
954c1994 3552=item PUTBACK
d8c40edc 3553X<PUTBACK>
954c1994
GS
3554
3555Closing bracket for XSUB arguments. This is usually handled by C<xsubpp>.
3556See C<PUSHMARK> and L<perlcall> for other uses.
3557
3558 PUTBACK;
3559
497711e7
GS
3560=for hackers
3561Found in file pp.h
3562
94bdecf9 3563=item SP
d8c40edc 3564X<SP>
d2cc3551 3565
94bdecf9
JH
3566Stack pointer. This is usually handled by C<xsubpp>. See C<dSP> and
3567C<SPAGAIN>.
d2cc3551 3568
94bdecf9
JH
3569=for hackers
3570Found in file pp.h
3571
3572=item SPAGAIN
d8c40edc 3573X<SPAGAIN>
94bdecf9
JH
3574
3575Refetch the stack pointer. Used after a callback. See L<perlcall>.
3576
3577 SPAGAIN;
d2cc3551
JH
3578
3579=for hackers
94bdecf9 3580Found in file pp.h
d2cc3551 3581
94bdecf9 3582=item XPUSHi
d8c40edc 3583X<XPUSHi>
954c1994 3584
94bdecf9 3585Push an integer onto the stack, extending the stack if necessary. Handles
d82b684c
SH
3586'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
3587declare it. Do not call multiple C<TARG>-oriented macros to return lists
3588from XSUB's - see C<mXPUSHi> instead. See also C<PUSHi> and C<mPUSHi>.
954c1994 3589
94bdecf9 3590 void XPUSHi(IV iv)
954c1994 3591
497711e7 3592=for hackers
94bdecf9 3593Found in file pp.h
497711e7 3594
d82b684c 3595=item XPUSHmortal
d8c40edc 3596X<XPUSHmortal>
d82b684c
SH
3597
3598Push a new mortal SV onto the stack, extending the stack if necessary. Does
3599not handle 'set' magic. Does not use C<TARG>. See also C<XPUSHs>,
3600C<PUSHmortal> and C<PUSHs>.
3601
3602 void XPUSHmortal()
3603
3604=for hackers
3605Found in file pp.h
3606
94bdecf9 3607=item XPUSHn
d8c40edc 3608X<XPUSHn>
954c1994 3609
94bdecf9 3610Push a double onto the stack, extending the stack if necessary. Handles
d82b684c
SH
3611'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be called to
3612declare it. Do not call multiple C<TARG>-oriented macros to return lists
3613from XSUB's - see C<mXPUSHn> instead. See also C<PUSHn> and C<mPUSHn>.
954c1994 3614
94bdecf9 3615 void XPUSHn(NV nv)
954c1994 3616
497711e7 3617=for hackers
94bdecf9 3618Found in file pp.h
497711e7 3619
94bdecf9 3620=item XPUSHp
d8c40edc 3621X<XPUSHp>
954c1994 3622
94bdecf9 3623Push a string onto the stack, extending the stack if necessary. The C<len>
d82b684c
SH
3624indicates the length of the string. Handles 'set' magic. Uses C<TARG>, so
3625C<dTARGET> or C<dXSTARG> should be called to declare it. Do not call
3626multiple C<TARG>-oriented macros to return lists from XSUB's - see
3627C<mXPUSHp> instead. See also C<PUSHp> and C<mPUSHp>.
954c1994 3628
94bdecf9 3629 void XPUSHp(char* str, STRLEN len)
954c1994 3630
94bdecf9
JH
3631=for hackers
3632Found in file pp.h
3633
3634=item XPUSHs
d8c40edc 3635X<XPUSHs>
94bdecf9
JH
3636
3637Push an SV onto the stack, extending the stack if necessary. Does not
d82b684c
SH
3638handle 'set' magic. Does not use C<TARG>. See also C<XPUSHmortal>,
3639C<PUSHs> and C<PUSHmortal>.
94bdecf9
JH
3640
3641 void XPUSHs(SV* sv)
954c1994 3642
497711e7 3643=for hackers
94bdecf9 3644Found in file pp.h
497711e7 3645
94bdecf9 3646=item XPUSHu
d8c40edc 3647X<XPUSHu>
954c1994 3648
94bdecf9 3649Push an unsigned integer onto the stack, extending the stack if necessary.
d82b684c
SH
3650Handles 'set' magic. Uses C<TARG>, so C<dTARGET> or C<dXSTARG> should be
3651called to declare it. Do not call multiple C<TARG>-oriented macros to
3652return lists from XSUB's - see C<mXPUSHu> instead. See also C<PUSHu> and
3653C<mPUSHu>.
954c1994 3654
94bdecf9
JH
3655 void XPUSHu(UV uv)
3656
3657=for hackers
3658Found in file pp.h
3659
3660=item XSRETURN
d8c40edc 3661X<XSRETURN>
94bdecf9
JH
3662
3663Return from XSUB, indicating number of items on the stack. This is usually
3664handled by C<xsubpp>.
3665
3666 void XSRETURN(int nitems)
954c1994 3667
497711e7
GS
3668=for hackers
3669Found in file XSUB.h
3670
e509e693 3671=item XSRETURN_EMPTY
d8c40edc 3672X<XSRETURN_EMPTY>
e509e693
SH
3673
3674Return an empty list from an XSUB immediately.
3675
3676 XSRETURN_EMPTY;
3677
3678=for hackers
3679Found in file XSUB.h
3680
94bdecf9 3681=item XSRETURN_IV
d8c40edc 3682X<XSRETURN_IV>
954c1994 3683
94bdecf9 3684Return an integer from an XSUB immediately. Uses C<XST_mIV>.
954c1994 3685
94bdecf9 3686 void XSRETURN_IV(IV iv)
954c1994 3687
497711e7 3688=for hackers
94bdecf9 3689Found in file XSUB.h
497711e7 3690
94bdecf9 3691=item XSRETURN_NO
d8c40edc 3692X<XSRETURN_NO>
954c1994 3693
94bdecf9 3694Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
954c1994 3695
94bdecf9 3696 XSRETURN_NO;
954c1994 3697
497711e7 3698=for hackers
94bdecf9 3699Found in file XSUB.h
497711e7 3700
94bdecf9 3701=item XSRETURN_NV
d8c40edc 3702X<XSRETURN_NV>
954c1994 3703
94bdecf9 3704Return a double from an XSUB immediately. Uses C<XST_mNV>.
954c1994 3705
94bdecf9 3706 void XSRETURN_NV(NV nv)
954c1994 3707
497711e7 3708=for hackers
94bdecf9
JH
3709Found in file XSUB.h
3710
3711=item XSRETURN_PV
d8c40edc 3712X<XSRETURN_PV>
94bdecf9
JH
3713
3714Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
3715
3716 void XSRETURN_PV(char* str)
3717
3718=for hackers
3719Found in file XSUB.h
3720
3721=item XSRETURN_UNDEF
d8c40edc 3722X<XSRETURN_UNDEF>
94bdecf9
JH
3723
3724Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
3725
3726 XSRETURN_UNDEF;
3727
3728=for hackers
3729Found in file XSUB.h
3730
0ee80f49 3731=item XSRETURN_UV
d8c40edc 3732X<XSRETURN_UV>
0ee80f49
JH
3733
3734Return an integer from an XSUB immediately. Uses C<XST_mUV>.
3735
3736 void XSRETURN_UV(IV uv)
3737
3738=for hackers
3739Found in file XSUB.h
3740
94bdecf9 3741=item XSRETURN_YES
d8c40edc 3742X<XSRETURN_YES>
94bdecf9
JH
3743
3744Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
3745
3746 XSRETURN_YES;
3747
3748=for hackers
3749Found in file XSUB.h
3750
3751=item XST_mIV
d8c40edc 3752X<XST_mIV>
94bdecf9
JH
3753
3754Place an integer into the specified position C<pos> on the stack. The
3755value is stored in a new mortal SV.
3756
3757 void XST_mIV(int pos, IV iv)
3758
3759=for hackers
3760Found in file XSUB.h
3761
3762=item XST_mNO
d8c40edc 3763X<XST_mNO>
94bdecf9
JH
3764
3765Place C<&PL_sv_no> into the specified position C<pos> on the
3766stack.
3767
3768 void XST_mNO(int pos)
3769
3770=for hackers
3771Found in file XSUB.h
3772
3773=item XST_mNV
d8c40edc 3774X<XST_mNV>
94bdecf9
JH
3775
3776Place a double into the specified position C<pos> on the stack. The value
3777is stored in a new mortal SV.
3778
3779 void XST_mNV(int pos, NV nv)
3780
3781=for hackers
3782Found in file XSUB.h
3783
3784=item XST_mPV
d8c40edc 3785X<XST_mPV>
94bdecf9
JH
3786
3787Place a copy of a string into the specified position C<pos> on the stack.
3788The value is stored in a new mortal SV.
3789
3790 void XST_mPV(int pos, char* str)
3791
3792=for hackers
3793Found in file XSUB.h
3794
3795=item XST_mUNDEF
d8c40edc 3796X<XST_mUNDEF>
94bdecf9
JH
3797
3798Place C<&PL_sv_undef> into the specified position C<pos> on the
3799stack.
3800
3801 void XST_mUNDEF(int pos)
3802
3803=for hackers
3804Found in file XSUB.h
3805
3806=item XST_mYES
d8c40edc 3807X<XST_mYES>
94bdecf9
JH
3808
3809Place C<&PL_sv_yes> into the specified position C<pos> on the
3810stack.
3811
3812 void XST_mYES(int pos)
3813
3814=for hackers
3815Found in file XSUB.h
3816
3817
3818=back
3819
3820=head1 SV Flags
497711e7 3821
94bdecf9 3822=over 8
954c1994 3823
94bdecf9 3824=item svtype
d8c40edc 3825X<svtype>
954c1994 3826
94bdecf9
JH
3827An enum of flags for Perl types. These are found in the file B<sv.h>
3828in the C<svtype> enum. Test these flags with the C<SvTYPE> macro.
954c1994 3829
497711e7 3830=for hackers
94bdecf9 3831Found in file sv.h
6e9d1081 3832
94bdecf9 3833=item SVt_IV
d8c40edc 3834X<SVt_IV>
6e9d1081 3835
94bdecf9 3836Integer type flag for scalars. See C<svtype>.
6e9d1081
NC
3837
3838=for hackers
94bdecf9 3839Found in file sv.h
6e9d1081 3840
94bdecf9 3841=item SVt_NV
d8c40edc 3842X<SVt_NV>
6e9d1081 3843
94bdecf9 3844Double type flag for scalars. See C<svtype>.
6e9d1081
NC
3845
3846=for hackers
94bdecf9 3847Found in file sv.h
6e9d1081 3848
94bdecf9 3849=item SVt_PV
d8c40edc 3850X<SVt_PV>
6e9d1081 3851
94bdecf9 3852Pointer type flag for scalars. See C<svtype>.
6e9d1081
NC
3853
3854=for hackers
94bdecf9 3855Found in file sv.h
cd1ee231 3856
94bdecf9 3857=item SVt_PVAV
d8c40edc 3858X<SVt_PVAV>
cd1ee231 3859
94bdecf9 3860Type flag for arrays. See C<svtype>.
cd1ee231
JH
3861
3862=for hackers
94bdecf9 3863Found in file sv.h
cd1ee231 3864
94bdecf9 3865=item SVt_PVCV
d8c40edc 3866X<SVt_PVCV>
cd1ee231 3867
94bdecf9 3868Type flag for code refs. See C<svtype>.
cd1ee231
JH
3869
3870=for hackers
94bdecf9 3871Found in file sv.h
cd1ee231 3872
94bdecf9 3873=item SVt_PVHV
d8c40edc 3874X<SVt_PVHV>
cd1ee231 3875
94bdecf9 3876Type flag for hashes. See C<svtype>.
cd1ee231
JH
3877
3878=for hackers
94bdecf9 3879Found in file sv.h
cd1ee231 3880
94bdecf9 3881=item SVt_PVMG
d8c40edc 3882X<SVt_PVMG>
cd1ee231 3883
94bdecf9 3884Type flag for blessed scalars. See C<svtype>.
cd1ee231
JH
3885
3886=for hackers
94bdecf9 3887Found in file sv.h
cd1ee231 3888
cd1ee231 3889
94bdecf9 3890=back
cd1ee231 3891
94bdecf9 3892=head1 SV Manipulation Functions
cd1ee231 3893
94bdecf9 3894=over 8
cd1ee231 3895
94bdecf9 3896=item get_sv
d8c40edc 3897X<get_sv>
cd1ee231 3898
94bdecf9
JH
3899Returns the SV of the specified Perl scalar. If C<create> is set and the
3900Perl variable does not exist then it will be created. If C<create> is not
3901set and the variable does not exist then NULL is returned.
3902
3903NOTE: the perl_ form of this function is deprecated.
3904
3905 SV* get_sv(const char* name, I32 create)
cd1ee231
JH
3906
3907=for hackers
94bdecf9 3908Found in file perl.c
cd1ee231 3909
94bdecf9 3910=item newRV_inc
d8c40edc 3911X<newRV_inc>
2a5a0c38 3912
94bdecf9
JH
3913Creates an RV wrapper for an SV. The reference count for the original SV is
3914incremented.
2a5a0c38 3915
94bdecf9 3916 SV* newRV_inc(SV* sv)
2a5a0c38
JH
3917
3918=for hackers
94bdecf9 3919Found in file sv.h
2a5a0c38 3920
740cce10
NC
3921=item newSVpvn_utf8
3922X<newSVpvn_utf8>
3923
3924Creates a new SV and copies a string into it. If utf8 is true, calls
3925C<SvUTF8_on> on the new SV. Implemented as a wrapper around C<newSVpvn_flags>.
3926
3927 SV* newSVpvn_utf8(NULLOK const char* s, STRLEN len, U32 utf8)
3928
3929=for hackers
3930Found in file sv.h
3931
954c1994 3932=item SvCUR
d8c40edc 3933X<SvCUR>
954c1994
GS
3934
3935Returns the length of the string which is in the SV. See C<SvLEN>.
3936
3937 STRLEN SvCUR(SV* sv)
3938
497711e7
GS
3939=for hackers
3940Found in file sv.h
3941
954c1994 3942=item SvCUR_set
d8c40edc 3943X<SvCUR_set>
954c1994 3944
20799e15
SP
3945Set the current length of the string which is in the SV. See C<SvCUR>
3946and C<SvIV_set>.
954c1994
GS
3947
3948 void SvCUR_set(SV* sv, STRLEN len)
3949
497711e7
GS
3950=for hackers
3951Found in file sv.h
3952
94bdecf9 3953=item SvEND
d8c40edc 3954X<SvEND>
954c1994 3955
94bdecf9
JH
3956Returns a pointer to the last character in the string which is in the SV.
3957See C<SvCUR>. Access the character as *(SvEND(sv)).
954c1994 3958
94bdecf9 3959 char* SvEND(SV* sv)
954c1994 3960
497711e7
GS
3961=for hackers
3962Found in file sv.h
3963
d34786ba
NC
3964=item SvGAMAGIC
3965X<SvGAMAGIC>
3966
3967Returns true if the SV has get magic or overloading. If either is true then
3968the scalar is active data, and has the potential to return a new value every
3969time it is accessed. Hence you must be careful to only read it once per user
3970logical operation and work with that returned value. If neither is true then
3971the scalar's value cannot change unless written to.
3972
3973 char* SvGAMAGIC(SV* sv)
3974
3975=for hackers
3976Found in file sv.h
3977
954c1994 3978=item SvGROW
d8c40edc 3979X<SvGROW>
954c1994
GS
3980
3981Expands the character buffer in the SV so that it has room for the
3982indicated number of bytes (remember to reserve space for an extra trailing
8cf8f3d1 3983NUL character). Calls C<sv_grow> to perform the expansion if necessary.
954c1994
GS
3984Returns a pointer to the character buffer.
3985
679ac26e 3986 char * SvGROW(SV* sv, STRLEN len)
954c1994 3987
497711e7
GS
3988=for hackers
3989Found in file sv.h
3990
954c1994 3991=item SvIOK
d8c40edc 3992X<SvIOK>
954c1994 3993
fbf9f983 3994Returns a U32 value indicating whether the SV contains an integer.
954c1994 3995
fbf9f983 3996 U32 SvIOK(SV* sv)
954c1994 3997
497711e7
GS
3998=for hackers
3999Found in file sv.h
4000
954c1994 4001=item SvIOKp
d8c40edc 4002X<SvIOKp>
954c1994 4003
fbf9f983 4004Returns a U32 value indicating whether the SV contains an integer. Checks
954c1994
GS
4005the B<private> setting. Use C<SvIOK>.
4006
fbf9f983 4007 U32 SvIOKp(SV* sv)
954c1994 4008
497711e7
GS
4009=for hackers
4010Found in file sv.h
4011
e331fc52 4012=item SvIOK_notUV
d8c40edc 4013X<SvIOK_notUV>
e331fc52 4014
f4758303 4015Returns a boolean indicating whether the SV contains a signed integer.
e331fc52 4016
12fa07df 4017 bool SvIOK_notUV(SV* sv)
e331fc52
JH
4018
4019=for hackers
4020Found in file sv.h
4021
954c1994 4022=item SvIOK_off
d8c40edc 4023X<SvIOK_off>
954c1994
GS
4024
4025Unsets the IV status of an SV.
4026
4027 void SvIOK_off(SV* sv)
4028
497711e7
GS
4029=for hackers
4030Found in file sv.h
4031
954c1994 4032=item SvIOK_on
d8c40edc 4033X<SvIOK_on>
954c1994
GS
4034
4035Tells an SV that it is an integer.
4036
4037 void SvIOK_on(SV* sv)
4038
497711e7
GS
4039=for hackers
4040Found in file sv.h
4041
954c1994 4042=item SvIOK_only
d8c40edc 4043X<SvIOK_only>
954c1994
GS
4044
4045Tells an SV that it is an integer and disables all other OK bits.
4046
4047 void SvIOK_only(SV* sv)
4048
497711e7
GS
4049=for hackers
4050Found in file sv.h
4051
e331fc52 4052=item SvIOK_only_UV
d8c40edc 4053X<SvIOK_only_UV>
e331fc52
JH
4054
4055Tells and SV that it is an unsigned integer and disables all other OK bits.
4056
4057 void SvIOK_only_UV(SV* sv)
4058
4059=for hackers
4060Found in file sv.h
4061
4062=item SvIOK_UV
d8c40edc 4063X<SvIOK_UV>
e331fc52
JH
4064
4065Returns a boolean indicating whether the SV contains an unsigned integer.
4066
12fa07df 4067 bool SvIOK_UV(SV* sv)
e331fc52
JH
4068
4069=for hackers
4070Found in file sv.h
4071
19dbb8f1 4072=item SvIsCOW
d8c40edc 4073X<SvIsCOW>
19dbb8f1
NC
4074
4075Returns a boolean indicating whether the SV is Copy-On-Write. (either shared
4076hash key scalars, or full Copy On Write scalars if 5.9.0 is configured for
4077COW)
4078
4079 bool SvIsCOW(SV* sv)
4080
4081=for hackers
4082Found in file sv.h
4083
4084=item SvIsCOW_shared_hash
d8c40edc 4085X<SvIsCOW_shared_hash>
19dbb8f1
NC
4086
4087Returns a boolean indicating whether the SV is Copy-On-Write shared hash key
4088scalar.
4089
4090 bool SvIsCOW_shared_hash(SV* sv)
4091
4092=for hackers
4093Found in file sv.h
4094
954c1994 4095=item SvIV
d8c40edc 4096X<SvIV>
954c1994 4097
c40f1585 4098Coerces the given SV to an integer and returns it. See C<SvIVx> for a
645c22ef 4099version which guarantees to evaluate sv only once.
954c1994
GS
4100
4101 IV SvIV(SV* sv)
4102
497711e7
GS
4103=for hackers
4104Found in file sv.h
4105
df344c0f 4106=item SvIVX
d8c40edc 4107X<SvIVX>
954c1994 4108
df344c0f
NC
4109Returns the raw value in the SV's IV slot, without checks or conversions.
4110Only use when you are sure SvIOK is true. See also C<SvIV()>.
954c1994 4111
df344c0f 4112 IV SvIVX(SV* sv)
954c1994 4113
497711e7
GS
4114=for hackers
4115Found in file sv.h
4116
df344c0f 4117=item SvIVx
d8c40edc 4118X<SvIVx>
645c22ef 4119
df344c0f 4120Coerces the given SV to an integer and returns it. Guarantees to evaluate
4ea561bc
NC
4121C<sv> only once. Only use this if C<sv> is an expression with side effects,
4122otherwise use the more efficient C<SvIV>.
645c22ef 4123
df344c0f 4124 IV SvIVx(SV* sv)
645c22ef
DM
4125
4126=for hackers
4127Found in file sv.h
4128
891f9566 4129=item SvIV_nomg
d8c40edc 4130X<SvIV_nomg>
891f9566
YST
4131
4132Like C<SvIV> but doesn't process magic.
4133
4134 IV SvIV_nomg(SV* sv)
4135
4136=for hackers
4137Found in file sv.h
4138
672994ce 4139=item SvIV_set
d8c40edc 4140X<SvIV_set>
672994ce 4141
20799e15
SP
4142Set the value of the IV pointer in sv to val. It is possible to perform
4143the same function of this macro with an lvalue assignment to C<SvIVX>.
4144With future Perls, however, it will be more efficient to use
4145C<SvIV_set> instead of the lvalue assignment to C<SvIVX>.
672994ce
SP
4146
4147 void SvIV_set(SV* sv, IV val)
4148
4149=for hackers
4150Found in file sv.h
4151
954c1994 4152=item SvLEN
d8c40edc 4153X<SvLEN>
954c1994 4154
91e74348
JH
4155Returns the size of the string buffer in the SV, not including any part
4156attributable to C<SvOOK>. See C<SvCUR>.
954c1994
GS
4157
4158 STRLEN SvLEN(SV* sv)
4159
497711e7
GS
4160=for hackers
4161Found in file sv.h
4162
672994ce 4163=item SvLEN_set
d8c40edc 4164X<SvLEN_set>
672994ce 4165
20799e15 4166Set the actual length of the string which is in the SV. See C<SvIV_set>.
672994ce
SP
4167
4168 void SvLEN_set(SV* sv, STRLEN len)
4169
4170=for hackers
4171Found in file sv.h
4172
4173=item SvMAGIC_set
d8c40edc 4174X<SvMAGIC_set>
672994ce 4175
20799e15 4176Set the value of the MAGIC pointer in sv to val. See C<SvIV_set>.
672994ce
SP
4177
4178 void SvMAGIC_set(SV* sv, MAGIC* val)
4179
4180=for hackers
4181Found in file sv.h
4182
954c1994 4183=item SvNIOK
d8c40edc 4184X<SvNIOK>
954c1994 4185
fbf9f983 4186Returns a U32 value indicating whether the SV contains a number, integer or
954c1994
GS
4187double.
4188
fbf9f983 4189 U32 SvNIOK(SV* sv)
954c1994 4190
497711e7
GS
4191=for hackers
4192Found in file sv.h
4193
954c1994 4194=item SvNIOKp
d8c40edc 4195X<SvNIOKp>
954c1994 4196
fbf9f983 4197Returns a U32 value indicating whether the SV contains a number, integer or
954c1994
GS
4198double. Checks the B<private> setting. Use C<SvNIOK>.
4199
fbf9f983 4200 U32 SvNIOKp(SV* sv)
954c1994 4201
497711e7
GS
4202=for hackers
4203Found in file sv.h
4204
954c1994 4205=item SvNIOK_off
d8c40edc 4206X<SvNIOK_off>
954c1994
GS
4207
4208Unsets the NV/IV status of an SV.
4209
4210 void SvNIOK_off(SV* sv)
4211
497711e7
GS
4212=for hackers
4213Found in file sv.h
4214
954c1994 4215=item SvNOK
d8c40edc 4216X<SvNOK>
954c1994 4217
fbf9f983 4218Returns a U32 value indicating whether the SV contains a double.
954c1994 4219
fbf9f983 4220 U32 SvNOK(SV* sv)
954c1994 4221
497711e7
GS
4222=for hackers
4223Found in file sv.h
4224
954c1994 4225=item SvNOKp
d8c40edc 4226X<SvNOKp>
954c1994 4227
fbf9f983 4228Returns a U32 value indicating whether the SV contains a double. Checks the
954c1994
GS
4229B<private> setting. Use C<SvNOK>.
4230
fbf9f983 4231 U32 SvNOKp(SV* sv)
954c1994 4232
497711e7
GS
4233=for hackers
4234Found in file sv.h
4235
954c1994 4236=item SvNOK_off
d8c40edc 4237X<SvNOK_off>
954c1994
GS
4238
4239Unsets the NV status of an SV.
4240
4241 void SvNOK_off(SV* sv)
4242
497711e7
GS
4243=for hackers
4244Found in file sv.h
4245
954c1994 4246=item SvNOK_on
d8c40edc 4247X<SvNOK_on>
954c1994
GS
4248
4249Tells an SV that it is a double.
4250
4251 void SvNOK_on(SV* sv)
4252
497711e7
GS
4253=for hackers
4254Found in file sv.h
4255
954c1994 4256=item SvNOK_only
d8c40edc 4257X<SvNOK_only>
954c1994
GS
4258
4259Tells an SV that it is a double and disables all other OK bits.
4260
4261 void SvNOK_only(SV* sv)
4262
497711e7
GS
4263=for hackers
4264Found in file sv.h
4265
954c1994 4266=item SvNV
d8c40edc 4267X<SvNV>
954c1994 4268
c40f1585 4269Coerce the given SV to a double and return it. See C<SvNVx> for a version
645c22ef 4270which guarantees to evaluate sv only once.
954c1994
GS
4271
4272 NV SvNV(SV* sv)
4273
497711e7
GS
4274=for hackers
4275Found in file sv.h
4276
b9381830 4277=item SvNVX
d8c40edc 4278X<SvNVX>
645c22ef 4279
b9381830
JP
4280Returns the raw value in the SV's NV slot, without checks or conversions.
4281Only use when you are sure SvNOK is true. See also C<SvNV()>.
645c22ef 4282
b9381830 4283 NV SvNVX(SV* sv)
645c22ef
DM
4284
4285=for hackers
4286Found in file sv.h
4287
b9381830 4288=item SvNVx
d8c40edc 4289X<SvNVx>
954c1994 4290
b9381830 4291Coerces the given SV to a double and returns it. Guarantees to evaluate
4ea561bc
NC
4292C<sv> only once. Only use this if C<sv> is an expression with side effects,
4293otherwise use the more efficient C<SvNV>.
954c1994 4294
b9381830 4295 NV SvNVx(SV* sv)
954c1994 4296
497711e7
GS
4297=for hackers
4298Found in file sv.h
4299
672994ce 4300=item SvNV_set
d8c40edc 4301X<SvNV_set>
672994ce 4302
20799e15 4303Set the value of the NV pointer in sv to val. See C<SvIV_set>.
672994ce
SP
4304
4305 void SvNV_set(SV* sv, NV val)
4306
4307=for hackers
4308Found in file sv.h
4309
954c1994 4310=item SvOK
d8c40edc 4311X<SvOK>
954c1994 4312
fbf9f983 4313Returns a U32 value indicating whether the value is an SV. It also tells
9adebda4 4314whether the value is defined or not.
954c1994 4315
fbf9f983 4316 U32 SvOK(SV* sv)
954c1994 4317
497711e7
GS
4318=for hackers
4319Found in file sv.h
4320
954c1994 4321=item SvOOK
d8c40edc 4322X<SvOOK>
954c1994 4323
fbf9f983 4324Returns a U32 indicating whether the SvIVX is a valid offset value for
954c1994
GS
4325the SvPVX. This hack is used internally to speed up removal of characters
4326from the beginning of a SvPV. When SvOOK is true, then the start of the
4327allocated string buffer is really (SvPVX - SvIVX).
4328
fbf9f983 4329 U32 SvOOK(SV* sv)
954c1994 4330
497711e7
GS
4331=for hackers
4332Found in file sv.h
4333
954c1994 4334=item SvPOK
d8c40edc 4335X<SvPOK>
954c1994 4336
fbf9f983 4337Returns a U32 value indicating whether the SV contains a character
954c1994
GS
4338string.
4339
fbf9f983 4340 U32 SvPOK(SV* sv)
954c1994 4341
497711e7
GS
4342=for hackers
4343Found in file sv.h
4344
954c1994 4345=item SvPOKp
d8c40edc 4346X<SvPOKp>
954c1994 4347
fbf9f983 4348Returns a U32 value indicating whether the SV contains a character string.
954c1994
GS
4349Checks the B<private> setting. Use C<SvPOK>.
4350
fbf9f983 4351 U32 SvPOKp(SV* sv)
954c1994 4352
497711e7
GS
4353=for hackers
4354Found in file sv.h
4355
954c1994 4356=item SvPOK_off
d8c40edc 4357X<SvPOK_off>
954c1994
GS
4358
4359Unsets the PV status of an SV.
4360
4361 void SvPOK_off(SV* sv)
4362
497711e7
GS
4363=for hackers
4364Found in file sv.h
4365
954c1994 4366=item SvPOK_on
d8c40edc 4367X<SvPOK_on>
954c1994
GS
4368
4369Tells an SV that it is a string.
4370
4371 void SvPOK_on(SV* sv)
4372
497711e7
GS
4373=for hackers
4374Found in file sv.h
4375
954c1994 4376=item SvPOK_only
d8c40edc 4377X<SvPOK_only>
954c1994
GS
4378
4379Tells an SV that it is a string and disables all other OK bits.
1e54db1a 4380Will also turn off the UTF-8 status.
954c1994
GS
4381
4382 void SvPOK_only(SV* sv)
4383
497711e7
GS
4384=for hackers
4385Found in file sv.h
4386
914184e1 4387=item SvPOK_only_UTF8
d8c40edc 4388X<SvPOK_only_UTF8>
914184e1 4389
d5ce4a7c 4390Tells an SV that it is a string and disables all other OK bits,
1e54db1a 4391and leaves the UTF-8 status as it was.
f1a1024e 4392
914184e1
JH
4393 void SvPOK_only_UTF8(SV* sv)
4394
4395=for hackers
4396Found in file sv.h
4397
954c1994 4398=item SvPV
d8c40edc 4399X<SvPV>
954c1994 4400
12b7c5c7
JH
4401Returns a pointer to the string in the SV, or a stringified form of
4402the SV if the SV does not contain a string. The SV may cache the
4403stringified version becoming C<SvPOK>. Handles 'get' magic. See also
645c22ef 4404C<SvPVx> for a version which guarantees to evaluate sv only once.
954c1994
GS
4405
4406 char* SvPV(SV* sv, STRLEN len)
4407
497711e7
GS
4408=for hackers
4409Found in file sv.h
4410
645c22ef 4411=item SvPVbyte
d8c40edc 4412X<SvPVbyte>
645c22ef
DM
4413
4414Like C<SvPV>, but converts sv to byte representation first if necessary.
4415
4416 char* SvPVbyte(SV* sv, STRLEN len)
4417
4418=for hackers
4419Found in file sv.h
4420
4421=item SvPVbytex
d8c40edc 4422X<SvPVbytex>
645c22ef
DM
4423
4424Like C<SvPV>, but converts sv to byte representation first if necessary.
d1be9408 4425Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte>
645c22ef
DM
4426otherwise.
4427
645c22ef
DM
4428 char* SvPVbytex(SV* sv, STRLEN len)
4429
4430=for hackers
4431Found in file sv.h
4432
4433=item SvPVbytex_force
d8c40edc 4434X<SvPVbytex_force>
645c22ef
DM
4435
4436Like C<SvPV_force>, but converts sv to byte representation first if necessary.
d1be9408 4437Guarantees to evaluate sv only once; use the more efficient C<SvPVbyte_force>
645c22ef
DM
4438otherwise.
4439
4440 char* SvPVbytex_force(SV* sv, STRLEN len)
4441
4442=for hackers
4443Found in file sv.h
4444
4445=item SvPVbyte_force
d8c40edc 4446X<SvPVbyte_force>
645c22ef
DM
4447
4448Like C<SvPV_force>, but converts sv to byte representation first if necessary.
4449
4450 char* SvPVbyte_force(SV* sv, STRLEN len)
4451
4452=for hackers
4453Found in file sv.h
4454
4455=item SvPVbyte_nolen
d8c40edc 4456X<SvPVbyte_nolen>
645c22ef
DM
4457
4458Like C<SvPV_nolen>, but converts sv to byte representation first if necessary.
4459
1fdc5aa6 4460 char* SvPVbyte_nolen(SV* sv)
645c22ef
DM
4461
4462=for hackers
4463Found in file sv.h
4464
4465=item SvPVutf8
d8c40edc 4466X<SvPVutf8>
645c22ef 4467
1fdc5aa6 4468Like C<SvPV>, but converts sv to utf8 first if necessary.
645c22ef
DM
4469
4470 char* SvPVutf8(SV* sv, STRLEN len)
4471
4472=for hackers
4473Found in file sv.h
4474
4475=item SvPVutf8x
d8c40edc 4476X<SvPVutf8x>
645c22ef 4477
1fdc5aa6 4478Like C<SvPV>, but converts sv to utf8 first if necessary.
d1be9408 4479Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8>
645c22ef
DM
4480otherwise.
4481
4482 char* SvPVutf8x(SV* sv, STRLEN len)
4483
4484=for hackers
4485Found in file sv.h
4486
4487=item SvPVutf8x_force
d8c40edc 4488X<SvPVutf8x_force>
645c22ef 4489
1fdc5aa6 4490Like C<SvPV_force>, but converts sv to utf8 first if necessary.
d1be9408 4491Guarantees to evaluate sv only once; use the more efficient C<SvPVutf8_force>
645c22ef
DM
4492otherwise.
4493
4494 char* SvPVutf8x_force(SV* sv, STRLEN len)
4495
4496=for hackers
4497Found in file sv.h
4498
4499=item SvPVutf8_force
d8c40edc 4500X<SvPVutf8_force>
645c22ef 4501
1fdc5aa6 4502Like C<SvPV_force>, but converts sv to utf8 first if necessary.
645c22ef
DM
4503
4504 char* SvPVutf8_force(SV* sv, STRLEN len)
4505
4506=for hackers
4507Found in file sv.h
4508
4509=item SvPVutf8_nolen
d8c40edc 4510X<SvPVutf8_nolen>
645c22ef 4511
1fdc5aa6 4512Like C<SvPV_nolen>, but converts sv to utf8 first if necessary.
645c22ef 4513
1fdc5aa6 4514 char* SvPVutf8_nolen(SV* sv)
645c22ef
DM
4515
4516=for hackers
4517Found in file sv.h
4518
df344c0f 4519=item SvPVX
d8c40edc 4520X<SvPVX>
645c22ef 4521
df344c0f
NC
4522Returns a pointer to the physical string in the SV. The SV must contain a
4523string.
645c22ef 4524
df344c0f 4525 char* SvPVX(SV* sv)
645c22ef
DM
4526
4527=for hackers
4528Found in file sv.h
4529
df344c0f 4530=item SvPVx
d8c40edc 4531X<SvPVx>
954c1994 4532
4ea561bc
NC
4533A version of C<SvPV> which guarantees to evaluate C<sv> only once.
4534Only use this if C<sv> is an expression with side effects, otherwise use the
4535more efficient C<SvPVX>.
954c1994 4536
df344c0f 4537 char* SvPVx(SV* sv, STRLEN len)
954c1994 4538
497711e7
GS
4539=for hackers
4540Found in file sv.h
4541
954c1994 4542=item SvPV_force
d8c40edc 4543X<SvPV_force>
954c1994 4544
12b7c5c7
JH
4545Like C<SvPV> but will force the SV into containing just a string
4546(C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
4547directly.
954c1994
GS
4548
4549 char* SvPV_force(SV* sv, STRLEN len)
4550
497711e7
GS
4551=for hackers
4552Found in file sv.h
4553
645c22ef 4554=item SvPV_force_nomg
d8c40edc 4555X<SvPV_force_nomg>
645c22ef 4556
12b7c5c7
JH
4557Like C<SvPV> but will force the SV into containing just a string
4558(C<SvPOK_only>). You want force if you are going to update the C<SvPVX>
4559directly. Doesn't process magic.
645c22ef
DM
4560
4561 char* SvPV_force_nomg(SV* sv, STRLEN len)
4562
4563=for hackers
4564Found in file sv.h
4565
954c1994 4566=item SvPV_nolen
d8c40edc 4567X<SvPV_nolen>
954c1994 4568
12b7c5c7
JH
4569Returns a pointer to the string in the SV, or a stringified form of
4570the SV if the SV does not contain a string. The SV may cache the
4571stringified form becoming C<SvPOK>. Handles 'get' magic.
954c1994
GS
4572
4573 char* SvPV_nolen(SV* sv)
4574
497711e7
GS
4575=for hackers
4576Found in file sv.h
4577
891f9566 4578=item SvPV_nomg
d8c40edc 4579X<SvPV_nomg>
891f9566
YST
4580
4581Like C<SvPV> but doesn't process magic.
4582
4583 char* SvPV_nomg(SV* sv, STRLEN len)
4584
4585=for hackers
4586Found in file sv.h
4587
672994ce 4588=item SvPV_set
d8c40edc 4589X<SvPV_set>
672994ce 4590
20799e15 4591Set the value of the PV pointer in sv to val. See C<SvIV_set>.
672994ce
SP
4592
4593 void SvPV_set(SV* sv, char* val)
4594
4595=for hackers
4596Found in file sv.h
4597
954c1994 4598=item SvREFCNT
d8c40edc 4599X<SvREFCNT>
954c1994
GS
4600
4601Returns the value of the object's reference count.
4602
4603 U32 SvREFCNT(SV* sv)
4604
497711e7
GS
4605=for hackers
4606Found in file sv.h
4607
954c1994 4608=item SvREFCNT_dec
d8c40edc 4609X<SvREFCNT_dec>
954c1994
GS
4610
4611Decrements the reference count of the given SV.
4612
4613 void SvREFCNT_dec(SV* sv)
4614
497711e7
GS
4615=for hackers
4616Found in file sv.h
4617
954c1994 4618=item SvREFCNT_inc
d8c40edc 4619X<SvREFCNT_inc>
954c1994
GS
4620
4621Increments the reference count of the given SV.
4622
3fe05580
MHM
4623All of the following SvREFCNT_inc* macros are optimized versions of
4624SvREFCNT_inc, and can be replaced with SvREFCNT_inc.
4625
954c1994
GS
4626 SV* SvREFCNT_inc(SV* sv)
4627
497711e7
GS
4628=for hackers
4629Found in file sv.h
4630
b37c2d43
AL
4631=item SvREFCNT_inc_NN
4632X<SvREFCNT_inc_NN>
4633
4634Same as SvREFCNT_inc, but can only be used if you know I<sv>
4635is not NULL. Since we don't have to check the NULLness, it's faster
4636and smaller.
4637
4638 SV* SvREFCNT_inc_NN(SV* sv)
4639
4640=for hackers
4641Found in file sv.h
4642
4643=item SvREFCNT_inc_simple
4644X<SvREFCNT_inc_simple>
4645
4ea561bc
NC
4646Same as SvREFCNT_inc, but can only be used with expressions without side
4647effects. Since we don't have to store a temporary value, it's faster.
b37c2d43
AL
4648
4649 SV* SvREFCNT_inc_simple(SV* sv)
4650
4651=for hackers
4652Found in file sv.h
4653
4654=item SvREFCNT_inc_simple_NN
4655X<SvREFCNT_inc_simple_NN>
4656
4657Same as SvREFCNT_inc_simple, but can only be used if you know I<sv>
4658is not NULL. Since we don't have to check the NULLness, it's faster
4659and smaller.
4660
4661 SV* SvREFCNT_inc_simple_NN(SV* sv)
4662
4663=for hackers
4664Found in file sv.h
4665
4666=item SvREFCNT_inc_simple_void
4667X<SvREFCNT_inc_simple_void>
4668
4669Same as SvREFCNT_inc_simple, but can only be used if you don't need the
4670return value. The macro doesn't need to return a meaningful value.
4671
f8f4df2c 4672 void SvREFCNT_inc_simple_void(SV* sv)
b37c2d43
AL
4673
4674=for hackers
4675Found in file sv.h
4676
3fe05580
MHM
4677=item SvREFCNT_inc_simple_void_NN
4678X<SvREFCNT_inc_simple_void_NN>
4679
4680Same as SvREFCNT_inc, but can only be used if you don't need the return
4681value, and you know that I<sv> is not NULL. The macro doesn't need
4682to return a meaningful value, or check for NULLness, so it's smaller
4683and faster.
4684
f8f4df2c 4685 void SvREFCNT_inc_simple_void_NN(SV* sv)
3fe05580
MHM
4686
4687=for hackers
4688Found in file sv.h
4689
b37c2d43
AL
4690=item SvREFCNT_inc_void
4691X<SvREFCNT_inc_void>
4692
4693Same as SvREFCNT_inc, but can only be used if you don't need the
4694return value. The macro doesn't need to return a meaningful value.
4695
f8f4df2c 4696 void SvREFCNT_inc_void(SV* sv)
b37c2d43
AL
4697
4698=for hackers
4699Found in file sv.h
4700
4701=item SvREFCNT_inc_void_NN
4702X<SvREFCNT_inc_void_NN>
4703
4704Same as SvREFCNT_inc, but can only be used if you don't need the return
4705value, and you know that I<sv> is not NULL. The macro doesn't need
4706to return a meaningful value, or check for NULLness, so it's smaller
4707and faster.
4708
f8f4df2c 4709 void SvREFCNT_inc_void_NN(SV* sv)
b37c2d43
AL
4710
4711=for hackers
4712Found in file sv.h
4713
954c1994 4714=item SvROK
d8c40edc 4715X<SvROK>
954c1994
GS
4716
4717Tests if the SV is an RV.
4718
fbf9f983 4719 U32 SvROK(SV* sv)
954c1994 4720
497711e7
GS
4721=for hackers
4722Found in file sv.h
4723
954c1994 4724=item SvROK_off
d8c40edc 4725X<SvROK_off>
954c1994
GS
4726
4727Unsets the RV status of an SV.
4728
4729 void SvROK_off(SV* sv)
4730
497711e7
GS
4731=for hackers
4732Found in file sv.h
4733
954c1994 4734=item SvROK_on
d8c40edc 4735X<SvROK_on>
954c1994
GS
4736
4737Tells an SV that it is an RV.
4738
4739 void SvROK_on(SV* sv)
4740
497711e7
GS
4741=for hackers
4742Found in file sv.h
4743
954c1994 4744=item SvRV
d8c40edc 4745X<SvRV>
954c1994
GS
4746
4747Dereferences an RV to return the SV.
4748
4749 SV* SvRV(SV* sv)
4750
497711e7
GS
4751=for hackers
4752Found in file sv.h
4753
672994ce 4754=item SvRV_set
d8c40edc 4755X<SvRV_set>
672994ce 4756
20799e15 4757Set the value of the RV pointer in sv to val. See C<SvIV_set>.
672994ce
SP
4758
4759 void SvRV_set(SV* sv, SV* val)
4760
4761=for hackers
4762Found in file sv.h
4763
954c1994 4764=item SvSTASH
d8c40edc 4765X<SvSTASH>
954c1994
GS
4766
4767Returns the stash of the SV.
4768
4769 HV* SvSTASH(SV* sv)
4770
497711e7
GS
4771=for hackers
4772Found in file sv.h
4773
672994ce 4774=item SvSTASH_set
d8c40edc 4775X<SvSTASH_set>
672994ce 4776
20799e15 4777Set the value of the STASH pointer in sv to val. See C<SvIV_set>.
672994ce 4778
d070ff45 4779 void SvSTASH_set(SV* sv, HV* val)
672994ce
SP
4780
4781=for hackers
4782Found in file sv.h
4783
954c1994 4784=item SvTAINT
d8c40edc 4785X<SvTAINT>
954c1994 4786
c55831ac 4787Taints an SV if tainting is enabled.
954c1994
GS
4788
4789 void SvTAINT(SV* sv)
4790
497711e7
GS
4791=for hackers
4792Found in file sv.h
4793
954c1994 4794=item SvTAINTED
d8c40edc 4795X<SvTAINTED>
954c1994
GS
4796
4797Checks to see if an SV is tainted. Returns TRUE if it is, FALSE if
4798not.
4799
4800 bool SvTAINTED(SV* sv)
4801
497711e7
GS
4802=for hackers
4803Found in file sv.h
4804
954c1994 4805=item SvTAINTED_off
d8c40edc 4806X<SvTAINTED_off>
954c1994
GS
4807
4808Untaints an SV. Be I<very> careful with this routine, as it short-circuits
4809some of Perl's fundamental security features. XS module authors should not
4810use this function unless they fully understand all the implications of
4811unconditionally untainting the value. Untainting should be done in the
4812standard perl fashion, via a carefully crafted regexp, rather than directly
4813untainting variables.
4814
4815 void SvTAINTED_off(SV* sv)
4816
497711e7
GS
4817=for hackers
4818Found in file sv.h
4819
954c1994 4820=item SvTAINTED_on
d8c40edc 4821X<SvTAINTED_on>
954c1994 4822
c55831ac 4823Marks an SV as tainted if tainting is enabled.
954c1994
GS
4824
4825 void SvTAINTED_on(SV* sv)
4826
497711e7
GS
4827=for hackers
4828Found in file sv.h
4829
954c1994 4830=item SvTRUE
d8c40edc 4831X<SvTRUE>
954c1994
GS
4832
4833Returns a boolean indicating whether Perl would evaluate the SV as true or
4834false, defined or undefined. Does not handle 'get' magic.
4835
4836 bool SvTRUE(SV* sv)
4837
497711e7
GS
4838=for hackers
4839Found in file sv.h
4840
9f4817db 4841=item SvTYPE
d8c40edc 4842X<SvTYPE>
af3c7592 4843
9f4817db
JH
4844Returns the type of the SV. See C<svtype>.
4845
4846 svtype SvTYPE(SV* sv)
954c1994 4847
497711e7
GS
4848=for hackers
4849Found in file sv.h
4850
a8586c98 4851=item SvUOK
d8c40edc 4852X<SvUOK>
a8586c98
JH
4853
4854Returns a boolean indicating whether the SV contains an unsigned integer.
4855
fbf9f983 4856 bool SvUOK(SV* sv)
a8586c98
JH
4857
4858=for hackers
4859Found in file sv.h
4860
954c1994 4861=item SvUPGRADE
d8c40edc 4862X<SvUPGRADE>
954c1994
GS
4863
4864Used to upgrade an SV to a more complex form. Uses C<sv_upgrade> to
4865perform the upgrade if necessary. See C<svtype>.
4866
4867 void SvUPGRADE(SV* sv, svtype type)
4868
497711e7
GS
4869=for hackers
4870Found in file sv.h
4871
914184e1 4872=item SvUTF8
d8c40edc 4873X<SvUTF8>
914184e1 4874
fbf9f983 4875Returns a U32 value indicating whether the SV contains UTF-8 encoded data.
5912531f
DM
4876Call this after SvPV() in case any call to string overloading updates the
4877internal flag.
914184e1 4878
fbf9f983 4879 U32 SvUTF8(SV* sv)
914184e1
JH
4880
4881=for hackers
4882Found in file sv.h
4883
4884=item SvUTF8_off
d8c40edc 4885X<SvUTF8_off>
914184e1 4886
1e54db1a 4887Unsets the UTF-8 status of an SV.
914184e1
JH
4888
4889 void SvUTF8_off(SV *sv)
4890
4891=for hackers
4892Found in file sv.h
4893
4894=item SvUTF8_on
d8c40edc 4895X<SvUTF8_on>
914184e1 4896
1e54db1a 4897Turn on the UTF-8 status of an SV (the data is not changed, just the flag).
d5ce4a7c 4898Do not use frivolously.
914184e1
JH
4899
4900 void SvUTF8_on(SV *sv)
4901
4902=for hackers
4903Found in file sv.h
4904
954c1994 4905=item SvUV
d8c40edc 4906X<SvUV>
954c1994 4907
645c22ef
DM
4908Coerces the given SV to an unsigned integer and returns it. See C<SvUVx>
4909for a version which guarantees to evaluate sv only once.
954c1994
GS
4910
4911 UV SvUV(SV* sv)
4912
497711e7
GS
4913=for hackers
4914Found in file sv.h
4915
b9381830 4916=item SvUVX
d8c40edc 4917X<SvUVX>
891f9566 4918
b9381830
JP
4919Returns the raw value in the SV's UV slot, without checks or conversions.
4920Only use when you are sure SvIOK is true. See also C<SvUV()>.
891f9566 4921
b9381830 4922 UV SvUVX(SV* sv)
891f9566
YST
4923
4924=for hackers
4925Found in file sv.h
4926
b9381830 4927=item SvUVx
d8c40edc 4928X<SvUVx>
b0f01acb 4929
b9381830 4930Coerces the given SV to an unsigned integer and returns it. Guarantees to
4ea561bc
NC
4931C<sv> only once. Only use this if C<sv> is an expression with side effects,
4932otherwise use the more efficient C<SvUV>.
b0f01acb 4933
b9381830 4934 UV SvUVx(SV* sv)
b0f01acb
JP
4935
4936=for hackers
4937Found in file sv.h
4938
891f9566 4939=item SvUV_nomg
d8c40edc 4940X<SvUV_nomg>
954c1994 4941
891f9566 4942Like C<SvUV> but doesn't process magic.
954c1994 4943
891f9566 4944 UV SvUV_nomg(SV* sv)
954c1994 4945
497711e7
GS
4946=for hackers
4947Found in file sv.h
4948
672994ce 4949=item SvUV_set
d8c40edc 4950X<SvUV_set>
672994ce 4951
20799e15 4952Set the value of the UV pointer in sv to val. See C<SvIV_set>.
672994ce
SP
4953
4954 void SvUV_set(SV* sv, UV val)
4955
4956=for hackers
4957Found in file sv.h
4958
b0f01acb 4959=item SvVOK
d8c40edc 4960X<SvVOK>
645c22ef 4961
b0f01acb 4962Returns a boolean indicating whether the SV contains a v-string.
645c22ef 4963
b0f01acb 4964 bool SvVOK(SV* sv)
645c22ef
DM
4965
4966=for hackers
4967Found in file sv.h
4968
d2a0f284
JC
4969=item sv_catpvn_nomg
4970X<sv_catpvn_nomg>
4971
4972Like C<sv_catpvn> but doesn't process magic.
4973
4974 void sv_catpvn_nomg(SV* sv, const char* ptr, STRLEN len)
4975
4976=for hackers
4977Found in file sv.h
4978
4979=item sv_catsv_nomg
4980X<sv_catsv_nomg>
4981
4982Like C<sv_catsv> but doesn't process magic.
4983
4984 void sv_catsv_nomg(SV* dsv, SV* ssv)
4985
4986=for hackers
4987Found in file sv.h
4988
4989=item sv_derived_from
4990X<sv_derived_from>
4991
6885da0e 4992Returns a boolean indicating whether the SV is derived from the specified class
4993I<at the C level>. To check derivation at the Perl level, call C<isa()> as a
4994normal Perl method.
d2a0f284
JC
4995
4996 bool sv_derived_from(SV* sv, const char* name)
4997
4998=for hackers
4999Found in file universal.c
5000
cbc021f9 5001=item sv_does
5002X<sv_does>
5003
5004Returns a boolean indicating whether the SV performs a specific, named role.
5005The SV can be a Perl object or the name of a Perl class.
5006
5007 bool sv_does(SV* sv, const char* name)
5008
5009=for hackers
5010Found in file universal.c
5011
d2a0f284
JC
5012=item sv_report_used
5013X<sv_report_used>
5014
5015Dump the contents of all SVs not yet freed. (Debugging aid).
5016
5017 void sv_report_used()
5018
5019=for hackers
5020Found in file sv.c
5021
5022=item sv_setsv_nomg
5023X<sv_setsv_nomg>
5024
5025Like C<sv_setsv> but doesn't process magic.
5026
5027 void sv_setsv_nomg(SV* dsv, SV* ssv)
5028
5029=for hackers
5030Found in file sv.h
5031
5032
5033=back
5034
5035=head1 SV-Body Allocation
5036
5037=over 8
5038
5039=item looks_like_number
5040X<looks_like_number>
5041
5042Test if the content of an SV looks like a number (or is a number).
5043C<Inf> and C<Infinity> are treated as numbers (so will not issue a
5044non-numeric warning), even if your atof() doesn't grok them.
5045
5046 I32 looks_like_number(SV* sv)
5047
5048=for hackers
5049Found in file sv.c
5050
5051=item newRV_noinc
5052X<newRV_noinc>
5053
5054Creates an RV wrapper for an SV. The reference count for the original
5055SV is B<not> incremented.
5056
7f466ec7 5057 SV* newRV_noinc(SV* sv)
d2a0f284
JC
5058
5059=for hackers
5060Found in file sv.c
5061
5062=item newSV
5063X<newSV>
5064
5065Creates a new SV. A non-zero C<len> parameter indicates the number of
5066bytes of preallocated string space the SV should have. An extra byte for a
5067trailing NUL is also reserved. (SvPOK is not set for the SV even if string
5068space is allocated.) The reference count for the new SV is set to 1.
5069
5070In 5.9.3, newSV() replaces the older NEWSV() API, and drops the first
5071parameter, I<x>, a debug aid which allowed callers to identify themselves.
5072This aid has been superseded by a new build option, PERL_MEM_LOG (see
5073L<perlhack/PERL_MEM_LOG>). The older API is still there for use in XS
5074modules supporting older perls.
5075
5076 SV* newSV(STRLEN len)
5077
5078=for hackers
5079Found in file sv.c
5080
5081=item newSVhek
5082X<newSVhek>
5083
5084Creates a new SV from the hash key structure. It will generate scalars that
5085point to the shared string table where possible. Returns a new (undefined)
5086SV if the hek is NULL.
5087
5088 SV* newSVhek(const HEK *hek)
5089
5090=for hackers
5091Found in file sv.c
5092
5093=item newSViv
5094X<newSViv>
5095
5096Creates a new SV and copies an integer into it. The reference count for the
5097SV is set to 1.
5098
5099 SV* newSViv(IV i)
5100
5101=for hackers
5102Found in file sv.c
5103
5104=item newSVnv
5105X<newSVnv>
5106
5107Creates a new SV and copies a floating point value into it.
5108The reference count for the SV is set to 1.
5109
5110 SV* newSVnv(NV n)
5111
5112=for hackers
5113Found in file sv.c
5114
5115=item newSVpv
5116X<newSVpv>
5117
5118Creates a new SV and copies a string into it. The reference count for the
5119SV is set to 1. If C<len> is zero, Perl will compute the length using
5120strlen(). For efficiency, consider using C<newSVpvn> instead.
5121
5122 SV* newSVpv(const char* s, STRLEN len)
5123
5124=for hackers
5125Found in file sv.c
5126
5127=item newSVpvf
5128X<newSVpvf>
5129
5130Creates a new SV and initializes it with the string formatted like
5131C<sprintf>.
5132
5133 SV* newSVpvf(const char* pat, ...)
5134
5135=for hackers
5136Found in file sv.c
5137
5138=item newSVpvn
5139X<newSVpvn>
5140
5141Creates a new SV and copies a string into it. The reference count for the
5142SV is set to 1. Note that if C<len> is zero, Perl will create a zero length
5143string. You are responsible for ensuring that the source string is at least
5144C<len> bytes long. If the C<s> argument is NULL the new SV will be undefined.
5145
5146 SV* newSVpvn(const char* s, STRLEN len)
5147
5148=for hackers
5149Found in file sv.c
5150
740cce10
NC
5151=item newSVpvn_flags
5152X<newSVpvn_flags>
5153
5154Creates a new SV and copies a string into it. The reference count for the
5155SV is set to 1. Note that if C<len> is zero, Perl will create a zero length
5156string. You are responsible for ensuring that the source string is at least
5157C<len> bytes long. If the C<s> argument is NULL the new SV will be undefined.
5158Currently the only flag bit accepted is SVf_UTF8. If this is set, then it
5159will be set on the new SV. C<newSVpvn_utf8()> is a convenience wrapper for
5160this function, defined as
5161
5162 #define newSVpvn_utf8(s, len, u) \
5163 newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0)
5164
5165 SV* newSVpvn_flags(const char* s, STRLEN len, U32 flags)
5166
5167=for hackers
5168Found in file sv.c
5169
d2a0f284
JC
5170=item newSVpvn_share
5171X<newSVpvn_share>
5172
5173Creates a new SV with its SvPVX_const pointing to a shared string in the string
5174table. If the string does not already exist in the table, it is created
fe5bfecd
JH
5175first. Turns on READONLY and FAKE. If the C<hash> parameter is non-zero, that
5176value is used; otherwise the hash is computed. The string's hash can be later
5177be retrieved from the SV with the C<SvSHARED_HASH()> macro. The idea here is
5178that as the string table is used for shared hash keys these strings will have
5179SvPVX_const == HeKEY and hash lookup will avoid string compare.
d2a0f284
JC
5180
5181 SV* newSVpvn_share(const char* s, I32 len, U32 hash)
5182
5183=for hackers
5184Found in file sv.c
5185
3fe05580
MHM
5186=item newSVpvs
5187X<newSVpvs>
5188
5189Like C<newSVpvn>, but takes a literal string instead of a string/length pair.
5190
5191 SV* newSVpvs(const char* s)
5192
5193=for hackers
5194Found in file handy.h
5195
5196=item newSVpvs_share
5197X<newSVpvs_share>
5198
5199Like C<newSVpvn_share>, but takes a literal string instead of a string/length
5200pair and omits the hash parameter.
5201
5202 SV* newSVpvs_share(const char* s)
5203
5204=for hackers
5205Found in file handy.h
5206
d2a0f284
JC
5207=item newSVrv
5208X<newSVrv>
5209
5210Creates a new SV for the RV, C<rv>, to point to. If C<rv> is not an RV then
5211it will be upgraded to one. If C<classname> is non-null then the new SV will
5212be blessed in the specified package. The new SV is returned and its
5213reference count is 1.
5214
5215 SV* newSVrv(SV* rv, const char* classname)
5216
5217=for hackers
5218Found in file sv.c
5219
5220=item newSVsv
5221X<newSVsv>
5222
5223Creates a new SV which is an exact duplicate of the original SV.
5224(Uses C<sv_setsv>).
5225
5226 SV* newSVsv(SV* old)
5227
5228=for hackers
5229Found in file sv.c
5230
5231=item newSVuv
5232X<newSVuv>
5233
5234Creates a new SV and copies an unsigned integer into it.
5235The reference count for the SV is set to 1.
5236
5237 SV* newSVuv(UV u)
5238
5239=for hackers
5240Found in file sv.c
5241
bae1192d
JH
5242=item newSV_type
5243X<newSV_type>
5244
353c6505 5245Creates a new SV, of the type specified. The reference count for the new SV
bae1192d
JH
5246is set to 1.
5247
5248 SV* newSV_type(svtype type)
5249
5250=for hackers
5251Found in file sv.c
5252
645c22ef 5253=item sv_2bool
d8c40edc 5254X<sv_2bool>
645c22ef
DM
5255
5256This function is only called on magical items, and is only used by
8cf8f3d1 5257sv_true() or its macro equivalent.
645c22ef
DM
5258
5259 bool sv_2bool(SV* sv)
5260
5261=for hackers
5262Found in file sv.c
5263
5264=item sv_2cv
d8c40edc 5265X<sv_2cv>
645c22ef
DM
5266
5267Using various gambits, try to get a CV from an SV; in addition, try if
5268possible to set C<*st> and C<*gvp> to the stash and GV associated with it.
9f435386 5269The flags in C<lref> are passed to sv_fetchsv.
645c22ef
DM
5270
5271 CV* sv_2cv(SV* sv, HV** st, GV** gvp, I32 lref)
5272
5273=for hackers
5274Found in file sv.c
5275
5276=item sv_2io
d8c40edc 5277X<sv_2io>
645c22ef
DM
5278
5279Using various gambits, try to get an IO from an SV: the IO slot if its a
5280GV; or the recursive result if we're an RV; or the IO slot of the symbol
5281named after the PV if we're a string.
5282
5283 IO* sv_2io(SV* sv)
5284
5285=for hackers
5286Found in file sv.c
5287
891f9566 5288=item sv_2iv_flags
d8c40edc 5289X<sv_2iv_flags>
645c22ef 5290
891f9566
YST
5291Return the integer value of an SV, doing any necessary string
5292conversion. If flags includes SV_GMAGIC, does an mg_get() first.
5293Normally used via the C<SvIV(sv)> and C<SvIVx(sv)> macros.
645c22ef 5294
891f9566 5295 IV sv_2iv_flags(SV* sv, I32 flags)
645c22ef
DM
5296
5297=for hackers
5298Found in file sv.c
5299
954c1994 5300=item sv_2mortal
d8c40edc 5301X<sv_2mortal>
954c1994 5302
793edb8a
JH
5303Marks an existing SV as mortal. The SV will be destroyed "soon", either
5304by an explicit call to FREETMPS, or by an implicit call at places such as
b0bc38e6
NC
5305statement boundaries. SvTEMP() is turned on which means that the SV's
5306string buffer can be "stolen" if this SV is copied. See also C<sv_newmortal>
5307and C<sv_mortalcopy>.
954c1994
GS
5308
5309 SV* sv_2mortal(SV* sv)
5310
497711e7
GS
5311=for hackers
5312Found in file sv.c
5313
645c22ef 5314=item sv_2nv
d8c40edc 5315X<sv_2nv>
645c22ef
DM
5316
5317Return the num value of an SV, doing any necessary string or integer
5318conversion, magic etc. Normally used via the C<SvNV(sv)> and C<SvNVx(sv)>
5319macros.
5320
5321 NV sv_2nv(SV* sv)
5322
5323=for hackers
5324Found in file sv.c
5325
451be7b1 5326=item sv_2pvbyte
d8c40edc 5327X<sv_2pvbyte>
451be7b1
DM
5328
5329Return a pointer to the byte-encoded representation of the SV, and set *lp
1e54db1a 5330to its length. May cause the SV to be downgraded from UTF-8 as a
451be7b1
DM
5331side-effect.
5332
5333Usually accessed via the C<SvPVbyte> macro.
5334
5335 char* sv_2pvbyte(SV* sv, STRLEN* lp)
5336
5337=for hackers
5338Found in file sv.c
5339
035cbb0e
RGS
5340=item sv_2pvutf8
5341X<sv_2pvutf8>
5342
5343Return a pointer to the UTF-8-encoded representation of the SV, and set *lp
5344to its length. May cause the SV to be upgraded to UTF-8 as a side-effect.
5345
5346Usually accessed via the C<SvPVutf8> macro.
5347
5348 char* sv_2pvutf8(SV* sv, STRLEN* lp)
5349
5350=for hackers
5351Found in file sv.c
5352
645c22ef 5353=item sv_2pv_flags
d8c40edc 5354X<sv_2pv_flags>
645c22ef 5355
ff276b08 5356Returns a pointer to the string value of an SV, and sets *lp to its length.
645c22ef
DM
5357If flags includes SV_GMAGIC, does an mg_get() first. Coerces sv to a string
5358if necessary.
5359Normally invoked via the C<SvPV_flags> macro. C<sv_2pv()> and C<sv_2pv_nomg>
5360usually end up here too.
5361
5362 char* sv_2pv_flags(SV* sv, STRLEN* lp, I32 flags)
5363
5364=for hackers
5365Found in file sv.c
5366
891f9566 5367=item sv_2uv_flags
d8c40edc 5368X<sv_2uv_flags>
645c22ef
DM
5369
5370Return the unsigned integer value of an SV, doing any necessary string
891f9566
YST
5371conversion. If flags includes SV_GMAGIC, does an mg_get() first.
5372Normally used via the C<SvUV(sv)> and C<SvUVx(sv)> macros.
645c22ef 5373
891f9566 5374 UV sv_2uv_flags(SV* sv, I32 flags)
645c22ef
DM
5375
5376=for hackers
5377Found in file sv.c
5378
5379=item sv_backoff
d8c40edc 5380X<sv_backoff>
645c22ef
DM
5381
5382Remove any string offset. You should normally use the C<SvOOK_off> macro
5383wrapper instead.
5384
5385 int sv_backoff(SV* sv)
5386
5387=for hackers
5388Found in file sv.c
5389
954c1994 5390=item sv_bless
d8c40edc 5391X<sv_bless>
954c1994
GS
5392
5393Blesses an SV into a specified package. The SV must be an RV. The package
5394must be designated by its stash (see C<gv_stashpv()>). The reference count
5395of the SV is unaffected.
5396
5397 SV* sv_bless(SV* sv, HV* stash)
5398
497711e7
GS
5399=for hackers
5400Found in file sv.c
5401
954c1994 5402=item sv_catpv
d8c40edc 5403X<sv_catpv>
954c1994
GS
5404
5405Concatenates the string onto the end of the string which is in the SV.
1e54db1a
JH
5406If the SV has the UTF-8 status set, then the bytes appended should be
5407valid UTF-8. Handles 'get' magic, but not 'set' magic. See C<sv_catpv_mg>.
954c1994
GS
5408
5409 void sv_catpv(SV* sv, const char* ptr)
5410
497711e7
GS
5411=for hackers
5412Found in file sv.c
5413
954c1994 5414=item sv_catpvf
d8c40edc 5415X<sv_catpvf>
954c1994 5416
d5ce4a7c
GA
5417Processes its arguments like C<sprintf> and appends the formatted
5418output to an SV. If the appended data contains "wide" characters
5419(including, but not limited to, SVs with a UTF-8 PV formatted with %s,
5420and characters >255 formatted with %c), the original SV might get
bffc3d17 5421upgraded to UTF-8. Handles 'get' magic, but not 'set' magic. See
cdd94ca7
NC
5422C<sv_catpvf_mg>. If the original SV was UTF-8, the pattern should be
5423valid UTF-8; if the original SV was bytes, the pattern should be too.
954c1994
GS
5424
5425 void sv_catpvf(SV* sv, const char* pat, ...)
5426
497711e7
GS
5427=for hackers
5428Found in file sv.c
5429
954c1994 5430=item sv_catpvf_mg
d8c40edc 5431X<sv_catpvf_mg>
954c1994
GS
5432
5433Like C<sv_catpvf>, but also handles 'set' magic.
5434
5435 void sv_catpvf_mg(SV *sv, const char* pat, ...)
5436
497711e7
GS
5437=for hackers
5438Found in file sv.c
5439
954c1994 5440=item sv_catpvn
d8c40edc 5441X<sv_catpvn>
954c1994
GS
5442
5443Concatenates the string onto the end of the string which is in the SV. The
1e54db1a
JH
5444C<len> indicates number of bytes to copy. If the SV has the UTF-8
5445status set, then the bytes appended should be valid UTF-8.
d5ce4a7c 5446Handles 'get' magic, but not 'set' magic. See C<sv_catpvn_mg>.
954c1994
GS
5447
5448 void sv_catpvn(SV* sv, const char* ptr, STRLEN len)
5449
497711e7
GS
5450=for hackers
5451Found in file sv.c
5452
8d6d96c1 5453=item sv_catpvn_flags
d8c40edc 5454X<sv_catpvn_flags>
8d6d96c1
HS
5455
5456Concatenates the string onto the end of the string which is in the SV. The
1e54db1a
JH
5457C<len> indicates number of bytes to copy. If the SV has the UTF-8
5458status set, then the bytes appended should be valid UTF-8.
8d6d96c1
HS
5459If C<flags> has C<SV_GMAGIC> bit set, will C<mg_get> on C<dsv> if
5460appropriate, else not. C<sv_catpvn> and C<sv_catpvn_nomg> are implemented
5461in terms of this function.
5462
5463 void sv_catpvn_flags(SV* sv, const char* ptr, STRLEN len, I32 flags)
5464
5465=for hackers
5466Found in file sv.c
5467
3fe05580
MHM
5468=item sv_catpvs
5469X<sv_catpvs>
5470
5471Like C<sv_catpvn>, but takes a literal string instead of a string/length pair.
5472
f8f4df2c 5473 void sv_catpvs(SV* sv, const char* s)
3fe05580
MHM
5474
5475=for hackers
5476Found in file handy.h
5477
954c1994 5478=item sv_catpv_mg
d8c40edc 5479X<sv_catpv_mg>
954c1994
GS
5480
5481Like C<sv_catpv>, but also handles 'set' magic.
5482
5483 void sv_catpv_mg(SV *sv, const char *ptr)
5484
497711e7
GS
5485=for hackers
5486Found in file sv.c
5487
954c1994 5488=item sv_catsv
d8c40edc 5489X<sv_catsv>
954c1994 5490
1aa99e6b
IH
5491Concatenates the string from SV C<ssv> onto the end of the string in
5492SV C<dsv>. Modifies C<dsv> but not C<ssv>. Handles 'get' magic, but
5493not 'set' magic. See C<sv_catsv_mg>.
954c1994
GS
5494
5495 void sv_catsv(SV* dsv, SV* ssv)
5496
497711e7
GS
5497=for hackers
5498Found in file sv.c
5499
8d6d96c1 5500=item sv_catsv_flags
d8c40edc 5501X<sv_catsv_flags>
8d6d96c1
HS
5502
5503Concatenates the string from SV C<ssv> onto the end of the string in
5504SV C<dsv>. Modifies C<dsv> but not C<ssv>. If C<flags> has C<SV_GMAGIC>
5505bit set, will C<mg_get> on the SVs if appropriate, else not. C<sv_catsv>
5506and C<sv_catsv_nomg> are implemented in terms of this function.
5507
5508 void sv_catsv_flags(SV* dsv, SV* ssv, I32 flags)
5509
5510=for hackers
5511Found in file sv.c
5512
954c1994 5513=item sv_chop
d8c40edc 5514X<sv_chop>
954c1994 5515
1c846c1f 5516Efficient removal of characters from the beginning of the string buffer.
954c1994
GS
5517SvPOK(sv) must be true and the C<ptr> must be a pointer to somewhere inside
5518the string buffer. The C<ptr> becomes the first character of the adjusted
645c22ef 5519string. Uses the "OOK hack".
3f7c398e 5520Beware: after this function returns, C<ptr> and SvPVX_const(sv) may no longer
5c3943b6 5521refer to the same chunk of data.
954c1994 5522
f54cb97a 5523 void sv_chop(SV* sv, const char* ptr)
954c1994 5524
497711e7
GS
5525=for hackers
5526Found in file sv.c
5527
c461cf8f 5528=item sv_clear
d8c40edc 5529X<sv_clear>
c461cf8f 5530
645c22ef
DM
5531Clear an SV: call any destructors, free up any memory used by the body,
5532and free the body itself. The SV's head is I<not> freed, although
5533its type is set to all 1's so that it won't inadvertently be assumed
5534to be live during global destruction etc.
5535This function should only be called when REFCNT is zero. Most of the time
5536you'll want to call C<sv_free()> (or its macro wrapper C<SvREFCNT_dec>)
5537instead.
c461cf8f
JH
5538
5539 void sv_clear(SV* sv)
5540
5541=for hackers
5542Found in file sv.c
5543
954c1994 5544=item sv_cmp
d8c40edc 5545X<sv_cmp>
954c1994
GS
5546
5547Compares the strings in two SVs. Returns -1, 0, or 1 indicating whether the
5548string in C<sv1> is less than, equal to, or greater than the string in
645c22ef
DM
5549C<sv2>. Is UTF-8 and 'use bytes' aware, handles get magic, and will
5550coerce its args to strings if necessary. See also C<sv_cmp_locale>.
954c1994
GS
5551
5552 I32 sv_cmp(SV* sv1, SV* sv2)
5553
497711e7
GS
5554=for hackers
5555Found in file sv.c
5556
c461cf8f 5557=item sv_cmp_locale
d8c40edc 5558X<sv_cmp_locale>
c461cf8f 5559
645c22ef
DM
5560Compares the strings in two SVs in a locale-aware manner. Is UTF-8 and
5561'use bytes' aware, handles get magic, and will coerce its args to strings
5562if necessary. See also C<sv_cmp_locale>. See also C<sv_cmp>.
c461cf8f
JH
5563
5564 I32 sv_cmp_locale(SV* sv1, SV* sv2)
5565
5566=for hackers
5567Found in file sv.c
5568
645c22ef 5569=item sv_collxfrm
d8c40edc 5570X<sv_collxfrm>
645c22ef
DM
5571
5572Add Collate Transform magic to an SV if it doesn't already have it.
5573
5574Any scalar variable may carry PERL_MAGIC_collxfrm magic that contains the
5575scalar data of the variable, but transformed to such a format that a normal
5576memory comparison can be used to compare the data according to the locale
5577settings.
5578
5579 char* sv_collxfrm(SV* sv, STRLEN* nxp)
5580
5581=for hackers
5582Found in file sv.c
5583
6050d10e 5584=item sv_copypv
d8c40edc 5585X<sv_copypv>
6050d10e
JP
5586
5587Copies a stringified representation of the source SV into the
5588destination SV. Automatically performs any necessary mg_get and
9ede5bc8 5589coercion of numeric values into strings. Guaranteed to preserve
2575c402 5590UTF8 flag even from overloaded objects. Similar in nature to
9ede5bc8
DM
5591sv_2pv[_flags] but operates directly on an SV instead of just the
5592string. Mostly uses sv_2pv_flags to do its work, except when that
6050d10e
JP
5593would lose the UTF-8'ness of the PV.
5594
5595 void sv_copypv(SV* dsv, SV* ssv)
5596
5597=for hackers
5598Found in file sv.c
5599
954c1994 5600=item sv_dec
d8c40edc 5601X<sv_dec>
954c1994 5602
645c22ef
DM
5603Auto-decrement of the value in the SV, doing string to numeric conversion
5604if necessary. Handles 'get' magic.
954c1994
GS
5605
5606 void sv_dec(SV* sv)
5607
497711e7
GS
5608=for hackers
5609Found in file sv.c
5610
954c1994 5611=item sv_eq
d8c40edc 5612X<sv_eq>
954c1994
GS
5613
5614Returns a boolean indicating whether the strings in the two SVs are
645c22ef
DM
5615identical. Is UTF-8 and 'use bytes' aware, handles get magic, and will
5616coerce its args to strings if necessary.
954c1994
GS
5617
5618 I32 sv_eq(SV* sv1, SV* sv2)
5619
497711e7
GS
5620=for hackers
5621Found in file sv.c
5622
645c22ef 5623=item sv_force_normal_flags
d8c40edc 5624X<sv_force_normal_flags>
645c22ef
DM
5625
5626Undo various types of fakery on an SV: if the PV is a shared string, make
5627a private copy; if we're a ref, stop refing; if we're a glob, downgrade to
765f542d
NC
5628an xpvmg; if we're a copy-on-write scalar, this is the on-write time when
5629we do the copy, and is also used locally. If C<SV_COW_DROP_PV> is set
5630then a copy-on-write scalar drops its PV buffer (if any) and becomes
5631SvPOK_off rather than making a copy. (Used where this scalar is about to be
d3050d9d 5632set to some other value.) In addition, the C<flags> parameter gets passed to
765f542d
NC
5633C<sv_unref_flags()> when unrefing. C<sv_force_normal> calls this function
5634with flags set to 0.
645c22ef
DM
5635
5636 void sv_force_normal_flags(SV *sv, U32 flags)
5637
5638=for hackers
5639Found in file sv.c
5640
c461cf8f 5641=item sv_free
d8c40edc 5642X<sv_free>
c461cf8f 5643
645c22ef
DM
5644Decrement an SV's reference count, and if it drops to zero, call
5645C<sv_clear> to invoke destructors and free up any memory used by
5646the body; finally, deallocate the SV's head itself.
5647Normally called via a wrapper macro C<SvREFCNT_dec>.
c461cf8f
JH
5648
5649 void sv_free(SV* sv)
5650
5651=for hackers
5652Found in file sv.c
5653
5654=item sv_gets
d8c40edc 5655X<sv_gets>
c461cf8f
JH
5656
5657Get a line from the filehandle and store it into the SV, optionally
5658appending to the currently-stored string.
5659
5660 char* sv_gets(SV* sv, PerlIO* fp, I32 append)
5661
5662=for hackers
5663Found in file sv.c
5664
954c1994 5665=item sv_grow
d8c40edc 5666X<sv_grow>
954c1994 5667
645c22ef
DM
5668Expands the character buffer in the SV. If necessary, uses C<sv_unref> and
5669upgrades the SV to C<SVt_PV>. Returns a pointer to the character buffer.
5670Use the C<SvGROW> wrapper instead.
954c1994
GS
5671
5672 char* sv_grow(SV* sv, STRLEN newlen)
5673
497711e7
GS
5674=for hackers
5675Found in file sv.c
5676
954c1994 5677=item sv_inc
d8c40edc 5678X<sv_inc>
954c1994 5679
645c22ef
DM
5680Auto-increment of the value in the SV, doing string to numeric conversion
5681if necessary. Handles 'get' magic.
954c1994
GS
5682
5683 void sv_inc(SV* sv)
5684
497711e7
GS
5685=for hackers
5686Found in file sv.c
5687
954c1994 5688=item sv_insert
d8c40edc 5689X<sv_insert>
954c1994
GS
5690
5691Inserts a string at the specified offset/length within the SV. Similar to
5692the Perl substr() function.
5693
e1ec3a88 5694 void sv_insert(SV* bigsv, STRLEN offset, STRLEN len, const char* little, STRLEN littlelen)
954c1994 5695
497711e7
GS
5696=for hackers
5697Found in file sv.c
5698
954c1994 5699=item sv_isa
d8c40edc 5700X<sv_isa>
954c1994
GS
5701
5702Returns a boolean indicating whether the SV is blessed into the specified
5703class. This does not check for subtypes; use C<sv_derived_from> to verify
5704an inheritance relationship.
5705
5706 int sv_isa(SV* sv, const char* name)
5707
497711e7
GS
5708=for hackers
5709Found in file sv.c
5710
954c1994 5711=item sv_isobject
d8c40edc 5712X<sv_isobject>
954c1994
GS
5713
5714Returns a boolean indicating whether the SV is an RV pointing to a blessed
5715object. If the SV is not an RV, or if the object is not blessed, then this
5716will return false.
5717
5718 int sv_isobject(SV* sv)
5719
497711e7
GS
5720=for hackers
5721Found in file sv.c
5722
954c1994 5723=item sv_len
d8c40edc 5724X<sv_len>
954c1994 5725
645c22ef
DM
5726Returns the length of the string in the SV. Handles magic and type
5727coercion. See also C<SvCUR>, which gives raw access to the xpv_cur slot.
954c1994
GS
5728
5729 STRLEN sv_len(SV* sv)
5730
497711e7
GS
5731=for hackers
5732Found in file sv.c
5733
c461cf8f 5734=item sv_len_utf8
d8c40edc 5735X<sv_len_utf8>
c461cf8f
JH
5736
5737Returns the number of characters in the string in an SV, counting wide
1e54db1a 5738UTF-8 bytes as a single character. Handles magic and type coercion.
c461cf8f
JH
5739
5740 STRLEN sv_len_utf8(SV* sv)
5741
5742=for hackers
5743Found in file sv.c
5744
954c1994 5745=item sv_magic
d8c40edc 5746X<sv_magic>
954c1994 5747
645c22ef
DM
5748Adds magic to an SV. First upgrades C<sv> to type C<SVt_PVMG> if necessary,
5749then adds a new magic item of type C<how> to the head of the magic list.
5750
2d8d5d5a
SH
5751See C<sv_magicext> (which C<sv_magic> now calls) for a description of the
5752handling of the C<name> and C<namlen> arguments.
5753
4509d3fb
SB
5754You need to use C<sv_magicext> to add magic to SvREADONLY SVs and also
5755to add more than one instance of the same 'how'.
5756
954c1994
GS
5757 void sv_magic(SV* sv, SV* obj, int how, const char* name, I32 namlen)
5758
497711e7
GS
5759=for hackers
5760Found in file sv.c
5761
a4f1a029 5762=item sv_magicext
d8c40edc 5763X<sv_magicext>
a4f1a029
NIS
5764
5765Adds magic to an SV, upgrading it if necessary. Applies the
2d8d5d5a 5766supplied vtable and returns a pointer to the magic added.
a4f1a029 5767
2d8d5d5a
SH
5768Note that C<sv_magicext> will allow things that C<sv_magic> will not.
5769In particular, you can add magic to SvREADONLY SVs, and add more than
5770one instance of the same 'how'.
a4f1a029 5771
2d8d5d5a
SH
5772If C<namlen> is greater than zero then a C<savepvn> I<copy> of C<name> is
5773stored, if C<namlen> is zero then C<name> is stored as-is and - as another
5774special case - if C<(name && namlen == HEf_SVKEY)> then C<name> is assumed
5775to contain an C<SV*> and is stored as-is with its REFCNT incremented.
a4f1a029 5776
2d8d5d5a 5777(This is now used as a subroutine by C<sv_magic>.)
a4f1a029 5778
53d44271 5779 MAGIC * sv_magicext(SV* sv, SV* obj, int how, const MGVTBL *vtbl, const char* name, I32 namlen)
a4f1a029
NIS
5780
5781=for hackers
5782Found in file sv.c
5783
954c1994 5784=item sv_mortalcopy
d8c40edc 5785X<sv_mortalcopy>
954c1994 5786
645c22ef 5787Creates a new SV which is a copy of the original SV (using C<sv_setsv>).
793edb8a
JH
5788The new SV is marked as mortal. It will be destroyed "soon", either by an
5789explicit call to FREETMPS, or by an implicit call at places such as
5790statement boundaries. See also C<sv_newmortal> and C<sv_2mortal>.
954c1994
GS
5791
5792 SV* sv_mortalcopy(SV* oldsv)
5793
497711e7
GS
5794=for hackers
5795Found in file sv.c
5796
954c1994 5797=item sv_newmortal
d8c40edc 5798X<sv_newmortal>
954c1994 5799
645c22ef 5800Creates a new null SV which is mortal. The reference count of the SV is
793edb8a
JH
5801set to 1. It will be destroyed "soon", either by an explicit call to
5802FREETMPS, or by an implicit call at places such as statement boundaries.
5803See also C<sv_mortalcopy> and C<sv_2mortal>.
954c1994
GS
5804
5805 SV* sv_newmortal()
5806
497711e7
GS
5807=for hackers
5808Found in file sv.c
5809
645c22ef 5810=item sv_newref
d8c40edc 5811X<sv_newref>
645c22ef
DM
5812
5813Increment an SV's reference count. Use the C<SvREFCNT_inc()> wrapper
5814instead.
5815
5816 SV* sv_newref(SV* sv)
5817
5818=for hackers
5819Found in file sv.c
5820
645c22ef 5821=item sv_pos_b2u
d8c40edc 5822X<sv_pos_b2u>
645c22ef
DM
5823
5824Converts the value pointed to by offsetp from a count of bytes from the
1e54db1a 5825start of the string, to a count of the equivalent number of UTF-8 chars.
645c22ef
DM
5826Handles magic and type coercion.
5827
5828 void sv_pos_b2u(SV* sv, I32* offsetp)
5829
5830=for hackers
5831Found in file sv.c
5832
5833=item sv_pos_u2b
d8c40edc 5834X<sv_pos_u2b>
645c22ef 5835
1e54db1a 5836Converts the value pointed to by offsetp from a count of UTF-8 chars from
645c22ef
DM
5837the start of the string, to a count of the equivalent number of bytes; if
5838lenp is non-zero, it does the same to lenp, but this time starting from
5839the offset, rather than from the start of the string. Handles magic and
5840type coercion.
5841
5842 void sv_pos_u2b(SV* sv, I32* offsetp, I32* lenp)
5843
5844=for hackers
5845Found in file sv.c
5846
645c22ef 5847=item sv_pvbyten_force
d8c40edc 5848X<sv_pvbyten_force>
645c22ef 5849
9244d4ad 5850The backend for the C<SvPVbytex_force> macro. Always use the macro instead.
645c22ef
DM
5851
5852 char* sv_pvbyten_force(SV* sv, STRLEN* lp)
5853
5854=for hackers
5855Found in file sv.c
5856
c461cf8f 5857=item sv_pvn_force
d8c40edc 5858X<sv_pvn_force>
c461cf8f
JH
5859
5860Get a sensible string out of the SV somehow.
645c22ef
DM
5861A private implementation of the C<SvPV_force> macro for compilers which
5862can't cope with complex macro expressions. Always use the macro instead.
c461cf8f
JH
5863
5864 char* sv_pvn_force(SV* sv, STRLEN* lp)
5865
5866=for hackers
5867Found in file sv.c
5868
8d6d96c1 5869=item sv_pvn_force_flags
d8c40edc 5870X<sv_pvn_force_flags>
8d6d96c1
HS
5871
5872Get a sensible string out of the SV somehow.
5873If C<flags> has C<SV_GMAGIC> bit set, will C<mg_get> on C<sv> if
5874appropriate, else not. C<sv_pvn_force> and C<sv_pvn_force_nomg> are
5875implemented in terms of this function.
645c22ef
DM
5876You normally want to use the various wrapper macros instead: see
5877C<SvPV_force> and C<SvPV_force_nomg>
8d6d96c1
HS
5878
5879 char* sv_pvn_force_flags(SV* sv, STRLEN* lp, I32 flags)
5880
5881=for hackers
5882Found in file sv.c
5883
c461cf8f 5884=item sv_pvutf8n_force
d8c40edc 5885X<sv_pvutf8n_force>
c461cf8f 5886
9244d4ad 5887The backend for the C<SvPVutf8x_force> macro. Always use the macro instead.
c461cf8f
JH
5888
5889 char* sv_pvutf8n_force(SV* sv, STRLEN* lp)
5890
5891=for hackers
5892Found in file sv.c
5893
5894=item sv_reftype
d8c40edc 5895X<sv_reftype>
c461cf8f
JH
5896
5897Returns a string describing what the SV is a reference to.
5898
2b388283 5899 const char* sv_reftype(const SV* sv, int ob)
c461cf8f
JH
5900
5901=for hackers
5902Found in file sv.c
5903
5904=item sv_replace
d8c40edc 5905X<sv_replace>
c461cf8f
JH
5906
5907Make the first argument a copy of the second, then delete the original.
645c22ef
DM
5908The target SV physically takes over ownership of the body of the source SV
5909and inherits its flags; however, the target keeps any magic it owns,
5910and any magic in the source is discarded.
ff276b08 5911Note that this is a rather specialist SV copying operation; most of the
645c22ef 5912time you'll want to use C<sv_setsv> or one of its many macro front-ends.
c461cf8f
JH
5913
5914 void sv_replace(SV* sv, SV* nsv)
5915
5916=for hackers
5917Found in file sv.c
5918
451be7b1 5919=item sv_reset
d8c40edc 5920X<sv_reset>
451be7b1
DM
5921
5922Underlying implementation for the C<reset> Perl function.
5923Note that the perl-level function is vaguely deprecated.
5924
e1ec3a88 5925 void sv_reset(const char* s, HV* stash)
451be7b1
DM
5926
5927=for hackers
5928Found in file sv.c
5929
c461cf8f 5930=item sv_rvweaken
d8c40edc 5931X<sv_rvweaken>
c461cf8f 5932
645c22ef
DM
5933Weaken a reference: set the C<SvWEAKREF> flag on this RV; give the
5934referred-to SV C<PERL_MAGIC_backref> magic if it hasn't already; and
5935push a back-reference to this RV onto the array of backreferences
1e73acc8
AS
5936associated with that magic. If the RV is magical, set magic will be
5937called after the RV is cleared.
c461cf8f
JH
5938
5939 SV* sv_rvweaken(SV *sv)
5940
5941=for hackers
5942Found in file sv.c
5943
954c1994 5944=item sv_setiv
d8c40edc 5945X<sv_setiv>
954c1994 5946
645c22ef
DM
5947Copies an integer into the given SV, upgrading first if necessary.
5948Does not handle 'set' magic. See also C<sv_setiv_mg>.
954c1994
GS
5949
5950 void sv_setiv(SV* sv, IV num)
5951
497711e7
GS
5952=for hackers
5953Found in file sv.c
5954
954c1994 5955=item sv_setiv_mg
d8c40edc 5956X<sv_setiv_mg>
954c1994
GS
5957
5958Like C<sv_setiv>, but also handles 'set' magic.
5959
5960 void sv_setiv_mg(SV *sv, IV i)
5961
497711e7
GS
5962=for hackers
5963Found in file sv.c
5964
954c1994 5965=item sv_setnv
d8c40edc 5966X<sv_setnv>
954c1994 5967
645c22ef
DM
5968Copies a double into the given SV, upgrading first if necessary.
5969Does not handle 'set' magic. See also C<sv_setnv_mg>.
954c1994
GS
5970
5971 void sv_setnv(SV* sv, NV num)
5972
497711e7
GS
5973=for hackers
5974Found in file sv.c
5975
954c1994 5976=item sv_setnv_mg
d8c40edc 5977X<sv_setnv_mg>
954c1994
GS
5978
5979Like C<sv_setnv>, but also handles 'set' magic.
5980
5981 void sv_setnv_mg(SV *sv, NV num)
5982
497711e7
GS
5983=for hackers
5984Found in file sv.c
5985
954c1994 5986=item sv_setpv
d8c40edc 5987X<sv_setpv>
954c1994
GS
5988
5989Copies a string into an SV. The string must be null-terminated. Does not
5990handle 'set' magic. See C<sv_setpv_mg>.
5991
5992 void sv_setpv(SV* sv, const char* ptr)
5993
497711e7
GS
5994=for hackers
5995Found in file sv.c
5996
954c1994 5997=item sv_setpvf
d8c40edc 5998X<sv_setpvf>
954c1994 5999
bffc3d17
SH
6000Works like C<sv_catpvf> but copies the text into the SV instead of
6001appending it. Does not handle 'set' magic. See C<sv_setpvf_mg>.
954c1994
GS
6002
6003 void sv_setpvf(SV* sv, const char* pat, ...)
6004
497711e7
GS
6005=for hackers
6006Found in file sv.c
6007
954c1994 6008=item sv_setpvf_mg
d8c40edc 6009X<sv_setpvf_mg>
954c1994
GS
6010
6011Like C<sv_setpvf>, but also handles 'set' magic.
6012
6013 void sv_setpvf_mg(SV *sv, const char* pat, ...)
6014
497711e7
GS
6015=for hackers
6016Found in file sv.c
6017
2307c6d0 6018=item sv_setpviv
d8c40edc 6019X<sv_setpviv>
2307c6d0
SB
6020
6021Copies an integer into the given SV, also updating its string value.
6022Does not handle 'set' magic. See C<sv_setpviv_mg>.
6023
6024 void sv_setpviv(SV* sv, IV num)
6025
6026=for hackers
6027Found in file sv.c
6028
6029=item sv_setpviv_mg
d8c40edc 6030X<sv_setpviv_mg>
2307c6d0
SB
6031
6032Like C<sv_setpviv>, but also handles 'set' magic.
6033
6034 void sv_setpviv_mg(SV *sv, IV iv)
6035
6036=for hackers
6037Found in file sv.c
6038
954c1994 6039=item sv_setpvn
d8c40edc 6040X<sv_setpvn>
954c1994
GS
6041
6042Copies a string into an SV. The C<len> parameter indicates the number of
9e09f5f2
MHM
6043bytes to be copied. If the C<ptr> argument is NULL the SV will become
6044undefined. Does not handle 'set' magic. See C<sv_setpvn_mg>.
954c1994
GS
6045
6046 void sv_setpvn(SV* sv, const char* ptr, STRLEN len)
6047
497711e7
GS
6048=for hackers
6049Found in file sv.c
6050
954c1994 6051=item sv_setpvn_mg
d8c40edc 6052X<sv_setpvn_mg>
954c1994
GS
6053
6054Like C<sv_setpvn>, but also handles 'set' magic.
6055
6056 void sv_setpvn_mg(SV *sv, const char *ptr, STRLEN len)
6057
497711e7
GS
6058=for hackers
6059Found in file sv.c
6060
3fe05580
MHM
6061=item sv_setpvs
6062X<sv_setpvs>
6063
6064Like C<sv_setpvn>, but takes a literal string instead of a string/length pair.
6065
f8f4df2c 6066 void sv_setpvs(SV* sv, const char* s)
3fe05580
MHM
6067
6068=for hackers
6069Found in file handy.h
6070
954c1994 6071=item sv_setpv_mg
d8c40edc 6072X<sv_setpv_mg>
954c1994
GS
6073
6074Like C<sv_setpv>, but also handles 'set' magic.
6075
6076 void sv_setpv_mg(SV *sv, const char *ptr)
6077
497711e7
GS
6078=for hackers
6079Found in file sv.c
6080
954c1994 6081=item sv_setref_iv
d8c40edc 6082X<sv_setref_iv>
954c1994
GS
6083
6084Copies an integer into a new SV, optionally blessing the SV. The C<rv>
6085argument will be upgraded to an RV. That RV will be modified to point to
6086the new SV. The C<classname> argument indicates the package for the
bd61b366 6087blessing. Set C<classname> to C<NULL> to avoid the blessing. The new SV
d34c2299 6088will have a reference count of 1, and the RV will be returned.
954c1994
GS
6089
6090 SV* sv_setref_iv(SV* rv, const char* classname, IV iv)
6091
497711e7
GS
6092=for hackers
6093Found in file sv.c
6094
954c1994 6095=item sv_setref_nv
d8c40edc 6096X<sv_setref_nv>
954c1994
GS
6097
6098Copies a double into a new SV, optionally blessing the SV. The C<rv>
6099argument will be upgraded to an RV. That RV will be modified to point to
6100the new SV. The C<classname> argument indicates the package for the
bd61b366 6101blessing. Set C<classname> to C<NULL> to avoid the blessing. The new SV
d34c2299 6102will have a reference count of 1, and the RV will be returned.
954c1994
GS
6103
6104 SV* sv_setref_nv(SV* rv, const char* classname, NV nv)
6105
497711e7
GS
6106=for hackers
6107Found in file sv.c
6108
954c1994 6109=item sv_setref_pv
d8c40edc 6110X<sv_setref_pv>
954c1994
GS
6111
6112Copies a pointer into a new SV, optionally blessing the SV. The C<rv>
6113argument will be upgraded to an RV. That RV will be modified to point to
6114the new SV. If the C<pv> argument is NULL then C<PL_sv_undef> will be placed
6115into the SV. The C<classname> argument indicates the package for the
bd61b366 6116blessing. Set C<classname> to C<NULL> to avoid the blessing. The new SV
d34c2299 6117will have a reference count of 1, and the RV will be returned.
954c1994
GS
6118
6119Do not use with other Perl types such as HV, AV, SV, CV, because those
6120objects will become corrupted by the pointer copy process.
6121
6122Note that C<sv_setref_pvn> copies the string while this copies the pointer.
6123
6124 SV* sv_setref_pv(SV* rv, const char* classname, void* pv)
6125
497711e7
GS
6126=for hackers
6127Found in file sv.c
6128
954c1994 6129=item sv_setref_pvn
d8c40edc 6130X<sv_setref_pvn>
954c1994
GS
6131
6132Copies a string into a new SV, optionally blessing the SV. The length of the
6133string must be specified with C<n>. The C<rv> argument will be upgraded to
6134an RV. That RV will be modified to point to the new SV. The C<classname>
6135argument indicates the package for the blessing. Set C<classname> to
bd61b366 6136C<NULL> to avoid the blessing. The new SV will have a reference count
d34c2299 6137of 1, and the RV will be returned.
954c1994
GS
6138
6139Note that C<sv_setref_pv> copies the pointer while this copies the string.
6140
1b6737cc 6141 SV* sv_setref_pvn(SV* rv, const char* classname, const char* pv, STRLEN n)
954c1994 6142
497711e7
GS
6143=for hackers
6144Found in file sv.c
6145
e1c57cef 6146=item sv_setref_uv
d8c40edc 6147X<sv_setref_uv>
e1c57cef
JH
6148
6149Copies an unsigned integer into a new SV, optionally blessing the SV. The C<rv>
6150argument will be upgraded to an RV. That RV will be modified to point to
6151the new SV. The C<classname> argument indicates the package for the
bd61b366 6152blessing. Set C<classname> to C<NULL> to avoid the blessing. The new SV
d34c2299 6153will have a reference count of 1, and the RV will be returned.
e1c57cef
JH
6154
6155 SV* sv_setref_uv(SV* rv, const char* classname, UV uv)
6156
6157=for hackers
6158Found in file sv.c
6159
954c1994 6160=item sv_setsv
d8c40edc 6161X<sv_setsv>
954c1994 6162
645c22ef
DM
6163Copies the contents of the source SV C<ssv> into the destination SV
6164C<dsv>. The source SV may be destroyed if it is mortal, so don't use this
6165function if the source SV needs to be reused. Does not handle 'set' magic.
6166Loosely speaking, it performs a copy-by-value, obliterating any previous
6167content of the destination.
6168
6169You probably want to use one of the assortment of wrappers, such as
6170C<SvSetSV>, C<SvSetSV_nosteal>, C<SvSetMagicSV> and
6171C<SvSetMagicSV_nosteal>.
6172
954c1994
GS
6173 void sv_setsv(SV* dsv, SV* ssv)
6174
497711e7
GS
6175=for hackers
6176Found in file sv.c
6177
8d6d96c1 6178=item sv_setsv_flags
d8c40edc 6179X<sv_setsv_flags>
8d6d96c1 6180
645c22ef
DM
6181Copies the contents of the source SV C<ssv> into the destination SV
6182C<dsv>. The source SV may be destroyed if it is mortal, so don't use this
6183function if the source SV needs to be reused. Does not handle 'set' magic.
6184Loosely speaking, it performs a copy-by-value, obliterating any previous
6185content of the destination.
6186If the C<flags> parameter has the C<SV_GMAGIC> bit set, will C<mg_get> on
2d8d5d5a
SH
6187C<ssv> if appropriate, else not. If the C<flags> parameter has the
6188C<NOSTEAL> bit set then the buffers of temps will not be stolen. <sv_setsv>
6189and C<sv_setsv_nomg> are implemented in terms of this function.
645c22ef
DM
6190
6191You probably want to use one of the assortment of wrappers, such as
6192C<SvSetSV>, C<SvSetSV_nosteal>, C<SvSetMagicSV> and
6193C<SvSetMagicSV_nosteal>.
6194
6195This is the primary function for copying scalars, and most other
6196copy-ish functions and macros use this underneath.
8d6d96c1
HS
6197
6198 void sv_setsv_flags(SV* dsv, SV* ssv, I32 flags)
6199
6200=for hackers
6201Found in file sv.c
6202
954c1994 6203=item sv_setsv_mg
d8c40edc 6204X<sv_setsv_mg>
954c1994
GS
6205
6206Like C<sv_setsv>, but also handles 'set' magic.
6207
6208 void sv_setsv_mg(SV *dstr, SV *sstr)
6209
497711e7
GS
6210=for hackers
6211Found in file sv.c
6212
954c1994 6213=item sv_setuv
d8c40edc 6214X<sv_setuv>
954c1994 6215
645c22ef
DM
6216Copies an unsigned integer into the given SV, upgrading first if necessary.
6217Does not handle 'set' magic. See also C<sv_setuv_mg>.
954c1994
GS
6218
6219 void sv_setuv(SV* sv, UV num)
6220
497711e7
GS
6221=for hackers
6222Found in file sv.c
6223
954c1994 6224=item sv_setuv_mg
d8c40edc 6225X<sv_setuv_mg>
954c1994
GS
6226
6227Like C<sv_setuv>, but also handles 'set' magic.
6228
6229 void sv_setuv_mg(SV *sv, UV u)
6230
497711e7
GS
6231=for hackers
6232Found in file sv.c
6233
451be7b1 6234=item sv_tainted
d8c40edc 6235X<sv_tainted>
451be7b1
DM
6236
6237Test an SV for taintedness. Use C<SvTAINTED> instead.
6238 bool sv_tainted(SV* sv)
6239
6240=for hackers
6241Found in file sv.c
6242
c461cf8f 6243=item sv_true
d8c40edc 6244X<sv_true>
c461cf8f
JH
6245
6246Returns true if the SV has a true value by Perl's rules.
645c22ef
DM
6247Use the C<SvTRUE> macro instead, which may call C<sv_true()> or may
6248instead use an in-line version.
c461cf8f
JH
6249
6250 I32 sv_true(SV *sv)
6251
6252=for hackers
6253Found in file sv.c
6254
6255=item sv_unmagic
d8c40edc 6256X<sv_unmagic>
c461cf8f 6257
645c22ef 6258Removes all magic of type C<type> from an SV.
c461cf8f
JH
6259
6260 int sv_unmagic(SV* sv, int type)
6261
6262=for hackers
6263Found in file sv.c
6264
840a7b70 6265=item sv_unref_flags
d8c40edc 6266X<sv_unref_flags>
840a7b70
IZ
6267
6268Unsets the RV status of the SV, and decrements the reference count of
6269whatever was being referenced by the RV. This can almost be thought of
6270as a reversal of C<newSVrv>. The C<cflags> argument can contain
6271C<SV_IMMEDIATE_UNREF> to force the reference count to be decremented
6272(otherwise the decrementing is conditional on the reference count being
6273different from one or the reference being a readonly SV).
ae154d6d 6274See C<SvROK_off>.
840a7b70
IZ
6275
6276 void sv_unref_flags(SV* sv, U32 flags)
6277
6278=for hackers
6279Found in file sv.c
6280
451be7b1 6281=item sv_untaint
d8c40edc 6282X<sv_untaint>
451be7b1
DM
6283
6284Untaint an SV. Use C<SvTAINTED_off> instead.
6285 void sv_untaint(SV* sv)
6286
6287=for hackers
6288Found in file sv.c
6289
954c1994 6290=item sv_upgrade
d8c40edc 6291X<sv_upgrade>
954c1994 6292
ff276b08 6293Upgrade an SV to a more complex form. Generally adds a new body type to the
645c22ef 6294SV, then copies across as much information as possible from the old body.
ff276b08 6295You generally want to use the C<SvUPGRADE> macro wrapper. See also C<svtype>.
954c1994 6296
42d0e0b7 6297 void sv_upgrade(SV* sv, svtype new_type)
954c1994 6298
497711e7
GS
6299=for hackers
6300Found in file sv.c
6301
fed01289
SP
6302=item sv_usepvn_flags
6303X<sv_usepvn_flags>
954c1994 6304
794a0d33
JH
6305Tells an SV to use C<ptr> to find its string value. Normally the
6306string is stored inside the SV but sv_usepvn allows the SV to use an
6307outside string. The C<ptr> should point to memory that was allocated
fed01289
SP
6308by C<malloc>. The string length, C<len>, must be supplied. By default
6309this function will realloc (i.e. move) the memory pointed to by C<ptr>,
794a0d33
JH
6310so that pointer should not be freed or used by the programmer after
6311giving it to sv_usepvn, and neither should any pointers from "behind"
fed01289 6312that pointer (e.g. ptr + 1) be used.
954c1994 6313
fed01289
SP
6314If C<flags> & SV_SMAGIC is true, will call SvSETMAGIC. If C<flags> &
6315SV_HAS_TRAILING_NUL is true, then C<ptr[len]> must be NUL, and the realloc
cbf82dd0 6316will be skipped. (i.e. the buffer is actually at least 1 byte longer than
fed01289 6317C<len>, and already meets the requirements for storing in C<SvPVX>)
954c1994 6318
fed01289 6319 void sv_usepvn_flags(SV* sv, char* ptr, STRLEN len, U32 flags)
954c1994 6320
497711e7
GS
6321=for hackers
6322Found in file sv.c
6323
2457d041 6324=item sv_utf8_decode
d8c40edc 6325X<sv_utf8_decode>
2457d041 6326
78ea37eb
TS
6327If the PV of the SV is an octet sequence in UTF-8
6328and contains a multiple-byte character, the C<SvUTF8> flag is turned on
6329so that it looks like a character. If the PV contains only single-byte
6330characters, the C<SvUTF8> flag stays being off.
6331Scans PV for validity and returns false if the PV is invalid UTF-8.
2457d041
JH
6332
6333NOTE: this function is experimental and may change or be
6334removed without notice.
6335
6336 bool sv_utf8_decode(SV *sv)
6337
6338=for hackers
6339Found in file sv.c
6340
c461cf8f 6341=item sv_utf8_downgrade
d8c40edc 6342X<sv_utf8_downgrade>
c461cf8f 6343
78ea37eb
TS
6344Attempts to convert the PV of an SV from characters to bytes.
6345If the PV contains a character beyond byte, this conversion will fail;
6346in this case, either returns false or, if C<fail_ok> is not
c461cf8f
JH
6347true, croaks.
6348
9ede5bc8
DM
6349This is not as a general purpose Unicode to byte encoding interface:
6350use the Encode extension for that.
6351
c461cf8f
JH
6352NOTE: this function is experimental and may change or be
6353removed without notice.
6354
6355 bool sv_utf8_downgrade(SV *sv, bool fail_ok)
6356
6357=for hackers
6358Found in file sv.c
6359
6360=item sv_utf8_encode
d8c40edc 6361X<sv_utf8_encode>
c461cf8f 6362
78ea37eb
TS
6363Converts the PV of an SV to UTF-8, but then turns the C<SvUTF8>
6364flag off so that it looks like octets again.
c461cf8f
JH
6365
6366 void sv_utf8_encode(SV *sv)
6367
6368=for hackers
6369Found in file sv.c
6370
6371=item sv_utf8_upgrade
d8c40edc 6372X<sv_utf8_upgrade>
c461cf8f 6373
78ea37eb 6374Converts the PV of an SV to its UTF-8-encoded form.
645c22ef 6375Forces the SV to string form if it is not already.
2457d041
JH
6376Always sets the SvUTF8 flag to avoid future validity checks even
6377if all the bytes have hibit clear.
c461cf8f 6378
9ede5bc8
DM
6379This is not as a general purpose byte encoding to Unicode interface:
6380use the Encode extension for that.
6381
2457d041 6382 STRLEN sv_utf8_upgrade(SV *sv)
c461cf8f
JH
6383
6384=for hackers
6385Found in file sv.c
6386
8d6d96c1 6387=item sv_utf8_upgrade_flags
d8c40edc 6388X<sv_utf8_upgrade_flags>
8d6d96c1 6389
78ea37eb 6390Converts the PV of an SV to its UTF-8-encoded form.
645c22ef 6391Forces the SV to string form if it is not already.
8d6d96c1
HS
6392Always sets the SvUTF8 flag to avoid future validity checks even
6393if all the bytes have hibit clear. If C<flags> has C<SV_GMAGIC> bit set,
6394will C<mg_get> on C<sv> if appropriate, else not. C<sv_utf8_upgrade> and
6395C<sv_utf8_upgrade_nomg> are implemented in terms of this function.
6396
9ede5bc8
DM
6397This is not as a general purpose byte encoding to Unicode interface:
6398use the Encode extension for that.
6399
8d6d96c1
HS
6400 STRLEN sv_utf8_upgrade_flags(SV *sv, I32 flags)
6401
6402=for hackers
6403Found in file sv.c
6404
bffc3d17 6405=item sv_vcatpvf
d8c40edc 6406X<sv_vcatpvf>
bffc3d17
SH
6407
6408Processes its arguments like C<vsprintf> and appends the formatted output
6409to an SV. Does not handle 'set' magic. See C<sv_vcatpvf_mg>.
6410
6411Usually used via its frontend C<sv_catpvf>.
6412
6413 void sv_vcatpvf(SV* sv, const char* pat, va_list* args)
6414
6415=for hackers
6416Found in file sv.c
6417
954c1994 6418=item sv_vcatpvfn
d8c40edc 6419X<sv_vcatpvfn>
954c1994
GS
6420
6421Processes its arguments like C<vsprintf> and appends the formatted output
6422to an SV. Uses an array of SVs if the C style variable argument list is
6423missing (NULL). When running with taint checks enabled, indicates via
6424C<maybe_tainted> if results are untrustworthy (often due to the use of
6425locales).
6426
bffc3d17 6427Usually used via one of its frontends C<sv_vcatpvf> and C<sv_vcatpvf_mg>.
645c22ef 6428
954c1994
GS
6429 void sv_vcatpvfn(SV* sv, const char* pat, STRLEN patlen, va_list* args, SV** svargs, I32 svmax, bool *maybe_tainted)
6430
497711e7
GS
6431=for hackers
6432Found in file sv.c
6433
bffc3d17 6434=item sv_vcatpvf_mg
d8c40edc 6435X<sv_vcatpvf_mg>
bffc3d17
SH
6436
6437Like C<sv_vcatpvf>, but also handles 'set' magic.
6438
6439Usually used via its frontend C<sv_catpvf_mg>.
6440
6441 void sv_vcatpvf_mg(SV* sv, const char* pat, va_list* args)
6442
6443=for hackers
6444Found in file sv.c
6445
6446=item sv_vsetpvf
d8c40edc 6447X<sv_vsetpvf>
bffc3d17
SH
6448
6449Works like C<sv_vcatpvf> but copies the text into the SV instead of
6450appending it. Does not handle 'set' magic. See C<sv_vsetpvf_mg>.
6451
6452Usually used via its frontend C<sv_setpvf>.
6453
6454 void sv_vsetpvf(SV* sv, const char* pat, va_list* args)
6455
6456=for hackers
6457Found in file sv.c
6458
954c1994 6459=item sv_vsetpvfn
d8c40edc 6460X<sv_vsetpvfn>
954c1994 6461
bffc3d17 6462Works like C<sv_vcatpvfn> but copies the text into the SV instead of
954c1994
GS
6463appending it.
6464
bffc3d17 6465Usually used via one of its frontends C<sv_vsetpvf> and C<sv_vsetpvf_mg>.
645c22ef 6466
954c1994
GS
6467 void sv_vsetpvfn(SV* sv, const char* pat, STRLEN patlen, va_list* args, SV** svargs, I32 svmax, bool *maybe_tainted)
6468
497711e7 6469=for hackers
94bdecf9
JH
6470Found in file sv.c
6471
bffc3d17 6472=item sv_vsetpvf_mg
d8c40edc 6473X<sv_vsetpvf_mg>
bffc3d17
SH
6474
6475Like C<sv_vsetpvf>, but also handles 'set' magic.
6476
6477Usually used via its frontend C<sv_setpvf_mg>.
6478
6479 void sv_vsetpvf_mg(SV* sv, const char* pat, va_list* args)
6480
6481=for hackers
6482Found in file sv.c
6483
94bdecf9
JH
6484
6485=back
6486
6487=head1 Unicode Support
6488
6489=over 8
6490
6491=item bytes_from_utf8
d8c40edc 6492X<bytes_from_utf8>
94bdecf9 6493
1e54db1a 6494Converts a string C<s> of length C<len> from UTF-8 into byte encoding.
35a4481c 6495Unlike C<utf8_to_bytes> but like C<bytes_to_utf8>, returns a pointer to
94bdecf9
JH
6496the newly-created string, and updates C<len> to contain the new
6497length. Returns the original string if no conversion occurs, C<len>
6498is unchanged. Do nothing if C<is_utf8> points to 0. Sets C<is_utf8> to
64990 if C<s> is converted or contains all 7bit characters.
6500
6501NOTE: this function is experimental and may change or be
6502removed without notice.
6503
e1ec3a88 6504 U8* bytes_from_utf8(const U8 *s, STRLEN *len, bool *is_utf8)
94bdecf9
JH
6505
6506=for hackers
6507Found in file utf8.c
6508
6509=item bytes_to_utf8
d8c40edc 6510X<bytes_to_utf8>
94bdecf9 6511
1e54db1a 6512Converts a string C<s> of length C<len> from ASCII into UTF-8 encoding.
94bdecf9
JH
6513Returns a pointer to the newly-created string, and sets C<len> to
6514reflect the new length.
6515
1e54db1a 6516If you want to convert to UTF-8 from other encodings than ASCII,
bd5cf849
HS
6517see sv_recode_to_utf8().
6518
94bdecf9
JH
6519NOTE: this function is experimental and may change or be
6520removed without notice.
6521
35a4481c 6522 U8* bytes_to_utf8(const U8 *s, STRLEN *len)
94bdecf9
JH
6523
6524=for hackers
6525Found in file utf8.c
6526
6527=item ibcmp_utf8
d8c40edc 6528X<ibcmp_utf8>
94bdecf9
JH
6529
6530Return true if the strings s1 and s2 differ case-insensitively, false
6531if not (if they are equal case-insensitively). If u1 is true, the
6532string s1 is assumed to be in UTF-8-encoded Unicode. If u2 is true,
6533the string s2 is assumed to be in UTF-8-encoded Unicode. If u1 or u2
6534are false, the respective string is assumed to be in native 8-bit
6535encoding.
6536
6537If the pe1 and pe2 are non-NULL, the scanning pointers will be copied
6538in there (they will point at the beginning of the I<next> character).
6539If the pointers behind pe1 or pe2 are non-NULL, they are the end
6540pointers beyond which scanning will not continue under any
fa11829f 6541circumstances. If the byte lengths l1 and l2 are non-zero, s1+l1 and
94bdecf9
JH
6542s2+l2 will be used as goal end pointers that will also stop the scan,
6543and which qualify towards defining a successful match: all the scans
6544that define an explicit length must reach their goal pointers for
6545a match to succeed).
6546
6547For case-insensitiveness, the "casefolding" of Unicode is used
6548instead of upper/lowercasing both the characters, see
6549http://www.unicode.org/unicode/reports/tr21/ (Case Mappings).
6550
6551 I32 ibcmp_utf8(const char* a, char **pe1, UV l1, bool u1, const char* b, char **pe2, UV l2, bool u2)
6552
6553=for hackers
6554Found in file utf8.c
6555
6556=item is_utf8_char
d8c40edc 6557X<is_utf8_char>
94bdecf9
JH
6558
6559Tests if some arbitrary number of bytes begins in a valid UTF-8
641d4181
JH
6560character. Note that an INVARIANT (i.e. ASCII) character is a valid
6561UTF-8 character. The actual number of bytes in the UTF-8 character
6562will be returned if it is valid, otherwise 0.
94bdecf9 6563
7fc63493 6564 STRLEN is_utf8_char(const U8 *p)
94bdecf9
JH
6565
6566=for hackers
6567Found in file utf8.c
6568
6569=item is_utf8_string
d8c40edc 6570X<is_utf8_string>
94bdecf9 6571
bd5cf849 6572Returns true if first C<len> bytes of the given string form a valid
1e54db1a
JH
6573UTF-8 string, false otherwise. Note that 'a valid UTF-8 string' does
6574not mean 'a string that contains code points above 0x7F encoded in UTF-8'
6575because a valid ASCII string is a valid UTF-8 string.
94bdecf9 6576
768c67ee
JH
6577See also is_utf8_string_loclen() and is_utf8_string_loc().
6578
7fc63493 6579 bool is_utf8_string(const U8 *s, STRLEN len)
94bdecf9
JH
6580
6581=for hackers
6582Found in file utf8.c
497711e7 6583
72d6ef7d 6584=item is_utf8_string_loc
d8c40edc 6585X<is_utf8_string_loc>
72d6ef7d 6586
9244d4ad 6587Like is_utf8_string() but stores the location of the failure (in the
768c67ee
JH
6588case of "utf8ness failure") or the location s+len (in the case of
6589"utf8ness success") in the C<ep>.
6590
6591See also is_utf8_string_loclen() and is_utf8_string().
72d6ef7d 6592
7fc63493 6593 bool is_utf8_string_loc(const U8 *s, STRLEN len, const U8 **p)
72d6ef7d
JH
6594
6595=for hackers
6596Found in file utf8.c
6597
768c67ee 6598=item is_utf8_string_loclen
d8c40edc 6599X<is_utf8_string_loclen>
768c67ee 6600
9244d4ad 6601Like is_utf8_string() but stores the location of the failure (in the
768c67ee
JH
6602case of "utf8ness failure") or the location s+len (in the case of
6603"utf8ness success") in the C<ep>, and the number of UTF-8
6604encoded characters in the C<el>.
6605
6606See also is_utf8_string_loc() and is_utf8_string().
6607
6608 bool is_utf8_string_loclen(const U8 *s, STRLEN len, const U8 **ep, STRLEN *el)
6609
6610=for hackers
6611Found in file utf8.c
6612
94bdecf9 6613=item pv_uni_display
d8c40edc 6614X<pv_uni_display>
954c1994 6615
94bdecf9
JH
6616Build to the scalar dsv a displayable version of the string spv,
6617length len, the displayable version being at most pvlim bytes long
6618(if longer, the rest is truncated and "..." will be appended).
0a2ef054
JH
6619
6620The flags argument can have UNI_DISPLAY_ISPRINT set to display
a4f1a029 6621isPRINT()able characters as themselves, UNI_DISPLAY_BACKSLASH
0a2ef054
JH
6622to display the \\[nrfta\\] as the backslashed versions (like '\n')
6623(UNI_DISPLAY_BACKSLASH is preferred over UNI_DISPLAY_ISPRINT for \\).
6624UNI_DISPLAY_QQ (and its alias UNI_DISPLAY_REGEX) have both
6625UNI_DISPLAY_BACKSLASH and UNI_DISPLAY_ISPRINT turned on.
6626
94bdecf9 6627The pointer to the PV of the dsv is returned.
954c1994 6628
e1ec3a88 6629 char* pv_uni_display(SV *dsv, const U8 *spv, STRLEN len, STRLEN pvlim, UV flags)
954c1994 6630
497711e7 6631=for hackers
94bdecf9 6632Found in file utf8.c
497711e7 6633
220e2d4e 6634=item sv_cat_decode
d8c40edc 6635X<sv_cat_decode>
220e2d4e
IH
6636
6637The encoding is assumed to be an Encode object, the PV of the ssv is
6638assumed to be octets in that encoding and decoding the input starts
6639from the position which (PV + *offset) pointed to. The dsv will be
6640concatenated the decoded UTF-8 string from ssv. Decoding will terminate
6641when the string tstr appears in decoding output or the input ends on
6642the PV of the ssv. The value which the offset points will be modified
6643to the last input position on the ssv.
6644
6645Returns TRUE if the terminator was found, else returns FALSE.
6646
6647 bool sv_cat_decode(SV* dsv, SV *encoding, SV *ssv, int *offset, char* tstr, int tlen)
6648
6649=for hackers
6650Found in file sv.c
6651
94bdecf9 6652=item sv_recode_to_utf8
d8c40edc 6653X<sv_recode_to_utf8>
954c1994 6654
94bdecf9
JH
6655The encoding is assumed to be an Encode object, on entry the PV
6656of the sv is assumed to be octets in that encoding, and the sv
6657will be converted into Unicode (and UTF-8).
954c1994 6658
94bdecf9
JH
6659If the sv already is UTF-8 (or if it is not POK), or if the encoding
6660is not a reference, nothing is done to the sv. If the encoding is not
6661an C<Encode::XS> Encoding object, bad things will happen.
6662(See F<lib/encoding.pm> and L<Encode>).
6663
6664The PV of the sv is returned.
6665
6666 char* sv_recode_to_utf8(SV* sv, SV *encoding)
954c1994 6667
497711e7 6668=for hackers
94bdecf9 6669Found in file sv.c
497711e7 6670
94bdecf9 6671=item sv_uni_display
d8c40edc 6672X<sv_uni_display>
954c1994 6673
94bdecf9 6674Build to the scalar dsv a displayable version of the scalar sv,
0a2ef054 6675the displayable version being at most pvlim bytes long
94bdecf9 6676(if longer, the rest is truncated and "..." will be appended).
0a2ef054
JH
6677
6678The flags argument is as in pv_uni_display().
6679
94bdecf9 6680The pointer to the PV of the dsv is returned.
954c1994 6681
94bdecf9 6682 char* sv_uni_display(SV *dsv, SV *ssv, STRLEN pvlim, UV flags)
954c1994 6683
497711e7 6684=for hackers
94bdecf9 6685Found in file utf8.c
497711e7 6686
6b5c0936 6687=item to_utf8_case
d8c40edc 6688X<to_utf8_case>
6b5c0936
JH
6689
6690The "p" contains the pointer to the UTF-8 string encoding
6691the character that is being converted.
6692
6693The "ustrp" is a pointer to the character buffer to put the
6694conversion result to. The "lenp" is a pointer to the length
6695of the result.
6696
12b7c5c7 6697The "swashp" is a pointer to the swash to use.
6b5c0936 6698
12b7c5c7 6699Both the special and normal mappings are stored lib/unicore/To/Foo.pl,
979f2922 6700and loaded by SWASHNEW, using lib/utf8_heavy.pl. The special (usually,
12b7c5c7
JH
6701but not always, a multicharacter mapping), is tried first.
6702
6703The "special" is a string like "utf8::ToSpecLower", which means the
6704hash %utf8::ToSpecLower. The access to the hash is through
6705Perl_to_utf8_case().
6b5c0936 6706
12b7c5c7
JH
6707The "normal" is a string like "ToLower" which means the swash
6708%utf8::ToLower.
6b5c0936 6709
9a957fbc 6710 UV to_utf8_case(const U8 *p, U8* ustrp, STRLEN *lenp, SV **swashp, const char *normal, const char *special)
6b5c0936
JH
6711
6712=for hackers
6713Found in file utf8.c
6714
d3e79532 6715=item to_utf8_fold
d8c40edc 6716X<to_utf8_fold>
d3e79532
JH
6717
6718Convert the UTF-8 encoded character at p to its foldcase version and
6719store that in UTF-8 in ustrp and its length in bytes in lenp. Note
59887a99 6720that the ustrp needs to be at least UTF8_MAXBYTES_CASE+1 bytes since the
d3e79532
JH
6721foldcase version may be longer than the original character (up to
6722three characters).
6723
6724The first character of the foldcased version is returned
6725(but note, as explained above, that there may be more.)
6726
7fc63493 6727 UV to_utf8_fold(const U8 *p, U8* ustrp, STRLEN *lenp)
d3e79532
JH
6728
6729=for hackers
6730Found in file utf8.c
6731
6732=item to_utf8_lower
d8c40edc 6733X<to_utf8_lower>
d3e79532
JH
6734
6735Convert the UTF-8 encoded character at p to its lowercase version and
6736store that in UTF-8 in ustrp and its length in bytes in lenp. Note
59887a99
MHM
6737that the ustrp needs to be at least UTF8_MAXBYTES_CASE+1 bytes since the
6738lowercase version may be longer than the original character.
d3e79532
JH
6739
6740The first character of the lowercased version is returned
6741(but note, as explained above, that there may be more.)
6742
7fc63493 6743 UV to_utf8_lower(const U8 *p, U8* ustrp, STRLEN *lenp)
d3e79532
JH
6744
6745=for hackers
6746Found in file utf8.c
6747
6748=item to_utf8_title
d8c40edc 6749X<to_utf8_title>
d3e79532
JH
6750
6751Convert the UTF-8 encoded character at p to its titlecase version and
6752store that in UTF-8 in ustrp and its length in bytes in lenp. Note
59887a99
MHM
6753that the ustrp needs to be at least UTF8_MAXBYTES_CASE+1 bytes since the
6754titlecase version may be longer than the original character.
d3e79532
JH
6755
6756The first character of the titlecased version is returned
6757(but note, as explained above, that there may be more.)
6758
7fc63493 6759 UV to_utf8_title(const U8 *p, U8* ustrp, STRLEN *lenp)
d3e79532
JH
6760
6761=for hackers
6762Found in file utf8.c
6763
6764=item to_utf8_upper
d8c40edc 6765X<to_utf8_upper>
d3e79532
JH
6766
6767Convert the UTF-8 encoded character at p to its uppercase version and
6768store that in UTF-8 in ustrp and its length in bytes in lenp. Note
59887a99
MHM
6769that the ustrp needs to be at least UTF8_MAXBYTES_CASE+1 bytes since
6770the uppercase version may be longer than the original character.
d3e79532
JH
6771
6772The first character of the uppercased version is returned
6773(but note, as explained above, that there may be more.)
6774
7fc63493 6775 UV to_utf8_upper(const U8 *p, U8* ustrp, STRLEN *lenp)
d3e79532
JH
6776
6777=for hackers
6778Found in file utf8.c
6779
cd299c6e
RGS
6780=item utf8n_to_uvchr
6781X<utf8n_to_uvchr>
6782
6783flags
6784
6785Returns the native character value of the first character in the string
6786C<s>
6787which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
6788length, in bytes, of that character.
6789
6790Allows length and flags to be passed to low level routine.
6791
6792 UV utf8n_to_uvchr(const U8 *s, STRLEN curlen, STRLEN *retlen, U32 flags)
6793
6794=for hackers
6795Found in file utf8.c
6796
282f25c9 6797=item utf8n_to_uvuni
d8c40edc 6798X<utf8n_to_uvuni>
282f25c9
JH
6799
6800Bottom level UTF-8 decode routine.
38a44b82 6801Returns the Unicode code point value of the first character in the string C<s>
1e54db1a 6802which is assumed to be in UTF-8 encoding and no longer than C<curlen>;
282f25c9
JH
6803C<retlen> will be set to the length, in bytes, of that character.
6804
1e54db1a 6805If C<s> does not point to a well-formed UTF-8 character, the behaviour
282f25c9
JH
6806is dependent on the value of C<flags>: if it contains UTF8_CHECK_ONLY,
6807it is assumed that the caller will raise a warning, and this function
6808will silently just set C<retlen> to C<-1> and return zero. If the
6809C<flags> does not contain UTF8_CHECK_ONLY, warnings about
6810malformations will be given, C<retlen> will be set to the expected
6811length of the UTF-8 character in bytes, and zero will be returned.
6812
6813The C<flags> can also contain various flags to allow deviations from
6814the strict UTF-8 encoding (see F<utf8.h>).
6815
6816Most code should use utf8_to_uvchr() rather than call this directly.
6817
9a957fbc 6818 UV utf8n_to_uvuni(const U8 *s, STRLEN curlen, STRLEN *retlen, U32 flags)
282f25c9
JH
6819
6820=for hackers
6821Found in file utf8.c
6822
b06226ff 6823=item utf8_distance
d8c40edc 6824X<utf8_distance>
b06226ff 6825
1e54db1a 6826Returns the number of UTF-8 characters between the UTF-8 pointers C<a>
b06226ff
JH
6827and C<b>.
6828
6829WARNING: use only if you *know* that the pointers point inside the
6830same UTF-8 buffer.
6831
35a4481c 6832 IV utf8_distance(const U8 *a, const U8 *b)
b06226ff
JH
6833
6834=for hackers
6835Found in file utf8.c
6836
6837=item utf8_hop
d8c40edc 6838X<utf8_hop>
b06226ff 6839
8850bf83
JH
6840Return the UTF-8 pointer C<s> displaced by C<off> characters, either
6841forward or backward.
b06226ff
JH
6842
6843WARNING: do not use the following unless you *know* C<off> is within
8850bf83
JH
6844the UTF-8 data pointed to by C<s> *and* that on entry C<s> is aligned
6845on the first byte of character or just after the last byte of a character.
b06226ff 6846
4373e329 6847 U8* utf8_hop(const U8 *s, I32 off)
b06226ff
JH
6848
6849=for hackers
6850Found in file utf8.c
6851
6852=item utf8_length
d8c40edc 6853X<utf8_length>
b06226ff
JH
6854
6855Return the length of the UTF-8 char encoded string C<s> in characters.
6856Stops at C<e> (inclusive). If C<e E<lt> s> or if the scan would end
6857up past C<e>, croaks.
6858
35a4481c 6859 STRLEN utf8_length(const U8* s, const U8 *e)
b06226ff
JH
6860
6861=for hackers
6862Found in file utf8.c
6863
497711e7 6864=item utf8_to_bytes
d8c40edc 6865X<utf8_to_bytes>
497711e7 6866
1e54db1a 6867Converts a string C<s> of length C<len> from UTF-8 into byte encoding.
246fae53
MG
6868Unlike C<bytes_to_utf8>, this over-writes the original string, and
6869updates len to contain the new length.
67e989fb 6870Returns zero on failure, setting C<len> to -1.
497711e7 6871
95be277c
NC
6872If you need a copy of the string, see C<bytes_from_utf8>.
6873
eebe1485
SC
6874NOTE: this function is experimental and may change or be
6875removed without notice.
6876
6877 U8* utf8_to_bytes(U8 *s, STRLEN *len)
497711e7
GS
6878
6879=for hackers
6880Found in file utf8.c
6881
282f25c9 6882=item utf8_to_uvchr
d8c40edc 6883X<utf8_to_uvchr>
b6b716fe 6884
282f25c9 6885Returns the native character value of the first character in the string C<s>
1e54db1a 6886which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
282f25c9 6887length, in bytes, of that character.
28d3d195 6888
1e54db1a 6889If C<s> does not point to a well-formed UTF-8 character, zero is
282f25c9 6890returned and retlen is set, if possible, to -1.
444155da 6891
9a957fbc 6892 UV utf8_to_uvchr(const U8 *s, STRLEN *retlen)
444155da
JH
6893
6894=for hackers
6895Found in file utf8.c
6896
282f25c9 6897=item utf8_to_uvuni
d8c40edc 6898X<utf8_to_uvuni>
444155da 6899
282f25c9 6900Returns the Unicode code point of the first character in the string C<s>
1e54db1a 6901which is assumed to be in UTF-8 encoding; C<retlen> will be set to the
1aa99e6b 6902length, in bytes, of that character.
444155da 6903
282f25c9
JH
6904This function should only be used when returned UV is considered
6905an index into the Unicode semantic tables (e.g. swashes).
6906
1e54db1a 6907If C<s> does not point to a well-formed UTF-8 character, zero is
dcad2880 6908returned and retlen is set, if possible, to -1.
b6b716fe 6909
9a957fbc 6910 UV utf8_to_uvuni(const U8 *s, STRLEN *retlen)
282f25c9
JH
6911
6912=for hackers
6913Found in file utf8.c
6914
cd299c6e
RGS
6915=item uvchr_to_utf8
6916X<uvchr_to_utf8>
6917
6918Adds the UTF-8 representation of the Native codepoint C<uv> to the end
6919of the string C<d>; C<d> should be have at least C<UTF8_MAXBYTES+1> free
6920bytes available. The return value is the pointer to the byte after the
6921end of the new character. In other words,
6922
6923 d = uvchr_to_utf8(d, uv);
6924
6925is the recommended wide native character-aware way of saying
6926
6927 *(d++) = uv;
6928
6929 U8* uvchr_to_utf8(U8 *d, UV uv)
6930
6931=for hackers
6932Found in file utf8.c
6933
b851fbc1 6934=item uvuni_to_utf8_flags
d8c40edc 6935X<uvuni_to_utf8_flags>
eebe1485 6936
1e54db1a 6937Adds the UTF-8 representation of the Unicode codepoint C<uv> to the end
59887a99 6938of the string C<d>; C<d> should be have at least C<UTF8_MAXBYTES+1> free
eebe1485 6939bytes available. The return value is the pointer to the byte after the
282f25c9 6940end of the new character. In other words,
eebe1485 6941
b851fbc1
JH
6942 d = uvuni_to_utf8_flags(d, uv, flags);
6943
6944or, in most cases,
6945
282f25c9 6946 d = uvuni_to_utf8(d, uv);
eebe1485 6947
b851fbc1
JH
6948(which is equivalent to)
6949
6950 d = uvuni_to_utf8_flags(d, uv, 0);
6951
eebe1485
SC
6952is the recommended Unicode-aware way of saying
6953
6954 *(d++) = uv;
6955
b851fbc1 6956 U8* uvuni_to_utf8_flags(U8 *d, UV uv, UV flags)
b6b716fe
SC
6957
6958=for hackers
6959Found in file utf8.c
6960
497711e7 6961
94bdecf9 6962=back
954c1994 6963
94bdecf9 6964=head1 Variables created by C<xsubpp> and C<xsubpp> internal functions
954c1994 6965
94bdecf9 6966=over 8
954c1994 6967
94bdecf9 6968=item ax
d8c40edc 6969X<ax>
497711e7 6970
94bdecf9
JH
6971Variable which is setup by C<xsubpp> to indicate the stack base offset,
6972used by the C<ST>, C<XSprePUSH> and C<XSRETURN> macros. The C<dMARK> macro
6973must be called prior to setup the C<MARK> variable.
954c1994 6974
94bdecf9 6975 I32 ax
954c1994 6976
497711e7
GS
6977=for hackers
6978Found in file XSUB.h
6979
94bdecf9 6980=item CLASS
d8c40edc 6981X<CLASS>
954c1994 6982
94bdecf9
JH
6983Variable which is setup by C<xsubpp> to indicate the
6984class name for a C++ XS constructor. This is always a C<char*>. See C<THIS>.
954c1994 6985
94bdecf9 6986 char* CLASS
954c1994 6987
497711e7
GS
6988=for hackers
6989Found in file XSUB.h
6990
94bdecf9 6991=item dAX
d8c40edc 6992X<dAX>
954c1994 6993
94bdecf9
JH
6994Sets up the C<ax> variable.
6995This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
954c1994 6996
94bdecf9 6997 dAX;
954c1994 6998
497711e7
GS
6999=for hackers
7000Found in file XSUB.h
7001
557b887a 7002=item dAXMARK
d8c40edc 7003X<dAXMARK>
557b887a
SS
7004
7005Sets up the C<ax> variable and stack marker variable C<mark>.
7006This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
7007
7008 dAXMARK;
7009
7010=for hackers
7011Found in file XSUB.h
7012
94bdecf9 7013=item dITEMS
d8c40edc 7014X<dITEMS>
954c1994 7015
94bdecf9
JH
7016Sets up the C<items> variable.
7017This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
954c1994 7018
94bdecf9 7019 dITEMS;
954c1994 7020
497711e7
GS
7021=for hackers
7022Found in file XSUB.h
7023
88037a85 7024=item dUNDERBAR
d8c40edc 7025X<dUNDERBAR>
88037a85
RGS
7026
7027Sets up the C<padoff_du> variable for an XSUB that wishes to use
7028C<UNDERBAR>.
7029
7030 dUNDERBAR;
7031
7032=for hackers
7033Found in file XSUB.h
7034
94bdecf9 7035=item dXSARGS
d8c40edc 7036X<dXSARGS>
954c1994 7037
94bdecf9
JH
7038Sets up stack and mark pointers for an XSUB, calling dSP and dMARK.
7039Sets up the C<ax> and C<items> variables by calling C<dAX> and C<dITEMS>.
7040This is usually handled automatically by C<xsubpp>.
954c1994 7041
94bdecf9 7042 dXSARGS;
954c1994 7043
497711e7
GS
7044=for hackers
7045Found in file XSUB.h
7046
94bdecf9 7047=item dXSI32
d8c40edc 7048X<dXSI32>
954c1994 7049
94bdecf9
JH
7050Sets up the C<ix> variable for an XSUB which has aliases. This is usually
7051handled automatically by C<xsubpp>.
954c1994 7052
94bdecf9 7053 dXSI32;
954c1994 7054
497711e7
GS
7055=for hackers
7056Found in file XSUB.h
7057
94bdecf9 7058=item items
d8c40edc 7059X<items>
954c1994 7060
94bdecf9
JH
7061Variable which is setup by C<xsubpp> to indicate the number of
7062items on the stack. See L<perlxs/"Variable-length Parameter Lists">.
954c1994 7063
94bdecf9 7064 I32 items
954c1994 7065
497711e7
GS
7066=for hackers
7067Found in file XSUB.h
7068
94bdecf9 7069=item ix
d8c40edc 7070X<ix>
954c1994 7071
94bdecf9
JH
7072Variable which is setup by C<xsubpp> to indicate which of an
7073XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">.
954c1994 7074
94bdecf9 7075 I32 ix
954c1994 7076
497711e7
GS
7077=for hackers
7078Found in file XSUB.h
7079
94bdecf9 7080=item newXSproto
d8c40edc 7081X<newXSproto>
954c1994 7082
94bdecf9
JH
7083Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to
7084the subs.
954c1994 7085
497711e7
GS
7086=for hackers
7087Found in file XSUB.h
7088
94bdecf9 7089=item RETVAL
d8c40edc 7090X<RETVAL>
954c1994 7091
94bdecf9
JH
7092Variable which is setup by C<xsubpp> to hold the return value for an
7093XSUB. This is always the proper type for the XSUB. See
7094L<perlxs/"The RETVAL Variable">.
954c1994 7095
94bdecf9 7096 (whatever) RETVAL
954c1994 7097
497711e7
GS
7098=for hackers
7099Found in file XSUB.h
7100
94bdecf9 7101=item ST
d8c40edc 7102X<ST>
954c1994 7103
94bdecf9 7104Used to access elements on the XSUB's stack.
954c1994 7105
94bdecf9 7106 SV* ST(int ix)
954c1994 7107
497711e7
GS
7108=for hackers
7109Found in file XSUB.h
7110
94bdecf9 7111=item THIS
d8c40edc 7112X<THIS>
954c1994 7113
94bdecf9
JH
7114Variable which is setup by C<xsubpp> to designate the object in a C++
7115XSUB. This is always the proper type for the C++ object. See C<CLASS> and
7116L<perlxs/"Using XS With C++">.
954c1994 7117
94bdecf9 7118 (whatever) THIS
954c1994 7119
497711e7
GS
7120=for hackers
7121Found in file XSUB.h
7122
88037a85 7123=item UNDERBAR
d8c40edc 7124X<UNDERBAR>
88037a85
RGS
7125
7126The SV* corresponding to the $_ variable. Works even if there
7127is a lexical $_ in scope.
7128
7129=for hackers
7130Found in file XSUB.h
7131
94bdecf9 7132=item XS
d8c40edc 7133X<XS>
954c1994 7134
94bdecf9
JH
7135Macro to declare an XSUB and its C parameter list. This is handled by
7136C<xsubpp>.
954c1994 7137
497711e7
GS
7138=for hackers
7139Found in file XSUB.h
7140
954c1994 7141=item XS_VERSION
d8c40edc 7142X<XS_VERSION>
954c1994
GS
7143
7144The version identifier for an XS module. This is usually
7145handled automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>.
7146
497711e7
GS
7147=for hackers
7148Found in file XSUB.h
7149
954c1994 7150=item XS_VERSION_BOOTCHECK
d8c40edc 7151X<XS_VERSION_BOOTCHECK>
954c1994
GS
7152
7153Macro to verify that a PM module's $VERSION variable matches the XS
7154module's C<XS_VERSION> variable. This is usually handled automatically by
7155C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.
7156
7157 XS_VERSION_BOOTCHECK;
7158
497711e7
GS
7159=for hackers
7160Found in file XSUB.h
7161
954c1994 7162
94bdecf9 7163=back
954c1994 7164
94bdecf9
JH
7165=head1 Warning and Dieing
7166
7167=over 8
7168
7169=item croak
d8c40edc 7170X<croak>
94bdecf9
JH
7171
7172This is the XSUB-writer's interface to Perl's C<die> function.
966353fd
MF
7173Normally call this function the same way you call the C C<printf>
7174function. Calling C<croak> returns control directly to Perl,
7175sidestepping the normal C order of execution. See C<warn>.
94bdecf9
JH
7176
7177If you want to throw an exception object, assign the object to
bd61b366 7178C<$@> and then pass C<NULL> to croak():
94bdecf9
JH
7179
7180 errsv = get_sv("@", TRUE);
7181 sv_setsv(errsv, exception_object);
bd61b366 7182 croak(NULL);
94bdecf9
JH
7183
7184 void croak(const char* pat, ...)
954c1994 7185
497711e7 7186=for hackers
94bdecf9
JH
7187Found in file util.c
7188
7189=item warn
d8c40edc 7190X<warn>
94bdecf9 7191
966353fd
MF
7192This is the XSUB-writer's interface to Perl's C<warn> function. Call this
7193function the same way you call the C C<printf> function. See C<croak>.
94bdecf9
JH
7194
7195 void warn(const char* pat, ...)
7196
7197=for hackers
7198Found in file util.c
7199
497711e7 7200
954c1994
GS
7201=back
7202
7203=head1 AUTHORS
7204
7205Until May 1997, this document was maintained by Jeff Okamoto
7206<okamoto@corp.hp.com>. It is now maintained as part of Perl itself.
7207
7208With lots of help and suggestions from Dean Roehrich, Malcolm Beattie,
7209Andreas Koenig, Paul Hudson, Ilya Zakharevich, Paul Marquess, Neil
7210Bowers, Matthew Green, Tim Bunce, Spider Boardman, Ulrich Pfeifer,
7211Stephen McCamant, and Gurusamy Sarathy.
7212
7213API Listing originally by Dean Roehrich <roehrich@cray.com>.
7214
7215Updated to be autogenerated from comments in the source by Benjamin Stuhl.
7216
7217=head1 SEE ALSO
7218
7219perlguts(1), perlxs(1), perlxstut(1), perlintern(1)
7220
e0492643
NC
7221=cut
7222
3f98fbb3 7223 ex: set ro: