Skip to content

Commit

Permalink
misc: Renamed structs with eponymous typedefs
Browse files Browse the repository at this point in the history
This is an issue in a CPP context, as both typedefs and structs
share the same identifier space.
  • Loading branch information
David Carlier authored and Snaipe committed Oct 10, 2017
1 parent d3fe1d4 commit c99f527
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 33 deletions.
34 changes: 21 additions & 13 deletions include/boxfort.h
Expand Up @@ -29,6 +29,10 @@
#include <math.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#if !defined BXF_STATIC_LIB && !defined BXF_API
# if defined _WIN32 || defined __CYGWIN__
# ifdef BXF_BUILDING_LIB
Expand Down Expand Up @@ -60,7 +64,7 @@
/**
* The opaque handle type representing a BoxFort memory arena.
*/
typedef struct bxf_arena *bxf_arena;
typedef struct bxf_arena_s *bxf_arena;

enum {
/**
Expand Down Expand Up @@ -139,7 +143,7 @@ typedef void *bxf_fhandle;
typedef int bxf_fhandle;
#endif

typedef struct bxf_context *bxf_context;
typedef struct bxf_context_s *bxf_context;

BXF_API int bxf_context_init(bxf_context *ctx);

Expand Down Expand Up @@ -221,13 +225,13 @@ struct bxf_debug {
struct bxf_inheritance inherit; \
struct bxf_debug debug;

struct bxf_sandbox {
struct bxf_sandbox_s {
BXFI_SANDBOX_FIELDS
};

typedef const struct bxf_sandbox bxf_sandbox;
typedef const struct bxf_sandbox_s bxf_sandbox;

struct bxf_instance {
struct bxf_instance_s {
bxf_sandbox *sandbox;
bxf_pid pid;

Expand All @@ -248,13 +252,13 @@ struct bxf_instance {
void *user;
};

typedef const struct bxf_instance bxf_instance;
typedef const struct bxf_instance_s bxf_instance;

typedef void (bxf_callback)(bxf_instance *);
typedef int (bxf_preexec)(bxf_instance *);
typedef void (bxf_dtor)(bxf_instance *, void *);

struct bxf_spawn_params {
struct bxf_spawn_params_s {
int bxfi_sentinel_; /* Reserved */
bxf_fn *fn;
bxf_preexec *preexec;
Expand All @@ -264,9 +268,9 @@ struct bxf_spawn_params {
BXFI_SANDBOX_FIELDS
};

typedef const struct bxf_spawn_params *bxf_spawn_params;
typedef const struct bxf_spawn_params_s *bxf_spawn_params;

struct bxf_start_params {
struct bxf_start_params_s {
int bxfi_sentinel_; /* Reserved */
bxf_fn *fn;
bxf_preexec *preexec;
Expand All @@ -277,12 +281,12 @@ struct bxf_start_params {

#define BXF_FOREVER INFINITY

typedef const struct bxf_start_params *bxf_start_params;
typedef const struct bxf_start_params_s *bxf_start_params;

#define bxf_start(Instance, Sandbox, ...) \
(bxf_start_struct((Instance), \
(Sandbox), \
&(struct bxf_start_params) { .bxfi_sentinel_ = 0, __VA_ARGS__ }))
&(struct bxf_start_params_s) { .bxfi_sentinel_ = 0, __VA_ARGS__ }))
BXF_API int bxf_start_struct(bxf_instance **instance,
bxf_sandbox *sandbox, bxf_start_params params);

Expand All @@ -291,15 +295,19 @@ BXF_API int bxf_wait(bxf_instance *instance, double timeout);

#define bxf_spawn(Instance, ...) \
(bxf_spawn_struct((Instance), \
&(struct bxf_spawn_params) { .bxfi_sentinel_ = 0, __VA_ARGS__ }))
&(struct bxf_spawn_params_s) { .bxfi_sentinel_ = 0, __VA_ARGS__ }))
BXF_API int bxf_spawn_struct(bxf_instance **instance, bxf_spawn_params params);

#define bxf_run(...) \
(bxf_run_struct( \
&(struct bxf_spawn_params) { .bxfi_sentinel_ = 0, __VA_ARGS__ }))
&(struct bxf_spawn_params_s) { .bxfi_sentinel_ = 0, __VA_ARGS__ }))
BXF_API int bxf_run_struct(bxf_spawn_params params);

