Change the class lookup code to C only using an Eina Hash table.
This commit is contained in:
parent
f607d989a1
commit
21ec3e18cf
|
@ -15,10 +15,12 @@
|
||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
|
# along with this Python-EFL. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from cpython cimport PyObject, Py_INCREF, Py_DECREF#, PyMem_Malloc, PyMem_Free
|
from cpython cimport PyObject, Py_INCREF, Py_DECREF
|
||||||
from libc.stdlib cimport malloc, free
|
from libc.stdlib cimport malloc, free
|
||||||
from libc.string cimport memcpy, strdup
|
from libc.string cimport memcpy, strdup
|
||||||
from efl cimport Eina_Bool, const_Eina_List, eina_list_append, const_void
|
from efl cimport Eina_Bool, const_Eina_List, eina_list_append, const_void, \
|
||||||
|
Eina_Hash, eina_hash_string_superfast_new, eina_hash_add, eina_hash_del, \
|
||||||
|
eina_hash_find
|
||||||
from efl.c_eo cimport Eo as cEo
|
from efl.c_eo cimport Eo as cEo
|
||||||
from efl.c_eo cimport eo_init, eo_shutdown, eo_del, eo_unref, eo_wref_add, eo_add, Eo_Class
|
from efl.c_eo cimport eo_init, eo_shutdown, eo_del, eo_unref, eo_wref_add, eo_add, Eo_Class
|
||||||
from efl.c_eo cimport eo_do, eo_class_name_get, eo_class_get
|
from efl.c_eo cimport eo_do, eo_class_name_get, eo_class_get
|
||||||
|
@ -208,22 +210,27 @@ cdef void _METHOD_DEPRECATED(object self, char *message):
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Object mapping is a dictionary into which object type names can be
|
Object mapping is an Eina Hash table into which object type names can be
|
||||||
registered. These can be used to find a bindings class for an object using
|
registered. These can be used to find a bindings class for an object using
|
||||||
the object_from_instance function.
|
the object_from_instance function."""
|
||||||
"""
|
cdef Eina_Hash *object_mapping = eina_hash_string_superfast_new(NULL)
|
||||||
cdef dict object_mapping = dict()
|
|
||||||
|
|
||||||
|
|
||||||
cdef void _object_mapping_register(str name, object cls) except *:
|
cdef void _object_mapping_register(char *name, object cls) except *:
|
||||||
# print("REGISTER: %s => %s" % (name, cls))
|
cdef void *value
|
||||||
if name in object_mapping:
|
|
||||||
|
#print("REGISTER: %s => %s" % (name, cls))
|
||||||
|
|
||||||
|
value = eina_hash_find(object_mapping, name)
|
||||||
|
|
||||||
|
if value == NULL:
|
||||||
|
eina_hash_add(object_mapping, name, <PyObject *>cls)
|
||||||
|
else:
|
||||||
raise ValueError("Object type name '%s' already registered." % name)
|
raise ValueError("Object type name '%s' already registered." % name)
|
||||||
object_mapping[name] = cls
|
|
||||||
|
|
||||||
|
|
||||||
cdef void _object_mapping_unregister(str name):
|
cdef void _object_mapping_unregister(char *name):
|
||||||
object_mapping.pop(name)
|
eina_hash_del(object_mapping, name, NULL)
|
||||||
|
|
||||||
|
|
||||||
cdef object object_from_instance(cEo *obj):
|
cdef object object_from_instance(cEo *obj):
|
||||||
|
@ -232,27 +239,28 @@ cdef object object_from_instance(cEo *obj):
|
||||||
void *data
|
void *data
|
||||||
Eo o
|
Eo o
|
||||||
const_char *cls_name
|
const_char *cls_name
|
||||||
object cls
|
type cls
|
||||||
|
|
||||||
if obj == NULL:
|
if obj == NULL:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
eo_do(obj, eo_base_data_get("python-eo", &data))
|
eo_do(obj, eo_base_data_get("python-eo", &data))
|
||||||
if data != NULL:
|
if data != NULL:
|
||||||
# print("Found: %s" % Eo.__repr__(<Eo>data))
|
#print("Found: %s" % Eo.__repr__(<Eo>data))
|
||||||
return <Eo>data
|
return <Eo>data
|
||||||
|
|
||||||
cls_name = eo_class_name_get(eo_class_get(obj))
|
cls_name = eo_class_name_get(eo_class_get(obj))
|
||||||
if cls_name == NULL:
|
if cls_name == NULL:
|
||||||
raise ValueError("Eo object %#x does not have a type!" % <long>obj)
|
raise ValueError("Eo object %#x does not have a type!" % <long>obj)
|
||||||
# print("Class name: %s" % cls_name)
|
#print("Class name: %s" % cls_name)
|
||||||
|
|
||||||
|
cls = <type>eina_hash_find(object_mapping, cls_name)
|
||||||
|
|
||||||
cls = object_mapping.get(cls_name, None)
|
|
||||||
if cls is None:
|
if cls is None:
|
||||||
raise ValueError("Eo object %#x of type %s does not have a mapping!" %
|
raise ValueError("Eo object %#x of type %s does not have a mapping!" %
|
||||||
(<long>obj, cls_name))
|
(<long>obj, cls_name))
|
||||||
|
|
||||||
# print "MAPPING OBJECT:", cls_name, "=>", cls
|
#print "MAPPING OBJECT:", cls_name, "=>", cls
|
||||||
o = cls.__new__(cls)
|
o = cls.__new__(cls)
|
||||||
o._set_obj(obj)
|
o._set_obj(obj)
|
||||||
return o
|
return o
|
||||||
|
|
|
@ -32,8 +32,8 @@ cdef class Eo(object):
|
||||||
cdef int PY_REFCOUNT(object o)
|
cdef int PY_REFCOUNT(object o)
|
||||||
|
|
||||||
cdef object object_from_instance(cEo *obj)
|
cdef object object_from_instance(cEo *obj)
|
||||||
cdef void _object_mapping_register(str name, object cls) except *
|
cdef void _object_mapping_register(char *name, object cls) except *
|
||||||
cdef void _object_mapping_unregister(str name)
|
cdef void _object_mapping_unregister(char *name)
|
||||||
|
|
||||||
cdef unicode _touni(char* s)
|
cdef unicode _touni(char* s)
|
||||||
cdef char* _fruni(s)
|
cdef char* _fruni(s)
|
||||||
|
|
|
@ -76,6 +76,8 @@ cdef extern from "Eina.h":
|
||||||
void *accounting
|
void *accounting
|
||||||
ctypedef Eina_List const_Eina_List "const Eina_List"
|
ctypedef Eina_List const_Eina_List "const Eina_List"
|
||||||
|
|
||||||
|
ctypedef struct Eina_Hash
|
||||||
|
|
||||||
ctypedef struct Eina_Hash_Tuple:
|
ctypedef struct Eina_Hash_Tuple:
|
||||||
void *key
|
void *key
|
||||||
void *data
|
void *data
|
||||||
|
@ -91,6 +93,7 @@ cdef extern from "Eina.h":
|
||||||
# Other typedefs
|
# Other typedefs
|
||||||
#
|
#
|
||||||
ctypedef int (*Eina_Compare_Cb)(const_void *data1, const_void *data2)
|
ctypedef int (*Eina_Compare_Cb)(const_void *data1, const_void *data2)
|
||||||
|
ctypedef void (*Eina_Free_Cb)(void *data)
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
# Functions
|
# Functions
|
||||||
|
@ -144,3 +147,8 @@ cdef extern from "Eina.h":
|
||||||
Eina_List *eina_list_prev(Eina_List *list)
|
Eina_List *eina_list_prev(Eina_List *list)
|
||||||
void *eina_list_data_get(Eina_List *list)
|
void *eina_list_data_get(Eina_List *list)
|
||||||
unsigned int eina_list_count(Eina_List *list)
|
unsigned int eina_list_count(Eina_List *list)
|
||||||
|
|
||||||
|
Eina_Hash *eina_hash_string_superfast_new(Eina_Free_Cb data_free_cb)
|
||||||
|
Eina_Bool eina_hash_add(Eina_Hash *hash, const_void *key, const_void *data)
|
||||||
|
Eina_Bool eina_hash_del(Eina_Hash *hash, const_void *key, const_void *data)
|
||||||
|
void *eina_hash_find(Eina_Hash *hash, const_void *key)
|
||||||
|
|
Loading…
Reference in New Issue