]> granicus.if.org Git - flex/commitdiff
Added yylex_destroy() to non-reentrant scanner.
authorJohn Millaway <john43@users.sourceforge.net>
Tue, 9 Jul 2002 20:52:14 +0000 (20:52 +0000)
committerJohn Millaway <john43@users.sourceforge.net>
Tue, 9 Jul 2002 20:52:14 +0000 (20:52 +0000)
Added ability to override memory functions.
Added tests for overriding memory functions.

configure.in
flex.skl
scan.l
tests/Makefile.am

index 1daa5266e87a67044e8dc296342b4e3515f7604f..ec09e7e91881685b518c56539726cc5fe21d6607 100644 (file)
@@ -75,6 +75,8 @@ tests/test-lineno-nr/Makefile
 tests/test-lineno-r/Makefile
 tests/test-debug-r/Makefile
 tests/test-debug-nr/Makefile
+tests/test-mem-nr/Makefile
+tests/test-mem-r/Makefile
 dnl --new-test-here-- This line is processed by tests/create-test.
 )
 AC_OUTPUT
index 99c059dda6608af670610e8bb0df75052c92c1b1..4a57c6464efe2ee1244f3dba16a2849da137ab16 100644 (file)
--- a/flex.skl
+++ b/flex.skl
@@ -154,7 +154,9 @@ int yylex_destroy YY_PROTO((yyscan_t scanner));
 #define YY_END_OF_BUFFER_CHAR 0
 
 /* Size of default input buffer. */
+#ifndef YY_BUF_SIZE
 #define YY_BUF_SIZE 16384
+#endif
 
 
 #ifndef YY_TYPEDEF_YY_BUFFER_STATE
@@ -337,9 +339,9 @@ YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len YY_LAST_AR
 %*
 
 %c
-static void *yy_flex_alloc YY_PROTO(( yy_size_t YY_LAST_ARG ));
-static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t YY_LAST_ARG ));
-static void yy_flex_free YY_PROTO(( void * YY_LAST_ARG ));
+void *yy_flex_alloc YY_PROTO(( yy_size_t YY_LAST_ARG ));
+void *yy_flex_realloc YY_PROTO(( void *, yy_size_t YY_LAST_ARG ));
+void yy_flex_free YY_PROTO(( void * YY_LAST_ARG ));
 %e
 
 #define yy_new_buffer yy_create_buffer
@@ -2043,33 +2045,36 @@ int yylex_init( ptr_yy_globals )
     return 0;
     }
 
+#endif /* End YY_REENTRANT */
+
+/* yylex_destroy is for both reentrant and non-reentrant scanners. */
 #ifdef YY_USE_PROTOS
-int yylex_destroy( yyscan_t yy_globals )
+int yylex_destroy( YY_ONLY_ARG )
 #else
-int yylex_destroy( yy_globals )
-    yyscan_t yy_globals;
+int yylex_destroy( YY_ONLY_ARG )
+    YY_DECL_LAST_ARG
 #endif
-    {
-    if( yy_globals )
-        {
-
-            /* Destroy the current (main) buffer. */
-            yy_delete_buffer( YY_G(yy_current_buffer) YY_CALL_LAST_ARG );
-            YY_G(yy_current_buffer) = NULL;
-
-            /* Destroy the start condition stack. */
-            if( YY_G(yy_start_stack) ) {
-                yy_flex_free( YY_G(yy_start_stack) YY_CALL_LAST_ARG );
-                YY_G(yy_start_stack) = NULL;
-            }
-
-            /* Destroy the main struct. */
-            yy_flex_free ( yy_globals YY_CALL_LAST_ARG );
-        }
-    return 0;
+{
+    /* Destroy the current (main) buffer. */
+    yy_delete_buffer( YY_G(yy_current_buffer) YY_CALL_LAST_ARG );
+    YY_G(yy_current_buffer) = NULL;
+
+
+#if defined(YY_STACK_USED) || defined(YY_REENTRANT)
+    /* Destroy the start condition stack. */
+    if (YY_G(yy_start_stack) ){
+        yy_flex_free( YY_G(yy_start_stack) YY_CALL_LAST_ARG );
+        YY_G(yy_start_stack) = NULL;
     }
+#endif
+
+#ifdef YY_REENTRANT
+    /* Destroy the main struct (reentrant only). */
+    yy_flex_free ( yy_globals YY_CALL_LAST_ARG );
+#endif
+    return 0;
+}
 
-#endif /* End YY_REENTRANT */
 
 /* Internal utility routines. */
 
@@ -2107,7 +2112,9 @@ YY_DECL_LAST_ARG
        }
 #endif
 
