PyPy objects are not implemented like this. This is an evil and atrocious hack to get the refcount and pyobjects stuff from python level using ctypes. works only on cpython.
On Fri, Nov 8, 2013 at 10:02 AM, KaShining <mail2sh...@qq.com> wrote: > Here is my test.py about resumable-hashlib: > > from ctypes import * > import hashlib > > PyObject_HEAD = [ > ('ob_refcnt', c_size_t), > ('ob_type', c_void_p), > ] > > class EVP_MD(Structure): > _fields_ = [ > ('type', c_int), > ('pkey_type', c_int), > ('md_size', c_int), > ('flags', c_ulong), > ('init', c_void_p), > ('update', c_void_p), > ('final', c_void_p), > ('copy', c_void_p), > ('cleanup', c_void_p), > ('sign', c_void_p), > ('verify', c_void_p), > ('required_pkey_type', c_int*5), > ('block_size', c_int), > ('ctx_size', c_int), > ] > > class EVP_MD_CTX(Structure): > _fields_ = [ > ('digest', POINTER(EVP_MD)), > ('engine', c_void_p), > ('flags', c_ulong), > ('md_data', POINTER(c_char)), > ] > > class EVPobject(Structure): > _fields_ = PyObject_HEAD + [ > ('name', py_object), > ('ctx', EVP_MD_CTX), > ] > > #import string > > # str4096 = random_str(4096) > str4096 = 'sssss' > > hash2 = hashlib.sha1() > c_evp_obj = cast(c_void_p(id(hash2)), POINTER(EVPobject)).contents > ctx = c_evp_obj.ctx > digest = ctx.digest.contents > state = ctx.md_data[:digest.ctx_size] > #print digest.ctx_size > > Pass in cpython while fail in pypy: > > Traceback (most recent call last): > File "app_main.py", line 72, in run_toplevel > File "t.py", line 49, in <module> > digest = ctx.digest.contents > File "/opt/pypy2.1/lib_pypy/_ctypes/pointer.py", line 83, in getcontents > raise ValueError("NULL pointer access") > ValueError: NULL pointer access > > > > > _______________________________________________ > pypy-dev mailing list > pypy-dev@python.org > https://mail.python.org/mailman/listinfo/pypy-dev > _______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev