Skip to content

Commit

Permalink
Delay contract checks until after all functions are defined
Browse files Browse the repository at this point in the history
Otherwise we might call it with the wrong ABI.
This so far wasn't an issue on platforms UniFFI tests on,
but can be observed on Windows (at leats in Wine),
where suddenly the checksums won't match, e.g.
39784 is expected, but the call gets 33135464 back.
The former is 0x9b68 and fits well within a 16-bit unsigned integer.
The latter is 0x1f99b68 which does not fit (but it has the same suffix,
guess why...)
  • Loading branch information
badboy committed Jun 22, 2023
1 parent 68107e3 commit 6938c26
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ def loadIndirect():
libname = libname.format("{{ config.cdylib_name() }}")
path = str(Path(__file__).parent / libname)
lib = ctypes.cdll.LoadLibrary(path)
uniffi_check_contract_api_version(lib)
uniffi_check_api_checksums(lib)
return lib

def uniffi_check_contract_api_version(lib):
Expand Down Expand Up @@ -82,3 +80,6 @@ def uniffi_check_api_checksums(lib):
)
_UniFFILib.{{ func.name() }}.restype = {% match func.return_type() %}{% when Some with (type_) %}{{ type_|ffi_type_name }}{% when None %}None{% 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)

0 comments on commit 6938c26

Please sign in to comment.