Watson1978
9/17/2011 - 8:46 AM

Indeed .bundle from .so in MacRuby

Indeed .bundle from .so in MacRuby

diff --git a/load.c b/load.c
index 06ca712..92ae5d7 100644
--- a/load.c
+++ b/load.c
@@ -267,6 +267,21 @@ rb_require_safe(VALUE fname, int safe)
 {
     FilePathValue(fname);
 
+    char *p = strrchr(RSTRING_PTR(fname), '.');
+    if (p != NULL && strcmp(p + 1, "so") == 0) {
+	const char *ext = "bundle";
+	const long ext_len = strlen(ext);
+	const long len = p - RSTRING_PTR(fname);
+
+	if (PATH_MAX > len + ext_len + 1) {
+	    char buf[PATH_MAX];
+	    strncpy(buf, RSTRING_PTR(fname), PATH_MAX);
+	    strcpy(buf + len + 1, ext);
+	    buf[PATH_MAX - 1] = '\0';
+	    fname = rb_str_new2(buf);
+	}
+    }
+
     // Immediately, check out if we have an AOT feature for this.
     if (rb_vm_aot_feature_load(RSTRING_PTR(fname))) {
 	rb_provide_feature(fname);