Commit Graph

1420 Commits

Author SHA1 Message Date
Neil Schemenauer 6c0f20088f Move call_trace(..., PyTrace_CALL, ...) call to top of eval_frame. That
way it's called each time a generator is resumed.  The tracing of normal
functions should be unaffected by this change.
2001-09-04 19:03:35 +00:00
Tim Peters 37a309db70 builtin_dir(): Treat classic classes like types. Use PyDict_Keys instead
of PyMapping_Keys because we know we have a real dict.  Tolerate that
objects may have an attr named "__dict__" that's not a dict (Py_None
popped up during testing).

test_descr.py, test_dir():  Test the new classic-class behavior; beef up
the new-style class test similarly.

test_pyclbr.py, checkModule():  dir(C) is no longer a synonym for
C.__dict__.keys() when C is a classic class (looks like the same thing
that burned distutils! -- should it be *made* a synoym again?  Then it
would be inconsistent with new-style class behavior.).
2001-09-04 01:20:04 +00:00
Tim Peters 5d2b77cf31 Make dir() wordier (see the new docstring). The new behavior is a mixed
bag.  It's clearly wrong for classic classes, at heart because a classic
class doesn't have a __class__ attribute, and I'm unclear on whether
that's feature or bug.  I'll repair this once I find out (in the
meantime, dir() applied to classic classes won't find the base classes,
while dir() applied to a classic-class instance *will* find the base
classes but not *their* base classes).

Please give the new dir() a try and see whether you love it or hate it.
The new dir([]) behavior is something I could come to love.  Here's
something to hate:

>>> class C:
...     pass
...
>>> c = C()
>>> dir(c)
['__doc__', '__module__']
>>>

