[pypy-commit] pypy py3.5: (arigato, plan_rich) add "newutf8" to the space object (use it to convert an rpython level string to wrapped unicode object), expose name property on W_SemLock, add parameters to descr_new

plan_rich pypy.commits at gmail.com
Fri Oct 14 05:05:07 EDT 2016


Author: Richard Plangger <planrichi at gmail.com>
Branch: py3.5
Changeset: r87772:988fed3776e7
Date: 2016-10-14 11:04 +0200
http://bitbucket.org/pypy/pypy/changeset/988fed3776e7/

Log:	(arigato, plan_rich) add "newutf8" to the space object (use it to
	convert an rpython level string to wrapped unicode object), expose
	name property on W_SemLock, add parameters to descr_new

diff --git a/pypy/module/_multiprocessing/interp_semaphore.py b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -436,17 +436,23 @@
 
 
 class W_SemLock(W_Root):
-    def __init__(self, space, handle, kind, maxvalue):
+    def __init__(self, space, handle, kind, maxvalue, name):
         self.handle = handle
         self.kind = kind
         self.count = 0
         self.maxvalue = maxvalue
         self.register_finalizer(space)
+        self.name = name
+
+    def name_get(self, space):
+        return space.newutf8(self.name)
 
     def kind_get(self, space):
         return space.newint(self.kind)
+
     def maxvalue_get(self, space):
         return space.newint(self.maxvalue)
+
     def handle_get(self, space):
         return w_handle(space, self.handle)
 
@@ -527,21 +533,24 @@
     def _finalize_(self):
         delete_semaphore(self.handle)
 
- at unwrap_spec(kind=int, value=int, maxvalue=int)
-def descr_new(space, w_subtype, kind, value, maxvalue):
+ at unwrap_spec(kind=int, value=int, maxvalue=int, name=str, unlink=int)
+def descr_new(space, w_subtype, kind, value, maxvalue, name, unlink):
     if kind != RECURSIVE_MUTEX and kind != SEMAPHORE:
         raise oefmt(space.w_ValueError, "unrecognized kind")
 
     counter = space.fromcache(CounterState).getCount()
-    name = "/mp%d-%d" % (os.getpid(), counter)
 
     try:
         handle = create_semaphore(space, name, value, maxvalue)
+        if unlink:
+            sem_unlink(name)
+            name = None
     except OSError as e:
         raise wrap_oserror(space, e)
 
+
     self = space.allocate_instance(W_SemLock, w_subtype)
-    self.__init__(space, handle, kind, maxvalue)
+    self.__init__(space, handle, kind, maxvalue, name)
 
     return space.wrap(self)
 
@@ -551,6 +560,7 @@
     kind = GetSetProperty(W_SemLock.kind_get),
     maxvalue = GetSetProperty(W_SemLock.maxvalue_get),
     handle = GetSetProperty(W_SemLock.handle_get),
+    name = GetSetProperty(W_SemLock.name_get),
     _count = interp2app(W_SemLock.get_count),
     _is_mine = interp2app(W_SemLock.is_mine),
     _is_zero = interp2app(W_SemLock.is_zero),
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -4,6 +4,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.function import Function, Method, FunctionWithFixedCode
 from pypy.interpreter.typedef import get_unique_interplevel_subclass
+from pypy.interpreter.unicodehelper import decode_utf8
 from pypy.objspace.std import frame, transparent, callmethod
 from pypy.objspace.descroperation import (
     DescrOperation, get_attribute_name, raiseattrerror)
@@ -353,6 +354,9 @@
     def newbytearray(self, l):
         return W_BytearrayObject(l)
 
+    def newutf8(self, string):
+        return space.newunicode(decode_utf8(string))
+
     def newunicode(self, uni):
         return W_UnicodeObject(uni)
 


More information about the pypy-commit mailing list