diff options
author | Nicholas Clark <nick@ccl4.org> | 2007-12-20 19:49:50 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2007-12-20 19:49:50 +0000 |
commit | ac572bf4fde55cf563ae338dfe4e12b22ebc6d80 (patch) | |
tree | fa0c5697d540c2039ef5fdaeea4f6506ca28199b | |
parent | 82c0efa4e83781652347e2d8715e3fc7441c39d4 (diff) | |
download | perl-ac572bf4fde55cf563ae338dfe4e12b22ebc6d80.tar.gz |
Perl_newAV() can become a mathom by making newAV() a wrapper around
newSV_type() and tweaking Perl_sv_upgrade().
p4raw-id: //depot/perl@32675
-rw-r--r-- | av.c | 19 | ||||
-rw-r--r-- | av.h | 10 | ||||
-rw-r--r-- | embed.fnc | 2 | ||||
-rw-r--r-- | embed.h | 2 | ||||
-rw-r--r-- | mathoms.c | 12 | ||||
-rw-r--r-- | proto.h | 4 | ||||
-rw-r--r-- | sv.c | 7 |
7 files changed, 31 insertions, 25 deletions
@@ -355,25 +355,6 @@ Perl_av_store(pTHX_ register AV *av, I32 key, SV *val) } /* -=for apidoc newAV - -Creates a new AV. The reference count is set to 1. - -=cut -*/ - -AV * -Perl_newAV(pTHX) -{ - register AV * const av = (AV*)newSV_type(SVt_PVAV); - /* sv_upgrade does AvREAL_only() */ - AvALLOC(av) = 0; - AvARRAY(av) = NULL; - AvMAX(av) = AvFILLp(av) = -1; - return av; -} - -/* =for apidoc av_make Creates a new AV and populates it with a list of SVs. The SVs are copied @@ -116,6 +116,16 @@ Same as C<av_len()>. Deprecated, use C<av_len()> instead. #define NEGATIVE_INDICES_VAR "NEGATIVE_INDICES" /* +=for apidoc newAV + +Creates a new AV. The reference count is set to 1. + +=cut +*/ + +#define newAV() ((AV *)newSV_type(SVt_PVAV)) + +/* * Local variables: * c-indentation-style: bsd * c-basic-offset: 4 @@ -565,7 +565,7 @@ ApM |CV * |newXS_flags |NULLOK const char *name|NN XSUBADDR_t subaddr\ |NN const char *const filename \ |NULLOK const char *const proto|U32 flags Apd |CV* |newXS |NULLOK const char* name|NN XSUBADDR_t f|NN const char* filename -Apda |AV* |newAV +Amdba |AV* |newAV Apa |OP* |newAVREF |NN OP* o Apa |OP* |newBINOP |I32 type|I32 flags|NULLOK OP* first|NULLOK OP* last Apa |OP* |newCVREF |I32 flags|NULLOK OP* o @@ -552,7 +552,6 @@ #define newSUB Perl_newSUB #define newXS_flags Perl_newXS_flags #define newXS Perl_newXS -#define newAV Perl_newAV #define newAVREF Perl_newAVREF #define newBINOP Perl_newBINOP #define newCVREF Perl_newCVREF @@ -2846,7 +2845,6 @@ #define newSUB(a,b,c,d) Perl_newSUB(aTHX_ a,b,c,d) #define newXS_flags(a,b,c,d,e) Perl_newXS_flags(aTHX_ a,b,c,d,e) #define newXS(a,b,c) Perl_newXS(aTHX_ a,b,c) -#define newAV() Perl_newAV(aTHX) #define newAVREF(a) Perl_newAVREF(aTHX_ a) #define newBINOP(a,b,c,d) Perl_newBINOP(aTHX_ a,b,c,d) #define newCVREF(a,b) Perl_newCVREF(aTHX_ a,b) @@ -66,7 +66,7 @@ PERL_CALLCONV void Perl_sv_usepvn(pTHX_ SV *sv, char *ptr, STRLEN len); PERL_CALLCONV int Perl_fprintf_nocontext(PerlIO *stream, const char *format, ...); PERL_CALLCONV int Perl_printf_nocontext(const char *format, ...); PERL_CALLCONV int Perl_magic_setglob(pTHX_ SV* sv, MAGIC* mg); - +PERL_CALLCONV AV * Perl_newAV(pTHX); /* ref() is now a macro using Perl_doref; * this version provided for binary compatibility only. @@ -1328,6 +1328,16 @@ Perl_magic_setglob(pTHX_ SV *sv, MAGIC *mg) return 0; } +AV * +Perl_newAV(pTHX) +{ + return (AV*)newSV_type(SVt_PVAV); + /* sv_upgrade does AvREAL_only(): + AvALLOC(av) = 0; + AvARRAY(av) = NULL; + AvMAX(av) = AvFILLp(av) = -1; */ +} + #endif /* NO_MATHOMS */ /* @@ -1508,9 +1508,9 @@ PERL_CALLCONV CV* Perl_newXS(pTHX_ const char* name, XSUBADDR_t f, const char* f __attribute__nonnull__(pTHX_2) __attribute__nonnull__(pTHX_3); -PERL_CALLCONV AV* Perl_newAV(pTHX) +/* PERL_CALLCONV AV* Perl_newAV(pTHX) __attribute__malloc__ - __attribute__warn_unused_result__; + __attribute__warn_unused_result__; */ PERL_CALLCONV OP* Perl_newAVREF(pTHX_ OP* o) __attribute__malloc__ @@ -1253,6 +1253,13 @@ Perl_sv_upgrade(pTHX_ register SV *sv, svtype new_type) AvMAX(sv) = -1; AvFILLp(sv) = -1; AvREAL_only(sv); + if (old_type >= SVt_RV) { + AvALLOC(sv) = 0; + } else { + /* It will have been zeroed when the new body was allocated. + Lets not write to it, in case it confuses a write-back + cache. */ + } } /* SVt_NULL isn't the only thing upgraded to AV or HV. |