@@ -64,9 +64,7 @@ cdef class Dependency:
6464 if ptr is NULL :
6565 raise PkgcraftError
6666
67- self .set = DependencySetKind(ptr.set)
68- self .kind = DependencyKind(ptr.kind)
69- self .ptr = ptr
67+ Dependency.from_ptr(ptr, self )
7068
7169 @classmethod
7270 def package (cls , s: str = None , eapi: Eapi | str = None ):
@@ -99,9 +97,10 @@ cdef class Dependency:
9997 return cls (s, set = DependencySetKind.SrcUri)
10098
10199 @staticmethod
102- cdef Dependency from_ptr(C.Dependency * ptr):
100+ cdef Dependency from_ptr(C.Dependency * ptr, Dependency inst = None ):
103101 """ Create a Dependency from a pointer and type."""
104- inst = < Dependency> Dependency.__new__ (Dependency)
102+ if inst is None :
103+ inst = < Dependency> Dependency.__new__ (Dependency)
105104 inst.set = DependencySetKind(ptr.set)
106105 inst.kind = DependencyKind(ptr.kind)
107106 inst.ptr = ptr
@@ -229,8 +228,7 @@ cdef class DependencySet:
229228 if ptr is NULL :
230229 raise PkgcraftError
231230
232- self .set = DependencySetKind(ptr.set)
233- self .ptr = ptr
231+ DependencySet.from_ptr(ptr, self )
234232
235233 @classmethod
236234 def package (cls , s: str = None , eapi: Eapi | str = None ):
@@ -263,9 +261,10 @@ cdef class DependencySet:
263261 return cls (s, set = DependencySetKind.SrcUri)
264262
265263 @staticmethod
266- cdef DependencySet from_ptr(C.DependencySet * ptr):
264+ cdef DependencySet from_ptr(C.DependencySet * ptr, DependencySet inst = None ):
267265 """ Create a DependencySet from a pointer."""
268- inst = < DependencySet> DependencySet.__new__ (DependencySet)
266+ if inst is None :
267+ inst = < DependencySet> DependencySet.__new__ (DependencySet)
269268 inst.set = DependencySetKind(ptr.set)
270269 inst.ptr = ptr
271270 return inst
@@ -527,12 +526,11 @@ cdef class MutableDependencySet(DependencySet):
527526 """ Mutable set of dependency objects."""
528527
529528 @staticmethod
530- cdef MutableDependencySet from_ptr(C.DependencySet * ptr):
529+ cdef MutableDependencySet from_ptr(C.DependencySet * ptr, DependencySet inst = None ):
531530 """ Create a MutableDependencySet from a pointer."""
532- inst = < MutableDependencySet> MutableDependencySet.__new__ (MutableDependencySet)
533- inst.set = DependencySetKind(ptr.set)
534- inst.ptr = ptr
535- return inst
531+ if inst is None :
532+ inst = < MutableDependencySet> MutableDependencySet.__new__ (MutableDependencySet)
533+ return DependencySet.from_ptr(ptr, inst)
536534
537535 def sort (self ):
538536 """ Recursively sort a DependencySet.
0 commit comments