Next: Tables File Format, Previous: Creating Serialized Tables, Up: Serialized Tables [Contents][Index]
If you’ve built your scanner with %option tables-file
, then you must
load the scanner tables at runtime. This can be accomplished with the following
function:
Locates scanner tables in the stream pointed to by fp and loads them.
Memory for the tables is allocated via yyalloc
. You must call this
function before the first call to yylex
. The argument scanner
only appears in the reentrant scanner.
This function returns ‘0’ (zero) on success, or non-zero on error.
The loaded tables are not automatically destroyed (unloaded) when you
call yylex_destroy
. The reason is that you may create several scanners
of the same type (in a reentrant scanner), each of which needs access to these
tables. To avoid a nasty memory leak, you must call the following function:
Unloads the scanner tables. The tables must be loaded again before you can scan any more data. The argument scanner only appears in the reentrant scanner. This function returns ‘0’ (zero) on success, or non-zero on error.
The functions yytables_fload
and yytables_destroy
are not
thread-safe. You must ensure that these functions are called exactly once (for
each scanner type) in a threaded program, before any thread calls yylex
.
After the tables are loaded, they are never written to, and no thread
protection is required thereafter – until you destroy them.