aboutsummaryrefslogtreecommitdiffstats
path: root/gawkapi.h
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2014-04-11 07:44:22 +0300
committerArnold D. Robbins <arnold@skeeve.com>2014-04-11 07:44:22 +0300
commitebb6772e9eabeb81e3cc9305a6bec7adf7aad450 (patch)
tree2cf743f82791db19cc7e31cab86b1fc9a4d5ddbb /gawkapi.h
parente069c636968370f0899d5e4ebaeb9c2341804245 (diff)
parenta4b59faf911743b30f2e6e979c4f9c1ea0669ac3 (diff)
downloadegawk-ebb6772e9eabeb81e3cc9305a6bec7adf7aad450.tar.gz
egawk-ebb6772e9eabeb81e3cc9305a6bec7adf7aad450.tar.bz2
egawk-ebb6772e9eabeb81e3cc9305a6bec7adf7aad450.zip
Merge branch 'master' into comment
Diffstat (limited to 'gawkapi.h')
-rw-r--r--gawkapi.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/gawkapi.h b/gawkapi.h
index b26ee24c..5ccadc21 100644
--- a/gawkapi.h
+++ b/gawkapi.h
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 2012, 2013 the Free Software Foundation, Inc.
+ * Copyright (C) 2012-2014 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -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)