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
e8c701af
Commit
e8c701af
authored
Mar 04, 2006
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change some sequnce APIs to use Py_ssize_t.
parent
f9f4c009
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
9 deletions
+13
-9
Include/abstract.h
Include/abstract.h
+4
-4
Objects/abstract.c
Objects/abstract.c
+9
-5
No files found.
Include/abstract.h
View file @
e8c701af
...
...
@@ -1042,7 +1042,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/* Return a pointer to the underlying item array for
an object retured by PySequence_Fast */
PyAPI_FUNC
(
in
t
)
PySequence_Count
(
PyObject
*
o
,
PyObject
*
value
);
PyAPI_FUNC
(
Py_ssize_
t
)
PySequence_Count
(
PyObject
*
o
,
PyObject
*
value
);
/*
Return the number of occurrences on value on o, that is,
...
...
@@ -1060,8 +1060,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
#define PY_ITERSEARCH_COUNT 1
#define PY_ITERSEARCH_INDEX 2
#define PY_ITERSEARCH_CONTAINS 3
PyAPI_FUNC
(
int
)
_PySequence_IterSearch
(
PyObject
*
seq
,
PyObject
*
obj
,
int
operation
);
PyAPI_FUNC
(
Py_ssize_t
)
_PySequence_IterSearch
(
PyObject
*
seq
,
PyObject
*
obj
,
int
operation
);
/*
Iterate over seq. Result depends on the operation:
PY_ITERSEARCH_COUNT: return # of times obj appears in seq; -1 if
...
...
@@ -1086,7 +1086,7 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
is equivalent to the Python expression: value in o.
*/
PyAPI_FUNC
(
in
t
)
PySequence_Index
(
PyObject
*
o
,
PyObject
*
value
);
PyAPI_FUNC
(
Py_ssize_
t
)
PySequence_Index
(
PyObject
*
o
,
PyObject
*
value
);
/*
Return the first index for which o[i]=value. On error,
...
...
Objects/abstract.c
View file @
e8c701af
...
...
@@ -1577,10 +1577,10 @@ PySequence_Fast(PyObject *v, const char *m)
set ValueError and return -1 if none found; also return -1 on error.
Py_ITERSEARCH_CONTAINS: return 1 if obj in seq, else 0; -1 on error.
*/
in
t
Py_ssize_
t
_PySequence_IterSearch
(
PyObject
*
seq
,
PyObject
*
obj
,
int
operation
)
{
in
t
n
;
Py_ssize_
t
n
;
int
wrapped
;
/* for PY_ITERSEARCH_INDEX, true iff n wrapped around */
PyObject
*
it
;
/* iter(seq) */
...
...
@@ -1614,6 +1614,7 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation)
case
PY_ITERSEARCH_COUNT
:
++
n
;
if
(
n
<=
0
)
{
/* XXX(nnorwitz): int means ssize_t */
PyErr_SetString
(
PyExc_OverflowError
,
"count exceeds C int size"
);
goto
Fail
;
...
...
@@ -1622,6 +1623,7 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation)
case
PY_ITERSEARCH_INDEX
:
if
(
wrapped
)
{
/* XXX(nnorwitz): int means ssize_t */
PyErr_SetString
(
PyExc_OverflowError
,
"index exceeds C int size"
);
goto
Fail
;
...
...
@@ -1660,7 +1662,7 @@ Done:
}
/* Return # of times o appears in s. */
in
t
Py_ssize_
t
PySequence_Count
(
PyObject
*
s
,
PyObject
*
o
)
{
return
_PySequence_IterSearch
(
s
,
o
,
PY_ITERSEARCH_COUNT
);
...
...
@@ -1672,12 +1674,14 @@ PySequence_Count(PyObject *s, PyObject *o)
int
PySequence_Contains
(
PyObject
*
seq
,
PyObject
*
ob
)
{
Py_ssize_t
result
;
if
(
PyType_HasFeature
(
seq
->
ob_type
,
Py_TPFLAGS_HAVE_SEQUENCE_IN
))
{
PySequenceMethods
*
sqm
=
seq
->
ob_type
->
tp_as_sequence
;
if
(
sqm
!=
NULL
&&
sqm
->
sq_contains
!=
NULL
)
return
(
*
sqm
->
sq_contains
)(
seq
,
ob
);
}
return
_PySequence_IterSearch
(
seq
,
ob
,
PY_ITERSEARCH_CONTAINS
);
result
=
_PySequence_IterSearch
(
seq
,
ob
,
PY_ITERSEARCH_CONTAINS
);
return
Py_SAFE_DOWNCAST
(
result
,
Py_ssize_t
,
int
);
}
/* Backwards compatibility */
...
...
@@ -1688,7 +1692,7 @@ PySequence_In(PyObject *w, PyObject *v)
return
PySequence_Contains
(
w
,
v
);
}
in
t
Py_ssize_
t
PySequence_Index
(
PyObject
*
s
,
PyObject
*
o
)
{
return
_PySequence_IterSearch
(
s
,
o
,
PY_ITERSEARCH_INDEX
);
...
...
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