[pypy-dev] fail about resumable hashlib code under pypy
KaShining
mail2shine at qq.com
Fri Nov 8 09:02:32 CET 2013
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20131108/a608ef7a/attachment.html>
More information about the pypy-dev
mailing list