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
9916ee8e
Commit
9916ee8e
authored
Feb 01, 2009
by
Mark Dickinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1717, stage 2: remove uses of tp_compare in Modules and most
Objects.
parent
e02dc87c
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
385 additions
and
113 deletions
+385
-113
Lib/test/test_descr.py
Lib/test/test_descr.py
+1
-1
Lib/test/test_funcattrs.py
Lib/test/test_funcattrs.py
+32
-1
Lib/test/test_parser.py
Lib/test/test_parser.py
+70
-0
Modules/_csv.c
Modules/_csv.c
+3
-3
Modules/_elementtree.c
Modules/_elementtree.c
+5
-4
Modules/_localemodule.c
Modules/_localemodule.c
+3
-1
Modules/_pickle.c
Modules/_pickle.c
+1
-1
Modules/_tkinter.c
Modules/_tkinter.c
+89
-45
Modules/parsermodule.c
Modules/parsermodule.c
+59
-13
Modules/pyexpat.c
Modules/pyexpat.c
+1
-1
Objects/cellobject.c
Objects/cellobject.c
+51
-11
Objects/descrobject.c
Objects/descrobject.c
+61
-15
Objects/rangeobject.c
Objects/rangeobject.c
+5
-6
Objects/setobject.c
Objects/setobject.c
+2
-9
PC/winreg.c
PC/winreg.c
+2
-2
No files found.
Lib/test/test_descr.py
View file @
9916ee8e
...
@@ -3885,7 +3885,7 @@ order (MRO) for bases """
...
@@ -3885,7 +3885,7 @@ order (MRO) for bases """
# Testing method-wrapper objects...
# Testing method-wrapper objects...
# <type 'method-wrapper'> did not support any reflection before 2.5
# <type 'method-wrapper'> did not support any reflection before 2.5
return
# XXX should methods really support __eq__?
# XXX should methods really support __eq__?
l
=
[]
l
=
[]
self
.
assertEqual
(
l
.
__add__
,
l
.
__add__
)
self
.
assertEqual
(
l
.
__add__
,
l
.
__add__
)
...
...
Lib/test/test_funcattrs.py
View file @
9916ee8e
...
@@ -224,10 +224,41 @@ class FunctionDocstringTest(FuncAttrsTest):
...
@@ -224,10 +224,41 @@ class FunctionDocstringTest(FuncAttrsTest):
del
self
.
b
.
__doc__
del
self
.
b
.
__doc__
self
.
assertEqual
(
self
.
b
.
__doc__
,
None
)
self
.
assertEqual
(
self
.
b
.
__doc__
,
None
)
def
cell
(
value
):
"""Create a cell containing the given value."""
def
f
():
print
(
a
)
a
=
value
return
f
.
__closure__
[
0
]
def
empty_cell
(
empty
=
True
):
"""Create an empty cell."""
def
f
():
print
(
a
)
# the intent of the following line is simply "if False:"; it's
# spelt this way to avoid the danger that a future optimization
# might simply remove an "if False:" code block.
if
not
empty
:
a
=
1729
return
f
.
__closure__
[
0
]
class
CellTest
(
unittest
.
TestCase
):
def
test_comparison
(
self
):
# These tests are here simply to exercise the comparison code;
# their presence should not be interpreted as providing any
# guarantees about the semantics (or even existence) of cell
# comparisons in future versions of CPython.
self
.
assert_
(
cell
(
2
)
<
cell
(
3
))
self
.
assert_
(
empty_cell
()
<
cell
(
'saturday'
))
self
.
assert_
(
empty_cell
()
==
empty_cell
())
self
.
assert_
(
cell
(
-
36
)
==
cell
(
-
36.0
))
self
.
assert_
(
cell
(
True
)
>
empty_cell
())
def
test_main
():
def
test_main
():
support
.
run_unittest
(
FunctionPropertiesTest
,
ImplicitReferencesTest
,
support
.
run_unittest
(
FunctionPropertiesTest
,
ImplicitReferencesTest
,
ArbitraryFunctionAttrTest
,
FunctionDictsTest
,
ArbitraryFunctionAttrTest
,
FunctionDictsTest
,
FunctionDocstringTest
)
FunctionDocstringTest
,
CellTest
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
test_main
()
test_main
()
Lib/test/test_parser.py
View file @
9916ee8e
...
@@ -2,6 +2,7 @@ import parser
...
@@ -2,6 +2,7 @@ import parser
import
os
import
os
import
unittest
import
unittest
import
sys
import
sys
import
operator
from
test
import
support
from
test
import
support
#
#
...
@@ -496,12 +497,81 @@ class ParserStackLimitTestCase(unittest.TestCase):
...
@@ -496,12 +497,81 @@ class ParserStackLimitTestCase(unittest.TestCase):
file
=
sys
.
stderr
)
file
=
sys
.
stderr
)
self
.
assertRaises
(
MemoryError
,
parser
.
expr
,
e
)
self
.
assertRaises
(
MemoryError
,
parser
.
expr
,
e
)
class
STObjectTestCase
(
unittest
.
TestCase
):
"""Test operations on ST objects themselves"""
def
test_comparisons
(
self
):
# ST objects should support order and equality comparisons
st1
=
parser
.
expr
(
'2 + 3'
)
st2
=
parser
.
suite
(
'x = 2; y = x + 3'
)
st3
=
parser
.
expr
(
'list(x**3 for x in range(20))'
)
st1_copy
=
parser
.
expr
(
'2 + 3'
)
st2_copy
=
parser
.
suite
(
'x = 2; y = x + 3'
)
st3_copy
=
parser
.
expr
(
'list(x**3 for x in range(20))'
)
# exercise fast path for object identity
self
.
assertEquals
(
st1
==
st1
,
True
)
self
.
assertEquals
(
st2
==
st2
,
True
)
self
.
assertEquals
(
st3
==
st3
,
True
)
# slow path equality
self
.
assertEqual
(
st1
,
st1_copy
)
self
.
assertEqual
(
st2
,
st2_copy
)
self
.
assertEqual
(
st3
,
st3_copy
)
self
.
assertEquals
(
st1
==
st2
,
False
)
self
.
assertEquals
(
st1
==
st3
,
False
)
self
.
assertEquals
(
st2
==
st3
,
False
)
self
.
assertEquals
(
st1
!=
st1
,
False
)
self
.
assertEquals
(
st2
!=
st2
,
False
)
self
.
assertEquals
(
st3
!=
st3
,
False
)
self
.
assertEquals
(
st1
!=
st1_copy
,
False
)
self
.
assertEquals
(
st2
!=
st2_copy
,
False
)
self
.
assertEquals
(
st3
!=
st3_copy
,
False
)
self
.
assertEquals
(
st2
!=
st1
,
True
)
self
.
assertEquals
(
st1
!=
st3
,
True
)
self
.
assertEquals
(
st3
!=
st2
,
True
)
# we don't particularly care what the ordering is; just that
# it's usable and self-consistent
self
.
assertEquals
(
st1
<
st2
,
not
(
st2
<=
st1
))
self
.
assertEquals
(
st1
<
st3
,
not
(
st3
<=
st1
))
self
.
assertEquals
(
st2
<
st3
,
not
(
st3
<=
st2
))
self
.
assertEquals
(
st1
<
st2
,
st2
>
st1
)
self
.
assertEquals
(
st1
<
st3
,
st3
>
st1
)
self
.
assertEquals
(
st2
<
st3
,
st3
>
st2
)
self
.
assertEquals
(
st1
<=
st2
,
st2
>=
st1
)
self
.
assertEquals
(
st3
<=
st1
,
st1
>=
st3
)
self
.
assertEquals
(
st2
<=
st3
,
st3
>=
st2
)
# transitivity
bottom
=
min
(
st1
,
st2
,
st3
)
top
=
max
(
st1
,
st2
,
st3
)
mid
=
sorted
([
st1
,
st2
,
st3
])[
1
]
self
.
assert_
(
bottom
<
mid
)
self
.
assert_
(
bottom
<
top
)
self
.
assert_
(
mid
<
top
)
self
.
assert_
(
bottom
<=
mid
)
self
.
assert_
(
bottom
<=
top
)
self
.
assert_
(
mid
<=
top
)
self
.
assert_
(
bottom
<=
bottom
)
self
.
assert_
(
mid
<=
mid
)
self
.
assert_
(
top
<=
top
)
# interaction with other types
self
.
assertEquals
(
st1
==
1588.602459
,
False
)
self
.
assertEquals
(
'spanish armada'
!=
st2
,
True
)
self
.
assertRaises
(
TypeError
,
operator
.
ge
,
st3
,
None
)
self
.
assertRaises
(
TypeError
,
operator
.
le
,
False
,
st1
)
self
.
assertRaises
(
TypeError
,
operator
.
lt
,
st1
,
1815
)
self
.
assertRaises
(
TypeError
,
operator
.
gt
,
b'waterloo'
,
st2
)
# XXX tests for pickling and unpickling of ST objects should go here
def
test_main
():
def
test_main
():
support
.
run_unittest
(
support
.
run_unittest
(
RoundtripLegalSyntaxTestCase
,
RoundtripLegalSyntaxTestCase
,
IllegalSyntaxTestCase
,
IllegalSyntaxTestCase
,
CompileTestCase
,
CompileTestCase
,
ParserStackLimitTestCase
,
ParserStackLimitTestCase
,
STObjectTestCase
,
)
)
...
...
Modules/_csv.c
View file @
9916ee8e
...
@@ -443,7 +443,7 @@ static PyTypeObject Dialect_Type = {
...
@@ -443,7 +443,7 @@ static PyTypeObject Dialect_Type = {
(
printfunc
)
0
,
/* tp_print */
(
printfunc
)
0
,
/* tp_print */
(
getattrfunc
)
0
,
/* tp_getattr */
(
getattrfunc
)
0
,
/* tp_getattr */
(
setattrfunc
)
0
,
/* tp_setattr */
(
setattrfunc
)
0
,
/* tp_setattr */
(
cmpfunc
)
0
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
0
,
/* tp_repr */
(
reprfunc
)
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
...
@@ -864,7 +864,7 @@ static PyTypeObject Reader_Type = {
...
@@ -864,7 +864,7 @@ static PyTypeObject Reader_Type = {
(
printfunc
)
0
,
/*tp_print*/
(
printfunc
)
0
,
/*tp_print*/
(
getattrfunc
)
0
,
/*tp_getattr*/
(
getattrfunc
)
0
,
/*tp_getattr*/
(
setattrfunc
)
0
,
/*tp_setattr*/
(
setattrfunc
)
0
,
/*tp_setattr*/
(
cmpfunc
)
0
,
/*tp_compare*/
0
,
/*tp_compare*/
(
reprfunc
)
0
,
/*tp_repr*/
(
reprfunc
)
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_sequence*/
...
@@ -1286,7 +1286,7 @@ static PyTypeObject Writer_Type = {
...
@@ -1286,7 +1286,7 @@ static PyTypeObject Writer_Type = {
(
printfunc
)
0
,
/*tp_print*/
(
printfunc
)
0
,
/*tp_print*/
(
getattrfunc
)
0
,
/*tp_getattr*/
(
getattrfunc
)
0
,
/*tp_getattr*/
(
setattrfunc
)
0
,
/*tp_setattr*/
(
setattrfunc
)
0
,
/*tp_setattr*/
(
cmpfunc
)
0
,
/*tp_compare*/
0
,
/*tp_compare*/
(
reprfunc
)
0
,
/*tp_repr*/
(
reprfunc
)
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_sequence*/
...
...
Modules/_elementtree.c
View file @
9916ee8e
...
@@ -761,7 +761,7 @@ element_find(ElementObject* self, PyObject* args)
...
@@ -761,7 +761,7 @@ element_find(ElementObject* self, PyObject* args)
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
PyObject
*
item
=
self
->
extra
->
children
[
i
];
PyObject
*
item
=
self
->
extra
->
children
[
i
];
if
(
Element_CheckExact
(
item
)
&&
if
(
Element_CheckExact
(
item
)
&&
PyObject_
Compare
(((
ElementObject
*
)
item
)
->
tag
,
tag
)
==
0
)
{
PyObject_
RichCompareBool
(((
ElementObject
*
)
item
)
->
tag
,
tag
,
Py_EQ
)
==
1
)
{
Py_INCREF
(
item
);
Py_INCREF
(
item
);
return
item
;
return
item
;
}
}
...
@@ -792,7 +792,8 @@ element_findtext(ElementObject* self, PyObject* args)
...
@@ -792,7 +792,8 @@ element_findtext(ElementObject* self, PyObject* args)
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
ElementObject
*
item
=
(
ElementObject
*
)
self
->
extra
->
children
[
i
];
ElementObject
*
item
=
(
ElementObject
*
)
self
->
extra
->
children
[
i
];
if
(
Element_CheckExact
(
item
)
&&
!
PyObject_Compare
(
item
->
tag
,
tag
))
{
if
(
Element_CheckExact
(
item
)
&&
(
PyObject_RichCompareBool
(
item
->
tag
,
tag
,
Py_EQ
)
==
1
))
{
PyObject
*
text
=
element_get_text
(
item
);
PyObject
*
text
=
element_get_text
(
item
);
if
(
text
==
Py_None
)
if
(
text
==
Py_None
)
return
PyBytes_FromString
(
""
);
return
PyBytes_FromString
(
""
);
...
@@ -830,7 +831,7 @@ element_findall(ElementObject* self, PyObject* args)
...
@@ -830,7 +831,7 @@ element_findall(ElementObject* self, PyObject* args)
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
PyObject
*
item
=
self
->
extra
->
children
[
i
];
PyObject
*
item
=
self
->
extra
->
children
[
i
];
if
(
Element_CheckExact
(
item
)
&&
if
(
Element_CheckExact
(
item
)
&&
PyObject_
Compare
(((
ElementObject
*
)
item
)
->
tag
,
tag
)
==
0
)
{
PyObject_
RichCompareBool
(((
ElementObject
*
)
item
)
->
tag
,
tag
,
Py_EQ
)
==
1
)
{
if
(
PyList_Append
(
out
,
item
)
<
0
)
{
if
(
PyList_Append
(
out
,
item
)
<
0
)
{
Py_DECREF
(
out
);
Py_DECREF
(
out
);
return
NULL
;
return
NULL
;
...
@@ -1102,7 +1103,7 @@ element_remove(ElementObject* self, PyObject* args)
...
@@ -1102,7 +1103,7 @@ element_remove(ElementObject* self, PyObject* args)
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
for
(
i
=
0
;
i
<
self
->
extra
->
length
;
i
++
)
{
if
(
self
->
extra
->
children
[
i
]
==
element
)
if
(
self
->
extra
->
children
[
i
]
==
element
)
break
;
break
;
if
(
PyObject_
Compare
(
self
->
extra
->
children
[
i
],
element
)
==
0
)
if
(
PyObject_
RichCompareBool
(
self
->
extra
->
children
[
i
],
element
,
Py_EQ
)
==
1
)
break
;
break
;
}
}
...
...
Modules/_localemodule.c
View file @
9916ee8e
...
@@ -272,7 +272,9 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
...
@@ -272,7 +272,9 @@ PyLocale_strcoll(PyObject* self, PyObject* args)
#ifdef HAVE_WCSXFRM
#ifdef HAVE_WCSXFRM
PyDoc_STRVAR
(
strxfrm__doc__
,
PyDoc_STRVAR
(
strxfrm__doc__
,
"string -> string. Returns a string that behaves for cmp locale-aware."
);
"strxfrm(string) -> string.
\n
\
\n
\
Return a string that can be used as a key for locale-aware comparisons."
);
static
PyObject
*
static
PyObject
*
PyLocale_strxfrm
(
PyObject
*
self
,
PyObject
*
args
)
PyLocale_strxfrm
(
PyObject
*
self
,
PyObject
*
args
)
...
...
Modules/_pickle.c
View file @
9916ee8e
...
@@ -715,7 +715,7 @@ whichmodule(PyObject *global, PyObject *global_name)
...
@@ -715,7 +715,7 @@ whichmodule(PyObject *global, PyObject *global_name)
i
=
0
;
i
=
0
;
module_name
=
NULL
;
module_name
=
NULL
;
while
((
j
=
PyDict_Next
(
modules_dict
,
&
i
,
&
module_name
,
&
module
)))
{
while
((
j
=
PyDict_Next
(
modules_dict
,
&
i
,
&
module_name
,
&
module
)))
{
if
(
PyObject_
Compare
(
module_name
,
main_str
)
==
0
)
if
(
PyObject_
RichCompareBool
(
module_name
,
main_str
,
Py_EQ
)
==
1
)
continue
;
continue
;
obj
=
PyObject_GetAttr
(
module
,
global_name
);
obj
=
PyObject_GetAttr
(
module
,
global_name
);
...
...
Modules/_tkinter.c
View file @
9916ee8e
...
@@ -788,15 +788,59 @@ PyTclObject_repr(PyTclObject *self)
...
@@ -788,15 +788,59 @@ PyTclObject_repr(PyTclObject *self)
self
->
value
->
typePtr
->
name
,
self
->
value
);
self
->
value
->
typePtr
->
name
,
self
->
value
);
}
}
static
int
#define TEST_COND(cond) ((cond) ? Py_True : Py_False)
PyTclObject_cmp
(
PyTclObject
*
self
,
PyTclObject
*
other
)
static
PyObject
*
PyTclObject_richcompare
(
PyObject
*
self
,
PyObject
*
other
,
int
op
)
{
{
int
res
;
int
result
;
res
=
strcmp
(
Tcl_GetString
(
self
->
value
),
PyObject
*
v
;
Tcl_GetString
(
other
->
value
));
if
(
res
<
0
)
return
-
1
;
/* neither argument should be NULL, unless something's gone wrong */
if
(
res
>
0
)
return
1
;
if
(
self
==
NULL
||
other
==
NULL
)
{
return
0
;
PyErr_BadInternalCall
();
return
NULL
;
}
/* both arguments should be instances of PyTclObject */
if
(
!
PyTclObject_Check
(
self
)
||
!
PyTclObject_Check
(
other
))
{
v
=
Py_NotImplemented
;
goto
finished
;
}
if
(
self
==
other
)
/* fast path when self and other are identical */
result
=
0
;
else
result
=
strcmp
(
Tcl_GetString
(((
PyTclObject
*
)
self
)
->
value
),
Tcl_GetString
(((
PyTclObject
*
)
other
)
->
value
));
/* Convert return value to a Boolean */
switch
(
op
)
{
case
Py_EQ
:
v
=
TEST_COND
(
result
==
0
);
break
;
case
Py_NE
:
v
=
TEST_COND
(
result
!=
0
);
break
;
case
Py_LE
:
v
=
TEST_COND
(
result
<=
0
);
break
;
case
Py_GE
:
v
=
TEST_COND
(
result
>=
0
);
break
;
case
Py_LT
:
v
=
TEST_COND
(
result
<
0
);
break
;
case
Py_GT
:
v
=
TEST_COND
(
result
>
0
);
break
;
default:
PyErr_BadArgument
();
return
NULL
;
}
finished:
Py_INCREF
(
v
);
return
v
;
}
}
PyDoc_STRVAR
(
get_typename__doc__
,
"name of the Tcl type"
);
PyDoc_STRVAR
(
get_typename__doc__
,
"name of the Tcl type"
);
...
@@ -818,45 +862,45 @@ static PyGetSetDef PyTclObject_getsetlist[] = {
...
@@ -818,45 +862,45 @@ static PyGetSetDef PyTclObject_getsetlist[] = {
static
PyTypeObject
PyTclObject_Type
=
{
static
PyTypeObject
PyTclObject_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_tkinter.Tcl_Obj"
,
/*tp_name*/
"_tkinter.Tcl_Obj"
,
/*tp_name*/
sizeof
(
PyTclObject
),
/*tp_basicsize*/
sizeof
(
PyTclObject
),
/*tp_basicsize*/
0
,
/*tp_itemsize*/
0
,
/*tp_itemsize*/
/* methods */
/* methods */
(
destructor
)
PyTclObject_dealloc
,
/*tp_dealloc*/
(
destructor
)
PyTclObject_dealloc
,
/*tp_dealloc*/
0
,
/*tp_print*/
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_getattr*/
0
,
/*tp_setattr*/
0
,
/*tp_setattr*/
(
cmpfunc
)
PyTclObject_cmp
,
/*tp_compare*/
0
,
/*tp_compare*/
(
reprfunc
)
PyTclObject_repr
,
/*tp_repr*/
(
reprfunc
)
PyTclObject_repr
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_mapping*/
0
,
/*tp_as_mapping*/
0
,
/*tp_hash*/
0
,
/*tp_hash*/
0
,
/*tp_call*/
0
,
/*tp_call*/
(
reprfunc
)
PyTclObject_str
,
/*tp_str*/
(
reprfunc
)
PyTclObject_str
,
/*tp_str*/
PyObject_GenericGetAttr
,
/*tp_getattro*/
PyObject_GenericGetAttr
,
/*tp_getattro*/
0
,
/*tp_setattro*/
0
,
/*tp_setattro*/
0
,
/*tp_as_buffer*/
0
,
/*tp_as_buffer*/
Py_TPFLAGS_DEFAULT
,
/*tp_flags*/
Py_TPFLAGS_DEFAULT
,
/*tp_flags*/
0
,
/*tp_doc*/
0
,
/*tp_doc*/
0
,
/*tp_traverse*/
0
,
/*tp_traverse*/
0
,
/*tp_clear*/
0
,
/*tp_clear*/
0
,
/*tp_richcompare*/
PyTclObject_richcompare
,
/*tp_richcompare*/
0
,
/*tp_weaklistoffset*/
0
,
/*tp_weaklistoffset*/
0
,
/*tp_iter*/
0
,
/*tp_iter*/
0
,
/*tp_iternext*/
0
,
/*tp_iternext*/
0
,
/*tp_methods*/
0
,
/*tp_methods*/
0
,
/*tp_members*/
0
,
/*tp_members*/
PyTclObject_getsetlist
,
/*tp_getset*/
PyTclObject_getsetlist
,
/*tp_getset*/
0
,
/*tp_base*/
0
,
/*tp_base*/
0
,
/*tp_dict*/
0
,
/*tp_dict*/
0
,
/*tp_descr_get*/
0
,
/*tp_descr_get*/
0
,
/*tp_descr_set*/
0
,
/*tp_descr_set*/
0
,
/*tp_dictoffset*/
0
,
/*tp_dictoffset*/
0
,
/*tp_init*/
0
,
/*tp_init*/
0
,
/*tp_alloc*/
0
,
/*tp_alloc*/
0
,
/*tp_new*/
0
,
/*tp_new*/
0
,
/*tp_free*/
0
,
/*tp_free*/
0
,
/*tp_is_gc*/
0
,
/*tp_is_gc*/
};
};
static
Tcl_Obj
*
static
Tcl_Obj
*
...
...
Modules/parsermodule.c
View file @
9916ee8e
...
@@ -169,7 +169,7 @@ typedef struct {
...
@@ -169,7 +169,7 @@ typedef struct {
static
void
parser_free
(
PyST_Object
*
st
);
static
void
parser_free
(
PyST_Object
*
st
);
static
int
parser_compare
(
PyST_Object
*
left
,
PyST_Object
*
right
);
static
PyObject
*
parser_richcompare
(
PyObject
*
left
,
PyObject
*
right
,
int
op
);
static
PyObject
*
parser_compilest
(
PyST_Object
*
,
PyObject
*
,
PyObject
*
);
static
PyObject
*
parser_compilest
(
PyST_Object
*
,
PyObject
*
,
PyObject
*
);
static
PyObject
*
parser_isexpr
(
PyST_Object
*
,
PyObject
*
,
PyObject
*
);
static
PyObject
*
parser_isexpr
(
PyST_Object
*
,
PyObject
*
,
PyObject
*
);
static
PyObject
*
parser_issuite
(
PyST_Object
*
,
PyObject
*
,
PyObject
*
);
static
PyObject
*
parser_issuite
(
PyST_Object
*
,
PyObject
*
,
PyObject
*
);
...
@@ -203,7 +203,7 @@ PyTypeObject PyST_Type = {
...
@@ -203,7 +203,7 @@ PyTypeObject PyST_Type = {
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
(
cmpfunc
)
parser_compare
,
/* tp_compare
*/
0
,
/* tp_compare
*/
0
,
/* tp_repr */
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
...
@@ -223,7 +223,7 @@ PyTypeObject PyST_Type = {
...
@@ -223,7 +223,7 @@ PyTypeObject PyST_Type = {
"Intermediate representation of a Python parse tree."
,
"Intermediate representation of a Python parse tree."
,
0
,
/* tp_traverse */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
parser_richcompare
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
...
@@ -231,6 +231,9 @@ PyTypeObject PyST_Type = {
...
@@ -231,6 +231,9 @@ PyTypeObject PyST_Type = {
};
/* PyST_Type */
};
/* PyST_Type */
/* PyST_Type isn't subclassable, so just check ob_type */
#define PyST_Object_Check(v) ((v)->ob_type == &PyST_Type)
static
int
static
int
parser_compare_nodes
(
node
*
left
,
node
*
right
)
parser_compare_nodes
(
node
*
left
,
node
*
right
)
{
{
...
@@ -260,26 +263,69 @@ parser_compare_nodes(node *left, node *right)
...
@@ -260,26 +263,69 @@ parser_compare_nodes(node *left, node *right)
return
(
0
);
return
(
0
);
}
}
/* parser_richcompare(PyObject* left, PyObject* right, int op)
/* int parser_compare(PyST_Object* left, PyST_Object* right)
*
*
* Comparison function used by the Python operators ==, !=, <, >, <=, >=
* Comparison function used by the Python operators ==, !=, <, >, <=, >=
* This really just wraps a call to parser_compare_nodes() with some easy
* This really just wraps a call to parser_compare_nodes() with some easy
* checks and protection code.
* checks and protection code.
*
*
*/
*/
static
int
parser_compare
(
PyST_Object
*
left
,
PyST_Object
*
right
)
#define TEST_COND(cond) ((cond) ? Py_True : Py_False)
static
PyObject
*
parser_richcompare
(
PyObject
*
left
,
PyObject
*
right
,
int
op
)
{
{
i
f
(
left
==
right
)
i
nt
result
;
return
(
0
)
;
PyObject
*
v
;
if
((
left
==
0
)
||
(
right
==
0
))
/* neither argument should be NULL, unless something's gone wrong */
return
(
-
1
);
if
(
left
==
NULL
||
right
==
NULL
)
{
PyErr_BadInternalCall
();
return
NULL
;
}
return
(
parser_compare_nodes
(
left
->
st_node
,
right
->
st_node
));
/* both arguments should be instances of PyST_Object */
}
if
(
!
PyST_Object_Check
(
left
)
||
!
PyST_Object_Check
(
right
))
{
v
=
Py_NotImplemented
;
goto
finished
;
}
if
(
left
==
right
)
/* if arguments are identical, they're equal */
result
=
0
;
else
result
=
parser_compare_nodes
(((
PyST_Object
*
)
left
)
->
st_node
,
((
PyST_Object
*
)
right
)
->
st_node
);
/* Convert return value to a Boolean */
switch
(
op
)
{
case
Py_EQ
:
v
=
TEST_COND
(
result
==
0
);
break
;
case
Py_NE
:
v
=
TEST_COND
(
result
!=
0
);
break
;
case
Py_LE
:
v
=
TEST_COND
(
result
<=
0
);
break
;
case
Py_GE
:
v
=
TEST_COND
(
result
>=
0
);
break
;
case
Py_LT
:
v
=
TEST_COND
(
result
<
0
);
break
;
case
Py_GT
:
v
=
TEST_COND
(
result
>
0
);
break
;
default:
PyErr_BadArgument
();
return
NULL
;
}
finished:
Py_INCREF
(
v
);
return
v
;
}
/* parser_newstobject(node* st)
/* parser_newstobject(node* st)
*
*
...
...
Modules/pyexpat.c
View file @
9916ee8e
...
@@ -1622,7 +1622,7 @@ static PyTypeObject Xmlparsetype = {
...
@@ -1622,7 +1622,7 @@ static PyTypeObject Xmlparsetype = {
(
printfunc
)
0
,
/*tp_print*/
(
printfunc
)
0
,
/*tp_print*/
0
,
/*tp_getattr*/
0
,
/*tp_getattr*/
(
setattrfunc
)
xmlparse_setattr
,
/*tp_setattr*/
(
setattrfunc
)
xmlparse_setattr
,
/*tp_setattr*/
(
cmpfunc
)
0
,
/*tp_compare*/
0
,
/*tp_compare*/
(
reprfunc
)
0
,
/*tp_repr*/
(
reprfunc
)
0
,
/*tp_repr*/
0
,
/*tp_as_number*/
0
,
/*tp_as_number*/
0
,
/*tp_as_sequence*/
0
,
/*tp_as_sequence*/
...
...
Objects/cellobject.c
View file @
9916ee8e
...
@@ -51,16 +51,56 @@ cell_dealloc(PyCellObject *op)
...
@@ -51,16 +51,56 @@ cell_dealloc(PyCellObject *op)
PyObject_GC_Del
(
op
);
PyObject_GC_Del
(
op
);
}
}
static
int
#define TEST_COND(cond) ((cond) ? Py_True : Py_False)
cell_compare
(
PyCellObject
*
a
,
PyCellObject
*
b
)
static
PyObject
*
cell_richcompare
(
PyObject
*
a
,
PyObject
*
b
,
int
op
)
{
{
if
(
a
->
ob_ref
==
NULL
)
{
int
result
;
if
(
b
->
ob_ref
==
NULL
)
PyObject
*
v
;
return
0
;
return
-
1
;
/* neither argument should be NULL, unless something's gone wrong */
}
else
if
(
b
->
ob_ref
==
NULL
)
assert
(
a
!=
NULL
&&
b
!=
NULL
);
return
1
;
return
PyObject_Compare
(
a
->
ob_ref
,
b
->
ob_ref
);
/* both arguments should be instances of PyCellObject */
if
(
!
PyCell_Check
(
a
)
||
!
PyCell_Check
(
b
))
{
v
=
Py_NotImplemented
;
Py_INCREF
(
v
);
return
v
;
}
/* compare cells by contents; empty cells come before anything else */
a
=
((
PyCellObject
*
)
a
)
->
ob_ref
;
b
=
((
PyCellObject
*
)
b
)
->
ob_ref
;
if
(
a
!=
NULL
&&
b
!=
NULL
)
return
PyObject_RichCompare
(
a
,
b
,
op
);
result
=
(
b
==
NULL
)
-
(
a
==
NULL
);
switch
(
op
)
{
case
Py_EQ
:
v
=
TEST_COND
(
result
==
0
);
break
;
case
Py_NE
:
v
=
TEST_COND
(
result
!=
0
);
break
;
case
Py_LE
:
v
=
TEST_COND
(
result
<=
0
);
break
;
case
Py_GE
:
v
=
TEST_COND
(
result
>=
0
);
break
;
case
Py_LT
:
v
=
TEST_COND
(
result
<
0
);
break
;
case
Py_GT
:
v
=
TEST_COND
(
result
>
0
);
break
;
default:
PyErr_BadArgument
();
return
NULL
;
}
Py_INCREF
(
v
);
return
v
;
}
}
static
PyObject
*
static
PyObject
*
...
@@ -114,7 +154,7 @@ PyTypeObject PyCell_Type = {
...
@@ -114,7 +154,7 @@ PyTypeObject PyCell_Type = {
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
(
cmpfunc
)
cell_compare
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
cell_repr
,
/* tp_repr */
(
reprfunc
)
cell_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
...
@@ -129,7 +169,7 @@ PyTypeObject PyCell_Type = {
...
@@ -129,7 +169,7 @@ PyTypeObject PyCell_Type = {
0
,
/* tp_doc */
0
,
/* tp_doc */
(
traverseproc
)
cell_traverse
,
/* tp_traverse */
(
traverseproc
)
cell_traverse
,
/* tp_traverse */
(
inquiry
)
cell_clear
,
/* tp_clear */
(
inquiry
)
cell_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
cell_richcompare
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
...
...
Objects/descrobject.c
View file @
9916ee8e
...
@@ -774,12 +774,6 @@ proxy_traverse(PyObject *self, visitproc visit, void *arg)
...
@@ -774,12 +774,6 @@ proxy_traverse(PyObject *self, visitproc visit, void *arg)
return
0
;
return
0
;
}
}
static
int
proxy_compare
(
proxyobject
*
v
,
PyObject
*
w
)
{
return
PyObject_Compare
(
v
->
dict
,
w
);
}
static
PyObject
*
static
PyObject
*
proxy_richcompare
(
proxyobject
*
v
,
PyObject
*
w
,
int
op
)
proxy_richcompare
(
proxyobject
*
v
,
PyObject
*
w
,
int
op
)
{
{
...
@@ -796,7 +790,7 @@ PyTypeObject PyDictProxy_Type = {
...
@@ -796,7 +790,7 @@ PyTypeObject PyDictProxy_Type = {
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
(
cmpfunc
)
proxy_compare
,
/* tp_compare */
0
,
/* tp_compare */
0
,
/* tp_repr */
0
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
&
proxy_as_sequence
,
/* tp_as_sequence */
&
proxy_as_sequence
,
/* tp_as_sequence */
...
@@ -844,12 +838,17 @@ PyDictProxy_New(PyObject *dict)
...
@@ -844,12 +838,17 @@ PyDictProxy_New(PyObject *dict)
/* This has no reason to be in this file except that adding new files is a
/* This has no reason to be in this file except that adding new files is a
bit of a pain */
bit of a pain */
/* forward */
static
PyTypeObject
wrappertype
;
typedef
struct
{
typedef
struct
{
PyObject_HEAD
PyObject_HEAD
PyWrapperDescrObject
*
descr
;
PyWrapperDescrObject
*
descr
;
PyObject
*
self
;
PyObject
*
self
;
}
wrapperobject
;
}
wrapperobject
;
#define Wrapper_Check(v) (Py_TYPE(v) == &wrappertype)
static
void
static
void
wrapper_dealloc
(
wrapperobject
*
wp
)
wrapper_dealloc
(
wrapperobject
*
wp
)
{
{
...
@@ -861,13 +860,60 @@ wrapper_dealloc(wrapperobject *wp)
...
@@ -861,13 +860,60 @@ wrapper_dealloc(wrapperobject *wp)
Py_TRASHCAN_SAFE_END
(
wp
)
Py_TRASHCAN_SAFE_END
(
wp
)
}
}
static
int
#define TEST_COND(cond) ((cond) ? Py_True : Py_False)
wrapper_compare
(
wrapperobject
*
a
,
wrapperobject
*
b
)
static
PyObject
*
wrapper_richcompare
(
PyObject
*
a
,
PyObject
*
b
,
int
op
)
{
{
if
(
a
->
descr
==
b
->
descr
)
int
result
;
return
PyObject_Compare
(
a
->
self
,
b
->
self
);
PyObject
*
v
;
else
PyWrapperDescrObject
*
a_descr
,
*
b_descr
;
return
(
a
->
descr
<
b
->
descr
)
?
-
1
:
1
;
assert
(
a
!=
NULL
&&
b
!=
NULL
);
/* both arguments should be wrapperobjects */
if
(
!
Wrapper_Check
(
a
)
||
!
Wrapper_Check
(
b
))
{
v
=
Py_NotImplemented
;
Py_INCREF
(
v
);
return
v
;
}
/* compare by descriptor address; if the descriptors are the same,
compare by the objects they're bound to */
a_descr
=
((
wrapperobject
*
)
a
)
->
descr
;
b_descr
=
((
wrapperobject
*
)
b
)
->
descr
;
if
(
a_descr
==
b_descr
)
{
a
=
((
wrapperobject
*
)
a
)
->
self
;
b
=
((
wrapperobject
*
)
b
)
->
self
;
return
PyObject_RichCompare
(
a
,
b
,
op
);
}
result
=
a_descr
-
b_descr
;
switch
(
op
)
{
case
Py_EQ
:
v
=
TEST_COND
(
result
==
0
);
break
;
case
Py_NE
:
v
=
TEST_COND
(
result
!=
0
);
break
;
case
Py_LE
:
v
=
TEST_COND
(
result
<=
0
);
break
;
case
Py_GE
:
v
=
TEST_COND
(
result
>=
0
);
break
;
case
Py_LT
:
v
=
TEST_COND
(
result
<
0
);
break
;
case
Py_GT
:
v
=
TEST_COND
(
result
>
0
);
break
;
default:
PyErr_BadArgument
();
return
NULL
;
}
Py_INCREF
(
v
);
return
v
;
}
}
static
long
static
long
...
@@ -977,7 +1023,7 @@ static PyTypeObject wrappertype = {
...
@@ -977,7 +1023,7 @@ static PyTypeObject wrappertype = {
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
(
cmpfunc
)
wrapper_compare
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
wrapper_repr
,
/* tp_repr */
(
reprfunc
)
wrapper_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
...
@@ -992,7 +1038,7 @@ static PyTypeObject wrappertype = {
...
@@ -992,7 +1038,7 @@ static PyTypeObject wrappertype = {
0
,
/* tp_doc */
0
,
/* tp_doc */
wrapper_traverse
,
/* tp_traverse */
wrapper_traverse
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
wrapper_richcompare
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
...
...
Objects/rangeobject.c
View file @
9916ee8e
...
@@ -123,7 +123,7 @@ range_length_obj(rangeobject *r)
...
@@ -123,7 +123,7 @@ range_length_obj(rangeobject *r)
Algorithm is equal to that of get_len_of_range(), but it operates
Algorithm is equal to that of get_len_of_range(), but it operates
on PyObjects (which are assumed to be PyLong or PyInt objects).
on PyObjects (which are assumed to be PyLong or PyInt objects).
---------------------------------------------------------------*/
---------------------------------------------------------------*/
int
cmp_result
,
cmp_call
;
int
cmp_result
;
PyObject
*
lo
,
*
hi
;
PyObject
*
lo
,
*
hi
;
PyObject
*
step
=
NULL
;
PyObject
*
step
=
NULL
;
PyObject
*
diff
=
NULL
;
PyObject
*
diff
=
NULL
;
...
@@ -134,13 +134,12 @@ range_length_obj(rangeobject *r)
...
@@ -134,13 +134,12 @@ range_length_obj(rangeobject *r)
PyObject
*
zero
=
PyLong_FromLong
(
0
);
PyObject
*
zero
=
PyLong_FromLong
(
0
);
if
(
zero
==
NULL
)
if
(
zero
==
NULL
)
return
NULL
;
return
NULL
;
cmp_
call
=
PyObject_Cmp
(
r
->
step
,
zero
,
&
cmp_result
);
cmp_
result
=
PyObject_RichCompareBool
(
r
->
step
,
zero
,
Py_GT
);
Py_DECREF
(
zero
);
Py_DECREF
(
zero
);
if
(
cmp_
call
==
-
1
)
if
(
cmp_
result
==
-
1
)
return
NULL
;
return
NULL
;
assert
(
cmp_result
!=
0
);
if
(
cmp_result
==
1
)
{
if
(
cmp_result
>
0
)
{
lo
=
r
->
start
;
lo
=
r
->
start
;
hi
=
r
->
stop
;
hi
=
r
->
stop
;
step
=
r
->
step
;
step
=
r
->
step
;
...
@@ -154,7 +153,7 @@ range_length_obj(rangeobject *r)
...
@@ -154,7 +153,7 @@ range_length_obj(rangeobject *r)
}
}
/* if (lo >= hi), return length of 0. */
/* if (lo >= hi), return length of 0. */
if
(
PyObject_
Compare
(
lo
,
hi
)
>=
0
)
{
if
(
PyObject_
RichCompareBool
(
lo
,
hi
,
Py_GE
)
==
1
)
{
Py_XDECREF
(
step
);
Py_XDECREF
(
step
);
return
PyLong_FromLong
(
0
);
return
PyLong_FromLong
(
0
);
}
}
...
...
Objects/setobject.c
View file @
9916ee8e
...
@@ -1824,13 +1824,6 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
...
@@ -1824,13 +1824,6 @@ set_richcompare(PySetObject *v, PyObject *w, int op)
return
Py_NotImplemented
;
return
Py_NotImplemented
;
}
}
static
int
set_nocmp
(
PyObject
*
self
,
PyObject
*
other
)
{
PyErr_SetString
(
PyExc_TypeError
,
"cannot compare sets using cmp()"
);
return
-
1
;
}
static
PyObject
*
static
PyObject
*
set_add
(
PySetObject
*
so
,
PyObject
*
key
)
set_add
(
PySetObject
*
so
,
PyObject
*
key
)
{
{
...
@@ -2111,7 +2104,7 @@ PyTypeObject PySet_Type = {
...
@@ -2111,7 +2104,7 @@ PyTypeObject PySet_Type = {
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
set_nocmp
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
set_repr
,
/* tp_repr */
(
reprfunc
)
set_repr
,
/* tp_repr */
&
set_as_number
,
/* tp_as_number */
&
set_as_number
,
/* tp_as_number */
&
set_as_sequence
,
/* tp_as_sequence */
&
set_as_sequence
,
/* tp_as_sequence */
...
@@ -2208,7 +2201,7 @@ PyTypeObject PyFrozenSet_Type = {
...
@@ -2208,7 +2201,7 @@ PyTypeObject PyFrozenSet_Type = {
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
set_nocmp
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
set_repr
,
/* tp_repr */
(
reprfunc
)
set_repr
,
/* tp_repr */
&
frozenset_as_number
,
/* tp_as_number */
&
frozenset_as_number
,
/* tp_as_number */
&
set_as_sequence
,
/* tp_as_sequence */
&
set_as_sequence
,
/* tp_as_sequence */
...
...
PC/winreg.c
View file @
9916ee8e
...
@@ -326,7 +326,7 @@ PyDoc_STRVAR(PyHKEY_doc,
...
@@ -326,7 +326,7 @@ PyDoc_STRVAR(PyHKEY_doc,
"Operations:
\n
"
"Operations:
\n
"
"__bool__ - Handles with an open object return true, otherwise false.
\n
"
"__bool__ - Handles with an open object return true, otherwise false.
\n
"
"__int__ - Converting a handle to an integer returns the Win32 handle.
\n
"
"__int__ - Converting a handle to an integer returns the Win32 handle.
\n
"
"
__cmp__
- Handle objects are compared using the handle value."
);
"
rich comparison
- Handle objects are compared using the handle value."
);
PyDoc_STRVAR
(
PyHKEY_Close_doc
,
PyDoc_STRVAR
(
PyHKEY_Close_doc
,
...
@@ -485,7 +485,7 @@ PyTypeObject PyHKEY_Type =
...
@@ -485,7 +485,7 @@ PyTypeObject PyHKEY_Type =
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
PyHKEY_compareFunc
,
/* tp_compare */
0
,
/* tp_compare */
0
,
/* tp_repr */
0
,
/* tp_repr */
&
PyHKEY_NumberMethods
,
/* tp_as_number */
&
PyHKEY_NumberMethods
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
...
...
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