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

Side by Side Diff: Modules/_io/stringio.c

Issue 20435: Discrepancy between io.StringIO and _pyio.StringIO with univeral newlines
Patch Set: Created 5 years, 12 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:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_memoryio.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #define PY_SSIZE_T_CLEAN 1 #define PY_SSIZE_T_CLEAN
2 #include "Python.h" 2 #include "Python.h"
3 #include "structmember.h" 3 #include "structmember.h"
4 #include "accu.h" 4 #include "accu.h"
5 #include "_iomodule.h" 5 #include "_iomodule.h"
6 6
7 /* Implementation note: the buffer is always at least one character longer 7 /* Implementation note: the buffer is always at least one character longer
8 than the enclosed string, for proper functioning of _PyIO_find_line_ending. 8 than the enclosed string, for proper functioning of _PyIO_find_line_ending.
9 */ 9 */
10 10
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 } 728 }
729 729
730 /* Now everything is set up, resize buffer to size of initial value, 730 /* Now everything is set up, resize buffer to size of initial value,
731 and copy it */ 731 and copy it */
732 self->string_size = 0; 732 self->string_size = 0;
733 if (value && value != Py_None) 733 if (value && value != Py_None)
734 value_len = PyUnicode_GetLength(value); 734 value_len = PyUnicode_GetLength(value);
735 else 735 else
736 value_len = 0; 736 value_len = 0;
737 if (value_len > 0) { 737 if (value_len > 0) {
738 /* This is a heuristic, for newline translation might change 738 if (resize_buffer(self, value_len) < 0)
739 the string length. */
740 if (resize_buffer(self, 0) < 0)
741 return -1; 739 return -1;
740 if (!PyUnicode_AsUCS4(value, self->buf, value_len, 0))
741 return -1;
742 self->string_size = self->pos = value_len;
742 self->state = STATE_REALIZED; 743 self->state = STATE_REALIZED;
743 self->pos = 0;
744 if (write_str(self, value) < 0)
745 return -1;
746 } 744 }
747 else { 745 else {
748 /* Empty stringio object, we can start by accumulating */ 746 /* Empty stringio object, we can start by accumulating */
749 if (resize_buffer(self, 0) < 0) 747 if (resize_buffer(self, 0) < 0)
750 return -1; 748 return -1;
751 if (_PyAccu_Init(&self->accu)) 749 if (_PyAccu_Init(&self->accu))
752 return -1; 750 return -1;
753 self->state = STATE_ACCUMULATING; 751 self->state = STATE_ACCUMULATING;
754 } 752 }
755 self->pos = 0; 753 self->pos = 0;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 stringio_getset, /*tp_getset*/ 1023 stringio_getset, /*tp_getset*/
1026 0, /*tp_base*/ 1024 0, /*tp_base*/
1027 0, /*tp_dict*/ 1025 0, /*tp_dict*/
1028 0, /*tp_descr_get*/ 1026 0, /*tp_descr_get*/
1029 0, /*tp_descr_set*/ 1027 0, /*tp_descr_set*/
1030 offsetof(stringio, dict), /*tp_dictoffset*/ 1028 offsetof(stringio, dict), /*tp_dictoffset*/
1031 (initproc)stringio_init, /*tp_init*/ 1029 (initproc)stringio_init, /*tp_init*/
1032 0, /*tp_alloc*/ 1030 0, /*tp_alloc*/
1033 stringio_new, /*tp_new*/ 1031 stringio_new, /*tp_new*/
1034 }; 1032 };
OLDNEW
« no previous file with comments | « Lib/test/test_memoryio.py ('k') | no next file » | no next file with comments »

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