Skip to content

Commit

Permalink
* lib/yaml/rubytypes.rb (to_yaml): added instance variable handling
Browse files Browse the repository at this point in the history
  for Ranges, Strings, Structs, Regexps.

* lib/yaml/rubytypes.rb (to_yaml_fold): new method for setting a
  String's flow style.

* lib/yaml.rb (YAML::object_maker): now uses Object.allocate.

* ext/syck/gram.c: fixed transfer methods on structs, broke it
  last commit.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
why committed May 6, 2004
1 parent f77db2e commit 2fa9a0b
Show file tree
Hide file tree
Showing 14 changed files with 456 additions and 311 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Thu May 6 14:22:29 2004 why the lucky stiff <[email protected]>

* lib/yaml/rubytypes.rb (to_yaml): added instance variable handling
for Ranges, Strings, Structs, Regexps.

* lib/yaml/rubytypes.rb (to_yaml_fold): new method for setting a
String's flow style.

* lib/yaml.rb (YAML::object_maker): now uses Object.allocate.

* ext/syck/gram.c: fixed transfer methods on structs, broke it
last commit.

Thu May 6 14:38:02 Hirokazu Yamamoto <[email protected]>

* dir.c (rb_push_glob): simplified code (not change behavior)
Expand Down
2 changes: 1 addition & 1 deletion ext/syck/bytecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*
* Copyright (C) 2003 why the lucky stiff
*/
#include "syck.h"
#include "ruby.h"
#include "syck.h"
#include "gram.h"

#define QUOTELEN 128
Expand Down
3 changes: 2 additions & 1 deletion ext/syck/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
* All Base64 code from Ruby's pack.c.
* Ruby is Copyright (C) 1993-2003 Yukihiro Matsumoto
*/
#include "ruby.h"

#include <stdio.h>
#include <string.h>

#include "syck.h"
#include "ruby.h"

#define DEFAULT_ANCHOR_FORMAT "id%03d"

Expand Down
397 changes: 191 additions & 206 deletions ext/syck/gram.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ext/syck/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Copyright (C) 2003 why the lucky stiff
*/

#include "syck.h"
#include "ruby.h"
#include "syck.h"

SYMID
syck_hdlr_add_node( SyckParser *p, SyckNode *n )
Expand Down
2 changes: 1 addition & 1 deletion ext/syck/implicit.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* Copyright (C) 2003 why the lucky stiff
*/

#include "syck.h"
#include "ruby.h"
#include "syck.h"

#define YYCTYPE char
#define YYCURSOR cursor
Expand Down
2 changes: 1 addition & 1 deletion ext/syck/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Copyright (C) 2003 why the lucky stiff
*/

#include "syck.h"
#include "ruby.h"
#include "syck.h"

/*
* Node allocation functions
Expand Down
67 changes: 45 additions & 22 deletions ext/syck/rubyext.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,33 @@

typedef struct RVALUE {
union {
struct {
unsigned long flags; /* always 0 for freed obj */
struct RVALUE *next;
} free;
struct RBasic basic;
struct RObject object;
struct RClass klass;
struct RFloat flonum;
struct RString string;
struct RArray array;
struct RRegexp regexp;
struct RHash hash;
struct RData data;
struct RStruct rstruct;
struct RBignum bignum;
struct RFile file;
#if 0
struct {
unsigned long flags; /* always 0 for freed obj */
struct RVALUE *next;
} free;
struct RNode node;
struct RMatch match;
struct RVarmap varmap;
struct SCOPE scope;
#endif
struct RBasic basic;
struct RObject object;
struct RClass klass;
/*struct RFloat flonum;*/
/*struct RString string;*/
struct RArray array;
/*struct RRegexp regexp;*/
struct RHash hash;
/*struct RData data;*/
struct RStruct rstruct;
/*struct RBignum bignum;*/
/*struct RFile file;*/
} as;
#ifdef GC_DEBUG
char *file;
int line;
#endif
} RVALUE;

typedef struct {
Expand All @@ -49,7 +57,7 @@ typedef struct {
/*
* symbols and constants
*/
static ID s_new, s_utc, s_at, s_to_f, s_to_i, 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 ID s_new, s_utc, s_at, s_to_f, s_to_i, s_read, s_binmode, s_call, s_cmp, s_transfer, s_update, s_dup, s_match, s_keys, s_to_str, s_unpack, s_tr_bang, s_anchors, s_default_set;
static ID s_anchors, s_domain, s_families, s_kind, s_name, s_options, s_private_types, s_type_id, s_value;
static VALUE sym_model, sym_generic, sym_input, sym_bytecode;
static VALUE sym_scalar, sym_seq, sym_map;
Expand Down Expand Up @@ -552,10 +560,9 @@ yaml_org_handler( n, ref )
}
else if ( strncmp( n->data.str->ptr, ":", 1 ) == 0 )
{
char *tmp;
tmp = syck_strndup( n->data.str->ptr + 1, n->data.str->len - 1 );
obj = ID2SYM( rb_intern( tmp ) );
free( tmp );
obj = rb_funcall( oDefaultLoader, s_transfer, 2,
rb_str_new2( "ruby/sym" ),
rb_str_new( n->data.str->ptr + 1, n->data.str->len - 1 ) );
}
else if ( strcmp( type_id, "str" ) == 0 )
{
Expand Down Expand Up @@ -660,7 +667,7 @@ rb_syck_load_handler(p, n)
/*
* ID already set, let's alter the symbol table to accept the new object
*/
if (n->id > 0)
if (n->id > 0 && !NIL_P(obj))
{
MEMCPY((void *)n->id, (void *)obj, RVALUE, 1);
MEMZERO((void *)obj, RVALUE, 1);
Expand Down Expand Up @@ -1146,6 +1153,19 @@ syck_badalias_initialize( self, val )
return self;
}

/*
* YAML::Syck::BadAlias.<=>
*/
VALUE
syck_badalias_cmp( alias1, alias2 )
VALUE alias1, alias2;
{
VALUE str1 = rb_ivar_get( alias1, s_name );
VALUE str2 = rb_ivar_get( alias2, s_name );
VALUE val = rb_funcall( str1, s_cmp, 1, str2 );
return val;
}

/*
* YAML::Syck::DomainType.initialize
*/
Expand Down Expand Up @@ -1421,6 +1441,7 @@ Init_syck()
s_binmode = rb_intern("binmode");
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_default_set = rb_intern("default=");
Expand Down Expand Up @@ -1512,6 +1533,8 @@ Init_syck()
cBadAlias = rb_define_class_under( rb_syck, "BadAlias", rb_cObject );
rb_define_attr( cBadAlias, "name", 1, 1 );
rb_define_method( cBadAlias, "initialize", syck_badalias_initialize, 1);
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
Expand Down
3 changes: 2 additions & 1 deletion ext/syck/syck.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
*
* Copyright (C) 2003 why the lucky stiff
*/
#include "ruby.h"

#include <stdio.h>
#include <string.h>

#include "syck.h"
#include "ruby.h"

void syck_parser_pop_level( SyckParser * );

Expand Down
2 changes: 1 addition & 1 deletion ext/syck/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*
* Copyright (C) 2003 why the lucky stiff
*/
#include "syck.h"
#include "ruby.h"
#include "syck.h"
#include "gram.h"

/*
Expand Down
2 changes: 1 addition & 1 deletion ext/syck/yaml2byte.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
* WARNING WARNING WARNING --- THIS IS *NOT JUST* PLAYING
* ANYMORE! -- WHY HAS EMBRACED THIS AS THE REAL THING!
*/
#include "ruby.h"
#include <syck.h>
#include <assert.h>
#define YAMLBYTE_UTF8
#include "yamlbyte.h"
#include "ruby.h"

#include <stdio.h>
#define TRACE0(a) \
Expand Down
14 changes: 7 additions & 7 deletions lib/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ def YAML.read_type_class( type, obj_class )
#
def YAML.object_maker( obj_class, val, is_attr = false )
if Hash === val
name = obj_class.name
ostr = sprintf( "%c%co:%c%s\000", Marshal::MAJOR_VERSION, Marshal::MINOR_VERSION,
name.length + 5, name )
if is_attr
ostr[ -1, 1 ] = Marshal.dump( val ).sub( /^[^{]+\{/, '' )
end
o = ::Marshal.load( ostr )
# name = obj_class.name
# ostr = sprintf( "%c%co:%c%s\000", ::Marshal::MAJOR_VERSION, ::Marshal::MINOR_VERSION,
# name.length + 5, name )
# if is_attr
# ostr[ -1, 1 ] = ::Marshal.dump( val ).sub( /^[^{]+\{/, '' )
# end
o = obj_class.allocate
unless is_attr
val.each_pair { |k,v|
o.instance_variable_set("@#{k}", v)
Expand Down
46 changes: 27 additions & 19 deletions lib/yaml/baseemitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,36 @@ def binary_base64( value )
def node_text( value, block = '>' )
@seq_map = false
valx = value.dup
if options(:UseBlock)
block = '|'
elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
block = '|'
end
str = block.dup
if valx =~ /\n\Z\n/
str << "+"
elsif valx =~ /\Z\n/
else
str << "-"
end
unless block
block =
if options(:UseBlock)
'|'
elsif not options(:UseFold) and valx =~ /\n[ \t]/ and not valx =~ /#{YAML::ESCAPE_CHAR}/
'|'
else
'>'
end
block +=
if valx =~ /\n\Z\n/
"+"
elsif valx =~ /\Z\n/
""
else
"-"
end
if valx =~ /\A[ \t#]/
block += options(:Indent).to_s
end
end
if valx =~ /#{YAML::ESCAPE_CHAR}/
valx = YAML::escape( valx )
end
if valx =~ /\A[ \t#]/
str << options(:Indent).to_s
end
if block == '>'
if block[0] == ?>
valx = fold( valx )
end
self << str + indent_text( valx ) + "\n"
indt = nil
indt = $&.to_i if block =~ /\d+/
self << block + indent_text( valx, indt ) + "\n"
end

#
Expand Down Expand Up @@ -85,9 +93,9 @@ def single( value )
#
# Write a text block with the current indent
#
def indent_text( text )
def indent_text( text, indt = nil )
return "" if text.to_s.empty?
spacing = " " * ( level * options(:Indent) )
spacing = " " * ( level * ( indt || options(:Indent) ) )
return "\n" + text.gsub( /^([^\n])/, "#{spacing}\\1" )
end

Expand Down
Loading

0 comments on commit 2fa9a0b

Please sign in to comment.