Skip to content

Commit a13192e

Browse files
committed
eapi: convert Eapi.from_ptr() to return pre-created objects from EAPIS
And internalize the actual Eapi object creation function.
1 parent da3528b commit a13192e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/pkgcraft/eapi.pyx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ cdef list eapis_to_list(const C.Eapi **c_eapis, size_t length, int start=0):
3030
"""Convert an array of Eapi pointers to a list of Eapi objects."""
3131
eapis = []
3232
for i in range(start, length):
33-
eapis.append(Eapi.from_ptr(c_eapis[i]))
33+
eapis.append(eapi_from_ptr(c_eapis[i]))
3434
return eapis
3535

3636

@@ -58,19 +58,27 @@ cdef object get_eapis():
5858
return MappingProxyType(d)
5959

6060

61+
cdef Eapi eapi_from_ptr(const C.Eapi *ptr):
62+
"""Create an Eapi from a pointer."""
63+
obj = <Eapi>Eapi.__new__(Eapi)
64+
obj.ptr = ptr
65+
c_str = C.pkgcraft_eapi_as_str(ptr)
66+
id = c_str.decode()
67+
C.pkgcraft_str_free(c_str)
68+
obj._id = id
69+
return obj
70+
71+
6172
@cython.final
6273
cdef class Eapi(_IndirectInit):
6374

6475
@staticmethod
6576
cdef Eapi from_ptr(const C.Eapi *ptr):
66-
"""Create an Eapi from a pointer."""
67-
obj = <Eapi>Eapi.__new__(Eapi)
68-
obj.ptr = ptr
77+
"""Return a known Eapi object for a given pointer."""
6978
c_str = C.pkgcraft_eapi_as_str(ptr)
7079
id = c_str.decode()
7180
C.pkgcraft_str_free(c_str)
72-
obj._id = id
73-
return obj
81+
return EAPIS[id]
7482

7583
@staticmethod
7684
def range(str s not None):

0 commit comments

Comments
 (0)