1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Ensure constants are constant

Contributed by STMicroelectronics

Change-Id: I3ceecdba0bcf5715ce0c4f683fd3fdb9b86ad8b3
Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
This commit is contained in:
Torbjörn Svensson 2021-10-18 20:04:10 +02:00
parent 69448337e5
commit e4c46094b1
6 changed files with 73 additions and 39 deletions

View file

@ -7,6 +7,18 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#undef org_eclipse_cdt_utils_spawner_Spawner_SIG_NOOP
#define org_eclipse_cdt_utils_spawner_Spawner_SIG_NOOP 0L
#undef org_eclipse_cdt_utils_spawner_Spawner_SIG_HUP
#define org_eclipse_cdt_utils_spawner_Spawner_SIG_HUP 1L
#undef org_eclipse_cdt_utils_spawner_Spawner_SIG_KILL
#define org_eclipse_cdt_utils_spawner_Spawner_SIG_KILL 9L
#undef org_eclipse_cdt_utils_spawner_Spawner_SIG_TERM
#define org_eclipse_cdt_utils_spawner_Spawner_SIG_TERM 15L
#undef org_eclipse_cdt_utils_spawner_Spawner_SIG_INT
#define org_eclipse_cdt_utils_spawner_Spawner_SIG_INT 2L
#undef org_eclipse_cdt_utils_spawner_Spawner_SIG_CTRLC
#define org_eclipse_cdt_utils_spawner_Spawner_SIG_CTRLC 1000L
/* /*
* Class: org_eclipse_cdt_utils_spawner_Spawner * Class: org_eclipse_cdt_utils_spawner_Spawner
* Method: exec0 * Method: exec0

View file

@ -228,28 +228,28 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise(JNIEnv *
int status = -1; int status = -1;
switch (sig) { switch (sig) {
case 0: /* NOOP */ case org_eclipse_cdt_utils_spawner_Spawner_SIG_NOOP:
status = killpg(pid, 0); status = killpg(pid, 0);
if (status == -1) { if (status == -1) {
status = kill(pid, 0); status = kill(pid, 0);
} }
break; break;
case 2: /* INTERRUPT */ case org_eclipse_cdt_utils_spawner_Spawner_SIG_INT:
status = killpg(pid, SIGINT); status = killpg(pid, SIGINT);
if (status == -1) { if (status == -1) {
status = kill(pid, SIGINT); status = kill(pid, SIGINT);
} }
break; break;
case 9: /* KILL */ case org_eclipse_cdt_utils_spawner_Spawner_SIG_KILL:
status = killpg(pid, SIGKILL); status = killpg(pid, SIGKILL);
if (status == -1) { if (status == -1) {
status = kill(pid, SIGKILL); status = kill(pid, SIGKILL);
} }
break; break;
case 15: /* TERM */ case org_eclipse_cdt_utils_spawner_Spawner_SIG_TERM:
status = killpg(pid, SIGTERM); status = killpg(pid, SIGTERM);
if (status == -1) { if (status == -1) {
status = kill(pid, SIGTERM); status = kill(pid, SIGTERM);
@ -257,9 +257,9 @@ JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_spawner_Spawner_raise(JNIEnv *
break; break;
default: default:
status = killpg(pid, sig); /* WHAT ?? */ status = killpg(pid, sig);
if (status == -1) { if (status == -1) {
status = kill(pid, sig); /* WHAT ?? */ status = kill(pid, sig);
} }
break; break;
} }

View file

@ -78,16 +78,6 @@ static void cleanUpProcBlock(pProcInfo_t pCurProcInfo);
int interruptProcess(int pid); int interruptProcess(int pid);
// Signal codes
typedef enum {
SIG_NOOP, //
SIG_HUP, //
SIG_INT, //
SIG_KILL = 9, //
SIG_TERM = 15, //
CTRLC = 1000 // special, Windows only. Sends CTRL-C in all cases, even when inferior is a Cygwin program
} signals;
extern CRITICAL_SECTION cs; extern CRITICAL_SECTION cs;
extern wchar_t path[MAX_PATH]; // Directory where spawner.dll is located extern wchar_t path[MAX_PATH]; // Directory where spawner.dll is located
@ -619,7 +609,7 @@ extern "C"
pProcInfo_t pCurProcInfo = findProcInfo(uid); pProcInfo_t pCurProcInfo = findProcInfo(uid);
if (!pCurProcInfo) { if (!pCurProcInfo) {
if (SIG_INT == signal) { // Try another way if (org_eclipse_cdt_utils_spawner_Spawner_SIG_INT == signal) { // Try another way
return interruptProcess(uid); return interruptProcess(uid);
} }
return -1; return -1;
@ -636,15 +626,15 @@ extern "C"
} }
switch (signal) { switch (signal) {
case SIG_NOOP: case org_eclipse_cdt_utils_spawner_Spawner_SIG_NOOP:
// Wait 0 msec -just check if the process has been still running // Wait 0 msec -just check if the process has been still running
ret = ((WAIT_TIMEOUT == WaitForSingleObject(hProc, 0)) ? 0 : -1); ret = ((WAIT_TIMEOUT == WaitForSingleObject(hProc, 0)) ? 0 : -1);
break; break;
case SIG_HUP: case org_eclipse_cdt_utils_spawner_Spawner_SIG_HUP:
// Temporary do nothing // Temporary do nothing
ret = 0; ret = 0;
break; break;
case SIG_TERM: case org_eclipse_cdt_utils_spawner_Spawner_SIG_TERM:
if (isTraceEnabled(CDT_TRACE_SPAWNER)) { if (isTraceEnabled(CDT_TRACE_SPAWNER)) {
cdtTrace(L"Spawner received TERM signal for process %i\n", pCurProcInfo->pid); cdtTrace(L"Spawner received TERM signal for process %i\n", pCurProcInfo->pid);
} }
@ -655,7 +645,7 @@ extern "C"
ret = 0; ret = 0;
break; break;
case SIG_KILL: case org_eclipse_cdt_utils_spawner_Spawner_SIG_KILL:
if (isTraceEnabled(CDT_TRACE_SPAWNER)) { if (isTraceEnabled(CDT_TRACE_SPAWNER)) {
cdtTrace(L"Spawner received KILL signal for process %i\n", pCurProcInfo->pid); cdtTrace(L"Spawner received KILL signal for process %i\n", pCurProcInfo->pid);
} }
@ -665,12 +655,12 @@ extern "C"
} }
ret = 0; ret = 0;
break; break;
case SIG_INT: case org_eclipse_cdt_utils_spawner_Spawner_SIG_INT:
ResetEvent(pCurProcInfo->eventWait.handle); ResetEvent(pCurProcInfo->eventWait.handle);
SetEvent(pCurProcInfo->eventBreak.handle); SetEvent(pCurProcInfo->eventBreak.handle);
ret = (WaitForSingleObject(pCurProcInfo->eventWait.handle, 100) == WAIT_OBJECT_0); ret = (WaitForSingleObject(pCurProcInfo->eventWait.handle, 100) == WAIT_OBJECT_0);
break; break;
case CTRLC: case org_eclipse_cdt_utils_spawner_Spawner_SIG_CTRLC:
ResetEvent(pCurProcInfo->eventWait.handle); ResetEvent(pCurProcInfo->eventWait.handle);
SetEvent(pCurProcInfo->eventCtrlc.handle); SetEvent(pCurProcInfo->eventCtrlc.handle);
ret = (WaitForSingleObject(pCurProcInfo->eventWait.handle, 100) == WAIT_OBJECT_0); ret = (WaitForSingleObject(pCurProcInfo->eventWait.handle, 100) == WAIT_OBJECT_0);

