Files
chatmail-core/python/src/deltachat/cutil.py
Friedel Ziegelmayer 8c10aa287c fix(python): free allocated string pointers (#393)
* fix(python): free allocated string pointers

* Update python/src/deltachat/cutil.py

Co-Authored-By: holger krekel  <holger@merlinux.eu>

* Update cutil.py

* probably the proper way to handle ffi.strings
2019-08-18 12:45:38 +02:00

20 lines
483 B
Python

from .capi import lib
from .capi import ffi
def as_dc_charpointer(obj):
if obj == ffi.NULL or obj is None:
return ffi.NULL
if not isinstance(obj, bytes):
return obj.encode("utf8")
return obj
def iter_array(dc_array_t, constructor):
for i in range(0, lib.dc_array_get_cnt(dc_array_t)):
yield constructor(lib.dc_array_get_id(dc_array_t, i))
def from_dc_charpointer(obj):
return ffi.string(ffi.gc(obj, lib.dc_str_unref)).decode("utf8")