Author: chromatic
Date: Sat Nov 29 14:37:38 2008
New Revision: 33353
Modified:
trunk/compilers/imcc/imcc.l
trunk/compilers/imcc/imclexer.c
Log:
[IMCC] Removed a misguided assert in read_macro(); when looping through yylex()
to read to the end of a macro, some tokens don't set yytext. Thus they only
add to the text of macros if they produce strings. This resolves RT #47978 and
RT #51104 (though the error message isn't great).
Modified: trunk/compilers/imcc/imcc.l
==============================================================================
--- trunk/compilers/imcc/imcc.l (original)
+++ trunk/compilers/imcc/imcc.l Sat Nov 29 14:37:38 2008
@@ -1006,31 +1006,33 @@
IMCC_INFO(interp)->cur_macro_name);
}
- PARROT_ASSERT(valp->s);
- elem_len = strlen(valp->s);
+ if (valp->s) {
+ elem_len = strlen(valp->s);
- if (buffer_used) {
- if (buffer_used + elem_len > buffer_size) {
- buffer_size += elem_len;
- buffer_size <<= 1;
+ if (buffer_used) {
+ if (buffer_used + elem_len > buffer_size) {
+ buffer_size += elem_len;
+ buffer_size <<= 1;
+
+ IMCC_INFO(interp)->macro_buffer =
+ (char
*)mem_sys_realloc(IMCC_INFO(interp)->macro_buffer,
+ buffer_size);
+ }
+ }
+ else {
+ buffer_size = (elem_len << 1) > 1024 ? elem_len << 1 : 1024;
IMCC_INFO(interp)->macro_buffer =
- (char *)mem_sys_realloc(IMCC_INFO(interp)->macro_buffer,
- buffer_size);
+ (char *)mem_sys_allocate_zeroed(buffer_size);
}
- }
- else {
- buffer_size = (elem_len << 1) > 1024 ? elem_len << 1 : 1024;
- IMCC_INFO(interp)->macro_buffer =
- (char *)mem_sys_allocate_zeroed(buffer_size);
- }
-
- strcat(IMCC_INFO(interp)->macro_buffer, valp->s);
- buffer_used += elem_len;
+ strcat(IMCC_INFO(interp)->macro_buffer, valp->s);
+ buffer_used += elem_len;
+ mem_sys_free(valp->s);
+ valp->s = NULL;
+ }
c = yylex(valp, yyscanner, interp);
- mem_sys_free(old_s);
}
mem_sys_free(valp->s);
Modified: trunk/compilers/imcc/imclexer.c
==============================================================================
--- trunk/compilers/imcc/imclexer.c (original)
+++ trunk/compilers/imcc/imclexer.c Sat Nov 29 14:37:38 2008
@@ -30,7 +30,7 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
-#define YY_FLEX_SUBMINOR_VERSION 35
+#define YY_FLEX_SUBMINOR_VERSION 34
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
@@ -75,6 +75,7 @@
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
+#endif /* ! C99 */
/* Limits of integral types. */
#ifndef INT8_MIN
@@ -105,8 +106,6 @@
#define UINT32_MAX (4294967295U)
#endif
-#endif /* ! C99 */
-
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
@@ -214,6 +213,13 @@
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
+/* The following is because we cannot portably get our hands on size_t
+ * (without autoconf's help, which isn't available because we want
+ * flex-generated scanners to compile on their own).
+ * Given that the standard has decreed that size_t exists since 1989,
+ * I guess we can afford to depend on it. Manoj.
+ */
+
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
@@ -2607,7 +2613,7 @@
-#line 2611 "compilers/imcc/imclexer.c"
+#line 2617 "compilers/imcc/imclexer.c"
#define INITIAL 0
#define emit 1
@@ -2750,7 +2756,7 @@
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
-#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
+#define ECHO fwrite( yytext, yyleng, 1, yyout )
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
@@ -2761,7 +2767,7 @@
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
- size_t n; \
+ int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@@ -2866,7 +2872,7 @@
return 0;
}
-#line 2870 "compilers/imcc/imclexer.c"
+#line 2876 "compilers/imcc/imclexer.c"
if ( !yyg->yy_init )
{
@@ -4066,7 +4072,7 @@
#line 731 "compilers/imcc/imcc.l"
ECHO;
YY_BREAK
-#line 4070 "compilers/imcc/imclexer.c"
+#line 4076 "compilers/imcc/imclexer.c"
case YY_STATE_EOF(pod):
case YY_STATE_EOF(cmt1):
case YY_STATE_EOF(cmt2):
@@ -5548,31 +5554,33 @@
IMCC_INFO(interp)->cur_macro_name);
}
- PARROT_ASSERT(valp->s);
- elem_len = strlen(valp->s);
+ if (valp->s) {
+ elem_len = strlen(valp->s);
- if (buffer_used) {
- if (buffer_used + elem_len > buffer_size) {
- buffer_size += elem_len;
- buffer_size <<= 1;
+ if (buffer_used) {
+ if (buffer_used + elem_len > buffer_size) {
+ buffer_size += elem_len;
+ buffer_size <<= 1;
+
+ IMCC_INFO(interp)->macro_buffer =
+ (char
*)mem_sys_realloc(IMCC_INFO(interp)->macro_buffer,
+ buffer_size);
+ }
+ }
+ else {
+ buffer_size = (elem_len << 1) > 1024 ? elem_len << 1 : 1024;
IMCC_INFO(interp)->macro_buffer =
- (char *)mem_sys_realloc(IMCC_INFO(interp)->macro_buffer,
- buffer_size);
+ (char *)mem_sys_allocate_zeroed(buffer_size);
}
- }
- else {
- buffer_size = (elem_len << 1) > 1024 ? elem_len << 1 : 1024;
- IMCC_INFO(interp)->macro_buffer =
- (char *)mem_sys_allocate_zeroed(buffer_size);
- }
-
- strcat(IMCC_INFO(interp)->macro_buffer, valp->s);
- buffer_used += elem_len;
+ strcat(IMCC_INFO(interp)->macro_buffer, valp->s);
+ buffer_used += elem_len;
+ mem_sys_free(valp->s);
+ valp->s = NULL;
+ }
c = yylex(valp,yyscanner,interp);
- mem_sys_free(old_s);
}
mem_sys_free(valp->s);