Skip to content

Commit 338e324

Browse files
committed
perlapi: Reword savepv entry
I think this makes it clearer
1 parent e96b722 commit 338e324

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

inline.h

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4628,40 +4628,50 @@ Perl_padnamelist_refcnt_inc(PADNAMELIST *pnl)
46284628
=for apidoc_item savesharedpvs
46294629
=for apidoc_item savesharedsvpv
46304630
4631-
Perl's version of C<strdup()> (or C<strndup()> would be if it existed).
4632-
46334631
These each return a pointer to a newly allocated string which is a duplicate of
4634-
the input string.
4632+
the one given by the input argument. Effectively, they implement the C library
4633+
L<C<strdup(3)>>.
46354634
4636-
The forms differ in how the string to be copied is specified, and where the new
4637-
memory is allocated from.
4635+
The forms differ in two main ways:
46384636
4639-
To prevent memory leaks, the memory allocated for the new string needs to be
4640-
freed when no longer needed. This can be done with the C<L</Safefree>>
4641-
function, or L<C<SAVEFREEPV>|perlguts/SAVEFREEPV(p)>.
4637+
=over
4638+
4639+
=item 1.
4640+
4641+
Whether or not the newly allocated memory is in an area that is sharable
4642+
between threads (the forms with C<shared> in their names) or if it is in an
4643+
area exclusive to the calling thread (the other forms).
4644+
4645+
=item 2.
46424646
4643-
The forms whose names contain C<shared> differ from the corresponding form
4644-
without that in its name, only in that the memory in the former comes from
4645-
memory shared between threads. This is needed, because on some platforms,
4646-
Windows for example, all allocated memory owned by a thread is deallocated when
4647-
that thread ends. So if you need that not to happen, you need to use the
4648-
shared memory forms.
4647+
How the string to be copied is specified.
46494648
4650-
The string to copy in C<savepvs> is a C language string literal surrounded by
4651-
double quotes.
4649+
In the C<savepv> and C<savesharedpv> forms, the source string is a C language
4650+
NUL-terminated string, or C<NULL>. If C<NULL>, no allocation is done, and
4651+
the functions return NULL.
46524652
4653-
The string to copy in the forms whose name contains C<svpv> comes from the PV
4654-
in the SV argument C<sv>, using C<SvPV()>
4653+
In the C<savepvn> and C<savesharedpvn> forms, C<pv> (if not NULL) points to the
4654+
first byte of the string to duplicate, and an additional parameter, C<len>,
4655+
specifies the number of bytes to copy. Hence, C<pv> may contain embedded-NUL
4656+
characters. It is illegal for C<pv> to be NULL when calling C<savesharedpvn>
4657+
(asserted against in DEBUGGING builds). If it is NULL in C<savepvn>, C<len>
4658+
bytes of zeroed memory are allocated.
46554659
4656-
The string to copy in the remaining forms comes from the C<pv> argument.
4660+
In the C<savepvs> and C<savesharedpvs> forms, the string must be a C literal
4661+
string, enclosed in double quotes.
46574662
4658-
In the case of C<savepv>, the size of the string is determined by C<strlen()>,
4659-
which means it may not contain embedded C<NUL> characters, and must have a
4660-
trailing C<NUL>.
4663+
In the C<savesvpv> and C<savesharedsvpv> forms, the string to duplicate is
4664+
extracted from C<sv> using L</C<SvPV_const>>. C<sv> must not be NULL.
4665+
4666+
=back
4667+
4668+
To prevent memory leaks, the memory allocated for the new string needs to be
4669+
freed when no longer needed. This can be done with the C<L</Safefree>>
4670+
function, or L<C<SAVEFREEPV>|perlguts/SAVEFREEPV(p)>.
46614671
4662-
In the case of C<savepvn>, C<len> gives the length of C<pv>, hence it may
4663-
contain embedded C<NUL> characters. The copy will be guaranteed to have a
4664-
trailing NUL added if not already present.
4672+
On some platforms, Windows for example, all allocated memory owned by a thread
4673+
is deallocated when that thread ends. So if you need that not to happen, you
4674+
need to use a C<shared> form.
46654675
46664676
=cut
46674677
*/

t/porting/known_pod_issues.dat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ splain
337337
sprintf(3)
338338
stat(2)
339339
strchr(3)
340+
strdup(3)
340341
strftime(3)
341342
strictures
342343
String::Base

0 commit comments

Comments
 (0)