Skip to content

Commit 4cc0f24

Browse files
committed
Rename PyUnicode_AsString -> _PyUnicode_AsString and
PyUnicode_AsStringAndSize -> _PyUnicode_AsStringAndSize to mark them for interpreter internal use only. We'll have to rework these APIs or create new ones for the purpose of accessing the UTF-8 representation of Unicode objects for 3.1.
1 parent 28bd1a3 commit 4cc0f24

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+156
-137
lines changed

Include/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ PyAPI_FUNC(long) _Py_HashDouble(double);
466466
PyAPI_FUNC(long) _Py_HashPointer(void*);
467467

468468
/* Helper for passing objects to printf and the like */
469-
#define PyObject_REPR(obj) PyUnicode_AsString(PyObject_Repr(obj))
469+
#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
470470

471471
/* Flag bits for printing: */
472472
#define Py_PRINT_RAW 1 /* No string quotes etc. */

Include/unicodeobject.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,22 +704,33 @@ PyAPI_FUNC(PyObject*) PyUnicode_DecodeFSDefaultAndSize(
704704
705705
In case of an error, no *size is set.
706706
707+
*** This API is for interpreter INTERNAL USE ONLY and will likely
708+
*** be removed or changed for Python 3.1.
709+
710+
*** If you need to access the Unicode object as UTF-8 bytes string,
711+
*** please use PyUnicode_AsUTF8String() instead.
712+
707713
*/
708714

709-
PyAPI_FUNC(char *) PyUnicode_AsStringAndSize(
715+
PyAPI_FUNC(char *) _PyUnicode_AsStringAndSize(
710716
PyObject *unicode,
711717
Py_ssize_t *size);
712718

713719
/* Returns a pointer to the default encoding (normally, UTf-8) of the
714720
Unicode object unicode.
715721
716722
Use of this API is DEPRECATED since no size information can be
717-
extracted from the returned data. Use PyUnicode_AsStringAndSize()
718-
instead.
723+
extracted from the returned data.
724+
725+
*** This API is for interpreter INTERNAL USE ONLY and will likely
726+
*** be removed or changed for Python 3.1.
727+
728+
*** If you need to access the Unicode object as UTF-8 bytes string,
729+
*** please use PyUnicode_AsUTF8String() instead.
719730
720731
*/
721732

722-
PyAPI_FUNC(char *) PyUnicode_AsString(PyObject *unicode);
733+
PyAPI_FUNC(char *) _PyUnicode_AsString(PyObject *unicode);
723734

724735
/* Returns the currently active default encoding.
725736

Misc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ Core and Builtins
1515
- Issue #1819: function calls with several named parameters are now on
1616
average 35% faster (as measured by pybench).
1717

18+
- The undocumented C APIs PyUnicode_AsString() and
19+
PyUnicode_AsStringAndSize() were made private to the interpreter, in
20+
order to be able to refine their interfaces for Python 3.1.
21+
22+
If you need to access the UTF-8 representation of a Unicode object
23+
as bytes string, please use PyUnicode_AsUTF8String() instead.
24+
25+
1826
Library
1927
-------
2028

Modules/_ctypes/_ctypes.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -683,8 +683,8 @@ StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
683683
return -1;
684684

685685
if (value && PyUnicode_Check(key) &&
686-
/* XXX struni PyUnicode_AsString can fail (also in other places)! */
687-
0 == strcmp(PyUnicode_AsString(key), "_fields_"))
686+
/* XXX struni _PyUnicode_AsString can fail (also in other places)! */
687+
0 == strcmp(_PyUnicode_AsString(key), "_fields_"))
688688
return StructUnionType_update_stgdict(self, value, 1);
689689
return 0;
690690
}
@@ -698,7 +698,7 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
698698
return -1;
699699

