summaryrefslogtreecommitdiff
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2020-06-30 09:03:15 +0300
committerGitHub <noreply@github.com>2020-06-30 09:03:15 +0300
commit349f76c6aace5a4a2b57f6b442a532faf0027d6b (patch)
treec9d8fe1e3062e51e65cd7b2a763822908cb7a1cb /Objects/unicodeobject.c
parentb3332660adb02babb7e66e45310c66dc9a9a94da (diff)
downloadcpython-git-349f76c6aace5a4a2b57f6b442a532faf0027d6b.tar.gz
bpo-36346: Prepare for removing the legacy Unicode C API (AC only). (GH-21223)
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 8eafdacf55..db3f55e02b 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3273,6 +3273,80 @@ PyUnicode_AsWideCharString(PyObject *unicode,
#endif /* HAVE_WCHAR_H */
+int
+_PyUnicode_WideCharString_Converter(PyObject *obj, void *ptr)
+{
+ wchar_t **p = (wchar_t **)ptr;
+ if (obj == NULL) {
+#if !USE_UNICODE_WCHAR_CACHE
+ PyMem_Free(*p);
+#endif /* USE_UNICODE_WCHAR_CACHE */
+ *p = NULL;
+ return 1;
+ }
+ if (PyUnicode_Check(obj)) {
+#if USE_UNICODE_WCHAR_CACHE
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ *p = (wchar_t *)_PyUnicode_AsUnicode(obj);
+ if (*p == NULL) {
+ return 0;
+ }
+ return 1;
+_Py_COMP_DIAG_POP
+#else /* USE_UNICODE_WCHAR_CACHE */
+ *p = PyUnicode_AsWideCharString(obj, NULL);
+ if (*p == NULL) {
+ return 0;
+ }
+ return Py_CLEANUP_SUPPORTED;
+#endif /* USE_UNICODE_WCHAR_CACHE */
+ }
+ PyErr_Format(PyExc_TypeError,
+ "argument must be str, not %.50s",
+ obj->ob_type->tp_name);
+ return 0;
+}
+
+int
+_PyUnicode_WideCharString_Opt_Converter(PyObject *obj, void *ptr)
+{
+ wchar_t **p = (wchar_t **)ptr;
+ if (obj == NULL) {
+#if !USE_UNICODE_WCHAR_CACHE
+ PyMem_Free(*p);
+#endif /* USE_UNICODE_WCHAR_CACHE */
+ *p = NULL;
+ return 1;
+ }
+ if (obj == Py_None) {
+ *p = NULL;
+ return 1;
+ }
+ if (PyUnicode_Check(obj)) {
+#if USE_UNICODE_WCHAR_CACHE
+_Py_COMP_DIAG_PUSH
+_Py_COMP_DIAG_IGNORE_DEPR_DECLS
+ *p = (wchar_t *)_PyUnicode_AsUnicode(obj);
+ if (*p == NULL) {
+ return 0;
+ }
+ return 1;
+_Py_COMP_DIAG_POP
+#else /* USE_UNICODE_WCHAR_CACHE */
+ *p = PyUnicode_AsWideCharString(obj, NULL);
+ if (*p == NULL) {
+ return 0;
+ }
+ return Py_CLEANUP_SUPPORTED;
+#endif /* USE_UNICODE_WCHAR_CACHE */
+ }
+ PyErr_Format(PyExc_TypeError,
+ "argument must be str or None, not %.50s",
+ obj->ob_type->tp_name);
+ return 0;
+}
+
PyObject *
PyUnicode_FromOrdinal(int ordinal)
{