From: Florian Ragwitz Date: Sat, 26 Feb 2011 05:52:08 +0000 (+0100) Subject: Re-alloc PL_linestr in block hooks, if available X-Git-Tag: 0.006001~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FDevel-Declare.git;a=commitdiff_plain;h=6ed8c948bd71150fd1e1bb81a4d0959350924e16 Re-alloc PL_linestr in block hooks, if available This makes us work again on perl >= 5.13.7, where evaled strings are always being copied. Thanks Zefram. --- diff --git a/Declare.xs b/Declare.xs index b11d65d..934f8f6 100644 --- a/Declare.xs +++ b/Declare.xs @@ -26,6 +26,8 @@ static int dd_debug = 0; #define DD_CONST_VIA_RV2CV PERL_VERSION_GE(5,11,2) +#define DD_GROW_VIA_BLOCKHOOK PERL_VERSION_GE(5,13,3) + #define LEX_NORMAL 10 #define LEX_INTERPNORMAL 9 @@ -322,6 +324,17 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { return o; } +#if DD_GROW_VIA_BLOCKHOOK + +static void dd_block_start(pTHX_ int full) +{ + PERL_UNUSED_VAR(full); + if (SvLEN(PL_linestr) < 8192) + (void) lex_grow_linestr(8192); +} + +#else /* !DD_GROW_VIA_BLOCKHOOK */ + OP* dd_pp_entereval(pTHX) { dSP; STRLEN len; @@ -374,6 +387,8 @@ static I32 dd_filter_realloc(pTHX_ int idx, SV *sv, int maxlen) return count; } +#endif /* !DD_GROW_VIA_BLOCKHOOK */ + static int dd_handle_const(pTHX_ char *name) { switch (PL_lex_inwhat) { case OP_QR: @@ -469,13 +484,25 @@ void setup() CODE: if (!initialized++) { - hook_op_check(OP_RV2CV, dd_ck_rv2cv, NULL); +#if DD_GROW_VIA_BLOCKHOOK + static BHK bhk; +#if PERL_VERSION_GE(5,13,6) + BhkENTRY_set(&bhk, bhk_start, dd_block_start); +#else /* <5.13.6 */ + BhkENTRY_set(&bhk, start, dd_block_start); +#endif /* <5.13.6 */ + Perl_blockhook_register(aTHX_ &bhk); +#else /* !DD_GROW_VIA_BLOCKHOOK */ hook_op_check(OP_ENTEREVAL, dd_ck_entereval, NULL); +#endif /* !DD_GROW_VIA_BLOCKHOOK */ + hook_op_check(OP_RV2CV, dd_ck_rv2cv, NULL); #if !DD_CONST_VIA_RV2CV hook_op_check(OP_CONST, dd_ck_const, NULL); #endif /* !DD_CONST_VIA_RV2CV */ } +#if !DD_GROW_VIA_BLOCKHOOK filter_add(dd_filter_realloc, NULL); +#endif /* !DD_GROW_VIA_BLOCKHOOK */ char* get_linestr()