Skip to content

Types pid_t and int are not always the same. #1411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use typedef instead of #define
  • Loading branch information
oicontrib committed Jul 26, 2020
commit f3b762a644a5f92ab4d85707bea85c403ebdb783
4 changes: 1 addition & 3 deletions include/CppUTest/CppUTestConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
#endif

#ifdef _cpputest_pid_t
#define PID_T _cpputest_pid_t
#else
#define PID_T pid_t
typedef _cpputest_pid_t pid_t;
#endif

/*
Expand Down
4 changes: 2 additions & 2 deletions include/CppUTest/PlatformSpecificFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment();

class TestPlugin;
extern void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result);
extern PID_T (*PlatformSpecificFork)(void);
extern PID_T (*PlatformSpecificWaitPid)(int pid, int* status, int options);
extern pid_t (*PlatformSpecificFork)(void);
extern pid_t (*PlatformSpecificWaitPid)(int pid, int* status, int options);

/* Platform specific interface we use in order to minimize dependencies with LibC.
* This enables porting to different embedded platforms.
Expand Down
18 changes: 9 additions & 9 deletions src/Platforms/Gcc/UtestPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, Test
result->addFailure(TestFailure(shell, "-p doesn't work on this platform, as it is lacking fork.\b"));
}

static PID_T PlatformSpecificForkImplementation(void)
static pid_t PlatformSpecificForkImplementation(void)
{
return 0;
}

static PID_T PlatformSpecificWaitPidImplementation(int, int*, int)
static pid_t PlatformSpecificWaitPidImplementation(int, int*, int)
{
return 0;
}
Expand All @@ -95,9 +95,9 @@ static void SetTestFailureByStatusCode(UtestShell* shell, TestResult* result, in

static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, TestPlugin* plugin, TestResult* result)
{
const PID_T syscallError = -1;
PID_T cpid;
PID_T w;
const pid_t syscallError = -1;
pid_t cpid;
pid_t w;
int status = 0;

cpid = PlatformSpecificFork();
Expand Down Expand Up @@ -136,12 +136,12 @@ static void GccPlatformSpecificRunTestInASeperateProcess(UtestShell* shell, Test
}
}

static PID_T PlatformSpecificForkImplementation(void)
static pid_t PlatformSpecificForkImplementation(void)
{
return fork();
}

static PID_T PlatformSpecificWaitPidImplementation(int pid, int* status, int options)
static pid_t PlatformSpecificWaitPidImplementation(int pid, int* status, int options)
{
return waitpid(pid, status, options);
}
Expand All @@ -155,8 +155,8 @@ TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment()

void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell* shell, TestPlugin* plugin, TestResult* result) =
GccPlatformSpecificRunTestInASeperateProcess;
PID_T (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation;
PID_T (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation;
pid_t (*PlatformSpecificFork)(void) = PlatformSpecificForkImplementation;
pid_t (*PlatformSpecificWaitPid)(int, int*, int) = PlatformSpecificWaitPidImplementation;

extern "C" {

Expand Down
8 changes: 4 additions & 4 deletions tests/CppUTest/UtestPlatformTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ static int waitpid_while_debugging_stub_forced_failures = 0;

extern "C" {

static PID_T (*original_waitpid)(int, int*, int) = NULLPTR;
static pid_t (*original_waitpid)(int, int*, int) = NULLPTR;

static PID_T fork_failed_stub(void) { return -1; }
static pid_t fork_failed_stub(void) { return -1; }

static PID_T waitpid_while_debugging_stub(int pid, int* status, int options)
static pid_t waitpid_while_debugging_stub(int pid, int* status, int options)
{
static int saved_status;

Expand All @@ -94,7 +94,7 @@ extern "C" {
}
}

static PID_T waitpid_failed_stub(int, int*, int) { return -1; }
static pid_t waitpid_failed_stub(int, int*, int) { return -1; }
}

#include <unistd.h>
Expand Down