Skip to content

Commit

Permalink
Getting the metadata of a smart pointer will not change over time.
Browse files Browse the repository at this point in the history
  • Loading branch information
Snaipe committed Jan 14, 2015
1 parent 2a3deae commit 67fa1a7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/mman.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ INLINE static size_t align(size_t s) {
return (s + (sizeof (void *) - 1)) & ~(sizeof (void *) - 1);
}

__attribute__ ((pure))
INLINE static s_meta *get_meta(void *ptr) {
size_t *size = (size_t *) ptr - 1;
return (s_meta *) ((char *) size - *size - sizeof (s_meta));
}

__attribute__ ((pure))
void *get_smart_ptr_meta(void *ptr) {
assert((size_t) ptr == align((size_t) ptr));

Expand Down
1 change: 1 addition & 0 deletions src/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef struct {

extern s_allocator smalloc_allocator;

__attribute__ ((pure))
void *get_smart_ptr_meta(void *ptr);
void *sref(void *ptr);
__attribute__((malloc))
Expand Down

0 comments on commit 67fa1a7

Please sign in to comment.