Author: Philip Jenvey <pjen...@underboss.org> Branch: py3k Changeset: r73930:bd8819a48208 Date: 2014-10-13 14:52 -0700 http://bitbucket.org/pypy/pypy/changeset/bd8819a48208/
Log: issue1883: add PyUnicode_InternFromString diff --git a/pypy/module/cpyext/test/test_unicodeobject.py b/pypy/module/cpyext/test/test_unicodeobject.py --- a/pypy/module/cpyext/test/test_unicodeobject.py +++ b/pypy/module/cpyext/test/test_unicodeobject.py @@ -219,6 +219,13 @@ assert space.unwrap(w_res) == u'sp�' rffi.free_charp(s) + def test_internfromstring(self, space, api): + with rffi.scoped_str2charp('foo') as s: + w_res = api.PyUnicode_InternFromString(s) + assert space.unwrap(w_res) == u'foo' + w_res2 = api.PyUnicode_InternFromString(s) + assert w_res is w_res2 + def test_unicode_resize(self, space, api): py_uni = new_empty_unicode(space, 10) ar = lltype.malloc(PyObjectP.TO, 1, flavor='raw') diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py --- a/pypy/module/cpyext/unicodeobject.py +++ b/pypy/module/cpyext/unicodeobject.py @@ -508,6 +508,16 @@ w_str = space.wrapbytes(rffi.charp2str(s)) return space.call_method(w_str, 'decode', space.wrap("utf-8")) +@cpython_api([CONST_STRING], PyObject) +def PyUnicode_InternFromString(space, s): + """A combination of PyUnicode_FromString() and + PyUnicode_InternInPlace(), returning either a new unicode string + object that has been interned, or a new ("owned") reference to an + earlier interned string object with the same value. + """ + w_str = PyUnicode_FromString(space, s) + return space.new_interned_w_str(w_str) + @cpython_api([CONST_STRING, Py_ssize_t], PyObject) def PyUnicode_FromStringAndSize(space, s, size): """Create a Unicode Object from the char buffer u. The bytes will be _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit