mirror of
https://github.com/capnproto/pycapnp.git
synced 2025-03-04 16:35:04 +01:00
Store Builders by value rather than allocate them separately on the heap (matches treatment of Readers). v0.3 fixes the bug that made this not work.
This commit is contained in:
parent
86b742e91d
commit
6731d7eb7d
2 changed files with 12 additions and 15 deletions
|
@ -241,18 +241,15 @@ cdef class _DynamicListBuilder:
|
|||
for phone in phones:
|
||||
print phone.number
|
||||
"""
|
||||
cdef C_DynamicList.Builder * thisptr
|
||||
cdef C_DynamicList.Builder thisptr
|
||||
cdef public object _parent
|
||||
cdef _init(self, C_DynamicList.Builder other, object parent):
|
||||
self.thisptr = new C_DynamicList.Builder(other)
|
||||
self.thisptr = other
|
||||
self._parent = parent
|
||||
return self
|
||||
|
||||
def __dealloc__(self):
|
||||
del self.thisptr
|
||||
|
||||
cdef _get(self, index) except +ValueError:
|
||||
return toPython(deref(self.thisptr)[index], self._parent)
|
||||
return toPython(self.thisptr[index], self._parent)
|
||||
|
||||
def __getitem__(self, index):
|
||||
size = self.thisptr.size()
|
||||
|
@ -377,11 +374,11 @@ cdef class _DynamicListBuilder:
|
|||
return _DynamicOrphan()._init(self.thisptr.disown(index), self._parent)
|
||||
|
||||
def __str__(self):
|
||||
return printListBuilder(deref(self.thisptr)).flatten().cStr()
|
||||
return printListBuilder(self.thisptr).flatten().cStr()
|
||||
|
||||
def __repr__(self):
|
||||
# TODO: Print the list type.
|
||||
return '<capnp list builder %s>' % strListBuilder(deref(self.thisptr)).cStr()
|
||||
return '<capnp list builder %s>' % strListBuilder(self.thisptr).cStr()
|
||||
|
||||
cdef class _List_NestedNode_Reader:
|
||||
cdef List[C_Node.NestedNode].Reader thisptr
|
||||
|
@ -526,16 +523,13 @@ cdef class _DynamicStructBuilder:
|
|||
setattr(person, 'field-with-hyphens', 'foo') # for names that are invalid for python, use setattr
|
||||
print getattr(person, 'field-with-hyphens') # for names that are invalid for python, use getattr
|
||||
"""
|
||||
cdef C_DynamicStruct.Builder * thisptr
|
||||
cdef C_DynamicStruct.Builder thisptr
|
||||
cdef public object _parent
|
||||
cdef _init(self, C_DynamicStruct.Builder other, object parent):
|
||||
self.thisptr = new C_DynamicStruct.Builder(other)
|
||||
self.thisptr = other
|
||||
self._parent = parent
|
||||
return self
|
||||
|
||||
def __dealloc__(self):
|
||||
del self.thisptr
|
||||
|
||||
cdef _get(self, field) except +ValueError:
|
||||
return toPython(self.thisptr.get(field), self._parent)
|
||||
|
||||
|
@ -731,10 +725,10 @@ cdef class _DynamicStructBuilder:
|
|||
return list(self.schema.fieldnames)
|
||||
|
||||
def __str__(self):
|
||||
return printStructBuilder(deref(self.thisptr)).flatten().cStr()
|
||||
return printStructBuilder(self.thisptr).flatten().cStr()
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s builder %s>' % (self.schema.node.displayName, strStructBuilder(deref(self.thisptr)).cStr())
|
||||
return '<%s builder %s>' % (self.schema.node.displayName, strStructBuilder(self.thisptr).cStr())
|
||||
|
||||
cdef class _DynamicOrphan:
|
||||
cdef C_DynamicOrphan thisptr
|
||||
|
|
|
@ -99,6 +99,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
|||
StructSchema getSchema()
|
||||
Maybe[StructSchema.Field] which()
|
||||
cppclass Builder:
|
||||
Builder()
|
||||
Builder(Builder &)
|
||||
DynamicValueForward.Builder get(char *)
|
||||
bint has(char *) except +ValueError
|
||||
|
@ -125,6 +126,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
|||
DynamicValueForward.Reader operator[](uint) except +ValueError
|
||||
uint size()
|
||||
cppclass Builder:
|
||||
Builder()
|
||||
Builder(Builder &)
|
||||
DynamicValueForward.Builder operator[](uint)
|
||||
uint size()
|
||||
|
@ -167,6 +169,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp":
|
|||
Data.Reader asData"as< ::capnp::Data>"()
|
||||
|
||||
cppclass Builder:
|
||||
Builder()
|
||||
Type getType()
|
||||
int64_t asInt"as<int64_t>"()
|
||||
uint64_t asUint"as<uint64_t>"()
|
||||
|
|
Loading…
Add table
Reference in a new issue