Changeset 98

Show
Ignore:
Timestamp:
01/27/2007 12:51:54 (23 months ago)
Author:
why
Message:
  • ext/hpricot_scan/hpricot_scan.rl: added buffer_size to allow increasing of Hpricot's buffer to compensate for ridiculous ASP.NET viewstate sizes!! The attribute values can be LARGER THAN 16K!! See #13 for how hassled I get about this. :)
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/ext/hpricot_scan/hpricot_scan.rl

    r95 r98  
    196196VALUE hpricot_scan(VALUE self, VALUE port) 
    197197{ 
    198   char buf[BUFSIZE]; 
    199198  int cs, act, have = 0, nread = 0, curline = 1, text = 0; 
    200   char *tokstart = 0, *tokend = 0; 
    201  
    202   VALUE attr = Qnil, tag = Qnil, akey = Qnil, aval = Qnil; 
     199  char *tokstart = 0, *tokend = 0, *buf = NULL; 
     200 
     201  VALUE attr = Qnil, tag = Qnil, akey = Qnil, aval = Qnil, bufsize = Qnil; 
    203202  char *mark_tag = 0, *mark_akey = 0, *mark_aval = 0; 
    204   int done = 0, ele_open = 0; 
     203  int done = 0, ele_open = 0, buffer_size = 0; 
    205204 
    206205  int taint = OBJ_TAINTED( port ); 
     
    217216    } 
    218217  } 
     218 
     219  bufsize = rb_ivar_get(self, rb_intern("@buffer_size")); 
     220  buffer_size = BUFSIZE; 
     221  if (!NIL_P(bufsize)) { 
     222    buffer_size = NUM2INT(bufsize); 
     223  } 
     224  buf = ALLOC_N(char, buffer_size); 
    219225 
    220226  %% write init; 
     
    223229    VALUE str; 
    224230    char *p = buf + have, *pe; 
    225     int len, space = BUFSIZE - have; 
     231    int len, space = buffer_size - have; 
    226232 
    227233    if ( space == 0 ) { 
     
    256262     
    257263    if ( cs == hpricot_scan_error ) { 
     264      free(buf); 
    258265      if ( !NIL_P(tag) ) 
    259266      { 
     
    308315    } 
    309316  } 
     317  free(buf); 
    310318} 
    311319 
     
    313321{ 
    314322  VALUE mHpricot = rb_define_module("Hpricot"); 
     323  rb_define_attr(rb_singleton_class(mHpricot), "buffer_size", 1, 1); 
    315324  rb_define_singleton_method(mHpricot, "scan", hpricot_scan, 1); 
    316325  rb_eHpricotParseError = rb_define_class_under(mHpricot, "ParseError", rb_eException);