Commit Graph

190 Commits

Author SHA1 Message Date
Guido van Rossum 0daf022225 New builtin buffer() creates a derived read-only buffer from any
object that supports the buffer interface (e.g. strings, arrays).
1999-03-19 19:07:19 +00:00
Barry Warsaw 72b715d979 (initerrors): Make sure that the exception tuples ("base-classes" when
string-based exceptions are used) reflect the real class hierarchy,
i.e. that SystemExit derives from Exception not StandardError.
1999-02-24 00:35:43 +00:00
Guido van Rossum 124eff0225 Patch by Tim Peters to improve the range checks for range() and
xrange(), especially for platforms where int and long are different
sizes (so sys.maxint isn't actually the theoretical limit for the
length of a list, but the largest C int is -- sys.maxint is the
largest Python int, which is actually a C long).
1999-02-23 16:11:01 +00:00
Barry Warsaw 7890203f49 bltin_exc[]: EnvironmentError is not a "leaf exception", so set it's
leaf_exc flag to zero otherwise the name leaks memory.
1999-01-29 20:29:49 +00:00
Barry Warsaw fa77e09dd0 builtin_map(): A better fix for the previous leak plug (remember
PyList_Append steals a reference even if it fails).

builtin_filter(): Had the same leak problem as builtin_map().
1999-01-28 18:49:12 +00:00
Barry Warsaw 2133287c3e builtin_map(): Nailed memory leak. PyList_Append() borrows a
reference, so you have to DECREF the appended value.  This was a fun
one!
1999-01-28 04:21:35 +00:00
Barry Warsaw f988e687a1 builtin_complex(): Nailed memory leak. This one's in the instance
test for classes with a __complex__() method.  The attribute is pulled
out of the instance with PyObject_GetAttr() but this transfers
ownership and the function object was never DECREF'd.
1999-01-27 23:13:59 +00:00
Guido van Rossum e23cde2f8d Avoid overflow if possible in calculations for range(); report
unavoidable overflow as OverflowError.
1999-01-12 05:07:47 +00:00
Barry Warsaw 344864fcfb Added new builtin standard exception: NotImplementedError (its C
counterpart is PyExc_NotImplementedError).
1998-12-01 18:52:06 +00:00
Guido van Rossum df12a59305 Fix cosmetic bug in delattr docstring discovered by JvR. 1998-11-23 22:13:04 +00:00
Barry Warsaw 968f8cbace builtin_apply(): Second argument type check is relaxed to allow any sequence. 1998-10-01 15:33:12 +00:00
Barry Warsaw 98b6246c0c Several changes that Python carry on in the face of errors in the
initialization of class exceptions.  Specifically:

init_class_exc(): This function now returns an integer status of the
class exception initialization.  No fatal errors in this method now.
Also, use PySys_WriteStderr() when writing error messages.  When an
error occurs in this function, 0 is returned, but the partial creation
of the exception classes is not undone (this happens elsewhere).

Things that could trigger the fallback:

    - exceptions.py fails to be imported (due to syntax error, etc.)

    - one of the exception classes is missing (e.g. due to library
      version mismatch)

    - exception class can't be inserted into __builtin__'s dictionary

    - MemoryError instance can't be pre-allocated

    - some other PyErr_Occurred

newstdexception(): Changed the error message.  This is still a fatal
error because if the string based exceptions can't be created, we
really can't continue.

initerrors(): Be sure to xdecref the .exc field, which might be
non-NULL if class exceptions init was aborted.

