summaryrefslogtreecommitdiff
path: root/ext/syck
diff options
context:
space:
mode:
authorwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-29 17:41:26 +0000
committerwhy <why@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-06-29 17:41:26 +0000
commit2970a70a808260d028ac798180dc890b7320cdab (patch)
tree79ec68cde9a027fc928d54c9b6e19dee9c7975cd /ext/syck
parent759ab333e3c4b7ee58e701e9adebafe13541f124 (diff)
* ext/syck/rubyext.c (syck_emitter_new): set buffer after
Data_Wrap_Struct to avoid possible GC. [ruby-talk:104835] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@6544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/syck')
-rw-r--r--ext/syck/rubyext.c215
1 files changed, 107 insertions, 108 deletions
diff --git a/ext/syck/rubyext.c b/ext/syck/rubyext.c
index 3cd63ee..cdf184c 100644
--- a/ext/syck/rubyext.c
+++ b/ext/syck/rubyext.c
@@ -87,7 +87,7 @@ struct parser_xtra {
*/
VALUE
rb_syck_compile(self, port)
- VALUE self, port;
+ VALUE self, port;
{
SYMID oid;
int taint;
@@ -96,7 +96,7 @@ rb_syck_compile(self, port)
bytestring_t *sav;
SyckParser *parser = syck_new_parser();
- taint = syck_parser_assign_io(parser, port);
+ taint = syck_parser_assign_io(parser, port);
syck_parser_handler( parser, syck_yaml2byte_handler );
syck_parser_error_handler( parser, NULL );
syck_parser_implicit_typing( parser, 0 );
@@ -153,14 +153,14 @@ rb_syck_io_str_read( char *buf, SyckIoStr *str, long max_size, long skip )
*/
int
syck_parser_assign_io(parser, port)
- SyckParser *parser;
- VALUE port;
+ SyckParser *parser;
+ VALUE port;
{
int taint = Qtrue;
if (rb_respond_to(port, s_to_str)) {
- taint = OBJ_TAINTED(port); /* original taintedness */
- StringValue(port); /* possible conversion */
- syck_parser_str( parser, RSTRING(port)->ptr, RSTRING(port)->len, NULL );
+ taint = OBJ_TAINTED(port); /* original taintedness */
+ StringValue(port); /* possible conversion */
+ syck_parser_str( parser, RSTRING(port)->ptr, RSTRING(port)->len, NULL );
}
else if (rb_respond_to(port, s_read)) {
if (rb_respond_to(port, s_binmode)) {
@@ -333,7 +333,7 @@ rb_syck_parse_handler(p, n)
bonus = (struct parser_xtra *)p->bonus;
if ( bonus->taint) OBJ_TAINT( obj );
- if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, v);
+ if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, v);
rb_ivar_set(obj, s_value, v);
rb_hash_aset(bonus->data, INT2FIX(RHASH(bonus->data)->tbl->num_entries), obj);
@@ -348,10 +348,10 @@ VALUE
syck_merge_i( entry, hsh )
VALUE entry, hsh;
{
- if ( rb_obj_is_kind_of( entry, rb_cHash ) )
- {
- rb_funcall( hsh, s_update, 1, entry );
- }
+ if ( rb_obj_is_kind_of( entry, rb_cHash ) )
+ {
+ rb_funcall( hsh, s_update, 1, entry );
+ }
return Qnil;
}
@@ -367,12 +367,12 @@ rb_new_syck_node( obj, type_id )
if (rb_respond_to(obj, s_to_str))
{
- StringValue(obj); /* possible conversion */
+ StringValue(obj); /* possible conversion */
n = syck_alloc_str();
n->data.str->ptr = RSTRING(obj)->ptr;
n->data.str->len = RSTRING(obj)->len;
}
- else if ( rb_obj_is_kind_of( obj, rb_cArray ) )
+ else if ( rb_obj_is_kind_of( obj, rb_cArray ) )
{
n = syck_alloc_seq();
for ( i = 0; i < RARRAY(obj)->len; i++ )
@@ -527,7 +527,7 @@ yaml_org_handler( n, ref )
ptr += 2;
while ( !ISDIGIT( *ptr ) ) ptr++;
day = INT2FIX(strtol(ptr, NULL, 10));
-
+
if ( !cDate ) {
/*
* Load Date module
@@ -670,7 +670,7 @@ rb_syck_load_handler(p, n)
bonus = (struct parser_xtra *)p->bonus;
if ( bonus->taint) OBJ_TAINT( obj );
- if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, obj);
+ if ( bonus->proc != 0 ) rb_funcall(bonus->proc, s_call, 1, obj);
rb_hash_aset(bonus->data, INT2FIX(RHASH(bonus->data)->tbl->num_entries), obj);
return obj;
@@ -716,21 +716,21 @@ rb_syck_bad_anchor_handler(p, a)
*/
void
syck_set_model( parser, input, model )
- SyckParser *parser;
- VALUE input, model;
+ SyckParser *parser;
+ VALUE input, model;
{
- if ( model == sym_generic )
- {
- syck_parser_handler( parser, rb_syck_parse_handler );
- syck_parser_implicit_typing( parser, 1 );
- syck_parser_taguri_expansion( parser, 1 );
- }
- else
- {
- syck_parser_handler( parser, rb_syck_load_handler );
- syck_parser_implicit_typing( parser, 1 );
- syck_parser_taguri_expansion( parser, 0 );
- }
+ if ( model == sym_generic )
+ {
+ syck_parser_handler( parser, rb_syck_parse_handler );
+ syck_parser_implicit_typing( parser, 1 );
+ syck_parser_taguri_expansion( parser, 1 );
+ }
+ else
+ {
+ syck_parser_handler( parser, rb_syck_load_handler );
+ syck_parser_implicit_typing( parser, 1 );
+ syck_parser_taguri_expansion( parser, 0 );
+ }
if ( input == sym_bytecode )
{
syck_parser_set_input_type( parser, syck_bytecode_utf8 );
@@ -757,13 +757,13 @@ VALUE
syck_parser_new(argc, argv, class)
int argc;
VALUE *argv;
- VALUE class;
+ VALUE class;
{
- VALUE pobj, options, init_argv[1];
+ VALUE pobj, options, init_argv[1];
SyckParser *parser = syck_new_parser();
rb_scan_args(argc, argv, "01", &options);
- pobj = Data_Wrap_Struct( class, syck_mark_parser, syck_free_parser, parser );
+ pobj = Data_Wrap_Struct( class, syck_mark_parser, syck_free_parser, parser );
syck_parser_set_root_on_error( parser, Qnil );
@@ -771,9 +771,9 @@ syck_parser_new(argc, argv, class)
{
options = rb_hash_new();
}
- init_argv[0] = options;
- rb_obj_call_init(pobj, 1, init_argv);
- return pobj;
+ init_argv[0] = options;
+ rb_obj_call_init(pobj, 1, init_argv);
+ return pobj;
}
/*
@@ -784,7 +784,7 @@ syck_parser_initialize( self, options )
VALUE self, options;
{
rb_ivar_set(self, s_options, options);
- return self;
+ return self;
}
/*
@@ -794,13 +794,13 @@ static VALUE
syck_parser_bufsize_set( self, size )
VALUE self, size;
{
- SyckParser *parser;
+ SyckParser *parser;
- Data_Get_Struct(self, SyckParser, parser);
+ Data_Get_Struct(self, SyckParser, parser);
if ( rb_respond_to( size, s_to_i ) ) {
parser->bufsize = NUM2INT(rb_funcall(size, s_to_i, 0));
}
- return self;
+ return self;
}
/*
@@ -810,10 +810,10 @@ static VALUE
syck_parser_bufsize_get( self )
VALUE self;
{
- SyckParser *parser;
+ SyckParser *parser;
- Data_Get_Struct(self, SyckParser, parser);
- return INT2FIX( parser->bufsize );
+ Data_Get_Struct(self, SyckParser, parser);
+ return INT2FIX( parser->bufsize );
}
/*
@@ -823,26 +823,26 @@ VALUE
syck_parser_load(argc, argv, self)
int argc;
VALUE *argv;
- VALUE self;
+ VALUE self;
{
VALUE port, proc, model, input;
- SyckParser *parser;
+ SyckParser *parser;
struct parser_xtra bonus;
volatile VALUE hash; /* protect from GC */
rb_scan_args(argc, argv, "11", &port, &proc);
- Data_Get_Struct(self, SyckParser, parser);
+ Data_Get_Struct(self, SyckParser, parser);
input = rb_hash_aref( rb_attr_get( self, s_options ), sym_input );
model = rb_hash_aref( rb_attr_get( self, s_options ), sym_model );
- syck_set_model( parser, input, model );
+ syck_set_model( parser, input, model );
- bonus.taint = syck_parser_assign_io(parser, port);
+ bonus.taint = syck_parser_assign_io(parser, port);
bonus.data = hash = rb_hash_new();
- if ( NIL_P( proc ) ) bonus.proc = 0;
+ if ( NIL_P( proc ) ) bonus.proc = 0;
else bonus.proc = proc;
-
- parser->bonus = (void *)&bonus;
+
+ parser->bonus = (void *)&bonus;
return syck_parse( parser );
}
@@ -854,38 +854,38 @@ VALUE
syck_parser_load_documents(argc, argv, self)
int argc;
VALUE *argv;
- VALUE self;
+ VALUE self;
{
VALUE port, proc, v, input, model;
- SyckParser *parser;
+ SyckParser *parser;
struct parser_xtra bonus;
volatile VALUE hash;
rb_scan_args(argc, argv, "1&", &port, &proc);
- Data_Get_Struct(self, SyckParser, parser);
+ Data_Get_Struct(self, SyckParser, parser);
input = rb_hash_aref( rb_attr_get( self, s_options ), sym_input );
model = rb_hash_aref( rb_attr_get( self, s_options ), sym_model );
- syck_set_model( parser, input, model );
+ syck_set_model( parser, input, model );
- bonus.taint = syck_parser_assign_io(parser, port);
+ bonus.taint = syck_parser_assign_io(parser, port);
while ( 1 )
- {
+ {
/* Reset hash for tracking nodes */
bonus.data = hash = rb_hash_new();
bonus.proc = 0;
parser->bonus = (void *)&bonus;
/* Parse a document */
- v = syck_parse( parser );
+ v = syck_parse( parser );
if ( parser->eof == 1 )
{
break;
}
/* Pass document to block */
- rb_funcall( proc, s_call, 1, v );
- }
+ rb_funcall( proc, s_call, 1, v );
+ }
return Qnil;
}
@@ -1019,15 +1019,15 @@ transfer_find_i(entry, col)
{
VALUE key = rb_ary_entry( entry, 0 );
VALUE tid = rb_ary_entry( col, 0 );
- if ( rb_respond_to( key, s_match ) )
- {
- VALUE match = rb_funcall( key, rb_intern("match"), 1, tid );
- if ( ! NIL_P( match ) )
- {
- rb_ary_push( col, rb_ary_entry( entry, 1 ) );
- rb_iter_break();
- }
- }
+ if ( rb_respond_to( key, s_match ) )
+ {
+ VALUE match = rb_funcall( key, rb_intern("match"), 1, tid );
+ if ( ! NIL_P( match ) )
+ {
+ rb_ary_push( col, rb_ary_entry( entry, 1 ) );
+ rb_iter_break();
+ }
+ }
return Qnil;
}
@@ -1282,25 +1282,24 @@ VALUE
syck_emitter_new(argc, argv, class)
int argc;
VALUE *argv;
- VALUE class;
+ VALUE class;
{
- VALUE pobj, options, init_argv[1];
+ VALUE pobj, options, init_argv[1];
SyckEmitter *emitter = syck_new_emitter();
+ rb_scan_args(argc, argv, "01", &options);
+
+ pobj = Data_Wrap_Struct( class, syck_mark_emitter, syck_free_emitter, emitter );
syck_emitter_ignore_id( emitter, Qnil );
syck_emitter_handler( emitter, rb_syck_output_handler );
-
emitter->bonus = (void *)rb_str_new2( "" );
- rb_scan_args(argc, argv, "01", &options);
- pobj = Data_Wrap_Struct( class, syck_mark_emitter, syck_free_emitter, emitter );
-
if ( ! rb_obj_is_instance_of( options, rb_cHash ) )
{
options = rb_hash_new();
}
- init_argv[0] = options;
- rb_obj_call_init(pobj, 1, init_argv);
- return pobj;
+ init_argv[0] = options;
+ rb_obj_call_init(pobj, 1, init_argv);
+ return pobj;
}
/*
@@ -1311,7 +1310,7 @@ syck_emitter_initialize( self, options )
VALUE self, options;
{
rb_ivar_set(self, s_options, options);
- return self;
+ return self;
}
/*
@@ -1323,7 +1322,7 @@ syck_emitter_level_m( self )
{
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
return LONG2NUM( emitter->level );
}
@@ -1336,7 +1335,7 @@ syck_emitter_flush_m( self )
{
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
syck_emitter_flush( emitter, 0 );
return self;
}
@@ -1350,7 +1349,7 @@ syck_emitter_write_m( self, str )
{
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
StringValue(str);
syck_emitter_write( emitter, RSTRING(str)->ptr, RSTRING(str)->len );
return self;
@@ -1365,7 +1364,7 @@ syck_emitter_simple_write( self, str )
{
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
StringValue(str);
syck_emitter_simple( emitter, RSTRING(str)->ptr, RSTRING(str)->len );
return self;
@@ -1381,7 +1380,7 @@ syck_emitter_start_object( self, oid )
char *anchor_name;
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
anchor_name = syck_emitter_start_obj( emitter, oid );
if ( anchor_name == NULL )
@@ -1401,7 +1400,7 @@ syck_emitter_end_object( self )
{
SyckEmitter *emitter;
- Data_Get_Struct(self, SyckEmitter, emitter);
+ Data_Get_Struct(self, SyckEmitter, emitter);
syck_emitter_end_obj( emitter );
if ( emitter->level < 0 )
@@ -1422,9 +1421,9 @@ Init_syck()
rb_define_const( rb_syck, "VERSION", rb_str_new2( SYCK_VERSION ) );
rb_define_module_function( rb_syck, "compile", rb_syck_compile, 1 );
- /*
- * Global symbols
- */
+ /*
+ * Global symbols
+ */
s_new = rb_intern("new");
s_utc = rb_intern("utc");
s_at = rb_intern("at");
@@ -1436,13 +1435,13 @@ Init_syck()
s_transfer = rb_intern("transfer");
s_call = rb_intern("call");
s_cmp = rb_intern("<=>");
- s_update = rb_intern("update");
- s_dup = rb_intern("dup");
+ s_update = rb_intern("update");
+ s_dup = rb_intern("dup");
s_default_set = rb_intern("default=");
- s_match = rb_intern("match");
- s_keys = rb_intern("keys");
- s_to_str = rb_intern("to_str");
- s_tr_bang = rb_intern("tr!");
+ s_match = rb_intern("match");
+ s_keys = rb_intern("keys");
+ s_to_str = rb_intern("to_str");
+ s_tr_bang = rb_intern("tr!");
s_unpack = rb_intern("unpack");
s_anchors = rb_intern("@anchors");
@@ -1455,10 +1454,10 @@ Init_syck()
s_type_id = rb_intern("@type_id");
s_value = rb_intern("@value");
- sym_model = ID2SYM(rb_intern("Model"));
- sym_generic = ID2SYM(rb_intern("Generic"));
- sym_input = ID2SYM(rb_intern("Input"));
- sym_bytecode = ID2SYM(rb_intern("Bytecode"));
+ sym_model = ID2SYM(rb_intern("Model"));
+ sym_generic = ID2SYM(rb_intern("Generic"));
+ sym_input = ID2SYM(rb_intern("Input"));
+ sym_bytecode = ID2SYM(rb_intern("Bytecode"));
sym_map = ID2SYM(rb_intern("map"));
sym_scalar = ID2SYM(rb_intern("scalar"));
sym_seq = ID2SYM(rb_intern("seq"));
@@ -1488,7 +1487,7 @@ Init_syck()
*/
cParser = rb_define_class_under( rb_syck, "Parser", rb_cObject );
rb_define_attr( cParser, "options", 1, 1 );
- rb_define_singleton_method( cParser, "new", syck_parser_new, -1 );
+ rb_define_singleton_method( cParser, "new", syck_parser_new, -1 );
rb_define_method(cParser, "initialize", syck_parser_initialize, 1);
rb_define_method(cParser, "load", syck_parser_load, -1);
rb_define_method(cParser, "load_documents", syck_parser_load_documents, -1);
@@ -1530,21 +1529,21 @@ Init_syck()
rb_define_method( cBadAlias, "<=>", syck_badalias_cmp, 1);
rb_include_module( cBadAlias, rb_const_get( rb_cObject, rb_intern("Comparable") ) );
- /*
- * Define YAML::Syck::MergeKey class
- */
- cMergeKey = rb_define_class_under( rb_syck, "MergeKey", rb_cObject );
+ /*
+ * Define YAML::Syck::MergeKey class
+ */
+ cMergeKey = rb_define_class_under( rb_syck, "MergeKey", rb_cObject );
- /*
- * Define YAML::Syck::DefaultKey class
- */
- cDefaultKey = rb_define_class_under( rb_syck, "DefaultKey", rb_cObject );
+ /*
+ * Define YAML::Syck::DefaultKey class
+ */
+ cDefaultKey = rb_define_class_under( rb_syck, "DefaultKey", rb_cObject );
/*
* Define YAML::Syck::Emitter class
*/
cEmitter = rb_define_class_under( rb_syck, "Emitter", rb_cObject );
- rb_define_singleton_method( cEmitter, "new", syck_emitter_new, -1 );
+ rb_define_singleton_method( cEmitter, "new", syck_emitter_new, -1 );
rb_define_method( cEmitter, "initialize", syck_emitter_initialize, 1 );
rb_define_method( cEmitter, "level", syck_emitter_level_m, 0 );
rb_define_method( cEmitter, "write", syck_emitter_write_m, 1 );