mirror of
https://github.com/chatmail/core.git
synced 2026-04-06 07:32:12 +03:00
* 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
20 lines
483 B
Python
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")
|