[pypy-svn] r74774 - in pypy/trunk/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Wed May 26 16:15:33 CEST 2010


Author: afa
Date: Wed May 26 16:15:31 2010
New Revision: 74774

Modified:
   pypy/trunk/pypy/module/cpyext/stringobject.py
   pypy/trunk/pypy/module/cpyext/test/test_stringobject.py
Log:
add PyString_InternFromString


Modified: pypy/trunk/pypy/module/cpyext/stringobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/stringobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/stringobject.py	Wed May 26 16:15:31 2010
@@ -238,3 +238,12 @@
     args.  The args argument must be a tuple."""
     return space.mod(w_format, w_args)
 
+ at cpython_api([CONST_STRING], PyObject)
+def PyString_InternFromString(space, string):
+    """A combination of PyString_FromString() and
+    PyString_InternInPlace(), returning either a new string object that has
+    been interned, or a new ("owned") reference to an earlier interned string
+    object with the same value."""
+    s = rffi.charp2str(string)
+    return space.new_interned_str(s)
+

Modified: pypy/trunk/pypy/module/cpyext/test/test_stringobject.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_stringobject.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_stringobject.py	Wed May 26 16:15:31 2010
@@ -246,3 +246,10 @@
 
         lltype.free(bufp, flavor='raw')
         lltype.free(lenp, flavor='raw')
+
+    def test_intern(self, space, api):
+        buf = rffi.str2charp("test")
+        w_s1 = api.PyString_InternFromString(buf)
+        w_s2 = api.PyString_InternFromString(buf)
+        rffi.free_charp(buf)
+        assert w_s1 is w_s2



More information about the Pypy-commit mailing list