summaryrefslogtreecommitdiffstats
path: root/third_party/rust/uniffi_bindgen/src/bindings/python/templates/NamespaceLibraryTemplate.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/rust/uniffi_bindgen/src/bindings/python/templates/NamespaceLibraryTemplate.py45
1 files changed, 27 insertions, 18 deletions
diff --git a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/NamespaceLibraryTemplate.py b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/NamespaceLibraryTemplate.py
index fac6cd5564..1929f9aad6 100644
--- a/third_party/rust/uniffi_bindgen/src/bindings/python/templates/NamespaceLibraryTemplate.py
+++ b/third_party/rust/uniffi_bindgen/src/bindings/python/templates/NamespaceLibraryTemplate.py
@@ -1,22 +1,6 @@
# Define some ctypes FFI types that we use in the library
"""
-ctypes type for the foreign executor callback. This is a built-in interface for scheduling
-tasks
-
-Args:
- executor: opaque c_size_t value representing the eventloop
- delay: delay in ms
- task: function pointer to the task callback
- task_data: void pointer to the task callback data
-
-Normally we should call task(task_data) after the detail.
-However, when task is NULL this indicates that Rust has dropped the ForeignExecutor and we should
-decrease the EventLoop refcount.
-"""
-_UNIFFI_FOREIGN_EXECUTOR_CALLBACK_T = ctypes.CFUNCTYPE(ctypes.c_int8, ctypes.c_size_t, ctypes.c_uint32, ctypes.c_void_p, ctypes.c_void_p)
-
-"""
Function pointer for a Rust task, which a callback function that takes a opaque pointer
"""
_UNIFFI_RUST_TASK = ctypes.CFUNCTYPE(None, ctypes.c_void_p, ctypes.c_int8)
@@ -25,7 +9,7 @@ def _uniffi_future_callback_t(return_type):
"""
Factory function to create callback function types for async functions
"""
- return ctypes.CFUNCTYPE(None, ctypes.c_size_t, return_type, _UniffiRustCallStatus)
+ return ctypes.CFUNCTYPE(None, ctypes.c_uint64, return_type, _UniffiRustCallStatus)
def _uniffi_load_indirect():
"""
@@ -72,12 +56,37 @@ def _uniffi_check_api_checksums(lib):
# This is an implementation detail which will be called internally by the public API.
_UniffiLib = _uniffi_load_indirect()
-{%- for func in ci.iter_ffi_function_definitions() %}
+
+{%- for def in ci.ffi_definitions() %}
+{%- match def %}
+{%- when FfiDefinition::CallbackFunction(callback) %}
+{{ callback.name()|ffi_callback_name }} = ctypes.CFUNCTYPE(
+ {%- match callback.return_type() %}
+ {%- when Some(return_type) %}{{ return_type|ffi_type_name }},
+ {%- when None %}None,
+ {%- endmatch %}
+ {%- for arg in callback.arguments() -%}
+ {{ arg.type_().borrow()|ffi_type_name }},
+ {%- endfor -%}
+ {%- if callback.has_rust_call_status_arg() %}
+ ctypes.POINTER(_UniffiRustCallStatus),
+ {%- endif %}
+)
+{%- when FfiDefinition::Struct(ffi_struct) %}
+class {{ ffi_struct.name()|ffi_struct_name }}(ctypes.Structure):
+ _fields_ = [
+ {%- for field in ffi_struct.fields() %}
+ ("{{ field.name()|var_name }}", {{ field.type_().borrow()|ffi_type_name }}),
+ {%- endfor %}
+ ]
+{%- when FfiDefinition::Function(func) %}
_UniffiLib.{{ func.name() }}.argtypes = (
{%- call py::arg_list_ffi_decl(func) -%}
)
_UniffiLib.{{ func.name() }}.restype = {% match func.return_type() %}{% when Some with (type_) %}{{ type_|ffi_type_name }}{% when None %}None{% endmatch %}
+{%- endmatch %}
{%- endfor %}
+
{# Ensure to call the contract verification only after we defined all functions. -#}
_uniffi_check_contract_api_version(_UniffiLib)
_uniffi_check_api_checksums(_UniffiLib)