Commit 20ba8ae6 authored by Lysander Trischler's avatar Lysander Trischler
Browse files

Don't duplicate twter for every parsed twt

Again, as in the previous commit, there's no need to duplicate the
author of a twt for each and every twt in the C bridge. The Python
binding can take care of that easily itself.
parent 87b2b4ed
......@@ -214,17 +214,14 @@ class Twt:
class _Twt(ctypes.Structure):
_fields_ = [("twter", ctypes.POINTER(_Twter)),
("created", ctypes.c_char_p),
_fields_ = [("created", ctypes.c_char_p),
("hash", ctypes.c_char_p),
("subject", ctypes.POINTER(_Subject)),
("elems_len", ctypes.c_int),
("elems", ctypes.POINTER(ctypes.POINTER(_Elem)))]
def to_python(self):
twt = Twt()
if self.twter is not None:
twt.twter = self.twter.contents.to_python()
def to_python(self, twter=None):
twt = Twt(twter=twter)
if self.created is not None:
twt.created = datetime.datetime.fromisoformat(self.created.decode("utf-8"))
if self.hash is not None:
......@@ -278,7 +275,7 @@ class _TwtFile(ctypes.Structure):
twtfile.twts = []
for i in range(self.twts_len):
twtfile.twts.append(self.twts[i].contents.to_python())
twtfile.twts.append(self.twts[i].contents.to_python(twter=twtfile.twter))
return twtfile
......
......@@ -32,7 +32,6 @@ struct elem {
};
struct twt {
struct twter *twter;
char *created;
char *hash;
struct subject *subject;
......@@ -154,7 +153,6 @@ func freeTwter(t *C.struct_twter) {
func convertTwt(t *lextwt.Twt) *C.struct_twt {
ptr := C.malloc(C.sizeof_struct_twt)
twt := (*C.struct_twt)(ptr)
twt.twter = convertTwter(t.Twter())
twt.created = C.CString(t.Created().Format(time.RFC3339))
twt.hash = C.CString(t.Hash())
if subject, ok := t.Subject().(*lextwt.Subject); ok && subject != nil {
......@@ -176,7 +174,6 @@ func convertTwt(t *lextwt.Twt) *C.struct_twt {
func freeTwt(t *C.struct_twt) {
if t != nil {
freeTwter(t.twter)
free_string(t.created)
free_string(t.hash)
freeSubject(t.subject)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment