mirror of
https://github.com/chatmail/core.git
synced 2026-04-19 06:26:30 +03:00
Handle new Context creation API on the FFI
This adopts the FFI API to use the new Context::new() and Contest::drop() Rust-style APIs while preserving the semantics of the existing FFI API. It introduces a wrapper around the context which keeps an optional reference to the actual context, changing dc_open() and dc_close() to create/destroy the actual reference. This changes the events emitted on closing slightly: they only get emitted when dc_close() was called while the context was open. While dc_close() remains idempotent in that it can still be called safely multiple times, the close events will only occur if the context is actually closed.
This commit is contained in:
committed by
Floris Bruynooghe
parent
afc9a31080
commit
a3f64d4e95
@@ -393,8 +393,9 @@ int dc_set_config (dc_context_t* context, const char*
|
||||
* @memberof dc_context_t
|
||||
* @param context The context object as created by dc_context_new(). For querying system values, this can be NULL.
|
||||
* @param key The key to query.
|
||||
* @return Returns current value of "key", if "key" is unset, the default value is returned.
|
||||
* The returned value must be free()'d, NULL is never returned.
|
||||
* @return Returns current value of "key", if "key" is unset, the default
|
||||
* value is returned. The returned value must be free()'d, NULL is never
|
||||
* returned. If there is an error an empty string will be returned.
|
||||
*/
|
||||
char* dc_get_config (dc_context_t* context, const char* key);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,11 +17,19 @@ def test_callback_None2int():
|
||||
clear_context_callback(ctx)
|
||||
|
||||
|
||||
def test_dc_close_events():
|
||||
ctx = capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL)
|
||||
def test_dc_close_events(tmpdir):
|
||||
ctx = ffi.gc(
|
||||
capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL),
|
||||
lib.dc_context_unref,
|
||||
)
|
||||
evlog = EventLogger(ctx)
|
||||
evlog.set_timeout(5)
|
||||
set_context_callback(ctx, lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2))
|
||||
set_context_callback(
|
||||
ctx,
|
||||
lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2)
|
||||
)
|
||||
p = tmpdir.join("hello.db")
|
||||
lib.dc_open(ctx, p.strpath.encode("ascii"), ffi.NULL)
|
||||
capi.lib.dc_close(ctx)
|
||||
|
||||
def find(info_string):
|
||||
|
||||
@@ -237,7 +237,6 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::test_utils::*;
|
||||
|
||||
|
||||
use crate::constants::DC_CONTACT_ID_SELF;
|
||||
use crate::types::uintptr_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user