[PATCH] mini-gmp: pass correct old_size to custom reallocate function

minux minux.ma at gmail.com
Thu Mar 12 19:55:33 UTC 2020


On Thu, Mar 12, 2020 at 3:19 PM Niels Möller <nisse at lysator.liu.se> wrote:
> minux <minux.ma at gmail.com> writes:
> > Indeed, this is much simpler and avoids the risk of calling
> > strlen(NULL). Thanks.
> >
> > Patch updated. Please take another look.
>
> Looks good to me. I was about to submit, but then I have one minor
> question about naming.
>
> >  #define gmp_xalloc(size) ((*gmp_allocate_func)((size)))
> > -#define gmp_free(p) ((*gmp_free_func) ((p), 0))
> > +#define gmp_xfree(p, size) ((*gmp_free_func) ((p), (size)))
> > +#define gmp_xrealloc(ptr, old_size, size) ((*gmp_reallocate_func)(ptr, old_size, size))
>
> Here, "xalloc" is the traditional name (at least in GNU code, another
> name is xmalloc) for an allocation function that will crash with an
> error message on failure, rather than returning NULL. The name
> gmp_xalloc in mini-gmp most likely dates from before support for
> get_set_memory_functions was added, and then it did the same thing as
> the current gmp_default_alloc, with no indirection.
>
> The xrealloc function is analogous (but maybe not as widely used as
> xalloc). On the other hand, I don't know of any traditional function
> named xfree. So maybe the least confusing naming is to strike "x" from
> all the names (six in all, including the _limbs variants)?

patch updated. I actually had this question while making changes. But
I took advantage of the naming convention to use gmp_xfree for the
two-parameter version so that I do not have to fix all use of
one-parameter gmp_free in one pass. And then for consistency, I also
renamed realloc to xrealloc.

Thanks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mini-gmp.patch
Type: application/octet-stream
Size: 12846 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20200312/d71249e0/attachment-0001.obj>


More information about the gmp-devel mailing list