4 files changed, 21 insertions(+), 81 deletions(-)

M ObjC.mmod
M PiObjCObject.m
M dynamic_class.m
M method_dispatch.m
M ObjC.mmod +7 -75
@@ 322,7 322,8 @@ PIKEFUN void purge_autorelease_pool()
 PIKEFUN program get_dynamic_class(string classname)
 {
    struct program * prog;
-   
+  
+   LOG("get_dynamic_class(%s)\n", classname->str); 
    prog = pike_create_objc_dynamic_class(classname);
    
    pop_stack();

          
@@ 835,18 836,10 @@ PIKEFUN int low_load_bundle(string bundl
 BOOL CreateClassDefinition( const char * name, 
         const char * superclassName, struct program * prog)
 {
-#if OBJC_V1
-    struct objc_class * meta_class;
-    struct objc_class * super_class;
-    struct objc_class * new_class;
-    struct objc_class * root_class;
-	struct objc_method_list ** emptyMethodLists;
-#else
     Class meta_class;
     Class super_class;
     Class new_class;
     Class root_class;
-#endif /* OBJC_V1 */
 	struct svalue * ptr;
 
 LOG("CreateClassDefinition(%s, %s)\n", name, superclassName);

          
@@ 873,85 866,22 @@ LOG("CreateClassDefinition(%s, %s)\n", n
 
     root_class = super_class;
 
-#if OBJC_V1
-    while( root_class->super_class != nil )
-    {
-        root_class = root_class->super_class;
-    }
-#else
     while( class_getSuperclass(root_class) != nil )
     {
         root_class = class_getSuperclass(root_class);
     }
-#endif /* OBJC_V1 */
+
     // Allocate space for the class and its metaclass
     //
 
-#if OBJC_V1
-    new_class = calloc( 2, sizeof(struct objc_class) );
-    meta_class = &new_class[1];
-
-    // setup class
-    new_class->isa      = meta_class;
-    new_class->info     = CLS_CLASS;
-    meta_class->info    = CLS_META;
-
-    // Create a copy of the class name.
-    // For efficiency, we have the metaclass and the class itself 
-    // to share this copy of the name, but this is not a requirement
-    // imposed by the runtime.
-    //
-    new_class->name = malloc (strlen (name) + 1);
-    strcpy ((char*)new_class->name, name);
-    meta_class->name = new_class->name;
-#else
     new_class = objc_allocateClassPair(super_class, name, 0);
-#endif /* OBJC_V1 */
-
-
-#if OBJC_V1
-    // Allocate empty method lists.
-    // We can add methods later.
-    //
-
-    new_class->methodLists = calloc( 1, sizeof(struct objc_method_list  *) );
-    *new_class->methodLists = NULL;
-    meta_class->methodLists = calloc( 1, sizeof(struct objc_method_list  *) );
-    *meta_class->methodLists = NULL;
-
-    // Connect the class definition to the class hierarchy:
-    // Connect the class to the superclass.
-    // Connect the metaclass to the metaclass of the superclass.
-    // Connect the metaclass of the metaclass to the metaclass of  the root class.
-    //
-
-    new_class->super_class  = super_class;
-    meta_class->super_class = super_class->isa;
-    meta_class->isa         = (void *)root_class->isa;
-
-    // Set the sizes of the class and the metaclass.
-    //
-
-    new_class->instance_size = super_class->instance_size;
-    meta_class->instance_size = meta_class->super_class->instance_size;
-
-
-    // We will add our methods later, so the list of lists starts with just end-of-list
-    emptyMethodLists = malloc( sizeof(void *) );
-    *emptyMethodLists = ((struct objc_method_list*)-1); // See objc-private.h in Darwin
-
-//	new_class->methodLists = NULL;
-	new_class->methodLists = emptyMethodLists;
-#endif /* OBJC_V1 */
 
     RegisterInstanceVariables(new_class, prog);
 
     // Finally, register the class with the runtime.
-#if OBJC_V1
-    objc_addClass( new_class ); 
-#else
+
     objc_registerClassPair(new_class);
-#endif /* OBJC_V1 */    
+
 printf("class: %s, %p\n", name, prog);
  //   RegisterDynamicMethod("init", name, (IMP)make_create_stub(prog), "@4@4:4");
     RegisterDynamicMethod("__create", name, (IMP)make_create_stub(prog), "@4@4:4");

          
@@ 967,6 897,8 @@ RegisterDynamicClassMethod("getPikeClass
 	SET_SVAL_SUBTYPE(*ptr, 0);
 	ptr->u.ptr = new_class;
 	
+	LOG("new Objective-C class: %p\n", new_class);
+	
 	ref_push_program(prog);
     mapping_insert(global_proxy_cache, Pike_sp-1, ptr);
     pop_stack();

          
M PiObjCObject.m +3 -2
@@ 1017,14 1017,15 @@ void dispatch_pike_class_method(struct p
   struct Method** lst;
   void* cookie;
 
-  LOG("PiObjCObject.respondsToSelector: %s? ", (char*) aSelector);
+  LOG("PiObjCObject(%s).respondsToSelector: %s? ", object_getClassName(self), sel_getName(aSelector));
+  NSLog([self description]);
 	/*
 	 * We cannot rely on NSProxy, it doesn't implement most of the
 	 * NSObject interface anyway.
 	 */
 	 
    Method m;
-   m = class_getInstanceMethod(self, aSelector);
+   m = class_getInstanceMethod(object_getClass(self), aSelector);
    if(m != NULL)
      return YES;
 /*

          
M dynamic_class.m +9 -3
@@ 197,7 197,7 @@ void f_call_objc_method(INT32 args, int 
     pool = [global_autorelease_pool getAutoreleasePool];
 	//describe_proxy();
 // LOG("\ncall\n");    
-//   LOG("class: %s, select: %s, is_instance: %d\n", obj->isa->name, (char *) select, is_instance);
+   LOG("class: %s, select: %s, is_instance: %d\n", class_getName(object_getClass(obj)), sel_getName(select), is_instance);
     if(is_instance)
       method = class_getInstanceMethod(object_getClass(obj), select);
     else

          
@@ 218,7 218,7 @@ void f_call_objc_method(INT32 args, int 
     arguments = method_getNumberOfArguments(method);
 
     LOG("%s(%d args), expecting %d, returning %d\n", (char * ) select, args, arguments-2, num_pointer_return_arguments+1);
-
+    LOG("%s -> %s\n", select, method_getTypeEncoding(method));
 	// the number of required arguments is:
 	// the total number of arguments for the method - (2 (standard objc args) + the number of pointer return args)
     if((args) < (arguments-(2 + num_pointer_return_arguments)))

          
@@ 346,6 346,7 @@ void f_call_objc_method(INT32 args, int 
 			    else
           {
 			      Class cls;
+LOG("wrapping obj%s\n", "");
             wrapper = id_from_object(o);
             argumentList[x] = &(wrapper);
 			    }

          
@@ 353,8 354,13 @@ void f_call_objc_method(INT32 args, int 
 		    else if(TYPEOF(*sv) == T_ARRAY)
 		    {
 			    id rv;
+LOG("encoding array as OC_Array%s\n", "");
 			    rv = [OC_Array newWithPikeArray: sv->u.array];
-          argumentList[x] = &(rv);
+//LOG("obj: %s\n",	[[obj description] UTF8String]);
+		//	rv =  [@"foo bar gazonk" componentsSeparatedByString: @" "];
+
+//LOG("obj: %s\n",	[[rv description] UTF8String]);
+          argumentList[x] = &rv;
 		    }
 			
 		    else if(TYPEOF(*sv) == T_MAPPING)

          
M method_dispatch.m +2 -1
@@ 324,7 324,7 @@ static const char ulong_type[] = { _C_UL
     }
             
   /* Build FFI argumentlist description */
-	LOG("num args: %d\n", numargs);
+	LOG("cif will have num args: %d\n", numargs);
 	
     cl_arg_types = malloc(sizeof(ffi_type*) * (numargs));
     if (cl_arg_types == NULL) {

          
@@ 372,6 372,7 @@ void * make_create_stub(struct program *
   const char* rettype;
   void (*disp)(ffi_cif*,void*,void**,void*) = low_create_pike_object;
 
+  LOG("make_create_stub(%p)\n", prog);
   // since Objective-C classes cannot be un-registered, we just add a reference and forget about it.
   // technically this is not a leak, i think.
   add_ref(prog);