Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(6)

Delta Between Two Patch Sets: Objects/bytesobject.c

Issue 25270: codecs.escape_encode systemerror on empty byte string
Left Patch Set: Created 4 years, 4 months ago
Right Patch Set: Created 3 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« Lib/test/test_codecs.py ('K') | « Lib/test/test_codecs.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /* bytes object implementation */ 1 /* bytes object implementation */
2 2
3 #define PY_SSIZE_T_CLEAN 3 #define PY_SSIZE_T_CLEAN
4 4
5 #include "Python.h" 5 #include "Python.h"
6 6
7 #include "bytes_methods.h" 7 #include "bytes_methods.h"
8 #include "pystrhex.h" 8 #include "pystrhex.h"
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 2892 matching lines...) Expand 10 before | Expand all | Expand 10 after
2903 As always, an extra byte is allocated for a trailing \0 byte (newsize 2903 As always, an extra byte is allocated for a trailing \0 byte (newsize
2904 does *not* include that), and a trailing \0 byte is stored. 2904 does *not* include that), and a trailing \0 byte is stored.
2905 */ 2905 */
2906 2906
2907 int 2907 int
2908 _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize) 2908 _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
2909 { 2909 {
2910 PyObject *v; 2910 PyObject *v;
2911 PyBytesObject *sv; 2911 PyBytesObject *sv;
2912 v = *pv; 2912 v = *pv;
2913 if (!PyBytes_Check(v) || Py_REFCNT(v) != 1 || newsize < 0) { 2913 if (!PyBytes_Check(v) || newsize < 0) {
2914 *pv = 0; 2914 goto error;
2915 Py_DECREF(v); 2915 }
2916 PyErr_BadInternalCall(); 2916 if (Py_SIZE(v) == newsize) {
2917 return -1; 2917 /* return early if newsize equals to v->ob_size */
2918 return 0;
2919 }
2920 if (Py_REFCNT(v) != 1) {
2921 goto error;
2918 } 2922 }
2919 /* XXX UNREF/NEWREF interface should be more symmetrical */ 2923 /* XXX UNREF/NEWREF interface should be more symmetrical */
2920 _Py_DEC_REFTOTAL; 2924 _Py_DEC_REFTOTAL;
2921 _Py_ForgetReference(v); 2925 _Py_ForgetReference(v);
2922 *pv = (PyObject *) 2926 *pv = (PyObject *)
2923 PyObject_REALLOC(v, PyBytesObject_SIZE + newsize); 2927 PyObject_REALLOC(v, PyBytesObject_SIZE + newsize);
2924 if (*pv == NULL) { 2928 if (*pv == NULL) {
2925 PyObject_Del(v); 2929 PyObject_Del(v);
2926 PyErr_NoMemory(); 2930 PyErr_NoMemory();
2927 return -1; 2931 return -1;
2928 } 2932 }
2929 _Py_NewReference(*pv); 2933 _Py_NewReference(*pv);
2930 sv = (PyBytesObject *) *pv; 2934 sv = (PyBytesObject *) *pv;
2931 Py_SIZE(sv) = newsize; 2935 Py_SIZE(sv) = newsize;
2932 sv->ob_sval[newsize] = '\0'; 2936 sv->ob_sval[newsize] = '\0';
2933 sv->ob_shash = -1; /* invalidate cached hash value */ 2937 sv->ob_shash = -1; /* invalidate cached hash value */
2934 return 0; 2938 return 0;
2939 error:
2940 *pv = 0;
2941 Py_DECREF(v);
2942 PyErr_BadInternalCall();
2943 return -1;
2935 } 2944 }
2936 2945
2937 void 2946 void
2938 PyBytes_Fini(void) 2947 PyBytes_Fini(void)
2939 { 2948 {
2940 int i; 2949 int i;
2941 for (i = 0; i < UCHAR_MAX + 1; i++) 2950 for (i = 0; i < UCHAR_MAX + 1; i++)
2942 Py_CLEAR(characters[i]); 2951 Py_CLEAR(characters[i]);
2943 Py_CLEAR(nullstring); 2952 Py_CLEAR(nullstring);
2944 } 2953 }
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 3379
3371 str = _PyBytesWriter_Prepare(writer, str, size); 3380 str = _PyBytesWriter_Prepare(writer, str, size);
3372 if (str == NULL) 3381 if (str == NULL)
3373 return NULL; 3382 return NULL;
3374 3383
3375 memcpy(str, bytes, size); 3384 memcpy(str, bytes, size);
3376 str += size; 3385 str += size;
3377 3386
3378 return str; 3387 return str;
3379 } 3388 }
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+