Permalink
Browse files

define our own version of method_getNumberOfArguments() since the sys…

…tem one is broken on SnowLeopard for Block types8~8~

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4768 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent fa2dc0e commit 6418ac75581881da6da766aa548dcda1c8c0d378 @lrz lrz committed Oct 8, 2010
Showing with 24 additions and 10 deletions.
  1. +3 −3 dispatcher.cpp
  2. +16 −0 objc.h
  3. +4 −6 objc.m
  4. +1 −1 vm.cpp
View
@@ -530,7 +530,7 @@ fill_ocache(struct mcache *cache, VALUE self, Class klass, IMP imp, SEL sel,
if (cache->as.ocall.bs_method != NULL
&& cache->as.ocall.bs_method->variadic && method != NULL) {
// TODO honor printf_format
- const int real_argc = method_getNumberOfArguments(method) - 2;
+ const int real_argc = rb_method_getNumberOfArguments(method) - 2;
if (real_argc < argc) {
const size_t s = strlen(types);
assert(s + argc - real_argc < sizeof types);
@@ -986,7 +986,7 @@ rb_vm_dispatch(void *_vm, struct mcache *cache, VALUE top, VALUE self,
expected_argc = node->arity.min;
}
else {
- expected_argc = method_getNumberOfArguments(m);
+ expected_argc = rb_method_getNumberOfArguments(m);
expected_argc -= 2; // removing receiver and selector
}
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)",
@@ -1434,7 +1434,7 @@ rb_vm_get_method(VALUE klass, VALUE obj, ID mid, int scope)
int arity;
rb_vm_method_node_t *new_node;
if (node == NULL) {
- arity = method_getNumberOfArguments(method) - 2;
+ arity = rb_method_getNumberOfArguments(method) - 2;
new_node = NULL;
}
else {
View
16 objc.h
@@ -145,6 +145,12 @@ SkipFirstType(const char *type)
case 'V': /* oneway */
break;
+ case _C_ID:
+ if (*type == _C_UNDEF) {
+ type++; /* Blocks */
+ }
+ return type;
+
/* arrays */
case _C_ARY_B:
return type + SubtypeUntil (type, _C_ARY_E) + 1;
@@ -191,6 +197,16 @@ TypeArity(const char *type)
return arity;
}
+// We do not use method_getNumberOfArguments since it's broken on
+// SnowLeopard for signatures containing Block objects.
+static inline unsigned int
+rb_method_getNumberOfArguments(Method m)
+{
+ const unsigned int arity = TypeArity(method_getTypeEncoding(m));
+ assert(arity >= 2);
+ return arity - 1; // Skip return type.
+}
+
id rb_objc_numeric2nsnumber(VALUE obj);
VALUE rb_objc_convert_immediate(id obj);
View
10 objc.m
@@ -33,6 +33,8 @@
const char *type;
unsigned i;
+ memset(buf, 0, buflen);
+
if (method != NULL) {
if (bs_method == NULL) {
type = method_getTypeEncoding(method);
@@ -44,8 +46,6 @@
type = SkipStackSize(type2);
}
while (*type != '\0');
- //strlcpy(buf, method_getTypeEncoding(method), buflen);
- //sig->argc = method_getNumberOfArguments(method);
}
else {
char buf2[100];
@@ -58,8 +58,7 @@
strlcpy(buf, buf2, buflen);
}
- //sig->argc = method_getNumberOfArguments(method);
- int argc = method_getNumberOfArguments(method);
+ const unsigned int argc = rb_method_getNumberOfArguments(method);
for (i = 0; i < argc; i++) {
if (i >= 2 && (type = rb_get_bs_method_type(bs_method, i - 2))
!= NULL) {
@@ -84,8 +83,7 @@
}
strlcpy(buf, type, buflen);
- //sig->argc = [msig numberOfArguments];
- int argc = [msig numberOfArguments];
+ const int argc = [msig numberOfArguments];
for (i = 0; i < argc; i++) {
if (i < 2 || (type = rb_get_bs_method_type(bs_method, i - 2))
== NULL) {
View
2 vm.cpp
@@ -1782,7 +1782,7 @@ resolve_method_type(char *buf, const size_t buflen, Class klass, Method m,
}
else {
assert(strlen(buf) >= 3);
- for (unsigned int i = method_getNumberOfArguments(m) + 1;
+ for (unsigned int i = rb_method_getNumberOfArguments(m) + 1;
i < types_count; i++) {
strlcat(buf, "@", buflen);
}

0 comments on commit 6418ac7

Please sign in to comment.