summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNick Ing-Simmons <nik@tiuk.ti.com>2002-01-18 22:11:42 +0000
committerNick Ing-Simmons <nik@tiuk.ti.com>2002-01-18 22:11:42 +0000
commit92110913508b9944d111285d9488f2f7b604919c (patch)
tree5328e9981561128fdf2360147fbe0315dca970e1 /util.c
parenta398d936ece03108233d87a6ab0b552b6272270a (diff)
downloadperl-92110913508b9944d111285d9488f2f7b604919c.tar.gz
Split out core of sv_magic() into sv_magicext().
sv_magic provides the extra restictions (no READONLY, only one of each type, canned set of vtables), and sv_magicext() does the actual data twiddling. Also enhances semantics of ->mg_ptr setting via name/namlen to allow either an uncopied ptr (namlen == 0), or a Newz()ed scratch area (namlen > 0 && name == NULL). sv_magicext also returns the MAGIC * it added. sv_magicext is intended mainly for PERL_MAGIC_ext (~) magic. To come sv_unmagicext() - which will remove just one magic of particular type, and additionaly match against ->mg_ptr, or the MAGIC * (need to experiment as to which is more natural). p4raw-id: //depot/perlio@14335
Diffstat (limited to 'util.c')
-rw-r--r--util.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/util.c b/util.c
index 72c85cdc76..a816cb99ba 100644
--- a/util.c
+++ b/util.c
@@ -905,7 +905,8 @@ Perl_savepv(pTHX_ const char *sv)
=for apidoc savepvn
Copy a string to a safe spot. The C<len> indicates number of bytes to
-copy. This does not use an SV.
+copy. If pointer is NULL allocate space for a string of size specified.
+This does not use an SV.
=cut
*/
@@ -916,8 +917,14 @@ Perl_savepvn(pTHX_ const char *sv, register I32 len)
register char *newaddr;
New(903,newaddr,len+1,char);
- Copy(sv,newaddr,len,char); /* might not be null terminated */
- newaddr[len] = '\0'; /* is now */
+ /* Give a meaning to NULL pointer mainly for the use in sv_magic() */
+ if (sv) {
+ Copy(sv,newaddr,len,char); /* might not be null terminated */
+ newaddr[len] = '\0'; /* is now */
+ }
+ else {
+ Zero(newaddr,len+1,char);
+ }
return newaddr;
}