Skip to content

Commit

Permalink
backport r4768 from trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/branches/0.7@4798 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed Oct 15, 2010
1 parent 33bed30 commit 50c1e02
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
6 changes: 3 additions & 3 deletions dispatcher.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions objc.h
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 4 additions & 6 deletions objc.m
Expand Up @@ -33,6 +33,8 @@
const char *type;
unsigned i;

memset(buf, 0, buflen);

if (method != NULL) {
if (bs_method == NULL) {
type = method_getTypeEncoding(method);
Expand All @@ -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];
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion vm.cpp
Expand Up @@ -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);
}
Expand Down

0 comments on commit 50c1e02

Please sign in to comment.