Skip to content

Commit fd66e51

Browse files
committed
Merged revisions 60383-60407 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r60388 | thomas.heller | 2008-01-28 09:44:13 +0100 (Mon, 28 Jan 2008) | 1 line Revert rev. 59925, it breaks comtypes (I need to further examine this). ........ r60397 | raymond.hettinger | 2008-01-28 21:34:33 +0100 (Mon, 28 Jan 2008) | 5 lines Make PySet_Add() work with frozensets. Works like PyTuple_SetItem() to build-up values in a brand new frozenset. Also, PyFrozenSet_New() is now guaranteed to produce a distinct new frozenset. ........ r60398 | raymond.hettinger | 2008-01-28 22:34:30 +0100 (Mon, 28 Jan 2008) | 1 line Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple). ........ r60399 | raymond.hettinger | 2008-01-28 22:47:42 +0100 (Mon, 28 Jan 2008) | 1 line Factor-out common code with a new macro ........ r60400 | raymond.hettinger | 2008-01-28 22:48:07 +0100 (Mon, 28 Jan 2008) | 1 line Factor-out common code with a new macro ........ r60401 | raymond.hettinger | 2008-01-28 22:51:25 +0100 (Mon, 28 Jan 2008) | 1 line Removed unnecessary conditional (spotted by Neal Norwitz). ........ r60403 | gregory.p.smith | 2008-01-29 00:21:00 +0100 (Tue, 29 Jan 2008) | 4 lines Disable use of BerkeleyDB 4.6.x to see what the odd platform buildbots think. In particular, neal norwitz has traced an Ubuntu sparc64 crash to the Lib/test/bsddb/test_basics.py test when opening a db with DB_THREAD. ........ r60405 | brett.cannon | 2008-01-29 05:13:07 +0100 (Tue, 29 Jan 2008) | 2 lines Fix the reindent rule to use $(BUILDPYTHON). ........ r60406 | brett.cannon | 2008-01-29 05:18:04 +0100 (Tue, 29 Jan 2008) | 3 lines Update Vim syntax highlighting to specify what revision was used to generate the file. ........ r60407 | brett.cannon | 2008-01-29 05:20:56 +0100 (Tue, 29 Jan 2008) | 2 lines Ignore .pyc and .pyo files. ........
1 parent 1fd7770 commit fd66e51

File tree

11 files changed

+51
-55
lines changed

11 files changed

+51
-55
lines changed

Doc/c-api/set.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ The following type check macros work on pointers to any Python object. Likewise,
5050
the constructor functions work with any iterable Python object.
5151

5252

53+
.. cfunction:: int PySet_Check(PyObject *p)
54+
55+
Return true if *p* is a :class:`set` object or an instance of a subtype.
56+
57+
.. versionadded:: 2.6
58+
5359
.. cfunction:: int PyAnySet_Check(PyObject *p)
5460

5561
Return true if *p* is a :class:`set` object, a :class:`frozenset` object, or an
@@ -84,6 +90,11 @@ the constructor functions work with any iterable Python object.
8490
set on success or *NULL* on failure. Raise :exc:`TypeError` if *iterable* is
8591
not actually iterable.
8692

93+
.. versionchanged:: 2.6
94+
Now guaranteed to return a brand-new :class:`frozenset`. Formerly,
95+
frozensets of zero-length were a singleton. This got in the way of
96+
building-up new frozensets with :meth:`PySet_Add`.
97+
8798
The following functions and macros are available for instances of :class:`set`
8899
or :class:`frozenset` or instances of their subtypes.
89100

@@ -110,9 +121,6 @@ or :class:`frozenset` or instances of their subtypes.
110121
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
111122
:class:`set`, :class:`frozenset`, or an instance of a subtype.
112123

113-
The following functions are available for instances of :class:`set` or its
114-
subtypes but not for instances of :class:`frozenset` or its subtypes.
115-
116124

117125
.. cfunction:: int PySet_Add(PyObject *set, PyObject *key)
118126

@@ -122,6 +130,14 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
122130
Raise a :exc:`SystemError` if *set* is an not an instance of :class:`set` or its
123131
subtype.
124132

133+
.. versionchanged:: 2.6
134+
Now works with instances of :class:`frozenset` or its subtypes.
135+
Like :cfunc:`PyTuple_SetItem` in that it can be used to fill-in the
136+
values of brand new frozensets before they are exposed to other code.
137+
138+
The following functions are available for instances of :class:`set` or its
139+
subtypes but not for instances of :class:`frozenset` or its subtypes.
140+
125141