_PyBuiltin_Init_2(): If class exception init fails, print a warning
message and reinstate the string based exceptions.
1998-09-14 18:51:11 +00:00
Guido van Rossum 746340d989 Should no longer surround PyOS_Readline() call with
Py_{BEGIN,END}_ALLOW_THREADS macros.  Also get rid of the declaration
for it (it's now in pythonrun.h).
1998-09-03 22:25:05 +00:00
Barry Warsaw d086a1a864 Added support for two new standard errors: EnvironmentError and
OSError.  The EnvironmentError serves primarily as the (common
implementation) base class for IOError and OSError.  OSError is used
by posixmodule.c

Also added tuple definition of EnvironmentError when using string
based exceptions.
1998-07-23 15:59:57 +00:00
Guido van Rossum fa4ac71dd6 Small changes to map() and filter():
(1) If a sequence S is shorter than len(S) indicated, don't fail --
just use the shorter size.  (I.e, len(S) is just a hint.)

(2) Implement the special case map(None, S) as list(S) -- it's faster.
1998-07-10 17:37:30 +00:00
Guido van Rossum 8ea9f4d10a Fix a stupid little bug: len() of an unsized returns -1 and leaves an
exception waiting to happen next...
1998-06-29 22:26:50 +00:00
Guido van Rossum 950ff2923a Experimental feature: add default argument to getattr(). 1998-06-29 13:38:57 +00:00
Guido van Rossum f9d9c6c5d2 Added doc strings. 1998-06-26 21:23:49 +00:00
Guido van Rossum d9b5208e90 In raw_input(prompt), make sure that str(prompt) really a string
object before using it.
1998-06-26 18:25:38 +00:00
Guido van Rossum 9396673a58 Remove a few unused locals (I love VC++ for this!). 1998-05-29 02:59:00 +00:00
Guido van Rossum 09df08a105 A bunch of functions are now properly implemented in abstract.c, and
the code here becomes much simpler.  In particular: abs(), divmod(),
pow(), int(), long(), float(), len(), tuple(), list().

Also make sure that no use of a function pointer gotten from a
tp_as_sequence or tp_as_mapping structure is made without checking it
for NULL first.

A few other cosmetic things, such as properly reindenting slice().
1998-05-22 00:51:39 +00:00
Guido van Rossum 1e162d3753 Implement round() slightly different, so that for negative ndigits no
additional errors happen in the last step.  The trick is to avoid
division by 0.1**n -- multiply by 10.0**n instead.
1998-05-09 14:42:25 +00:00
Guido van Rossum a937d14898 Fred's right -- we need PyList_SET_ITEM(). 1998-04-24 18:22:02 +00:00
Guido van Rossum 507338e5ca In-line the code in range() to set the list items; there's really no
need to call PyList_SetItem(v,i,w) when PyList_GET_ITEM(v,i)=w {sic}
will do.
1998-04-23 21:46:19 +00:00
Guido van Rossum 730806d3d9 Make new gcc -Wall happy 1998-04-10 22:27:42 +00:00
Guido van Rossum 8f74571596 Use a faster way to check for null bytes in the string argument for
int(), long(), float().
1998-03-13 21:30:14 +00:00
Guido van Rossum d6af46d4ae Need a cast when comparing type object in isinstance() 1997-12-10 05:51:47 +00:00
Guido van Rossum f5dd914196 Support type objects in isinstance().
E.g. isinstance('',types.StringType) will return true now instead of
raising a TypeError exception.  This is for JPython compatibility.
1997-12-02 19:11:45 +00:00
Guido van Rossum ee81af8977 Release interpreter lock around readline call in [raw_]input(). 1997-09-26 21:47:43 +00:00
Barry Warsaw b01a7fa5f8 initerrors(): Eliminate circular reference which was causing a small
but annoying memory leak.  This was introduced when PyExc_Exception
was added; the loop above populating the PyExc_StandardError exception
tuple started at index 1 in bltin_exc, but PyExc_Exception was added
at index 0, so PyExc_StandardError was getting inserted in itself!
How else can a tuple include itself?!

Change the loop to start at index 2.

This was a *fun* one! :-)
1997-09-18 03:44:38 +00:00
Barry Warsaw 412cdc2284 [Py_Exc]NumberError => [Py_Exc]ArithmeticError 1997-09-16 21:51:14 +00:00
Guido van Rossum 0474832d9c Introduce PyExc_Exception as the conceptual root class for all exceptions. 1997-09-16 18:43:15 +00:00
Guido van Rossum aee0bad0a5 First part of package support.
This doesn't yet support "import a.b.c" or "from a.b.c import x", but
it does recognize directories.  When importing a directory, it
initializes __path__ to a list containing the directory name, and
loads the __init__ module if found.

