[Python-checkins] r46640 - in python/trunk: Doc/lib/libthread.tex Doc/lib/libthreading.tex Include/pythread.h Lib/dummy_thread.py Lib/test/output/test_thread Lib/test/test_thread.py Lib/test/test_threading.py Lib/threading.py Misc/NEWS Modules/th

Neal Norwitz nnorwitz at gmail.com
Sun Jun 4 19:19:00 CEST 2006


On 6/4/06, andrew.macintyre <python-checkins at python.org> wrote:
> Author: andrew.macintyre
> Date: Sun Jun  4 14:31:09 2006
> New Revision: 46640
>
> Modified: python/trunk/Modules/threadmodule.c
> ==============================================================================
> --- python/trunk/Modules/threadmodule.c (original)
> +++ python/trunk/Modules/threadmodule.c Sun Jun  4 14:31:09 2006
> @@ -586,6 +586,51 @@
>  be relied upon, and the number should be seen purely as a magic cookie.\n\
>  A thread's identity may be reused for another thread after it exits.");
>
> +static PyObject *
> +thread_stack_size(PyObject *self, PyObject *args)
> +{
> +       size_t old_size, new_size;
> +       PyObject *set_size = NULL;
> +
> +       if (!PyArg_UnpackTuple(args, "stack_size", 0, 1, &set_size))
> +               return NULL;
> +
> +       old_size = PyThread_get_stacksize();
> +
> +       if (set_size != NULL) {
> +               if (PyInt_Check(set_size))
> +                       new_size = (size_t) PyInt_AsLong(set_size);
> +               else {
> +                       PyErr_SetString(PyExc_TypeError,
> +                                       "size must be an integer");
> +                       return NULL;
> +               }
> +               if (PyThread_set_stacksize(new_size))
> +                       return NULL;
> +       }
> +
> +       return PyInt_FromLong((long) old_size);
> +}

You should accept PyLongs too and deal with Py_ssize_t features also.
I don't think you should need any casts.

> Modified: python/trunk/Python/thread.c
> ==============================================================================
> --- python/trunk/Python/thread.c        (original)
> +++ python/trunk/Python/thread.c        Sun Jun  4 14:31:09 2006
> @@ -94,6 +94,31 @@
>         PyThread__init_thread();
>  }
>
> +/* Support for runtime thread stack size tuning.
> +   A value of 0 means using the platform's default stack size
> +   or the size specified by the THREAD_STACK_SIZE macro. */
> +static size_t _pythread_stacksize = 0;
> +
> +size_t
> +PyThread_get_stacksize(void)
> +{
> +       return _pythread_stacksize;
> +}
> +
> +static int
> +_pythread_unsupported_set_stacksize(size_t size)
> +{
> +       return PyErr_Warn(PyExc_RuntimeWarning,
> +                         "setting thread stack size not supported on "
> +                          "this platform");
> +}
> +
> +/* Only platforms with THREAD_SET_STACKSIZE() defined in
> +   pthread_<platform>.h, overriding this default definition,
> +   will support changing the stack size.
> +   Return 1 if an exception is pending, 0 otherwise. */
> +#define THREAD_SET_STACKSIZE(x)        _pythread_unsupported_set_stacksize(x)
> +
>  #ifdef SGI_THREADS
>  #include "thread_sgi.h"
>  #endif
> @@ -149,6 +174,14 @@
>  #endif
>  */
>
> +/* use appropriate thread stack size setting routine.
> +   Return 1 if an exception is pending, 0 otherwise. */

This looks like it returns the result of PyErr_Warn which returns 0 on
success and -1 if an error occurs.  This comment doesn't seem to agree
with the code.  I think there are multiple occurrences of this
comment.

> +int
> +PyThread_set_stacksize(size_t size)
> +{
> +       return THREAD_SET_STACKSIZE(size);
> +}

> Modified: python/trunk/Python/thread_pthread.h
> ==============================================================================
> --- python/trunk/Python/thread_pthread.h        (original)
> +++ python/trunk/Python/thread_pthread.h        Sun Jun  4 14:31:09 2006
...
> +static int
> +_pythread_pthread_set_stacksize(size_t size)
> +{
> +       /* set to default */
> +       if (size == 0) {
> +               _pythread_stacksize = 0;
> +               return 0;
> +       }
> +
> +       /* valid range? */
> +       if (size >= THREAD_STACK_MIN) {
> +               _pythread_stacksize = size;
> +               return 0;
> +       }
> +       else {
> +               char warning[128];
> +               snprintf(warning,
> +                        128,
> +                        "thread stack size of %#x bytes not supported",
> +                        size);

Why not use PyOS_snprintf for more portability, just in case?  Ditto
for other header changes (even though those are more windows/platform
specific).

> +               return PyErr_Warn(PyExc_RuntimeWarning, warning);
> +       }
> +}

n


More information about the Python-checkins mailing list