Skip to content

Commit 9278ddf

Browse files
authored
Revert "bpo-1635741: Port _signal module to multi-phase init (PEP 489) (GH-22049)"
This reverts commit 71d1bd9.
1 parent 54a66ad commit 9278ddf

File tree

2 files changed

+82
-87
lines changed

2 files changed

+82
-87
lines changed

Misc/NEWS.d/next/Core and Builtins/2020-09-01-17-07-20.bpo-1635741.7wSuCc.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.

Modules/signalmodule.c

Lines changed: 82 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,63 +1377,77 @@ ITIMER_PROF -- decrements both when the process is executing and\n\
13771377
A signal handler function is called with two arguments:\n\
13781378
the first is the signal number, the second is the interrupted stack frame.");
13791379

1380+
static struct PyModuleDef signalmodule = {
1381+
PyModuleDef_HEAD_INIT,
1382+
"_signal",
1383+
module_doc,
1384+
-1,
1385+
signal_methods,
1386+
NULL,
1387+
NULL,
1388+
NULL,
1389+
NULL
1390+
};
13801391

1381-
1382-
static int
1383-
signal_exec(PyObject *m)
1392+
PyMODINIT_FUNC
1393+
PyInit__signal(void)
13841394
{
1385-
/* add the functions */
1395+
PyObject *m, *d;
1396+
int i;
1397+
1398+
/* Create the module and add the functions */
1399+
m = PyModule_Create(&signalmodule);
1400+
if (m == NULL)
1401+
return NULL;
1402+
13861403
#if defined(HAVE_SIGWAITINFO) || defined(HAVE_SIGTIMEDWAIT)
13871404
if (!initialized) {
1388-
if (PyStructSequence_InitType2(&SiginfoType, &struct_siginfo_desc) < 0) {
1389-
return -1;
1390-
}
1391-
}
1392-
1393-
if (PyModule_AddType(m, &SiginfoType) < 0) {
1394-
return -1;
1405+
if (PyStructSequence_InitType2(&SiginfoType, &struct_siginfo_desc) < 0)
1406+
return NULL;
13951407
}
1408+
Py_INCREF((PyObject*) &SiginfoType);
1409+
PyModule_AddObject(m, "struct_siginfo", (PyObject*) &SiginfoType);
13961410
initialized = 1;
13971411
#endif
13981412

13991413
/* Add some symbolic constants to the module */
1400-
PyObject *d = PyModule_GetDict(m);
1414+
d = PyModule_GetDict(m);
14011415

14021416
DefaultHandler = PyLong_FromVoidPtr((void *)SIG_DFL);
14031417
if (!DefaultHandler ||
14041418
PyDict_SetItemString(d, "SIG_DFL", DefaultHandler) < 0) {
1405-
return -1;
1419+
goto finally;
14061420
}
14071421

14081422
IgnoreHandler = PyLong_FromVoidPtr((void *)SIG_IGN);
14091423
if (!IgnoreHandler ||
14101424
PyDict_SetItemString(d, "SIG_IGN", IgnoreHandler) < 0) {
1411-
return -1;
1425+
goto finally;
14121426
}
14131427

14141428
if (PyModule_AddIntMacro(m, NSIG))
1415-
return -1;
1429+
goto finally;
14161430

14171431
#ifdef SIG_BLOCK
14181432
if (PyModule_AddIntMacro(m, SIG_BLOCK))
1419-
return -1;
1433+
goto finally;
14201434
#endif
14211435
#ifdef SIG_UNBLOCK
14221436
if (PyModule_AddIntMacro(m, SIG_UNBLOCK))
1423-
return -1;
1437+
goto finally;
14241438
#endif
14251439
#ifdef SIG_SETMASK
14261440
if (PyModule_AddIntMacro(m, SIG_SETMASK))
1427-
return -1;
1441+
goto finally;
14281442
#endif
14291443

14301444
IntHandler = PyDict_GetItemString(d, "default_int_handler");
14311445
if (!IntHandler)
1432-
return -1;
1446+
goto finally;
14331447
Py_INCREF(IntHandler);
14341448

14351449
_Py_atomic_store_relaxed(&Handlers[0].tripped, 0);
1436-
for (int i = 1; i < NSIG; i++) {
1450+
for (i = 1; i < NSIG; i++) {
14371451
void (*t)(int);
14381452
t = PyOS_getsig(i);
14391453
_Py_atomic_store_relaxed(&Handlers[i].tripped, 0);
@@ -1454,187 +1468,187 @@ signal_exec(PyObject *m)
14541468

14551469
#ifdef SIGHUP
14561470
if (PyModule_AddIntMacro(m, SIGHUP))
1457-
return -1;
1471+
goto finally;
14581472
#endif
14591473
#ifdef SIGINT
14601474
if (PyModule_AddIntMacro(m, SIGINT))
1461-
return -1;
1475+
goto finally;
14621476
#endif
14631477
#ifdef SIGBREAK
14641478
if (PyModule_AddIntMacro(m, SIGBREAK))
1465-
return -1;
1479+
goto finally;
14661480
#endif
14671481
#ifdef SIGQUIT
14681482
if (PyModule_AddIntMacro(m, SIGQUIT))
1469-
return -1;
1483+
goto finally;
14701484
#endif
14711485
#ifdef SIGILL
14721486
if (PyModule_AddIntMacro(m, SIGILL))
1473-
return -1;
1487+
goto finally;
14741488
#endif
14751489
#ifdef SIGTRAP
14761490
if (PyModule_AddIntMacro(m, SIGTRAP))
1477-
return -1;
1491+
goto finally;
14781492
#endif
14791493
#ifdef SIGIOT
14801494
if (PyModule_AddIntMacro(m, SIGIOT))
1481-
return -1;
1495+
goto finally;
14821496
#endif
14831497
#ifdef SIGABRT
14841498
if (PyModule_AddIntMacro(m, SIGABRT))
1485-
return -1;
1499+
goto finally;
14861500
#endif
14871501
#ifdef SIGEMT
14881502
if (PyModule_AddIntMacro(m, SIGEMT))
1489-
return -1;
1503+
goto finally;
14901504
#endif
14911505
#ifdef SIGFPE
14921506
if (PyModule_AddIntMacro(m, SIGFPE))
1493-
return -1;
1507+
goto finally;
14941508
#endif
14951509
#ifdef SIGKILL
14961510
if (PyModule_AddIntMacro(m, SIGKILL))
1497-
return -1;
1511+
goto finally;
14981512
#endif
14991513
#ifdef SIGBUS
15001514
if (PyModule_AddIntMacro(m, SIGBUS))
1501-
return -1;
1515+
goto finally;
15021516
#endif
15031517
#ifdef SIGSEGV
15041518
if (PyModule_AddIntMacro(m, SIGSEGV))
1505-
return -1;
1519+
goto finally;
15061520
#endif
15071521
#ifdef SIGSYS
15081522
if (PyModule_AddIntMacro(m, SIGSYS))
1509-
return -1;
1523+
goto finally;
15101524
#endif
15111525
#ifdef SIGPIPE
15121526
if (PyModule_AddIntMacro(m, SIGPIPE))
1513-
return -1;
1527+
goto finally;
15141528
#endif
15151529
#ifdef SIGALRM
15161530
if (PyModule_AddIntMacro(m, SIGALRM))
1517-
return -1;
1531+
goto finally;
15181532
#endif
15191533
#ifdef SIGTERM
15201534
if (PyModule_AddIntMacro(m, SIGTERM))
1521-
return -1;
1535+
goto finally;
15221536
#endif
15231537
#ifdef SIGUSR1
15241538
if (PyModule_AddIntMacro(m, SIGUSR1))
1525-
return -1;
1539+
goto finally;
15261540
#endif
15271541
#ifdef SIGUSR2
15281542
if (PyModule_AddIntMacro(m, SIGUSR2))
1529-
return -1;
1543+
goto finally;
15301544
#endif
15311545
#ifdef SIGCLD
15321546
if (PyModule_AddIntMacro(m, SIGCLD))
1533-
return -1;
1547+
goto finally;
15341548
#endif
15351549
#ifdef SIGCHLD
15361550
if (PyModule_AddIntMacro(m, SIGCHLD))
1537-
return -1;
1551+
goto finally;
15381552
#endif
15391553
#ifdef SIGPWR
15401554
if (PyModule_AddIntMacro(m, SIGPWR))
1541-
return -1;
1555+
goto finally;
15421556
#endif
15431557
#ifdef SIGIO
15441558
if (PyModule_AddIntMacro(m, SIGIO))
1545-
return -1;
1559+
goto finally;
15461560
#endif
15471561
#ifdef SIGURG
15481562
if (PyModule_AddIntMacro(m, SIGURG))
1549-
return -1;
1563+
goto finally;
15501564
#endif
15511565
#ifdef SIGWINCH
15521566
if (PyModule_AddIntMacro(m, SIGWINCH))
1553-
return -1;
1567+
goto finally;
15541568
#endif
15551569
#ifdef SIGPOLL
15561570
if (PyModule_AddIntMacro(m, SIGPOLL))
1557-
return -1;
1571+
goto finally;
15581572
#endif
15591573
#ifdef SIGSTOP
15601574
if (PyModule_AddIntMacro(m, SIGSTOP))
1561-
return -1;
1575+
goto finally;
15621576
#endif
15631577
#ifdef SIGTSTP
15641578
if (PyModule_AddIntMacro(m, SIGTSTP))
1565-
return -1;
1579+
goto finally;
15661580
#endif
15671581
#ifdef SIGCONT
15681582
if (PyModule_AddIntMacro(m, SIGCONT))
1569-
return -1;
1583+
goto finally;
15701584
#endif
15711585
#ifdef SIGTTIN
15721586
if (PyModule_AddIntMacro(m, SIGTTIN))
1573-
return -1;
1587+
goto finally;
15741588
#endif
15751589
#ifdef SIGTTOU
15761590
if (PyModule_AddIntMacro(m, SIGTTOU))
1577-
return -1;
1591+
goto finally;
15781592
#endif
15791593
#ifdef SIGVTALRM
15801594
if (PyModule_AddIntMacro(m, SIGVTALRM))
1581-
return -1;
1595+
goto finally;
15821596
#endif
15831597
#ifdef SIGPROF
15841598
if (PyModule_AddIntMacro(m, SIGPROF))
1585-
return -1;
1599+
goto finally;
15861600
#endif
15871601
#ifdef SIGXCPU
15881602
if (PyModule_AddIntMacro(m, SIGXCPU))
1589-
return -1;
1603+
goto finally;
15901604
#endif
15911605
#ifdef SIGXFSZ
15921606
if (PyModule_AddIntMacro(m, SIGXFSZ))
1593-
return -1;
1607+
goto finally;
15941608
#endif
15951609
#ifdef SIGRTMIN
15961610
if (PyModule_AddIntMacro(m, SIGRTMIN))
1597-
return -1;
1611+
goto finally;
15981612
#endif
15991613
#ifdef SIGRTMAX
16001614
if (PyModule_AddIntMacro(m, SIGRTMAX))
1601-
return -1;
1615+
goto finally;
16021616
#endif
16031617
#ifdef SIGINFO
16041618
if (PyModule_AddIntMacro(m, SIGINFO))
1605-
return -1;
1619+
goto finally;
16061620
#endif
16071621

16081622
#ifdef ITIMER_REAL
16091623
if (PyModule_AddIntMacro(m, ITIMER_REAL))
1610-
return -1;
1624+
goto finally;
16111625
#endif
16121626
#ifdef ITIMER_VIRTUAL
16131627
if (PyModule_AddIntMacro(m, ITIMER_VIRTUAL))
1614-
return -1;
1628+
goto finally;
16151629
#endif
16161630
#ifdef ITIMER_PROF
16171631
if (PyModule_AddIntMacro(m, ITIMER_PROF))
1618-
return -1;
1632+
goto finally;
16191633
#endif
16201634

16211635
#if defined (HAVE_SETITIMER) || defined (HAVE_GETITIMER)
16221636
ItimerError = PyErr_NewException("signal.ItimerError",
16231637
PyExc_OSError, NULL);
16241638
if (!ItimerError ||
16251639
PyDict_SetItemString(d, "ItimerError", ItimerError) < 0) {
1626-
return -1;
1640+
goto finally;
16271641
}
16281642
#endif
16291643

16301644
#ifdef CTRL_C_EVENT
16311645
if (PyModule_AddIntMacro(m, CTRL_C_EVENT))
1632-
return -1;
1646+
goto finally;
16331647
#endif
16341648

16351649
#ifdef CTRL_BREAK_EVENT
16361650
if (PyModule_AddIntMacro(m, CTRL_BREAK_EVENT))
1637-
return -1;
1651+
goto finally;
16381652
#endif
16391653

16401654
#ifdef MS_WINDOWS
@@ -1643,30 +1657,12 @@ signal_exec(PyObject *m)
16431657
#endif
16441658

16451659
if (PyErr_Occurred()) {
1646-
return -1;
1660+
Py_DECREF(m);
1661+
m = NULL;
16471662
}
16481663

1649-
return 0;
1650-
}
1651-
1652-
static PyModuleDef_Slot signal_slots[] = {
1653-
{Py_mod_exec, signal_exec},
1654-
{0, NULL}
1655-
};
1656-
1657-
static struct PyModuleDef signalmodule = {
1658-
PyModuleDef_HEAD_INIT,
1659-
"_signal",
1660-
.m_doc = module_doc,
1661-
.m_size = 0,
1662-
.m_methods = signal_methods,
1663-
.m_slots = signal_slots
1664-
};
1665-
1666-
PyMODINIT_FUNC
1667-
PyInit__signal(void)
1668-
{
1669-
return PyModuleDef_Init(&signalmodule);
1664+
finally:
1665+
return m;
16701666
}
16711667

16721668
static void

0 commit comments

Comments
 (0)