The (internal) find_module() and load_module() functions are
restructured so that they both also handle built-in and frozen modules
and Mac resources (and directories of course).  The imp module's
find_module() and (new) load_module() also have this functionality.
Moreover, imp unconditionally defines constants for all module types,
and has two more new functions: find_module_in_package() and
find_module_in_directory().

There's also a new API function, PyImport_ImportModuleEx(), which
takes all four __import__ arguments (name, globals, locals, fromlist).
The last three may be NULL.  This is currently the same as
PyImport_ImportModule() but in the future it will be able to do
relative dotted-path imports.

Other changes:

- bltinmodule.c: in __import__, call PyImport_ImportModuleEx().

- ceval.c: always pass the fromlist to __import__, even if it is a C
function, so PyImport_ImportModuleEx() is useful.

- getmtime.c: the function has a second argument, the FILE*, on which
it applies fstat().  According to Sjoerd this is much faster.  The
first (pathname) argument is ignored, but remains for backward
compatibility (so the Mac version still works without changes).

By cleverly combining the new imp functionality, the full support for
dotted names in Python (mini.py, not checked in) is now about 7K,
lavishly commented (vs. 14K for ni plus 11K for ihooks, also lavishly
commented).

Good night!
1997-09-05 07:33:22 +00:00
Barry Warsaw 757af0e7bb Removed obsolete exception PyExc_AccessError.
Added PyErr_MemoryErrorInst to hold the pre-instantiated instance when
using class based exceptions.

Simplified the creation of all built-in exceptions, both class based
and string based.  Actually, for class based exceptions, the string
ones are still created just in case there's a problem creating the
class based ones (so you still get *some* exception handling!).  Now
the init and fini functions run through a list of structure elements,
creating the strings (and optionally classes) for every entry.

initerrors(): the new base class exceptions StandardError,
LookupError, and NumberError are initialized when using string
exceptions, to tuples containing the list of derived string
exceptions.  This GvR trick enables forward compatibility!  One bit of
nastiness is that the C code has to know the inheritance tree embodied
in exceptions.py.

Added the two phase init and fini functions.
1997-08-29 22:13:51 +00:00
Barry Warsaw cde8b1ba0c Two new built-in functions: issubclass() and isinstance(). Both take
classes as their second arguments.  The former takes a class as the
first argument and returns true iff first is second, or is a subclass
of second.

The latter takes any object as the first argument and returns true iff
first is an instance of the second, or any subclass of second.

Also, change all occurances of pointer compares against
PyExc_IndexError with PyErr_ExceptionMatches() calls.
1997-08-22 21:14:38 +00:00
Guido van Rossum 25ce566661 The last of the mass checkins for separate (sub)interpreters.
Everything should now work again.

See the comments for the .h files mass checkin (e.g. pystate.h) for
more detail.
1997-08-02 03:10:38 +00:00
Guido van Rossum c8b6df9004 PyObject_Compare can raise an exception now. 1997-05-23 00:06:51 +00:00
Guido van Rossum b6a7f77c9f Oops -- missed FloatingPointError in renaming. 1997-05-09 03:03:23 +00:00
Guido van Rossum b05a5c7698 Instead of importing graminit.h whenever one of the three grammar 'root'
symbols is needed, define these in Python.h with a Py_ prefix.
1997-05-07 17:46:13 +00:00
Guido van Rossum 666b17a280 New dir() function --
- uses abstract interface where possible
- uses __members__ and __methods__
- returns [] when an object has no info available
1997-05-06 16:36:57 +00:00
Guido van Rossum 15e33a4c42 Avoid sprintf buffer overflow if more than 9999 arguments. 1997-04-30 19:00:27 +00:00
Guido van Rossum 79f25d9a7b Quickly renamed the remaining files -- this directory is done. 1997-04-29 20:08:16 +00:00
Guido van Rossum 6bf62dad9e Keep gcc -Wall and Microsoft VC happy. 1997-04-11 20:37:35 +00:00
Guido van Rossum c6472e9ee1 1. Add string conversions to int(), long(), float(). (Not to complex()!)
2. Fix two bugs in complex():

   - Memory leak when using complex(classinstance) -- r was never
   DECREF'ed.

   - Conversion of the second argument, if not complex, was done using
   the type vector of the 1st.
