From 07497f7f885db23ce3526a0d4d73dbcd3775c2dd Mon Sep 17 00:00:00 2001 From: mmckerns Date: Tue, 13 Jan 2015 14:23:00 +0000 Subject: [PATCH] added `HAS_PYTHONAPI` for compatibilty with newer versions of `pypy` git-svn-id: svn+ssh://svn.mystic.cacr.caltech.edu/pathos/dill@732 8bfda07e-5b16-0410-ab1d-fd04ec2748df --- dill/dill.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/dill/dill.py b/dill/dill.py index dea7150e..19da0848 100644 --- a/dill/dill.py +++ b/dill/dill.py @@ -78,8 +78,10 @@ def _trace(boolean): try: import ctypes HAS_CTYPES = True + HAS_PYTHONAPI = True except ImportError: HAS_CTYPES = False + HAS_PYTHONAPI = False try: from numpy import ufunc as NumpyUfuncType from numpy import ndarray as NumpyArrayType @@ -524,12 +526,16 @@ def __getattribute__(self, attr): attrs[index] = ".".join([attrs[index], attr]) return type(self)(attrs, index) -if HAS_CTYPES: - ctypes.pythonapi.PyCell_New.restype = ctypes.py_object - ctypes.pythonapi.PyCell_New.argtypes = [ctypes.py_object] - # thanks to Paul Kienzle for cleaning the ctypes CellType logic - def _create_cell(contents): - return ctypes.pythonapi.PyCell_New(contents) +if HAS_CTYPES and HAS_PYTHONAPI: + try: # if using `pypi`, pythonapi is not found + ctypes.pythonapi.PyCell_New.restype = ctypes.py_object + ctypes.pythonapi.PyCell_New.argtypes = [ctypes.py_object] + # thanks to Paul Kienzle for cleaning the ctypes CellType logic + def _create_cell(contents): + return ctypes.pythonapi.PyCell_New(contents) + + except AttributeError: + HAS_PYTHONAPI = False def _create_weakref(obj, *args): from weakref import ref @@ -819,7 +825,7 @@ def save_wrapper_descriptor(pickler, obj): obj.__repr__()), obj=obj) return -if HAS_CTYPES: +if HAS_CTYPES and HAS_PYTHONAPI: @register(CellType) def save_cell(pickler, obj): log.info("Ce: %s" % obj)