@@ -493,46 +493,40 @@ narrow_hmac_hash_kind(hmacmodule_state *state, HMAC_Hash_Kind kind)
493
493
static int
494
494
_hacl_convert_errno (hacl_errno_t code , PyObject * algorithm )
495
495
{
496
+ assert (PyGILState_GetThisThreadState () != NULL );
497
+ if (code == Hacl_Streaming_Types_Success ) {
498
+ return 0 ;
499
+ }
500
+ PyGILState_STATE gstate = PyGILState_Ensure ();
496
501
switch (code ) {
497
- case Hacl_Streaming_Types_Success : {
498
- return 0 ;
499
- }
500
502
case Hacl_Streaming_Types_InvalidAlgorithm : {
501
- PyGILState_STATE gstate = PyGILState_Ensure ();
502
503
// only makes sense if an algorithm is known at call time
503
504
assert (algorithm != NULL );
504
505
assert (PyUnicode_CheckExact (algorithm ));
505
506
PyErr_Format (PyExc_ValueError , "invalid algorithm: %U" , algorithm );
506
- PyGILState_Release (gstate );
507
- return -1 ;
507
+ break ;
508
508
}
509
509
case Hacl_Streaming_Types_InvalidLength : {
510
- PyGILState_STATE gstate = PyGILState_Ensure ();
511
510
PyErr_SetString (PyExc_ValueError , "invalid length" );
512
- PyGILState_Release (gstate );
513
- return -1 ;
511
+ break ;
514
512
}
515
513
case Hacl_Streaming_Types_MaximumLengthExceeded : {
516
- PyGILState_STATE gstate = PyGILState_Ensure ();
517
514
PyErr_SetString (PyExc_OverflowError , "maximum length exceeded" );
518
- PyGILState_Release (gstate );
519
- return -1 ;
515
+ break ;
520
516
}
521
517
case Hacl_Streaming_Types_OutOfMemory : {
522
- PyGILState_STATE gstate = PyGILState_Ensure ();
523
518
PyErr_NoMemory ();
524
- PyGILState_Release (gstate );
525
- return -1 ;
519
+ break ;
526
520
}
527
521
default : {
528
- PyGILState_STATE gstate = PyGILState_Ensure ();
529
522
PyErr_Format (PyExc_RuntimeError ,
530
523
"HACL* internal routine failed with error code: %d" ,
531
524
code );
532
- PyGILState_Release (gstate );
533
- return -1 ;
525
+ break ;
534
526
}
535
527
}
528
+ PyGILState_Release (gstate );
529
+ return -1 ;
536
530
}
537
531
538
532
/*
0 commit comments