1997-03-31 17:15:43 +00:00
Guido van Rossum 1c6a459921 Define __debug__ as 0 if -O is given, 1 otherwise. Also test for
errors in initializing the dictionary.
1997-03-11 18:43:26 +00:00
Guido van Rossum 0ae748d3c4 Changes for Lee Busby's SIGFPE patch set.
New file pyfpe.c and exception FloatingPointError.
Surround some f.p. operations with PyFPE macro brackets.
1997-02-14 22:58:07 +00:00
Guido van Rossum e8811f85ed Added intern() function. 1997-02-14 15:48:05 +00:00
Guido van Rossum 8d75161671 Intern the string "__complex__". 1997-01-18 08:04:16 +00:00
Guido van Rossum 1a2c5cbcc4 Add unistd.h to make gcc -Wall happy. 1996-12-10 15:37:36 +00:00
Guido van Rossum ed0af8fe70 Support __complex__ method on instances, for complex() conversion.
Keep gcc -Wall happy.
1996-12-05 23:18:18 +00:00
Guido van Rossum d266eb460e New permission notice, includes CNRI. 1996-10-25 14:44:06 +00:00
Guido van Rossum b75fba04c7 Forget about Ellipses b/w compatibility. 1996-10-16 04:18:36 +00:00
Guido van Rossum e449af7da9 Ellipses -> Ellipsis rename (the dictionary really says that it should
be Ellipsis!).
Bumped the API version because a linker-visible symbol is affected.
Old C code will still compile -- there's a b/w compat macro.
Similarly, old Python code will still run, builtin exports both
Ellipses and Ellipsis.
1996-10-11 16:25:41 +00:00
Guido van Rossum b072150d7f Stupid bug: complex(x,y) would yield x+xj 1996-09-07 15:55:27 +00:00
Guido van Rossum 79d96d6bff Don't die in resizestring() on filter(<func>, ""). 1996-08-16 20:44:34 +00:00
Guido van Rossum fe4b6ee775 Include mymath.h instead of declaring prototypes for math functions.
Fix leak and unchecked error in complex().
1996-08-08 18:49:41 +00:00
Guido van Rossum 6ffd553899 Add 'Ellipses' object. 1996-07-30 18:37:55 +00:00
Guido van Rossum 8861b74445 Changes for slice and ellipses 1996-07-30 16:49:37 +00:00
Guido van Rossum 530956d247 Py_complex; and WITHOUT_COMPLEX added to getargs.c 1996-07-21 02:27:43 +00:00
Guido van Rossum 795ba583f2 Removed some redundant header includes.
dir(object) now returns object.__dict__.keys() even if __dict__ is not
a dictionary.
1996-05-23 22:49:07 +00:00
Guido van Rossum d17057745c Add list() method, analogous to tuple(). 1996-04-09 02:41:06 +00:00
Guido van Rossum c96ef6ab9e properly initialize optional arguments to apply() 1996-01-26 20:44:30 +00:00
Guido van Rossum 8a5c5d277e changes for complex numbers 1996-01-12 01:09:56 +00:00
Guido van Rossum b7b45627e8 avoid resize of 0-length tuple 1995-08-04 04:07:45 +00:00
Guido van Rossum 53bb7fff11 be more suspicious of getlocals() 1995-07-26 16:26:31 +00:00
Guido van Rossum 681d79aaf3 keyword arguments and faster calls 1995-07-18 14:51:37 +00:00
Guido van Rossum 32120311ed rename arglist to alist (conflict with new grammar symbol) 1995-07-10 13:52:21 +00:00
Guido van Rossum 872537cc86 added locals() and globals(); [raw_]input() uses readline() 1995-07-07 22:43:42 +00:00
Guido van Rossum 8a1e8eb62f fix bogus test for negative float 1995-02-18 14:51:32 +00:00
Guido van Rossum 24c137432c call __import__() with 4 args instead of 1 1995-02-14 09:42:43 +00:00
Guido van Rossum 2165158ab3 test for float to the float power here 1995-02-10 16:57:16 +00:00
Guido van Rossum a6f6050229 moved callable() to object.c 1995-01-26 00:39:50 +00:00
Guido van Rossum 7f9fa97ca2 fix import related leaks 1995-01-20 16:53:12 +00:00
Guido van Rossum 0865dd9ce9 fix Alpha bug in (x)range; different __builtins__ initialization 1995-01-17 16:30:22 +00:00
Guido van Rossum 58b6873f6b fix subtle refcount big in filter() -- Tim MacKenzie 1995-01-10 17:40:55 +00:00
Guido van Rossum 5524a59b09 move coerce() from bltinmodule.c to object.c and implement builtin_coerce() differently 1995-01-10 15:26:20 +00:00
Guido van Rossum 84eaa8396e fix globals/locals defaults for eval/execfile 1995-01-10 10:47:05 +00:00
Guido van Rossum 6135a87f2b __builtins__ mods (and sys_checkinterval for ceval.c) 1995-01-09 17:53:26 +00:00
Guido van Rossum 6a00cd8b89 * Python/bltinmodule.c: restructured coerce(), divmod(), pow() to
use new instancebinop interface
1995-01-07 12:39:01 +00:00
Guido van Rossum 6d023c98b0 Added 1995 to copyright message.
bltinmodule.c: fixed coerce() nightmare in ternary pow().
modsupport.c (initmodule2): pass METH_FREENAME flag to newmethodobject().
pythonrun.c: move flushline() into and around print_error().
1995-01-04 19:12:13 +00:00
Guido van Rossum 1ae940a587 Lots of changes, most minor (fatal() instead of abort(), use of
err_fetch/err_restore and so on).  But...
NOTE: import.c has been rewritten and all the DL stuff is now in the
new file importdl.c.
1995-01-02 19:04:15 +00:00
Guido van Rossum 030ae17582 fix pow() core dump 1994-11-10 22:33:19 +00:00
Guido van Rossum 180d7b4d55 * Python/ceval.c, Include/ceval.h: promote MakePendingCalls to
global: Py_MakePendingCalls.  Also guard against recursive calls

	* Include/classobject.h, Objects/classobject.c,
	Python/{ceval.c,bltinmodule.c}: entirely redone operator
	overloading.  The rules for class instances are now much more
	relaxed than for other built-in types
	(whose coerce must still return two objects of the same type)
