r5289 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r5288‎ | r5289 | r5290 >
Date:11:35, 18 September 2004
Author:timwi
Status:old
Tags:
Comment:
fix segmentation fault error pointed out by Jens Frank on the mailing list.
Also lots more debug information (if you enable it, that is)
Modified paths:
  • /trunk/flexbisonparse/fb_defines.h (modified) (history)
  • /trunk/flexbisonparse/parsetree.c (modified) (history)
  • /trunk/flexbisonparse/wikilex.l (modified) (history)

Diff [purge]

Index: trunk/flexbisonparse/wikilex.l
@@ -102,13 +102,13 @@
103103
104104 /* For the table-related tokens, we need to remember enough information so that we can
105105 * reliably turn things back into text. */
106 -"{|"" "* { BEGIN(attributes); debuglex ("TABLEBEGIN "); yylval.num = yyleng-2; return TABLEBEGIN; }
107 -"||"" "* { yylval.num = 2*(yyleng-2); BEGIN(attributes); debuglex2 ("TABLECELL(%u) ", yylval.num); return TABLECELL; }
108 -^"|"" "* { yylval.num = 2*(yyleng-1)+1; BEGIN(attributes); debuglex2 ("TABLECELL(%u) ", yylval.num); return TABLECELL; }
109 -"!!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-2); return TABLEHEAD; }
110 -^"!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-1)+1; return TABLEHEAD; }
 106+"{|"" "* { BEGIN(attributes); debuglex ("TABLEBEGIN "); yylval.num = yyleng-2; return TABLEBEGIN; }
 107+"||"" "* { BEGIN(attributes); debuglex ("TABLECELL "); yylval.num = 2*(yyleng-2); return TABLECELL; }
 108+^"|"" "* { BEGIN(attributes); debuglex ("TABLECELL "); yylval.num = 2*(yyleng-1)+1; return TABLECELL; }
 109+"!!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-2); return TABLEHEAD; }
 110+^"!"" "* { BEGIN(attributes); debuglex ("TABLEHEAD "); yylval.num = 2*(yyleng-1)+1; return TABLEHEAD; }
 111+"|+"" "* { BEGIN(attributes); debuglex ("TABLECAPTION "); yylval.num = yyleng-2; return TABLECAPTION; }
