Skip to content

Commit 17e7283

Browse files
author
Matteo Fusi
committed
FFI: remove legacy callback
1 parent 32539dd commit 17e7283

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/buildFFI.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def make_ffi(name, headers, libraries, includes=[], extra_header=""):
2525
# Define C declarations
2626
ffi.cdef(header_content)
2727

28+
ffi.cdef("""
29+
extern "Python" void iter_callback(void*, char*, char*);
30+
""")
31+
2832
# Set the C source file
2933
ffi.set_source(name, '''
3034
#include "nix_api_util.h"

src/nix/store.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ def build(self, path: StorePath | str) -> dict[str, str]:
8080
path = self._ensure_store_path(path)
8181
res = {}
8282

83-
# todo extern "Python"
84-
@ffi.callback("void(void*, char*, char*)")
83+
@ffi.def_extern()
8584
def iter_callback(userdata: CData, key: CData, path: CData) -> None:
86-
res[ffi.string(key).decode()] = ffi.string(path).decode()
85+
ud = ffi.from_handle(userdata)
86+
k = ffi.from_handle(key)
87+
p = ffi.from_handle(path)
88+
res[k.decode()] = p.decode()
8789

88-
lib.nix_store_build(self._store, path._path, ffi.NULL, iter_callback)
90+
lib.nix_store_build(self._store, path._path, ffi.NULL, lib_unwrapped.iter_callback)
8991
return res

0 commit comments

Comments
 (0)