/ Check-in [a9be4c2d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix Lemon so that it actually works with -DYYSTACKDEPTH=0.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a9be4c2d56d08fea2cd1aab20b19092a45ef7620
User & Date: drh 2016-05-27 04:10:47
Context
2016-05-27
12:30
Improvements to WHERE-clause debug tracing. Show TK_MATCH expressions and show more details on WhereTerm traces. check-in: 71087c12 user: drh tags: trunk
04:10
Fix Lemon so that it actually works with -DYYSTACKDEPTH=0. check-in: a9be4c2d user: drh tags: trunk
01:07
Fix the Lemon-generated parser so that it compiles with -DYYSTACKDEPTH=0. It does compile now, but there are subtle issues still. check-in: 28d439f8 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/misc5.test.

566
567
568
569
570
571
572


573
574
575
576
577
578
579
      LIMIT (SELECT lmt FROM logs_base) ;
    }
  } {1 {no such table: logs_base}}
}

# Overflow the lemon parser stack by providing an overly complex
# expression.  Make sure that the overflow is detected and reported.


#
do_test misc5-7.1 {
  execsql {CREATE TABLE t1(x)}
  set sql "INSERT INTO t1 VALUES("
  set tail ""
  for {set i 0} {$i<200} {incr i} {
    append sql "(1+"







>
>







566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
      LIMIT (SELECT lmt FROM logs_base) ;
    }
  } {1 {no such table: logs_base}}
}

# Overflow the lemon parser stack by providing an overly complex
# expression.  Make sure that the overflow is detected and reported.
#
# This test fails when building with -DYYSTACKDEPTH=0
#
do_test misc5-7.1 {
  execsql {CREATE TABLE t1(x)}
  set sql "INSERT INTO t1 VALUES("
  set tail ""
  for {set i 0} {$i<200} {incr i} {
    append sql "(1+"

Changes to tool/lempar.c.

210
211
212
213
214
215
216

217
218
219
220
221
222
223
...
267
268
269
270
271
272
273
274

275
276
277
278
279
280
281
282




283

284
285
286
287
288
289
290
291
292
293

294

295
296
297
298
299
300
301
...
323
324
325
326
327
328
329
330



331
332
333
334
335
336
337
...
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
...
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
...
642
643
644
645
646
647
648
649
650
651
652
653

654
655
656
657
658
659
660
#ifndef YYNOERRORRECOVERY
  int yyerrcnt;                 /* Shifts left before out of the error */
#endif
  ParseARG_SDECL                /* A place to hold %extra_argument */
#if YYSTACKDEPTH<=0
  int yystksz;                  /* Current side of the stack */
  yyStackEntry *yystack;        /* The parser's stack */

#else
  yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
#endif
};
typedef struct yyParser yyParser;

#ifndef NDEBUG
................................................................................
%%
};
#endif /* NDEBUG */


#if YYSTACKDEPTH<=0
/*
** Try to increase the size of the parser stack.

*/
static void yyGrowStack(yyParser *p){
  int newSize;
  int idx;
  yyStackEntry *pNew;

  newSize = p->yystksz*2 + 100;
  idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;




  pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));

  if( pNew ){
    p->yystack = pNew;
    p->yytos = &p->yystack[idx];
    p->yystksz = newSize;
#ifndef NDEBUG
    if( yyTraceFILE ){
      fprintf(yyTraceFILE,"%sStack grows to %d entries!\n",
              yyTracePrompt, p->yystksz);
    }
#endif

  }

}
#endif

/* Datatype of the argument to the memory allocated passed as the
** second argument to ParseAlloc() below.  This can be changed by
** putting an appropriate #define in the %include section of the input
** grammar.
................................................................................
#ifdef YYTRACKMAXSTACKDEPTH
    pParser->yyhwm = 0;
#endif
#if YYSTACKDEPTH<=0
    pParser->yytos = NULL;
    pParser->yystack = NULL;
    pParser->yystksz = 0;
    yyGrowStack(pParser);



#endif
    pParser->yytos = pParser->yystack;
    pParser->yystack[0].stateno = 0;
    pParser->yystack[0].major = 0;
  }
  return pParser;
}
................................................................................
){
  yyParser *pParser = (yyParser*)p;
#ifndef YYPARSEFREENEVERNULL
  if( pParser==0 ) return;
#endif
  while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
#if YYSTACKDEPTH<=0
  free(pParser->yystack);
#endif
  (*freeProc)((void*)pParser);
}

/*
** Return the peak depth of the stack for a parser.
*/
................................................................................
#if YYSTACKDEPTH>0 
  if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
    yyStackOverflow(yypParser);
    return;
  }
