~pythonregexp2.7/python/issue2636-01+09-01-01

« back to all changes in this revision

Viewing changes to Modules/_testcapimodule.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-09-22 00:02:12 UTC
  • mfrom: (39022.1.34 Regexp-2.7)
  • Revision ID: darklord@timehorse.com-20080922000212-7r0q4f4ugiq57jph
Merged in changes from the Atomic Grouping / Possessive Qualifiers branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
600
600
        if (!PyArg_ParseTuple(args, "Oi:raise_exception",
601
601
                              &exc, &num_args))
602
602
                return NULL;
 
603
        if (!PyExceptionClass_Check(exc)) {
 
604
                PyErr_Format(PyExc_TypeError, "an exception class is required");
 
605
                return NULL;
 
606
        }
603
607
 
604
608
        exc_args = PyTuple_New(num_args);
605
609
        if (exc_args == NULL)
628
632
 */
629
633
static PyThread_type_lock thread_done = NULL;
630
634
 
631
 
static void
 
635
static int
632
636
_make_call(void *callable)
633
637
{
634
638
        PyObject *rc;
 
639
        int success;
635
640
        PyGILState_STATE s = PyGILState_Ensure();
636
641
        rc = PyObject_CallFunction((PyObject *)callable, "");
 
642
        success = (rc != NULL);
637
643
        Py_XDECREF(rc);
638
644
        PyGILState_Release(s);
 
645
        return success;
639
646
}
640
647
 
641
648
/* Same thing, but releases `thread_done` when it returns.  This variant
652
659
test_thread_state(PyObject *self, PyObject *args)
653
660
{
654
661
        PyObject *fn;
 
662
        int success = 1;
655
663
 
656
664
        if (!PyArg_ParseTuple(args, "O:test_thread_state", &fn))
657
665
                return NULL;
658
666
 
 
667
        if (!PyCallable_Check(fn)) {
 
668
                PyErr_Format(PyExc_TypeError, "'%s' object is not callable",
 
669
                        fn->ob_type->tp_name);
 
670
                return NULL;
 
671
        }
 
672
 
659
673
        /* Ensure Python is set up for threading */
660
674
        PyEval_InitThreads();
661
675
        thread_done = PyThread_allocate_lock();
666
680
        /* Start a new thread with our callback. */
667
681
        PyThread_start_new_thread(_make_call_from_thread, fn);
668
682
        /* Make the callback with the thread lock held by this thread */
669
 
        _make_call(fn);
 
683
        success &= _make_call(fn);
670
684
        /* Do it all again, but this time with the thread-lock released */
671
685
        Py_BEGIN_ALLOW_THREADS
672
 
        _make_call(fn);
 
686
        success &= _make_call(fn);
673
687
        PyThread_acquire_lock(thread_done, 1);  /* wait for thread to finish */
674
688
        Py_END_ALLOW_THREADS
675
689
 
679
693
        */
680
694
        Py_BEGIN_ALLOW_THREADS
681
695
        PyThread_start_new_thread(_make_call_from_thread, fn);
682
 
        _make_call(fn);
 
696
        success &= _make_call(fn);
683
697
        PyThread_acquire_lock(thread_done, 1);  /* wait for thread to finish */
684
698
        Py_END_ALLOW_THREADS
685
699
 
687
701
        PyThread_release_lock(thread_done);
688
702
 
689
703
        PyThread_free_lock(thread_done);
 
704
        if (!success)
 
705
                return NULL;
690
706
        Py_RETURN_NONE;
691
707
}
692
708
#endif
967
983
        PyModule_AddObject(m, "ULLONG_MAX", PyLong_FromUnsignedLongLong(PY_ULLONG_MAX));
968
984
        PyModule_AddObject(m, "PY_SSIZE_T_MAX", PyInt_FromSsize_t(PY_SSIZE_T_MAX));
969
985
        PyModule_AddObject(m, "PY_SSIZE_T_MIN", PyInt_FromSsize_t(PY_SSIZE_T_MIN));
 
986
        PyModule_AddObject(m, "SIZEOF_PYGC_HEAD", PyInt_FromSsize_t(sizeof(PyGC_Head)));
970
987
 
971
988
        TestError = PyErr_NewException("_testcapi.error", NULL, NULL);
972
989
        Py_INCREF(TestError);