1994-09-29 09:45:57 +00:00
Guido van Rossum e4ab6475f1 * Python/getmtime.c: Remove mac specifics (Mac subdirectory has
its own version now)
* Python/bltinmodule.c (builtin_tuple): use pre-existing
listtuple(v) for lists
1994-08-30 12:38:05 +00:00
Guido van Rossum 14144fcdfd Added delattr() 1994-08-29 12:53:40 +00:00
Guido van Rossum cae027b298 * Python/bltinmodule.c: added tuple() builtin 1994-08-29 12:53:11 +00:00
Guido van Rossum df05ac6dfb Python/bltinmodule.c: mods by Andrew Kuchling to implement
pow(x,y,z) == pow(x,y)%z, but without incurring overflow
1994-08-29 12:52:37 +00:00
Guido van Rossum 2d9518585c * Python/bltinmodule.c (builtin_vars): correct typo in error msg 1994-08-29 12:52:16 +00:00
Guido van Rossum 7d6aa51b56 * rangeobject.[ch], bltinmodule.c: incorporate new version of range
object (unchanged from source except "range" -> "xrange").
1993-12-21 22:50:31 +00:00
Guido van Rossum 590baa4a7a * import.c (get_module): pass .py filename to parse_file, not .pyc filename!
* funcobject.c (func_repr): don't call getstringvalue(None) for anonymous
  functions.
* bltinmodule.c: removed lambda (which is now a built-in function);
  removed implied lambda for string arg to filter/map/reduce.
* Grammar, graminit.[ch], compile.[ch]: replaced lambda as built-in
  function by lambda as grammar entity: instead of "lambda('x: x+1')" you
  write "lambda x: x+1".
