diff --git a/inline.h b/inline.h index fa55325db3c5..bfa5842998a5 100644 --- a/inline.h +++ b/inline.h @@ -4628,40 +4628,64 @@ Perl_padnamelist_refcnt_inc(PADNAMELIST *pnl) =for apidoc_item savesharedpvs =for apidoc_item savesharedsvpv -Perl's version of C (or C would be if it existed). - These each return a pointer to a newly allocated string which is a duplicate of -the input string. +the one given by the input argument. Effectively, they implement the C library +L>. + +The forms differ in three main ways: + +=over + +=item 1. + +Whether or not the newly allocated memory is in an area that is sharable +between threads (the forms with C in their names) or if it is in an +area exclusive to the calling thread (the other forms). + +=item 2. + +How the string to be copied is specified. + +In the C and C forms, the source string is a C language +NUL-terminated string, or C. If C, no allocation is done, and +the functions return NULL. -The forms differ in how the string to be copied is specified, and where the new -memory is allocated from. +In the C and C forms, C (if not NULL) points to the +first byte of the string to duplicate, and an additional parameter, C, +specifies the number of bytes to copy. Hence, C may contain embedded-NUL +characters. It is illegal for C to be NULL when calling C +(asserted against in DEBUGGING builds). If it is NULL in C, C +bytes of zeroed memory are allocated. + +In the C and C forms, the string must be a C literal +string, enclosed in double quotes. + +In the C and C forms, the string to duplicate is +extracted from C using L>. C must not be NULL. + +=item 3. + +Memory deallocation To prevent memory leaks, the memory allocated for the new string needs to be -freed when no longer needed. This can be done with the C> -function, or L|perlguts/SAVEFREEPV(p)>. +freed when no longer needed. -The forms whose names contain C differ from the corresponding form -without that in its name, only in that the memory in the former comes from -memory shared between threads. This is needed, because on some platforms, -Windows for example, all allocated memory owned by a thread is deallocated when -that thread ends. So if you need that not to happen, you need to use the -shared memory forms. +=over -The string to copy in C is a C language string literal surrounded by -double quotes. +=item C forms -The string to copy in the forms whose name contains C comes from the PV -in the SV argument C, using C +Use the C> function, or L|perlguts/SAVEFREEPV(p)>. +However, BE AWARE, this can happen automatically on some platforms, such as +Windows, when the thread that allocated it ends. So if you need that not to +happen, you need to use a C form. -The string to copy in the remaining forms comes from the C argument. +=item C forms -In the case of C, the size of the string is determined by C, -which means it may not contain embedded C characters, and must have a -trailing C. +Use the C function. -In the case of C, C gives the length of C, hence it may -contain embedded C characters. The copy will be guaranteed to have a -trailing NUL added if not already present. +=back + +=back =cut */ diff --git a/t/porting/known_pod_issues.dat b/t/porting/known_pod_issues.dat index bb1db7311d70..8213094a3b05 100644 --- a/t/porting/known_pod_issues.dat +++ b/t/porting/known_pod_issues.dat @@ -337,6 +337,7 @@ splain sprintf(3) stat(2) strchr(3) +strdup(3) strftime(3) strictures String::Base