[pypy-commit] pypy cffi-handle-lifetime: crash cleanly if we manage to detect a bogus or dead object
arigo
noreply at buildbot.pypy.org
Sun Oct 11 23:22:33 CEST 2015
Author: Armin Rigo <arigo at 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
More information about the pypy-commit
mailing list