diff options
author | Yves Orton <demerphq@gmail.com> | 2022-11-22 15:41:14 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-11-23 11:28:17 +0100 |
commit | a511d7dcd744640a1ebc498a80f1d05411368c83 (patch) | |
tree | b4f1b91e2b01437e9e3b774df713911ef8c076b9 /cop.h | |
parent | 4d6de2e9446beedb11b442184296d8c374d12741 (diff) | |
download | perl-a511d7dcd744640a1ebc498a80f1d05411368c83.tar.gz |
op.c - add support for empty RCPV strings.
Currently we have no need for an empty shared string, but there is no
reason it should not be possible. This patch reworks the internals so it
is possible to create one without triggering asserts. Currently we don't
use this, but it seems reasonable that someone might want it in the
future. Under DEBUGGING we will still assert if someone tries to create
an empty RCPV unless the flag specifies it should be allowed.
At the same time the docs for rcpv_new() have been cleaned up a bit to
be more correct and reflect what actually happens inside.
This changes things so that the len member of the RCPV structure is
always non-zero in a well formed structure by accounting for the null
we add to the end explicitly. The RCPV_LEN() macro continues to return
the old value (not including the null).
Diffstat (limited to 'cop.h')
-rw-r--r-- | cop.h | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -534,7 +534,10 @@ string pv created with C<rcpv_new()>. Returns the refcount for a pv created with C<rcpv_new()>. =for apidoc Am|RCPV *|RCPV_LEN|char *pv -Returns the length of a pv created with C<rcpv_new()>. +Returns the length of a pv created with C<rcpv_new()>. +Note that this reflects the length of the string from the callers +point of view, it does not include the mandatory null which is +always injected at the end of the string by rcpv_new(). =cut */ @@ -542,16 +545,19 @@ Returns the length of a pv created with C<rcpv_new()>. struct rcpv { STRLEN refcount; /* UV would mean a 64 refcnt on 32 bit builds with -Duse64bitint */ - STRLEN len; + STRLEN len; /* length of string including mandatory + null byte at end */ char pv[1]; }; typedef struct rcpv RCPV; -#define RCPVf_USE_STRLEN 1 -#define RCPVf_NO_COPY 2 +#define RCPVf_USE_STRLEN (1 << 0) +#define RCPVf_NO_COPY (1 << 1) +#define RCPVf_ALLOW_EMPTY (1 << 2) + #define RCPVx(pv_arg) ((RCPV *)((pv_arg) - STRUCT_OFFSET(struct rcpv, pv))) #define RCPV_REFCOUNT(pv) (RCPVx(pv)->refcount) -#define RCPV_LEN(pv) (RCPVx(pv)->len) +#define RCPV_LEN(pv) (RCPVx(pv)->len-1) /* len always includes space for a null */ #ifdef USE_ITHREADS |