700700
if (PyUnicode_Check(key) &&
701-
0 == strcmp(PyUnicode_AsString(key), "_fields_"))
701+
0 == strcmp(_PyUnicode_AsString(key), "_fields_"))
702702
return StructUnionType_update_stgdict(self, value, 0);
703703
return 0;
704704
}
@@ -1681,7 +1681,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
16811681
if (stgd && CDataObject_Check(value) && stgd->proto && PyUnicode_Check(stgd->proto)) {
16821682
PyCArgObject *parg;
16831683

1684-
switch (PyUnicode_AsString(stgd->proto)[0]) {
1684+
switch (_PyUnicode_AsString(stgd->proto)[0]) {
16851685
case 'z': /* c_char_p */
16861686
case 'Z': /* c_wchar_p */
16871687
parg = new_CArgObject();
@@ -1791,7 +1791,7 @@ SimpleType_paramfunc(CDataObject *self)
17911791

17921792
dict = PyObject_stgdict((PyObject *)self);
17931793
assert(dict); /* Cannot be NULL for CDataObject instances */
1794-
fmt = PyUnicode_AsString(dict->proto);
1794+
fmt = _PyUnicode_AsString(dict->proto);
17951795
assert(fmt);
17961796

17971797
fd = getentry(fmt);
@@ -2012,7 +2012,7 @@ SimpleType_from_param(PyObject *type, PyObject *value)
20122012
assert(dict);
20132013

20142014
/* I think we can rely on this being a one-character string */
2015-
fmt = PyUnicode_AsString(dict->proto);
2015+
fmt = _PyUnicode_AsString(dict->proto);
20162016
assert(fmt);
20172017

20182018
fd = getentry(fmt);
@@ -3058,7 +3058,7 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
30583058
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
30593059
&& PyUnicode_Check(dict->proto)
30603060
/* We only allow c_void_p, c_char_p and c_wchar_p as a simple output parameter type */
3061-
&& (strchr("PzZ", PyUnicode_AsString(dict->proto)[0]))) {
3061+
&& (strchr("PzZ", _PyUnicode_AsString(dict->proto)[0]))) {
30623062
return 1;
30633063
}
30643064

@@ -3148,7 +3148,7 @@ _get_name(PyObject *obj, char **pname)
31483148
return *pname ? 1 : 0;
31493149
}
31503150
if (PyUnicode_Check(obj)) {
3151-
*pname = PyUnicode_AsString(obj);
3151+
*pname = _PyUnicode_AsString(obj);
31523152
return *pname ? 1 : 0;
31533153
}
31543154
PyErr_SetString(PyExc_TypeError,
@@ -5127,7 +5127,7 @@ cast_check_pointertype(PyObject *arg)
51275127
dict = PyType_stgdict(arg);
51285128
if (dict) {
51295129
if (PyUnicode_Check(dict->proto)
5130-
&& (strchr("sPzUZXO", PyUnicode_AsString(dict->proto)[0]))) {
5130+
&& (strchr("sPzUZXO", _PyUnicode_AsString(dict->proto)[0]))) {
51315131
/* simple pointer types, c_void_p, c_wchar_p, BSTR, ... */
51325132
return 1;
51335133
}

Modules/_ctypes/callproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ POINTER(PyObject *self, PyObject *cls)
17501750
return result;
17511751
}
17521752
if (PyUnicode_CheckExact(cls)) {
1753-
char *name = PyUnicode_AsString(cls);
1753+
char *name = _PyUnicode_AsString(cls);
17541754
buf = alloca(strlen(name) + 3 + 1);
17551755
sprintf(buf, "LP_%s", name);
17561756
result = PyObject_CallFunction((PyObject *)Py_TYPE(&Pointer_Type),

Modules/_ctypes/stgdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
479479
bitsize = 0;
480480
if (isStruct && !isPacked) {
481481
char *fieldfmt = dict->format ? dict->format : "B";
482-
char *fieldname = PyUnicode_AsString(name);
482+
char *fieldname = _PyUnicode_AsString(name);
483483
char *ptr;
484484
Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
485485
char *buf = alloca(len + 2 + 1);

Modules/_elementtree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ element_getattro(ElementObject* self, PyObject* nameobj)
13031303
char *name = "";
13041304

13051305
if (PyUnicode_Check(nameobj))
1306-
name = PyUnicode_AsString(nameobj);
1306+
name = _PyUnicode_AsString(nameobj);
13071307

13081308
if (strcmp(name, "tag") == 0)
13091309
res = self->tag;
@@ -2529,7 +2529,7 @@ xmlparser_getattro(XMLParserObject* self, PyObject* nameobj)
25292529
char *name = "";
25302530

25312531
if (PyUnicode_Check(nameobj))
2532-
name = PyUnicode_AsString(nameobj);
2532+
name = _PyUnicode_AsString(nameobj);
25332533

25342534
PyErr_Clear();
25352535

Modules/_gestalt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ convert_to_OSType(PyObject *v, OSType *pr)
3838
"OSType arg must be string of 4 chars");
3939
return 0;
4040
}
41-
memcpy((char *)&tmp, PyUnicode_AsString(v), 4);
41+
memcpy((char *)&tmp, _PyUnicode_AsString(v), 4);
4242
*pr = (OSType)ntohl(tmp);
4343
return 1;
4444
}

Modules/_hashopenssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ EVP_repr(PyObject *self)
241241
{
242242
char buf[100];
243243
PyOS_snprintf(buf, sizeof(buf), "<%s HASH object @ %p>",
244-
PyUnicode_AsString(((EVPobject *)self)->name), self);
244+
_PyUnicode_AsString(((EVPobject *)self)->name), self);
245245
return PyUnicode_FromString(buf);
246246
}
247247

Modules/_lsprof.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ normalizeUserObj(PyObject *obj)
180180
PyObject *mod = fn->m_module;
181181
const char *modname;
182182
if (mod && PyUnicode_Check(mod)) {
183-
modname = PyUnicode_AsString(mod);
183+
modname = _PyUnicode_AsString(mod);
184184
}
185185
else if (mod && PyModule_Check(mod)) {
186186
modname = PyModule_GetName(mod);

0 commit comments

Comments
 (0)