fixes latest tests. works in PY2 and PY3

This commit is contained in:
Mathieu Virbel 2018-11-08 11:10:02 +01:00
parent 82ef0180ee
commit 02ad49a6dc
5 changed files with 14 additions and 6 deletions

View File

@ -14,6 +14,10 @@ html:
$(MAKE) -C docs html
distclean:
rm -rf .pytest_cache
rm -rf build
rm -rf pyobjus/config.pxi
rm -rf pyobjus/pyobjus.c
rm -rf pyobjus/*.so
rm -rf pyobjus/*.pyc
rm -rf pyobjus/__pycache__

View File

@ -2,6 +2,7 @@ import ctypes
import itertools
from ctypes import Structure
from .pyobjus import signature_types_to_list, dev_platform
from .debug import dprint
########## NS STRUCT TYPES ##########

View File

@ -87,6 +87,7 @@ def dereference(py_ptr, **kwargs):
# pass
return convert_cy_ret_to_py(<id*>c_addr, py_ptr.of_type, py_ptr.size)
cdef void* cast_to_cy_data_type(id *py_obj, size_t size, char* of_type, by_value=True, py_val=None):
''' Function for casting Python data type (struct, union) to some Cython type
@ -162,6 +163,7 @@ cdef void* cast_to_cy_data_type(id *py_obj, size_t size, char* of_type, by_value
return val_ptr
cdef convert_to_cy_cls_instance(id ret_id, main_cls_name=None):
''' Function for converting C pointer into Cython ObjcClassInstance type
Args:
@ -264,10 +266,8 @@ cdef object convert_cy_ret_to_py(id *f_result, sig, size_t size, members=None, o
# return type -> struct OR union
elif sig.startswith((b'(', b'{')):
#NOTE: This need to be tested more! Does this way work in all cases? TODO: Find better solution for this!
if <long>f_result[0] in ctypes_struct_cache:
dprint("ctypes struct value found in cache", of_type='i')
if <unsigned long long>f_result[0] in ctypes_struct_cache:
val = ctypes.cast(<unsigned long long>f_result[0], ctypes.POINTER(factory.find_object(return_type, members=members))).contents
else:
if return_type[0] != b'CGRect' or dev_platform == 'darwin':

View File

@ -42,11 +42,14 @@ def signature_types_to_list(type_encoding):
types_str = b""
if type_encoding.find(b'=') == -1:
return [bytes([ret_type]) for ret_type in type_encoding]
if PY_MAJOR_VERSION == 2:
return list(type_encoding)
else:
return [bytes([ret_type]) for ret_type in type_encoding]
for letter in type_encoding:
letter = bytes([letter])
# dprint("type_encoding={!r} letter={!r}".format(type_encoding, letter))
dprint("type_encoding={!r} letter={!r}".format(type_encoding, letter))
if letter in [b'(', b'{']:
if types_str:
begin_ind = end_ind

View File

@ -3,7 +3,7 @@ from pyobjus import autoclass, objc_py_types as opy, dereference
NSValue = None
class NSString(unittest.TestCase):
class NSValueTest(unittest.TestCase):
def setUp(self):
global NSValue