[Python-checkins] cpython: Issue #25207, #14626: Fix my commit.

victor.stinner python-checkins at python.org
Tue Sep 22 01:29:42 CEST 2015


https://hg.python.org/cpython/rev/170cd0104267
changeset: 98154:170cd0104267
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Sep 22 01:29:33 2015 +0200
summary:
 Issue #25207, #14626: Fix my commit.
It doesn't work to use #define XXX defined(YYY)" and then "#ifdef XXX"
to check YYY.
files:
 Modules/posixmodule.c | 6 +-
 Objects/unicodeobject.c | 52 +++++++++++++++++++++++-----
 2 files changed, 46 insertions(+), 12 deletions(-)
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4605,9 +4605,9 @@
 #define PATH_UTIME_HAVE_FD 0
 #endif
 
-
-#define UTIME_HAVE_NOFOLLOW_SYMLINKS \
- (defined(HAVE_UTIMENSAT) || defined(HAVE_LUTIMES))
+#if defined(HAVE_UTIMENSAT) || defined(HAVE_LUTIMES)
+# define UTIME_HAVE_NOFOLLOW_SYMLINKS
+#endif
 
 #ifdef UTIME_HAVE_NOFOLLOW_SYMLINKS
 
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4709,8 +4709,9 @@
 Py_ssize_t startinpos;
 Py_ssize_t endinpos;
 const char *errmsg = "";
- PyObject *errorHandler = NULL;
+ PyObject *error_handler_obj = NULL;
 PyObject *exc = NULL;
+ _Py_error_handler error_handler = _Py_ERROR_UNKNOWN;
 
 if (size == 0) {
 if (consumed)
@@ -4773,24 +4774,57 @@
 continue;
 }
 
- if (unicode_decode_call_errorhandler_writer(
- errors, &errorHandler,
- "utf-8", errmsg,
- &starts, &end, &startinpos, &endinpos, &exc, &s,
- &writer))
- goto onError;
+ /* undecodable byte: call the error handler */
+
+ if (error_handler == _Py_ERROR_UNKNOWN)
+ error_handler = get_error_handler(errors);
+
+ switch (error_handler)
+ {
+ case _Py_ERROR_REPLACE:
+ case _Py_ERROR_SURROGATEESCAPE:
+ {
+ unsigned char ch = (unsigned char)*s;
+
+ /* Fast-path: the error handler only writes one character,
+ but we may switch to UCS2 at the first write */
+ if (_PyUnicodeWriter_PrepareKind(&writer, PyUnicode_2BYTE_KIND) < 0)
+ goto onError;
+ kind = writer.kind;
+
+ if (error_handler == _Py_ERROR_REPLACE)
+ PyUnicode_WRITE(kind, writer.data, writer.pos, 0xfffd);
+ else
+ PyUnicode_WRITE(kind, writer.data, writer.pos, ch + 0xdc00);
+ writer.pos++;
+ ++s;
+ break;
+ }
+
+ case _Py_ERROR_IGNORE:
+ s++;
+ break;
+
+ default:
+ if (unicode_decode_call_errorhandler_writer(
+ errors, &error_handler_obj,
+ "utf-8", errmsg,
+ &starts, &end, &startinpos, &endinpos, &exc, &s,
+ &writer))
+ goto onError;
+ }
 }
 
 End:
 if (consumed)
 *consumed = s - starts;
 
- Py_XDECREF(errorHandler);
+ Py_XDECREF(error_handler_obj);
 Py_XDECREF(exc);
 return _PyUnicodeWriter_Finish(&writer);
 
 onError:
- Py_XDECREF(errorHandler);
+ Py_XDECREF(error_handler_obj);
 Py_XDECREF(exc);
 _PyUnicodeWriter_Dealloc(&writer);
 return NULL;
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /