[Python-Dev] r84430 - in python/branches/py3k: Include/unicodeobject.h Objects/unicodeobject.c (original) (raw)

M.-A. Lemburg mal at egenix.com
Thu Sep 2 11:13:22 CEST 2010


Georg Brandl wrote:

Hi Victor,

1. This function and PyUnicodestrcat are missing documentation. 2. Are you sure they need to be public APIs? What are they going to be used for? (I'm not sure myself, but I think we usually have a short notice here when new C APIs are added.)

If you want to make this a public API function, it also needs to be renamed to fit the rest of the API.

I'd suggest PyUnicode_AsUnicodeCopy() which then corresponds to PyUnicode_FromUnicode(), but I'm not sure whether we should have such a public API in the first place.

Georg > Am 02.09.2010 01:43, schrieb victor.stinner: > Author: victor.stinner > Date: Thu Sep 2 01:43:53 2010 > New Revision: 84430 >>> Log: > Create PyUnicodestrdup() function >>> Modified: > python/branches/py3k/Include/unicodeobject.h > python/branches/py3k/Objects/unicodeobject.c >>> Modified: python/branches/py3k/Include/unicodeobject.h > ============================================================================== > --- python/branches/py3k/Include/unicodeobject.h (original) > +++ python/branches/py3k/Include/unicodeobject.h Thu Sep 2 01:43:53 2010 > @@ -220,6 +220,7 @@ > # define PyUnicodeAsDefaultEncodedString PyUnicodeUCS2AsDefaultEncodedString > # define PyUnicodeFini PyUnicodeUCS2Fini > # define PyUnicodeInit PyUnicodeUCS2Init > +# define PyUnicodestrdup PyUnicodeUCS2strdup >>> #else >>> @@ -302,7 +303,7 @@ > # define PyUnicodeAsDefaultEncodedString PyUnicodeUCS4AsDefaultEncodedString > # define PyUnicodeFini PyUnicodeUCS4Fini > # define PyUnicodeInit PyUnicodeUCS4Init > - > +# define PyUnicodestrdup PyUnicodeUCS4strdup >>> #endif >>> @@ -1602,6 +1603,14 @@ > PyUNICODE c > ); >>> +/* Create a copy of a unicode string ending with a nul character. Return NULL > + and raise a MemoryError exception on memory allocation failure, otherwise > + return a new allocated buffer (use PyMemFree() to free the buffer). */ > + > +PyAPIFUNC(PyUNICODE*) PyUnicodestrdup( > + PyObject *unicode > + ); > + > _#ifdef cplusplus > } > #endif >>> Modified: python/branches/py3k/Objects/unicodeobject.c > ============================================================================== > --- python/branches/py3k/Objects/unicodeobject.c (original) > +++ python/branches/py3k/Objects/unicodeobject.c Thu Sep 2 01:43:53 2010 > @@ -10014,6 +10014,28 @@ > return NULL; > } >>> +PyUNICODE* > +PyUnicodestrdup(PyObject *object) > +{ > + PyUnicodeObject *unicode = (PyUnicodeObject *)object; > + PyUNICODE *copy; > + Pyssizet size; > + > + /* Ensure we won't overflow the size. */ > + if (PyUnicodeGETSIZE(unicode) > ((PYSSIZETMAX / sizeof(PyUNICODE)) - 1)) { > + PyErrNoMemory(); > + return NULL; > + } > + size = PyUnicodeGETSIZE(unicode) + 1; /* copy the nul character */ > + size *= sizeof(PyUNICODE); > + copy = PyMemMalloc(size); > + if (copy == NULL) { > + PyErrNoMemory(); > + return NULL; > + } > + memcpy(copy, PyUnicodeASUNICODE(unicode), size); > + return copy; > +} >>> _#ifdef cplusplus > } >

Marc-Andre Lemburg eGenix.com

Professional Python Services directly from the Source (#1, Sep 02 2010)

Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/


2010-08-19: Released mxODBC 3.1.0 http://python.egenix.com/ 2010-09-15: DZUG Tagung, Dresden, Germany 12 days to go

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::

eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/



More information about the Python-Dev mailing list