From a7dfb33ae8858b10e0a5f21edaedf0597610574f Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Sun, 1 Apr 2018 11:17:34 +0200 Subject: ossig: add a C wrapper for PyOS_getsig() instead of accessing the API through ctypes PyPy doesn't support the ctypes.PyDLL interface. The ctypes approach was a bit hacky anyway because the interface for loading the python DLL isn't really documented. --- gi/_ossighelper.py | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) (limited to 'gi/_ossighelper.py') diff --git a/gi/_ossighelper.py b/gi/_ossighelper.py index dc8a8272..5176e97c 100644 --- a/gi/_ossighelper.py +++ b/gi/_ossighelper.py @@ -20,10 +20,11 @@ import os import sys import socket import signal -import ctypes import threading from contextlib import closing, contextmanager +from . import _gi + def ensure_socket_not_inheritable(sock): """Ensures that the socket is not inherited by child processes @@ -139,28 +140,7 @@ def wakeup_on_signal(): _wakeup_fd_is_active = False -def create_pythonapi(): - if not hasattr(ctypes, "PyDLL"): - # PyPy - return - # We need our own instance of ctypes.pythonapi so we don't modify the - # global shared one. Adapted from the ctypes source. - if os.name == "nt": - return ctypes.PyDLL("python dll", None, sys.dllhandle) - elif sys.platform == "cygwin": - return ctypes.PyDLL("libpython%d.%d.dll" % sys.version_info[:2]) - else: - return ctypes.PyDLL(None) - - -pydll = create_pythonapi() -if pydll is None: - PyOS_getsig = lambda s: -1 -else: - PyOS_getsig = pydll.PyOS_getsig - PyOS_getsig.restype = ctypes.c_void_p - PyOS_getsig.argtypes = [ctypes.c_int] - +PyOS_getsig = _gi.pyos_getsig # We save the signal pointer so we can detect if glib has changed the # signal handler behind Python's back (GLib.unix_signal_add) -- cgit v1.2.1