roxen.lists.pike.general

Subject Author Date
Stack Overflow 雪松 郭 <zenothing[at]hotmail[dot]com> 26-03-2009
I wrote a program to get the max-infomation block from html file:

$ cat t.pike

void main(){
string get_main_str2(string data)/*{{{*/
{
        array a=Parser.SGML.SGML()->feed(data)->finish();
        string max_str="";
        int max_count=0;
        int count(string s)
        {
                multiset m=(<>);
                foreach(s;int i;int c){
                        m[c]=1;
                }
                return sizeof(m);
        };
        //int n;
        //int key_n=17473;
        void walk(array a,void|int found_body)
        {
                //write("walk step %d\n",n++);
                foreach(a,object|string ob){
                        if(stringp(ob)){
                                int n=count(ob);
                                //werror("count=%d\n",n);
                                if(n>max_count&&found_body){
                                        //werror("update max_str=%s\n",ob);
                                        max_str=ob;
                                        max_count=n;
                                }
                        }else{
                                if(lower_case(ob->name)=="body"){
                                        //werror("found body\n");
                                        found_body=1;
                                }else{
                                        //ASSERT(ob->name!="body");
                                }
                                if(lower_case(ob->name)!="style"){
                                        walk(ob->data,found_body);
                                }
                        }
                }
        };
        walk(a);
        if(max_str=="")
                walk(a,1);
        return max_str;
};/*}}}*/
        write("%s\n",get_main_str2(Stdio.read_file("debug.txt")));
}

Using the attached debug.txt (in the debug.zip, unzip it please) as input, the
program crashed, and a simple one-line error said: Segmentation fault, no
call-stack dump at all.

$ pike t.pike
Segmentation fault

So I don't know what happened, I insert the debug codes into the source. When
the following lines added, call-stack dumped.

        int n;
        int key_n=17473;


$ pike t.pike
t.pike:17: Warning: Unused local variable n.
C stack overflow.
/home/peterpan/pike/7.8.116/lib/modules/Parser.pmod/SGML.pike:84:
Parser.SGML()->SGML()->SGMLatom()->_sprintf(79,mapping[1])
.... last 1 frames above repeated 918 times ...
/home/peterpan/pike/7.8.116/lib/master.pike:4153:
master()->Describer()->describe(Parser.SGML()->SGML()->SGMLatom(),198)
/home/peterpan/pike/7.8.116/lib/master.pike:4185:
    master()->Describer()->describe_comma_list(({"\n",SGMLatom(<b>
      "poner detra")," nachstellen",@0=Parser.SGML()->SGML()->SGMLatom()}),198)
/home/peterpan/pike/7.8.116/lib/master.pike:4098:
master()->Describer()->describe_array(@1=({"\n",SGMLatom(<b>
  "poner detra")," nachstellen",@0}),200)
/home/peterpan/pike/7.8.116/lib/master.pike:4136:
master()->Describer()->describe(@1,200)
/home/peterpan/pike/7.8.116/lib/master.pike:4185:
master()->Describer()->describe_comma_list((),200)
/home/peterpan/pike/7.8.116/lib/master.pike:4683:
   
describe_backtrace(({backtrace_frame(/home/peterpan/pike/7.8.116/lib/master.pike:3835,
_main(), Args: 1),backtrace_frame(/home/peterpan/work-hadoop/t.pike:51, main(),
No args),,,11066}
    ),190)
/home/peterpan/pike/7.8.116/lib/master.pike:1972:
master()->handle_error(({"Svalue stack overflow. (99624 of 100000 entries on
stack, needed 256 more entries)\n",@2}))
C stack overflow.
/home/peterpan/pike/7.8.116/lib/modules/Parser.pmod/SGML.pike:84:
Parser.SGML()->SGML()->SGMLatom()->_sprintf(79,mapping[1])
.... last 1 frames above repeated 918 times ...
/home/peterpan/pike/7.8.116/lib/master.pike:4153:
master()->Describer()->describe(Parser.SGML()->SGML()->SGMLatom(),198)
/home/peterpan/pike/7.8.116/lib/master.pike:4185:
    master()->Describer()->describe_comma_list(({"\n",SGMLatom(<b>
      "poner detra")," nachstellen",@0=Parser.SGML()->SGML()->SGMLatom()}),198)
/home/peterpan/pike/7.8.116/lib/master.pike:4098:
master()->Describer()->describe_array(@1=({"\n",SGMLatom(<b>
  "poner detra")," nachstellen",@0}),200)
/home/peterpan/pike/7.8.116/lib/master.pike:4136:
master()->Describer()->describe(@1,200)
/home/peterpan/pike/7.8.116/lib/master.pike:4185:
master()->Describer()->describe_comma_list((),200)
/home/peterpan/pike/7.8.116/lib/master.pike:4683:
   
describe_backtrace(({backtrace_frame(/home/peterpan/pike/7.8.116/lib/master.pike:3835,
_main(), Args: 1),backtrace_frame(/home/peterpan/work-hadoop/t.pike:51, main(),
No args),,,11066}
    ),190)
/home/peterpan/pike/7.8.116/lib/master.pike:1972:
master()->handle_error(({"Svalue stack overflow. (99624 of 100000 entries on
stack, needed 256 more entries)\n",@2}))

It's strange

_________________________________________________________________
Drag n’ drop—Get easy photo sharing with Windows Live™ Photos.

http://www.microsoft.com/windows/windowslive/products/photos.aspx