@@ -2746,6 +2746,7 @@ get_date_fromdate(PyObject *self, PyObject *args)
27462746 return rv ;
27472747}
27482748
2749+
27492750static PyObject *
27502751get_datetime_fromdateandtime (PyObject * self , PyObject * args )
27512752{
@@ -4526,12 +4527,19 @@ temporary_c_thread(void *data)
45264527 PyThread_release_lock (test_c_thread -> exit_event );
45274528}
45284529
4530+ static test_c_thread_t test_c_thread ;
4531+
45294532static PyObject *
4530- call_in_temporary_c_thread (PyObject * self , PyObject * callback )
4533+ call_in_temporary_c_thread (PyObject * self , PyObject * args )
45314534{
45324535 PyObject * res = NULL ;
4533- test_c_thread_t test_c_thread ;
4536+ PyObject * callback = NULL ;
45344537 long thread ;
4538+ int wait = 1 ;
4539+ if (!PyArg_ParseTuple (args , "O|i" , & callback , & wait ))
4540+ {
4541+ return NULL ;
4542+ }
45354543
45364544 test_c_thread .start_event = PyThread_allocate_lock ();
45374545 test_c_thread .exit_event = PyThread_allocate_lock ();
@@ -4541,8 +4549,7 @@ call_in_temporary_c_thread(PyObject *self, PyObject *callback)
45414549 goto exit ;
45424550 }
45434551
4544- Py_INCREF (callback );
4545- test_c_thread .callback = callback ;
4552+ test_c_thread .callback = Py_NewRef (callback );
45464553
45474554 PyThread_acquire_lock (test_c_thread .start_event , 1 );
45484555 PyThread_acquire_lock (test_c_thread .exit_event , 1 );
@@ -4558,23 +4565,45 @@ call_in_temporary_c_thread(PyObject *self, PyObject *callback)
45584565 PyThread_acquire_lock (test_c_thread .start_event , 1 );
45594566 PyThread_release_lock (test_c_thread .start_event );
45604567
4568+ if (!wait ) {
4569+ Py_RETURN_NONE ;
4570+ }
4571+
45614572 Py_BEGIN_ALLOW_THREADS
45624573 PyThread_acquire_lock (test_c_thread .exit_event , 1 );
45634574 PyThread_release_lock (test_c_thread .exit_event );
45644575 Py_END_ALLOW_THREADS
45654576
4566- Py_INCREF (Py_None );
4567- res = Py_None ;
4577+ res = Py_NewRef (Py_None );
45684578
45694579exit :
45704580 Py_CLEAR (test_c_thread .callback );
4571- if (test_c_thread .start_event )
4581+ if (test_c_thread .start_event ) {
45724582 PyThread_free_lock (test_c_thread .start_event );
4573- if (test_c_thread .exit_event )
4583+ test_c_thread .start_event = NULL ;
4584+ }
4585+ if (test_c_thread .exit_event ) {
45744586 PyThread_free_lock (test_c_thread .exit_event );
4587+ test_c_thread .exit_event = NULL ;
4588+ }
45754589 return res ;
45764590}
45774591
4592+ static PyObject *
4593+ join_temporary_c_thread (PyObject * self , PyObject * Py_UNUSED (ignored ))
4594+ {
4595+ Py_BEGIN_ALLOW_THREADS
4596+ PyThread_acquire_lock (test_c_thread .exit_event , 1 );
4597+ PyThread_release_lock (test_c_thread .exit_event );
4598+ Py_END_ALLOW_THREADS
4599+ Py_CLEAR (test_c_thread .callback );
4600+ PyThread_free_lock (test_c_thread .start_event );
4601+ test_c_thread .start_event = NULL ;
4602+ PyThread_free_lock (test_c_thread .exit_event );
4603+ test_c_thread .exit_event = NULL ;
4604+ Py_RETURN_NONE ;
4605+ }
4606+
45784607/* marshal */
45794608
45804609static PyObject *
@@ -6418,8 +6447,9 @@ static PyMethodDef TestMethods[] = {
64186447 {"docstring_with_signature_with_defaults" ,
64196448 (PyCFunction )test_with_docstring , METH_NOARGS ,
64206449 docstring_with_signature_with_defaults },
6421- {"call_in_temporary_c_thread" , call_in_temporary_c_thread , METH_O ,
6450+ {"call_in_temporary_c_thread" , call_in_temporary_c_thread , METH_VARARGS ,
64226451 PyDoc_STR ("set_error_class(error_class) -> None" )},
6452+ {"join_temporary_c_thread" , join_temporary_c_thread , METH_NOARGS },
64236453 {"pymarshal_write_long_to_file" ,
64246454 pymarshal_write_long_to_file , METH_VARARGS },
64256455 {"pymarshal_write_object_to_file" ,
0 commit comments