* Xtmodule.c (checkargdict): return 0, not NULL, for error.
1993-11-30 13:40:46 +00:00
Guido van Rossum c600411755 * mpzmodule.c: removed redundant mpz_print function.
* object.[ch], bltinmodule.c, fileobject.c: changed str() to call
  strobject() which calls an object's __str__ method if it has one.
  strobject() is also called by writeobject() when PRINT_RAW is passed.
* ceval.c: rationalize code for PRINT_ITEM (no change in function!)
* funcobject.c, codeobject.c: added compare and hash functionality.
  Functions with identical code objects and the same global dictionary are
  equal.  Code objects are equal when their code, constants list and names
  list are identical (i.e. the filename and code name don't count).
  (hash doesn't work yet since the constants are in a list and lists can't
  be hashed -- suppose this should really be done with a tuple now we have
  resizetuple!)
1993-11-05 10:22:19 +00:00
Guido van Rossum e77a757094 * nismodule.c: database keys and values can contain null bytes. be more
careful about these.
* arraymodule.c: added 8 byte swap; added 'i' format character; added
  reverse() method; rename read/write to fromfile/tofile.
* config.c: Set version to 0.9.9++.
* rotormodule.c (r_rand): declare k1..k5 as unsigned longs so the shifts
  will have a well-defined effect independent of word size.
* bltinmodule.c: renamed bagof() to filter().
1993-11-03 15:01:26 +00:00
Guido van Rossum 2586bf0a34 * rangeobject.{c,h}, bltinmodule.c: removed non-essential ops from range
object.
1993-11-01 16:21:44 +00:00
Sjoerd Mullender 615194a352 Fixed bugs in resizetuple and extended the interface.
Added ifdefs in stringobject.c for shared strings of length 1.
Renamed free_list in tupleobject.c to free_tuples.
1993-11-01 13:46:50 +00:00
Guido van Rossum dc4b93db70 * listobject.c (list_ass_slice): XDECREF instead of DECREF so
setlistslice() can be used to cut the unused part out of a freshly made
  slice (as done by bagof()).  [needed by the next mod!]
* structural changes to bagof(), map() etc.
1993-10-27 14:56:44 +00:00
Guido van Rossum 12d12c5faf * compile.[ch]: support for lambda()
* PROTO.h, mymalloc.h: added #ifdefs for TURBOC and GNUC.
* allobjects.h: added #include "rangeobject.h"
* Grammar: added lambda_input; relaxed syntax for exec.
* bltinmodule.c: added bagof, map, reduce, lambda, xrange.
* tupleobject.[ch]: added resizetuple().
* rangeobject.[ch]: new object type to speed up range operations (not
  convinced this is needed!!!)
1993-10-26 17:58:25 +00:00
Guido van Rossum 89b3325dc4 * import.c (MAGIC): Changed magic word to avoid confusion about exec
function vs. exec statement
* bltinmodule.c: renamed the module to __builtin__.
* posixmodule.c (posix_execv): renamed exec --> execv since it is now a
  reserved word.
1993-10-22 14:26:06 +00:00
Guido van Rossum db3165e655 * bltinmodule.c: removed exec() built-in function.
* Grammar: add exec statement; allow testlist in expr statement.
* ceval.c, compile.c, opcode.h: support exec statement;
  avoid optimizing locals when it is used
* fileobject.{c,h}: add getfilename() internal function.
1993-10-18 17:06:59 +00:00
Guido van Rossum 234f942aef * Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Added $(SYSDEF) to its build rule in Makefile.
* cgensupport.[ch], modsupport.[ch]: removed some old stuff.  Also
  changed files that still used it...  And made several things static
  that weren't but should have been...  And other minor cleanups...
* listobject.[ch]: add external interfaces {set,get}listslice
* socketmodule.c: fix bugs in new send() argument parsing.
* sunaudiodevmodule.c: added flush() and close().
1993-06-17 12:35:49 +00:00
Guido van Rossum 81daa32c15 Access checks now work, at least for instance data (not for methods
yet).  The class is now passed to eval_code and stored in the current
frame.  It is also stored in instance method objects.  An "unbound"
instance method is now returned when a function is retrieved through
"classname.funcname", which when called passes the class to eval_code.
1993-05-20 14:24:46 +00:00