Skip to content

Commit

Permalink
Remove ctypes so it can work with no dynamic linking builds (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane authored Oct 5, 2023
1 parent 3c228fd commit 0ad4fd3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pytest_pyodide/_decorator_in_pyodide.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
https://github.com/pyodide/pytest-pyodide/issues/43
"""

import ctypes
import pickle
from base64 import b64decode, b64encode
from io import BytesIO
from typing import Any

import pyodide_js


def pointer_to_object(ptr: int) -> Any:
"""Interpret ptr as a PyObject* and convert it to the actual Python object.
Expand All @@ -32,7 +33,7 @@ def pointer_to_object(ptr: int) -> Any:
# object: use PyObject_SetItem to assign it to a dictionary.
# ctypes doesn't seem to have an API to do this directly.
temp: dict[int, Any] = {}
ctypes.pythonapi.PyObject_SetItem(id(temp), id(0), ptr)
pyodide_js._module._PyDict_SetItem(id(temp), id(0), ptr)
return temp[0]


Expand All @@ -55,7 +56,7 @@ class Pickler(pickle.Pickler):
def persistent_id(self, obj: Any) -> Any:
if not isinstance(obj, PyodideHandle):
return None
ctypes.pythonapi.Py_IncRef(obj.ptr)
pyodide_js._module._Py_IncRef(obj.ptr)
return ("PyodideHandle", obj.ptr)


Expand Down

0 comments on commit 0ad4fd3

Please sign in to comment.