[macruby-changes] [4067] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon May 10 22:02:46 PDT 2010


Revision: 4067
          http://trac.macosforge.org/projects/ruby/changeset/4067
Author:   lsansonetti at apple.com
Date:     2010-05-10 22:02:44 -0700 (Mon, 10 May 2010)
Log Message:
-----------
more robust runtime signature parsing, by dynamically allocating the temporary buffer instead of using a static array (which might be too small when parsing big signatures like in CoreAudio)

Modified Paths:
--------------
    MacRuby/trunk/bridgesupport.cpp
    MacRuby/trunk/compiler.cpp

Modified: MacRuby/trunk/bridgesupport.cpp
===================================================================
--- MacRuby/trunk/bridgesupport.cpp	2010-05-11 02:28:27 UTC (rev 4066)
+++ MacRuby/trunk/bridgesupport.cpp	2010-05-11 05:02:44 UTC (rev 4067)
@@ -530,21 +530,26 @@
 rb_vm_bs_boxed_t *
 RoxorCore::register_anonymous_bs_struct(const char *type)
 {
-    if (strlen(type) < 3 || type[0] != _C_STRUCT_B || type[1] != '?'
-	   || type[2] != '=') {
+    const size_t type_len = strlen(type);
+    assert(type_len > 0);
+
+    if (type_len < 3 || type[0] != _C_STRUCT_B || type[1] != '?'
+	    || type[2] != '=') {
 	// Does not look like an anonymous struct...
 	return NULL;
     }
 
     // Prepare the list of field types.
+    const size_t buf_len = type_len + 1;
+    char *buf = (char *)malloc(buf_len);
     std::vector<std::string> s_types;
-    char buf[100];
     const char *p = &type[3];
     while (*p != _C_STRUCT_E) {
-	p = GetFirstType(p, buf, sizeof buf);
+	p = GetFirstType(p, buf, buf_len);
 	assert(*p != '\0');
 	s_types.push_back(buf);
     }
+    free(buf);
 
     // Prepare the BridgeSupport structure.
     bs_element_struct_t *bs_struct = (bs_element_struct_t *)

Modified: MacRuby/trunk/compiler.cpp
===================================================================
--- MacRuby/trunk/compiler.cpp	2010-05-11 02:28:27 UTC (rev 4066)
+++ MacRuby/trunk/compiler.cpp	2010-05-11 05:02:44 UTC (rev 4067)
@@ -749,6 +749,7 @@
 		debug_compile_unit, DILocation(NULL));
 #if LLVM_TOT
 	insn->setMetadata(dbg_mdkind, loc.getNode());
+	//insn->setDebugLoc(DebugLoc::getFromDILocation(loc.getNode()));
 #else
 	context.getMetadata().addMD(dbg_mdkind, loc.getNode(), insn);
 #endif
@@ -6460,15 +6461,18 @@
 			    nilVal, "");
 		new StoreInst(val, proc_gvar, bb);
 
