Python segfault

Hans-Joachim Widmaier hjwidmai at foxboro.com
Fri Jun 16 08:19:03 EDT 2000


Thomas Wouters wrote:

> The problem is not the 'height' of this graph, or the total number of 'nodes' 
> (which is limited only by memory), but the 'width' of the first tree.
> The 'node' struct is defined like this: 
> 
> typedef struct _node { 
> short n_type; 
> char *n_str; 
> short n_lineno; 
> short n_nchildren; 
> struct _node *n_child; 
> } node; 
> 
> and the 'n_nchildren' member is the number of immediate subexpressions
> (not grandchildren, only children) -- and it is limited to a short, which is
> 16 bits on most systems. And the short is signed, which means the maximum number
> of children is 32767. This includes the operators itself, so you can operate on
> just 16384 items in a single expression. If you try to operate on more, the short
> wraps, and the parser tries to index node->n_child[-32768], which usually segfaults. 

Why not simply make 'n_nchildren' an (32 bit) int? And, while at it, 'n_lineno' also?
It would cost some memory, though.

-- 
Hans-Joachim Widmaier             E-Mail:  hjwidmaier at web.de




More information about the Python-list mailing list