Commit Graph

241 Commits

Author SHA1 Message Date
Thomas Wouters 49fd7fa443 Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
number of tests, all because of the codecs/_multibytecodecs issue described
here (it's not a Py3K issue, just something Py3K discovers):
http://mail.python.org/pipermail/python-dev/2006-April/064051.html

Hye-Shik Chang promised to look for a fix, so no need to fix it here. The
tests that are expected to break are:

test_codecencodings_cn
test_codecencodings_hk
test_codecencodings_jp
test_codecencodings_kr
test_codecencodings_tw
test_codecs
test_multibytecodec

This merge fixes an actual test failure (test_weakref) in this branch,
though, so I believe merging is the right thing to do anyway.
2006-04-21 10:40:58 +00:00
Neal Norwitz bcc0db82dc Get rid of remnants of integer division 2006-03-24 08:14:36 +00:00
Guido van Rossum 38fff8c4e4 Checking in the code for PEP 357.
This was mostly written by Travis Oliphant.
I've inspected it all; Neal Norwitz and MvL have also looked at it
(in an earlier incarnation).
2006-03-07 18:50:55 +00:00
Martin v. Löwis 15e62742fa Revert backwards-incompatible const changes. 2006-02-27 16:46:16 +00:00
Martin v. Löwis dde99d2633 Remove size constraints in SLICE opcodes. 2006-02-17 15:57:41 +00:00
Martin v. Löwis 18e165558b Merge ssize_t branch. 2006-02-15 17:27:45 +00:00
Jeremy Hylton af68c874a6 Add const to several API functions that take char *.
In C++, it's an error to pass a string literal to a char* function
without a const_cast().  Rather than require every C++ extension
module to put a cast around string literals, fix the API to state the
const-ness.

I focused on parts of the API where people usually pass literals:
PyArg_ParseTuple() and friends, Py_BuildValue(), PyMethodDef, the type
slots, etc.  Predictably, there were a large set of functions that
needed to be fixed as a result of these changes.  The most pervasive
change was to make the keyword args list passed to
PyArg_ParseTupleAndKewords() to be a const char *kwlist[].

One cast was required as a result of the changes:  A type object
mallocs the memory for its tp_doc slot and later frees it.
PyTypeObject says that tp_doc is const char *; but if the type was
created by type_new(), we know it is safe to cast to char *.
2005-12-10 18:50:16 +00:00
Guido van Rossum 630db60a55 - On 64-bit platforms, when __len__() returns a value that cannot be
represented as a C int, raise OverflowError.

(Forward port from 2.4.2; the patch to classobject.c was already in
but needed a correction in the error message text.)
2005-09-20 18:49:54 +00:00
Guido van Rossum ba3e6ec0c9 A minor fix for 64-bit platforms: when __len__() returns Python int
containing a value that doesn't fit in a C int, raise OverflowError
rather than truncating silently (and having 50% chance of hitting the
"it should be >= 0" error).
2005-09-19 22:42:41 +00:00
Raymond Hettinger bff60aeb93 Insert missing flag. 2005-06-19 08:42:20 +00:00
Michael W. Hudson e2749cb264 Fix for rather inaccurately titled bug
[ 1165306 ] Property access with decorator makes interpreter crash

Don't allow the creation of unbound methods with NULL im_class, because
attempting to call such crashes.

Backport candidate.
2005-03-30 16:32:10 +00:00
Tim Peters f4aca755bc A static swapped_op[] array was defined in 3 different C files, & I think
I need to define it again.  Bite the bullet and define it once as an
extern, _Py_SwappedOp[].
2004-09-23 02:39:37 +00:00
Michael W. Hudson 3f3b66823f Repair the same thinko in two places about handling of _Py_RefTotal in
the case of __del__ resurrecting an object.
This makes the apparent reference leaks in test_descr go away (which I
expected) and also kills off those in test_gc (which is more surprising
but less so once you actually think about it a bit).
2004-08-03 10:21:03 +00:00
Guido van Rossum baf0f8f24d - When method objects have an attribute that can be satisfied either
by the function object or by the method object, the function
  object's attribute usually wins.  Christian Tismer pointed out that
  that this is really a mistake, because this only happens for special
  methods (like __reduce__) where the method object's version is
  really more appropriate than the function's attribute.  So from now
  on, all method attributes will have precedence over function
  attributes with the same name.
2003-11-22 23:55:50 +00:00
Armin Rigo 2b3eb4062c Deleting cyclic object comparison.
SF patch 825639
http://mail.python.org/pipermail/python-dev/2003-October/039445.html
2003-10-28 12:05:48 +00:00
Raymond Hettinger 8ae4689657 Simplify and speedup uses of Py_BuildValue():
* Py_BuildValue("(OOO)",a,b,c)  -->  PyTuple_Pack(3,a,b,c)
* Py_BuildValue("()",a)         -->  PyTuple_New(0)
* Py_BuildValue("O", a)         -->  Py_INCREF(a)
2003-10-12 19:09:37 +00:00
Raymond Hettinger a9e14b7015 Fix leak in classobject.c. The leak surfaced on the error exit when
hashing a class that does not define __hash__ but does define a
comparison.
2003-09-16 07:11:46 +00:00
Guido van Rossum 2fb9fdc96a Make it possible to call instancemethod() with 2 arguments. 2003-04-09 19:35:08 +00:00
Tim Peters df875b99fc New private API function _PyInstance_Lookup. gc will use this to figure
out whether __del__ exists, without executing any Python-level code.
2003-04-07 17:51:59 +00:00
Guido van Rossum 6bae46d8c1 Refactor instancemethod_descr_get() to (a) be more clear, (b) be safe
in the light of weird args, and (c) not to expect None (which is now
changed to NULL by slot_tp_descr_get()).
2003-02-11 18:43:00 +00:00
Raymond Hettinger ea3fdf44a2 SF patch #659536: Use PyArg_UnpackTuple where possible.
Obtain cleaner coding and a system wide
performance boost by using the fast, pre-parsed
PyArg_Unpack function instead of PyArg_ParseTuple
function which is driven by a format string.
2002-12-29 16:33:45 +00:00
Walter Dörwald 7e5c6a02eb Change issubclass() so that recursive tuples (directly or indirectly
containing class objects) are allowed as the second argument.
This makes issubclass() more similar to isinstance() where recursive
tuples are allowed too.
2002-12-12 19:14:08 +00:00
Walter Dörwald d9a6ad3beb Enhance issubclass() and PyObject_IsSubclass() so that a tuple is
supported as the second argument. This has the same meaning as
for isinstance(), i.e. issubclass(X, (A, B)) is equivalent
to issubclass(X, A) or issubclass(X, B). Compared to isinstance(),
this patch does not search the tuple recursively for classes, i.e.
any entry in the tuple that is not a class, will result in a
TypeError.

This closes SF patch #649608.
2002-12-12 16:41:44 +00:00
Guido van Rossum f740bdf337 Since properties are supported here, is possible that
instance_getattr2() raises an exception.  Fix all code that made this
assumption.

Backport candidate.
2002-10-29 18:36:40 +00:00
Guido van Rossum 617080b6cf Fix (real! :-) memory leaks in half_cmp and half_binop.
Perhaps found by NealN and valgrind.  Will forward port.
2002-10-18 14:15:33 +00:00
Tim Peters 75585d4ec1 getinstclassname(): Squash new compiler wng in assert (comparison of
signed vs unsigned).
2002-08-20 14:31:35 +00:00
Guido van Rossum 45ec02aed1 SF patch 576101, by Oren Tirosh: alternative implementation of
interning.  I modified Oren's patch significantly, but the basic idea
and most of the implementation is unchanged.  Interned strings created
with PyString_InternInPlace() are now mortal, and you must keep a
reference to the resulting string around; use the new function
PyString_InternImmortal() to create immortal interned strings.
2002-08-19 21:43:18 +00:00
Tim Peters 3459251d5a object.h special-build macro minefield: renamed all the new lexical
helper macros to something saner, and used them appropriately in other
files too, to reduce #ifdef blocks.

classobject.c, instance_dealloc():  One of my worst Python Memories is
trying to fix this routine a few years ago when COUNT_ALLOCS was defined
but Py_TRACE_REFS wasn't.  The special-build code here is way too
complicated.  Now it's much simpler.  Difference:  in a Py_TRACE_REFS
build, the instance is no longer in the doubly-linked list of live
objects while its __del__ method is executing, and that may be visible
via sys.getobjects() called from a __del__ method.  Tough -- the object
is presumed dead while its __del__ is executing anyway, and not calling
_Py_NewReference() at the start allows enormous code simplification.

typeobject.c, call_finalizer():  The special-build instance_dealloc()
pain apparently spread to here too via cut-'n-paste, and this is much
simpler now too.  In addition, I didn't understand why this routine
was calling _PyObject_GC_TRACK() after a resurrection, since there's no
plausible way _PyObject_GC_UNTRACK() could have been called on the
object by this point.  I suspect it was left over from pasting the
instance_delloc() code.  Instead asserted that the object is still
tracked.  Caution:  I suspect we don't have a test that actually
exercises the subtype_dealloc() __del__-resurrected-me code.
2002-07-11 06:23:50 +00:00
Tim Peters 943382c8e5 Removed WITH_CYCLE_GC #ifdef-ery. Holes:
+ I'm not sure what to do about configure.in.  Left it alone.

+ Ditto pyexpat.c.  Fred or Martin will know what to do.
2002-07-07 03:59:34 +00:00
Michael W. Hudson b1e8154013 About the new but unreferenced new_class, Guido sez:
> Looks like an experiment by Oren Tirosh that didn't get nuked.  I
> think you can safely lose it.

It's gone.
2002-06-18 12:38:06 +00:00
Guido van Rossum bea18ccde6 SF patch 568629 by Oren Tirosh: types made callable.
These built-in functions are replaced by their (now callable) type:

    slice()
    buffer()

and these types can also be called (but have no built-in named
function named after them)

    classobj (type name used to be "class")
    code
    function
    instance
    instancemethod (type name used to be "instance method")

The module "new" has been replaced with a small backward compatibility
placeholder in Python.

A large portion of the patch simply removes the new module from
various platform-specific build recipes.  The following binary Mac
project files still have references to it:

    Mac/Build/PythonCore.mcp
    Mac/Build/PythonStandSmall.mcp
    Mac/Build/PythonStandalone.mcp

[I've tweaked the code layout and the doc strings here and there, and
added a comment to types.py about StringTypes vs. basestring.  --Guido]
2002-06-14 20:41:17 +00:00
Guido van Rossum e7b8ecf196 Major cleanup operation: whenever there's a call that looks for an
optional attribute, only clear the exception when the internal getattr
operation raised AttributeError.  Many places in this file already had
that policy; but just as many didn't, and there didn't seem to be any
rhyme or reason to it.  Be consistently cautious.

Question: should I backport this?  On the one hand it's a bugfix.  On
the other hand it's a change in behavior.  Certain forms of buggy or
just weird code would work in the past but raise an exception under
the new rules; e.g. if you define a __getattr__ method that raises a
non-AttributeError exception.
2002-06-13 21:42:04 +00:00
Guido van Rossum 16b93b3d0e Fix for SF bug 532646. This is a little simpler than what Neal
suggested there, based upon a better analysis (__getattr__ is a red
herring).  Will backport to 2.2.
2002-06-13 21:32:51 +00:00
Fred Drake c916f5a390 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.
2001-10-26 17:56:51 +00:00
Guido van Rossum 56ff387a7e Fix for SF bug #472940: can't getattr() attribute shown by dir()
There really isn't a good reason for instance method objects to have
their own __dict__, __doc__ and __name__ properties that just delegate
the request to the function (callable); the default attribute behavior
already does this.

The test suite had to be fixed because the error changes from
TypeError to AttributeError.
2001-10-22 02:00:09 +00:00
Guido van Rossum 915f0eb212 Protect references to tp_descr_get and tp_dict with the appropriate test:
PyType_HasFeature(t, Py_TPFLAGS_HAVE_CLASS).
2001-10-17 20:26:38 +00:00
Tim Peters 8b13b3ede2 SF bug [#466173] unpack TypeError unclear
Replaced 3 instances of "iter() of non-sequence" with
"iteration over non-sequence".
Restored "unpack non-sequence" for stuff like "a, b = 1".
2001-09-30 05:58:42 +00:00
Guido van Rossum 32d34c809f Add optional docstrings to getset descriptors. Fortunately, there's
no backwards compatibility to worry about, so I just pushed the
'closure' struct member to the back -- it's never used in the current
code base (I may eliminate it, but that's more work because the getter
and setter signatures would have to change.)

As examples, I added actual docstrings to the getset attributes of a
few types: file.closed, xxsubtype.spamdict.state.
2001-09-20 21:45:26 +00:00
Guido van Rossum 6f7993765a Add optional docstrings to member descriptors. For backwards
compatibility, this required all places where an array of "struct
memberlist" structures was declared that is referenced from a type's
tp_members slot to change the type of the structure to PyMemberDef;
"struct memberlist" is now only used by old code that still calls
PyMember_Get/Set.  The code in PyObject_GenericGetAttr/SetAttr now
calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef
argument.

As examples, I added actual docstrings to the attributes of a few
types: file, complex, instance method, super, and xxsubtype.spamlist.

Also converted the symtable to new style getattr.
2001-09-20 20:46:19 +00:00
Martin v. Löwis cf95f9cacb Properly repr classes without module names. 2001-09-18 20:23:28 +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 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 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
Neil Schemenauer e83c00efd0 Use new GC API. 2001-08-29 23:54:21 +00:00
Guido van Rossum a15dece519 Improve the error message issued when an unbound method is called with
an inappropriate first argument.  Now that there are more ways for
this to fail, make sure to report the name of the class of the
expected instance and of the actual instance.
2001-08-24 18:48:27 +00:00
Barry Warsaw 7ce3694a52 repr's converted to using PyString_FromFormat() instead of sprintf'ing
into a hardcoded char* buffer.

Closes patch #454743.
2001-08-24 18:34:26 +00:00
Guido van Rossum 4066769b91 Fix core dump in repr() of instancemethod whose class==NULL. 2001-08-17 13:59:27 +00:00
Guido van Rossum f23c41d56a instance_getattr2(): rewritten to remove unnecessary stuff and
streamlined a bit.

instancemethod_descr_get(): don't bind an unbound method of a class
that's not a base class of the argument class.
2001-08-17 13:43:27 +00:00
Guido van Rossum cdf0d75897 Instance methods: allow a NULL value for im_class. 2001-08-17 12:07:34 +00:00
Guido van Rossum 501c7c7d0e classobject.c:instancemethod_descr_get(): when a bound method is
assigned to a class variable and then accessed via an instance, it
should not be rebound.

test_descr.py:methods(): test for the condition above.
2001-08-16 20:41:56 +00:00
Guido van Rossum 23cc2b4991 PyMethod_Type: add a tp_descr_get slot function to ensure proper
binding of unbound methods.
2001-08-15 17:52:31 +00:00
Guido van Rossum 4668b000a1 Implement PEP 238 in its (almost) full glory.
This introduces:

- A new operator // that means floor division (the kind of division
  where 1/2 is 0).

- The "future division" statement ("from __future__ import division)
  which changes the meaning of the / operator to implement "true
  division" (where 1/2 is 0.5).

- New overloadable operators __truediv__ and __floordiv__.

- New slots in the PyNumberMethods struct for true and floor division,
  new abstract APIs for them, new opcodes, and so on.

I emphasize that without the future division statement, the semantics
of / will remain unchanged until Python 3.0.

Not yet implemented are warnings (default off) when / is used with int
or long arguments.

This has been on display since 7/31 as SF patch #443474.

Flames to /dev/null.
2001-08-08 05:00:18 +00:00
Tim Peters 5962cbf5ba Fix the test_weakref.py failure. Introduced by resolving "a conflict"
(which didn't actually exist!) incorrectly.
2001-08-02 04:45:20 +00:00
Tim Peters 6d6c1a35e0 Merge of descr-branch back into trunk. 2001-08-02 04:15:00 +00:00
Guido van Rossum 0ba9e3ac27 init_name_op(): add (void) to the argument list to make it a valid
prototype, for gcc -Wstrict-prototypes.
2001-05-22 02:33:08 +00:00
Jeremy Hylton 1b0feb4ada Variant of SF patch 423181
For rich comparisons, use instance_getattr2() when possible to avoid
the expense of setting an AttributeError.  Also intern the name_op[]
table and use the interned strings rather than creating a new string
and interning it each time through.
2001-05-11 14:48:41 +00:00
Tim Peters cb8d368b82 Reimplement PySequence_Contains() and instance_contains(), so they work
safely together and don't duplicate logic (the common logic was factored
out into new private API function _PySequence_IterContains()).
Visible change:
    some_complex_number  in  some_instance
no longer blows up if some_instance has __getitem__ but neither
__contains__ nor __iter__.  test_iter changed to ensure that remains true.
2001-05-05 21:05:01 +00:00
Fred Drake 4dcb85b817 Since Py_TPFLAGS_HAVE_WEAKREFS is set in Py_TPFLAGS_DEFAULT, it does not
need to be specified in the type structures independently.  The flag
exists only for binary compatibility.

This is a "source cleanliness" issue and introduces no behavioral changes.
2001-05-03 16:04:13 +00:00
Guido van Rossum 82c690f11a Well darnit! The innocuous fix I made to PyObject_Print() caused
printing of instances not to look for __str__().  Fix this.
2001-04-30 14:39:18 +00:00
Guido van Rossum 213c7a6aa5 Mondo changes to the iterator stuff, without changing how Python code
sees it (test_iter.py is unchanged).

- Added a tp_iternext slot, which calls the iterator's next() method;
  this is much faster for built-in iterators over built-in types
  such as lists and dicts, speeding up pybench's ForLoop with about
  25% compared to Python 2.1.  (Now there's a good argument for
  iterators. ;-)

- Renamed the built-in sequence iterator SeqIter, affecting the C API
  functions for it.  (This frees up the PyIter prefix for generic
  iterator operations.)

- Added PyIter_Check(obj), which checks that obj's type has a
  tp_iternext slot and that the proper feature flag is set.

- Added PyIter_Next(obj) which calls the tp_iternext slot.  It has a
  somewhat complex return condition due to the need for speed: when it
  returns NULL, it may not have set an exception condition, meaning
  the iterator is exhausted; when the exception StopIteration is set
  (or a derived exception class), it means the same thing; any other
  exception means some other error occurred.
2001-04-23 14:08:49 +00:00
Guido van Rossum 59d1d2b434 Iterators phase 1. This comprises:
new slot tp_iter in type object, plus new flag Py_TPFLAGS_HAVE_ITER
new C API PyObject_GetIter(), calls tp_iter
new builtin iter(), with two forms: iter(obj), and iter(function, sentinel)
new internal object types iterobject and calliterobject
new exception StopIteration
new opcodes for "for" loops, GET_ITER and FOR_ITER (also supported by dis.py)
new magic number for .pyc files
new special method for instances: __iter__() returns an iterator
iteration over dictionaries: "for x in dict" iterates over the keys
iteration over files: "for x in file" iterates over lines

TODO:

documentation
test suite
decide whether to use a different way to spell iter(function, sentinal)
decide whether "for key in dict" is a good idea
use iterators in map/filter/reduce, min/max, and elsewhere (in/not in?)
speed tuning (make next() a slot tp_next???)
2001-04-20 19:13:02 +00:00
Fred Drake db81e8ddf8 Add support for weak references to the function and method types. 2001-03-23 04:19:27 +00:00
Fred Drake 4e262a9631 A small change to the C API for weakly-referencable types: Such types
must now initialize the extra field used by the weak-ref machinery to
NULL themselves, to avoid having to require PyObject_INIT() to check
if the type supports weak references and do it there.  This causes less
work to be done for all objects (the type object does not need to be
consulted to check for the Py_TPFLAGS_HAVE_WEAKREFS bit).
2001-03-22 18:26:47 +00:00
Fred Drake b60654bc15 The return value from PyObject_ClearWeakRefs() is no longer meaningful,
so make it void.
2001-02-26 18:56:37 +00:00
Barry Warsaw 4f9b13bac8 instancemethod_setattro(): Raise TypeError if an attempt is made to
set a function attribute on a method (either bound or unbound).  This
reverts to Python 2.0 behavior that no attributes of the method are
writable, but provides a more informative error message.
2001-02-26 18:09:15 +00:00
Fred Drake 41deb1efc2 PEP 205, Weak References -- initial checkin. 2001-02-01 05:27:45 +00:00
Guido van Rossum 3202c6fac8 Rename dubiously named local variable 'cmpfunc' -- this is also a
typedef, and at least one compiler choked on this.

(SF patch #103457, by bquinlan)
2001-01-29 23:50:25 +00:00
Jeremy Hylton 09ac89ae78 fix indentation glitch 2001-01-29 22:38:32 +00:00
Fred Drake 5cc2c8c3c8 Re-factored PyInstance_New() into PyInstance_New() and PyInstance_NewRaw(). 2001-01-28 03:53:08 +00:00
Guido van Rossum 65e8bd7fd5 Rich comparisons fallout: instance_hash() should check for both
__cmp__ and __eq__ absent before deciding to do a quickie
based on the object address.  (Tim Peters discovered this.)
2001-01-18 23:46:31 +00:00
Guido van Rossum 24f67d568c Fix a leak in instance_coerce(). This was introduced by Neil's
earlier coercion changes, not by rich comparisons.  When a coercion
function returns 1 (meaning it cannot do it), it should not INCREF the
arguments.  When no __coerce__() method was found, instance_coerce()
originally returned 0, pretending it did it.  Neil changed the return
value to 1, more accurately reflecting that it didn't do anything, but
forgot to take out the two INCREF calls.
2001-01-17 23:43:43 +00:00
Guido van Rossum 8998b4f691 Rich comparisons.
- Got rid of instance_cmp(); refactored instance_compare().

- Added instance_richcompare() which calls __lt__() etc.

Some unrelated stuff mixed in:

- Aligned comments in various large struct initializers.

- Better test to avoid recursion if __coerce__ returns self as the
  first argument (this is an unrelated fix by Neil Schemenauer!).

- Style nit: don't use Py_DECREF(Py_NotImplemented); use
  Py_DECREF(result) -- it just looks better. :-)
2001-01-17 15:28:20 +00:00
Barry Warsaw d6a9e84c81 Committing PEP 232, function attribute feature, approved by Guido.
Closes SF patch #103123.

funcobject.h:

    PyFunctionObject: add the func_dict slot.

funcobject.c:

    PyFunction_New(): Initialize the func_dict slot to NULL.

    func_getattr(): Rename to func_getattro() and change the
    signature.  It's more efficient to use attro methods and dig the C
    string out than it is to re-convert a C string to a PyString.

    Also, add support for getting the __dict__ (a.k.a. func_dict)
    attribute, and for getting an arbitrary function attribute.

    func_setattr(): Rename to func_setattro() and change the signature
    for the same reason.  Also add support for setting __dict__
    (a.k.a. func_dict) and any arbitrary function attribute.

    func_dealloc(): Be sure to DECREF the func_dict slot.

    func_traverse(): Be sure to traverse func_dict too.

    PyFunction_Type: make the necessary func_?etattro() changes.

classobject.c:

    instancemethod_memberlist: Add __dict__

    instancemethod_setattro(): New method to set arbitrary attributes
    on methods (really the underlying im_func).  Raise TypeError when
    the instance is bound or when you're trying to set one of the
    reserved im_* attributes.

    instancemethod_getattr(): Renamed to instancemethod_getattro()
    since that's what it really is.  Also, added support fo getting
    arbitrary attributes through the im_func.

    PyMethod_Type: Do the ?etattr{,o} dance.
2001-01-15 20:40:19 +00:00
Neil Schemenauer 29bfc07183 Make instances a new style number type. See PEP 208 for details. Instance
types no longer get special treatment from abstract.c so more number number
methods have to be implemented.
2001-01-04 01:43:46 +00:00
Fred Drake 661ea26b3d Ka-Ping Yee <ping@lfw.org>:
Changes to error messages to increase consistency & clarity.

This (mostly) closes SourceForge patch #101839.
2000-10-24 19:57:45 +00:00
Neil Schemenauer e3550a65eb - fix a GC bug caused by malloc() failing 2000-10-04 16:20:41 +00:00
Tim Peters 6b184918f6 Fix for SF bug 110688: Instance deallocation neglected to account for
that Py_INCREF boosts global _Py_RefTotal when Py_REF_DEBUG is defined
but Py_TRACE_REFS isn't.

There are, IMO, way too many preprocessor gimmicks in use for refcount
debugging (at least 3 distinct true/false symbols, but not all 8 combos
are supported by the code, etc etc), and no coherent documentation of
this stuff -- 'twas too painful to track this one down.
2000-09-17 14:40:17 +00:00
Neil Schemenauer ce20967c2c Don't remove instance objects from the GC container set until we are
they are dead.  Fixes bug #113812.
2000-09-15 18:57:21 +00:00
Guido van Rossum 8586991099 REMOVED all CWI, CNRI and BeOpen copyright markings.
This should match the situation in the 1.6b1 tree.
2000-09-01 23:29:29 +00:00
Jeremy Hylton b709df3810 refactor __del__ exception handler into PyErr_WriteUnraisable
add sanity check to gc: if an exception occurs during GC, call
PyErr_WriteUnraisable and then call Py_FatalEror.
2000-09-01 02:47:25 +00:00
Thomas Wouters 1de2a79a48 Call PyErr_Clear() to clear the AttributeError raised by GetAttr. 2000-08-25 10:47:46 +00:00
Thomas Wouters e289e0bd0c Support for the in-place operations introduced by augmented assignment. Only
the list object supports this currently, but other candidates are
gladly accepted (like arraymodule and such.)
2000-08-24 20:08:19 +00:00
Barry Warsaw dc55d715bb PyInstance_DoBinOp(): When comparing the pointers, they must be cast
to integer types (i.e. Py_uintptr_t, our spelling of C9X's uintptr_t).
ANSI specifies that pointer compares other than == and != to
non-related structures are undefined.  This quiets an Insure
portability warning.
2000-08-18 04:57:32 +00:00
Thomas Wouters 1d75a79c00 Apply SF patch #101029: call __getitem__ with a proper slice object if there
is no __getslice__ available. Also does the same for C extension types.
Includes rudimentary documentation (it could use a cross reference to the
section on slice objects, I couldn't figure out how to do that) and a test
suite for all Python __hooks__ I could think of, including the new
behaviour.
2000-08-17 22:37:32 +00:00
Thomas Wouters c307352027 ANSIfy functions that were hiding inside a macro. 2000-07-23 22:09:59 +00:00
Thomas Wouters 7e47402264 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
comments, docstrings or error messages. I fixed two minor things in
test_winreg.py ("didn't" -> "Didn't" and "Didnt" -> "Didn't").

There is a minor style issue involved: Guido seems to have preferred English
grammar (behaviour, honour) in a couple places. This patch changes that to
American, which is the more prominent style in the source. I prefer English
myself, so if English is preferred, I'd be happy to supply a patch myself ;)
2000-07-16 12:04:32 +00:00
Fred Drake 799124718d ANSI-fication of the sources. 2000-07-09 04:06:11 +00:00
Tim Peters dbd9ba6a6c Nuke all remaining occurrences of Py_PROTO and Py_FPROTO. 2000-07-09 03:09:57 +00:00
Skip Montanaro 4ca150bdb2 _Py_RefTotal should only be declared here when Py_TRACE_REFS are #define'd 2000-07-08 12:04:57 +00:00
Guido van Rossum 4cc6ac7b87 Neil Schemenauer: small fixes for GC 2000-07-01 01:00:38 +00:00
Guido van Rossum ffcc3813d8 Change copyright notice - 2nd try. 2000-06-30 23:58:06 +00:00
Guido van Rossum fd71b9e9d4 Change copyright notice. 2000-06-30 23:50:40 +00:00
Fred Drake a44d353e2b Trent Mick <trentm@activestate.com>:
The common technique for printing out a pointer has been to cast to a long
and use the "%lx" printf modifier. This is incorrect on Win64 where casting
to a long truncates the pointer. The "%p" formatter should be used instead.

The problem as stated by Tim:
> Unfortunately, the C committee refused to define what %p conversion "looks
> like" -- they explicitly allowed it to be implementation-defined. Older
> versions of Microsoft C even stuck a colon in the middle of the address (in
> the days of segment+offset addressing)!

The result is that the hex value of a pointer will maybe/maybe not have a 0x
prepended to it.


Notes on the patch:

There are two main classes of changes:
- in the various repr() functions that print out pointers
- debugging printf's in the various thread_*.h files (these are why the
patch is large)


Closes SourceForge patch #100505.
2000-06-30 15:01:00 +00:00
Jeremy Hylton c5007aa5c3 final patches from Neil Schemenauer for garbage collection 2000-06-30 05:02:53 +00:00
Fred Drake 13634cf7a4 This patch addresses two main issues: (1) There exist some non-fatal
errors in some of the hash algorithms. For exmaple, in float_hash and
complex_hash a certain part of the value is not included in the hash
calculation. See Tim's, Guido's, and my discussion of this on
python-dev in May under the title "fix float_hash and complex_hash for
64-bit *nix"

(2) The hash algorithms that use pointers (e.g. func_hash, code_hash)
are universally not correct on Win64 (they assume that sizeof(long) ==
sizeof(void*))

As well, this patch significantly cleans up the hash code. It adds the
two function _Py_HashDouble and _PyHash_VoidPtr that the various
hashing routine are changed to use.

These help maintain the hash function invariant: (a==b) =>
(hash(a)==hash(b))) I have added Lib/test/test_hash.py and
Lib/test/output/test_hash to test this for some cases.
2000-06-29 19:17:04 +00:00
Guido van Rossum d7823f2645 Vladimir Marangozov:
Avoid calling the dealloc function, previously triggered with
DECREF(inst).  This caused a segfault in PyDict_GetItem, called with a
NULL dict, whenever inst->in_dict fails under low-memory conditions.
2000-06-28 23:46:07 +00:00
Guido van Rossum ad89bbcd88 Trent Mick: change a few casts for Win64 compatibility. 2000-06-28 21:57:18 +00:00
Jeremy Hylton d08b4c4524 part 2 of Neil Schemenauer's GC patches:
This patch modifies the type structures of objects that
participate in GC.  The object's tp_basicsize is increased when
GC is enabled.  GC information is prefixed to the object to
maintain binary compatibility.  GC objects also define the
tp_flag Py_TPFLAGS_GC.
2000-06-23 19:37:02 +00:00
Jeremy Hylton d22162bac7 traverse functions should return 0 on success 2000-06-23 17:14:56 +00:00