BXF_API void bxf_suspend(bxf_instance *instance);
BXF_API void bxf_resume(bxf_instance *instance);

#ifdef __cplusplus
}
#endif

#endif /* !BOXFORT_H_ */
14 changes: 7 additions & 7 deletions src/arena.c
Expand Up @@ -138,7 +138,7 @@ int bxf_arena_init(size_t initial, int flags, bxf_arena *arena)
mmap_seed = bxfi_timestamp_monotonic();

intptr_t r;
struct bxf_arena *a;
struct bxf_arena_s *a;
int tries = 0;

for (tries = 0; tries < MAP_RETRIES;) {
Expand Down Expand Up @@ -224,7 +224,7 @@ retry: ;
mmap_seed = bxfi_timestamp_monotonic();

intptr_t r;
struct bxf_arena *a;
struct bxf_arena_s *a;
int tries = 0;

for (tries = 0; tries < MAP_RETRIES;) {
Expand Down Expand Up @@ -315,7 +315,7 @@ int bxfi_arena_inherit(bxf_fhandle hndl, int flags, bxf_arena *arena)
else
prot = FILE_MAP_COPY;

struct bxf_arena *a = MapViewOfFile(hndl, prot, 0, 0, sizeof (*a));
struct bxf_arena_s *a = MapViewOfFile(hndl, prot, 0, 0, sizeof (*a));

if (!a)
return -ENOMEM;
Expand All @@ -335,7 +335,7 @@ int bxfi_arena_inherit(bxf_fhandle hndl, int flags, bxf_arena *arena)
if (!(flags & BXF_ARENA_IMMUTABLE))
prot |= PROT_WRITE;

struct bxf_arena *a = mmap(NULL, sizeof (*a), prot, MAP_PRIVATE, hndl, 0);
struct bxf_arena_s *a = mmap(NULL, sizeof (*a), prot, MAP_PRIVATE, hndl, 0);

if (a == MAP_FAILED)
return -errno;
Expand Down Expand Up @@ -406,7 +406,7 @@ static int arena_resize(bxf_arena *arena, size_t newsize)
return -ENOMEM;

FlushViewOfFile(*arena, size);
struct bxf_arena *a = MapViewOfFile((*arena)->handle, FILE_MAP_WRITE,
struct bxf_arena_s *a = MapViewOfFile((*arena)->handle, FILE_MAP_WRITE,
0, 0, newsize);

if (!a)
Expand All @@ -429,7 +429,7 @@ static int arena_resize(bxf_arena *arena, size_t newsize)
# if defined (HAVE_MREMAP)
int flags = (*arena)->flags & BXF_ARENA_MAYMOVE ? MREMAP_MAYMOVE : 0;

struct bxf_arena *a = mremap(*arena, (*arena)->size, newsize, flags);
struct bxf_arena_s *a = mremap(*arena, (*arena)->size, newsize, flags);
if (a == MAP_FAILED)
return -errno;

Expand All @@ -451,7 +451,7 @@ static int arena_resize(bxf_arena *arena, size_t newsize)
return -ENOMEM;

msync(*arena, (*arena)->size, MS_SYNC);
struct bxf_arena *a = mmap(*arena, newsize, PROT_READ | PROT_WRITE,
struct bxf_arena_s *a = mmap(*arena, newsize, PROT_READ | PROT_WRITE,
MAP_SHARED, (*arena)->handle, 0);
if (a == MAP_FAILED)
return -ENOMEM;
Expand Down
2 changes: 1 addition & 1 deletion src/arena.h
Expand Up @@ -52,7 +52,7 @@ struct bxfi_arena_chunk {
# endif
#endif

struct bxf_arena {
struct bxf_arena_s {
void *addr;
size_t size;
intptr_t free_chunks;
Expand Down
4 changes: 2 additions & 2 deletions src/context.c
Expand Up @@ -41,7 +41,7 @@

int bxf_context_init(bxf_context *ctx)
{
struct bxf_context *nctx = malloc(sizeof (*nctx));
struct bxf_context_s *nctx = malloc(sizeof (*nctx));

if (!nctx)
return -ENOMEM;
Expand Down Expand Up @@ -382,7 +382,7 @@ static int inherit_elt(void *ptr, size_t size, void *user)
return 0;
}

static struct bxf_context current_ctx;
static struct bxf_context_s current_ctx;

int bxfi_context_inherit(struct bxfi_ctx_arena *ctx)
{
Expand Down
2 changes: 1 addition & 1 deletion src/context.h
Expand Up @@ -27,7 +27,7 @@
#include "addr.h"
#include "arena.h"

struct bxf_context {
struct bxf_context_s {
bxf_arena arena;
};

Expand Down
4 changes: 2 additions & 2 deletions src/sandbox-posix.c
Expand Up @@ -683,7 +683,7 @@ int bxfi_exec(bxf_instance **out, bxf_sandbox *sandbox,
instance->start_monotonic = bxfi_timestamp_monotonic();
instance->wait_pid = pid;

instance->props = (struct bxf_instance) {
instance->props = (struct bxf_instance_s) {
.sandbox = sandbox,
.pid = pid,
.status.alive = 1,
Expand Down Expand Up @@ -773,7 +773,7 @@ int bxfi_exec(bxf_instance **out, bxf_sandbox *sandbox,

pid = getpid();

instance->props = (struct bxf_instance) {
instance->props = (struct bxf_instance_s) {
.sandbox = sandbox,
.pid = pid,
};
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox-posix.h
Expand Up @@ -47,7 +47,7 @@ struct bxfi_map {
};

struct bxfi_sandbox {
struct bxf_instance props;
struct bxf_instance_s props;

/* A sandbox is said to be mantled if there is an unique instance
managing its memory. */
Expand Down
4 changes: 2 additions & 2 deletions src/sandbox-windows.c
Expand Up @@ -167,7 +167,7 @@ struct callback_ctx {
* be directly translated to translate to SIGSYS.
*
*/
static void get_status(HANDLE handle, struct bxf_instance *instance)
static void get_status(HANDLE handle, struct bxf_instance_s *instance)
{
DWORD exit_code;

Expand Down Expand Up @@ -498,7 +498,7 @@ int bxfi_exec(bxf_instance **out, bxf_sandbox *sandbox,
if (si.lpAttributeList)
DeleteProcThreadAttributeList(si.lpAttributeList);

instance->props = (struct bxf_instance) {
instance->props = (struct bxf_instance_s) {
.sandbox = sandbox,
.pid = info.dwProcessId,
.status.alive = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/sandbox-windows.h
Expand Up @@ -44,7 +44,7 @@ struct bxfi_map {
};

struct bxfi_sandbox {
struct bxf_instance props;
struct bxf_instance_s props;
HANDLE proc;
HANDLE mainthread;

Expand Down
2 changes: 1 addition & 1 deletion src/sandbox.c
Expand Up @@ -72,7 +72,7 @@ int bxf_spawn_struct(bxf_instance **out, bxf_spawn_params params)
if (!params->fn)
return -EINVAL;

struct bxf_sandbox *sandbox = calloc(1, sizeof (*sandbox));
struct bxf_sandbox_s *sandbox = calloc(1, sizeof (*sandbox));
if (!sandbox)
return -ENOMEM;

Expand Down
4 changes: 2 additions & 2 deletions src/timeout-windows.c
Expand Up @@ -42,7 +42,7 @@ void CALLBACK timeout_killer_fn(void *lpParameter, BOOLEAN TimerOrWaitFired)
sb->props.status.timed_out = 1;
}

int bxfi_push_timeout(struct bxfi_sandbox *instance, double timeout)
int bxfi_push_timeout(struct bxfi_sandbox_s *instance, double timeout)
{
HANDLE timer;
BOOL ok = CreateTimerQueueTimer(&timer, NULL, timeout_killer_fn, instance,
Expand All @@ -53,7 +53,7 @@ int bxfi_push_timeout(struct bxfi_sandbox *instance, double timeout)
return 0;
}

void bxfi_cancel_timeout(struct bxfi_sandbox *instance)
void bxfi_cancel_timeout(struct bxfi_sandbox_s *instance)
{
(void) instance;
}
Expand Down

0 comments on commit c99f527

Please sign in to comment.