Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 123938
Collapse All | Expand All

(-)ruby-1.8.4/ext/syck/emitter.c (-21 / +14 lines)
Lines 1-9 Link Here
1
/*
1
/*
2
 * emitter.c
2
 * emitter.c
3
 *
3
 *
4
 * $Author: why $
4
 * $Author: ocean $
5
 * $Date: 2005/09/20 06:46:43 $
5
 * $Date: 2006/02/02 15:02:49 $
6
 *
6
 *
7
 * Copyright (C) 2003 why the lucky stiff
7
 * Copyright (C) 2003 why the lucky stiff
8
 * 
8
 * 
9
 * All Base64 code from Ruby's pack.c.
9
 * All Base64 code from Ruby's pack.c.
Lines 313-321 Link Here
313
     * Write to buffer
313
     * Write to buffer
314
     */
314
     */
315
    S_MEMCPY( e->marker, str, char, len );
315
    S_MEMCPY( e->marker, str, char, len );
316
    e->marker += len;
316
    e->marker += len;
317
    e->marker[0] = '\0';
318
}
317
}
319
318
320
/*
319
/*
321
 * Write a chunk of data out.
320
 * Write a chunk of data out.
Lines 1002-1009 Link Here
1002
    if ( style == seq_inline || ( parent->status == syck_lvl_imap || parent->status == syck_lvl_iseq ) ) {
1001
    if ( style == seq_inline || ( parent->status == syck_lvl_imap || parent->status == syck_lvl_iseq ) ) {
1003
        syck_emitter_write( e, "[", 1 );
1002
        syck_emitter_write( e, "[", 1 );
1004
        lvl->status = syck_lvl_iseq;
1003
        lvl->status = syck_lvl_iseq;
1005
    } else {
1004
    } else {
1005
        /* complex key */
1006
        if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 ) {
1007
            syck_emitter_write( e, "? ", 2 );
1008
            parent->status = syck_lvl_mapx;
1009
        }
1006
        lvl->status = syck_lvl_seq;
1010
        lvl->status = syck_lvl_seq;
1007
    }
1011
    }
1008
}
1012
}
1009
1013
Lines 1018-1025 Link Here
1018
    if ( style == map_inline || ( parent->status == syck_lvl_imap || parent->status == syck_lvl_iseq ) ) {
1022
    if ( style == map_inline || ( parent->status == syck_lvl_imap || parent->status == syck_lvl_iseq ) ) {
1019
        syck_emitter_write( e, "{", 1 );
1023
        syck_emitter_write( e, "{", 1 );
1020
        lvl->status = syck_lvl_imap;
1024
        lvl->status = syck_lvl_imap;
1021
    } else {
1025
    } else {
1026
        /* complex key */
1027
        if ( parent->status == syck_lvl_map && parent->ncount % 2 == 1 ) {
1028
            syck_emitter_write( e, "? ", 2 );
1029
            parent->status = syck_lvl_mapx;
1030
        }
1022
        lvl->status = syck_lvl_map;
1031
        lvl->status = syck_lvl_map;
1023
    }
1032
    }
1024
}
1033
}
1025
1034
Lines 1035-1055 Link Here
1035
        case syck_lvl_seq:
1044
        case syck_lvl_seq:
1036
        {
1045
        {
1037
            SyckLevel *parent = syck_emitter_parent_level( e );
1046
            SyckLevel *parent = syck_emitter_parent_level( e );
1038
1047
1039
            /* seq-in-map shortcut */
1048
            /* seq-in-map shortcut -- the lvl->anctag check should be unneccesary but
1040
            if ( parent->status == syck_lvl_map && lvl->ncount == 0 ) {
1041
                /* complex key */
1042
                if ( parent->ncount % 2 == 1 ) {
1043
                    syck_emitter_write( e, "?", 1 );
1044
                    parent->status = syck_lvl_mapx;
1045
                /* shortcut -- the lvl->anctag check should be unneccesary but
1046
                 * there is a nasty shift/reduce in the parser on this point and
1049
                 * there is a nasty shift/reduce in the parser on this point and
1047
                 * i'm not ready to tickle it. */
1050
                 * i'm not ready to tickle it. */
1048
                } else if ( lvl->anctag == 0 ) { 
1051
            if ( lvl->anctag == 0 && parent->status == syck_lvl_map && lvl->ncount == 0 ) {
1049
                    lvl->spaces = parent->spaces;
1052
                    lvl->spaces = parent->spaces;
1050
                }
1053
                }
1051
            }
1052
1054
1053
            /* seq-in-seq shortcut */
1055
            /* seq-in-seq shortcut */
1054
            else if ( lvl->anctag == 0 && parent->status == syck_lvl_seq && lvl->ncount == 0 ) {
1056
            else if ( lvl->anctag == 0 && parent->status == syck_lvl_seq && lvl->ncount == 0 ) {
1055
                int spcs = ( lvl->spaces - parent->spaces ) - 2;
1057
                int spcs = ( lvl->spaces - parent->spaces ) - 2;
Lines 1079-1095 Link Here
1079
        case syck_lvl_map:
1081
        case syck_lvl_map:
1080
        {
1082
        {
1081
            SyckLevel *parent = syck_emitter_parent_level( e );
1083
            SyckLevel *parent = syck_emitter_parent_level( e );
1082
1084
1083
            /* map-in-map */
1084
            if ( parent->status == syck_lvl_map && lvl->ncount == 0 ) {
1085
                /* complex key */
1086
                if ( parent->ncount % 2 == 1 ) {
1087
                    syck_emitter_write( e, "?", 1 );
1088
                    parent->status = syck_lvl_mapx;
1089
                }
1090
            }
1091
1092
            /* map-in-seq shortcut */
1085
            /* map-in-seq shortcut */
1093
            if ( lvl->anctag == 0 && parent->status == syck_lvl_seq && lvl->ncount == 0 ) {
1086
            if ( lvl->anctag == 0 && parent->status == syck_lvl_seq && lvl->ncount == 0 ) {
1094
                int spcs = ( lvl->spaces - parent->spaces ) - 2;
1087
                int spcs = ( lvl->spaces - parent->spaces ) - 2;
1095
                if ( spcs >= 0 ) {
1088
                if ( spcs >= 0 ) {
(-)ruby-1.8.4/ext/syck/rubyext.c (-7 / +18 lines)
Lines 2-10 Link Here
2
/*
2
/*
3
 * rubyext.c
3
 * rubyext.c
4
 *
4
 *
5
 * $Author: ocean $
5
 * $Author: ocean $
6
 * $Date: 2005/12/20 04:13:26 $
6
 * $Date: 2006/02/03 10:28:27 $
7
 *
7
 *
8
 * Copyright (C) 2003-2005 why the lucky stiff
8
 * Copyright (C) 2003-2005 why the lucky stiff
9
 */
9
 */
10
10
Lines 48-57 Link Here
48
48
49
/*
49
/*
50
 * symbols and constants
50
 * symbols and constants
51
 */
51
 */
52
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_haskey, s_match, s_keys, s_unpack, s_tr_bang, s_default_set, s_tag_read_class, s_tag_subclasses, s_resolver, s_push, s_emitter, s_level, s_detect_implicit, s_node_import, s_out, s_input, s_intern, s_transform, s_yaml_new, s_yaml_initialize, s_node_export, s_to_yaml, s_write, s_set_resolver;
52
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_haskey, s_match, s_keys, s_unpack, s_tr_bang, s_default_set, s_tag_read_class, s_tag_subclasses, s_resolver, s_push, s_emitter, s_level, s_detect_implicit, s_node_import, s_out, s_input, s_intern, s_transform, s_yaml_new, s_yaml_initialize, s_node_export, s_to_yaml, s_write, s_set_resolver, s_each;
53
static ID s_tags, s_domain, s_kind, s_name, s_options, s_type_id, s_type_id_set, s_style, s_style_set, s_value, s_value_set;
53
static ID s_tags, s_kind, s_name, s_options, s_type_id, s_type_id_set, s_style, s_style_set, s_value, s_value_set;
54
static VALUE sym_model, sym_generic, sym_input, sym_bytecode;
54
static VALUE sym_model, sym_generic, sym_input, sym_bytecode;
55
static VALUE sym_scalar, sym_seq, sym_map;
55
static VALUE sym_scalar, sym_seq, sym_map;
56
static VALUE sym_1quote, sym_2quote, sym_fold, sym_literal, sym_plain, sym_inline;
56
static VALUE sym_1quote, sym_2quote, sym_fold, sym_literal, sym_plain, sym_inline;
57
static VALUE cDate, cNode, cMap, cSeq, cScalar, cOut, cParser, cResolver, cPrivateType, cDomainType, cYObject, cBadAlias, cDefaultKey, cMergeKey, cEmitter;
57
static VALUE cDate, cNode, cMap, cSeq, cScalar, cOut, cParser, cResolver, cPrivateType, cDomainType, cYObject, cBadAlias, cDefaultKey, cMergeKey, cEmitter;
Lines 114-129 Link Here
114
    syck_parser_taguri_expansion( parser, 0 );
114
    syck_parser_taguri_expansion( parser, 0 );
115
    oid = syck_parse( parser );
115
    oid = syck_parse( parser );
116
    syck_lookup_sym( parser, oid, (char **)&sav );
116
    syck_lookup_sym( parser, oid, (char **)&sav );
117
117
118
    ret = S_ALLOC_N( char, strlen( sav->buffer ) + 3 );
118
    ret = S_ALLOCA_N( char, strlen( sav->buffer ) + 3 );
119
    ret[0] = '\0';
119
    ret[0] = '\0';
120
    strcat( ret, "D\n" );
120
    strcat( ret, "D\n" );
121
    strcat( ret, sav->buffer );
121
    strcat( ret, sav->buffer );
122
122
123
    syck_free_parser( parser );
123
    syck_free_parser( parser );
124
124
125
    bc = rb_str_new2( ret );  S_FREE( ret );
125
    bc = rb_str_new2( ret );
126
    if ( taint )      OBJ_TAINT( bc );
126
    if ( taint )      OBJ_TAINT( bc );
127
    return bc;
127
    return bc;
128
}
128
}
129
129
Lines 1042-1055 Link Here
1042
{
1042
{
1043
    VALUE ivname = rb_ary_entry( vars, 0 );
1043
    VALUE ivname = rb_ary_entry( vars, 0 );
1044
    char *ivn;
1044
    char *ivn;
1045
    StringValue( ivname );
1045
    StringValue( ivname );
1046
    ivn = S_ALLOC_N( char, RSTRING(ivname)->len + 2 );
1046
    ivn = S_ALLOCA_N( char, RSTRING(ivname)->len + 2 );
1047
    ivn[0] = '@';
1047
    ivn[0] = '@';
1048
    ivn[1] = '\0';
1048
    ivn[1] = '\0';
1049
    strncat( ivn, RSTRING(ivname)->ptr, RSTRING(ivname)->len );
1049
    strncat( ivn, RSTRING(ivname)->ptr, RSTRING(ivname)->len );
1050
    rb_iv_set( obj, ivn, rb_ary_entry( vars, 1 ) );
1050
    rb_iv_set( obj, ivn, rb_ary_entry( vars, 1 ) );
1051
    S_FREE( ivn );
1052
    return Qnil;
1051
    return Qnil;
1053
}
1052
}
1054
1053
1055
/*
1054
/*
Lines 1134-1141 Link Here
1134
                            target_class = cYObject;
1133
                            target_class = cYObject;
1135
                            type = subclass;
1134
                            type = subclass;
1136
                            subclass = cYObject;
1135
                            subclass = cYObject;
1137
                        }
1136
                        }
1137
                        else /* workaround for SEGV. real fix please */
1138
                        {
1139
                            rb_raise( rb_eTypeError, "invalid subclass" );
1140
                        }
1138
                    }
1141
                    }
1139
                    break;
1142
                    break;
1140
                }
1143
                }
1141
            }
1144
            }
Lines 1156-1163 Link Here
1156
                obj = rb_funcall( target_class, s_yaml_new, 3, subclass, type, val );
1159
                obj = rb_funcall( target_class, s_yaml_new, 3, subclass, type, val );
1157
            }
