[pypy-svn] pypy improve-unwrap_spec: progress in "hash" modules

amauryfa commits-noreply at bitbucket.org
Wed Feb 16 19:19:21 CET 2011


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: improve-unwrap_spec
Changeset: r42056:8bc2084a78fe
Date: 2011-02-16 11:46 +0100
http://bitbucket.org/pypy/pypy/changeset/8bc2084a78fe/

Log:	progress in "hash" modules

diff --git a/pypy/module/_hashlib/interp_hashlib.py b/pypy/module/_hashlib/interp_hashlib.py
--- a/pypy/module/_hashlib/interp_hashlib.py
+++ b/pypy/module/_hashlib/interp_hashlib.py
@@ -3,7 +3,7 @@
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.interpreter.error import OperationError
 from pypy.tool.sourcetools import func_renamer
-from pypy.interpreter.baseobjspace import Wrappable, W_Root, ObjSpace
+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.rpython.lltypesystem import lltype, rffi
 from pypy.rlib.objectmodel import keepalive_until_here
 from pypy.rlib import ropenssl
@@ -33,20 +33,18 @@
         ropenssl.EVP_MD_CTX_cleanup(self.ctx)
         lltype.free(self.ctx, flavor='raw')
 
-    @unwrap_spec('self', ObjSpace)
     def descr_repr(self, space):
         addrstring = self.getaddrstring(space)
         return space.wrap("<%s HASH object at 0x%s>" % (
             self.name, addrstring))
 
-    @unwrap_spec('self', ObjSpace, 'bufferstr')
+    @unwrap_spec(string='bufferstr')
     def update(self, space, string):
         with rffi.scoped_nonmovingbuffer(string) as buf:
             with self.lock:
                 # XXX try to not release the GIL for small requests
                 ropenssl.EVP_DigestUpdate(self.ctx, buf, len(string))
 
-    @unwrap_spec('self', ObjSpace)
     def copy(self, space):
         "Return a copy of the hash object."
         w_hash = W_Hash(space, self.name)
@@ -54,13 +52,11 @@
             ropenssl.EVP_MD_CTX_copy(w_hash.ctx, self.ctx)
         return w_hash
 
-    @unwrap_spec('self', ObjSpace)
     def digest(self, space):
         "Return the digest value as a string of binary data."
         digest = self._digest(space)
         return space.wrap(digest)
 
-    @unwrap_spec('self', ObjSpace)
     def hexdigest(self, space):
         "Return the digest value as a string of hexadecimal digits."
         digest = self._digest(space)
@@ -132,7 +128,7 @@
     block_size=GetSetProperty(W_Hash.get_block_size),
     )
 
- at unwrap_spec(ObjSpace, str, 'bufferstr')
+ at unwrap_spec(name=str, string='bufferstr')
 def new(space, name, string=''):
     w_hash = W_Hash(space, name)
     w_hash.update(space, string)
@@ -141,7 +137,7 @@
 # shortcut functions
 def make_new_hash(name, funcname):
     @func_renamer(funcname)
-    @unwrap_spec(ObjSpace, 'bufferstr')
+    @unwrap_spec(string='bufferstr')
     def new_hash(space, string=''):
         return new(space, name, string)
     return new_hash

diff --git a/pypy/module/_md5/interp_md5.py b/pypy/module/_md5/interp_md5.py
--- a/pypy/module/_md5/interp_md5.py
+++ b/pypy/module/_md5/interp_md5.py
@@ -1,7 +1,7 @@
 from pypy.rlib import rmd5
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.gateway import interp2app, ObjSpace, W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 
 
 class W_MD5(Wrappable, rmd5.RMD5):
@@ -13,6 +13,7 @@
         self.space = space
         self._init()
 
+    @unwrap_spec(string='bufferstr')
     def update_w(self, string):
         self.update(string)
 
@@ -28,6 +29,7 @@
         return self.space.wrap(clone)
 
 
+ at unwrap_spec(initialdata='bufferstr')
 def W_MD5___new__(space, w_subtype, initialdata=''):
     """
     Create a new md5 object and call its initializer.
@@ -41,12 +43,11 @@
 
 W_MD5.typedef = TypeDef(
     'MD5Type',
-    __new__   = interp2app(W_MD5___new__, unwrap_spec=[ObjSpace, W_Root,
-                                                       'bufferstr']),
-    update    = interp2app(W_MD5.update_w, unwrap_spec=['self', 'bufferstr']),
-    digest    = interp2app(W_MD5.digest_w, unwrap_spec=['self']),
-    hexdigest = interp2app(W_MD5.hexdigest_w, unwrap_spec=['self']),
-    copy      = interp2app(W_MD5.copy_w, unwrap_spec=['self']),
+    __new__   = interp2app(W_MD5___new__),
+    update    = interp2app(W_MD5.update_w),
+    digest    = interp2app(W_MD5.digest_w),
+    hexdigest = interp2app(W_MD5.hexdigest_w),
+    copy      = interp2app(W_MD5.copy_w),
     digest_size = 16,
     digestsize = 16,
     block_size = 64,

diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -2,7 +2,7 @@
 from pypy.interpreter.typedef import (
     TypeDef, GetSetProperty, generic_new_descr, descr_get_dict, descr_set_dict,
     make_weakref_descr)
-from pypy.interpreter.gateway import interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.rlib.rstring import StringBuilder
 

diff --git a/pypy/module/_sha/interp_sha.py b/pypy/module/_sha/interp_sha.py
--- a/pypy/module/_sha/interp_sha.py
+++ b/pypy/module/_sha/interp_sha.py
@@ -1,7 +1,7 @@
 from pypy.rlib import rsha
 from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.gateway import interp2app, ObjSpace, W_Root
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 
 
 class W_SHA(Wrappable, rsha.RSHA):
@@ -13,6 +13,7 @@
         self.space = space
         self._init()
 
+    @unwrap_spec(string='bufferstr')
     def update_w(self, string):
         self.update(string)
 
@@ -28,6 +29,7 @@
         return self.space.wrap(clone)
 
 
+ at unwrap_spec(initialdata='bufferstr')
 def W_SHA___new__(space, w_subtype, initialdata=''):
     """
     Create a new sha object and call its initializer.
@@ -41,12 +43,11 @@
 
 W_SHA.typedef = TypeDef(
     'SHAType',
-    __new__   = interp2app(W_SHA___new__, unwrap_spec=[ObjSpace, W_Root,
-                                                       'bufferstr']),
-    update    = interp2app(W_SHA.update_w, unwrap_spec=['self', 'bufferstr']),
-    digest    = interp2app(W_SHA.digest_w, unwrap_spec=['self']),
-    hexdigest = interp2app(W_SHA.hexdigest_w, unwrap_spec=['self']),
-    copy      = interp2app(W_SHA.copy_w, unwrap_spec=['self']),
+    __new__   = interp2app(W_SHA___new__),
+    update    = interp2app(W_SHA.update_w),
+    digest    = interp2app(W_SHA.digest_w),
+    hexdigest = interp2app(W_SHA.hexdigest_w),
+    copy      = interp2app(W_SHA.copy_w),
     digest_size = 20,
     digestsize = 20,
     block_size = 64,


More information about the Pypy-commit mailing list