manpagez: man pages & more
info flex
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

22.2 Loading and Unloading Serialized Tables

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:

Function: int yytables_fload (FILE* fp [, yyscan_t scanner])

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:

Function: int yytables_destroy ([yyscan_t scanner])

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.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on August 12, 2012 using texi2html 5.0.

© manpagez.com 2000-2017
Individual documents may contain additional copyright information.