Changes for Devel-Declare
- - eliminate PERL_5_9_PLUS macro in favour of ifdef PL_parser
+0.002002
+ - switch done_declare call from call_argv to call_pv.
+ - Make get_linestr{,_offset} return sensible values when called while the
+ parser isn't running.
+ - Remove several compile time warnings.
+ - Allow enabling of debug mode using $ENV{DD_DEBUG}.
+
+0.002001
- clean up checks for whether we're lexing and whether lex_stuff exists
to handle the PL_parser factor-out in 5.10
+ - check if reallocation of PL_linestr is necessary before doing it. this way
+ we can bail out properly instead of corrupting memory in some cases
+ - don't call strlen twice on the same sting
+ - try to be more portable
+ - stop using Nullsv
+ - don't use Perl_* functions directly.
+ - don't define PERL_CORE
+ - use NEWSV from handy.h instead of defining our own
+ - don't define PERL_NO_GET_CONTEXT
+ - don't support preprocessors (perl -P)
0.002000
- rewrite guts into perl, add tests for new declaration style
-#define PERL_CORE
-#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
# define Newx(v,n,t) New(0,v,n,t)
#endif /* !Newx */
-#if 0
-#define DD_DEBUG
-#endif
-
-#ifdef DD_DEBUG
-#define DD_DEBUG_S printf("Buffer: %s\n", s);
-#else
-#define DD_DEBUG_S
-#endif
+static int dd_debug = 0;
#define LEX_NORMAL 10
#define LEX_INTERPNORMAL 9
#define DD_AM_LEXING_CHECK (PL_lex_state == LEX_NORMAL || PL_lex_state == LEX_INTERPNORMAL)
-#ifdef PL_parser
+#if defined(PL_parser) || defined(PERL_5_9_PLUS)
#define DD_HAVE_PARSER PL_parser
#define DD_HAVE_LEX_STUFF (PL_parser && PL_lex_stuff)
#define DD_AM_LEXING (PL_parser && DD_AM_LEXING_CHECK)
/* $declarators{$current_package_name} */
+ if (!HvNAME(PL_curstash))
+ return -1;
+
is_declarator_pack_ref = hv_fetch(is_declarator, HvNAME(PL_curstash),
strlen(HvNAME(PL_curstash)), FALSE);
}
char* dd_get_linestr(pTHX) {
+ if (!DD_HAVE_PARSER) {
+ return NULL;
+ }
return SvPVX(PL_linestr);
}
void dd_set_linestr(pTHX_ char* new_value) {
int new_len = strlen(new_value);
- char* old_linestr = SvPVX(PL_linestr);
- SvGROW(PL_linestr, strlen(new_value));
+ if (SvLEN(PL_linestr) < new_len) {
+ croak("forced to realloc PL_linestr for line %s, bailing out before we crash harder", SvPVX(PL_linestr));
+ }
- if (SvPVX(PL_linestr) != old_linestr)
- Perl_croak(aTHX_ "forced to realloc PL_linestr for line %s, bailing out before we crash harder", SvPVX(PL_linestr));
+ SvGROW(PL_linestr, new_len);
memcpy(SvPVX(PL_linestr), new_value, new_len+1);
return (DD_HAVE_LEX_STUFF ? SvPVX(PL_lex_stuff) : "");
}
-char* dd_clear_lex_stuff(pTHX) {
+void dd_clear_lex_stuff(pTHX) {
if (DD_HAVE_PARSER)
- PL_lex_stuff = Nullsv;
+ PL_lex_stuff = (SV*)NULL;
}
char* dd_get_curstash_name(pTHX) {
}
int dd_get_linestr_offset(pTHX) {
- char* linestr = SvPVX(PL_linestr);
+ char* linestr;
+ if (!DD_HAVE_PARSER) {
+ return -1;
+ }
+ linestr = SvPVX(PL_linestr);
return PL_bufptr - linestr;
}
STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) {
OP* kid;
int dd_flags;
- char* cb_args[6];
if (in_declare) {
- cb_args[0] = NULL;
-#ifdef DD_DEBUG
- printf("Deconstructing declare\n");
- printf("PL_bufptr: %s\n", PL_bufptr);
- printf("bufend at: %i\n", PL_bufend - PL_bufptr);
- printf("linestr: %s\n", SvPVX(PL_linestr));
- printf("linestr len: %i\n", PL_bufend - SvPVX(PL_linestr));
-#endif
- call_argv("Devel::Declare::done_declare", G_VOID|G_DISCARD, cb_args);
-#ifdef DD_DEBUG
- printf("PL_bufptr: %s\n", PL_bufptr);
- printf("bufend at: %i\n", PL_bufend - PL_bufptr);
- printf("linestr: %s\n", SvPVX(PL_linestr));
- printf("linestr len: %i\n", PL_bufend - SvPVX(PL_linestr));
- printf("actual len: %i\n", strlen(PL_bufptr));
-#endif
+ if (dd_debug) {
+ printf("Deconstructing declare\n");
+ printf("PL_bufptr: %s\n", PL_bufptr);
+ printf("bufend at: %i\n", PL_bufend - PL_bufptr);
+ printf("linestr: %s\n", SvPVX(PL_linestr));
+ printf("linestr len: %i\n", PL_bufend - SvPVX(PL_linestr));
+ }
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+
+ call_pv("Devel::Declare::done_declare", G_VOID|G_DISCARD);
+
+ FREETMPS;
+ LEAVE;
+
+ if (dd_debug) {
+ printf("PL_bufptr: %s\n", PL_bufptr);
+ printf("bufend at: %i\n", PL_bufend - PL_bufptr);
+ printf("linestr: %s\n", SvPVX(PL_linestr));
+ printf("linestr len: %i\n", PL_bufend - SvPVX(PL_linestr));
+ printf("actual len: %i\n", strlen(PL_bufptr));
+ }
return o;
}
if (!DD_AM_LEXING)
return o; /* not lexing? */
-#ifdef DD_DEBUG
- printf("Checking GV %s -> %s\n", HvNAME(GvSTASH(kGVOP_gv)), GvNAME(kGVOP_gv));
-#endif
+ if (dd_debug) {
+ printf("Checking GV %s -> %s\n", HvNAME(GvSTASH(kGVOP_gv)), GvNAME(kGVOP_gv));
+ }
dd_flags = dd_is_declarator(aTHX_ GvNAME(kGVOP_gv));
if (dd_flags == -1)
return o;
-#ifdef DD_DEBUG
- printf("dd_flags are: %i\n", dd_flags);
-#endif
-
-#ifdef DD_DEBUG
- printf("PL_tokenbuf: %s\n", PL_tokenbuf);
-#endif
+ if (dd_debug) {
+ printf("dd_flags are: %i\n", dd_flags);
+ printf("PL_tokenbuf: %s\n", PL_tokenbuf);
+ }
dd_linestr_callback(aTHX_ "rv2cv", GvNAME(kGVOP_gv));
STRLEN len;
const char* s;
if (SvPOK(sv)) {
-#ifdef DD_DEBUG
- printf("mangling eval sv\n");
-#endif
+ if (dd_debug) {
+ printf("mangling eval sv\n");
+ }
if (SvREADONLY(sv))
sv = sv_2mortal(newSVsv(sv));
s = SvPVX(sv);
STATIC OP *dd_ck_const(pTHX_ OP *o, void *user_data) {
int dd_flags;
- char* s;
char* name;
/* if this is set, we just grabbed a delimited string or something,
set_in_declare(int value)
CODE:
in_declare = value;
+
+BOOT:
+ if (getenv ("DD_DEBUG")) {
+ dd_debug = 1;
+ }
#define PERL_5_8_8_PLUS
#endif
-#ifdef PL_parser
+#if PERL_REVISION == 5 && PERL_VERSION > 8
+#define PERL_5_9_PLUS
+#endif
+
+#ifdef PERL_5_9_PLUS
/* 5.9+ moves a bunch of things to a PL_parser struct so we need to
declare the backcompat macros for things to still work (mst) */
# define PL_nextval (PL_parser->nextval)
/* end of backcompat macros form 5.9 toke.c (mst) */
#endif
-/* we also need this because we define PERL_CORE so handy.h doesn't provide
- it for us (mst) */
-#ifndef NEWSV
-#define NEWSV(x,len) newSV(len)
-#endif
/* when ccflags include -DDEBUGGING we need this for earlier 5.8 perls */
#ifndef SvPV_nolen_const
PL_bufend = SvPVX(PL_linestr) + SvCUR(PL_linestr);
PL_last_lop = PL_last_uni = Nullch;
- /* Close the filehandle. Could be from -P preprocessor,
+ /* In perl versions previous to p4-rawid: //depot/perl@32954 -P
+ * preprocessors were supported here. We don't support -P at all, even
+ * on perls that support it, and use the following chunk from blead
+ * perl. (rafl)
+ */
+
+ /* Close the filehandle. Could be from
* STDIN, or a regular file. If we were reading code from
* STDIN (because the commandline held no -e or filename)
* then we don't close it, we reset it so the code can
* read from STDIN too.
*/
- if (PL_preprocess && !PL_in_eval)
- (void)PerlProc_pclose(PL_rsfp);
- else if ((PerlIO*)PL_rsfp == PerlIO_stdin())
+ if ((PerlIO*)PL_rsfp == PerlIO_stdin())
PerlIO_clearerr(PL_rsfp);
else
(void)PerlIO_close(PL_rsfp);