diff --git a/mem.c b/mem.c index 8c27491..1431264 100644 --- a/mem.c +++ b/mem.c @@ -8,8 +8,8 @@ #include #include #include -#define XC_SHM_IMPL -#define XC_MEM_IMPL +#define XC_MEMBLOCK_IMPL _xc_mem_block_t +#define XC_MEM_IMPL _xc_mem_mem_t #include "xc_shm.h" #include "align.h" @@ -29,7 +29,7 @@ #define PSUB(p1, p2) (CHAR_PTR(p1) - CHAR_PTR(p2)) /* {{{ mem */ -struct _xc_block_t { +struct _xc_mem_block_t { #ifdef ALLOC_DEBUG_BLOCK_CHECK unsigned int magic; #endif @@ -37,7 +37,7 @@ struct _xc_block_t { xc_block_t *next; /* not used after alloc */ }; -struct _xc_mem_t { +struct _xc_mem_mem_t { const xc_mem_handlers_t *handlers; xc_shm_t *shm; xc_memsize_t size; diff --git a/mem.h b/mem.h index df630fb..9d35894 100644 --- a/mem.h +++ b/mem.h @@ -1,5 +1,18 @@ -typedef struct _xc_mem_t xc_mem_t; -typedef struct _xc_block_t xc_block_t; +typedef struct _xc_mem_handlers_t xc_mem_handlers_t; + +#ifndef XC_MEM_IMPL +struct _xc_mem_t { + const xc_mem_handlers_t *handlers; + xc_shm_t *shm; +}; +# define XC_MEM_IMPL _xc_mem_t +#endif + +#ifndef XC_MEMBLOCK_IMPL +# define XC_MEMBLOCK_IMPL _xc_block_t +#endif +typedef struct XC_MEM_IMPL xc_mem_t; +typedef struct XC_MEMBLOCK_IMPL xc_block_t; typedef unsigned int xc_memsize_t; /* shm::mem */ @@ -37,7 +50,7 @@ typedef unsigned int xc_memsize_t; , xc_##name##_destroy \ } -typedef struct { +struct _xc_mem_handlers_t { XC_MEM_MALLOC((*malloc)); XC_MEM_FREE((*free)); XC_MEM_CALLOC((*calloc)); @@ -53,14 +66,7 @@ typedef struct { XC_MEM_INIT((*init)); XC_MEM_DESTROY((*destroy)); -} xc_mem_handlers_t; - -#ifndef XC_MEM_IMPL -struct _xc_mem_t { - const xc_mem_handlers_t *handlers; - xc_shm_t *shm; }; -#endif int xc_mem_scheme_register(const char *name, const xc_mem_handlers_t *handlers); const xc_mem_handlers_t *xc_mem_scheme_find(const char *name); diff --git a/mmap.c b/mmap.c index 33f74ff..6f96338 100644 --- a/mmap.c +++ b/mmap.c @@ -31,7 +31,7 @@ #endif #include "php.h" -#define XC_SHM_IMPL +#define XC_SHM_IMPL _xc_mmap_shm_t #include "xc_shm.h" #ifndef max @@ -39,7 +39,7 @@ #endif /* {{{ xc_shm_t */ -struct _xc_shm_t { +struct _xc_mmap_shm_t { xc_shm_handlers_t *handlers; void *ptr; void *ptr_ro; diff --git a/xc_malloc.c b/xc_malloc.c index f79dccf..47b1112 100644 --- a/xc_malloc.c +++ b/xc_malloc.c @@ -1,5 +1,5 @@ -#define XC_SHM_IMPL -#define XC_MEM_IMPL +#define XC_SHM_IMPL _xc_malloc_shm_t +#define XC_MEM_IMPL _xc_malloc_mem_t #include #include #include @@ -7,7 +7,7 @@ #include "php.h" #include "align.h" -struct _xc_mem_t { +struct _xc_malloc_mem_t { const xc_mem_handlers_t *handlers; xc_shm_t *shm; xc_memsize_t size; @@ -105,8 +105,8 @@ static XC_MEM_DESTROY(xc_mem_malloc_destroy) /* {{{ */ } /* }}} */ -/* {{{ xc_shm_t */ -struct _xc_shm_t { +/* {{{ _xc_malloc_shm_t */ +struct _xc_malloc_shm_t { xc_shm_handlers_t *handlers; xc_shmsize_t size; xc_shmsize_t memoffset; diff --git a/xc_shm.h b/xc_shm.h index 1717e48..fb36d10 100644 --- a/xc_shm.h +++ b/xc_shm.h @@ -1,4 +1,13 @@ -typedef struct _xc_shm_t xc_shm_t; +typedef struct _xc_shm_handlers_t xc_shm_handlers_t; + +#ifndef XC_SHM_IMPL +struct _xc_shm_t { + const xc_shm_handlers_t *handlers; +}; +#define XC_SHM_IMPL _xc_shm_t +#endif + +typedef struct XC_SHM_IMPL xc_shm_t; typedef size_t xc_shmsize_t; #include "mem.h" @@ -31,7 +40,7 @@ typedef size_t xc_shmsize_t; , xc_##name##_memdestroy \ } -typedef struct { +struct _xc_shm_handlers_t { const xc_mem_handlers_t *memhandlers; XC_SHM_CAN_READONLY((*can_readonly)); XC_SHM_IS_READWRITE((*is_readwrite)); @@ -43,14 +52,8 @@ typedef struct { XC_SHM_MEMINIT((*meminit)); XC_SHM_MEMDESTROY((*memdestroy)); -} xc_shm_handlers_t; - - -#ifndef XC_SHM_IMPL -struct _xc_shm_t { - const xc_shm_handlers_t *handlers; }; -#endif + typedef struct _xc_shm_scheme_t xc_shm_scheme_t; void xc_shm_init_modules();