Commit Graph

54 Commits

Author SHA1 Message Date
Collin Winter e19d7a3c0a Bug #742342: make Python stop segfaulting on infinitely-recursive reload()s. Fixed by patch #922167.
Backported from r54291.
2007-03-12 16:49:23 +00:00
Georg Brandl b14b59fcf9 Backport rev. 51987: superfluous semicola. 2006-09-25 06:53:42 +00:00
Neal Norwitz 0bcafac29e Building with HP's cc on HP-UX turned up a couple of problems.
_PyGILState_NoteThreadState was declared as static inconsistently.
Make it static as it's not necessary outside of this module.

Some tests failed because errno was reset to 0. (I think the tests
that failed were at least: test_fcntl and test_mailbox).
Ensure that errno doesn't change after a call to Py_END_ALLOW_THREADS.
This only affected debug builds.

This needs to be ported to HEAD.  I'll try to remember to do that tomorrow.
(Anyone, feel free to port it.)
2006-09-11 08:51:17 +00:00
Tim Peters 4643c2fda1 Followup to bug #1069160.
PyThreadState_SetAsyncExc():  internal correctness changes wrt
refcount safety and deadlock avoidance.  Also added a basic test
case (relying on ctypes) and repaired the docs.
2006-08-10 22:45:34 +00:00
Neal Norwitz e1fdb32ff2 Handle allocation failures gracefully. Found with failmalloc.
Many (all?) of these could be backported.
2006-07-21 05:32:28 +00:00
Tim Peters 112aad3630 SF bug 1524317: configure --without-threads fails to build
Moved the code for _PyThread_CurrentFrames() up, so it's no longer
in a huge "#ifdef WITH_THREAD" block (I didn't realize it /was/ in
one).

Changed test_sys's test_current_frames() so it passes with or without
thread supported compiled in.

Note that test_sys fails when Python is compiled without threads,
but for an unrelated reason (the old test_exit() fails with an
indirect ImportError on the `thread` module).  There are also
other unrelated compilation failures without threads, in extension
modules (like ctypes); at least the core compiles again.

Do we really support --without-threads?  If so, there are several
problems remaining.
2006-07-19 00:03:19 +00:00
Tim Peters 32a8361f2d After approval from Anthony, merge the tim-current_frames
branch into the trunk.  This adds a new sys._current_frames()
function, which returns a dict mapping thread id to topmost
thread stack frame.
2006-07-10 21:08:24 +00:00
Martin v. Löwis ab0e284a24 Zap ZAP. 2006-04-15 18:14:21 +00:00
Anthony Baxter ac6bd46d5c spread the extern "C" { } magic pixie dust around. Python itself builds now
using a C++ compiler. Still lots and lots of errors in the modules built by
setup.py, and a bunch of warnings from g++ in the core.
2006-04-13 02:06:09 +00:00
Anthony Baxter 7b782b61c5 more low-hanging fruit to make code compile under a C++ compiler. Not
entirely happy with the two new VISIT macros in compile.c, but I
couldn't see a better approach.
2006-04-11 12:01:56 +00:00
Tim Peters f4e6928c4d Patch 1413181, by Gabriel Becedillas.
PyThreadState_Delete():  if the auto-GIL-state machinery knows about
the thread state, forget it (since the thread state is being deleted,
continuing to remember it can't help, but can hurt if another thread
happens to get created with the same thread id).

I'll backport to 2.4 next.
2006-02-27 17:15:31 +00:00
Michael W. Hudson ce7da6c5e9 Forward port bugfix:
[ 1307978 ] Unsatisfied symbols: _PyGILState_NoteThreadState (code)

(note that this only happens in a threads-disabled build).
2005-09-30 08:20:24 +00:00
Michael W. Hudson 188d4366be Fix bug:
[ 1163563 ] Sub threads execute in restricted mode

basically by fixing bug 1010677 in a non-broken way.

Backport candidate.
2005-06-20 16:52:57 +00:00
Michael W. Hudson 867f2d45cd You can have more than one thread state for a thread if they
correspond to different interpreters (I hope, please revert if this is
wrong :).
2005-06-16 11:35:00 +00:00
Michael W. Hudson 774479c68b Fix:
[ 1176893 ] Readline segfault

by unsilly-ing PyGILState_Release().

Backport candidate.
2005-04-18 08:46:17 +00:00
Guido van Rossum 0f1f63cf07 Close the discussion in SF bug 1069160. 2005-02-08 02:07:57 +00:00
Tim Peters fb1ffb0ebb SF bug 1061968: threads: segfault or Py_FatalError at exit
PyGILState_Ensure():  The fix in 2.4a3 for bug 1010677 reintroduced thread
shutdown race bug 225673.  Repaired by (once again) ensuring the GIL is
held whenever deleting a thread state.

Alas, there's no useful test case for this shy bug.  Four years ago, only
Guido could provoke it, on his box, and today only Armin can provoke it
on his box.  I've never been able to provoke it (but not for lack of
trying!).

This is a critical fix for 2.3.5 too, since the fix for 1010677 got
backported there already and so also reintroduced 225673.  I don't intend to
backport this fix.  For whoever (if anyone) does, there are other thread
fixes in 2.4 that need backporting too, and I bet they need to happen first
for this patch to apply cleanly.
2004-11-08 04:30:21 +00:00
Tim Peters 89c0ec9beb Revert rev 2.35. It was based on erroneous reasoning -- the current
thread's id can't get duplicated, because (of course!) the current thread
is still running.  The code should work either way, but reverting the
gratuitous change should make backporting easier, and gets the bad
reasoning out of 2.35's new comments.
2004-10-10 05:30:40 +00:00
Tim Peters 8470558a04 PyInterpreterState_New(), PyThreadState_New(): use malloc/free directly.
This appears to finish repairs for SF bug 1041645.

This is a critical bugfix.
2004-10-10 02:47:33 +00:00
Tim Peters 5c14e6498a PyGILState_Release(): If we need to delete the TLS entry for this thread,
that must be done under protection of the GIL, for reasons explained in
new comments.
2004-10-09 23:55:36 +00:00
Tim Peters f9becec8cd _PyGILState_Init(), PyGILState_Ensure(): Since PyThread_set_key_value()
can fail, check its return value, and die if it does fail.

_PyGILState_Init():  Assert that the thread doesn't already have an
association for autoTLSkey.  If it does, PyThread_set_key_value() will
ignore the attempt to (re)set the association, which the code clearly
doesn't want.
2004-10-09 22:47:13 +00:00
Tim Peters 19717fa33a Style guide & consistency changes. No semantic changes. 2004-10-09 17:38:29 +00:00
Tim Peters 4c1f5ecfe3 Trim trailing whitespace. 2004-10-09 17:25:05 +00:00
Martin v. Löwis f30d60edbc Patch #510695: Add TSC profiling for the VM. 2004-06-08 08:17:44 +00:00
Nicholas Bastin e5662aedef Changed random calls to PyThreadState_Get() to use the macro 2004-03-24 22:22:12 +00:00
Martin v. Löwis f9ce67d65f Initialize thread_id to 0 in unthreaded build. Fixes #770247. 2003-07-13 10:41:53 +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
Martin v. Löwis 9e29625a1b Patch #729300: Disable error message if Python is not built for threads. 2003-05-01 05:25:29 +00:00
Mark Hammond 8d98d2cb95 New PyGILState_ API - implements pep 311, from patch 684256. 2003-04-19 15:41:53 +00:00
Guido van Rossum 0fc8f00252 - pythunrun.c, Py_Finalize(): move the call to _Py_PrintReferences()
even farther down, to just before the call to
  _PyObject_DebugMallocStats().  This required the following changes:

- pystate.c, PyThreadState_GetDict(): changed not to raise an
  exception or issue a fatal error when no current thread state is
  available, but simply return NULL without raising an exception
  (ever).

- object.c, Py_ReprEnter(): when PyThreadState_GetDict() returns NULL,
  don't raise an exception but return 0.  This means that when
  printing a container that's recursive, printing will go on and on
  and on.  But that shouldn't happen in the case we care about (see
  first bullet).

- Updated Misc/NEWS and Doc/api/init.tex to reflect changes to
  PyThreadState_GetDict() definition.
2003-04-15 15:12:39 +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
Guido van Rossum 6297a7a9fb - PyEval_GetFrame() is now declared to return a PyFrameObject *
instead of a plain PyObject *.  (SF patch #686601 by Ben Laurie.)
2003-02-19 15:53:17 +00:00
Michael W. Hudson 019a78e76d Assorted patches from Armin Rigo:
[ 617309 ] getframe hook (Psyco #1)
[ 617311 ] Tiny profiling info (Psyco #2)
[ 617312 ] debugger-controlled jumps (Psyco #3)

These are forward ports from 2.2.2.
2002-11-08 12:53:11 +00:00
Skip Montanaro 066a8df3a4 missed this one on the previous multi-file checkin - see
http://python.org/sf/602191
2002-09-03 20:24:31 +00:00
Guido van Rossum f5df46d701 Add a low-level API to access interpreters, for David Beazley.
SF patch #436376.
2001-07-19 12:19:27 +00:00
Martin v. Löwis f0473d511b Patch #412229: Add functions sys.getdlopenflags and sys.setdlopenflags.
Add dlopenflags to PyInterpreterState, and use it in dlopen calls.
2001-07-18 16:17:16 +00:00
Fred Drake 9e3ad78444 This change adjusts the profiling/tracing support so that the common
path (with no profile/trace function) through eval_code2() and
eval_frame() avoids several checks.

In the common cases of calls, returns, and exception propogation,
eval_code2() and eval_frame() used to test two values in the
thread-state: the profiling function and the tracing function.  With
this change, a flag is set in the thread-state if either of these is
active, allowing a single check to suffice when both are NULL.  This
also simplifies the code needed when either function is in use but is
already active (to avoid profiling/tracing the profiler/tracer); the
flag is set to 0 when the profile/trace code is entered, allowing the
same check to suffice for "already in the tracer" for call/return/
exception events.
2001-07-03 23:39:52 +00:00
Fred Drake 5755ce693d Revise the interface to the profiling and tracing support for the
Python interpreter.

This change adds two new C-level APIs:  PyEval_SetProfile() and
PyEval_SetTrace().  These can be used to install profile and trace
functions implemented in C, which can operate at much higher speeds
than Python-based functions.  The overhead for calling a C-based
profile function is a very small fraction of a percent of the overhead
involved in calling a Python-based function.

The machinery required to call a Python-based profile or trace
function been moved to sysmodule.c, where sys.setprofile() and
sys.setprofile() simply become users of the new interface.

As a side effect, SF bug #436058 is fixed; there is no longer a
_PyTrace_Init() function to declare.
2001-06-27 19:19:46 +00:00
Guido van Rossum 2975786dec Add a new API, PyThreadState_DeleteCurrent() that combines
PyThreadState_Delete() and PyEval_ReleaseLock().  It is only defined
if WITH_THREAD is defined.
2001-01-23 01:46:06 +00:00
Tim Peters 412f246024 PyInterpreterState_New is not thread-safe, and the recent fix to _PyPclose
can cause it to get called by multiple threads simultaneously.

Ditto for PyInterpreterState_Delete.

Of the former, the docs say "The interpreter lock need not be held, but may
be held if it is necessary to serialize calls to this function".  This
kinda implies it both is and isn't thread-safe.

Of the latter, the docs merely say "The interpreter lock need not be
held.", and the clause about serializing is absent.

I expect it was *believed* these are both thread-safe, and the bit about
serializing via the global lock was meant as a permission rather than a
caution.

I also expect we've never seen a problem here because the Python core
(prior to the _PyPclose fix) only calls these functions once per run.
The Py_NewInterpreter subsystem exposed by the C API (but not used by
Python itself) also calls them, but that subsystem appears to be very
rarely used.

Whatever, they're both thread-safe now.
2000-09-02 09:16:15 +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
Moshe Zadka 9fb6af9640 Removing warnings by gcc -Wall -- cast ugly || to void. 2000-08-04 21:27:47 +00:00
Thomas Wouters f70ef4f860 Mass ANSIfication of function definitions. Doesn't cover all 'extern'
declarations yet, those come later.
2000-07-22 18:47:25 +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
Guido van Rossum 1d5ad90c1c CRITICAL PATCH!
We occasionally received reports from people getting "invalid tstate"
crashes (this is a fatal error in PyThreadState_Delete()).  Finally
several people were able to reproduce it reliably and Tim Peters
discovered that there is a race condition when multiple threads are
calling this function without holding the global interpreter lock (the
function may be called without holding that).

Solved the race condition by adding a lock around the mutating uses of
interp->tstate_head.  Tim and Jonathan Giddy have run tests that make
it likely that this fixes the crashes -- although Tim hasn't heard
from the person who reported the original problem.
1999-06-18 14:22:24 +00:00
Guido van Rossum 18bc7c2276 Make current_tstate a global, _PyThreadState_Current. This is to
support a macro in pystate.h.
1998-12-21 18:27:28 +00:00
Guido van Rossum ede0439cd8 /* An extension mechanism to store arbitrary additional per-thread state.
PyThreadState_GetDict() returns a dictionary that can be used to hold such
   state; the caller should pick a unique key and store its state there.  If
   PyThreadState_GetDict() returns NULL, an exception has been raised (most
   likely MemoryError) and the caller should pass on the exception. */

PyObject *
PyThreadState_GetDict()
1998-04-10 20:18:25 +00:00
Guido van Rossum 22348dc0e1 The warning about thread still having a frame now only happens in
verbose mode.
1997-11-03 22:08:36 +00:00
Guido van Rossum 5f896a4de0 Added missing newline to warning msg 1997-08-21 02:28:19 +00:00