Commit Graph

1090 Commits

Author SHA1 Message Date
Raymond Hettinger 9c18e81fb2 Install two code generation optimizations that depend on NOP.
Reduces the cost of "not" to almost zero.
2004-06-21 16:31:15 +00:00
Tim Peters 9ddf40b4e1 SF patch 876130: add C API to datetime module, from Anthony Tuininga.
The LaTeX is untested (well, so is the new API, for that matter).
Note that I also changed NULL to get spelled consistently in concrete.tex.
If that was a wrong thing to do, Fred should yell at me.
2004-06-20 22:41:32 +00:00
Tim Peters 1b6f7a9057 Bug 975996: Add _PyTime_DoubleToTimet to C API
New include file timefuncs.h exports private API function
_PyTime_DoubleToTimet() from timemodule.c.  timemodule should export
some other functions too (look for painful bits in datetimemodule.c).

Added insane-argument checking to datetime's assorted fromtimestamp()
and utcfromtimestamp() methods.  Added insane-argument tests of these
to test_datetime, and insane-argument tests for ctime(), localtime()
and gmtime() to test_time.
2004-06-20 02:50:16 +00:00
Martin v. Löwis 737ea82a5a Patch #774665: Make Python LC_NUMERIC agnostic. 2004-06-08 18:52:54 +00:00
Martin v. Löwis f30d60edbc Patch #510695: Add TSC profiling for the VM. 2004-06-08 08:17:44 +00:00
Hye-Shik Chang 974ed7cfa5 - SF #962502: Add two more methods for unicode type; width() and
iswide() for east asian width manipulation. (Inspired by David
Goodger, Reviewed by Martin v. Loewis)
- Move _PyUnicode_TypeRecord.flags to the end of the struct so that
no padding is added for UCS-4 builds. (Suggested by Martin v. Loewis)
2004-06-02 16:49:17 +00:00
Martin v. Löwis e440e47e91 Patch #957398: Add public API for Generator Object/Type. 2004-06-01 15:22:42 +00:00
Raymond Hettinger cb87bc8e7e Add weakref support to array.array and file objects. 2004-05-31 00:35:52 +00:00
Raymond Hettinger 691d80532b Make sets and deques weak referencable. 2004-05-30 07:26:47 +00:00
Raymond Hettinger 354433a59d SF patch #872326: Generator expression implementation
(Code contributed by Jiwon Seo.)

The documentation portion of the patch is being re-worked and will be
checked-in soon.  Likewise, PEP 289 will be updated to reflect Guido's
rationale for the design decisions on binding behavior (as described in
in his patch comments and in discussions on python-dev).

The test file, test_genexps.py, is written in doctest format and is
meant to exercise all aspects of the the patch.  Further additions are
welcome from everyone.  Please stress test this new feature as much as
possible before the alpha release.
2004-05-19 08:20:33 +00:00
Thomas Heller 1328b52c6f Two new public API functions, Py_IncRef and Py_DecRef. Useful for
dynamic embedders of Python.
2004-04-22 17:23:49 +00:00
Tim Peters 174175bf3a Added a comment about the unreferenced PyThreadState.tick_counter
member.
2004-03-29 02:24:26 +00:00
Nicholas Bastin c69ebe8d50 Enable the profiling of C functions (builtins and extensions) 2004-03-24 21:57:10 +00:00
Hye-Shik Chang 77d9a3effa Patch #871657: Set EDOM for `nan' return values on FreeBSD and OpenBSD.
This fixes a problem that math.sqrt(-1) doesn't raise math.error.
2004-03-22 08:43:55 +00:00
Nicholas Bastin a7604bf1b4 Moved tracebackobject to traceback.h, Closes SF Bug #497067 2004-03-21 18:37:23 +00:00
Skip Montanaro 6e098a15a3 compile.h and eval.h weren't being included which kept a fair bit of the
public API from being exposed by simply including Python.h (as recommended).
2004-03-13 23:11:44 +00:00
Raymond Hettinger 4eec95ad2a SF patch #906501: Fix typos in pystate.h comments
(Contributed by Greg Chapman.)
2004-03-13 20:45:47 +00:00
Raymond Hettinger 42bec93e5c Make PySequence_Fast_ITEMS public. (Thanks Skip.) 2004-03-12 16:38:17 +00:00
Raymond Hettinger c1e4f9dd92 Use a new macro, PySequence_Fast_ITEMS to factor out code common to
three recent optimizations.  Aside from reducing code volume, it
increases readability.
2004-03-12 08:04:00 +00:00
Raymond Hettinger 8ca92ae54c Eliminate a big block of duplicate code in PySequence_List() by
exposing _PyList_Extend().
2004-03-11 09:13:12 +00:00
Raymond Hettinger dd80f76265 SF patch #910929: Optimize list comprehensions
Add a new opcode, LIST_APPEND, and apply it to the code generation for
list comprehensions.  Reduces the per-loop overhead by about a third.
2004-03-07 07:31:06 +00:00
Raymond Hettinger 4bb9540dd6 * Optimized list appends and pops by making fewer calls the underlying system
realloc().  This is achieved by tracking the overallocation size in a new
  field and using that information to skip calls to realloc() whenever
  possible.

* Simplified and tightened the amount of overallocation.  For larger lists,
  this overallocates by 1/8th (compared to the previous scheme which ranged
  between 1/4th to 1/32nd over-allocation).  For smaller lists (n<6), the
  maximum overallocation is one byte (formerly it could be upto eight bytes).
  This saves memory in applications with large numbers of small lists.

* Eliminated the NRESIZE macro in favor of a new, static list_resize function
  that encapsulates the resizing logic.  Coverting this back to macro would
  give a small (under 1%) speed-up.  This was too small to warrant the loss
  of readability, maintainability, and de-coupling.

* Some functions using NRESIZE had grown unnecessarily complex in their
  efforts to bend to the macro's calling pattern.  With the new list_resize
  function in place, those other functions could be simplified.  That is
  being saved for a separate patch.

* The ob_item==NULL check could be eliminated from the new list_resize
  function.  This would entail finding each piece of code that sets ob_item
  to NULL and adding a new line to invalidate the overallocation tracking
  field.  Rather than impose a new requirement on other pieces of list code,
  it was preferred to leave the NULL check in place and retain the benefits
  of decoupling, maintainability and information hiding (only PyList_New()
  and list_sort() need to know about the new field).  This approach also
  reduces the odds of breaking an extension module.

(Collaborative effort by Raymond Hettinger, Hye-Shik Chang, Tim Peters,
 and Armin Rigo.)
2004-02-13 11:36:39 +00:00
Michael W. Hudson ecfeb7f095 This is my patch #876198 plus a NEWS entry and a header frob.
Remove the ability to use (from C) arbitrary objects supporting the
read buffer interface as the co_code member of code objects.
2004-02-12 15:28:27 +00:00
Skip Montanaro 7befb9966e remove support for missing ANSI C header files (limits.h, stddef.h, etc). 2004-02-10 16:50:21 +00:00
Raymond Hettinger 204b000610 Revert improvement to list.append() checked in before it was ready. 2004-02-08 11:08:52 +00:00
Raymond Hettinger 06353f76be Let reversed() work with itself. 2004-02-08 10:49:42 +00:00
Skip Montanaro db6080507d Remove support for --without-universal-newlines (see PEP 11). 2004-02-07 13:53:46 +00:00
Skip Montanaro ce59c04127 Remove support for SunOS 4.
Remove BAD_EXEC_PROTOYPE (leftover from IRIX 4 demolition).
2004-01-17 14:19:44 +00:00
Jeremy Hylton 87c1afa057 Fix name problem in previous checkin: Dict not List 2003-12-26 17:17:49 +00:00
Andrew MacIntyre e99990f9e1 At 2.2, the Py<type>_Check() family of API functions (macros) changed
semantics to include subtypes.  Most concrete object APIs then had
a Py<type>_CheckExact() macro added to test for an object's type
not including subtypes.

The PyDict_CheckExact() macro wasn't created at that time, so I've added
it for API completeness/symmetry - even though nobody has complained
about its absence in the time since 2.2 was released.

Not a backport candidate.
2003-12-26 00:20:53 +00:00
Andrew MacIntyre 6f3a24d0b3 reverting 2.29: the patch was Ok, but the commit msg wrong 2003-12-26 00:19:28 +00:00
Andrew MacIntyre 43e5711309 The semantics of PyList_Check() and PyDict_Check() changed at 2.2, along
with most other concrete object checks, but the docs weren't brought into
line.

PyList_CheckExact() was added at 2.2 but never documented.

backport candidate.
2003-12-26 00:02:23 +00:00
Tim Peters 0490fe96d8 Changed the UCHAR_MAX error msg a bit: we don't really assume anything
about "characters", we assume something about C's char type (which is
an integral type).
2003-12-22 18:10:51 +00:00
Skip Montanaro ac4ea13a3a There are places in Python which assume bytes have 8-bits. Formalize that a
bit by checking the value of UCHAR_MAX in Include/Python.h.  There was a
check in Objects/stringobject.c.  Remove that.  (Note that we don't define
UCHAR_MAX if it's not defined as the old test did.)
2003-12-22 16:31:41 +00:00
Hye-Shik Chang 3ae811b57d Add rsplit method for str and unicode builtin types.
SF feature request #801847.
Original patch is written by Sean Reifschneider.
2003-12-15 18:49:53 +00:00
Raymond Hettinger 8f5cdaa784 * Added a new method flag, METH_COEXIST.
* Used the flag to optimize set.__contains__(), dict.__contains__(),
  dict.__getitem__(), and list.__getitem__().
2003-12-13 11:26:12 +00:00
Raymond Hettinger bc0f2ab9bb Expose dict_contains() and PyDict_Contains() with is about 10% faster
than PySequence_Contains() and more clearly applicable to dicts.

Apply the new function in setobject.c where __contains__ checking is
ubiquitous.
2003-11-25 21:12:14 +00:00
Raymond Hettinger f5f41bf087 * Checkin remaining documentation
* Add more tests
* Refactor and neaten the code a bit.
* Rename union_update() to update().
* Improve the algorithms (making them a closer to sets.py).
2003-11-24 02:57:33 +00:00
Tim Peters 403a203223 SF bug 839548: Bug in type's GC handling causes segfaults.
Also SF patch 843455.

This is a critical bugfix.
I'll backport to 2.3 maint, but not beyond that.  The bugs this fixes
have been there since weakrefs were introduced.
2003-11-20 21:21:46 +00:00
Jack Jansen 3305d2487d Got rid of macglue.h, moved the little bit that remains relevant
to pymactoolbox.h (where it should have been in the first place).
2003-11-20 13:28:19 +00:00
Jack Jansen eddc1449ba Getting rid of all the code inside #ifdef macintosh too. 2003-11-20 01:44:59 +00:00
Jack Jansen 37249c5524 WITHOUT_FRAMEWORKS conditional code bites the dust: this was for
pre-carbon MacOS9 support.
2003-11-19 15:32:46 +00:00
Raymond Hettinger 50a4bb325c Various fixups (most suggested by Armin Rigo). 2003-11-17 16:42:33 +00:00
Raymond Hettinger a690a9967e * Migrate set() and frozenset() from the sandbox.
* Install the unittests, docs, newsitem, include file, and makefile update.
* Exercise the new functions whereever sets.py was being used.

Includes the docs for libfuncs.tex.  Separate docs for the types are
forthcoming.
2003-11-16 16:17:49 +00:00
Alex Martelli 721b776175 fixed buggy comment as per SF bug #827856
(same as commit of Sun Nov 2 to the release23-maint branch)
2003-11-09 16:38:39 +00:00
Raymond Hettinger 85c20a41df Implement and apply PEP 322, reverse iteration 2003-11-06 14:06:48 +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
Walter Dörwald f0dfc7ac5c Fix a bunch of typos in documentation, docstrings and comments.
(From SF patch #810751)
2003-10-20 14:01:56 +00:00
Brett Cannon 4b17e3993b Modify the Py_RETURN_* macros to be of the form ``do {...} while (0)`` in order
to handle situations like ``if (foo) Py_RETURN_NONE else ...``.
2003-10-19 22:58:11 +00:00
Brett Cannon 26b3a7b82c Modified the Py_RETURN_* macros by having the statements surrounded by {} in
order to prevent any unexpected surprises from someone using them in a
conditional without using curly braces (e.g., ``if (foo) Py_RETURN_TRUE``.
2003-10-19 21:31:43 +00:00
Brett Cannon d05235ec49 Defined macros Py_RETURN_(TRUE|FALSE|NONE) as helper functions for returning
the specified value.  All three Py_INCREF the singleton and then return it.
2003-10-19 21:19:40 +00:00
Martin v. Löwis 01a74b2fa1 Make CObjects mutable. Fixes #477441. 2003-10-19 18:30:01 +00:00
Raymond Hettinger cb2da43db8 Extended tuple's C API to include a new function, PyTuple_Pack() that is
useful for rapidly building argument tuples without having to invoke the
more sophisticated machinery of Py_BuildValue().
2003-10-12 18:24:34 +00:00
Anthony Baxter 83dd43fde1 workaround for OpenBSD compiler bug w.r.t. handling of overflows. 2003-09-30 14:58:59 +00:00
Martin v. Löwis 1e3bdf6c45 Patch #788249: Pass an explicit buffer to setvbuf in PyFile_SetBufSize().
Fixes #603724. Will backport to 2.3.
2003-09-04 19:01:46 +00:00
Jason Tishler 6bc06eca70 Bug #794140: cygwin builds do not embed
The embed2.diff patch solves the user's problem by exporting the missing
symbols from the Python core so Python can be embedded in another Cygwin
application (well, at lest vim).
2003-09-04 11:59:50 +00:00
Jason Tishler 3076559ea5 This patch enables the building of Cygwin Python with a static core
which still supports shared extensions. It takes advantage the latest
Cygwin binutils (i.e., 20030901-1) which can export symbols from
executables:

http://cygwin.com/ml/cygwin-announce/2003-09/msg00002.html

Additionally, it finally lays to rest the following mailing list
subthread:

http://mail.python.org/pipermail/python-list/2002-May/102500.html

I tested the patch under Red Hat Linux 8.0 too
2003-09-04 11:04:06 +00:00
Barry Warsaw bf71fa1a59 Bump the trunk to 2.4a0 2003-07-30 05:37:39 +00:00
Tim Peters f7e609140e Repair botched release serial number. 2003-07-29 00:21:36 +00:00
Tim Peters 2f99ae5f70 Bump release level to 2.3 (we won't have time for this tomorrow). 2003-07-29 00:05:34 +00:00
Barry Warsaw ee924cd3b6 Bump the version number 2003-07-25 03:13:02 +00:00
Tim Peters 6560a254ea Update version numbers and dates for 2.3c2 -- we won't be able to do this
during the day tomorrow, so doing it earlier than I'd like.
2003-07-24 00:15:46 +00:00
Tim Peters 29dfcd108d Bump the release number to 2.3c1. 2003-07-17 14:48:26 +00:00
Neal Norwitz 21d896cfa1 Use appropriate macros not the deprecated DL_IMPORT/DL_EXPORT macros 2003-07-01 20:15:21 +00:00
Tim Peters b346096b65 Bump version string to "2.3b2+". 2003-06-30 02:14:28 +00:00
Andrew MacIntyre e3454afb2f FreeBSD 5.x uses different wchar_t/win_t guards than earlier versions 2003-06-29 15:46:21 +00:00
Tim Peters 63fd15c3d3 Bump release level to 2.3b2. 2003-06-29 00:57:17 +00:00
Guido van Rossum b8b6d0c2c6 Add PyThreadState_SetAsyncExc(long, PyObject *).
A new API (only accessible from C) to interrupt a thread by sending it
an exception.  This is not always effective, but might help some people.
Requested by Just van Rossum and Alex Martelli.  It is intentional
that you have to write your own C extension to call it from Python.

Docs will have to wait.
2003-06-28 21:53:52 +00:00
Andrew MacIntyre 1a90117880 fix the curses module build failure on FreeBSD, reported in SF #740234. 2003-06-11 12:26:08 +00:00
Jack Jansen 4eb45e7804 Added functions CFObj_New and CFObj_Convert, general functions to convert
between CF objects and their Python representation. Fixes 734695.
2003-05-27 21:39:58 +00:00
Christian Tismer 661a9e3e5b After Raymond's remark, I changed the Stackless bits to
two fixed bits, position 15 and 16. It is right, why should these
be elsewhere.
2003-05-23 12:47:36 +00:00
Christian Tismer c26ff41d3d Generalized my type flags structure extension without being specific about
the purpose. Increased my claim to two bits, hoping that nobody
will complain about it. I'm taking the highest two bits, whatever
the integer word size may be.
2003-05-23 03:33:35 +00:00
Jeremy Hylton 4d508adae3 Fix for SF [ 734869 ] Lambda functions in list comprehensions
The compiler was reseting the list comprehension tmpname counter for each function, but the symtable was using the same counter for the entire module.  Repair by move tmpname into the symtable entry.

Bugfix candidate.
2003-05-21 17:34:50 +00:00
Christian Tismer 6695ba89de Preserved one bit in type objects for Stackless.
The presence of this bit controls, whether there
are special fields for non-recursive calls.
2003-05-20 15:14:31 +00:00
Fred Drake b5662898e7 Fix broken API descriptions in comments. 2003-05-12 21:41:39 +00:00
Martin v. Löwis a94568a753 Patch #734231: Update RiscOS support. In particular, correct
riscospath.extsep, and use os.extsep throughout.
2003-05-10 07:36:56 +00:00
Martin v. Löwis 5467d4c0e3 Patch #612627: Add encoding attribute to file objects, and determine
the terminal encoding on Windows and Unix.
2003-05-10 07:10:12 +00:00
Raymond Hettinger 930427b892 Add a reference to dictnotes.txt. It does no good if you don't know it's
there or where to find it.
2003-05-03 06:51:59 +00:00
Guido van Rossum 16ec34eefb Mark CVS as 2.3b1+. 2003-04-30 22:14:27 +00:00
Tim Peters 3209410cb5 Bump version number to 2.3b1. 2003-04-24 16:45:34 +00:00
Raymond Hettinger f4cf76dd5e Revert the previous enhancement to the bytecode optimizer.
The additional code complexity and new NOP opcode were not worth it.
2003-04-24 05:45:23 +00:00
Raymond Hettinger 060641d511 Improved the bytecode optimizer.
* Can now test for basic blocks.
* Optimize inverted comparisions.
* Optimize unary_not followed by a conditional jump.
* Added a new opcode, NOP, to keep code size constant.
* Applied NOP to previous transformations where appropriate.

Note, the NOP would not be necessary if other functions were
added to re-target jump addresses and update the co_lnotab mapping.
That would yield slightly faster and cleaner bytecode at the
expense of optimizer simplicity and of keeping it decoupled
from the line-numbering structure.
2003-04-22 06:49:11 +00:00
Mark Hammond 8d98d2cb95 New PyGILState_ API - implements pep 311, from patch 684256. 2003-04-19 15:41:53 +00:00
Tim Peters 269b2a6797 _Py_PrintReferences(): Changed to print object address at start of each
new line.

New pvt API function _Py_PrintReferenceAddresses():  Prints only the
addresses and refcnts of the live objects.  This is always safe to call,
because it has no dependence on Python's C API.

Py_Finalize():  If envar PYTHONDUMPREFS is set, call (the new)
_Py_PrintReferenceAddresses() right before dumping final pymalloc stats.
We can't print the reprs of the objects here because too much of the
interpreter has been shut down.  You need to correlate the addresses
displayed here with the object reprs printed by the earlier
PYTHONDUMPREFS call to _Py_PrintReferences().
2003-04-17 19:52:29 +00:00
Thomas Heller a4ea603b05 SF # 595026: support for masks in getargs.c.
New functions:
  unsigned long PyInt_AsUnsignedLongMask(PyObject *);
  unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
  unsigned long PyLong_AsUnsignedLongMask(PyObject *);
  unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);

New and changed format codes:

b unsigned char 0..UCHAR_MAX
B unsigned char none **
h unsigned short 0..USHRT_MAX
H unsigned short none **
i int INT_MIN..INT_MAX
I * unsigned int 0..UINT_MAX
l long LONG_MIN..LONG_MAX
k * unsigned long none
L long long LLONG_MIN..LLONG_MAX
K * unsigned long long none

Notes:

* New format codes.

** Changed from previous "range-and-a-half" to "none"; the
range-and-a-half checking wasn't particularly useful.

New test test_getargs2.py, to verify all this.
2003-04-17 18:55:45 +00:00
Guido van Rossum e13ddc9ec8 - New C API PyGC_Collect(), same as calling gc.collect().
- Call this in Py_Finalize().
- Expand the Misc/NEWS text on PY_LONG_LONG.
2003-04-17 17:29:22 +00:00
Guido van Rossum d3ab37f1df Changes from Jonathan Riehl to allow his pgen extension (PEP 269) to
work.  This includes some more code that used to be part of pgen in
the main parser; I'm okay with that.  I'll see if the Windows build
needs work next.
2003-04-17 14:55:42 +00:00
Guido van Rossum a12fe4e81f - New function sys.call_tracing() allows pdb to debug code
recursively.
- pdb has a new command, "debug", which lets you step through
  arbitrary code from the debugger's (pdb) prompt.
2003-04-09 19:06:21 +00:00
Tim Peters f995cce4df Typo repair. 2003-04-08 18:47:21 +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
Martin v. Löwis b9a0f91218 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285. 2003-03-29 10:06:18 +00:00
Tim Peters 7571a0fbcf Improved new Py_TRACE_REFS gimmicks.
Arranged that all the objects exposed by __builtin__ appear in the list
of all objects.  I basically peed away two days tracking down a mystery
leak in sys.gettotalrefcount() in a ZODB app (== tons of code), because
the object leaking the references didn't appear in the sys.getobjects(0)
list.  The object happened to be False.  Now False is in the list, along
with other popular & previously missing leak candidates (like None).
Alas, we still don't have a choke point covering *all* Python objects,
so the list of all objects may still be incomplete.
2003-03-23 17:52:28 +00:00
Tim Peters 36eb4dfb81 Refactored some of the Py_TRACE_REFS code. New private API function
_Py_AddToAllObjects() that simply inserts an object at the front of
the doubly-linked list of all objects.  Changed PyType_Ready() (the
 closest thing we've got to a choke point for type objects) to call
that.
2003-03-23 03:33:13 +00:00
Tim Peters 9905b943f7 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
refactoring to get all the duplicates of this delicate code out of the
cPickle and struct modules.
2003-03-20 20:53:32 +00:00
Gustavo Niemeyer 5ddd4c3f77 Fixed SF bug #663074. The codec system was using global static
variables to store internal data. As a result, any atempts to use the
unicode system with multiple active interpreters, or successive
interpreter executions, would fail.

Now that information is stored into members of the PyInterpreterState
structure.
2003-03-19 00:35:36 +00:00
Raymond Hettinger 1da1dbf458 Renamed PyObject_GenericGetIter to PyObject_SelfIter
to more accurately describe what the function does.

Suggested by Thomas Wouters.
2003-03-17 19:46:11 +00:00
Raymond Hettinger 0153826964 Created PyObject_GenericGetIter().
Factors out the common case of returning self.
2003-03-17 08:24:35 +00:00
Guido van Rossum e5c691abe3 - The extended type structure used for heap types (new-style
classes defined by Python code using a class statement) is now
  exported from object.h as PyHeapTypeObject.  (SF patch #696193.)
2003-03-07 15:13:17 +00:00
Neal Norwitz 1930949a8a Fix SF bug #697256, PyMarshal_WriteShortToFile() documented, but not implemented
Remove prototype and doc.  Backport candidate.
2003-03-06 22:04:24 +00:00
Jack Jansen d00c13a9be Moved the Apple workaround for the guard define for wchar_t out of
the #ifdef HAVE_NCURSES_H: the same problem exists on OSX 10.1 with
a fink-installed curses (which uses curses.h as the include file name).
2003-02-28 12:51:18 +00:00