]> granicus.if.org Git - python/commitdiff
Issue #10951: Fix compiler warnings in timemodule.c and unicodeobject.c
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 17 Dec 2011 21:39:43 +0000 (22:39 +0100)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 17 Dec 2011 21:39:43 +0000 (22:39 +0100)
Thanks Jérémy Anger for the fix.

1  2 
Modules/timemodule.c
Objects/unicodeobject.c

Simple merge
index 3f70af7e379e50664f99ea789f29295f0e1dee6a,d13c5470b35db90bf3ec4cbf59c2b4bf7b59cbfd..f5f1c46f24394df821dc231c11e8156b6c8a5dad
@@@ -4796,78 -2770,11 +4796,78 @@@ decode_utf8_errors(const char *starts
    onError:
      Py_XDECREF(errorHandler);
      Py_XDECREF(exc);
 -    Py_DECREF(unicode);
 +    Py_XDECREF(unicode);
      return NULL;
  }
-         return unicode_fromascii(s, size);
 +#undef WRITE_MAYBE_FAIL
 +
 +PyObject *
 +PyUnicode_DecodeUTF8Stateful(const char *s,
 +                             Py_ssize_t size,
 +                             const char *errors,
 +                             Py_ssize_t *consumed)
 +{
 +    Py_UCS4 maxchar = 0;
 +    Py_ssize_t unicode_size;
 +    int has_errors = 0;
 +    PyObject *unicode;
 +    int kind;
 +    void *data;
 +    const char *starts = s;
 +    const char *e;
 +    Py_ssize_t i;
 +
 +    if (size == 0) {
 +        if (consumed)
 +            *consumed = 0;
 +        Py_INCREF(unicode_empty);
 +        return unicode_empty;
 +    }
 +
 +    maxchar = utf8_scanner((const unsigned char *)s, size, &unicode_size);
 +
 +    /* When the string is ASCII only, just use memcpy and return.
 +       unicode_size may be != size if there is an incomplete UTF-8
 +       sequence at the end of the ASCII block.  */
 +    if (maxchar < 128 && size == unicode_size) {
 +        if (consumed)
 +            *consumed = size;
++        return unicode_fromascii((const unsigned char *)s, size);
 +    }
 +
 +    unicode = PyUnicode_New(unicode_size, maxchar);
 +    if (!unicode)
 +        return NULL;
 +    kind = PyUnicode_KIND(unicode);
 +    data = PyUnicode_DATA(unicode);
 +
 +    /* Unpack UTF-8 encoded data */
 +    i = 0;
 +    e = starts + size;
 +    switch (kind) {
 +    case PyUnicode_1BYTE_KIND:
 +        has_errors = ucs1lib_utf8_try_decode(s, e, (Py_UCS1 *) data, &s, &i);
 +        break;
 +    case PyUnicode_2BYTE_KIND:
 +        has_errors = ucs2lib_utf8_try_decode(s, e, (Py_UCS2 *) data, &s, &i);
 +        break;
 +    case PyUnicode_4BYTE_KIND:
 +        has_errors = ucs4lib_utf8_try_decode(s, e, (Py_UCS4 *) data, &s, &i);
 +        break;
 +    }
 +    if (!has_errors) {
 +        /* Ensure the unicode size calculation was correct */
 +        assert(i == unicode_size);
 +        assert(s == e);
 +        if (consumed)
 +            *consumed = size;
 +        return unicode;
 +    }
  
 -#undef ASCII_CHAR_MASK
 +    /* In case of errors, maxchar and size computation might be incorrect;
 +       code below refits and resizes as necessary. */
 +    return decode_utf8_errors(starts, size, errors, consumed, s, unicode, i);
 +}
  
  #ifdef __APPLE__