[macruby-changes] [2890] MacRuby/trunk/ext/libyaml/rubyext.c

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 23 17:51:20 PDT 2009


Revision: 2890
          http://trac.macosforge.org/projects/ruby/changeset/2890
Author:   lsansonetti at apple.com
Date:     2009-10-23 17:51:19 -0700 (Fri, 23 Oct 2009)
Log Message:
-----------
fixed a problem when emitting ByteString scalars (since the C string might not be NULL-terminated)

Modified Paths:
--------------
    MacRuby/trunk/ext/libyaml/rubyext.c

Modified: MacRuby/trunk/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/trunk/ext/libyaml/rubyext.c	2009-10-24 00:49:22 UTC (rev 2889)
+++ MacRuby/trunk/ext/libyaml/rubyext.c	2009-10-24 00:51:19 UTC (rev 2890)
@@ -863,16 +863,16 @@
     yaml_event_t ev;
     yaml_emitter_t *emitter = &RYAMLEmitter(self)->emitter;
     yaml_char_t *output = (yaml_char_t *)RSTRING_PTR(val);
-    size_t length = strlen((const char *)output);
+    const size_t length = *(VALUE *)val == rb_cByteString
+	? RSTRING_LEN(val) : strlen((const char *)output);
 
     int can_omit_tag = 0;
     int string_tag   = 0;
     yaml_char_t *tag = rb_yaml_tag_or_null(taguri, &can_omit_tag, &string_tag);
     yaml_scalar_style_t sstyl = rb_symbol_to_scalar_style(style);
-    if (string_tag && 
-	(sstyl==YAML_ANY_SCALAR_STYLE || sstyl==YAML_PLAIN_SCALAR_STYLE) &&
-	(detect_scalar_type((const char *)output, length) != NULL)
-    ) {
+    if (string_tag
+	    && (sstyl==YAML_ANY_SCALAR_STYLE || sstyl==YAML_PLAIN_SCALAR_STYLE)
+	    && (detect_scalar_type((const char *)output, length) != NULL)) {
       /* Quote so this is read back as a string, no matter what type it looks like */
       sstyl = YAML_DOUBLE_QUOTED_SCALAR_STYLE;
     }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091023/e6b42191/attachment.html>


More information about the macruby-changes mailing list