[Kst] Re: branches/work/kst/portto4/kst/src/libkstmath
Peter Kümmel
syntheticpp at gmx.net
Sun Jan 16 16:16:38 CET 2011
On 16.01.2011 00:07, Barth Netterfield wrote:
> SVN commit 1214694 by netterfield:
>
> -Update escan.cpp using flex 3.5. This contains optimizations for ia64.
> I think I ported all of Peters windows fixes, but I haven't tested that.
Compiles without problems on Windows.
>
> -Fix a memory leak in equation parsing.
>
>
>
> M +5 -0 equation.cpp
> M +129 -65 escan.cpp
>
>
> --- branches/work/kst/portto4/kst/src/libkstmath/equation.cpp #1214693:1214694
> @@ -39,6 +39,7 @@
> /*extern "C"*/ int yyparse(Kst::ObjectStore *store);
> extern void *ParsedEquation;
> /*extern "C"*/ struct yy_buffer_state *yy_scan_string(const char*);
> +int yylex_destroy (void );
>
> namespace Kst {
>
> @@ -146,6 +147,7 @@
> return (_equation);
> }
>
> + yylex_destroy();
> yy_scan_string(_equation.toLatin1());
> ParsedEquation = 0L;
> int rc = yyparse(store());
> @@ -170,6 +172,7 @@
> // the optimizer
> if (!_equation.isEmpty()) {
> QMutexLocker ml(&Equations::mutex());
> + yylex_destroy();
> yy_scan_string(_equation.toLatin1());
> ParsedEquation = 0L;
> int rc = yyparse(store());
> @@ -209,6 +212,7 @@
> _pe = 0L;
> if (!_equation.isEmpty()) {
> Equations::mutex().lock();
> + yylex_destroy();
> yy_scan_string(_equation.toLatin1());
> int rc = yyparse(store());
> _pe = static_cast<Equations::Node*>(ParsedEquation);
> @@ -447,6 +451,7 @@
> }
>
> QMutexLocker ml(&Equations::mutex());
> + yylex_destroy();
> yy_scan_string(_equation.toLatin1());
> int rc = yyparse(store());
> _pe = static_cast<Equations::Node*>(ParsedEquation);
> --- branches/work/kst/portto4/kst/src/libkstmath/escan.cpp #1214693:1214694
> @@ -1,11 +1,8 @@
> #include "kstmath_export.h"
> -
> #ifdef Q_CC_MSVC
> #define strdup _strdup
> #endif
> -
> -#line 3 "lex.yy.c"
> -
> +#line 4 "escan.cpp"
> #define YY_INT_ALIGNED short int
>
> /* A lexical scanner generated by flex */
> @@ -13,7 +10,7 @@
> #define FLEX_SCANNER
> #define YY_FLEX_MAJOR_VERSION 2
> #define YY_FLEX_MINOR_VERSION 5
> -#define YY_FLEX_SUBMINOR_VERSION 33
> +#define YY_FLEX_SUBMINOR_VERSION 35
> #if YY_FLEX_SUBMINOR_VERSION> 0
> #define FLEX_BETA
> #endif
> @@ -35,7 +32,7 @@
>
> /* C99 systems have<inttypes.h>. Non-C99 systems may or may not. */
>
> -#if __STDC_VERSION__>= 199901L
> +#if defined (__STDC_VERSION__)&& __STDC_VERSION__>= 199901L
>
> /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
> * if you want the limit (max/min) macros for int types.
> @@ -58,7 +55,6 @@
> 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
> @@ -89,6 +85,8 @@
> #define UINT32_MAX (4294967295U)
> #endif
>
> +#endif /* ! C99 */
> +
> #endif /* ! FLEXINT_H */
>
> #ifdef __cplusplus
> @@ -98,11 +96,12 @@
>
> #else /* ! __cplusplus */
>
> -#if __STDC__
> +/* C99 requires __STDC__ to be defined as 1. */
> +#if defined (__STDC__)
>
> #define YY_USE_CONST
>
> -#endif /* __STDC__ */
> +#endif /* defined (__STDC__) */
> #endif /* ! __cplusplus */
>
> #ifdef YY_USE_CONST
> @@ -144,7 +143,15 @@
>
> /* Size of default input buffer. */
> #ifndef YY_BUF_SIZE
> +#ifdef __ia64__
> +/* On IA-64, the buffer size is 16k, not 8k.
> + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
> + * Ditto for the __ia64__ case accordingly.
> + */
> +#define YY_BUF_SIZE 32768
> +#else
> #define YY_BUF_SIZE 16384
> +#endif /* __ia64__ */
> #endif
>
> /* The state buf must be large enough to hold one state per character in the main buffer.
> @@ -180,16 +187,11 @@
> } \
> while ( 0 )
>
> -#define unput(c) yyunput( c, (yytext_ptr) )
> +//#define unput(c) yyunput( c, (yytext_ptr) )
>
> -/* 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).
> - */
> -
> #ifndef YY_TYPEDEF_YY_SIZE_T
> #define YY_TYPEDEF_YY_SIZE_T
> -typedef unsigned int yy_size_t;
> +typedef size_t yy_size_t;
> #endif
>
> #ifndef YY_STRUCT_YY_BUFFER_STATE
> @@ -340,7 +342,7 @@
>
> /* Begin user sect3 */
>
> -#define yywrap() 1
> +#define yywrap(n) 1
> #define YY_SKIP_YYWRAP
>
> typedef unsigned char YY_CHAR;
> @@ -350,6 +352,9 @@
> typedef int yy_state_type;
>
> extern int yylineno;
> +
> +int yylineno = 1;
> +
> extern char *yytext;
> #define yytext_ptr yytext
>
> @@ -483,9 +488,9 @@
> #define YY_MORE_ADJ 0
> #define YY_RESTORE_YY_MORE_OFFSET
> char *yytext;
> -#line 1 "../../../src/libkstmath/escan.l"
> +#line 1 "escan.l"
>
> -#line 4 "../../../src/libkstmath/escan.l"
> +#line 4 "escan.l"
> #include<stdlib.h>
> #include<stdio.h>
> #include<string.h>
> @@ -498,7 +503,7 @@
> //void yyerror(Kst::ObjectStore *store, const char *s);
> #define YY_DECL int yylex(Kst::ObjectStore *store)
>
> -#line 497 "lex.yy.c"
> +#line 506 "escan.cpp"
>
> #define INITIAL 0
> #define DATA 1
> @@ -519,6 +524,35 @@
>
> static int yy_init_globals (void );
>
> +/* Accessor methods to globals.
> + These are made visible to non-reentrant scanners for convenience. */
> +
> +int yylex_destroy (void );
> +
> +int yyget_debug (void );
> +
> +void yyset_debug (int debug_flag );
> +
> +YY_EXTRA_TYPE yyget_extra (void );
> +
> +void yyset_extra (YY_EXTRA_TYPE user_defined );
> +
> +FILE *yyget_in (void );
> +
> +void yyset_in (FILE * in_str );
> +
> +FILE *yyget_out (void );
> +
> +void yyset_out (FILE * out_str );
> +
> +int yyget_leng (void );
> +
> +char *yyget_text (void );
> +
> +int yyget_lineno (void );
> +
> +void yyset_lineno (int line_number );
> +
> /* Macros after this point can all be overridden by user definitions in
> * section 1.
> */
> @@ -553,7 +587,12 @@
>
> /* Amount of stuff to slurp up with each read. */
> #ifndef YY_READ_BUF_SIZE
> +#ifdef __ia64__
> +/* On IA-64, the buffer size is 16k, not 8k */
> +#define YY_READ_BUF_SIZE 16384
> +#else
> #define YY_READ_BUF_SIZE 8192
> +#endif /* __ia64__ */
> #endif
>
> /* Copy whatever the last rule matched to the standard output. */
> @@ -561,7 +600,7 @@
> /* This used to be an fputs(), but since the string might contain NUL's,
> * we now use fwrite().
> */
> -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout )
> +#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0)
> #endif
>
> /* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
> @@ -654,10 +693,10 @@
> register char *yy_cp, *yy_bp;
> register int yy_act;
>
> -#line 21 "../../../src/libkstmath/escan.l"
> +#line 21 "escan.l"
>
>
> -#line 654 "lex.yy.c"
> +#line 697 "escan.cpp"
>
> if ( !(yy_init) )
> {
> @@ -742,7 +781,7 @@
>
> case 1:
> YY_RULE_SETUP
> -#line 23 "../../../src/libkstmath/escan.l"
> +#line 23 "escan.l"
> {
> yylval.number = atof(yytext);
> /*printf("Found a number %.15f\n", yylval.number);*/
> @@ -751,7 +790,7 @@
> YY_BREAK
> case 2:
> YY_RULE_SETUP
> -#line 30 "../../../src/libkstmath/escan.l"
> +#line 30 "escan.l"
> {
> yylval.data = strdup(yytext);
> /*printf("Found an ID [%s]\n", yylval.data);*/
> @@ -760,7 +799,7 @@
> YY_BREAK
> case 3:
> YY_RULE_SETUP
> -#line 36 "../../../src/libkstmath/escan.l"
> +#line 36 "escan.l"
> {
> switch (*yytext) {
> case '[':
> @@ -792,7 +831,7 @@
> }
> YY_BREAK
> case YY_STATE_EOF(DATA):
> -#line 66 "../../../src/libkstmath/escan.l"
> +#line 66 "escan.l"
> {
> yyerror(store, "Invalid data reference.");
> yy_flush_buffer(YY_CURRENT_BUFFER);
> @@ -802,7 +841,7 @@
> YY_BREAK
> case 4:
> YY_RULE_SETUP
> -#line 73 "../../../src/libkstmath/escan.l"
> +#line 73 "escan.l"
> {
> bracketCount = 1;
> dataSpecPtr = dataSpec;
> @@ -812,7 +851,7 @@
> YY_BREAK
> case 5:
> YY_RULE_SETUP
> -#line 80 "../../../src/libkstmath/escan.l"
> +#line 80 "escan.l"
> {
> yyerror(store, "Unmatched ']'.");
> yy_flush_buffer(YY_CURRENT_BUFFER);
> @@ -821,117 +860,117 @@
> YY_BREAK
> case 6:
> YY_RULE_SETUP
> -#line 86 "../../../src/libkstmath/escan.l"
> +#line 86 "escan.l"
> return T_NOT;
> YY_BREAK
> case 7:
> YY_RULE_SETUP
> -#line 88 "../../../src/libkstmath/escan.l"
> +#line 88 "escan.l"
> return T_AND;
> YY_BREAK
> case 8:
> YY_RULE_SETUP
> -#line 90 "../../../src/libkstmath/escan.l"
> +#line 90 "escan.l"
> return T_OR;
> YY_BREAK
> case 9:
> YY_RULE_SETUP
> -#line 92 "../../../src/libkstmath/escan.l"
> +#line 92 "escan.l"
> return T_LAND;
> YY_BREAK
> case 10:
> YY_RULE_SETUP
> -#line 94 "../../../src/libkstmath/escan.l"
> +#line 94 "escan.l"
> return T_LOR;
> YY_BREAK
> case 11:
> YY_RULE_SETUP
> -#line 96 "../../../src/libkstmath/escan.l"
> +#line 96 "escan.l"
> return T_LT;
> YY_BREAK
> case 12:
> YY_RULE_SETUP
> -#line 98 "../../../src/libkstmath/escan.l"
> +#line 98 "escan.l"
> return T_LE;
> YY_BREAK
> case 13:
> YY_RULE_SETUP
> -#line 100 "../../../src/libkstmath/escan.l"
> +#line 100 "escan.l"
> return T_GT;
> YY_BREAK
> case 14:
> YY_RULE_SETUP
> -#line 102 "../../../src/libkstmath/escan.l"
> +#line 102 "escan.l"
> return T_GE;
> YY_BREAK
> case 15:
> YY_RULE_SETUP
> -#line 104 "../../../src/libkstmath/escan.l"
> +#line 104 "escan.l"
> return T_EQ;
> YY_BREAK
> case 16:
> YY_RULE_SETUP
> -#line 106 "../../../src/libkstmath/escan.l"
> +#line 106 "escan.l"
> return T_EQ;
> YY_BREAK
> case 17:
> YY_RULE_SETUP
> -#line 108 "../../../src/libkstmath/escan.l"
> +#line 108 "escan.l"
> return T_NE;
> YY_BREAK
> case 18:
> YY_RULE_SETUP
> -#line 110 "../../../src/libkstmath/escan.l"
> +#line 110 "escan.l"
> return T_ADD;
> YY_BREAK
> case 19:
> YY_RULE_SETUP
> -#line 112 "../../../src/libkstmath/escan.l"
> +#line 112 "escan.l"
> return T_SUBTRACT;
> YY_BREAK
> case 20:
> YY_RULE_SETUP
> -#line 114 "../../../src/libkstmath/escan.l"
> +#line 114 "escan.l"
> return T_MULTIPLY;
> YY_BREAK
> case 21:
> YY_RULE_SETUP
> -#line 116 "../../../src/libkstmath/escan.l"
> +#line 116 "escan.l"
> return T_DIVIDE;
> YY_BREAK
> case 22:
> YY_RULE_SETUP
> -#line 118 "../../../src/libkstmath/escan.l"
> +#line 118 "escan.l"
> return T_MOD;
> YY_BREAK
> case 23:
> YY_RULE_SETUP
> -#line 120 "../../../src/libkstmath/escan.l"
> +#line 120 "escan.l"
> return T_EXP;
> YY_BREAK
> case 24:
> YY_RULE_SETUP
> -#line 122 "../../../src/libkstmath/escan.l"
> +#line 122 "escan.l"
> return T_OPENPAR;
> YY_BREAK
> case 25:
> YY_RULE_SETUP
> -#line 124 "../../../src/libkstmath/escan.l"
> +#line 124 "escan.l"
> return T_CLOSEPAR;
> YY_BREAK
> case 26:
> YY_RULE_SETUP
> -#line 126 "../../../src/libkstmath/escan.l"
> +#line 126 "escan.l"
> return T_COMMA;
> YY_BREAK
> case 27:
> YY_RULE_SETUP
> -#line 128 "../../../src/libkstmath/escan.l"
> +#line 128 "escan.l"
> {}
> YY_BREAK
> case 28:
> YY_RULE_SETUP
> -#line 130 "../../../src/libkstmath/escan.l"
> +#line 130 "escan.l"
> {
> /*printf("Found char '%c'\n", yytext[0]);*/
> yylval.character = yytext[0];
> @@ -939,7 +978,7 @@
> }
> YY_BREAK
> case YY_STATE_EOF(INITIAL):
> -#line 137 "../../../src/libkstmath/escan.l"
> +#line 137 "escan.l"
> {
> /*printf("yyterminate\n");*/
> yyterminate();
> @@ -947,10 +986,10 @@
> YY_BREAK
> case 29:
> YY_RULE_SETUP
> -#line 142 "../../../src/libkstmath/escan.l"
> +#line 142 "escan.l"
> ECHO;
> YY_BREAK
> -#line 947 "lex.yy.c"
> +#line 990 "escan.cpp"
>
> case YY_END_OF_BUFFER:
> {
> @@ -1203,6 +1242,14 @@
> else
> ret_val = EOB_ACT_CONTINUE_SCAN;
>
> + if ((yy_size_t) ((yy_n_chars) + number_to_move)> YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
> + /* Extend the array by 50%, plus the number we really need. */
> + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars)>> 1);
> + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size );
> + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
> + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
> + }
> +
> (yy_n_chars) += number_to_move;
> YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
> YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
> @@ -1268,10 +1315,7 @@
>
> return yy_is_jam ? 0 : yy_current_state;
> }
> -
> -
> #if 0
> -// Not used
> static void yyunput (int c, register char * yy_bp )
> {
> register char *yy_cp;
> @@ -1309,7 +1353,6 @@
> (yy_c_buf_p) = yy_cp;
> }
> #endif
> -
> #ifndef YY_NO_INPUT
> #ifdef __cplusplus
> static int yyinput (void)
> @@ -1522,13 +1565,11 @@
> b->yy_bs_lineno = 1;
> b->yy_bs_column = 0;
> }
> -
> #ifdef Q_WS_WIN32
> b->yy_is_interactive = false;
> #else
> b->yy_is_interactive = file ? (isatty( fileno(file) )> 0) : 0;
> #endif
> -
> errno = oerrno;
> }
>
> @@ -1628,6 +1669,8 @@
> (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
> (num_to_alloc * sizeof(struct yy_buffer_state*)
> );
> + if ( ! (yy_buffer_stack) )
> + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
>
> memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
>
> @@ -1646,6 +1689,8 @@
> ((yy_buffer_stack),
> num_to_alloc * sizeof(struct yy_buffer_state*)
> );
> + if ( ! (yy_buffer_stack) )
> + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
>
> /* zero only the new slots.*/
> memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
> @@ -1690,7 +1735,7 @@
>
> /** Setup the input buffer state to scan a string. The next call to yylex() will
> * scan from a @e copy of @a str.
> - * @param str a NUL-terminated string to scan
> + * @param yystr a NUL-terminated string to scan
> *
> * @return the newly allocated buffer state object.
> * @note If you want to scan bytes that may contain NUL values, then use
> @@ -1704,8 +1749,8 @@
>
> /** Setup the input buffer state to scan the given bytes. The next call to yylex() will
> * scan from a @e copy of @a bytes.
> - * @param bytes the byte buffer to scan
> - * @param len the number of bytes in the buffer pointed to by @a bytes.
> + * @param yybytes the byte buffer to scan
> + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
> *
> * @return the newly allocated buffer state object.
> */
> @@ -1768,6 +1813,15 @@
>
> /* Accessor methods (get/set functions) to struct members. */
>
> +/** Get the current line number.
> + *
> + */
> +int yyget_lineno (void)
> +{
> +
> + return yylineno;
> +}
> +
> /** Get the input stream.
> *
> */
> @@ -1801,6 +1855,16 @@
> return yytext;
> }
>
> +/** Set the current line number.
> + * @param line_number
> + *
> + */
> +void yyset_lineno (int line_number )
> +{
> +
> + yylineno = line_number;
> +}
> +
> /** Set the input stream. This does not discard the current
> * input buffer.
> * @param in_str A readable stream.
> @@ -1925,7 +1989,7 @@
>
> #define YYTABLES_NAME "yytables"
>
> -#line 142 "../../../src/libkstmath/escan.l"
> +#line 142 "escan.l"
>
>
>
> _______________________________________________
> Kst mailing list
> Kst at kde.org
> https://mail.kde.org/mailman/listinfo/kst
>
More information about the Kst
mailing list