1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/syck/rubyext.c: default keys handled.

* ext/syck/syck.h: lowered default buffer size to 16k for increased
  performance.

* test/yaml: checkin of basic unit tests.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4667 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
why 2003-10-03 19:51:25 +00:00
parent 7d18f560f5
commit df0e9dbe97
4 changed files with 1189 additions and 10 deletions

View file

@ -1,3 +1,12 @@
Sat Oct 4 04:48:49 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
* ext/syck/rubyext.c: default keys handled.
* ext/syck/syck.h: lowered default buffer size to 16k for increased
performance.
* test/yaml: checkin of basic unit tests.
Sat Oct 4 04:24:19 2003 GOTOU Yuuzou <gotoyuzo@notwork.org> Sat Oct 4 04:24:19 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
* ext/openssl/extconf.rb: add check for X509V3_set_nconf. * ext/openssl/extconf.rb: add check for X509V3_set_nconf.

View file

@ -40,10 +40,10 @@ typedef struct RVALUE {
/* /*
* symbols and constants * symbols and constants
*/ */
static ID s_new, s_utc, s_at, s_to_f, s_read, s_binmode, s_call, s_transfer, s_update, s_dup, s_match, s_keys, s_to_str, s_unpack, s_tr_bang; static ID s_new, s_utc, s_at, s_to_f, s_read, s_binmode, s_call, s_transfer, s_update, s_dup, s_match, s_keys, s_to_str, s_unpack, s_tr_bang, s_anchors, s_default_set;
static VALUE sym_model, sym_generic; static VALUE sym_model, sym_generic;
static VALUE sym_scalar, sym_seq, sym_map; static VALUE sym_scalar, sym_seq, sym_map;
VALUE cDate, cParser, cLoader, cNode, cPrivateType, cDomainType, cBadAlias, cMergeKey, cEmitter; VALUE cDate, cParser, cLoader, cNode, cPrivateType, cDomainType, cBadAlias, cDefaultKey, cMergeKey, cEmitter;
VALUE oDefaultLoader; VALUE oDefaultLoader;
/* /*
@ -364,9 +364,6 @@ yaml_org_handler( n, ref )
long i = 0; long i = 0;
VALUE obj = Qnil; VALUE obj = Qnil;
/*
* If prefixed with YAML_DOMAIN, skip to type name
*/
switch (n->kind) switch (n->kind)
{ {
case syck_str_kind: case syck_str_kind:
@ -464,6 +461,10 @@ yaml_org_handler( n, ref )
{ {
obj = rb_funcall( cMergeKey, s_new, 0 ); obj = rb_funcall( cMergeKey, s_new, 0 );
} }
else if ( strncmp( type_id, "default", 7 ) == 0 )
{
obj = rb_funcall( cDefaultKey, s_new, 0 );
}
else else
{ {
transferred = 0; transferred = 0;
@ -489,7 +490,7 @@ yaml_org_handler( n, ref )
{ {
VALUE k = syck_map_read( n, map_key, i ); VALUE k = syck_map_read( n, map_key, i );
VALUE v = syck_map_read( n, map_value, i ); VALUE v = syck_map_read( n, map_value, i );
int merge_key = 0; int skip_aset = 0;
/* /*
* Handle merge keys * Handle merge keys
@ -501,7 +502,7 @@ yaml_org_handler( n, ref )
VALUE dup = rb_funcall( v, s_dup, 0 ); VALUE dup = rb_funcall( v, s_dup, 0 );
rb_funcall( dup, s_update, 1, obj ); rb_funcall( dup, s_update, 1, obj );
obj = dup; obj = dup;
merge_key = 1; skip_aset = 1;
} }
else if ( rb_obj_is_kind_of( v, rb_cArray ) ) else if ( rb_obj_is_kind_of( v, rb_cArray ) )
{ {
@ -513,12 +514,17 @@ yaml_org_handler( n, ref )
rb_ary_push( v, obj ); rb_ary_push( v, obj );
rb_iterate( rb_each, v, syck_merge_i, dup ); rb_iterate( rb_each, v, syck_merge_i, dup );
obj = dup; obj = dup;
merge_key = 1; skip_aset = 1;
} }
} }
} }
else if ( rb_obj_is_kind_of( k, cDefaultKey ) )
{
rb_funcall( obj, s_default_set, 1, v );
skip_aset = 1;
}
if ( ! merge_key ) if ( ! skip_aset )
{ {
rb_hash_aset( obj, k, v ); rb_hash_aset( obj, k, v );
} }
@ -762,6 +768,7 @@ syck_loader_initialize( self )
rb_iv_set(self, "@families", rb_hash_new() ); rb_iv_set(self, "@families", rb_hash_new() );
rb_iv_set(self, "@private_types", rb_hash_new() ); rb_iv_set(self, "@private_types", rb_hash_new() );
rb_iv_set(self, "@anchors", rb_hash_new() );
families = rb_iv_get(self, "@families"); families = rb_iv_get(self, "@families");
rb_hash_aset(families, rb_str_new2( YAML_DOMAIN ), rb_hash_new()); rb_hash_aset(families, rb_str_new2( YAML_DOMAIN ), rb_hash_new());
@ -1274,11 +1281,13 @@ Init_syck()
s_at = rb_intern("at"); s_at = rb_intern("at");
s_to_f = rb_intern("to_f"); s_to_f = rb_intern("to_f");
s_read = rb_intern("read"); s_read = rb_intern("read");
s_anchors = rb_intern("anchors");
s_binmode = rb_intern("binmode"); s_binmode = rb_intern("binmode");
s_transfer = rb_intern("transfer"); s_transfer = rb_intern("transfer");
s_call = rb_intern("call"); s_call = rb_intern("call");
s_update = rb_intern("update"); s_update = rb_intern("update");
s_dup = rb_intern("dup"); s_dup = rb_intern("dup");
s_default_set = rb_intern("default=");
s_match = rb_intern("match"); s_match = rb_intern("match");
s_keys = rb_intern("keys"); s_keys = rb_intern("keys");
s_to_str = rb_intern("to_str"); s_to_str = rb_intern("to_str");
@ -1303,6 +1312,7 @@ Init_syck()
cLoader = rb_define_class_under( rb_syck, "Loader", rb_cObject ); cLoader = rb_define_class_under( rb_syck, "Loader", rb_cObject );
rb_define_attr( cLoader, "families", 1, 1 ); rb_define_attr( cLoader, "families", 1, 1 );
rb_define_attr( cLoader, "private_types", 1, 1 ); rb_define_attr( cLoader, "private_types", 1, 1 );
rb_define_attr( cLoader, "anchors", 1, 1 );
rb_define_method( cLoader, "initialize", syck_loader_initialize, 0 ); rb_define_method( cLoader, "initialize", syck_loader_initialize, 0 );
rb_define_method( cLoader, "add_domain_type", syck_loader_add_domain_type, -1 ); rb_define_method( cLoader, "add_domain_type", syck_loader_add_domain_type, -1 );
rb_define_method( cLoader, "add_builtin_type", syck_loader_add_builtin_type, -1 ); rb_define_method( cLoader, "add_builtin_type", syck_loader_add_builtin_type, -1 );
@ -1364,6 +1374,11 @@ Init_syck()
*/ */
cMergeKey = rb_define_class_under( rb_syck, "MergeKey", rb_cObject ); 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::Emitter class * Define YAML::Syck::Emitter class
*/ */

View file

@ -47,7 +47,7 @@ extern "C" {
#endif #endif
#define ALLOC_CT 8 #define ALLOC_CT 8
#define SYCK_BUFFERSIZE 262144 #define SYCK_BUFFERSIZE 16384
#define S_ALLOC_N(type,n) (type*)malloc(sizeof(type)*(n)) #define S_ALLOC_N(type,n) (type*)malloc(sizeof(type)*(n))
#define S_ALLOC(type) (type*)malloc(sizeof(type)) #define S_ALLOC(type) (type*)malloc(sizeof(type))
#define S_REALLOC_N(var,type,n) (var)=(type*)realloc((char*)(var),sizeof(type)*(n)) #define S_REALLOC_N(var,type,n) (var)=(type*)realloc((char*)(var),sizeof(type)*(n))

1155
test/yaml/test_yaml.rb Normal file

File diff suppressed because it is too large Load diff