View file

@ -29,10 +29,31 @@ import org.eclipse.osgi.util.NLS;
public class Spawner extends Process { public class Spawner extends Process {
public int NOOP = 0; @Deprecated(forRemoval = true)
public int HUP = 1; public int NOOP = SIG_NOOP;
public int KILL = 9;
public int TERM = 15; @Deprecated(forRemoval = true)
public int HUP = SIG_HUP;
@Deprecated(forRemoval = true)
public int KILL = SIG_KILL;
@Deprecated(forRemoval = true)
public int TERM = SIG_TERM;
@Deprecated(forRemoval = true)
public int INT = SIG_INT;
/**
* @since 5.2
*/
@Deprecated(forRemoval = true)
public int CTRLC = SIG_CTRLC;
private final static int SIG_NOOP = 0;
private final static int SIG_HUP = 1;
private final static int SIG_KILL = 9;
private final static int SIG_TERM = 15;
/** /**
* On Windows, what this does is far from easy to explain. * On Windows, what this does is far from easy to explain.
@ -51,17 +72,14 @@ public class Spawner extends Process {
* </ul> * </ul>
* *
* On non-Windows, raising this just raises a POSIX SIGINT * On non-Windows, raising this just raises a POSIX SIGINT
*
*/ */
public int INT = 2; private final static int SIG_INT = 2;
/** /**
* A fabricated signal number for use on Windows only. Tells the starter program to send a CTRL-C * A fabricated signal number for use on Windows only. Tells the starter program to send a CTRL-C
* regardless of whether the process is a Cygwin one or not. * regardless of whether the process is a Cygwin one or not.
*
* @since 5.2
*/ */
public int CTRLC = 1000; // arbitrary high number to avoid collision private final static int SIG_CTRLC = 1000; // arbitrary high number to avoid collision
int pid = 0; int pid = 0;
int status; int status;
@ -323,7 +341,7 @@ public class Spawner extends Process {
* linux, interrupt it by raising a SIGINT. * linux, interrupt it by raising a SIGINT.
*/ */
public int interrupt() { public int interrupt() {
return raise(pid, INT); return raise(pid, SIG_INT);
} }
/** /**
@ -334,26 +352,26 @@ public class Spawner extends Process {
*/ */
public int interruptCTRLC() { public int interruptCTRLC() {
if (Platform.getOS().equals(Platform.OS_WIN32)) { if (Platform.getOS().equals(Platform.OS_WIN32)) {
return raise(pid, CTRLC); return raise(pid, SIG_CTRLC);
} else { } else {
return interrupt(); return interrupt();
} }
} }
public int hangup() { public int hangup() {
return raise(pid, HUP); return raise(pid, SIG_HUP);
} }
public int kill() { public int kill() {
return raise(pid, KILL); return raise(pid, SIG_KILL);
} }
public int terminate() { public int terminate() {
return raise(pid, TERM); return raise(pid, SIG_TERM);
} }
public boolean isRunning() { public boolean isRunning() {
return (raise(pid, NOOP) == 0); return (raise(pid, SIG_NOOP) == 0);
} }
private void exec(String[] cmdarray, String[] envp, String dirpath) throws IOException { private void exec(String[] cmdarray, String[] envp, String dirpath) throws IOException {

View file

@ -68,6 +68,7 @@
</p> </p>
<ol> <ol>
<li><a href="#GnuMakefileGeneratorAPI">GnuMakefileGenerator is no longer part of API</a></li> <li><a href="#GnuMakefileGeneratorAPI">GnuMakefileGenerator is no longer part of API</a></li>
<li><a href="#Spawner.signals">The Spawner signal constants are nolonger API</a></li>
</ol> </ol>
<p> <p>
@ -500,7 +501,7 @@
<h3>1. <a name="GnuMakefileGeneratorAPI">GnuMakefileGenerator is no longer part of API</a></h3> <h3>1. <a name="GnuMakefileGeneratorAPI">GnuMakefileGenerator is no longer part of API</a></h3>
<p> <p>
The following classes have been removed from the API. The following classes will be removed from the API.
</p> </p>
<ul> <ul>
<li>org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator</li> <li>org.eclipse.cdt.managedbuilder.makegen.gnu.GnuMakefileGenerator</li>
@ -510,6 +511,19 @@
<p> <p>
See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=505882" target="_blank">Bug 505882</a>. See <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=505882" target="_blank">Bug 505882</a>.
</p> </p>
<h3>2. <a name="Spawner.signals">The Spawner signal constants are nolonger API</a></h3>
<p>
The following constants will be removed from the Spawner API.
</p>
<ul>
<li>NOOP</li>
<li>HUP</li>
<li>KILL</li>
<li>TERM</li>
<li>INT</li>
<li>CTRLC</li>
</ul>
</body> </body>
</html> </html>