126142
.. cfunction:: int PySet_Discard(PyObject *set, PyObject *key)
127143

Include/setobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ PyAPI_DATA(PyTypeObject) PySetIter_Type;
7474
(Py_TYPE(ob) == &PySet_Type || Py_TYPE(ob) == &PyFrozenSet_Type || \
7575
PyType_IsSubtype(Py_TYPE(ob), &PySet_Type) || \
7676
PyType_IsSubtype(Py_TYPE(ob), &PyFrozenSet_Type))
77+
#define PySet_Check(ob) \
78+
(Py_TYPE(ob) == &PySet_Type || PyType_IsSubtype(Py_TYPE(ob), &PySet_Type))
7779

7880
PyAPI_FUNC(PyObject *) PySet_New(PyObject *);
7981
PyAPI_FUNC(PyObject *) PyFrozenSet_New(PyObject *);

Lib/ctypes/test/test_funcptr.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,5 @@ def c_string(init):
123123
self.failUnlessEqual(strtok(None, b"\n"), "c")
124124
self.failUnlessEqual(strtok(None, b"\n"), None)
125125

126-
def test_NULL_funcptr(self):
127-
tp = CFUNCTYPE(c_int)
128-
func = tp() # NULL function pointer
129-
# raise a ValueError when we try to call it
130-
self.assertRaises(ValueError, func)
131-
132126
if __name__ == '__main__':
133127
unittest.main()

Makefile.pre.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ config.status: $(srcdir)/configure
10431043

10441044
# Run reindent on the library
10451045
reindent:
1046-
./python$(EXEEXT) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
1046+
./$(BUILDPYTHON) $(srcdir)/Tools/scripts/reindent.py -r $(srcdir)/Lib
10471047

10481048
# Rerun configure with the same options as it was run last time,
10491049
# provided the config.status script exists

Misc/Vim/python.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" Auto-generated Vim syntax file for Python
1+
" Auto-generated Vim syntax file for Python (trunk: r60376M).
22
"
33
" To use: copy or symlink to ~/.vim/syntax/python.vim
44

@@ -63,7 +63,7 @@ endif
6363

6464
if exists("python_highlight_builtins")
6565
syn keyword pythonBuiltin Ellipsis False None NotImplemented True __debug__
66-
syn keyword pythonBuiltin __import__ abs all any basestring bool
66+
syn keyword pythonBuiltin __import__ abs all any bool
6767
syn keyword pythonBuiltin buffer callable chr classmethod cmp
6868
syn keyword pythonBuiltin complex copyright credits delattr dict
6969
syn keyword pythonBuiltin dir divmod enumerate eval exec exit
@@ -73,7 +73,8 @@ if exists("python_highlight_builtins")
7373
syn keyword pythonBuiltin max min object oct open ord pow property quit
7474
syn keyword pythonBuiltin range reload repr reversed round
7575
syn keyword pythonBuiltin set setattr slice sorted staticmethod str sum
76-
syn keyword pythonBuiltin super tuple type unichr unicode vars zip
76+
syn keyword pythonBuiltin super trunc tuple type unicode vars
77+
syn keyword pythonBuiltin zip
7778

7879
endif
7980