-		char buf[100];
-		const char *p = GetFirstType(type + 1, buf, sizeof(buf));
+		const size_t buf_len = strlen(type + 1) + 1;
+		assert(buf_len > 1);
+		char *buf = (char *)malloc(buf_len);
+
+		const char *p = GetFirstType(type + 1, buf, buf_len);
 		const Type *ret_type = convert_type(buf);
 		int argc = 0;
 
 		std::vector<std::string> arg_ctypes;
 		std::vector<const Type *> arg_types;
 		while (*p != _C_FPTR_E) {
-		    p = GetFirstType(p, buf, sizeof(buf));
+		    p = GetFirstType(p, buf, buf_len);
 		    arg_ctypes.push_back(std::string(buf));
 		    arg_types.push_back(convert_type(buf));
 		    argc++;
@@ -6524,7 +6528,7 @@
 		Value *ret_val = compile_protected_call(proc_call_f, params);
 
 		if (ret_type != VoidTy) {
-		    GetFirstType(type + 1, buf, sizeof(buf));
+		    GetFirstType(type + 1, buf, buf_len);
 		    ret_val = compile_conversion_to_c(buf, ret_val,
 			new AllocaInst(ret_type, "", bb));
 		    ReturnInst::Create(context, ret_val, bb);
@@ -6532,10 +6536,10 @@
 		else {
 		    ReturnInst::Create(context, bb);
 		}
+
 		bb = oldbb;
-		Value *ret = new BitCastInst(f, PtrTy, "", bb);
-
-		return ret;
+		free(buf);
+		return new BitCastInst(f, PtrTy, "", bb);
 	    }
 	    break;
 
@@ -7043,9 +7047,12 @@
     std::vector<const Type *> f_types;
     std::vector<Value *> params;
 
+    const size_t buf_len = strlen(types) + 1;
+    assert(buf_len > 1);
+    char *buf = (char *)malloc(buf_len);
+
     // retval
-    char buf[100];
-    const char *p = GetFirstType(types, buf, sizeof buf);
+    const char *p = GetFirstType(types, buf, buf_len);
     const Type *ret_type = convert_type(buf);
 
     Value *sret = NULL;
@@ -7083,7 +7090,7 @@
     std::vector<unsigned int> byval_args;
     int given_argc = 0;
     bool stop_arg_type = false;
-    while ((p = GetFirstType(p, buf, sizeof buf)) != NULL && buf[0] != '\0') {
+    while ((p = GetFirstType(p, buf, buf_len)) != NULL && buf[0] != '\0') {
 	if (variadic && given_argc == min_argc) {
 	    stop_arg_type = true;
 	}
@@ -7139,7 +7146,7 @@
 	retval = imp_call;
     }
 
-    GetFirstType(types, buf, sizeof buf);
+    GetFirstType(types, buf, buf_len);
     ret_type = convert_type(buf);
     if (self_arg != NULL && ret_type == VoidTy) {
 	// If we are calling an Objective-C method that returns void, let's
@@ -7151,6 +7158,8 @@
     }
     ReturnInst::Create(context, retval, bb);
 
+    free(buf);
+
     return f;
 }
 
@@ -7340,7 +7349,10 @@
 {
     assert(ruby_func != NULL || ruby_imp != NULL);
 
-    char buf[100];
+    const size_t buf_len = strlen(types) + 1;
+    assert(buf_len > 1);
+    char *buf = (char *)malloc(buf_len);
+
     const char *p = types;
     std::vector<const Type *> f_types;
 
@@ -7349,7 +7361,7 @@
 #endif
 
     // Return value.
-    p = GetFirstType(p, buf, sizeof buf);
+    p = GetFirstType(p, buf, buf_len);
     std::string ret_type(buf);
     const Type *f_ret_type = convert_type(buf);
     const Type *f_sret_type = NULL;
@@ -7380,7 +7392,7 @@
     std::vector<std::string> arg_types;
     std::vector<unsigned int> byval_args;
     for (int i = 0; i < arity.real; i++) {
-	p = GetFirstType(p, buf, sizeof buf);
+	p = GetFirstType(p, buf, buf_len);
 	const Type *t = convert_type(buf);
 	bool enough_registers = true;
 #if __LP64__
@@ -7492,7 +7504,8 @@
     if (ruby2ocExcHandlerFunc == NULL) {
 	// void rb_rb2oc_exc_handler(void);
 	ruby2ocExcHandlerFunc = cast<Function>(
-		module->getOrInsertFunction("rb_rb2oc_exc_handler", VoidTy, NULL));
+		module->getOrInsertFunction("rb_rb2oc_exc_handler", VoidTy,
+		    NULL));
     }
     CallInst::Create(ruby2ocExcHandlerFunc, "", bb);
 
@@ -7502,6 +7515,8 @@
     rescue_invoke_bb = old_rescue_invoke_bb;
 #endif
 
+    free(buf);
+
     return f;
 }
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100510/4b3ef9ff/attachment.html>


More information about the macruby-changes mailing list