Skip to content

Commit

Permalink
[fix #59] remove klass field
Browse files Browse the repository at this point in the history
`class_createInstance()` fills following structure fields properly.

```
struct objc_class {
    Class isa  OBJC_ISA_AVAILABILITY;

#if !__OBJC2__
    Class super_class                                        OBJC2_UNAVAILABLE;
    const char *name                                         OBJC2_UNAVAILABLE;
    long version                                             OBJC2_UNAVAILABLE;
    long info                                                OBJC2_UNAVAILABLE;
    long instance_size                                       OBJC2_UNAVAILABLE;
    struct objc_ivar_list *ivars                             OBJC2_UNAVAILABLE;
    struct objc_method_list **methodLists                    OBJC2_UNAVAILABLE;
    struct objc_cache *cache                                 OBJC2_UNAVAILABLE;
    struct objc_protocol_list *protocols                     OBJC2_UNAVAILABLE;
#endif

} OBJC2_UNAVAILABLE;
```

Our `klass` in `struct rb_class_ptr` covers `isa` of `struct objc_class`.
If store a value in `klass`, it will break `isa`.
And then we cannot call Objective-C method on its instance.
  • Loading branch information
Watson1978 committed Dec 5, 2016
1 parent 9ca88e2 commit b459603
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/rubymotion.h
Expand Up @@ -75,7 +75,7 @@ VALUE rb_vm_call_s(VALUE self, SEL sel, int argc, const VALUE *argv);
#define rb_send(rcv, sel, argc, argv) rb_vm_call_s(rcv, sel, argc, argv)

struct rb_class_ptr {
VALUE klass;
VALUE reserved; // MUST NOT use.
VALUE flags;
void *ptr;
};
Expand All @@ -89,7 +89,6 @@ rb_class_wrap_new(void *ptr, VALUE klass)
(struct rb_class_ptr *)class_createInstance((Class)klass,
sizeof(struct rb_class_ptr));
assert(obj != NULL);
//obj->klass = klass;
obj->flags = T_NATIVE;
obj->ptr = ptr;
objc_msgSend((id)obj, sel_registerName("autorelease"));
Expand Down

0 comments on commit b459603

Please sign in to comment.