[Python-checkins] r84416 - in python/branches/import_unicode: Include/unicodeobject.h Objects/unicodeobject.c
victor.stinner
python-checkins at python.org
Thu Sep 2 00:14:09 CEST 2010
Author: victor.stinner
Date: Thu Sep 2 00:14:09 2010
New Revision: 84416
Log:
Create Py_UNICODE_strdup() function
Modified:
python/branches/import_unicode/Include/unicodeobject.h
python/branches/import_unicode/Objects/unicodeobject.c
Modified: python/branches/import_unicode/Include/unicodeobject.h
==============================================================================
--- python/branches/import_unicode/Include/unicodeobject.h (original)
+++ python/branches/import_unicode/Include/unicodeobject.h Thu Sep 2 00:14:09 2010
@@ -1634,6 +1634,14 @@
const Py_UNICODE *s, Py_UNICODE c
);
+/* Create a copy of a unicode string ending with a nul character.
+ Return NULL on memory error, otherwise return a new allocated buffer:
+ use PyMem_Free() to free the buffer. */
+
+PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strdup(
+ PyObject *unicode
+ );
+
#ifdef __cplusplus
}
#endif
Modified: python/branches/import_unicode/Objects/unicodeobject.c
==============================================================================
--- python/branches/import_unicode/Objects/unicodeobject.c (original)
+++ python/branches/import_unicode/Objects/unicodeobject.c Thu Sep 2 00:14:09 2010
@@ -10018,6 +10018,22 @@
return NULL;
}
+Py_UNICODE*
+Py_UNICODE_strdup(PyObject *object)
+{
+ PyUnicodeObject *unicode = (PyUnicodeObject *)object;
+ Py_UNICODE *copy;
+ Py_ssize_t size;
+ size = PyUnicode_GET_SIZE(unicode) + 1; /* copy the nul character */
+ size *= sizeof(Py_UNICODE);
+ copy = PyMem_Malloc(size);
+ if (copy == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ memcpy(copy, PyUnicode_AS_UNICODE(unicode), size);
+ return copy;
+}
#ifdef __cplusplus
}
More information about the Python-checkins
mailing list