Permalink
Browse files

misc: Renamed structs with eponymous typedefs

This is an issue in a CPP context, as both typedefs and structs
share the same identifier space.
  • Loading branch information...
dcarlier-afilias authored and Snaipe committed Sep 5, 2017
1 parent d3fe1d4 commit c99f5279bba41b2dcf1826daa5daa23d08b0b5ee
Showing with 41 additions and 33 deletions.
  1. +21 −13 include/boxfort.h
  2. +7 −7 src/arena.c
  3. +1 −1 src/arena.h
  4. +2 −2 src/context.c
  5. +1 −1 src/context.h
  6. +2 −2 src/sandbox-posix.c
  7. +1 −1 src/sandbox-posix.h
  8. +2 −2 src/sandbox-windows.c
  9. +1 −1 src/sandbox-windows.h
  10. +1 −1 src/sandbox.c
  11. +2 −2 src/timeout-windows.c
@@ -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
@@ -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 {
/**
@@ -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);

@@ -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;

@@ -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;
@@ -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;
@@ -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);

@@ -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_ */
@@ -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;) {
@@ -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;) {
@@ -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;
@@ -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;
@@ -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)
@@ -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;

@@ -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;
@@ -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;
@@ -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;
@@ -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)
{
@@ -27,7 +27,7 @@
#include "addr.h"
#include "arena.h"

struct bxf_context {
struct bxf_context_s {
bxf_arena arena;
};

@@ -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,
@@ -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,
};
@@ -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. */
@@ -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;

@@ -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,
@@ -44,7 +44,7 @@ struct bxfi_map {
};

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

@@ -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;

@@ -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,
@@ -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;
}

0 comments on commit c99f527

Please sign in to comment.