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

Delta Between Two Patch Sets: Objects/bytesobject.c

Issue 25270: codecs.escape_encode systemerror on empty byte string
Left Patch Set: Created 3 years, 5 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:
Left: Side by side diff | Download
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
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 2891 matching lines...) Expand 10 before | Expand all | Expand 10 after
2902 returned, and the value in *pv may or may not be the same as on input. 2902 returned, and the value in *pv may or may not be the same as on input.
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 Py_ssize_t oldsize;
2913 v = *pv; 2912 v = *pv;
2914 if (!PyBytes_Check(v) || newsize < 0) { 2913 if (!PyBytes_Check(v) || newsize < 0) {
2915 goto error; 2914 goto error;
2916 } 2915 }
2917 oldsize = Py_SIZE(v); 2916 if (Py_SIZE(v) == newsize) {
storchaka 2016/09/16 12:20:39 oldsize is used only once. It can be inlined.
berkerpeksag 2016/09/16 12:41:15 Done.
2918 if (oldsize == newsize) { 2917 /* return early if newsize equals to v->ob_size */
2919 return 0; 2918 return 0;
berkerpeksag 2016/09/16 12:41:15 Question: Should I add a comment to explain this?
2920 } 2919 }
2921 if (Py_REFCNT(v) != 1) { 2920 if (Py_REFCNT(v) != 1) {
2922 goto error; 2921 goto error;
2923 } 2922 }
2924 /* XXX UNREF/NEWREF interface should be more symmetrical */ 2923 /* XXX UNREF/NEWREF interface should be more symmetrical */
2925 _Py_DEC_REFTOTAL; 2924 _Py_DEC_REFTOTAL;
2926 _Py_ForgetReference(v); 2925 _Py_ForgetReference(v);
2927 *pv = (PyObject *) 2926 *pv = (PyObject *)
2928 PyObject_REALLOC(v, PyBytesObject_SIZE + newsize); 2927 PyObject_REALLOC(v, PyBytesObject_SIZE + newsize);
2929 if (*pv == NULL) { 2928 if (*pv == NULL) {
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
3380 3379
3381 str = _PyBytesWriter_Prepare(writer, str, size); 3380 str = _PyBytesWriter_Prepare(writer, str, size);
3382 if (str == NULL) 3381 if (str == NULL)
3383 return NULL; 3382 return NULL;
3384 3383
3385 memcpy(str, bytes, size); 3384 memcpy(str, bytes, size);
3386 str += size; 3385 str += size;
3387 3386
3388 return str; 3387 return str;
3389 } 3388 }
LEFTRIGHT

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