The idea that an instance has a __doc__ attribute is jarring (of course
it's really c.__class__.__doc__ == C.__doc__; likewise for __module__).

OTOH, the code already has too many special cases, and dir(x) doesn't
have a compelling or clear purpose when x isn't a module.
2001-09-03 05:47:38 +00:00
Jack Jansen fabd00fa91 Added glue routine for PyMac_BuildFSSpec, PyMac_GetFSRef and PyMac_BuildFSRef.
Moved the declarations to pymactoolbox.h.
2001-09-01 23:39:58 +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
Fred Drake 14ef244dfe When re-writing a factor containing a unary negation of a literal, only
affect nodes without another operator.  This was causing negated
exponentiations to drop the exponentiation.  This closes SF bug #456756.
2001-08-30 18:53:25 +00:00
Guido van Rossum 46add98758 Do the int inlining only if the type is really an int, not whenever
PyInt_Check() succeeds.  That returns true for subtypes of int, which
may override __add__ or __sub__.
2001-08-30 16:06:23 +00:00
Michael W. Hudson 8019913e4a fix for part of bug #453523: disable unmarshalling of code objects in
restricted execution mode.
2001-08-30 14:50:20 +00:00
Sjoerd Mullender a2c2ae62df Removed unreachable goto statement to silence SGI compiler. 2001-08-30 14:06:45 +00:00
Sjoerd Mullender 2f38f81fec Removed some unreachable break statements to silence SGI compiler. 2001-08-30 14:05:20 +00:00
Tim Peters 692323488b Add a new function imp.lock_held(), and use it to skip test_threaded_import
when that test is doomed to deadlock.
2001-08-30 05:16:13 +00:00
Tim Peters 79248aa1e4 SF bug [#456252] Python should never stomp on [u]intptr_t.
pyport.h:  typedef a new Py_intptr_t type.
    DELICATE ASSUMPTION:  That HAVE_UINTPTR_T implies intptr_t is
    available as well as uintptr_t.  If that turns out not to be
    true, things must get uglier (C99 wants both, so I think it's
    an assumption we're *likely* to get away with).
thread_nt.h, PyThread_start_new_thread:  MS _beginthread is documented
    as returning unsigned long; no idea why uintptr_t was being used.
Others:  Always use Py_[u]intptr_t, never [u]intptr_t directly.
2001-08-29 21:37:10 +00:00
Jack Jansen c51395d797 GUSI on the Mac creates threads with a default stack size of 20KB, which is
not enough for Python. Increased the stacksize to a (somewhat arbitrary)
64KB.
2001-08-29 15:24:53 +00:00
Tim Peters 8211237db8 marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
ints, convert to PyLong (rather than throwing away the high-order 32 bits).
2001-08-29 02:28:42 +00:00
Guido van Rossum cbfc855f57 The "O!" format code should implement an isinstance() test
rather than a type equality test.
2001-08-28 16:37:51 +00:00
Jeremy Hylton 71b6af91d3 If an integer constant can't be generated from an integer literal
because of overflow, generate a long instead.
2001-08-27 19:45:25 +00:00
Jack Jansen 06bd3234cb Refer to the toolbox modules by their official name (Carbon.AE), not the internal name (_AE). This can slow things down (once) but it's the only way I can get things to work on OSX, OS9 dynamically loaded and OS9 frozen. 2001-08-27 14:01:05 +00:00
Barry Warsaw 876c8cb597 PyErr_Format(): Factor out most of this code into
PyString_FromFormat() since it's much more generally useful than
    just for exceptions.
2001-08-24 18:35:23 +00:00
Guido van Rossum f5cb357468 Add 'super' builtin type. 2001-08-24 16:52:18 +00:00
Guido van Rossum 29a62dd6eb Add new built-in type 'getset' (PyGetSet_Type).
This implements the 'getset' class from test_binop.py.
2001-08-23 21:40:38 +00:00
Jack Jansen 3cbf6d9d6e Mac toolbox modules have gotten an _ prepended to their name. 2001-08-23 13:53:34 +00:00
Guido van Rossum 87780dfa97 When an inlined operation on two small ints causes overflow, don't
raise the exception here -- call the generic function (which may
convert the arguments to long and try again).
2001-08-23 02:58:07 +00:00
Guido van Rossum ae347b33be Introduce OverflowWarning -- to be issued when short int operations
are overflowing and a long int operation is substituted.
2001-08-23 02:56:07 +00:00
Jeremy Hylton 1e35ce58e8 Fix SF bug [ #450245 ] Error in parsing future stmts
Check return value from future_parse() in for loop for file_input to
accomodate multiple future statements on separate lines.

Add several comments explaining how the code works.

Remove out-dated XXX comment.
2001-08-20 20:32:33 +00:00
Guido van Rossum 50d756e262 Fix SF bug #443600:
Change to get/set/del slice operations so that if the object doesn't
support slicing, *or* if either of the slice arguments is not an int
or long, we construct a slice object and call the get/set/del item
operation instead.  This makes it possible to design classes that
support slice arguments of non-integral types.
2001-08-18 17:43:36 +00:00
Tim Peters 9fa96bed6f Fix for bug [#452230] future division isn't propagated.
builtin_eval wasn't merging in the compiler flags from the current frame;
I suppose we never noticed this before because future division is the
first future-feature that can affect expressions (nested_scopes and
generators had only statement-level effects).
2001-08-17 23:04:59 +00:00
Tim Peters 6cd6a82db9 A fiddled version of the rest of Michael Hudson's SF patch
#449043 supporting __future__ in simulated shells
which implements PEP 264.
2001-08-17 22:11:27 +00:00
Tim Peters e2c18e90da ceval, PyEval_MergeCompilerFlags: wasn't merging in the
CO_FUTURE_DIVISION flag.  Redid this to use Jeremy's PyCF_MASK #define
instead, so we dont have to remember to fiddle individual feature names
here again.

pythonrun.h:  Also #define a PyCF_MASK_OBSOLETE mask.  This isn't used
yet, but will be as part of the PEP 264 implementation (compile() mustn't
raise an error just because old code uses a flag name that's become
obsolete; a warning may be appropriate, but not an error; so compile() has
to know about obsolete flags too, but nobody is going to remember to
update compile() with individual obsolete flag names across releases either
-- i.e., this is the flip side of PyEval_MergeCompilerFlags's oversight).
2001-08-17 20:47:47 +00:00
Martin v. Löwis 339d0f720e Patch #445762: Support --disable-unicode
- Do not compile unicodeobject, unicodectype, and unicodedata if Unicode is disabled
- check for Py_USING_UNICODE in all places that use Unicode functions
- disables unicode literals, and the builtin functions
- add the types.StringTypes list
- remove Unicode literals from most tests.
2001-08-17 18:39:25 +00:00
Martin v. Löwis e3eb1f2b23 Patch #427190: Implement and use METH_NOARGS and METH_O. 2001-08-16 13:15:00 +00:00
Guido van Rossum f6309e8ecf Oops. Two fixes for SF bug #422004 are not needed. :-) 2001-08-16 08:24:00 +00:00
Guido van Rossum 70d893a6aa Bunchathings:
- initsigs(): Ignore SIGXFZ so writing files beyond the file system
  size limit won't kill us.

- Py_Initialize(): call _Py_ReadyTypes() instead of readying types
  here.

- Py_Initialize(): call _PyImport_FixupExtension() for module
  "extensions".  (SF bug #422004.)
2001-08-16 08:21:42 +00:00
Jeremy Hylton 481081e369 Fix SF bug [ #450909 ] __future__.division fails at prompt
When code is compiled and compiler flags are passed in, be sure to
update cf_flags with any features defined by future statements in the
compiled code.
2001-08-14 20:01:59 +00:00
Barry Warsaw 928833891a Fixed typo in comment leading up to _PyImport_FixupExtension(). 2001-08-13 23:05:44 +00:00
Barry Warsaw 5821bc5145 Py_Initialize(): Apply patch by Jürgen Hermann to call
_PyImport_FixupExtension() on the exceptions module.  Now
    reload(exceptions) acts just like reload(sys) instead of raising
    an ImportError.

    This closes SF bug #422004.
2001-08-13 23:04:56 +00:00
Jeremy Hylton 910d7d46dc Remove much dead code from ceval.c
The descr changes moved the dispatch for calling objects from
call_object() in ceval.c to PyObject_Call() in abstract.c.
call_object() and the many functions it used in ceval.c were no longer
used, but were not removed.

Rename meth_call() as PyCFunction_Call() so that it can be called by
the CALL_FUNCTION opcode in ceval.c.

Also, fix error message that referred to PyEval_EvalCodeEx() by its
old name eval_code2().  (I'll probably refer to it by its old name,
too.)
2001-08-12 21:52:24 +00:00
Jeremy Hylton d5e5a2aa28 SF Patch [ 429024 ] deal with some unary ops at compile time
Revised version of Fred's patch, including support for ~ operator.

If the unary +, -, or ~ operator is applied to a constant, don't
generate a UNARY_xxx opcode. Just store the approriate value as a
constant.  If the value is negative, extend the string containing the
constant and insert a negative in the 0th position.

For ~, compute the inverse of int and longs and use them directly, but
be prepared to generate code for all other possibilities (invalid
numbers, floats, complex).
2001-08-12 01:54:38 +00:00
Jack Jansen abce416e16 Patch by Jonathan Wight (slightly reformatted) to forestall loading the
same module twice, which apparently crashes Python. I could not test the
error condition, but in normal life it seems to have no adverse effects.

Also removed an unsued variable, and corrected 2 glaring errors (missing
'case' in front of a label).
2001-08-11 21:54:11 +00:00
Jeremy Hylton 1abf610b15 Remove st_nested_scopes from struct symtable,
because nested scopes are always enabled.

(Accidentally checked in one small change along this path yesterday,
wreaking havoc in the Windows build.)
2001-08-11 21:51:24 +00:00
Tim Peters ff1f8521ac st_nested_scopes was uninitialized trash. Jeremy should fix in a better
way; see code comments.
2001-08-11 01:06:35 +00:00
Jeremy Hylton b857ba261f Refactor future feature handling
Replace uses of PyCF_xxx with CO_xxx.

Replace individual feature slots in PyFutureFeatures with single
bitmask ff_features.

When flags must be transfered among the three parts of the interpreter
that care about them -- the pythonrun layer, the compiler, and the
future feature parser -- can simply or (|) the definitions.
2001-08-10 21:41:33 +00:00
Guido van Rossum 92e2d5c7ae Apply SF patch #424554: check for PYTHONDUMPREFS to be set instead of
asking to print the references.
2001-08-09 16:37:16 +00:00
Jack Jansen d844a5f428 Got rid of unused includes. 2001-08-08 15:28:03 +00:00
Jack Jansen 94bebc0381 Split macglue.c into two: a new mactoolboxglue.c (in ./Python)
with functionality needed for both unix-Python and MacPython and a
new smaller ./Mac/Python/macglue.c which contains MacPython stuff only.

pymactoolbox.h has moved to ./Include from ./Mac/Include and now also
contains the relevant stuff from macglue.h.

The net effect of this is that the ./Mac subdirectory is not needed
anymore for building the unix-Python core on MacOSX (it is needed
for building the extension modules).
2001-08-08 13:17:31 +00:00
Martin v. Löwis 11d03c57de Put conditional S_IFMT definition into pyport.h. 2001-08-08 12:54:28 +00:00
Martin v. Löwis f9836ba4fe Put conditional S_ISDIR definition(s) into pyport.h. 2001-08-08 10:28:06 +00:00
Tim Peters 257b3bfa76 Repair the Windows build (S_ISDIR() macro doesn't exist).
Somebody else should feel free to repair this a different way; see Python-
Dev for discussion.
2001-08-08 06:24:48 +00:00
Martin v. Löwis 6b3a2c4a48 Patch #448227: Raise an exception when a directory is passed to execfile. 2001-08-08 05:30:36 +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
Guido van Rossum 528b7eb0b0 - Rename PyType_InitDict() to PyType_Ready().
- Add an explicit call to PyType_Ready(&PyList_Type) to pythonrun.c
  (just for the heck of it, really -- we should either explicitly
  ready all types, or none).
2001-08-07 17:24:28 +00:00