Skip to content

Commit bc9889f

Browse files
committed
Support wrapper generation with 4 parameter constructors for backward compat with swift wrappers.
1 parent a765436 commit bc9889f

File tree

6 files changed

+177
-57
lines changed

6 files changed

+177
-57
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
__pycache__/
2+
.vscode/
3+
4+
15
*.gz
26
*.zip
37
*.pyc

refcount/interop.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ def create_wrapper(self, obj: Any, type_id: str, release_native: Optional[Callab
504504
else:
505505
s = signature(wrapper_type)
506506
n = len(s.parameters)
507+
parameters = [v for k, v in s.parameters.items()]
508+
# [<Parameter "handle: Any">, <Parameter "release_native: Callable[[Any], NoneType]">, <Parameter "type_id: Optional[str] = None">, <Parameter "prior_ref_count: int = 0">]
507509
if n == 0:
508510
raise TypeError("Wrapper constructor must have at least one argument")
509511
elif n == 1:
@@ -516,8 +518,12 @@ def create_wrapper(self, obj: Any, type_id: str, release_native: Optional[Callab
516518
if release_native is None:
517519
raise ValueError(f"Wrapper class '{type(wrapper_type)}' has three constructor arguments; the argument 'release_native' cannot be None")
518520
return wrapper_type(obj, release_native, type_id)
521+
elif n == 4:
522+
if parameters[3].default == parameters[3].empty:
523+
raise ValueError(f"Wrapper class '{type(wrapper_type)}' has four constructor arguments; the last argument 'prior_ref_count' must have a default value")
524+
return wrapper_type(obj, release_native, type_id)
519525
else:
520-
raise NotImplementedError("Wrapper constructors with more than 3 arguments are not yet supported")
526+
raise NotImplementedError("Wrapper constructors with more than 4 arguments are not yet supported")
521527

522528

523529
WrapperCreationFunction = Callable[[Any, str, Callable], DeletableCffiNativeHandle]

tests/Readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ If you want to explore the unit tests e.g. in debug mode from your IDE, you can
55
on Linux:
66

77
```sh
8-
cd tests
9-
cd test_native_library
10-
cmake -Bbuild .
8+
cd $HOME/src/pyrefcount/tests/test_native_library
9+
# rm -rf CMakeFiles/ Makefile CMakeCache.txt cmake_install.cmake
10+
cmake -DCMAKE_BUILD_TYPE=DEBUG -Bbuild .
1111
cmake --build build
1212
```
1313

0 commit comments

Comments
 (0)