Eolian: Fix obj conversion

The generic converter was an idea which didn't work in practise.
This commit is contained in:
Kai Huuhko 2014-06-07 21:01:01 +03:00
parent 38a1d15016
commit cb7c2bf07b
1 changed files with 79 additions and 40 deletions

View File

@ -75,19 +75,59 @@ EOLIAN_SCOPE_PUBLIC = enums.EOLIAN_SCOPE_PUBLIC
EOLIAN_SCOPE_PROTECTED = enums.EOLIAN_SCOPE_PROTECTED
cdef list eina_list_obj_to_python_list(const Eina_List *lst, object cls):
cdef list eina_list_obj_to_python_list(const Eina_List *lst, type cls):
cdef:
list ret = list()
while lst:
o = eolian_obj_to_python_obj(<uintptr_t>lst.data, cls)
if cls is Class:
o = eolian_class_to_python_obj(<Eolian_Class>lst.data)
elif cls is Function:
o = eolian_func_to_python_obj(<Eolian_Function>lst.data)
elif cls is FunctionParameter:
o = eolian_func_param_to_python_obj(<Eolian_Function_Parameter>lst.data)
elif cls is Type:
o = eolian_type_to_python_obj(<Eolian_Type>lst.data)
elif cls is Implement:
o = eolian_implement_to_python_obj(<Eolian_Implement>lst.data)
elif cls is Event:
o = eolian_event_to_python_obj(<Eolian_Event>lst.data)
else:
print("Unknown type")
return
ret.append(o)
lst = lst.next
return ret
cdef object eolian_obj_to_python_obj(uintptr_t ptr, object cls):
ret = cls.__new__(cls)
ret._set_obj(ptr)
cdef Class eolian_class_to_python_obj(Eolian_Class o):
cdef Class ret = Class.__new__(Class)
ret._set_obj(o)
return ret
cdef Function eolian_func_to_python_obj(Eolian_Function o):
cdef Function ret = Function.__new__(Function)
ret._set_obj(o)
return ret
cdef FunctionParameter eolian_func_param_to_python_obj(
Eolian_Function_Parameter o):
cdef FunctionParameter ret = FunctionParameter.__new__(FunctionParameter)
ret._set_obj(o)
return ret
cdef Type eolian_type_to_python_obj(Eolian_Type o):
cdef Type ret = Type.__new__(Type)
ret._set_obj(o)
return ret
cdef Implement eolian_implement_to_python_obj(Eolian_Implement o):
cdef Implement ret = Implement.__new__(Implement)
ret._set_obj(o)
return ret
cdef Event eolian_event_to_python_obj(Eolian_Event o):
cdef Event ret = Event.__new__(Event)
ret._set_obj(o)
return ret
@ -163,9 +203,11 @@ def class_find_by_name(class_name):
"""
if isinstance(class_name, unicode): class_name = PyUnicode_AsUTF8String(class_name)
return eolian_obj_to_python_obj(
<uintptr_t>eolian_class_find_by_name(class_name), Class
)
cdef Eolian_Class klass = eolian_class_find_by_name(class_name)
if klass is NULL:
return None
else:
return eolian_class_to_python_obj(klass)
def class_find_by_file(file_name):
"""Finds a class by its location (.eo file)
@ -175,8 +217,8 @@ def class_find_by_file(file_name):
"""
if isinstance(file_name, unicode): file_name = PyUnicode_AsUTF8String(file_name)
return eolian_obj_to_python_obj(
<uintptr_t>eolian_class_find_by_file(file_name), Class
return eolian_class_to_python_obj(
eolian_class_find_by_file(file_name)
)
@ -184,8 +226,8 @@ cdef class Class(object):
cdef Eolian_Class klass
cdef _set_obj(self, uintptr_t obj):
self.klass = <Eolian_Class>obj
cdef _set_obj(self, Eolian_Class obj):
self.klass = obj
def __init__(self):
pass
@ -353,11 +395,10 @@ cdef class Class(object):
"""
if isinstance(func_name, unicode):
func_name = PyUnicode_AsUTF8String(func_name)
return eolian_obj_to_python_obj(
<uintptr_t>eolian_class_function_find_by_name(
return eolian_func_to_python_obj(
eolian_class_function_find_by_name(
self.klass, func_name, f_type
),
Function
)
)
@ -377,8 +418,8 @@ cdef class Function(object):
cdef Eolian_Function function_id
cdef _set_obj(self, uintptr_t obj):
self.function_id = <Eolian_Function>obj
cdef _set_obj(self, Eolian_Function obj):
self.function_id = obj
def __init__(self):
pass
@ -447,11 +488,10 @@ cdef class Function(object):
"""
if isinstance(param_name, unicode):
param_name = PyUnicode_AsUTF8String(param_name)
return eolian_obj_to_python_obj(
<uintptr_t>eolian_function_parameter_get(
return eolian_func_param_to_python_obj(
eolian_function_parameter_get(
self.function_id, param_name
),
FunctionParameter
)
)
property property_keys_list:
@ -509,11 +549,10 @@ cdef class Function(object):
:return: the types of the function return
"""
return eolian_obj_to_python_obj(
<uintptr_t>eolian_function_return_types_list_get(
return eolian_type_to_python_obj(
eolian_function_return_types_list_get(
self.function_id, ftype
),
Type
)
)
def return_dflt_value_get(self, Eolian_Function_Type ftype):
@ -573,8 +612,8 @@ cdef class FunctionParameter(object):
cdef Eolian_Function_Parameter param
cdef _set_obj(self, uintptr_t obj):
self.param = <Eolian_Function_Parameter>obj
cdef _set_obj(self, Eolian_Function_Parameter obj):
self.param = obj
def __init__(self):
pass
@ -615,8 +654,8 @@ cdef class FunctionParameter(object):
"""
def __get__(self):
return eolian_obj_to_python_obj(
<uintptr_t>eolian_parameter_types_list_get(self.param), Type
return eolian_type_to_python_obj(
eolian_parameter_types_list_get(self.param)
)
property name:
@ -655,8 +694,8 @@ cdef class Type(object):
cdef Eolian_Type etype
cdef _set_obj(self, uintptr_t obj):
self.etype = <Eolian_Type>obj
cdef _set_obj(self, Eolian_Type obj):
self.etype = obj
def __init__(self):
pass
@ -708,8 +747,8 @@ cdef class Implement(object):
cdef Eolian_Implement impl
cdef _set_obj(self, uintptr_t obj):
self.impl = <Eolian_Implement>obj
cdef _set_obj(self, Eolian_Implement obj):
self.impl = obj
def __init__(self):
pass
@ -744,8 +783,8 @@ cdef class Implement(object):
raise RuntimeError("Could not fetch information")
return (
eolian_obj_to_python_obj(<uintptr_t>klass, Class),
eolian_obj_to_python_obj(<uintptr_t>function, Function),
eolian_class_to_python_obj(klass),
eolian_func_to_python_obj(function),
type
)
@ -754,8 +793,8 @@ cdef class Event(object):
cdef Eolian_Event event
cdef _set_obj(self, uintptr_t obj):
self.event = <Eolian_Event>obj
cdef _set_obj(self, Eolian_Event obj):
self.event = obj
def __init__(self):
pass
@ -790,6 +829,6 @@ def type_find_by_alias(alias):
"""
if isinstance(alias, unicode): alias = PyUnicode_AsUTF8String(alias)
return eolian_obj_to_python_obj(
<uintptr_t>eolian_type_find_by_alias(alias), Type
return eolian_type_to_python_obj(
eolian_type_find_by_alias(alias)
)