1160
            }
1158
            else if ( !NIL_P( target_class ) )
1161
            else if ( !NIL_P( target_class ) )
1159
            {
1162
            {
1163
                if ( subclass == rb_cBignum )
1164
                {
1165
                    obj = rb_str2inum( val, 10 ); /* for yaml dumped by 1.8.3 [ruby-core:6159] */
1166
                }
1167
                else
1168
                {
1160
                obj = rb_obj_alloc( subclass );
1169
                obj = rb_obj_alloc( subclass );
1170
                }
1171
1161
                if ( rb_respond_to( obj, s_yaml_initialize ) )
1172
                if ( rb_respond_to( obj, s_yaml_initialize ) )
1162
                {
1173
                {
1163
                    rb_funcall( obj, s_yaml_initialize, 2, type, val );
1174
                    rb_funcall( obj, s_yaml_initialize, 2, type, val );
1164
                }
1175
                }
(-)ruby-1.8.4/ext/syck/syck.c (-5 / +2 lines)
Lines 1-9 Link Here
1
/*
1
/*
2
 * syck.c
2
 * syck.c
3
 *
3
 *
4
 * $Author: why $
4
 * $Author: ocean $
5
 * $Date: 2005/09/13 03:58:32 $
5
 * $Date: 2006/02/03 06:10:21 $
6
 *
6
 *
7
 * Copyright (C) 2003 why the lucky stiff
7
 * Copyright (C) 2003 why the lucky stiff
8
 */
8
 */
9
#include "ruby.h"
9
#include "ruby.h"
Lines 409-419 Link Here
409
    if ( p->token == NULL )
409
    if ( p->token == NULL )
410
        return 0;
410
        return 0;
411
411
412
    skip = p->limit - p->token;
412
    skip = p->limit - p->token;
413
    if ( skip < 1 )
414
        return 0;
415
416
    if ( ( count = p->token - p->buffer ) )
413
    if ( ( count = p->token - p->buffer ) )
417
    {
414
    {
418
        S_MEMMOVE( p->buffer, p->token, char, skip );
415
        S_MEMMOVE( p->buffer, p->token, char, skip );
419
        p->token = p->buffer;
416
        p->token = p->buffer;
(-)ruby-1.8.4/lib/yaml/emitter.rb (+107 lines)
Line 0 Link Here
1
#
2
# Output classes and methods
3
#
4
5
require 'yaml/baseemitter'
6
require 'yaml/encoding'
7
8
module YAML
9
10
	#
11
	# Emit a set of values
12
	#
13
    
14
	class Emitter
15
16
        include BaseEmitter
17
18
		attr_accessor :options
19
20
		def initialize( opts )
21
			opts = {} if opts.class != Hash
22
			@options = YAML::DEFAULTS.dup.update( opts )
23
            @headless = 0
24
            @seq_map = false
25
            @anchors = {}
26
            @anchor_extras = {}
27
            @active_anchors = []
28
            @level = -1
29
            self.clear
30
		end
31
32
		def clear
33
			@buffer = []
34
		end
35
36
        def level
37
            @level
38
        end
39
40
		#
41
		# Version string
42
		#
43
		def version_s
44
			" %YAML:#{@options[:Version]}" if @options[:UseVersion]
45
		end
46
47
		#
48
		# Header
49
		#
50
		def header
51
            if @headless.nonzero?
52
                ""
53
            else
54
                "---#{version_s} "
55
            end
56
		end
57
58
		#
59
		# Concatenate to the buffer
60
		#
61
		def <<( str )
62
            #p [ self.id, @level, str ]
63
			@buffer.last << str
64
		end
65
66
        #
67
        # Monitor objects and allow references
68
        #
69
        def start_object( oid )
70
		    @level += 1
71
            @buffer.push( "" )
72
            #p [ self.id, @level, :OPEN ]
73
            idx = nil
74
            if oid
75
                if @anchors.has_key?( oid )
76
                    idx = @active_anchors.index( oid )
77
                    unless idx
78
                        idx = @active_anchors.length
79
                        af_str = "&#{@options[:AnchorFormat]} " % [ idx + 1 ]
80
                        af_str += @anchor_extras[ @anchors[ oid ] ].to_s
81
                        @buffer[ @anchors[ oid ] ][0,0] = af_str
82
					    @headless = 0 if @anchors[ oid ].zero?
83
                    end
84
                    idx += 1
85
                    @active_anchors.push( oid )
86
                else
87
                    @anchors[ oid ] = @buffer.length - 1
88
                end
89
            end
90
            return idx
91
        end
92
93
		#
94
		# Output method
95
		#
96
		def end_object
97
		    @level -= 1
98
            @buffer.push( "" )
99
            #p [ self.id, @level, :END ]
100
			if @level < 0
101
				header + @buffer.to_s[@headless..-1].to_s
102
			end
103
		end
104
	end
105
106
end
107
(-)ruby-1.8.4/lib/yaml/rubytypes.rb (-10 / +13 lines)
Lines 182-189 Link Here
182
    yaml_as "tag:ruby.yaml.org,2002:symbol"
182
    yaml_as "tag:ruby.yaml.org,2002:symbol"
183
    yaml_as "tag:ruby.yaml.org,2002:sym"
183
    yaml_as "tag:ruby.yaml.org,2002:sym"
184
    def Symbol.yaml_new( klass, tag, val )
184
    def Symbol.yaml_new( klass, tag, val )
185
        if String === val
185
        if String === val
186
            val = YAML::load( val ) if val =~ /\A(["']).*\1\z/
186
            val.intern
187
            val.intern
187
        else
188
        else
188
            raise YAML::TypeError, "Invalid Symbol: " + val.inspect
189
            raise YAML::TypeError, "Invalid Symbol: " + val.inspect
189
        end
190
        end
Lines 351-359 Link Here
351
        end
352
        end
352
	end
353
	end
353
end
354
end
354
355
355
class Numeric
356
class Integer
357
    yaml_as "tag:yaml.org,2002:int"
358
	def to_yaml( opts = {} )
359
		YAML::quick_emit( nil, opts ) do |out|
360
            out.scalar( "tag:yaml.org,2002:int", self.to_s, :plain )
361
        end
362
	end
363
end
364
365
class Float
366
    yaml_as "tag:yaml.org,2002:float"
356
	def to_yaml( opts = {} )
367
	def to_yaml( opts = {} )
357
		YAML::quick_emit( nil, opts ) do |out|
368
		YAML::quick_emit( nil, opts ) do |out|
358
            str = self.to_s
369
            str = self.to_s
359
            if str == "Infinity"
370
            if str == "Infinity"
Lines 362-382 Link Here
362
                str = "-.Inf"
373
                str = "-.Inf"
363
            elsif str == "NaN"
374
            elsif str == "NaN"
364
                str = ".NaN"
375
                str = ".NaN"
365
            end
376
            end
366
            out.scalar( taguri, str, :plain )
377
            out.scalar( "tag:yaml.org,2002:float", str, :plain )
367
        end
378
        end
368
	end
379
	end
369
end
380
end
370
381
371
class Fixnum
372
    yaml_as "tag:yaml.org,2002:int"
373
end
374
375
class Float
376
    yaml_as "tag:yaml.org,2002:float"
377
end
378
379
class TrueClass
382
class TrueClass
380
    yaml_as "tag:yaml.org,2002:bool#yes"
383
    yaml_as "tag:yaml.org,2002:bool#yes"
381
	def to_yaml( opts = {} )
384
	def to_yaml( opts = {} )
382
		YAML::quick_emit( nil, opts ) do |out|
385
		YAML::quick_emit( nil, opts ) do |out|

Return to bug 123938