Commit Graph

1237 Commits

Author SHA1 Message Date
Marc-André Lemburg 6871f6ac57 Implement the changes proposed in patch #413333. unicode(obj) now
works just like str(obj) in that it tries __str__/tp_str on the object
in case it finds that the object is not a string or buffer.
2001-09-20 12:53:16 +00:00
Marc-André Lemburg c60e6f7771 Patch #435971: UTF-7 codec by Brian Quinlan. 2001-09-20 10:35:46 +00:00
Tim Peters efc3a3af3b SF bug [#463093] File methods need doc strings.
Now they don't.
2001-09-20 07:55:22 +00:00
Martin v. Löwis 2777c021fc Patch #462849: Pass Unicode objects to file's .write method. 2001-09-19 13:47:32 +00:00
Guido van Rossum 1952e388ca Add additional coercion support for "self subtypes" to int, long,
float (compare the recent checkin to complex).  Added tests for these.
2001-09-19 01:25:16 +00:00
Guido van Rossum 638059603c complex_coerce(): add explicit PyComplex_Check() test. Previously,
complex_coerce() would never be called with a complex argument,
because PyNumber_Coerce[Ex] doesn't bother calling the type's coercion
method if the values already have the same type.  But now, of course,
it's possible to pass an instance of a complex *subtype*, and those
must be accepted.
2001-09-19 01:13:10 +00:00
Guido van Rossum ab3b0343b8 Hopefully fix 3-way comparisons. This unfortunately adds yet another
hack, and it's even more disgusting than a PyInstance_Check() call.
If the tp_compare slot is the slot used for overrides in Python,
it's always called.

Add some tests that show what should work too.
2001-09-18 20:38:53 +00:00
Martin v. Löwis cf95f9cacb Properly repr classes without module names. 2001-09-18 20:23:28 +00:00
Guido van Rossum ceccae5365 wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
only safely call a type's tp_compare slot if the second argument is
also an instance of the same type.  I hate to think what
e.g. int_compare() would do with a second argument that's a float!
2001-09-18 20:03:57 +00:00
Guido van Rossum f0b35e1501 Redo the PyMethod attributes using a dir()-friendly approach, creating
descriptors for each attribute.  The getattr() implementation is
similar to PyObject_GenericGetAttr(), but delegates to im_self instead
of looking in __dict__; I couldn't do this as a wrapper around
PyObject_GenericGetAttr().

XXX A problem here is that this is a case of *delegation*.  dir()
doesn't see exactly the same attributes that are actually defined;
e.g. if the delegate is a Python function object, it supports
attributes like func_code etc., but these are not visible to dir(); on
the other hand, dynamic function attributes (stored in the function's
__dict__) *are* visible to dir().  Maybe we need a mechanism to tell
dir() about the delegation mechanism?  I vaguely recall seeing a
request in the newsgroup for a more formal definition of attribute
delegation too.  Sigh, time for a new PEP.
2001-09-18 03:53:24 +00:00
Tim Peters 26f68f5957 type_new(): Didn't compile anymore, due to change in struct memberlist
definition.  Guido, what else did you forget to check in <wink>?
2001-09-18 00:23:33 +00:00
Guido van Rossum d9d1d4ac6f Rewrite function attributes to use the generic routines properly.
This uses the new "restricted" feature of structmember, and getset
descriptors for some of the type checks.
2001-09-17 23:46:56 +00:00
Tim Peters 305b5857f6 PyObject_Dir(): Merge in __members__ and __methods__ too (if they exist,
and are lists, and then just the string elements (if any)).

There are good and bad reasons for this.  The good reason is to support
dir() "like before" on objects of extension types that haven't migrated
to the class introspection API yet.  The bad reason is that Python's own
method objects are such a type, and this is the quickest way to get their
im_self etc attrs to "show up" via dir().  It looks much messier to move
them to the new scheme, as their current getattr implementation presents
a view of their attrs that's a untion of their own attrs plus their
im_func's attrs.  In particular, methodobject.__dict__ actually returns
methodobject.im_func.__dict__, and if that's important to preserve it
doesn't seem to fit the class introspection model at all.
2001-09-17 02:38:46 +00:00
Tim Peters bc7e863ce2 merge_class_dict(): Clear the error if __bases__ doesn't exist. 2001-09-16 20:33:22 +00:00
Guido van Rossum 7e35d57c0c A fix for SF bug #461546 (bug in long_mul).
Both int and long multiplication are changed to be more careful in
their assumptions about when one of the arguments is a sequence: the
assumption that at least one of the arguments must be an int (or long,
respectively) is still held, but the assumption that these don't smell
like sequences is no longer true: a subtype of int or long may well
have a sequence-repeat thingie!
2001-09-15 03:14:32 +00:00
Guido van Rossum a8c60f478c tp_new_wrapper(): A subtle change in the check for safe use.
Allow staticbase != type, as long as their tp_new slots are the same.
2001-09-14 19:43:36 +00:00
Guido van Rossum f21c6be7bd Add call_maybe(): a variant of call_method() that returns
NotImplemented when the lookup fails, and use this for binary
operators.  Also lookup_maybe() which doesn't raise an exception when
the lookup fails (still returning NULL).
2001-09-14 17:51:50 +00:00
Guido van Rossum 717ce00c7c call_method():
- Don't turn a non-tuple argument into a one-tuple.  Rather, the
  caller must pass a format that causes Py_VaBuildValue() to return a
  tuple.

- Speed things up by calling PyObject_Call (which is fairly low-level
  and straightforward) rather than PyObject_CallObject (which calls
  PyEval_CallObjectWithKeywords which calls PyObject_Call, and nothing
  is really done in the mean time except some tests for NULL args and
  valid types, which are already guaranteed).

- Cosmetics.

Other places:

- Make sure that the format argument to call_method() is surrounded by
  parentheses, so it will cause a tuple to be created.

- Replace a few calls to PyEval_CallObject() with a surefire tuple for
  args to calls to PyObject_Call().  (A few calls to
  PyEval_CallObject() remain that have NULL for args.)
2001-09-14 16:58:08 +00:00
Guido van Rossum 5560b7492c PyObject_CallObject(): this may as well call PyEval_CallObject()
directly, as the only thing done here (replace NULL args with an empty
tuple) is also done there.

XXX Maybe we should take one step further and equate the two at the
macro level?  That's harder though because PyEval_Call* is declared in
a header that's not included standard.  But it is silly that
PyObject_CallObject calls PyEval_CallObject which calls back to
PyObject_Call.  Maybe PyEval_CallObject should be moved into this file
instead?  All I know is that there are too many call APIs!  The
differences between PyObject_Call and PyEval_CallObjectWithKeywords is
that the latter allows args to be NULL, and does explicit type checks
for args and kwds.
2001-09-14 16:47:50 +00:00
Guido van Rossum 5f5512d246 _PyObject_Dump(): print the type of the object. This is by far the
most frequently interesting information IMO.  Also tidy up the output.
2001-09-14 15:50:08 +00:00
Tim Peters 4441001b56 The end of [#460467] file objects should be subclassable.
A surprising number of changes to split tp_new into tp_new and tp_init.
Turned out the older PyFile_FromFile() didn't initialize the memory it
allocated in all (error) cases, which caused new sanity asserts
elsewhere to fail left & right (and could have, e.g., caused file_dealloc
to try decrefing random addresses).
2001-09-14 03:26:08 +00:00
Tim Peters 0ab085c4cb Changed the dict implementation to take "string shortcuts" only when
keys are true strings -- no subclasses need apply.  This may be debatable.

The problem is that a str subclass may very well want to override __eq__
and/or __hash__ (see the new example of case-insensitive strings in
test_descr), but go-fast shortcuts for strings are ubiquitous in our dicts
(and subclass overrides aren't even looked for then).  Another go-fast
reason for the change is that PyCheck_StringExact() is a quicker test
than PyCheck_String(), and we make such a test on virtually every access
to every dict.

OTOH, a str subclass may also be perfectly happy using the base str eq
and hash, and this change slows them a lot.  But those cases are still
hypothetical, while Python's own reliance on true-string dicts is not.
2001-09-14 00:25:33 +00:00
Tim Peters 742dfd6f17 Get rid of builtin_open() entirely (the C code and docstring, not the
builtin function); Guido pointed out that it could be just another
name in the __builtin__ dict for the file constructor now.
2001-09-13 21:49:44 +00:00
Tim Peters 8fa45677c1 Now that file objects are subclassable, you can get at the file constructor
just by doing type(f) where f is any file object.  This left a hole in
restricted execution mode that rexec.py can't plug by itself (although it
can plug part of it; the rest is plugged in fileobject.c now).
2001-09-13 21:01:29 +00:00
Tim Peters 3f996e7266 type_call(): Change in policy. The keyword args (if any) are now passed
on to the tp_new slot (if non-NULL), as well as to the tp_init slot (if
any).  A sane type implementing both tp_new and tp_init should probably
pay attention to the arguments in only one of them.
2001-09-13 19:18:27 +00:00
Skip Montanaro bafedecc06 based upon a suggestion in c.l.py, this slight expansion of the
OverflowError message seems reasonable.
2001-09-13 19:05:30 +00:00
Tim Peters 59c9a645e2 SF bug [#460467] file objects should be subclassable.
Preliminary support.  What's here works, but needs fine-tuning.
2001-09-13 05:38:56 +00:00
Tim Peters 2400fa4ad1 Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.
Inhibited complex unary plus optimization when applied to a complex subtype.
Added PyComplex_CheckExact macro.  Some comments and minor code fiddling.
2001-09-12 19:12:49 +00:00
Tim Peters 111f60964e If interning an instance of a string subclass, intern a real string object
with the same value instead.  This ensures that a string (or string
subclass) object's ob_sinterned pointer is always a str (or NULL), and
that the dict of interned strings only has strs as keys.
2001-09-12 07:54:51 +00:00
Tim Peters af90b3e610 str_subtype_new, unicode_subtype_new:
+ These were leaving the hash fields at 0, which all string and unicode
  routines believe is a legitimate hash code.  As a result, hash() applied
  to str and unicode subclass instances always returned 0, which in turn
  confused dict operations, etc.
+ Changed local names "new"; no point to antagonizing C++ compilers.
2001-09-12 05:18:58 +00:00
Tim Peters 7a29bd5861 More on bug 460020: disable many optimizations of unicode subclasses. 2001-09-12 03:03:31 +00:00
Tim Peters 8fa5dd0601 More bug 460020: lots of string optimizations inhibited for string
subclasses, all "the usual" ones (slicing etc), plus replace, translate,
ljust, rjust, center and strip.  I don't know how to be sure they've all
been caught.

Question:  Should we complain if someone tries to intern an instance of
a string subclass?  I hate to slow any code on those paths.
2001-09-12 02:18:30 +00:00
Tim Peters 40c397dd56 long_invert(): tiny speed and space optimization. 2001-09-11 23:24:22 +00:00
Tim Peters 69c2de3ad6 More bug 460020. Disable a number of long optimizations for long subclasses. 2001-09-11 22:31:33 +00:00
Tim Peters 0280cf79a7 More bug 460020: when F is a subclass of float, disable the unary plus
optimization (+F(whatever)).
2001-09-11 21:53:35 +00:00
Tim Peters 73a1dfe367 More bug 460020. When I is a subclass of int, disable the +I(whatever),
I(0) << whatever, I(0) >> whatever, I(whatever) << 0 and I(whatever) >> 0
optimizations.
2001-09-11 21:44:14 +00:00
Tim Peters 7b07a41e9f The endless 460020 bug.
Disable t[:], t*0, t*1 optimizations when t is of a tuple subclass type.
2001-09-11 19:48:03 +00:00
Guido van Rossum dea6ef9bfd Replace a few places where X->ob_type was compared to &PyXXX_Type with
calls to PyXXX_CheckExact(X).
2001-09-11 16:13:52 +00:00
Tim Peters 78e0fc74bc Possibly the end of SF [#460020] bug or feature: unicode() and subclasses.
Changed unicode(i) to return a true Unicode object when i is an instance of
a unicode subclass.  Added PyUnicode_CheckExact macro.
2001-09-11 03:07:38 +00:00
Tim Peters 0ebeb584a4 PyUnicode_FromEncodedObject(): Repair memory leak in an error case. 2001-09-11 02:00:50 +00:00
Tim Peters 5a49ade70e More on SF bug [#460020] bug or feature: unicode() and subclasses.
Repaired str(i) to return a genuine string when i is an instance of a str
subclass.  New PyString_CheckExact() macro.
2001-09-11 01:41:59 +00:00
Tim Peters 8ff70a9606 Fix tortured comment -- I must be on drugs today. 2001-09-10 23:53:53 +00:00
Tim Peters 4c3a0a35cd More on SF bug [#460020] bug or feature: unicode() and subclasses.
tuple(i) repaired to return a true tuple when i is an instance of a
tuple subclass.
Added PyTuple_CheckExact macro.
PySequence_Tuple():  if a tuple-like object isn't exactly a tuple, it's
not safe to return the object as-is -- make a new tuple of it instead.
2001-09-10 23:37:46 +00:00
Tim Peters 7a50f2536e More for SF bug [#460020] bug or feature: unicode() and subclasses
Repair float constructor to return a true float when passed a subclass
instance.  New PyFloat_CheckExact macro.
2001-09-10 21:28:20 +00:00
Tim Peters 64b5ce3a69 SF bug #460020: bug or feature: unicode() and subclasses.
Given an immutable type M, and an instance I of a subclass of M, the
constructor call M(I) was just returning I as-is; but it should return a
new instance of M.  This fixes it for M in {int, long}.  Strings, floats
and tuples remain to be done.
Added new macros PyInt_CheckExact and PyLong_CheckExact, to more easily
distinguish between "is" and "is a" (i.e., only an int passes
PyInt_CheckExact, while any sublass of int passes PyInt_Check).
Added private API function _PyLong_Copy.
2001-09-10 20:52:51 +00:00
Guido van Rossum 8b4e43e768 _portable_fseek():
Subtlety on Windows: if we change test_largefile.py to use a file
> 4GB, it still fails.  A debug session suggests this is because
fseek(fp, 0, 2) refuses to seek to the end of the file when the file
is > 4GB, because it uses the SetFilePointer() in 32-bit mode.

But it only fails when we seek relative to the end of the file,
because in the other seek modes only calls to fgetpos() and fsetpos()
are made, which use Get/SetFilePointer() in 64-bit mode.  Solution:
#ifdef MS_WInDOWS, replace the call to fseek(fp, ...) with a call to
_lseeki64(fileno(fp), ...).  Make sure to call fflush(fp) first.

(XXX Could also replace the entire branch with a call to _lseeki64().
Would that be more efficient?  Certainly less generated code.)

(XXX This needs more testing.  I can't actually test that it works for
files >4GB on my Win98 machine, because the filesystem here won't let
me create files >=4GB at all.  Tim should test this on his Win2K
machine.)
2001-09-10 20:43:35 +00:00
Guido van Rossum 8dbd3d8c50 PyObject_Dir():
- use PyModule_Check() instead of PyObject_TypeCheck(), now we can.
  - don't assert that the __dict__ gotten out of a module is always
    a dictionary; check its type, and raise an exception if it's not.
2001-09-10 18:27:43 +00:00
Tim Peters 16a77adfbd Generalize operator.indexOf (PySequence_Index) to work with any
iterable object.  I'm not sure how that got overlooked before!

Got rid of the internal _PySequence_IterContains, introduced a new
internal _PySequence_IterSearch, and rewrote all the iteration-based
"count of", "index of", and "is the object in it or not?" routines to
just call the new function.  I suppose it's slower this way, but the
code duplication was getting depressing.
2001-09-08 04:00:12 +00:00
Guido van Rossum 28d80b1058 PyClass_New(): put the extended Don Beaudry hook back in. When one of
the base classes is not a classic class, and its class (the metaclass)
is callable, call the metaclass to do the deed.

One effect of this is that, when mixing classic and new-style classes
amongst the bases of a class, it doesn't matter whether the first base
class is a classic class or not: you will always get the error
"TypeError: metatype conflict among bases".  (Formerly, with a classic
class first, you'd get "TypeError: PyClass_New: base must be a class".)

Another effect is that multiple inheritance from ExtensionClass.Base,
with a classic class as the first class, transfers control to the
ExtensionClass.Base class.  This is what we need for SF #443239 (and
also for running Zope under 2.2a4, before ExtensionClass is replaced).
2001-09-07 21:08:32 +00:00
Guido van Rossum 8700b4281a PySequence_Check(), PyMapping_Check(): only return true if the
corresponding "getitem" operation (sq_item or mp_subscript) is
implemented.  I realize that "sequence-ness" and "mapping-ness" are
poorly defined (and the tests may still be wrong for user-defined
instances, which always have both slots filled), but I believe that a
sequence that doesn't support its getitem operation should not be
considered a sequence.  All other operations are optional though.

For example, the ZODB BTree tests crashed because PySequence_Check()
returned true for a dictionary!  (In 2.2, the dictionary type has a
tp_as_sequence pointer, but the only field filled is sq_contains, so
you can write "if key in dict".)  With this fix, all standalone ZODB
tests succeed.
2001-09-07 20:20:11 +00:00
Guido van Rossum 9478d07ee7 PyType_IsSubtype(): test tp_flags for HAVE_CLASS bit before accessing
a->tp_mro.  If a doesn't have class, it's considered a subclass only
of itself or of 'object'.

This one fix is enough to prevent the ExtensionClass test suite from
dumping core, but that doesn't say much (it's a rather small test
suite).  Also note that for ExtensionClass-defined types, a different
subclass test may be needed.  But I haven't checked whether
PyType_IsSubtype() is actually used in situations where this matters
-- probably it doesn't, since we also don't check for classic classes.
2001-09-07 18:52:13 +00:00
Tim Peters e56ed9ba15 long_true_divide: reliably force underflow to 0 when the denominator
has more bits than the numerator than can be counted in a C int (yes,
that's unlikely, and no, I'm not adding a test case with a 2 gigabit
long).
2001-09-06 21:59:14 +00:00
Guido van Rossum 8bce4acb17 Rename 'getset' to 'property'. 2001-09-06 21:56:42 +00:00
Martin v. Löwis 387c547fd3 Revert parts of patch #453627, documenting the resulting test failures
instead.
2001-09-06 08:16:17 +00:00
Tim Peters 6e13a562ae Enable large file support on Win32 systems.
Curious:  the MS docs say stati64 etc are supported even on Win95, but
Win95 doesn't support a filesystem that allows partitions > 2 Gb.

test_largefile:  This was opening its test file in text mode.  I have no
idea how that worked under Win64, but it sure needs binary mode on Win98.
BTW, on Win98 test_largefile runs quickly (under a second).
2001-09-06 00:32:15 +00:00
Tim Peters 97f4a33e12 Better error msg for 3-arg pow with a float argument. 2001-09-05 23:49:24 +00:00
Guido van Rossum b479dc561c Add PyMethod_Function(), PyMethod_Self(), PyMethod_Class() back.
While not even documented, they were clearly part of the C API,
there's no great difficulty to support them, and it has the cool
effect of not requiring any changes to ExtensionClass.c.
2001-09-05 22:52:50 +00:00
Tim Peters a40c793d06 Rework the way we try to check for libm overflow, given that C99 no longer
requires that errno ever get set, and it looks like glibc is already
playing that game.  New rules:

+ Never use HUGE_VAL.  Use the new Py_HUGE_VAL instead.

+ Never believe errno.  If overflow is the only thing you're interested in,
  use the new Py_OVERFLOWED(x) macro.  If you're interested in any libm
  errors, use the new Py_SET_ERANGE_IF_OVERFLOW(x) macro, which attempts
  to set errno the way C89 said it worked.

Unfortunately, none of these are reliable, but they work on Windows and I
*expect* under glibc too.
2001-09-05 22:36:56 +00:00
Guido van Rossum b855216099 Changes to automatically enable large file support on some systems.
I believe this works on Linux (tested both on a system with large file
support and one without it), and it may work on Solaris 2.7.

The changes are twofold:

(1) The configure script now boldly tries to set the two symbols that
    are recommended (for Solaris and Linux), and then tries a test
    script that does some simple seeking without writing.

(2) The _portable_{fseek,ftell} functions are a little more systematic
    in how they try the different large file support options: first
    try fseeko/ftello, but only if off_t is large; then try
    fseek64/ftell64; then try hacking with fgetpos/fsetpos.

I'm keeping my fingers crossed.  The meaning of the
HAVE_LARGEFILE_SUPPORT macro is not at all clear.

I'll see if I can get it to work on Windows as well.
2001-09-05 14:58:11 +00:00
Martin v. Löwis 655c9557f6 Patch #453627: Define the following macros when compiling on a UnixWare 7.x system:
SCO_ATAN2_BUG, SCO_ACCEPT_BUG, and STRICT_SYSV_CURSES.
Work aroudn a bug in the SCO UnixWare atan2() implementation.
2001-09-05 14:45:54 +00:00
Tim Peters 4c483c4d8e Make the error msgs in our pow() implementations consistent. 2001-09-05 06:24:58 +00:00
Tim Peters 57f282a2a0 Try to recover from that glibc's ldexp apparently doesn't set errno on
overflow.  Needs testing on Linux (test_long.py and test_long_future.py
especially).
2001-09-05 05:38:10 +00:00
Tim Peters 7eea37e831 At Guido's suggestion, here's a new C API function, PyObject_Dir(), like
__builtin__.dir().  Moved the guts from bltinmodule.c to object.c.
2001-09-04 22:08:56 +00:00
Tim Peters e2a600099d Change long/long true division to return as many good bits as it can;
e.g., (1L << 40000)/(1L << 40001) returns 0.5, not Inf or NaN or whatever.
2001-09-04 06:17:36 +00:00
Tim Peters 9c1d7fd5f2 Move int_true_divide next to the other division routines. 2001-09-04 05:52:47 +00:00
Tim Peters 20dab9f168 Move long_true_divide next to the other division routines (for clarity!). 2001-09-04 05:31:47 +00:00
Tim Peters 9fffa3eea3 Raise OverflowError when appropriate on long->float conversion. Most of
the fiddling is simply due to that no caller of PyLong_AsDouble ever
checked for failure (so that's fixing old bugs).  PyLong_AsDouble is much
faster for big inputs now too, but that's more of a happy consequence
than a design goal.
2001-09-04 05:14:19 +00:00
Guido van Rossum 1832de4bc0 PEP 238 documented -Qwarn as warning only for classic int or long
division, and this makes sense.  Add -Qwarnall to warn for all
classic divisions, as required by the fixdiv.py tool.
2001-09-04 03:51:09 +00:00
Tim Peters a1c1b0f468 Introduce new private API function _PyLong_AsScaledDouble. Not used yet,
but will be the foundation for Good Things:
+ Speed PyLong_AsDouble.
+ Give PyLong_AsDouble the ability to detect overflow.
+ Make true division of long/long nearly as accurate as possible (no
  spurious infinities or NaNs).
+ Return non-insane results from math.log and math.log10 when passing a
  long that can't be approximated by a double better than HUGE_VAL.
2001-09-04 02:50:49 +00:00
Tim Peters 32f453eaa4 New restriction on pow(x, y, z): If z is not None, x and y must be of
integer types, and y must be >= 0.  See discussion at
http://sf.net/tracker/index.php?func=detail&aid=457066&group_id=5470&atid=105470
2001-09-03 08:35:41 +00:00
Tim Peters b95ec09a44 Repair typo in comment. 2001-09-02 18:35:54 +00:00
Tim Peters 25786c0851 Make dictionary() a real constructor. Accepts at most one argument, "a
mapping object", in the same sense dict.update(x) requires of x (that x
has a keys() method and a getitem).
Questionable:  The other type constructors accept a keyword argument, so I
did that here too (e.g., dictionary(mapping={1:2}) works).  But type_call
doesn't pass the keyword args to the tp_new slot (it passes NULL), it only
passes them to the tp_init slot, so getting at them required adding a
tp_init slot to dicts.  Looks like that makes the normal case (i.e., no
args at all) a little slower (the time it takes to call dict.tp_init and
have it figure out there's nothing to do).
2001-09-02 08:22:48 +00:00
Tim Peters 1b8ca0d87a Rewrite the tuple() docstring to parallel the list() docstring. 2001-09-02 06:42:25 +00:00
Tim Peters 9577761337 Repair apparent cut'n'pasteo in tuple() docstring. 2001-09-02 06:29:48 +00:00
Guido van Rossum 393661d15f Add warning mode for classic division, almost exactly as specified in
PEP 238.  Changes:

- add a new flag variable Py_DivisionWarningFlag, declared in
  pydebug.h, defined in object.c, set in main.c, and used in
  {int,long,float,complex}object.c.  When this flag is set, the
  classic division operator issues a DeprecationWarning message.

- add a new API PyRun_SimpleStringFlags() to match
  PyRun_SimpleString().  The main() function calls this so that
  commands run with -c can also benefit from -Dnew.

- While I was at it, I changed the usage message in main() somewhat:
  alphabetized the options, split it in *four* parts to fit in under
  512 bytes (not that I still believe this is necessary -- doc strings
  elsewhere are much longer), and perhaps most visibly, don't display
  the full list of options on each command line error.  Instead, the
  full list is only displayed when -h is used, and otherwise a brief
  reminder of -h is displayed.  When -h is used, write to stdout so
  that you can do `python -h | more'.

Notes:

- I don't want to use the -W option to control whether the classic
  division warning is issued or not, because the machinery to decide
  whether to display the warning or not is very expensive (it involves
  calling into the warnings.py module).  You can use -Werror to turn
  the warnings into exceptions though.

- The -Dnew option doesn't select future division for all of the
  program -- only for the __main__ module.  I don't know if I'll ever
  change this -- it would require changes to the .pyc file magic
  number to do it right, and a more global notion of compiler flags.

- You can usefully combine -Dwarn and -Dnew: this gives the __main__
  module new division, and warns about classic division everywhere
  else.
2001-08-31 17:40:15 +00:00
Guido van Rossum 29d55a38ce Fix a memory leak in str_subtype_new(). (All the other
xxx_subtype_new() functions are OK, but I goofed up in this one. :-( )
2001-08-31 16:11:15 +00:00
Guido van Rossum 41eb14dffa Give 'super' a decent repr(), and readonly attributes to access the
type and obj properties.  The "bogus super object" message is gone --
this will now just raise an AttributeError.
2001-08-30 23:13:11 +00:00
Guido van Rossum 21922aa939 PyObject_Repr(): add missing ">" back at end of format string: "<%s
object at %p>".
2001-08-30 20:26:05 +00:00
Tim Peters 017cb2c7d8 Squash new compiler wng. 2001-08-30 20:07:55 +00:00
Guido van Rossum 6fb3fdec7c Pytype_GenericAlloc(): round up size so we zap all four bytes of the
__dict__ slot for string subtypes.

subtype_dealloc(): properly use _PyObject_GetDictPtr() to get the
(potentially negative) dict offset.  Don't copy things into local
variables that are used only once.

type_new(): properly calculate a negative dict offset when tp_itemsize
is nonzero.  The __dict__ attribute, if present, is now a calculated
attribute rather than a structure member.
2001-08-30 20:00:07 +00:00
Guido van Rossum 4b8c0f6d7d More stuff discovered while writing the simplest of testcases:
tupledealloc(): only feed the free list when the type is really a
tuple, not a subtype.  Otherwise, use PyObject_GC_Del().

_PyTuple_Resize(): disallow using this for tuple subtypes.
2001-08-30 18:31:30 +00:00
Guido van Rossum 13228a6f09 Ah, the joy of writing test cases...
long_subtype_new(): fix a typo (type->ob_size instead of
tmp->ob_size).
2001-08-30 15:54:44 +00:00
Sjoerd Mullender 38b88c233a Removed some unreachable break statements to silence SGI compiler. 2001-08-30 13:58:58 +00:00
Tim Peters 52e0717215 Give the internal immutable list type .extend and .pop methods (they
"should have" been added here when they were added to lists).
2001-08-30 06:15:32 +00:00
Guido van Rossum c41418751f Safety measures now that str and tuple are subclassable:
If tp_itemsize of the basetype is nonzero, only allow empty __slots__
(declaring that no __dict__ should be added), and don't add a weakref
offset.
2001-08-30 04:43:35 +00:00
Guido van Rossum 31bcff8815 Make 'super' subclassable. (Not sure how useful this is yet. :-) 2001-08-30 04:37:15 +00:00
Guido van Rossum e023fe0eef Make unicode subclassable. 2001-08-30 03:12:59 +00:00
Guido van Rossum ae960afb5e Make str and tuple types subclassable. 2001-08-30 03:11:59 +00:00
Guido van Rossum 147b13c069 Make getset subclassable. 2001-08-30 03:10:36 +00:00
Guido van Rossum d93dce1699 Fix typo: double semicolons. 2001-08-30 03:09:31 +00:00
Tim Peters deb77e8394 Squash new compiler wng in debug build. 2001-08-30 00:32:51 +00:00
Neil Schemenauer c806c8858d Use new GC API. Remove usage of BASICSIZE macros. 2001-08-29 23:54:54 +00:00
Neil Schemenauer e83c00efd0 Use new GC API. 2001-08-29 23:54:21 +00:00
Neil Schemenauer fd34369ecb Remove GC related code. It lives in gcmodule now. 2001-08-29 23:54:03 +00:00
Neil Schemenauer 4f4817fee8 Make frames a PyVarObject. Use new GC API. 2001-08-29 23:52:17 +00:00
Guido van Rossum bef1417f9f Make int, long and float subclassable.
This uses a slightly wimpy and wasteful approach, but it works. :-)
2001-08-29 15:47:46 +00:00
Guido van Rossum e705ef1bce Fix super() so that it is usable for static methods (like __new__) as well.
In particular, the second argument can now be a subclass of the first
as well (normally it must be an instance though).
2001-08-29 15:47:06 +00:00
Guido van Rossum 5592e4d7d5 Fix a typo in SLOT0 macro for the declaration of cache_str.
Dunno why I didn't catch this before.
2001-08-28 18:28:21 +00:00
Guido van Rossum 2730b13202 Finish the previous checkin: also avoid getattr when calling the method
directly.
2001-08-28 18:22:14 +00:00
Guido van Rossum 607187325f Change in policy: when a slot_tp_xxx function looks for the __xxx__ method,
don't use getattr, but only look in the dict of the type and base types.
This prevents picking up all sorts of weird stuff, including things defined
by the metaclass when the object is a class (type).

For this purpose, a helper function lookup_method() was added.  One or two
other places also use this.
2001-08-28 17:47:51 +00:00