Skip to content

Commit

Permalink
#74 fix issue with redefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Oct 23, 2021
1 parent 74d2aed commit 2d1cc9b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions include/ravi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@

#include <stdlib.h>

typedef struct Ravi_MemoryAllocatorInterface {
#ifndef C_MEMORYALLOCATOR_DEFINED
#define C_MEMORYALLOCATOR_DEFINED
typedef struct C_MemoryAllocator {
void *arena;
void *(*realloc)(void *arena, void* mem, size_t newsize);
void *(*calloc)(void *arena, size_t n_elements, size_t elem_size);
void (*free)(void *arena, void *p);
} Ravi_MemoryAllocatorInterface;
} C_MemoryAllocator;
#endif

typedef struct Ravi_CompilerInterface {
/* ------------------------ Inputs ------------------------------ */
Expand All @@ -46,7 +49,7 @@ typedef struct Ravi_CompilerInterface {

char main_func_name[31]; /* Name of the generated function that when called will set up the Lua closure */

Ravi_MemoryAllocatorInterface *memory_allocator;
C_MemoryAllocator *memory_allocator;

/* ------------------------- Outputs ------------------------------ */
const char* generated_code; /* Output of the compiler, must be freed by caller. */
Expand Down
6 changes: 4 additions & 2 deletions src/chibicc/chibicc.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ typedef struct C_Member C_Member;
typedef struct C_Relocation C_Relocation;
typedef struct C_Hideset C_Hideset;
typedef struct C_Parser C_Parser;
typedef struct C_MemoryAllocator C_MemoryAllocator;

#ifndef C_MEMORYALLOCATOR_DEFINED
#define C_MEMORYALLOCATOR_DEFINED
typedef struct C_MemoryAllocator C_MemoryAllocator;
struct C_MemoryAllocator {
void *arena;
void *(*realloc)(void *arena, void* mem, size_t newsize);
void *(*calloc)(void *arena, size_t n_elements, size_t elem_size);
void (*free)(void *arena, void *p);
};

#endif

//
// strings.c
Expand Down

0 comments on commit 2d1cc9b

Please sign in to comment.