@@ -487,39 +487,31 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
487
487
{
488
488
PyObject * func , * result ;
489
489
long retval ;
490
- static PyObject * context ;
491
-
492
- if (context == NULL )
493
- context = PyUnicode_InternFromString ("_ctypes.DllGetClassObject" );
494
490
495
491
func = PyImport_ImportModuleAttrString ("ctypes" , "DllGetClassObject" );
496
492
if (!func ) {
497
- PyErr_WriteUnraisable (context ? context : Py_None );
498
493
/* There has been a warning before about this already */
499
- return E_FAIL ;
494
+ goto error ;
500
495
}
501
496
502
497
{
503
498
PyObject * py_rclsid = PyLong_FromVoidPtr ((void * )rclsid );
504
499
if (py_rclsid == NULL ) {
505
500
Py_DECREF (func );
506
- PyErr_WriteUnraisable (context ? context : Py_None );
507
- return E_FAIL ;
501
+ goto error ;
508
502
}
509
503
PyObject * py_riid = PyLong_FromVoidPtr ((void * )riid );
510
504
if (py_riid == NULL ) {
511
505
Py_DECREF (func );
512
506
Py_DECREF (py_rclsid );
513
- PyErr_WriteUnraisable (context ? context : Py_None );
514
- return E_FAIL ;
507
+ goto error ;
515
508
}
516
509
PyObject * py_ppv = PyLong_FromVoidPtr (ppv );
517
510
if (py_ppv == NULL ) {
518
511
Py_DECREF (py_rclsid );
519
512
Py_DECREF (py_riid );
520
513
Py_DECREF (func );
521
- PyErr_WriteUnraisable (context ? context : Py_None );
522
- return E_FAIL ;
514
+ goto error ;
523
515
}
524
516
result = PyObject_CallFunctionObjArgs (func ,
525
517
py_rclsid ,
@@ -532,17 +524,21 @@ long Call_GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
532
524
}
533
525
Py_DECREF (func );
534
526
if (!result ) {
535
- PyErr_WriteUnraisable (context ? context : Py_None );
536
- return E_FAIL ;
527
+ goto error ;
537
528
}
538
529
539
530
retval = PyLong_AsLong (result );
540
531
if (PyErr_Occurred ()) {
541
- PyErr_WriteUnraisable ( context ? context : Py_None );
542
- retval = E_FAIL ;
532
+ Py_DECREF ( result );
533
+ goto error ;
543
534
}
544
535
Py_DECREF (result );
545
536
return retval ;
537
+
538
+ error :
539
+ PyErr_FormatUnraisable ("Exception ignored while calling "
540
+ "ctypes.DllGetClassObject" );
541
+ return E_FAIL ;
546
542
}
547
543
548
544
STDAPI DllGetClassObject (REFCLSID rclsid ,
@@ -563,10 +559,6 @@ long Call_CanUnloadNow(void)
563
559
{
564
560
PyObject * mod , * func , * result ;
565
561
long retval ;
566
- static PyObject * context ;
567
-
568
- if (context == NULL )
569
- context = PyUnicode_InternFromString ("_ctypes.DllCanUnloadNow" );
570
562
571
563
mod = PyImport_ImportModule ("ctypes" );
572
564
if (!mod ) {
@@ -580,24 +572,27 @@ long Call_CanUnloadNow(void)
580
572
func = PyObject_GetAttrString (mod , "DllCanUnloadNow" );
581
573
Py_DECREF (mod );
582
574
if (!func ) {
583
- PyErr_WriteUnraisable (context ? context : Py_None );
584
- return E_FAIL ;
575
+ goto error ;
585
576
}
586
577
587
578
result = _PyObject_CallNoArgs (func );
588
579
Py_DECREF (func );
589
580
if (!result ) {
590
- PyErr_WriteUnraisable (context ? context : Py_None );
591
- return E_FAIL ;
581
+ goto error ;
592
582
}
593
583
594
584
retval = PyLong_AsLong (result );
595
585
if (PyErr_Occurred ()) {
596
- PyErr_WriteUnraisable ( context ? context : Py_None );
597
- retval = E_FAIL ;
586
+ Py_DECREF ( result );
587
+ goto error ;
598
588
}
599
589
Py_DECREF (result );
600
590
return retval ;
591
+
592
+ error :
593
+ PyErr_FormatUnraisable ("Exception ignored while calling "
594
+ "ctypes.DllCanUnloadNow" );
595
+ return E_FAIL ;
601
596
}
602
597
603
598
/*
0 commit comments