diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2014-03-08 22:13:53 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2014-03-08 22:13:53 +0200 |
commit | 23e7f1057b1abdebb25fc7d2f11ee3f5360976a4 (patch) | |
tree | cdd91edb34458798d5c0a65cd4c476b01fbf76ec /gawkapi.h | |
parent | 586bb71fdbeb5041263a3e48392d79c5931df3c4 (diff) | |
parent | c972e253abc34f8bd02f6ade74e7999a2b6d8a08 (diff) | |
download | egawk-23e7f1057b1abdebb25fc7d2f11ee3f5360976a4.tar.gz egawk-23e7f1057b1abdebb25fc7d2f11ee3f5360976a4.tar.bz2 egawk-23e7f1057b1abdebb25fc7d2f11ee3f5360976a4.zip |
Merge branch 'gawk-4.1-stable'
Diffstat (limited to 'gawkapi.h')
-rw-r--r-- | gawkapi.h | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -30,7 +30,6 @@ * * FILE - <stdio.h> * NULL - <stddef.h> - * malloc() - <stdlib.h> * memset(), memcpy() - <string.h> * size_t - <sys/types.h> * struct stat - <sys/stat.h> @@ -62,7 +61,7 @@ * * Additional important information: * - * 1. ALL string values in awk_value_t objects need to come from malloc(). + * 1. ALL string values in awk_value_t objects need to come from api_malloc(). * Gawk will handle releasing the storage if necessary. This is slightly * awkward, in that you can't take an awk_value_t that you got from gawk * and reuse it directly, even for something that is conceptually pass @@ -264,7 +263,7 @@ typedef struct awk_two_way_processor { /* Current version of the API. */ enum { GAWK_API_MAJOR_VERSION = 1, - GAWK_API_MINOR_VERSION = 0 + GAWK_API_MINOR_VERSION = 1 }; /* A number of typedefs related to different types of values. */ @@ -665,6 +664,16 @@ typedef struct gawk_api { awk_bool_t (*api_release_flattened_array)(awk_ext_id_t id, awk_array_t a_cookie, awk_flat_array_t *data); + + /* + * Hooks to provide access to gawk's memory allocation functions. + * This ensures that memory passed between gawk and the extension + * is allocated and released by the same library. + */ + void *(*api_malloc)(size_t size); + void *(*api_calloc)(size_t nmemb, size_t size); + void *(*api_realloc)(void *ptr, size_t size); + void (*api_free)(void *ptr); } gawk_api_t; #ifndef GAWK /* these are not for the gawk code itself! */ @@ -736,6 +745,11 @@ typedef struct gawk_api { #define release_flattened_array(array, data) \ (api->api_release_flattened_array(ext_id, array, data)) +#define gawk_malloc(size) (api->api_malloc(size)) +#define gawk_calloc(nmemb, size) (api->api_calloc(nmemb, size)) +#define gawk_realloc(ptr, size) (api->api_realloc(ptr, size)) +#define gawk_free(ptr) (api->api_free(ptr)) + #define create_value(value, result) \ (api->api_create_value(ext_id, value,result)) @@ -747,13 +761,13 @@ typedef struct gawk_api { #define emalloc(pointer, type, size, message) \ do { \ - if ((pointer = (type) malloc(size)) == 0) \ + if ((pointer = (type) gawk_malloc(size)) == 0) \ fatal(ext_id, "%s: malloc of %d bytes failed\n", message, size); \ } while(0) #define erealloc(pointer, type, size, message) \ do { \ - if ((pointer = (type) realloc(pointer, size)) == 0) \ + if ((pointer = (type) gawk_realloc(pointer, size)) == 0) \ fatal(ext_id, "%s: realloc of %d bytes failed\n", message, size); \ } while(0) |