Permalink
Browse files

merging macruby64 branch into trunk

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@675 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
lrz committed Oct 26, 2008
1 parent f95d252 commit 6bcd45f162d044874606f2b2f6513aa57138a3f9
View
@@ -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 @@ end
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,7 +27,16 @@ ENABLE_DEBUG_LOGGING = do_option('enable_debug_logging', true) { |x| x == 'true'
# 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]
@@ -512,7 +523,7 @@ namespace :macruby do
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
View
4 bs.c
@@ -252,7 +252,7 @@ undecorate_struct_type(const char *src, char *dest, size_t dest_len,
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 @@ undecorate_struct_type(const char *src, char *dest, size_t dest_len,
}
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;
}
View
88 class.c
@@ -153,7 +153,7 @@ rb_objc_alloc_class(const char *name, VALUE super, VALUE flags, VALUE klass)
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 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
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_clone(VALUE obj)
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 @@ rb_make_metaclass(VALUE obj, VALUE super)
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 @@ rb_define_module_under(VALUE outer, const char *name)
}
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 @@ rb_include_module(VALUE klass, VALUE module)
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 @@ rb_include_module(VALUE klass, VALUE module)
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));
- }
- else {
- assert(class_addMethod((Class)klass,
- method_getName(method),
- method_getImplementation(method),
- method_getTypeEncoding(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)));
+ }
}
+ 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 @@ ins_methods_push(VALUE name, long type, VALUE ary, long visi)
}
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 @@ rb_objc_push_methods(VALUE ary, VALUE mod, VALUE objc_methods, int (*func) (VALU
}
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;
View
@@ -68,7 +68,7 @@ enc_init_db(void)
}
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 @@ enc_init_db(void)
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;
}
View
19 gc.c
@@ -1231,7 +1231,8 @@ rb_call_os_finalizer(void *obj)
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 @@ rb_obj_imp_finalize(void *obj, SEL sel)
}
}
+static bool gc_disabled = false;
+
void
Init_PreGC(void)
{
@@ -1276,9 +1279,13 @@ Init_PreGC(void)
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 @@ Init_PreGC(void)
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 @@ Init_GC(void)
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);
View
@@ -1,2 +1,3 @@
#define RUBY_INCLUDED_AS_FRAMEWORK 1
+#include <Foundation/Foundation.h>
#include "ruby/ruby.h"
View
@@ -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
View
@@ -295,7 +295,17 @@ void rb_ia64_flushrs(void);
# 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
Oops, something went wrong.

0 comments on commit 6bcd45f

Please sign in to comment.