Author: Armin Rigo <ar...@tunes.org> Branch: cffi-handle-lifetime Changeset: r80116:7ba53dd4f845 Date: 2015-10-11 22:26 +0100 http://bitbucket.org/pypy/pypy/changeset/7ba53dd4f845/
Log: crash cleanly if we manage to detect a bogus or dead object diff --git a/pypy/module/_cffi_backend/handle.py b/pypy/module/_cffi_backend/handle.py --- a/pypy/module/_cffi_backend/handle.py +++ b/pypy/module/_cffi_backend/handle.py @@ -1,6 +1,7 @@ import py from pypy.interpreter.error import OperationError, oefmt from pypy.interpreter.gateway import unwrap_spec +from pypy.interpreter.baseobjspace import W_Root from pypy.module._cffi_backend import ctypeobj, ctypeptr, cdataobj from rpython.rtyper.lltypesystem import lltype, llmemory, rffi from rpython.rlib import rweaklist, objectmodel, jit @@ -53,5 +54,10 @@ if not gcref: raise oefmt(space.w_RuntimeError, "cannot use from_handle() on NULL pointer") - cd = annlowlevel.cast_gcref_to_instance(cdataobj.W_CDataHandle, gcref) + cd = annlowlevel.cast_gcref_to_instance(W_Root, gcref) + # force an 'isinstance', to crash clearly if the handle is + # dead or bogus + if not isinstance(cd, cdataobj.W_CDataHandle): + raise oefmt(space.w_SystemError, + "ffi.from_handle(): dead or bogus object handle") return cd.w_keepalive _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit