scratch: rename `max_size` to `size`, document that extra will actually be allocated

This commit is contained in:
Andrew Poelstra 2019-03-14 14:41:03 +00:00
parent 5a4bc0bb95
commit a7a164f2c6
2 changed files with 6 additions and 5 deletions

View File

@ -285,11 +285,12 @@ SECP256K1_API void secp256k1_context_set_error_callback(
* *
* Returns: a newly created scratch space. * Returns: a newly created scratch space.
* Args: ctx: an existing context object (cannot be NULL) * Args: ctx: an existing context object (cannot be NULL)
* In: max_size: maximum amount of memory to allocate * In: size: amount of memory to be available as scratch space. Some extra
* (<100 bytes) will be allocated for extra accounting.
*/ */
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space* secp256k1_scratch_space_create( SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space* secp256k1_scratch_space_create(
const secp256k1_context* ctx, const secp256k1_context* ctx,
size_t max_size size_t size
) SECP256K1_ARG_NONNULL(1); ) SECP256K1_ARG_NONNULL(1);
/** Destroy a secp256k1 scratch space. /** Destroy a secp256k1 scratch space.

View File

@ -10,15 +10,15 @@
#include "util.h" #include "util.h"
#include "scratch.h" #include "scratch.h"
static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t max_size) { static secp256k1_scratch* secp256k1_scratch_create(const secp256k1_callback* error_callback, size_t size) {
const size_t base_alloc = ((sizeof(secp256k1_scratch) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT; const size_t base_alloc = ((sizeof(secp256k1_scratch) + ALIGNMENT - 1) / ALIGNMENT) * ALIGNMENT;
void *alloc = checked_malloc(error_callback, base_alloc + max_size); void *alloc = checked_malloc(error_callback, base_alloc + size);
secp256k1_scratch* ret = (secp256k1_scratch *)alloc; secp256k1_scratch* ret = (secp256k1_scratch *)alloc;
if (ret != NULL) { if (ret != NULL) {
memset(ret, 0, sizeof(*ret)); memset(ret, 0, sizeof(*ret));
memcpy(ret->magic, "scratch", 8); memcpy(ret->magic, "scratch", 8);
ret->data = (void *) ((char *) alloc + base_alloc); ret->data = (void *) ((char *) alloc + base_alloc);
ret->max_size = max_size; ret->max_size = size;
} }
return ret; return ret;
} }