-
+/* You may override yy_flex_alloc by defining YY_NO_FLEX_ALLOC and linking to
+ * your own version */
+#ifndef YY_NO_FLEX_ALLOC
 #ifdef YY_USE_PROTOS
 static void *yy_flex_alloc( yy_size_t size YY_LAST_ARG )
 #else
@@ -2118,7 +2125,11 @@ YY_DECL_LAST_ARG
        {
        return (void *) malloc( size );
        }
+#endif
 
+/* You may override yy_flex_realloc by defining YY_NO_FLEX_REALLOC and linking
+ * to your own version. */
+#ifndef YY_NO_FLEX_REALLOC
 #ifdef YY_USE_PROTOS
 static void *yy_flex_realloc( void *ptr, yy_size_t size YY_LAST_ARG )
 #else
@@ -2137,7 +2148,11 @@ YY_DECL_LAST_ARG
         */
        return (void *) realloc( (char *) ptr, size );
        }
+#endif
 
+/* You may override yy_flex_free by defining YY_NO_FLEX_FREE and linking to
+ * your own version.*/
+#ifndef YY_NO_FLEX_FREE
 #ifdef YY_USE_PROTOS
 static void yy_flex_free( void *ptr YY_LAST_ARG )
 #else
@@ -2148,6 +2163,7 @@ YY_DECL_LAST_ARG
        {
        free( (char *) ptr );   /* see yy_flex_realloc() for (char *) cast */
        }
+#endif
 
 #if YY_MAIN
 int main()
diff --git a/scan.l b/scan.l
index 3c341a209353ad45ad32cb686fc1de30b4bb561f..f8c6c8a92f79b8893ea1ac9391522b53c33ebddc 100644 (file)
--- a/scan.l
+++ b/scan.l
@@ -286,6 +286,10 @@ LEXOPT             [aceknopr]
        yy_scan_bytes   ACTION_IFDEF("YY_NO_SCAN_BYTES", ! option_sense);
        yy_scan_string  ACTION_IFDEF("YY_NO_SCAN_STRING", ! option_sense);
 
+    yy_flex_alloc   ACTION_IFDEF("YY_NO_FLEX_ALLOC", ! option_sense);
+    yy_flex_realloc ACTION_IFDEF("YY_NO_FLEX_REALLOC", ! option_sense);
+    yy_flex_free    ACTION_IFDEF("YY_NO_FLEX_FREE", ! option_sense);
+
     yyget_debug     ACTION_IFDEF("YY_NO_GET_DEBUG", ! option_sense);
     yyset_debug     ACTION_IFDEF("YY_NO_SET_DEBUG", ! option_sense);
     yyget_extra     ACTION_IFDEF("YY_NO_GET_EXTRA", ! option_sense);
index 4a32c2440f892b422bc5b41a7b26921ce1ecadcb..a264b9f4b24ca07d51fa6594dc81879c11e23d3a 100644 (file)
@@ -26,6 +26,8 @@ noinst_SCRIPTS = \
        create-test
 
 SUBDIRS = \
+       test-mem-r \
+       test-mem-nr \
        test-debug-nr \
        test-debug-r \
        test-lineno-r \