Guido van Rossum [Tue, 30 Oct 2001 03:17:30 +0000 (03:17 +0000)]
Fix SF bug #456386: test_commands regression failure (Andrew Dalke)
test_commands does not work on IRIX
It assumes the output of "ls /bin/ls" is a line
that starts with a '-'. On IRIX that file is
a symbolic link, so the first character is an l.
This causes test_getstatus to fail.
Tim Peters [Tue, 30 Oct 2001 01:26:49 +0000 (01:26 +0000)]
PySocketSock_connect_ex(): On Windows, return the correct Windows exit
code. The patch is from Jeremy, and allows test_asynchat to run again.
Bugfix candidate.
Guido van Rossum [Mon, 29 Oct 2001 22:11:00 +0000 (22:11 +0000)]
Add __del__ callbacks. They are too useful to leave out.
XXX Remaining problems:
- The GC module doesn't know about these; I think it has its reasons
to disallow calling __del__, but for now, __del__ on new-style
objects is called when the GC module discards an object, for better
or for worse.
- The code to call a __del__ handler is really ridiculously
complicated, due to all the different debug #ifdefs. I've copied
this from the similar code in classobject.c, so I'm pretty sure I
did it right, but it's not pretty. :-(
Tim Peters [Mon, 29 Oct 2001 21:46:08 +0000 (21:46 +0000)]
SF bug #476138: tempfile behavior across platforms
Ensure that a tempfile can be closed any number of times without error.
This wasn't true on Windows.
Fred Drake [Mon, 29 Oct 2001 21:02:28 +0000 (21:02 +0000)]
Revise the PDF support in the LaTeX style sheet. This still isn't quite
right, but the tests for whether we are generating PDF are a bit more
readable, and some unnecessary indirection has been removed.
Fred Drake [Mon, 29 Oct 2001 20:57:23 +0000 (20:57 +0000)]
Update to reflect changes to the low-level logreader: share the info
dictionary instead of building a new one, and provide an overridable method
to allow subclasses to catch ADD_INFO records that are not part of the
initial block of ADD_INFO records created by the profiler itself.
Fred Drake [Mon, 29 Oct 2001 20:45:57 +0000 (20:45 +0000)]
Make the low-level log-reader object export a dictionary mapping keys
to lists of values, giving the contents of all the ADD_INFO records
seen so far. This is initialized agressively when the log file is
opened, so that whoever is looking at the log reader can always see
the initial data loaded into the data stream. ADD_INFO events later
in the log file continue to be reported to the application layer as
before.
Add a new method, addinfo(), to the profiler. This can be used to
insert additional ADD_INFO records into the profiler log.
Fix the tp_flags and tp_name slots on the type objects.
Fred Drake [Mon, 29 Oct 2001 18:01:24 +0000 (18:01 +0000)]
Add additional information on exceptions from time.mktime() and related to
improper time tuples passed to various functions. Based on comments from
Andreas Jung.
Fred Drake [Mon, 29 Oct 2001 17:40:40 +0000 (17:40 +0000)]
Make sure we generate versions of each file in the Python/C API manual with
reference-count annotations; this is needed for the typeset forms of the
manuals.
Guido van Rossum [Sun, 28 Oct 2001 12:31:33 +0000 (12:31 +0000)]
Oops. In the tp_name field, the name should be "_socket.socket", not
"socket.socket" -- on Windows, "socket.socket" is the wrapper class.
Also added the module name to the SSL type (which is not a new-style
class -- I don't want to mess with it yet).
Guido van Rossum [Sat, 27 Oct 2001 22:20:47 +0000 (22:20 +0000)]
Made SocketType and socket the same thing: a subclassable type whose
constructor acts just like socket() before. All three arguments have
a sensible default now; socket() is equivalent to
socket(AF_INET, SOCK_STREAM).
One minor issue: the socket() function and the SocketType had
different doc strings; socket.__doc__ gave the signature,
SocketType.__doc__ gave the methods. I've merged these for now, but
maybe the list of methods is no longer necessary since it can easily
be recovered through socket.__dict__.keys(). The problem with keeping
it is that the total doc string is a bit long (34 lines -- it scrolls
of a standard tty screen).
Another general issue with the socket module is that it's a big mess.
There's pages and pages of random platform #ifdefs, and the naming
conventions are totally wrong: it uses Py prefixes and CapWords for
static functions. That's a cleanup for another day... (Also I think
the big starting comment that summarizes the API can go -- it's a
repeat of the docstring.)
Tim Peters [Sat, 27 Oct 2001 19:37:48 +0000 (19:37 +0000)]
SF bug #475327: type() produces incorrect error msg
object.h: Added PyType_CheckExact macro.
typeobject.c, type_new():
+ Use the new macro.
+ Assert that the arguments have the right types rather than do incomplete
runtime checks "sometimes".
+ If this isn't the 1-argument flavor() of type, and there aren't 3 args
total, produce a "types() takes 1 or 3 args" msg before
PyArg_ParseTupleAndKeywords produces a "takes exactly 3" msg.
Tim Peters [Sat, 27 Oct 2001 18:27:48 +0000 (18:27 +0000)]
dictionary() constructor:
+ Change keyword arg name from "x" to "items". People passing a mapping
object can stretch their imaginations <wink>.
+ Simplify the docstring text.
Tim Peters [Sat, 27 Oct 2001 07:25:06 +0000 (07:25 +0000)]
vgetargskeywords()
+ Squash another potential buffer overrun.
+ Simplify the keyword-arg loop by decrementing the count of keywords
remaining instead of incrementing Yet Another Variable; also break
out early if the number of keyword args remaining hits 0.
Since I hit the function's closing curly brace with this patch, that's
enough of this for now <wink>.
Fred Drake [Sat, 27 Oct 2001 06:16:31 +0000 (06:16 +0000)]
PyObject_CallFunction(), PyObject_CallMethod(): Make sure we do not touch
the va_list until we are sure we have a format string and need to use it;
this avoid premature initialization and having to finalize it several
different places because of error returns.
Tim Peters [Sat, 27 Oct 2001 06:14:32 +0000 (06:14 +0000)]
vgetargskeywords: Removed all PyErr_Clear() calls. It's possible that
this routine will report an error now when it didn't before, but, if so,
it's a legitimate error that should never have been suppressed.
Tim Peters [Sat, 27 Oct 2001 05:30:17 +0000 (05:30 +0000)]
vgetargskeywords: Removed one of the mysterious PyErr_Clear() calls.
The "need" for this was probably removed by an earlier patch that stopped
the loop right before it from passing NULL to a dict lookup routine.
I still haven't convinced myself that the next loop is correct, so am
leaving the next mysterious PyErr_Clear() call in for now.
Tim Peters [Sat, 27 Oct 2001 05:07:41 +0000 (05:07 +0000)]
vgetargskeywords:
+ Generally test nkeywords against 0 instead of keywords against NULL
(saves a little work if an empty keywords dict is passed, and is
conceptually more on-target regardless).
+ When a call erroneously specifies a keyword argument both by position
and by keyword name:
- It was easy to provoke this routine into an internal buffer overrun
by using a long argument name. Now uses PyErr_format instead (which
computes a safe buffer size).
- Improved the error msg.
Tim Peters [Sat, 27 Oct 2001 04:45:34 +0000 (04:45 +0000)]
vgetargskeywords:
+ Got rid of now-redundant dict typecheck.
+ Renamed nkwds to nkwlist. Now all the "counting" vrbls have names
related to the things they're counting in an obvious way.
Tim Peters [Sat, 27 Oct 2001 04:38:11 +0000 (04:38 +0000)]
vgetargskeywords:
+ Renamed argslen to nargs.
+ Renamed kwlen to nkeywords. This one was especially confusing because
kwlen wasn't the length of the kwlist argument, but of the keywords
argument.
Tim Peters [Sat, 27 Oct 2001 04:33:41 +0000 (04:33 +0000)]
vgetargskeywords:
+ Removed now-redundant tuple typecheck.
+ Renamed "tplen" local to "argslen" (it's the length of the "args"
argument; I suppose "tp" was for "Tim Peters should rename me
someday <wink>).
Tim Peters [Sat, 27 Oct 2001 04:26:57 +0000 (04:26 +0000)]
PyArg_ParseTupleAndKeywords: return false on internal error, not -1 (I
introduced this bug just a little while ago, when *adding* internal error
checks).
vgetargskeywords: Rewrote the section that crawls over the format string.
+ Added block comment so it won't take the next person 15 minutes to
reverse-engineer what it's doing.
+ Lined up the "else" clauses.
+ Rearranged the ifs in decreasing order of likelihood (for speed).
Tim Peters [Sat, 27 Oct 2001 03:58:40 +0000 (03:58 +0000)]
PyArg_ParseTupleAndKeywords: do basic sanity checks on the arguments,
and raise an error if they're insane.
vgetargskeywords: the same, except that since this is an internal routine,
just assert that the arguments are sane.
Tim Peters [Sat, 27 Oct 2001 00:46:09 +0000 (00:46 +0000)]
tuple(3,4,5,x=2) dumped core on my box. vgetargskeywords() overindexed
the kwlist vector whenever there was a mix of positional and keyword
arguments, and the number of positional arguments exceeded the length
of the kwlist vector. If there was just one more positional arg than
keyword, the kwlist-terminating NULL got passed to PyMapping_HasKeyString,
which set an internal error that vgetargskeywords() then squashed (but
it's impossible to say whether it knew it was masking an error). If
more than one more positional argument, it went on to pass random trash
to PyMapping_HasKeyString, which is why the example at the start
happened to kill the process.
Tim Peters [Fri, 26 Oct 2001 20:57:38 +0000 (20:57 +0000)]
dict_constructor(): The last test was passing for the wrong reason (it
was intended to verify that sub-sequences of lengths 1 and 3 raise
ValueError, but was actually testing string lengths).
Fill in remaining XXX spots
- Describe UnpackTuple()
- Credit __unicode__ to MAL
Use \pep macro everywhere in body text.
(Listening to "The Great Gate of Kiev" -- appropriately triumphal
music for this check-in...)
Fred Drake [Fri, 26 Oct 2001 18:37:27 +0000 (18:37 +0000)]
Add notes pointing out that these classes are kept for backward compatibility
and suggeest that new code that does not require compatibility with older
Python versions subclass dictionary, list, or str.
Fred Drake [Fri, 26 Oct 2001 17:56:51 +0000 (17:56 +0000)]
Be smarter about clearing the weakref lists for instances, instance methods,
and functions: we only need to call PyObject_ClearWeakRefs() if the weakref
list is non-NULL. Since these objects are common but weakrefs are still
unusual, saving the call at deallocation time makes a lot of sense.
Fred Drake [Fri, 26 Oct 2001 16:21:32 +0000 (16:21 +0000)]
Added two new functions to conveniently call functions/methods from C.
PyObject_CallFunctionObArgs() and PyObject_CallMethodObArgs() have the
advantage that no format strings need to be parsed. The CallMethod
variant also avoids creating a new string object in order to retrieve
a method from an object as well.
Fred Drake [Fri, 26 Oct 2001 14:16:23 +0000 (14:16 +0000)]
Clean up the tables of child links generated by stock LaTeX2HTML so we get
consistent (lack of) vertical space between sections, and remove some of the
unnecessary cruft that was added in (finally we get to *remove* something
that got generated!).
Tim Peters [Fri, 26 Oct 2001 05:06:50 +0000 (05:06 +0000)]
Generalize dictionary() to accept a sequence of 2-sequences. At the
outer level, the iterator protocol is used for memory-efficiency (the
outer sequence may be very large if fully materialized); at the inner
level, PySequence_Fast() is used for time-efficiency (these should
always be sequences of length 2).
dictobject.c, new functions PyDict_{Merge,Update}FromSeq2. These are
wholly analogous to PyDict_{Merge,Update}, but process a sequence-of-2-
sequences argument instead of a mapping object. For now, I left these
functions file static, so no corresponding doc changes. It's tempting
to change dict.update() to allow a sequence-of-2-seqs argument too.
Also changed the name of dictionary's keyword argument from "mapping"
to "x". Got a better name? "mapping_or_sequence_of_pairs" isn't
attractive, although more so than "mosop" <wink>.
abstract.h, abstract.tex: Added new PySequence_Fast_GET_SIZE function,
much faster than going thru the all-purpose PySequence_Size.
libfuncs.tex:
- Document dictionary().
- Fiddle tuple() and list() to admit that their argument is optional.
- The long-winded repetitions of "a sequence, a container that supports
iteration, or an iterator object" is getting to be a PITA. Many
months ago I suggested factoring this out into "iterable object",
where the definition of that could include being explicit about
generators too (as is, I'm not sure a reader outside of PythonLabs
could guess that "an iterator object" includes a generator call).
- Please check my curly braces -- I'm going blind <0.9 wink>.
abstract.c, PySequence_Tuple(): When PyObject_GetIter() fails, leave
its error msg alone now (the msg it produces has improved since
PySequence_Tuple was generalized to accept iterable objects, and
PySequence_Tuple was also stomping on the msg in cases it shouldn't
have even before PyObject_GetIter grew a better msg).
Guido van Rossum [Fri, 26 Oct 2001 03:25:00 +0000 (03:25 +0000)]
Add sendall() method, which loops until all data is written or an
error occurs, and doesn't return a count. (This is my second patch
from SF patch #474307, with small change to the docstring for send().)
Fred Drake [Fri, 26 Oct 2001 03:09:27 +0000 (03:09 +0000)]
Add yet more markup that let's a stylesheet pick out a small bit of the
presentation. This is acceptable since it only occurs in the formatted
output and does not affect the document markup.
Fred Drake [Fri, 26 Oct 2001 03:04:23 +0000 (03:04 +0000)]
Enforce a bit of markup consistency.
When describing a Boolean return value, use "true" and "false" instead of
"1" and "0".
Style-guide conformance: no "iff" -- to obscure for many readers. ;-(
Barry Warsaw [Thu, 25 Oct 2001 21:49:18 +0000 (21:49 +0000)]
Applying proposed patch for bug #474583, optional support for
non-standard but common types. Including Martin's suggestion to add
rejected non-standard types from patch #438790. Specifically,
guess_type(), guess_extension(): Both the functions and the methods
grow an optional "strict" flag, defaulting to true, which determines
whether to recognize non-standard, but commonly found types or not.
Also, I sorted, reformatted, and culled duplicates from the big
types_map dictionary. Note that there are a few non-equivalent
duplicates (e.g. .cdf and .xls) for which the first will just get
thrown away. I didn't remove those though.
Finally, use of the module as a script as grown the -l and -e options
to toggle strictness and to do guess_extension(), respectively.