[macruby-changes] [2161] MacRuby/branches/experimental

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 3 10:45:31 PDT 2009


Revision: 2161
          http://trac.macosforge.org/projects/ruby/changeset/2161
Author:   pthomson at apple.com
Date:     2009-08-03 10:45:31 -0700 (Mon, 03 Aug 2009)
Log Message:
-----------
Further work in making even a semi-usable YAML parser out of this code.

Modified Paths:
--------------
    MacRuby/branches/experimental/.gitignore
    MacRuby/branches/experimental/include/ruby/intern.h
    MacRuby/branches/experimental/io.c

Added Paths:
-----------
    MacRuby/branches/experimental/ext/libyaml/
    MacRuby/branches/experimental/ext/libyaml/rubyext.c

Modified: MacRuby/branches/experimental/.gitignore
===================================================================
--- MacRuby/branches/experimental/.gitignore	2009-08-03 17:45:29 UTC (rev 2160)
+++ MacRuby/branches/experimental/.gitignore	2009-08-03 17:45:31 UTC (rev 2161)
@@ -14,4 +14,8 @@
 spec/frozen/upstream_patches
 mspec_upstream
 mspec/upstream_patches
-spec/frozen/optional/ffi/fixtures/build
\ No newline at end of file
+spec/frozen/optional/ffi/fixtures/build
+*.bundle
+mkmf.log
+Makefile
+>>>>>>> Further work in making even a semi-usable YAML parser out of this code.:.gitignore

Added: MacRuby/branches/experimental/ext/libyaml/rubyext.c
===================================================================
--- MacRuby/branches/experimental/ext/libyaml/rubyext.c	                        (rev 0)
+++ MacRuby/branches/experimental/ext/libyaml/rubyext.c	2009-08-03 17:45:31 UTC (rev 2161)
@@ -0,0 +1,96 @@
+/*
+ *
+ * rubyext.c - ruby extensions to libYAML
+ * author: Patrick Thomson
+ * date: July 27, 2009
+ *
+ */ 
+
+#include "ruby/ruby.h"
+#include "yaml.h"
+
+static VALUE
+yaml_load(VALUE module, SEL sel, VALUE input)
+{
+	return Qnil;
+}
+
+static VALUE
+yaml_dump(VALUE module, SEL sel, int argc, VALUE* argv)
+{
+	return Qnil;
+}
+
+static VALUE
+rb_yaml_parser_alloc(VALUE klass, SEL sel)
+{
+	yaml_parser_t *parser = ALLOC(yaml_parser_t);
+	yaml_parser_initialize(parser);
+	// XXX: Figure out how to pass the yaml_parser_delete() method to the parser upon deallocation.
+	return Data_Wrap_Struct(klass, NULL, NULL, parser);
+}
+
+static int
+rb_yaml_parser_io_handler(VALUE io, unsigned char *out_buffer, size_t size, size_t *size_read)
+{
+	if (rb_io_eof(io, 0) == Qtrue)
+	{
+		*size_read = 0;
+		return 1;
+	}
+	long ret = rb_io_primitive_read(ExtractIOStruct(io), (UInt8*)buffer, size);
+	if (ret == -1) {
+		return 0;
+	}
+	*size_read = (size_t)ret;
+	return 1;
+}
+
+static VALUE
+rb_yaml_parser_load(VALUE self, SEL sel, VALUE io)
+{
+	yaml_parser_t *parser;
+	Data_Get_Struct(self, yaml_parser_t, parser);
+	yaml_parser_set_input(parser, (yaml_read_handler_t*)rb_yaml_parser_io_handler, io);
+}
+
+static IMP rb_yaml_parser_finalize_super = NULL; 
+
+static void
+rb_yaml_parser_finalize(void *rcv, SEL sel)
+{
+	yaml_parser_t *parser;
+	Data_Get_Struct(rcv, yaml_parser_t, parser);
+	yaml_parser_delete(parser);
+	if (rb_yaml_parser_finalize_super != NULL)
+	{
+		((void(*)(void *, SEL))rb_yaml_parser_finalize_super)(rcv, sel);
+	}
+}
+
+static VALUE
+rb_yaml_emitter_emit(VALUE self, SEL sel, int argc, VALUE *argv)
+{
+	return Qnil;
+}
+
+void
+Init_yaml()
+{
+	VALUE rb_mYAML = rb_define_module("YAML");
+	
+	rb_objc_define_method(*(VALUE *)rb_mYAML, "load", yaml_load, 1);
+	rb_objc_define_method(*(VALUE *)rb_mYAML, "dump", yaml_dump, -1);
+	
+	VALUE rb_mLibYAML = rb_define_module_under(rb_mYAML, "LibYAML");
+	rb_define_const(rb_mLibYAML, "VERSION", rb_str_new2(yaml_get_version_string()));
+	
+	VALUE rb_cParser = rb_define_class_under(rb_mLibYAML, "Parser", rb_cObject);
+	rb_objc_define_method(*(VALUE *)rb_cParser, "alloc", rb_yaml_parser_alloc, 0);
+	rb_objc_define_method(rb_cParser, "load", rb_yaml_parser_load, 1);
+	
+	rb_yaml_parser_finalize_super = rb_objc_install_method2((Class)rb_cParser, "finalize", (IMP)rb_yaml_parser_finalize);
+	
+	VALUE rb_cEmitter = rb_define_class_under(rb_mLibYAML, "Emitter", rb_cObject);
+	rb_objc_define_method(rb_cEmitter, "emit", rb_yaml_emitter_emit, -1);
+}
\ No newline at end of file

Modified: MacRuby/branches/experimental/include/ruby/intern.h
===================================================================
--- MacRuby/branches/experimental/include/ruby/intern.h	2009-08-03 17:45:29 UTC (rev 2160)
+++ MacRuby/branches/experimental/include/ruby/intern.h	2009-08-03 17:45:31 UTC (rev 2161)
@@ -394,6 +394,7 @@
 VALUE rb_io_printf(VALUE, SEL, int, VALUE *);
 VALUE rb_io_print(VALUE, SEL, int, VALUE *);
 VALUE rb_io_fdopen(int, int, const char*);
+long rb_io_primitive_read(rb_io_t *, UInt8 *, long);
 VALUE rb_gets(void);
 void rb_write_error(const char*);
 void rb_write_error2(const char*, long);

Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c	2009-08-03 17:45:29 UTC (rev 2160)
+++ MacRuby/branches/experimental/io.c	2009-08-03 17:45:31 UTC (rev 2161)
@@ -1076,6 +1076,12 @@
     return rb_io_read_internal(io_struct, buffer, buffer_len) > 0;
 }
 
+long
+rb_io_primitive_read(rb_io_t *io_struct, UInt8 *buffer, long len)
+{
+	return rb_io_read_internal(io_struct, buffer, len);
+}
+
 /*
  *  call-seq:
  *     ios.read_nonblock(maxlen)              => string
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090803/9c0084b8/attachment-0001.html>


More information about the macruby-changes mailing list