Changeset 98
- Timestamp:
- 01/27/2007 12:51:54 (23 months ago)
- Files:
-
- 1 modified
-
trunk/ext/hpricot_scan/hpricot_scan.rl (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/hpricot_scan/hpricot_scan.rl
r95 r98 196 196 VALUE hpricot_scan(VALUE self, VALUE port) 197 197 { 198 char buf[BUFSIZE];199 198 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; 203 202 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; 205 204 206 205 int taint = OBJ_TAINTED( port ); … … 217 216 } 218 217 } 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); 219 225 220 226 %% write init; … … 223 229 VALUE str; 224 230 char *p = buf + have, *pe; 225 int len, space = BUFSIZE- have;231 int len, space = buffer_size - have; 226 232 227 233 if ( space == 0 ) { … … 256 262 257 263 if ( cs == hpricot_scan_error ) { 264 free(buf); 258 265 if ( !NIL_P(tag) ) 259 266 { … … 308 315 } 309 316 } 317 free(buf); 310 318 } 311 319 … … 313 321 { 314 322 VALUE mHpricot = rb_define_module("Hpricot"); 323 rb_define_attr(rb_singleton_class(mHpricot), "buffer_size", 1, 1); 315 324 rb_define_singleton_method(mHpricot, "scan", hpricot_scan, 1); 316 325 rb_eHpricotParseError = rb_define_class_under(mHpricot, "ParseError", rb_eException);
