[macruby-changes] [675] MacRuby/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Sat Oct 25 19:00:15 PDT 2008
Revision: 675
http://trac.macosforge.org/projects/ruby/changeset/675
Author: lsansonetti at apple.com
Date: 2008-10-25 19:00:15 -0700 (Sat, 25 Oct 2008)
Log Message:
-----------
merging macruby64 branch into trunk
Modified Paths:
--------------
MacRuby/trunk/Rakefile
MacRuby/trunk/bs.c
MacRuby/trunk/class.c
MacRuby/trunk/encoding.c
MacRuby/trunk/gc.c
MacRuby/trunk/include/MacRuby.h
MacRuby/trunk/include/ruby/config.h.in
MacRuby/trunk/include/ruby/defines.h
MacRuby/trunk/include/ruby/ruby.h
MacRuby/trunk/lib/hotcocoa/application_builder.rb
MacRuby/trunk/marshal.c
MacRuby/trunk/misc/xcode-templates/Project Templates/Application/MacRuby Application/MacRubyApp.xcodeproj/project.pbxproj
MacRuby/trunk/objc.m
MacRuby/trunk/object.c
MacRuby/trunk/regexec.c
MacRuby/trunk/sample-macruby/ABPresence/ABPresence.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/AnimatingViews/AnimatingViews.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/CircleView/CircleView.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/DotView/DotView.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/EmbeddedMacRuby/EmbeddedMacRuby.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemo.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/OutlineView/OutlineView.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/PagePacker/PagePacker.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/PathDemo/PathDemo.xcodeproj/project.pbxproj
MacRuby/trunk/sample-macruby/ViewModelDemo/ViewModelDemo.xcodeproj/project.pbxproj
MacRuby/trunk/test/ruby/test_objc.rb
MacRuby/trunk/thread.c
MacRuby/trunk/variable.c
MacRuby/trunk/version.c
MacRuby/trunk/version.h
MacRuby/trunk/vm.h
MacRuby/trunk/vm_insnhelper.c
Modified: MacRuby/trunk/Rakefile
===================================================================
--- MacRuby/trunk/Rakefile 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/Rakefile 2008-10-26 02:00:15 UTC (rev 675)
@@ -1,4 +1,6 @@
# User customizable variables.
+# These variables can be set from the command line. Example:
+# $ rake build_as_embeddable=true
def do_option(name, default)
val = ENV[name]
@@ -15,7 +17,7 @@
RUBY_INSTALL_NAME = do_option('ruby_install_name', 'macruby')
RUBY_SO_NAME = do_option('ruby_so_name', RUBY_INSTALL_NAME)
-ARCHS = do_option('archs', %w{ppc i386}) { |x| x.split(',') }
+ARCHS = do_option('archs', `arch`.include?('ppc') ? 'ppc' : %w{i386 x86_64}) { |x| x.split(',') }
FRAMEWORK_NAME = do_option('framework_name', 'MacRuby')
FRAMEWORK_INSTDIR = do_option('framework_instdir', '/Library/Frameworks')
NO_WARN_BUILD = !do_option('allow_build_warnings', false)
@@ -25,8 +27,17 @@
# TODO: we should find a way to document these options in rake's --help
-# Everything below this comment should *not* be customized.
+# Everything below this comment should *not* be modified.
+if `sw_vers -productVersion`.strip.to_f < 10.5
+ $stderr.puts "Sorry, your environment is not supported. MacRuby requires Mac OS X 10.5 or higher."
+ exit 1
+end
+
+if `arch`.include?('ppc')
+ $stderr.puts "Warning: your appear to use a PowerPC machine. MacRuby's PPC support is very basic and may be dropped in a near future. Supported architectures are Intel 32-bit and 64-bit (i386 and x86_64)."
+end
+
version_h = File.read('version.h')
NEW_RUBY_VERSION = version_h.scan(/#\s*define\s+RUBY_VERSION\s+\"([^"]+)\"/)[0][0]
MACRUBY_VERSION = version_h.scan(/#\s*define\s+MACRUBY_VERSION\s+(.*)/)[0][0]
@@ -512,7 +523,7 @@
desc "Build MacRuby"
task :build => :dylib do
- $builder.link_executable(RUBY_INSTALL_NAME, ['main', 'gc-stub'], "-L. -l#{RUBY_SO_NAME}")
+ $builder.link_executable(RUBY_INSTALL_NAME, ['main', 'gc-stub'], "-L. -l#{RUBY_SO_NAME} -lobjc")
end
end
Modified: MacRuby/trunk/bs.c
===================================================================
--- MacRuby/trunk/bs.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/bs.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -252,7 +252,7 @@
p_src = pos + 1;
pos = strchr(p_src, '"');
if (pos == NULL) {
- fprintf(stderr, "Can't find the end of field delimiter starting at %d\n", p_src - src);
+ fprintf(stderr, "Can't find the end of field delimiter starting at %d\n", (int)(p_src - src));
goto bails;
}
if (field != NULL) {
@@ -307,7 +307,7 @@
}
if (ok == false) {
- fprintf(stderr, "Can't find the field encoding starting at %d\n", p_src - src);
+ fprintf(stderr, "Can't find the field encoding starting at %d\n", (int)(p_src - src));
goto bails;
}
Modified: MacRuby/trunk/class.c
===================================================================
--- MacRuby/trunk/class.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/class.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -153,7 +153,7 @@
version_flag |= RCLASS_IS_OBJECT_SUBCLASS;
}
- class_setVersion(ocklass, version_flag);
+ RCLASS_SET_VERSION(ocklass, version_flag);
DLOG("DEFC", "%s < %s (version=%d)", ocname, class_getName(class_getSuperclass((Class)ocklass)), version_flag);
@@ -230,13 +230,14 @@
else {
super = RCLASS_SUPER(orig);
}
- RCLASS_SUPER(clone) = super;
+ RCLASS_SET_SUPER(clone, super);
version_flag = RCLASS_IS_RUBY_CLASS;
- if ((RCLASS_VERSION(super) & RCLASS_IS_OBJECT_SUBCLASS) == RCLASS_IS_OBJECT_SUBCLASS)
+ if ((RCLASS_VERSION(super) & RCLASS_IS_OBJECT_SUBCLASS) == RCLASS_IS_OBJECT_SUBCLASS) {
version_flag |= RCLASS_IS_OBJECT_SUBCLASS;
+ }
- class_setVersion((Class)clone, version_flag);
+ RCLASS_SET_VERSION(clone, version_flag);
}
#if 0 // TODO
if (RCLASS_IV_TBL(orig)) {
@@ -315,7 +316,8 @@
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
if (RCLASS_SUPER(clone) == rb_cNSObject) {
- RCLASS_VERSION(clone) ^= RCLASS_IS_OBJECT_SUBCLASS;
+ long v = RCLASS_VERSION(clone) ^ RCLASS_IS_OBJECT_SUBCLASS;
+ RCLASS_SET_VERSION(clone, v);
}
RCLASS_SET_VERSION_FLAG(clone, RCLASS_IS_SINGLETON);
@@ -347,7 +349,8 @@
klass = rb_class_boot(super);
RBASIC(obj)->klass = klass;
if (super == rb_cNSObject) {
- RCLASS_VERSION(klass) ^= RCLASS_IS_OBJECT_SUBCLASS;
+ long v = RCLASS_VERSION(klass) ^ RCLASS_IS_OBJECT_SUBCLASS;
+ RCLASS_SET_VERSION(klass, v);
}
RCLASS_SET_VERSION_FLAG(klass, RCLASS_IS_SINGLETON);
@@ -498,18 +501,18 @@
}
void
-rb_include_module(VALUE klass, VALUE module)
+rb_include_module2(VALUE klass, VALUE module, int check, int add_methods)
{
- Method *methods;
- unsigned int i, methods_count;
VALUE ary;
- rb_frozen_class_p(klass);
+ if (check) {
+ rb_frozen_class_p(klass);
- if (!OBJ_TAINTED(klass))
- rb_secure(4);
+ if (!OBJ_TAINTED(klass))
+ rb_secure(4);
- Check_Type(module, T_MODULE);
+ Check_Type(module, T_MODULE);
+ }
ary = rb_attr_get(klass, idIncludedModules);
if (ary == Qnil) {
@@ -520,6 +523,9 @@
return;
rb_ary_insert(ary, 0, module);
+ long v = RCLASS_VERSION(module) | RCLASS_IS_INCLUDED;
+ RCLASS_SET_VERSION(module, v);
+
ary = rb_attr_get(module, idIncludedInClasses);
if (ary == Qnil) {
ary = rb_ary_new();
@@ -529,27 +535,39 @@
DLOG("INCM", "%s <- %s", class_getName((Class)klass), class_getName((Class)module));
- methods = class_copyMethodList((Class)module, &methods_count);
- if (methods != NULL) {
- for (i = 0; i < methods_count; i++) {
- Method method = methods[i], method2;
- DLOG("DEFI", "-[%s %s]", class_getName((Class)klass), (char *)method_getName(method));
-
- method2 = class_getInstanceMethod((Class)klass, method_getName(method));
- if (method2 != NULL && method2 != class_getInstanceMethod((Class)RCLASS_SUPER(klass), method_getName(method))) {
- method_setImplementation(method2, method_getImplementation(method));
+ if (add_methods) {
+ Method *methods;
+ unsigned int i, methods_count;
+
+ methods = class_copyMethodList((Class)module, &methods_count);
+ if (methods != NULL) {
+ for (i = 0; i < methods_count; i++) {
+ Method method = methods[i], method2;
+ DLOG("DEFI", "-[%s %s]", class_getName((Class)klass), (char *)method_getName(method));
+
+ method2 = class_getInstanceMethod((Class)klass, method_getName(method));
+ if (method2 != NULL && method2 != class_getInstanceMethod((Class)RCLASS_SUPER(klass), method_getName(method))) {
+ method_setImplementation(method2, method_getImplementation(method));
+ }
+ else {
+ assert(class_addMethod((Class)klass,
+ method_getName(method),
+ method_getImplementation(method),
+ method_getTypeEncoding(method)));
+ }
}
- else {
- assert(class_addMethod((Class)klass,
- method_getName(method),
- method_getImplementation(method),
- method_getTypeEncoding(method)));
- }
+ free(methods);
}
- free(methods);
}
}
+void
+rb_include_module(VALUE klass, VALUE module)
+{
+ rb_include_module2(klass, module, 1, 1);
+}
+
+
/*
* call-seq:
* mod.included_modules -> array
@@ -673,31 +691,31 @@
}
static int
-ins_methods_i(VALUE name, long type, VALUE ary)
+ins_methods_i(VALUE name, ID type, VALUE ary)
{
return ins_methods_push(name, type, ary, -1); /* everything but private */
}
static int
-ins_methods_prot_i(VALUE name, long type, VALUE ary)
+ins_methods_prot_i(VALUE name, ID type, VALUE ary)
{
return ins_methods_push(name, type, ary, NOEX_PROTECTED);
}
static int
-ins_methods_priv_i(VALUE name, long type, VALUE ary)
+ins_methods_priv_i(VALUE name, ID type, VALUE ary)
{
return ins_methods_push(name, type, ary, NOEX_PRIVATE);
}
static int
-ins_methods_pub_i(VALUE name, long type, VALUE ary)
+ins_methods_pub_i(VALUE name, ID type, VALUE ary)
{
return ins_methods_push(name, type, ary, NOEX_PUBLIC);
}
static void
-rb_objc_push_methods(VALUE ary, VALUE mod, VALUE objc_methods, int (*func) (VALUE, long, VALUE))
+rb_objc_push_methods(VALUE ary, VALUE mod, VALUE objc_methods, int (*func) (VALUE, ID, VALUE))
{
Method *methods;
unsigned int i, count;
@@ -798,7 +816,7 @@
}
static VALUE
-class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, long, VALUE))
+class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (VALUE, ID, VALUE))
{
VALUE ary;
VALUE recur, objc_methods;
Modified: MacRuby/trunk/encoding.c
===================================================================
--- MacRuby/trunk/encoding.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/encoding.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -68,7 +68,7 @@
}
rb_define_const(rb_cEncoding, name, encoding);
}
- CFDictionarySetValue(__encodings, (const void *)(*e),
+ CFDictionarySetValue(__encodings, (const void *)iana,
(const void *)encoding);
e++;
}
@@ -79,10 +79,12 @@
static VALUE
enc_make(const CFStringEncoding *enc)
{
- VALUE v;
+ VALUE iana, v;
+
assert(enc != NULL);
- v = (VALUE)CFDictionaryGetValue( (CFDictionaryRef)__encodings,
- (const void *)(*enc));
+ iana = (VALUE)CFStringConvertEncodingToIANACharSetName(*enc);
+ v = (VALUE)CFDictionaryGetValue((CFDictionaryRef)__encodings,
+ (const void *)iana);
assert(v != 0);
return v;
}
Modified: MacRuby/trunk/gc.c
===================================================================
--- MacRuby/trunk/gc.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/gc.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -1231,7 +1231,8 @@
static void
rb_obj_imp_finalize(void *obj, SEL sel)
{
- const bool need_protection = GET_THREAD()->thread_id != pthread_self();
+ const bool need_protection =
+ GET_THREAD()->thread_id != pthread_self();
bool call_finalize, free_ivar;
if (NATIVE((VALUE)obj)) {
@@ -1263,6 +1264,8 @@
}
}
+static bool gc_disabled = false;
+
void
Init_PreGC(void)
{
@@ -1276,9 +1279,13 @@
control = auto_collection_parameters(__auto_zone);
control->scan_external_callout =
rb_objc_scan_external_callout;
- if (getenv("GC_DEBUG"))
+ if (getenv("GC_DEBUG")) {
control->log = AUTO_LOG_COLLECTIONS | AUTO_LOG_REGIONS
| AUTO_LOG_UNUSUAL | AUTO_LOG_COLLECT_DECISION;
+ }
+ if (getenv("GC_DISABLE")) {
+ gc_disabled = true;
+ }
Method m = class_getInstanceMethod((Class)objc_getClass("NSObject"), sel_registerName("finalize"));
assert(m != NULL);
@@ -1290,8 +1297,10 @@
void
Init_PostGC(void)
{
- objc_startCollectorThread();
- auto_collector_reenable(__auto_zone);
+ if (!gc_disabled) {
+ objc_startCollectorThread();
+ auto_collector_reenable(__auto_zone);
+ }
}
void
@@ -1320,7 +1329,7 @@
rb_global_variable(&nomem_error);
nomem_error = rb_exc_new2(rb_eNoMemError, "failed to allocate memory");
- rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
+ //rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
Modified: MacRuby/trunk/include/MacRuby.h
===================================================================
--- MacRuby/trunk/include/MacRuby.h 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/include/MacRuby.h 2008-10-26 02:00:15 UTC (rev 675)
@@ -1,2 +1,3 @@
#define RUBY_INCLUDED_AS_FRAMEWORK 1
+#include <Foundation/Foundation.h>
#include "ruby/ruby.h"
Modified: MacRuby/trunk/include/ruby/config.h.in
===================================================================
--- MacRuby/trunk/include/ruby/config.h.in 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/include/ruby/config.h.in 2008-10-26 02:00:15 UTC (rev 675)
@@ -21,16 +21,32 @@
#define _TANDEM_SOURCE 1
#define HAVE_LONG_LONG 1
#define HAVE_OFF_T 1
+#define SIZEOF___INT64 0
+#if defined(__LP64__)
#define SIZEOF_INT 4
#define SIZEOF_SHORT 2
+#define SIZEOF_LONG 8
+#define SIZEOF_LONG_LONG 8
+#define SIZEOF_OFF_T 8
+#define SIZEOF_VOIDP 8
+#define SIZEOF_FLOAT 4
+#define SIZEOF_DOUBLE 8
+#define SIZEOF_TIME_T 8
+#define SIZEOF_RLIM_T 8
+#define SIZEOF_SIZE_T 8
+#else
+#define SIZEOF_INT 4
+#define SIZEOF_SHORT 2
#define SIZEOF_LONG 4
#define SIZEOF_LONG_LONG 8
-#define SIZEOF___INT64 0
#define SIZEOF_OFF_T 8
#define SIZEOF_VOIDP 4
#define SIZEOF_FLOAT 4
#define SIZEOF_DOUBLE 8
#define SIZEOF_TIME_T 4
+#define SIZEOF_RLIM_T 8
+#define SIZEOF_SIZE_T 4
+#endif
#define rb_pid_t pid_t
#define PIDT2NUM(v) LONG2NUM(v)
#define NUM2PIDT(v) NUM2LONG(v)
@@ -77,8 +93,6 @@
#define HAVE_LANGINFO_H 1
#define HAVE_LOCALE_H 1
#define HAVE_TIME_H 1
-#define SIZEOF_RLIM_T 8
-#define SIZEOF_SIZE_T 4
#define HAVE_STRUCT_STAT_ST_BLKSIZE 1
#define HAVE_ST_BLKSIZE 1
#define HAVE_STRUCT_STAT_ST_BLOCKS 1
Modified: MacRuby/trunk/include/ruby/defines.h
===================================================================
--- MacRuby/trunk/include/ruby/defines.h 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/include/ruby/defines.h 2008-10-26 02:00:15 UTC (rev 675)
@@ -295,7 +295,17 @@
# define ASSERT_NO_OBJC() (assert(1 == 0))
void rb_objc_wb(void *dst, void *newval);
void rb_objc_root(void *addr);
-# define GC_WB(dst, newval) (SPECIAL_CONST_P(newval) ? *(void **)dst = (void *)newval : rb_objc_wb((void *)dst, (void *)newval))
+# define GC_WB(dst, newval) \
+ do { \
+ void *nv = (void *)newval; \
+ if (SPECIAL_CONST_P(nv)) { \
+ *(void **)dst = nv; \
+ } \
+ else { \
+ rb_objc_wb((void *)dst, (void *)newval); \
+ } \
+ } \
+ while (0)
# define GC_ROOT(dst) (rb_objc_root((void *)dst))
# define GC_WEAK(dst) (rb_objc_weak((void *)dst))
#else
Modified: MacRuby/trunk/include/ruby/ruby.h
===================================================================
--- MacRuby/trunk/include/ruby/ruby.h 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/include/ruby/ruby.h 2008-10-26 02:00:15 UTC (rev 675)
@@ -92,7 +92,11 @@
#if SIZEOF_LONG == SIZEOF_VOIDP
typedef unsigned long VALUE;
+#if WITH_OBJC
+#define ID unsigned long
+#else
typedef unsigned long ID;
+#endif
# define SIGNED_VALUE long
# define SIZEOF_VALUE SIZEOF_LONG
# define PRIdVALUE "ld"
@@ -505,15 +509,20 @@
# define RCLASS_IS_STRING_SUBCLASS 0x10000 /* class is a subclass of NSCFString */
# define RCLASS_IS_ARRAY_SUBCLASS 0x20000 /* class is a subclass of NSCFArray */
# define RCLASS_IS_HASH_SUBCLASS 0x40000 /* class is a subclass of NSCFDictionary */
-# if __OBJC2__
+# define RCLASS_IS_INCLUDED 0x80000 /* module is included */
+# if defined(__LP64__)
# define RCLASS_VERSION(m) (class_getVersion((Class)m))
+# define RCLASS_SET_VERSION(m,f) (class_setVersion((Class)m, f))
# define RCLASS_SET_VERSION_FLAG(m,f) (class_setVersion((Class)m, (RCLASS_VERSION(m) | f)))
-# define RCLASS_SUPER(m) (class_getSuperclass((Class)m))
-# define RCLASS_META(m) (class_isMetaclass((Class)m))
+# define RCLASS_SUPER(m) (*(VALUE *)((void *)m + (sizeof(void *) * 1)))
+# define RCLASS_SET_SUPER(m, s) (class_setSuperclass((Class)m, (Class)s))
+# define RCLASS_META(m) (class_isMetaClass((Class)m))
# else
# define RCLASS_VERSION(m) (*(long *)((void *)m + (sizeof(void *) * 3)))
+# define RCLASS_SET_VERSION(m,f) do { RCLASS_VERSION(m) = f; } while (0)
# define RCLASS_SET_VERSION_FLAG(m,f) (RCLASS_VERSION(m) |= f)
# define RCLASS_SUPER(m) (*(VALUE *)((void *)m + (sizeof(void *) * 1)))
+# define RCLASS_SET_SUPER(m, s) (RCLASS_SUPER(m) = s)
# define _RCLASS_INFO(m) (*(long *)((void *)m + (sizeof(void *) * 4)))
# define RCLASS_META(m) (_RCLASS_INFO(m) & CLS_META)
# endif
@@ -816,7 +825,7 @@
#define FL_REVERSE(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags ^= (f);} while (0)
#if WITH_OBJC
-# define OBJ_TAINTED(x) (SPECIAL_CONST_P(x) || NATIVE(x) ? rb_obj_tainted((VALUE)x) : FL_TEST((x), FL_TAINT))
+# define OBJ_TAINTED(x) (int)(SPECIAL_CONST_P(x) || NATIVE(x) ? rb_obj_tainted((VALUE)x) == Qtrue : FL_TEST((x), FL_TAINT))
# define OBJ_TAINT(x) (rb_obj_taint((VALUE)x))
#else
# define OBJ_TAINTED(x) FL_TEST((x), FL_TAINT)
@@ -826,7 +835,7 @@
#define OBJ_INFECT(x,s) do {if (FL_ABLE(x) && FL_ABLE(s)) RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT;} while (0)
#if WITH_OBJC
-# define OBJ_FROZEN(x) (SPECIAL_CONST_P(x) || NATIVE(x) ? rb_obj_frozen_p((VALUE)x) : FL_TEST((x), FL_FREEZE))
+# define OBJ_FROZEN(x) (int)(SPECIAL_CONST_P(x) || NATIVE(x) ? rb_obj_frozen_p((VALUE)x) == Qtrue : FL_TEST((x), FL_FREEZE))
# define OBJ_FREEZE(x) (rb_obj_freeze((VALUE)x))
#else
# define OBJ_FROZEN(x) FL_TEST((x), FL_FREEZE)
Modified: MacRuby/trunk/lib/hotcocoa/application_builder.rb
===================================================================
--- MacRuby/trunk/lib/hotcocoa/application_builder.rb 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/lib/hotcocoa/application_builder.rb 2008-10-26 02:00:15 UTC (rev 675)
@@ -176,7 +176,8 @@
}
}
end
- puts `cd "#{macos_root}" && gcc main.m -o #{name.gsub(/ /, '')} -arch ppc -arch i386 -framework MacRuby -framework Foundation -fobjc-gc-only`
+ archs = RUBY_ARCH.include?('ppc') ? '-arch ppc' : '-arch i386 -arch x86_64'
+ puts `cd "#{macos_root}" && gcc main.m -o #{name.gsub(/ /, '')} #{archs} -framework MacRuby -framework Foundation -fobjc-gc-only`
File.unlink(objective_c_source_file)
end
@@ -232,4 +233,4 @@
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/marshal.c
===================================================================
--- MacRuby/trunk/marshal.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/marshal.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -1095,7 +1095,7 @@
ID id;
long num = r_long(arg);
- if (st_lookup(arg->symbols, num, &id)) {
+ if (st_lookup(arg->symbols, num, (st_data_t *)&id)) {
return id;
}
rb_raise(rb_eArgError, "bad symbol");
Modified: MacRuby/trunk/misc/xcode-templates/Project Templates/Application/MacRuby Application/MacRubyApp.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/misc/xcode-templates/Project Templates/Application/MacRuby Application/MacRubyApp.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/misc/xcode-templates/Project Templates/Application/MacRuby Application/MacRubyApp.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -231,6 +231,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -242,6 +243,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/objc.m
===================================================================
--- MacRuby/trunk/objc.m 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/objc.m 2008-10-26 02:00:15 UTC (rev 675)
@@ -26,6 +26,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <Foundation/Foundation.h>
#include "ruby/ruby.h"
#include "ruby/node.h"
#include "ruby/encoding.h"
@@ -33,7 +34,7 @@
#include <unistd.h>
#include <dlfcn.h>
#include <mach-o/dyld.h>
-#include <Foundation/Foundation.h>
+#include <sys/mman.h>
#if HAVE_BRIDGESUPPORT_FRAMEWORK
# include <BridgeSupport/BridgeSupport.h>
#else
@@ -43,6 +44,11 @@
#include "vm.h"
#include "eval_intern.h"
+void native_mutex_lock(pthread_mutex_t *lock);
+void native_mutex_unlock(pthread_mutex_t *lock);
+rb_thread_t *rb_thread_wrap_existing_native_thread(rb_thread_id_t id);
+extern VALUE rb_cMutex;
+
typedef struct {
bs_element_type_t type;
void *value;
@@ -69,29 +75,14 @@
static struct st_table *bs_inf_prot_imethods;
static struct st_table *bs_cftypes;
-#if 0
-static char *
-rb_objc_sel_to_mid(SEL selector, char *buffer, unsigned buffer_len)
+VALUE rb_cPointer;
+
+struct RPointer
{
- size_t s;
- char *p;
+ void *ptr;
+ const char *type;
+};
- s = strlcpy(buffer, (const char *)selector, buffer_len);
-
- p = buffer + s - 1;
- if (*p == ':')
- *p = '\0';
-
- p = buffer;
- while ((p = strchr(p, ':')) != NULL) {
- *p = '_';
- p++;
- }
-
- return buffer;
-}
-#endif
-
static inline const char *
rb_objc_skip_octype_modifiers(const char *octype)
{
@@ -367,7 +358,7 @@
bs_boxed->ffi_type->alignment = 0;
bs_boxed->ffi_type->type = FFI_TYPE_STRUCT;
bs_boxed->ffi_type->elements = malloc(
- (bs_struct->fields_count) * sizeof(ffi_type *));
+ (bs_struct->fields_count + 1) * sizeof(ffi_type *));
for (i = 0; i < bs_struct->fields_count; i++) {
bs_element_struct_field_t *field = &bs_struct->fields[i];
@@ -513,14 +504,6 @@
return n;
}
-VALUE rb_cPointer;
-
-struct RPointer
-{
- void *ptr;
- const char *type;
-};
-
static VALUE
rb_pointer_create(void *ptr, const char *type)
{
@@ -536,6 +519,25 @@
static void rb_objc_rval_to_ocval(VALUE, const char *, void **);
static VALUE
+rb_pointer_new_with_type(VALUE recv, VALUE type)
+{
+ const char *ctype;
+ ffi_type *ffitype;
+ struct RPointer *data;
+
+ Check_Type(type, T_STRING);
+ ctype = RSTRING_PTR(type);
+ ffitype = rb_objc_octype_to_ffitype(ctype);
+
+ data = (struct RPointer *)xmalloc(sizeof(struct RPointer ));
+ GC_WB(&data->ptr, xmalloc(ffitype->size));
+ GC_WB(&data->type, xmalloc(strlen(ctype) + 1));
+ strcpy((char *)data->type, ctype);
+
+ return Data_Wrap_Struct(rb_cPointer, NULL, NULL, data);
+}
+
+static VALUE
rb_pointer_assign(VALUE recv, VALUE val)
{
struct RPointer *data;
@@ -714,14 +716,18 @@
}
break;
default:
- if (strcmp(octype, "^v") == 0) {
- if (SPECIAL_CONST_P(rval)) {
- ok = false;
- }
- else {
- *(void **)ocval = (void *)rval;
- }
+ if (SPECIAL_CONST_P(rval)) {
+ ok = false;
}
+ else if (*(VALUE *)rval == rb_cPointer) {
+ struct RPointer *data;
+
+ Data_Get_Struct(rval, struct RPointer, data);
+ *(void **)ocval = data->ptr;
+ }
+ else if (strcmp(octype, "^v") == 0) {
+ *(void **)ocval = (void *)rval;
+ }
else if (st_lookup(bs_boxeds, (st_data_t)octype + 1,
(st_data_t *)&bs_boxed)) {
*(void **)ocval = xmalloc(bs_boxed->ffi_type->size);
@@ -1167,14 +1173,25 @@
argc, count - 2);
}
+#define UNLOCK_GIL() \
+ do { if (rb_cMutex != 0) { native_mutex_unlock(&GET_THREAD()->vm->global_interpreter_lock); }; } while (0)
+#define LOCK_GIL() \
+ do { if (rb_cMutex != 0) { native_mutex_lock(&GET_THREAD()->vm->global_interpreter_lock); }; } while (0)
+
if (count == 2) {
if (sig->types[0] == '@' || sig->types[0] == '#' || sig->types[0] == 'v') {
/* Easy case! */
+ id exception = nil;
+ //UNLOCK_GIL();
@try {
if (klass == RCLASS_SUPER(*(Class *)ocrcv)) {
struct objc_super s;
s.receiver = ocrcv;
+#if defined(__LP64__)
+ s.super_class = (Class)klass;
+#else
s.class = (Class)klass;
+#endif
ffi_ret = objc_msgSendSuper(&s, sel);
}
else {
@@ -1182,8 +1199,12 @@
}
}
@catch (id e) {
- rb_objc_exc_raise(e);
+ exception = e;
}
+ //LOCK_GIL();
+ if (exception != nil) {
+ rb_objc_exc_raise(exception);
+ }
if (sig->types[0] == '@' || sig->types[0] == '#') {
VALUE retval;
buf[0] = sig->types[0];
@@ -1397,7 +1418,8 @@
name_sel = sel_registerName(name_str);
def_sel = sel_registerName(def_str);
- included_in_classes = RCLASS_MODULE(klass) ? rb_attr_get(klass, idIncludedInClasses) : Qnil;
+ included_in_classes = RCLASS_VERSION(klass) & RCLASS_IS_INCLUDED
+ ? rb_attr_get(klass, idIncludedInClasses) : Qnil;
method = class_getInstanceMethod((Class)klass, def_sel);
if (method == NULL) {
@@ -1472,7 +1494,9 @@
redo = true;
goto alias_method;
}
- }
+ }
+
+#undef forward_method_definition
}
static VALUE
@@ -1541,8 +1565,8 @@
NODE *body, *node;
bs_element_method_t *bs_method;
- rcv = (*(id **)args)[0];
- sel = (*(SEL **)args)[1];
+ rcv = *(id *)args[0];
+ sel = *(SEL *)args[1];
body = (NODE *)userdata;
node = body->nd_body;
@@ -1595,8 +1619,6 @@
ctx.args = args;
ctx.userdata = userdata;
- extern VALUE rb_cMutex;
-
if (rb_cMutex == 0) {
/* GL not initialized yet! */
rb_ruby_to_objc_closure_handler_main(&ctx);
@@ -1607,8 +1629,6 @@
}
else {
rb_thread_t *rb_thread_wrap_existing_native_thread(rb_thread_id_t id);
- void native_mutex_lock(pthread_mutex_t *lock);
- void native_mutex_unlock(pthread_mutex_t *lock);
rb_thread_t *th, *old;
@@ -1647,14 +1667,30 @@
}
cif = (ffi_cif *)malloc(sizeof(ffi_cif));
- if (ffi_prep_cif(cif, FFI_DEFAULT_ABI, arity + 2, ret, args) != FFI_OK)
+ if (ffi_prep_cif(cif, FFI_DEFAULT_ABI, arity + 2, ret, args) != FFI_OK) {
rb_fatal("can't prepare ruby to objc cif");
-
+ }
+
closure = (ffi_closure *)malloc(sizeof(ffi_closure));
+
+ /* XXX mmap() and mprotect() are 2 expensive calls, maybe we should try to
+ * mmap() and mprotect() a large memory page and reuse it for closures?
+ */
+
+ if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0)) == (void *)-1) {
+ rb_fatal("can't allocate ruby to objc closure");
+ }
+
if (ffi_prep_closure(closure, cif, rb_ruby_to_objc_closure_handler, node)
- != FFI_OK)
+ != FFI_OK) {
rb_fatal("can't prepare ruby to objc closure");
+ }
+ if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1) {
+ rb_fatal("can't mprotect the ruby to objc closure");
+ }
+
rb_objc_retain(node);
return closure;
@@ -1807,7 +1843,8 @@
}
}
- included_in_classes = RCLASS_MODULE(mod) ? rb_attr_get(mod, idIncludedInClasses) : Qnil;
+ included_in_classes = RCLASS_VERSION(mod) & RCLASS_IS_INCLUDED
+ ? rb_attr_get(mod, idIncludedInClasses) : Qnil;
direct_override = false;
method = class_getInstanceMethod((Class)mod, sel);
@@ -2237,8 +2274,8 @@
{
struct rb_struct_accessor_context *ctx;
VALUE recv, *data;
-
- recv = (*(VALUE **)args)[0];
+
+ recv = *(VALUE *)args[0];
Data_Get_Struct(recv, VALUE, data);
assert(data != NULL);
@@ -2255,8 +2292,8 @@
size_t fdata_size;
void *fdata;
- recv = (*(VALUE **)args)[0];
- value = (*(VALUE **)args)[1];
+ recv = *(VALUE *)args[0];
+ value = *(VALUE *)args[1];
Data_Get_Struct(recv, VALUE, data);
assert(data != NULL);
@@ -2292,14 +2329,21 @@
args = (ffi_type **)malloc(sizeof(ffi_type *) * 1);
args[0] = &ffi_type_pointer;
if (ffi_prep_cif(struct_reader_cif, FFI_DEFAULT_ABI, 1,
- &ffi_type_pointer, args) != FFI_OK)
+ &ffi_type_pointer, args) != FFI_OK) {
rb_fatal("can't prepare struct_reader_cif");
+ }
}
- closure = (ffi_closure *)malloc(sizeof(ffi_closure));
+ if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0)) == (void *)-1) {
+ rb_fatal("can't allocate struct reader closure");
+ }
if (ffi_prep_closure(closure, struct_reader_cif,
- rb_struct_reader_closure_handler, ctx)
- != FFI_OK)
+ rb_struct_reader_closure_handler, ctx) != FFI_OK) {
rb_fatal("can't prepare struct reader closure");
+ }
+ if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1) {
+ rb_fatal("can't mprotect struct reader closure");
+ }
rb_define_method(klass, field->name, (VALUE(*)(ANYARGS))closure, 0);
@@ -2311,14 +2355,21 @@
args[0] = &ffi_type_pointer;
args[1] = &ffi_type_pointer;
if (ffi_prep_cif(struct_writer_cif, FFI_DEFAULT_ABI, 2,
- &ffi_type_pointer, args) != FFI_OK)
+ &ffi_type_pointer, args) != FFI_OK) {
rb_fatal("can't prepare struct_writer_cif");
+ }
}
- closure = (ffi_closure *)malloc(sizeof(ffi_closure));
+ if ((closure = mmap(NULL, sizeof(ffi_closure), PROT_READ | PROT_WRITE,
+ MAP_ANON | MAP_PRIVATE, -1, 0)) == (void *)-1) {
+ rb_fatal("can't allocate struct writer closure");
+ }
if (ffi_prep_closure(closure, struct_writer_cif,
- rb_struct_writer_closure_handler, ctx)
- != FFI_OK)
+ rb_struct_writer_closure_handler, ctx) != FFI_OK) {
rb_fatal("can't prepare struct writer closure");
+ }
+ if (mprotect(closure, sizeof(closure), PROT_READ | PROT_EXEC) == -1) {
+ rb_fatal("can't mprotect struct writer closure");
+ }
snprintf(buf, sizeof buf, "%s=", field->name);
rb_define_method(klass, buf, (VALUE(*)(ANYARGS))closure, 1);
@@ -3154,8 +3205,8 @@
return fmt;
types = (char **)alloca(sizeof(char *) * argc);
- ffi_argtypes = (ffi_type **)alloca(sizeof(ffi_type *) * argc + 4);
- ffi_args = (void **)alloca(sizeof(void *) * argc + 4);
+ ffi_argtypes = (ffi_type **)alloca(sizeof(ffi_type *) * (argc + 4));
+ ffi_args = (void **)alloca(sizeof(void *) * (argc + 4));
null = NULL;
new_fmt = NULL;
@@ -3234,11 +3285,12 @@
rb_obj_imp_isaForAutonotifying(void *rcv, SEL sel)
{
Class ret;
+ long ret_version;
#define KVO_CHECK_DONE 0x100000
ret = ((Class (*)(void *, SEL)) old_imp_isaForAutonotifying)(rcv, sel);
- if (ret != NULL && (RCLASS_VERSION(ret) & KVO_CHECK_DONE) == 0) {
+ if (ret != NULL && ((ret_version = RCLASS_VERSION(ret)) & KVO_CHECK_DONE) == 0) {
const char *name = class_getName(ret);
if (strncmp(name, "NSKVONotifying_", 15) == 0) {
Class ret_orig;
@@ -3246,10 +3298,11 @@
ret_orig = objc_getClass(name);
if (ret_orig != NULL && RCLASS_VERSION(ret_orig) & RCLASS_IS_OBJECT_SUBCLASS) {
DLOG("XXX", "marking KVO generated klass %p (%s) as RObject", ret, class_getName(ret));
- RCLASS_VERSION(ret) |= RCLASS_IS_OBJECT_SUBCLASS;
+ ret_version |= RCLASS_IS_OBJECT_SUBCLASS;
}
}
- RCLASS_VERSION(ret) |= KVO_CHECK_DONE;
+ ret_version |= KVO_CHECK_DONE;
+ RCLASS_SET_VERSION(ret, ret_version);
}
return ret;
}
@@ -3270,13 +3323,14 @@
rb_cBoxed = rb_define_class("Boxed", (VALUE)objc_getClass("NSValue"));
RCLASS_SET_VERSION_FLAG(rb_cBoxed, RCLASS_IS_OBJECT_SUBCLASS);
- rb_define_singleton_method(rb_cBoxed, "objc_type", rb_boxed_objc_type, 0);
+ rb_define_singleton_method(rb_cBoxed, "type", rb_boxed_objc_type, 0);
rb_define_singleton_method(rb_cBoxed, "opaque?", rb_boxed_is_opaque, 0);
rb_define_singleton_method(rb_cBoxed, "fields", rb_boxed_fields, 0);
rb_install_boxed_primitives();
rb_cPointer = rb_define_class("Pointer", rb_cObject);
rb_undef_alloc_func(rb_cPointer);
+ rb_define_singleton_method(rb_cPointer, "new_with_type", rb_pointer_new_with_type, 1);
rb_define_method(rb_cPointer, "assign", rb_pointer_assign, 1);
rb_define_method(rb_cPointer, "[]", rb_pointer_aref, 1);
@@ -3297,10 +3351,23 @@
assert(m != NULL);
old_imp_isaForAutonotifying = method_getImplementation(m);
method_setImplementation(m, (IMP)rb_obj_imp_isaForAutonotifying);
+
+ {
+ VALUE klass;
+ NODE *node, *body;
+ void *closure;
+
+ klass = rb_singleton_class(rb_cNSObject);
+ node = NEW_CFUNC(rb_class_new_instance, -1);
+ body = NEW_FBODY(NEW_METHOD(node, klass, NOEX_PUBLIC), 0);
+ closure = rb_ruby_to_objc_closure("@@:@", 1, body->nd_body);
+ assert(class_addMethod((Class)klass, @selector(new:), (IMP)closure, "@@:@"));
+ }
}
// for debug in gdb
int __rb_type(VALUE v) { return TYPE(v); }
+int __rb_native(VALUE v) { return NATIVE(v); }
@interface Protocol
@end
@@ -3470,9 +3537,6 @@
}
}
- rb_thread_t *rb_thread_wrap_existing_native_thread(rb_thread_id_t id);
- void native_mutex_unlock(pthread_mutex_t *lock);
- void native_mutex_lock(pthread_mutex_t *lock);
rb_thread_t *th, *old = NULL;
if (need_protection) {
@@ -3535,4 +3599,3 @@
}
@end
-
Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/object.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -1464,9 +1464,10 @@
rb_scan_args(argc, argv, "01", &super);
rb_check_inheritable(super);
}
- RCLASS_SUPER(klass) = super;
+ RCLASS_SET_SUPER(klass, super);
if ((RCLASS_VERSION(super) & RCLASS_IS_OBJECT_SUBCLASS) != RCLASS_IS_OBJECT_SUBCLASS) {
- RCLASS_VERSION(klass) ^= RCLASS_IS_OBJECT_SUBCLASS;
+ long v = RCLASS_VERSION(klass) ^ RCLASS_IS_OBJECT_SUBCLASS;
+ RCLASS_SET_VERSION(klass, v);
}
rb_objc_install_primitives((Class)klass, (Class)super);
if (super == rb_cObject)
@@ -2464,10 +2465,16 @@
rb_const_set(rb_cObject, rb_intern("Object"), rb_cNSObject);
rb_set_class_path(rb_cObject, rb_cObject, "NSObject");
rb_cBasicObject = (VALUE)objc_duplicateClass((Class)rb_cObject, "BasicObject", 0);
- rb_cModule = boot_defclass("Module", rb_cObject);
+ rb_cModule = boot_defclass("Module", rb_cNSObject);
rb_cClass = boot_defclass("Class", rb_cModule);
- RCLASS_SUPER(*(Class *)rb_cNSObject) = rb_cClass;
+ rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
+
+ void rb_include_module2(VALUE klass, VALUE module, int check, int add_methods);
+
+ rb_include_module2(*(VALUE *)rb_cNSObject, rb_cClass, 0, 0);
+ rb_include_module2(*(VALUE *)rb_cNSObject, rb_cModule, 0, 0);
+
rb_define_private_method(rb_cNSObject, "initialize", rb_obj_dummy, 0);
rb_define_method(rb_cNSObject, "==", rb_obj_equal, 1);
rb_define_method(rb_cNSObject, "equal?", rb_obj_equal, 1);
@@ -2603,7 +2610,6 @@
rb_define_method(rb_cModule, "class_variable_defined?", rb_mod_cvar_defined, 1);
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
- rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
rb_define_method(rb_cClass, "initialize_copy", rb_class_init_copy, 1); /* in class.c */
rb_define_alloc_func(rb_cClass, rb_class_s_alloc);
rb_undef_method(rb_cClass, "extend_object");
Modified: MacRuby/trunk/regexec.c
===================================================================
--- MacRuby/trunk/regexec.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/regexec.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -272,8 +272,8 @@
onig_region_resize(to, from->num_regs);
for (i = 0; i < from->num_regs; i++) {
- GC_WB(&to->beg[i], from->beg[i]);
- GC_WB(&to->end[i], from->end[i]);
+ to->beg[i] = from->beg[i];
+ to->end[i] = from->end[i];
}
to->num_regs = from->num_regs;
Modified: MacRuby/trunk/sample-macruby/ABPresence/ABPresence.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/ABPresence/ABPresence.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/ABPresence/ABPresence.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -243,6 +243,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -254,6 +255,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/sample-macruby/AnimatingViews/AnimatingViews.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/AnimatingViews/AnimatingViews.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/AnimatingViews/AnimatingViews.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -235,6 +235,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -249,6 +250,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/sample-macruby/CircleView/CircleView.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/CircleView/CircleView.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/CircleView/CircleView.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -252,6 +252,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -268,6 +269,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/sample-macruby/DotView/DotView.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/DotView/DotView.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/DotView/DotView.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -235,6 +235,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -246,6 +247,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/sample-macruby/EmbeddedMacRuby/EmbeddedMacRuby.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/EmbeddedMacRuby/EmbeddedMacRuby.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/EmbeddedMacRuby/EmbeddedMacRuby.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -237,11 +237,18 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = (
+ ppc64,
+ ppc,
+ i386,
+ x86_64,
+ );
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
+ VALID_ARCHS = "i386 x86_64";
};
name = Debug;
};
@@ -249,14 +256,17 @@
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
+ ppc64,
ppc,
i386,
+ x86_64,
);
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
+ VALID_ARCHS = "i386 x86_64";
};
name = Release;
};
Modified: MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemo.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemo.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/FlickrDemo/FlickrDemo.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -243,6 +243,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -254,6 +255,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/sample-macruby/OutlineView/OutlineView.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/OutlineView/OutlineView.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/OutlineView/OutlineView.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -239,6 +239,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -253,6 +254,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/sample-macruby/PagePacker/PagePacker.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/PagePacker/PagePacker.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/PagePacker/PagePacker.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -381,20 +381,24 @@
C05733CC08A9546B00998B17 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
+ VALID_ARCHS = "i386 x86_64";
};
name = Debug;
};
C05733CD08A9546B00998B17 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
+ VALID_ARCHS = "i386 x86_64";
};
name = Release;
};
Modified: MacRuby/trunk/sample-macruby/PathDemo/PathDemo.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/PathDemo/PathDemo.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/PathDemo/PathDemo.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -239,6 +239,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -250,6 +251,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/sample-macruby/ViewModelDemo/ViewModelDemo.xcodeproj/project.pbxproj
===================================================================
--- MacRuby/trunk/sample-macruby/ViewModelDemo/ViewModelDemo.xcodeproj/project.pbxproj 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/sample-macruby/ViewModelDemo/ViewModelDemo.xcodeproj/project.pbxproj 2008-10-26 02:00:15 UTC (rev 675)
@@ -243,6 +243,7 @@
C01FCF4F08A954540054247B /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
@@ -254,6 +255,7 @@
C01FCF5008A954540054247B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
+ ARCHS = "$(NATIVE_ARCH_ACTUAL)";
GCC_ENABLE_OBJC_GC = required;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
Modified: MacRuby/trunk/test/ruby/test_objc.rb
===================================================================
--- MacRuby/trunk/test/ruby/test_objc.rb 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/test/ruby/test_objc.rb 2008-10-26 02:00:15 UTC (rev 675)
@@ -57,7 +57,7 @@
if !File.exist?('/tmp/dummy.bundle') or File.mtime(__FILE__) > File.mtime('/tmp/dummy.bundle')
File.open('/tmp/dummy.m', 'w') { |io| io.write(DUMMY_M) }
- system("/usr/bin/gcc /tmp/dummy.m -o /tmp/dummy.bundle -g -framework Foundation -dynamiclib -fobjc-gc")
+ system("/usr/bin/gcc /tmp/dummy.m -o /tmp/dummy.bundle -g -framework Foundation -dynamiclib -fobjc-gc -arch i386 -arch x86_64 -arch ppc")
end
require '/tmp/dummy.bundle'
@@ -255,18 +255,32 @@
def test_struct_inspect
r = NSRect.new
- assert_equal("#<NSRect origin=#<NSPoint x=0.0 y=0.0> size=#<NSSize width=0.0 height=0.0>>",
- r.inspect)
+ if RUBY_ARCH == 'x86_64'
+ assert_equal("#<NSRect origin=#<CGPoint x=0.0 y=0.0> size=#<CGSize width=0.0 height=0.0>>",
+ r.inspect)
+ else
+ assert_equal("#<NSRect origin=#<NSPoint x=0.0 y=0.0> size=#<NSSize width=0.0 height=0.0>>",
+ r.inspect)
+ end
r.origin.x = 42
r.size.width = 42
- assert_equal("#<NSRect origin=#<NSPoint x=42.0 y=0.0> size=#<NSSize width=42.0 height=0.0>>",
- r.inspect)
+ if RUBY_ARCH == 'x86_64'
+ assert_equal("#<NSRect origin=#<CGPoint x=42.0 y=0.0> size=#<CGSize width=42.0 height=0.0>>",
+ r.inspect)
+ else
+ assert_equal("#<NSRect origin=#<NSPoint x=42.0 y=0.0> size=#<NSSize width=42.0 height=0.0>>",
+ r.inspect)
+ end
end
def test_struct_dup
r = NSMakeRect(1, 2, 3, 4)
r2 = r.dup
- assert_kind_of(NSRect, r2)
+ if RUBY_ARCH == 'x86_64'
+ assert_kind_of(CGRect, r2)
+ else
+ assert_kind_of(NSRect, r2)
+ end
assert_equal(r, r2)
r2.origin.x = 42
assert(r != r2)
@@ -422,4 +436,24 @@
assert_equal(o, o.mutableCopy)
assert_equal('^{_NSZone=}', o.methodSignatureForSelector('mutableCopyWithZone:').getArgumentTypeAtIndex(2))
end
+
+ def test_create_pointer
+ assert_equal(nil, NSString.stringWithContentsOfFile('/does/not/exist', encoding:NSASCIIStringEncoding, error:nil))
+ p = Pointer.new_with_type('@')
+ p.assign(nil)
+ assert_equal(nil, NSString.stringWithContentsOfFile('/does/not/exist', encoding:NSASCIIStringEncoding, error:p))
+ err = p[0]
+ assert_kind_of(NSError, err)
+ p.assign(nil)
+ assert(NSString.stringWithContentsOfFile(__FILE__, encoding:NSASCIIStringEncoding, error:p))
+ assert_equal(nil, p[0])
+ end
+
+ def test_create_pointer2
+ p1 = Pointer.new_with_type(NSRect.type)
+ p2 = Pointer.new_with_type(NSRect.type)
+ NSDivideRect([0, 0, 100, 100], p1, p2, 10.0, 0)
+ assert_equal(NSMakeRect(0, 0, 10, 100), p1[0])
+ assert_equal(NSMakeRect(10, 0, 90, 100), p2[0])
+ end
end
Modified: MacRuby/trunk/thread.c
===================================================================
--- MacRuby/trunk/thread.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/thread.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -510,7 +510,7 @@
file);
}
rb_raise(rb_eThreadError, "already initialized thread - %s:%d",
- file, NUM2INT(line));
+ file, (int)NUM2INT(line));
}
return thread_create_core(thread, args, 0);
}
@@ -1886,6 +1886,10 @@
int result, lerrno;
fd_set orig_read, orig_write, orig_except;
+ bzero(&orig_read, sizeof(fd_set));
+ bzero(&orig_write, sizeof(fd_set));
+ bzero(&orig_except, sizeof(fd_set));
+
#ifndef linux
double limit = 0;
struct timeval wait_rest;
Modified: MacRuby/trunk/variable.c
===================================================================
--- MacRuby/trunk/variable.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/variable.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -349,7 +349,7 @@
}
if (!rb_const_defined(c, id)) {
undefined_class:
- rb_raise(rb_eArgError, "undefined class/module %.*s", p-path, path);
+ rb_raise(rb_eArgError, "undefined class/module %.*s", (int)(p-path), path);
}
c = rb_const_get_at(c, id);
switch (TYPE(c)) {
@@ -436,7 +436,7 @@
entry = ALLOC(struct global_entry);
var = ALLOC(struct global_variable);
entry->id = id;
- entry->var = var;
+ GC_WB(&entry->var, var);
var->counter = 1;
var->data = 0;
var->getter = undef_getter;
@@ -468,7 +468,7 @@
var->setter = val_setter;
var->marker = val_marker;
- var->data = (void*)val;
+ GC_WB(&var->data, (void*)val);
}
static void
@@ -504,7 +504,7 @@
static void
var_setter(VALUE val, ID id, VALUE *var)
{
- *var = val;
+ GC_WB(var, val);
}
static void
@@ -655,7 +655,7 @@
trace->func = rb_trace_eval;
trace->data = cmd;
trace->removed = 0;
- entry->var->trace = trace;
+ GC_WB(&entry->var->trace, trace);
return Qnil;
}
Modified: MacRuby/trunk/version.c
===================================================================
--- MacRuby/trunk/version.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/version.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -37,6 +37,7 @@
rb_define_global_const("RUBY_COPYRIGHT", MKSTR(copyright));
rb_define_global_const("RUBY_ENGINE", MKSTR(engine));
#if WITH_OBJC
+ rb_define_global_const("RUBY_ARCH", rb_str_new2(RUBY_ARCH));
rb_define_global_const("MACRUBY_VERSION", rb_float_new(MACRUBY_VERSION));
#endif
}
Modified: MacRuby/trunk/version.h
===================================================================
--- MacRuby/trunk/version.h 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/version.h 2008-10-26 02:00:15 UTC (rev 675)
@@ -53,11 +53,24 @@
#if WITH_OBJC
# define MACRUBY_VERSION 0.4
+# if defined(__LP64__)
+# if BYTE_ORDER == BIG_ENDIAN
+# define RUBY_ARCH "ppc64"
+# else
+# define RUBY_ARCH "x86_64"
+# endif
+# else
+# if BYTE_ORDER == BIG_ENDIAN
+# define RUBY_ARCH "ppc"
+# else
+# define RUBY_ARCH "i386"
+# endif
+# endif
# define RUBY_DESCRIPTION \
"MacRuby version " STRINGIZE(MACRUBY_VERSION) \
" (ruby "RUBY_VERSION \
" "RUBY_RELEASE_DATE")" \
- " ["RUBY_PLATFORM"]"
+ " ["RUBY_PLATFORM", "RUBY_ARCH"]"
#else
# define RUBY_DESCRIPTION \
"ruby "RUBY_VERSION \
Modified: MacRuby/trunk/vm.h
===================================================================
--- MacRuby/trunk/vm.h 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/vm.h 2008-10-26 02:00:15 UTC (rev 675)
@@ -82,8 +82,8 @@
extern void rb_enter_insn_trace(rb_control_frame_t *);
extern void rb_end_insn_trace(rb_control_frame_t *);
#define debugs
-#define DEBUG_ENTER_INSN(insn) rb_enter_insn_trace(GET_CFP())
-#define DEBUG_END_INSN() rb_end_insn_trace(GET_CFP());
+#define DEBUG_ENTER_INSN(insn) do { if (MACRUBY_INSN_ENTRY_ENABLED()) rb_enter_insn_trace(GET_CFP()); } while (0)
+#define DEBUG_END_INSN() do { if (MACRUBY_INSN_RETURN_ENABLED()) rb_end_insn_trace(GET_CFP()); } while (0)
#endif
#define throwdebug if(0)printf
Modified: MacRuby/trunk/vm_insnhelper.c
===================================================================
--- MacRuby/trunk/vm_insnhelper.c 2008-10-26 01:33:48 UTC (rev 674)
+++ MacRuby/trunk/vm_insnhelper.c 2008-10-26 02:00:15 UTC (rev 675)
@@ -1858,39 +1858,35 @@
void
rb_enter_insn_trace(rb_control_frame_t *cfp)
{
- if (MACRUBY_INSN_ENTRY_ENABLED()) {
- /* just to get rid of compilation warnings... */
- if (0) {
- insn_op_types(0);
- insn_op_type(0, 0);
- }
+ /* just to get rid of compilation warnings... */
+ if (0) {
+ insn_op_types(0);
+ insn_op_type(0, 0);
+ }
- rb_iseq_t *iseq = cfp->iseq;
+ rb_iseq_t *iseq = cfp->iseq;
- if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
- VALUE *seq = iseq->iseq;
- int pc = cfp->pc - iseq->iseq_encoded;
+ if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
+ VALUE *seq = iseq->iseq;
+ int pc = cfp->pc - iseq->iseq_encoded;
- MACRUBY_INSN_ENTRY((char *)insn_name(seq[pc]),
- (char *)rb_sourcefile(),
- rb_sourceline());
- }
+ MACRUBY_INSN_ENTRY((char *)insn_name(seq[pc]),
+ (char *)rb_sourcefile(),
+ rb_sourceline());
}
}
void
rb_end_insn_trace(rb_control_frame_t *cfp)
{
- if (MACRUBY_INSN_RETURN_ENABLED()) {
- rb_iseq_t *iseq = cfp->iseq;
+ rb_iseq_t *iseq = cfp->iseq;
- if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
- VALUE *seq = iseq->iseq;
- int pc = cfp->pc - iseq->iseq_encoded;
+ if (iseq != NULL && VM_FRAME_TYPE(cfp) != FRAME_MAGIC_FINISH) {
+ VALUE *seq = iseq->iseq;
+ int pc = cfp->pc - iseq->iseq_encoded;
- MACRUBY_INSN_RETURN((char *)insn_name(seq[pc]),
- (char *)rb_sourcefile(),
- rb_sourceline());
- }
+ MACRUBY_INSN_RETURN((char *)insn_name(seq[pc]),
+ (char *)rb_sourcefile(),
+ rb_sourceline());
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20081025/55c5b126/attachment-0001.html>
More information about the macruby-changes
mailing list