Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
49d6b07c
Commit
49d6b07c
authored
Aug 17, 2006
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the it_index field in the str/unicode iterators Py_ssize_t's.
Test the new iterators on str/unicode.
parent
bf12cdbb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
10 deletions
+31
-10
Lib/test/test_str.py
Lib/test/test_str.py
+8
-0
Lib/test/test_unicode.py
Lib/test/test_unicode.py
+8
-0
Objects/stringobject.c
Objects/stringobject.c
+9
-6
Objects/unicodeobject.c
Objects/unicodeobject.c
+6
-4
No files found.
Lib/test/test_str.py
View file @
49d6b07c
...
...
@@ -19,6 +19,14 @@ class StrTest(
string_tests
.
MixinStrUnicodeUserStringTest
.
test_formatting
(
self
)
self
.
assertRaises
(
OverflowError
,
'%c'
.
__mod__
,
0x1234
)
def
test_iterators
(
self
):
# Make sure str objects have an __iter__ method
it
=
"abc"
.
__iter__
()
self
.
assertEqual
(
it
.
next
(),
"a"
)
self
.
assertEqual
(
it
.
next
(),
"b"
)
self
.
assertEqual
(
it
.
next
(),
"c"
)
self
.
assertRaises
(
StopIteration
,
it
.
next
)
def
test_conversion
(
self
):
# Make sure __str__() behaves properly
class
Foo0
:
...
...
Lib/test/test_unicode.py
View file @
49d6b07c
...
...
@@ -93,6 +93,14 @@ class UnicodeTest(
testrepr
=
repr
(
u''
.
join
(
map
(
unichr
,
xrange
(
256
))))
self
.
assertEqual
(
testrepr
,
latin1repr
)
def
test_iterators
(
self
):
# Make sure unicode objects have an __iter__ method
it
=
u"
\
u1111
\
u2222
\
u3333
"
.
__iter__
()
self
.
assertEqual
(
it
.
next
(),
u"
\
u1111
"
)
self
.
assertEqual
(
it
.
next
(),
u"
\
u2222
"
)
self
.
assertEqual
(
it
.
next
(),
u"
\
u3333
"
)
self
.
assertRaises
(
StopIteration
,
it
.
next
)
def
test_count
(
self
):
string_tests
.
CommonTest
.
test_count
(
self
)
# check mixed argument types
...
...
Objects/stringobject.c
View file @
49d6b07c
...
...
@@ -4992,7 +4992,7 @@ void _Py_ReleaseInternedStrings(void)
typedef
struct
{
PyObject_HEAD
long
it_index
;
Py_ssize_t
it_index
;
PyStringObject
*
it_seq
;
/* Set to NULL when iterator is exhausted */
}
striterobject
;
...
...
@@ -5024,7 +5024,8 @@ striter_next(striterobject *it)
assert
(
PyString_Check
(
seq
));
if
(
it
->
it_index
<
PyString_GET_SIZE
(
seq
))
{
item
=
PyString_FromStringAndSize
(
PyString_AS_STRING
(
seq
)
+
it
->
it_index
,
1
);
item
=
PyString_FromStringAndSize
(
PyString_AS_STRING
(
seq
)
+
it
->
it_index
,
1
);
if
(
item
!=
NULL
)
++
it
->
it_index
;
return
item
;
...
...
@@ -5044,18 +5045,20 @@ striter_len(striterobject *it)
return
PyInt_FromSsize_t
(
len
);
}
PyDoc_STRVAR
(
length_hint_doc
,
"Private method returning an estimate of len(list(it))."
);
PyDoc_STRVAR
(
length_hint_doc
,
"Private method returning an estimate of len(list(it))."
);
static
PyMethodDef
striter_methods
[]
=
{
{
"__length_hint__"
,
(
PyCFunction
)
striter_len
,
METH_NOARGS
,
length_hint_doc
},
{
"__length_hint__"
,
(
PyCFunction
)
striter_len
,
METH_NOARGS
,
length_hint_doc
},
{
NULL
,
NULL
}
/* sentinel */
};
PyTypeObject
PyStringIter_Type
=
{
PyObject_HEAD_INIT
(
&
PyType_Type
)
0
,
/* ob_size */
"striterator"
,
/* tp_name */
sizeof
(
striterobject
),
/* tp_basicsize */
"striterator"
,
/* tp_name */
sizeof
(
striterobject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
/* methods */
(
destructor
)
striter_dealloc
,
/* tp_dealloc */
...
...
Objects/unicodeobject.c
View file @
49d6b07c
...
...
@@ -7969,7 +7969,7 @@ _PyUnicode_Fini(void)
typedef
struct
{
PyObject_HEAD
long
it_index
;
Py_ssize_t
it_index
;
PyUnicodeObject
*
it_seq
;
/* Set to NULL when iterator is exhausted */
}
unicodeiterobject
;
...
...
@@ -8001,7 +8001,8 @@ unicodeiter_next(unicodeiterobject *it)
assert
(
PyUnicode_Check
(
seq
));
if
(
it
->
it_index
<
PyUnicode_GET_SIZE
(
seq
))
{
item
=
PyUnicode_FromUnicode
(
PyUnicode_AS_UNICODE
(
seq
)
+
it
->
it_index
,
1
);
item
=
PyUnicode_FromUnicode
(
PyUnicode_AS_UNICODE
(
seq
)
+
it
->
it_index
,
1
);
if
(
item
!=
NULL
)
++
it
->
it_index
;
return
item
;
...
...
@@ -8024,7 +8025,8 @@ unicodeiter_len(unicodeiterobject *it)
PyDoc_STRVAR
(
length_hint_doc
,
"Private method returning an estimate of len(list(it))."
);
static
PyMethodDef
unicodeiter_methods
[]
=
{
{
"__length_hint__"
,
(
PyCFunction
)
unicodeiter_len
,
METH_NOARGS
,
length_hint_doc
},
{
"__length_hint__"
,
(
PyCFunction
)
unicodeiter_len
,
METH_NOARGS
,
length_hint_doc
},
{
NULL
,
NULL
}
/* sentinel */
};
...
...
@@ -8035,7 +8037,7 @@ PyTypeObject PyUnicodeIter_Type = {
sizeof
(
unicodeiterobject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
/* methods */
(
destructor
)
unicodeiter_dealloc
,
/* tp_dealloc */
(
destructor
)
unicodeiter_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment