@@ -189,7 +189,6 @@ def convert_return_value(retval, clsname, methodname):
189
189
190
190
cdef class ObjcMethod(object ):
191
191
cdef bytes name
192
- cdef bytes signature
193
192
cdef int is_static
194
193
cdef object signature_return
195
194
cdef object signature_current_args
@@ -211,7 +210,7 @@ cdef class ObjcMethod(object):
211
210
cdef ffi_type ** f_arg_types
212
211
cdef object objc_name
213
212
214
- def __cinit__ (self , signature , objc_name , **kwargs ):
213
+ def __cinit__ (self , objc_name , signature_args , signature_return , **kwargs ):
215
214
self .is_ready = 0
216
215
self .f_result_type = NULL
217
216
self .f_arg_types = NULL
@@ -238,10 +237,12 @@ cdef class ObjcMethod(object):
238
237
# self.f_result_type = NULL
239
238
# TODO: Memory management
240
239
241
- def __init__ (self , bytes signature , bytes objc_name , **kwargs ):
240
+ def __init__ (self , bytes objc_name , signature_args , signature_return , **kwargs ):
242
241
super (ObjcMethod, self ).__init__()
243
- self .signature = < bytes> signature
244
- self .signature_return, self .signature_args = parse_signature(signature)
242
+
243
+ self .signature_args = [clean_type_specifier(sign_arg) for sign_arg in signature_args]
244
+ self .signature_return = clean_type_specifier(signature_return)
245
+
245
246
self .is_static = kwargs.get(' static' , False )
246
247
self .name = kwargs.get(' name' )
247
248
self .objc_name = objc_name
@@ -272,8 +273,8 @@ cdef class ObjcMethod(object):
272
273
else :
273
274
self .name = self .objc_name
274
275
275
- if self .signature_return[ 0 ] .startswith((b' (' , b' {' )):
276
- sig = self .signature_return[ 0 ]
276
+ if self .signature_return.startswith((b' (' , b' {' )):
277
+ sig = self .signature_return
277
278
self .return_type = sig[1 :- 1 ].split(b' =' , 1 )
278
279
279
280
self .selector = sel_registerName(< bytes> self .name)
@@ -290,12 +291,12 @@ cdef class ObjcMethod(object):
290
291
dprint(' signature: {}' .format(signature_args))
291
292
292
293
# resolve f_result_type
293
- if self .signature_return[ 0 ] .startswith(b' (' ):
294
+ if self .signature_return.startswith(b' (' ):
294
295
self .f_result_type = type_encoding_to_ffitype(
295
- self .signature_return[ 0 ] , str_in_union = True )
296
+ self .signature_return, str_in_union = True )
296
297
else :
297
298
self .f_result_type = type_encoding_to_ffitype(
298
- self .signature_return[ 0 ] )
299
+ self .signature_return)
299
300
300
301
# casting is needed here because otherwise we will get warning at compile
301
302
cdef unsigned int num_args = < unsigned int > len (signature_args)
@@ -313,12 +314,12 @@ cdef class ObjcMethod(object):
313
314
# populate f_args_type array for FFI prep
314
315
cdef int index = 0
315
316
for arg in signature_args:
316
- if arg[ 0 ] .startswith(b' (' ):
317
+ if arg.startswith(b' (' ):
317
318
raise ObjcException(
318
319
' Currently passing unions as arguments by '
319
320
' value is not supported in pyobjus!' )
320
321
dprint(' argument ==>' , arg, len (signature_args))
321
- self .f_arg_types[index] = type_encoding_to_ffitype(arg[ 0 ] )
322
+ self .f_arg_types[index] = type_encoding_to_ffitype(arg)
322
323
index = index + 1
323
324
324
325
# FFI PREP
@@ -360,7 +361,6 @@ cdef class ObjcMethod(object):
360
361
cdef int index
361
362
cdef size_t size
362
363
cdef ObjcClassInstance arg_objcclass
363
- cdef size_t result_size = < size_t> int (self .signature_return[1 ])
364
364
365
365
# check that we have at least the same number of arguments as the
366
366
# signature want (having more than expected could signify that the called
@@ -405,7 +405,7 @@ cdef class ObjcMethod(object):
405
405
sig_index = - 1
406
406
signature_args.append(signature_args[- 1 ])
407
407
408
- sig, offset, attr = sig_full = signature_args[sig_index]
408
+ sig = signature_args[sig_index]
409
409
arg_size = type_encoding_to_ffitype(sig).size
410
410
411
411
# we already know the ffitype/size being used
@@ -435,7 +435,7 @@ cdef class ObjcMethod(object):
435
435
if res_ptr == NULL :
436
436
raise MemoryError (' Unable to allocate res_ptr' )
437
437
438
- if not self .signature_return[ 0 ] .startswith((b' (' , b' {' )):
438
+ if not self .signature_return.startswith((b' (' , b' {' )):
439
439
ffi_call(& self .f_cif, < void (* )() noexcept>< id (* )(id , SEL)> objc_msgSend, res_ptr, f_args)
440
440
441
441
else :
@@ -461,7 +461,7 @@ cdef class ObjcMethod(object):
461
461
size_ret = ctypes.sizeof(obj_ret)
462
462
463
463
stret = False
464
- if self .signature_return[ 0 ] .startswith((b' {' , b' (' )) and size_ret > 16 :
464
+ if self .signature_return.startswith((b' {' , b' (' )) and size_ret > 16 :
465
465
stret = True
466
466
467
467
if stret and MACOS_HAVE_OBJMSGSEND_STRET:
@@ -490,8 +490,8 @@ cdef class ObjcMethod(object):
490
490
cdef ObjcClassInstance cret
491
491
cdef bytes bret
492
492
493
- sig = self .signature_return[ 0 ]
494
- dprint(" return signature" , self .signature_return[ 0 ] , of_type = " i" )
493
+ sig = self .signature_return
494
+ dprint(" return signature" , self .signature_return, of_type = " i" )
495
495
496
496
if sig == b' @' :
497
497
ret_id = (< id > res_ptr[0 ])
@@ -529,10 +529,13 @@ cdef objc_method_to_py(Method method, main_cls_name, static=True):
529
529
'''
530
530
531
531
cdef char * method_name = < char * > sel_getName(method_getName(method))
532
- cdef char * method_args = < char * > method_getTypeEncoding(method)
532
+ cdef unsigned int method_args_len = method_getNumberOfArguments(method)
533
+ cdef char * method_return_type = method_copyReturnType(method)
534
+ cdef list method_args_types = [method_copyArgumentType(method, i) for i in range (method_args_len)]
535
+
533
536
cdef basestring py_name = (< bytes> method_name).replace(b" :" , b" _" ).decode(" utf-8" )
534
537
535
- return py_name, ObjcMethod(< bytes > method_args, method_name , static = static, main_cls_name = main_cls_name)
538
+ return py_name, ObjcMethod(method_name, method_args_types, method_return_type , static = static, main_cls_name = main_cls_name)
536
539
537
540
cdef class_get_methods(Class cls , static = False , main_cls_name = None ):
538
541
cdef unsigned int index, num_methods
@@ -605,7 +608,11 @@ cdef get_class_method(Class cls, char *name):
605
608
ObjcMethod instance
606
609
'''
607
610
cdef Method m_cls = class_getClassMethod(cls , sel_registerName(name))
608
- return ObjcMethod(< bytes>< char * > method_getTypeEncoding(m_cls), name, static = True , \
611
+ cdef unsigned int method_args_len = method_getNumberOfArguments(m_cls)
612
+ cdef char * method_return_type = method_copyReturnType(m_cls)
613
+ cdef list method_args_types = [method_copyArgumentType(m_cls, i) for i in range (method_args_len)]
614
+
615
+ return ObjcMethod(name, method_args_types, method_return_type, static = True , \
609
616
main_cls_name = class_getName(cls ))
610
617
611
618
cdef resolve_super_class_methods(Class cls , instance_methods = True ):
0 commit comments