#else
  if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
    yyGrowStack(yypParser);
    if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
      yyStackOverflow(yypParser);
      return;
    }
  }
#endif
  yytos = yypParser->yytos;
  yytos->stateno = (YYACTIONTYPE)yyNewState;
................................................................................
#if YYSTACKDEPTH>0 
    if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH-1] ){
      yyStackOverflow(yypParser);
      return;
    }
#else
    if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
      yyGrowStack(yypParser);
      if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
        yyStackOverflow(yypParser);
        return;
      }

    }
#endif
  }

  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows:







>







 







|
>

|






>
>
>
>
|
>



<


|
|


>

>







 







|
>
>
>







 







|







 







|
<







 







|
<



>







210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
...
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
...
588
589
590
591
592
593
594
595

596
597
598
599
600
601
602
...
652
653
654
655
656
657
658
659

660
661
662
663
664
665
666
667
668
669
670
#ifndef YYNOERRORRECOVERY
  int yyerrcnt;                 /* Shifts left before out of the error */
#endif
  ParseARG_SDECL                /* A place to hold %extra_argument */
#if YYSTACKDEPTH<=0
  int yystksz;                  /* Current side of the stack */
  yyStackEntry *yystack;        /* The parser's stack */
  yyStackEntry yystk0;          /* First stack entry */
#else
  yyStackEntry yystack[YYSTACKDEPTH];  /* The parser's stack */
#endif
};
typedef struct yyParser yyParser;

#ifndef NDEBUG
................................................................................
%%
};
#endif /* NDEBUG */


#if YYSTACKDEPTH<=0
/*
** Try to increase the size of the parser stack.  Return the number
** of errors.  Return 0 on success.
*/
static int yyGrowStack(yyParser *p){
  int newSize;
  int idx;
  yyStackEntry *pNew;

  newSize = p->yystksz*2 + 100;
  idx = p->yytos ? (int)(p->yytos - p->yystack) : 0;
  if( p->yystack==&p->yystk0 ){
    pNew = malloc(newSize*sizeof(pNew[0]));
    if( pNew ) pNew[0] = p->yystk0;
  }else{
    pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
  }
  if( pNew ){
    p->yystack = pNew;
    p->yytos = &p->yystack[idx];

#ifndef NDEBUG
    if( yyTraceFILE ){
      fprintf(yyTraceFILE,"%sStack grows from %d to %d entries.\n",
              yyTracePrompt, p->yystksz, newSize);
    }
#endif
    p->yystksz = newSize;
  }
  return pNew==0; 
}
#endif

/* Datatype of the argument to the memory allocated passed as the
** second argument to ParseAlloc() below.  This can be changed by
** putting an appropriate #define in the %include section of the input
** grammar.
................................................................................
#ifdef YYTRACKMAXSTACKDEPTH
    pParser->yyhwm = 0;
#endif
#if YYSTACKDEPTH<=0
    pParser->yytos = NULL;
    pParser->yystack = NULL;
    pParser->yystksz = 0;
    if( yyGrowStack(pParser) ){
      pParser->yystack = &pParser->yystk0;
      pParser->yystksz = 1;
    }
#endif
    pParser->yytos = pParser->yystack;
    pParser->yystack[0].stateno = 0;
    pParser->yystack[0].major = 0;
  }
  return pParser;
}
................................................................................
){
  yyParser *pParser = (yyParser*)p;
#ifndef YYPARSEFREENEVERNULL
  if( pParser==0 ) return;
#endif
  while( pParser->yytos>pParser->yystack ) yy_pop_parser_stack(pParser);
#if YYSTACKDEPTH<=0
  if( pParser->yystack!=&pParser->yystk0 ) free(pParser->yystack);
#endif
  (*freeProc)((void*)pParser);
}

/*
** Return the peak depth of the stack for a parser.
*/
................................................................................
#if YYSTACKDEPTH>0 
  if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH] ){
    yyStackOverflow(yypParser);
    return;
  }
#else
  if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz] ){
    if( yyGrowStack(yypParser) ){

      yyStackOverflow(yypParser);
      return;
    }
  }
#endif
  yytos = yypParser->yytos;
  yytos->stateno = (YYACTIONTYPE)yyNewState;
................................................................................
#if YYSTACKDEPTH>0 
    if( yypParser->yytos>=&yypParser->yystack[YYSTACKDEPTH-1] ){
      yyStackOverflow(yypParser);
      return;
    }
#else
    if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){
      if( yyGrowStack(yypParser) ){

        yyStackOverflow(yypParser);
        return;
      }
      yymsp = yypParser->yytos;
    }
#endif
  }

  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows: