@@ -498,28 +498,38 @@ _hacl_convert_errno(hacl_errno_t code, PyObject *algorithm)
498498 return 0 ;
499499 }
500500 case Hacl_Streaming_Types_InvalidAlgorithm : {
501+ PyGILState_STATE gstate = PyGILState_Ensure ();
501502 // only makes sense if an algorithm is known at call time
502503 assert (algorithm != NULL );
503504 assert (PyUnicode_CheckExact (algorithm ));
504505 PyErr_Format (PyExc_ValueError , "invalid algorithm: %U" , algorithm );
506+ PyGILState_Release (gstate );
505507 return -1 ;
506508 }
507509 case Hacl_Streaming_Types_InvalidLength : {
510+ PyGILState_STATE gstate = PyGILState_Ensure ();
508511 PyErr_SetString (PyExc_ValueError , "invalid length" );
512+ PyGILState_Release (gstate );
509513 return -1 ;
510514 }
511515 case Hacl_Streaming_Types_MaximumLengthExceeded : {
516+ PyGILState_STATE gstate = PyGILState_Ensure ();
512517 PyErr_SetString (PyExc_OverflowError , "maximum length exceeded" );
518+ PyGILState_Release (gstate );
513519 return -1 ;
514520 }
515521 case Hacl_Streaming_Types_OutOfMemory : {
522+ PyGILState_STATE gstate = PyGILState_Ensure ();
516523 PyErr_NoMemory ();
524+ PyGILState_Release (gstate );
517525 return -1 ;
518526 }
519527 default : {
528+ PyGILState_STATE gstate = PyGILState_Ensure ();
520529 PyErr_Format (PyExc_RuntimeError ,
521530 "HACL* internal routine failed with error code: %d" ,
522531 code );
532+ PyGILState_Release (gstate );
523533 return -1 ;
524534 }
525535 }
0 commit comments