pypy comes with normal hashlib. it just works like cpython one.

On Fri, Nov 8, 2013 at 10:55 AM, KaShining <mail2sh...@qq.com> wrote:
> ok.
> Can i see any demo code about hashlib-pypy ??
>
>
> ------------------ 原始邮件 ------------------
> 发件人: "Maciej Fijalkowski";<fij...@gmail.com>;
> 发送时间: 2013年11月8日(星期五) 下午4:51
> 收件人: "KaShining"<mail2sh...@qq.com>;
> 抄送: "pypy-dev"<pypy-dev@python.org>;
> 主题: Re: 回复: [pypy-dev] fail about resumable hashlib code under pypy
>
> this can work, but these days we have implemented hashlib differently., why?
>
> On Fri, Nov 8, 2013 at 10:49 AM, KaShining <mail2sh...@qq.com> wrote:
>> Maybe this way can work:
>>
>> https://bitbucket.org/pypy/pypy/src/cli-jit/pypy/lib/_hashlib.py?at=cli-jit
>>
>>
>> ------------------ 原始邮件 ------------------
>> 发件人: "Maciej Fijalkowski";<fij...@gmail.com>;
>> 发送时间: 2013年11月8日(星期五) 下午4:47
>> 收件人: "KaShining"<mail2sh...@qq.com>;
>> 抄送: "pypy-dev"<pypy-dev@python.org>;
>> 主题: Re: [pypy-dev] fail about resumable hashlib code under pypy
>>
>> 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

Reply via email to