Skip to content

Commit 0f4c7cb

Browse files
committed
refactor(unix_signal): provide a conservative table size
1 parent 39143f0 commit 0f4c7cb

File tree

2 files changed

+78
-71
lines changed

2 files changed

+78
-71
lines changed

luaa.c

Lines changed: 10 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,17 @@ luaA_dofunction_on_error(lua_State *L)
940940
static void
941941
setup_awesome_signals(lua_State *L)
942942
{
943+
int count = 0;
944+
#define SETUP_SIGNAL(sig) \
945+
do { \
946+
count++; \
947+
} while (0)
948+
#include "unix_signals.h"
949+
#undef SETUP_SIGNAL
950+
943951
lua_getglobal(L, "awesome");
944952
lua_pushstring(L, "unix_signal");
945-
lua_newtable(L);
953+
lua_createtable(L, 0, count);
946954

947955
#define SETUP_SIGNAL(sig) \
948956
do { \
@@ -954,76 +962,7 @@ setup_awesome_signals(lua_State *L)
954962
lua_pushstring(L, #sig); \
955963
lua_settable(L, -3); \
956964
} while (0)
957-
958-
/* Non-standard signals. These are first so that e.g. (on my system)
959-
* signals[29] is SIGPOLL and not SIGIO (the value gets overwritten).
960-
*/
961-
#ifdef SIGIOT
962-
SETUP_SIGNAL(SIGIOT);
963-
#endif
964-
#ifdef SIGEMT
965-
SETUP_SIGNAL(SIGEMT);
966-
#endif
967-
#ifdef SIGSTKFLT
968-
SETUP_SIGNAL(SIGSTKFLT);
969-
#endif
970-
#ifdef SIGIO
971-
SETUP_SIGNAL(SIGIO);
972-
#endif
973-
#ifdef SIGCLD
974-
SETUP_SIGNAL(SIGCLD);
975-
#endif
976-
#ifdef SIGPWR
977-
SETUP_SIGNAL(SIGPWR);
978-
#endif
979-
#ifdef SIGINFO
980-
SETUP_SIGNAL(SIGINFO);
981-
#endif
982-
#ifdef SIGLOST
983-
SETUP_SIGNAL(SIGLOST);
984-
#endif
985-
#ifdef SIGWINCH
986-
SETUP_SIGNAL(SIGWINCH);
987-
#endif
988-
#ifdef SIGUNUSED
989-
SETUP_SIGNAL(SIGUNUSED);
990-
#endif
991-
992-
/* POSIX.1-1990, according to man 7 signal */
993-
SETUP_SIGNAL(SIGHUP);
994-
SETUP_SIGNAL(SIGINT);
995-
SETUP_SIGNAL(SIGQUIT);
996-
SETUP_SIGNAL(SIGILL);
997-
SETUP_SIGNAL(SIGABRT);
998-
SETUP_SIGNAL(SIGFPE);
999-
SETUP_SIGNAL(SIGKILL);
1000-
SETUP_SIGNAL(SIGSEGV);
1001-
SETUP_SIGNAL(SIGPIPE);
1002-
SETUP_SIGNAL(SIGALRM);
1003-
SETUP_SIGNAL(SIGTERM);
1004-
SETUP_SIGNAL(SIGUSR1);
1005-
SETUP_SIGNAL(SIGUSR2);
1006-
SETUP_SIGNAL(SIGCHLD);
1007-
SETUP_SIGNAL(SIGCONT);
1008-
SETUP_SIGNAL(SIGSTOP);
1009-
SETUP_SIGNAL(SIGTSTP);
1010-
SETUP_SIGNAL(SIGTTIN);
1011-
SETUP_SIGNAL(SIGTTOU);
1012-
1013-
/* POSIX.1-2001, according to man 7 signal */
1014-
SETUP_SIGNAL(SIGBUS);
1015-
/* Some Operating Systems doesn't have SIGPOLL (e.g. FreeBSD) */
1016-
#ifdef SIGPOLL
1017-
SETUP_SIGNAL(SIGPOLL);
1018-
#endif
1019-
SETUP_SIGNAL(SIGPROF);
1020-
SETUP_SIGNAL(SIGSYS);
1021-
SETUP_SIGNAL(SIGTRAP);
1022-
SETUP_SIGNAL(SIGURG);
1023-
SETUP_SIGNAL(SIGVTALRM);
1024-
SETUP_SIGNAL(SIGXCPU);
1025-
SETUP_SIGNAL(SIGXFSZ);
1026-
965+
#include "unix_signals.h"
1027966
#undef SETUP_SIGNAL
1028967

1029968
/* Set awesome.signal to the table we just created, key was already pushed */

unix_signals.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* Non-standard signals. These are first so that e.g. (on my system)
2+
* signals[29] is SIGPOLL and not SIGIO (the value gets overwritten).
3+
*/
4+
#ifdef SIGIOT
5+
SETUP_SIGNAL(SIGIOT);
6+
#endif
7+
#ifdef SIGEMT
8+
SETUP_SIGNAL(SIGEMT);
9+
#endif
10+
#ifdef SIGSTKFLT
11+
SETUP_SIGNAL(SIGSTKFLT);
12+
#endif
13+
#ifdef SIGIO
14+
SETUP_SIGNAL(SIGIO);
15+
#endif
16+
#ifdef SIGCLD
17+
SETUP_SIGNAL(SIGCLD);
18+
#endif
19+
#ifdef SIGPWR
20+
SETUP_SIGNAL(SIGPWR);
21+
#endif
22+
#ifdef SIGINFO
23+
SETUP_SIGNAL(SIGINFO);
24+
#endif
25+
#ifdef SIGLOST
26+
SETUP_SIGNAL(SIGLOST);
27+
#endif
28+
#ifdef SIGWINCH
29+
SETUP_SIGNAL(SIGWINCH);
30+
#endif
31+
#ifdef SIGUNUSED
32+
SETUP_SIGNAL(SIGUNUSED);
33+
#endif
34+
35+
/* POSIX.1-1990, according to man 7 signal */
36+
SETUP_SIGNAL(SIGHUP);
37+
SETUP_SIGNAL(SIGINT);
38+
SETUP_SIGNAL(SIGQUIT);
39+
SETUP_SIGNAL(SIGILL);
40+
SETUP_SIGNAL(SIGABRT);
41+
SETUP_SIGNAL(SIGFPE);
42+
SETUP_SIGNAL(SIGKILL);
43+
SETUP_SIGNAL(SIGSEGV);
44+
SETUP_SIGNAL(SIGPIPE);
45+
SETUP_SIGNAL(SIGALRM);
46+
SETUP_SIGNAL(SIGTERM);
47+
SETUP_SIGNAL(SIGUSR1);
48+
SETUP_SIGNAL(SIGUSR2);
49+
SETUP_SIGNAL(SIGCHLD);
50+
SETUP_SIGNAL(SIGCONT);
51+
SETUP_SIGNAL(SIGSTOP);
52+
SETUP_SIGNAL(SIGTSTP);
53+
SETUP_SIGNAL(SIGTTIN);
54+
SETUP_SIGNAL(SIGTTOU);
55+
56+
/* POSIX.1-2001, according to man 7 signal */
57+
SETUP_SIGNAL(SIGBUS);
58+
/* Some Operating Systems doesn't have SIGPOLL (e.g. FreeBSD) */
59+
#ifdef SIGPOLL
60+
SETUP_SIGNAL(SIGPOLL);
61+
#endif
62+
SETUP_SIGNAL(SIGPROF);
63+
SETUP_SIGNAL(SIGSYS);
64+
SETUP_SIGNAL(SIGTRAP);
65+
SETUP_SIGNAL(SIGURG);
66+
SETUP_SIGNAL(SIGVTALRM);
67+
SETUP_SIGNAL(SIGXCPU);
68+
SETUP_SIGNAL(SIGXFSZ);

0 commit comments

Comments
 (0)