111112 "|""-"+" "* { BEGIN(attributes); debuglex ("TABLEROW "); yylval.num = encodeTableRowInfo (yytext, yyleng); return TABLEROW; }
112 -"|+"" "* { BEGIN(attributes); debuglex ("TABLECAPTION "); yylval.num = yyleng-2; return TABLECAPTION; }
113113 "|}" { BEGIN(cannotbelistorheadingorpre); debuglex ("TABLEEND "); return TABLEEND; }
114114
115115 <attributes>[-a-zA-Z:_]+" "* {
Index: trunk/flexbisonparse/fb_defines.h
@@ -8,20 +8,35 @@
99 ** Originally written 2004 by Timwi
1010 **/
1111
 12+/* - Lots of debug information
1213
13 -/* Change these to
14 - #define debuglex printf
15 - #define debuglex2 printf
16 - #define debuglex3 printf
17 - to have the lexer output all the tokens generated. */
 14+#define debuglex printf
 15+#define debuglex2 printf
 16+#define debuglex3 printf
 17+#define debugf printf
 18+#define debugpt_end debug_indent--;
 19+#define debugpt(x) \
 20+ debug_indent++; \
 21+ printf ("%s", addSpaces ("", 2*debug_indent)); \
 22+ printf (x);
 23+#define debugpt2(x,y) \
 24+ debug_indent++; \
 25+ printf ("%s", addSpaces ("", 2*debug_indent)); \
 26+ printf (x, y);
 27+#define debugpt3(x,y,z) \
 28+ debug_indent++; \
 29+ printf ("%s", addSpaces ("", 2*debug_indent)); \
 30+ printf (x, y, z);
1831
 32+/*/
 33+
1934 #define debuglex(x)
2035 #define debuglex2(x,y)
2136 #define debuglex3(x,y,z)
 37+#define debugf(x)
 38+#define debugpt_end
 39+#define debugpt(x)
 40+#define debugpt2(x,y)
 41+#define debugpt3(x,y,z)
2242
23 -
24 -/* Change this one to
25 - #define debugf printf
26 - to have the parser output all reductions. */
27 -
28 -#define debugf(x)
 43+/**/
Index: trunk/flexbisonparse/parsetree.c
@@ -13,6 +13,18 @@
1414 #include <string.h>
1515 #include <stdio.h>
1616
 17+int debug_indent = 0;
 18+/* - use this only if you need debug info
 19+void freeNode (Node node)
 20+{
 21+ debugpt3 ("freeNode (%u, %u)\n", node, node->type);
 22+ free (node);
 23+ debugpt_end;
 24+}
 25+/*/
 26+#define freeNode free
 27+/**/
 28+
1729 Node newNode (NodeType newType)
1830 {
1931 Node result = (Node) malloc (sizeof (struct NodeStruct));
@@ -108,6 +120,8 @@
109121 {
110122 Node next, child = node->firstChild;
111123
 124+ debugpt2 ("freeRecursively (%u)\n", node);
 125+
112126 while (child)
113127 {
114128 next = child->nextSibling;
@@ -115,7 +129,9 @@
116130 child = next;
117131 }
118132
119 - free (node);
 133+ freeNode (node);
 134+
 135+ debugpt_end;
120136 }
121137
122138 void freeRecursivelyWithSiblings (Node node)
@@ -299,7 +315,7 @@
300316 examine->nextSibling = tmpnode;
301317 }
302318 /* Newlines nodes don't have children, no need for freeRecursively */
303 - free (newlinesnode);
 319+ freeNode (newlinesnode);
304320 }
305321 examine = examine->nextSibling;
306322 }
@@ -332,7 +348,7 @@
333349 if (node->type == Paragraph && !node->nextSibling)
334350 {
335351 ret = node->firstChild;
336 - free (node);
 352+ freeNode (node);
337353 return ret;
338354 }
339355 return node;
@@ -416,7 +432,7 @@
417433 examine = examine->nextSibling;
418434 /* Free the now-obsolete Italics node */
419435 /* We have attached its children elsewhere, so don't use freeRecursively */
420 - free (childSibling);
 436+ freeNode (childSibling);
421437 }
422438 /* Any node that is not an Italics node needs to become attached to one.
423439 * (In the above example, this is only Y.) */
@@ -454,7 +470,7 @@
455471 {
456472 nodeAddChild (a, b->firstChild);
457473 /* We have attached b's children elsewhere, so don't use freeRecursively */
458 - free (b);
 474+ freeNode (b);
459475 return a;
460476 }
461477 else if (a->type == TextBlock)
@@ -475,7 +491,7 @@
476492 if (node->type != AttributeGroup) return 0;
477493
478494 /* We've stored the first child in examine, so we can already free the parent */
479 - free (node);
 495+ freeNode (node);
480496
481497 while (examine) /* should be an Attribute node */
482498 {
@@ -520,7 +536,7 @@
521537 }
522538 prevExamine = examine;
523539 examine = examine->nextSibling;
524 - free (prevExamine);
 540+ freeNode (prevExamine);
525541 }
526542
527543 return ret;
@@ -535,16 +551,28 @@
536552 Node convertPipeSeriesToText (Node node)
537553 {
538554 Node result = 0;
539 - Node nextNode;
 555+ Node nextNode, child;
540556
 557+ debugpt ("convertPipeSeriesToText()\n");
 558+
541559 while (node)
542560 {
543 - result = makeTextBlock2 (result, newNodeS (TextToken, "|"), node->firstChild);
544561 nextNode = node->nextSibling;
545 - freeRecursively (node);
 562+ child = node->firstChild;
 563+
 564+ /* Performance optimisation: Instead of freeing 'node' and creating a new
 565+ * TextToken node, we'll reuse this one! */
 566+ node->type = TextToken;
 567+ node->data.str = "|";
 568+ node->nextSibling = 0;
 569+ node->firstChild = 0;
 570+
 571+ result = makeTextBlock2 (result, node, child);
546572 node = nextNode;
547573 }
548574
 575+ debugpt_end;
 576+
549577 return result;
550578 }
551579

Status & tagging log