Misc/Vim/syntax_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
Not necessarily sensical or comprehensive (assume that if one exception is
55
highlighted that all are, for instance).
66
7-
Highlighting extraneous whitespace at the end of the line is not represented
8-
here as all trailing whitespace is automatically removed from .py files in the
9-
repository.
7+
Extraneous trailing whitespace can't be tested because of svn pre-commit hook
8+
checks for such things.
109
1110
"""
1211
# Comment

Misc/Vim/vim_syntax.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import exceptions
77
import builtins
88
from string import Template
9+
from sys import subversion
910

10-
comment_header = '''" Auto-generated Vim syntax file for Python.
11+
comment_header = '''" Auto-generated Vim syntax file for Python (%s: r%s).
1112
"
1213
" To use: copy or symlink to ~/.vim/syntax/python.vim'''
1314

@@ -162,7 +163,7 @@ def fill_stmt(iterable, fill_len):
162163
def main(file_path):
163164
with open(file_path, 'w') as FILE:
164165
# Comment for file
165-
print>>FILE, comment_header
166+
print>>FILE, comment_header % subversion[1:]
166167
print>>FILE, ''
167168
# Statements at start of file
168169
print>>FILE, statement_header

Modules/_ctypes/_ctypes.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,11 +3414,6 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
34143414

34153415

34163416
pProc = *(void **)self->b_ptr;
3417-
if (pProc == NULL) {
3418-
PyErr_SetString(PyExc_ValueError,
3419-
"attempt to call NULL function pointer");
3420-
return NULL;
3421-
}
34223417
#ifdef MS_WIN32
34233418
if (self->index) {
34243419
/* It's a COM method */

Objects/setobject.c

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,17 +2127,7 @@ PySet_New(PyObject *iterable)
21272127
PyObject *
21282128
PyFrozenSet_New(PyObject *iterable)
21292129
{
2130-
PyObject *args, *result;
2131-
2132-
if (iterable == NULL)
2133-
args = PyTuple_New(0);
2134-
else
2135-
args = PyTuple_Pack(1, iterable);
2136-
if (args == NULL)
2137-
return NULL;
2138-
result = frozenset_new(&PyFrozenSet_Type, args, NULL);
2139-
Py_DECREF(args);
2140-
return result;
2130+
return make_new_set(&PyFrozenSet_Type, iterable);
21412131
}
21422132

21432133
Py_ssize_t
@@ -2153,7 +2143,7 @@ PySet_Size(PyObject *anyset)
21532143
int
21542144
PySet_Clear(PyObject *set)
21552145
{
2156-
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
2146+
if (!PySet_Check(set)) {
21572147
PyErr_BadInternalCall();
21582148
return -1;
21592149
}
@@ -2173,21 +2163,21 @@ PySet_Contains(PyObject *anyset, PyObject *key)
21732163
int
21742164
PySet_Discard(PyObject *set, PyObject *key)
21752165
{
2176-
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
2166+
if (!PySet_Check(set)) {
21772167
PyErr_BadInternalCall();
21782168
return -1;
21792169
}
21802170
return set_discard_key((PySetObject *)set, key);
21812171
}
21822172

21832173
int
2184-
PySet_Add(PyObject *set, PyObject *key)
2174+
PySet_Add(PyObject *anyset, PyObject *key)
21852175
{
2186-
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
2176+
if (!PyAnySet_Check(anyset)) {
21872177
PyErr_BadInternalCall();
21882178
return -1;
21892179
}
2190-
return set_add_key((PySetObject *)set, key);
2180+
return set_add_key((PySetObject *)anyset, key);
21912181
}
21922182

21932183
int
@@ -2224,7 +2214,7 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash)
22242214
PyObject *
22252215
PySet_Pop(PyObject *set)
22262216
{
2227-
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
2217+
if (!PySet_Check(set)) {
22282218
PyErr_BadInternalCall();
22292219
return NULL;
22302220
}
@@ -2234,7 +2224,7 @@ PySet_Pop(PyObject *set)
22342224
int
22352225
_PySet_Update(PyObject *set, PyObject *iterable)
22362226
{
2237-
if (!PyType_IsSubtype(Py_TYPE(set), &PySet_Type)) {
2227+
if (!PySet_Check(set)) {
22382228
PyErr_BadInternalCall();
22392229
return -1;
22402230
}
@@ -2330,7 +2320,6 @@ test_c_api(PySetObject *so)
23302320
f = PyFrozenSet_New(dup);
23312321
assert(PySet_Size(f) == 3);
23322322
assert(PyFrozenSet_CheckExact(f));
2333-
assertRaises(PySet_Add(f, elem) == -1, PyExc_SystemError);
23342323
assertRaises(PySet_Discard(f, elem) == -1, PyExc_SystemError);
23352324
assertRaises(PySet_Pop(f) == NULL, PyExc_SystemError);
23362325
Py_DECREF(f);

Python/marshal.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ r_object(RFILE *p)
812812
retval = NULL;
813813
break;
814814
}
815-
v = PyTuple_New((int)n);
815+
v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL);
816816
if (v == NULL) {
817817
retval = NULL;
818818
break;
@@ -827,18 +827,14 @@ r_object(RFILE *p)
827827
v = NULL;
828828
break;
829829
}
830-
PyTuple_SET_ITEM(v, (int)i, v2);
831-
}
832-
if (v == NULL) {
833-
retval = NULL;
834-
break;
830+
if (PySet_Add(v, v2) == -1) {
831+
Py_DECREF(v);
832+
Py_DECREF(v2);
833+
v = NULL;
834+
break;
835+
}
835836
}
836-
if (type == TYPE_SET)
837-
v3 = PySet_New(v);
838-
else
839-
v3 = PyFrozenSet_New(v);
840-
Py_DECREF(v);
841-
retval = v3;
837+
retval = v;
842838
break;
843839

844840
case TYPE_CODE:

0 commit comments

Comments
 (0)