X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=handy.h;h=72d71227bdac8e72ff3eb21f1d55bce651e3ad08;hb=e4c5322dee1b8e87ff0e7aee20effad846301447;hp=db9e0065de3aed5255cf72adb66a886df053f8f5;hpb=3341f5772454aa6fd2d3ee32728b288f60620abf;p=p5sagit%2Fp5-mst-13.2.git diff --git a/handy.h b/handy.h index db9e006..72d7122 100644 --- a/handy.h +++ b/handy.h @@ -175,7 +175,7 @@ typedef U64TYPE U64; #endif /* HMB H.Merijn Brand - a placeholder for preparing Configure patches */ -#if defined(HAS_MALLOC_SIZE) && defined(HAS_SNPRINTF) && defined(HAS_VSNPRINTF) +#if defined(HAS_MALLOC_SIZE) && defined(LOCALTIME_R_NEEDS_TZSET) && defined(HAS_DIR_DD_FD) && defined(HAS_PSEUDOFORK) /* Not (yet) used at top level, but mention them for metaconfig */ #endif @@ -236,6 +236,44 @@ typedef U64TYPE U64; #define Ctl(ch) ((ch) & 037) +/* +=head1 SV-Body Allocation + +=for apidoc Ama|SV*|newSVpvs|const char* s +Like C, but takes a literal string instead of a string/length pair. + +=for apidoc Ama|SV*|newSVpvs_share|const char* s +Like C, but takes a literal string instead of a string/length +pair and omits the hash parameter. + +=for apidoc Am|void|sv_catpvs|SV* sv|const char* s +Like C, but takes a literal string instead of a string/length pair. + +=for apidoc Am|void|sv_setpvs|SV* sv|const char* s +Like C, but takes a literal string instead of a string/length pair. + +=head1 Memory Management + +=for apidoc Ama|char*|savepvs|const char* s +Like C, but takes a literal string instead of a string/length pair. + +=head1 GV Functions + +=for apidoc Am|HV*|gv_stashpvs|const char* name|I32 create +Like C, but takes a literal string instead of a string/length pair. + +=head1 Hash Manipulation Functions + +=for apidoc Am|SV**|hv_fetchs|HV* tb|const char* key|I32 lval +Like C, but takes a literal string instead of a string/length pair. + +=for apidoc Am|SV**|hv_stores|HV* tb|const char* key|NULLOK SV* val +Like C, but takes a literal string instead of a string/length pair +and omits the hash parameter. + +=cut +*/ + /* concatenating with "" ensures that only literal strings are accepted as argument */ #define STR_WITH_LEN(s) (s ""), (sizeof(s)-1) @@ -248,10 +286,12 @@ typedef U64TYPE U64; #define newSVpvs(str) Perl_newSVpvn(aTHX_ STR_WITH_LEN(str)) #define newSVpvs_share(str) Perl_newSVpvn_share(aTHX_ STR_WITH_LEN(str), 0) #define sv_catpvs(sv, str) Perl_sv_catpvn_flags(aTHX_ sv, STR_WITH_LEN(str), SV_GMAGIC) +#define sv_setpvs(sv, str) Perl_sv_setpvn(aTHX_ sv, STR_WITH_LEN(str)) #define savepvs(str) Perl_savepvn(aTHX_ STR_WITH_LEN(str)) #define gv_stashpvs(str, create) Perl_gv_stashpvn(aTHX_ STR_WITH_LEN(str), create) #define gv_fetchpvs(namebeg, add, sv_type) Perl_gv_fetchpvn_flags(aTHX_ STR_WITH_LEN(namebeg), add, sv_type) #define hv_fetchs(hv,key,lval) Perl_hv_fetch(aTHX_ hv, STR_WITH_LEN(key), lval) +#define hv_stores(hv,key,val) Perl_hv_store(aTHX_ hv, STR_WITH_LEN(key), val, 0) /* @@ -310,6 +350,10 @@ C). # define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) #endif +#define memEQs(s1, l, s2) \ + (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1))) +#define memNEs(s1, l, s2) !memEQs(s1, l, s2) + /* * Character classes. * @@ -626,7 +670,7 @@ again) that hopefully catches attempts to access uninitialized memory. PoisonWith(0xAB) for catching access to allocated but uninitialized memory. -=for apidoc Am|void|Poison|void* dest|int nitems|type +=for apidoc Am|void|PoisonFree|void* dest|int nitems|type PoisonWith(0xEF) for catching access to freed memory. @@ -641,13 +685,18 @@ PoisonWith(0xEF) for catching access to freed memory. #define NEWSV(x,len) newSV(len) #endif +#define MEM_SIZE_MAX ((MEM_SIZE)~0) + +/* The +0.0 in MEM_WRAP_CHECK_ is an attempt to foil + * overly eager compilers that will bleat about e.g. + * (U16)n > (size_t)~0/sizeof(U16) always being false. */ #ifdef PERL_MALLOC_WRAP #define MEM_WRAP_CHECK(n,t) MEM_WRAP_CHECK_1(n,t,PL_memory_wrap) #define MEM_WRAP_CHECK_1(n,t,a) \ - (void)(sizeof(t) > 1 && (n) > ((MEM_SIZE)~0)/sizeof(t) && (Perl_croak_nocontext(a),0)) + (void)(sizeof(t) > 1 && ((MEM_SIZE)(n)+0.0) > MEM_SIZE_MAX/sizeof(t) && (Perl_croak_nocontext(a),0)) #define MEM_WRAP_CHECK_(n,t) MEM_WRAP_CHECK(n,t), -#define PERL_STRLEN_ROUNDUP(n) ((void)(((n) > (MEM_SIZE)~0 - 2 * PERL_STRLEN_ROUNDUP_QUANTUM) ? (Perl_croak_nocontext(PL_memory_wrap),0):0),((n-1+PERL_STRLEN_ROUNDUP_QUANTUM)&~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM-1))) +#define PERL_STRLEN_ROUNDUP(n) ((void)(((n) > MEM_SIZE_MAX - 2 * PERL_STRLEN_ROUNDUP_QUANTUM) ? (Perl_croak_nocontext(PL_memory_wrap),0):0),((n-1+PERL_STRLEN_ROUNDUP_QUANTUM)&~((MEM_SIZE)PERL_STRLEN_ROUNDUP_QUANTUM-1))) #else