[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/8] xalloc: new function xreallocarray

From: Paul Eggert
Subject: Re: [PATCH 4/8] xalloc: new function xreallocarray
Date: Tue, 19 Oct 2021 16:49:45 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0

On 4/21/21 17:18, Bruno Haible wrote:
xnmalloc and XNMALLOC take 2 arguments, whereas xreallocarray takes 3
arguments. It is often possible to express a function with a simple
interface as a special case of a more complex function. If, in many
use-cases, the simpler function is sufficient, users should not be
forced to understand the more complex function.

Good point. Also, xnmalloc enables better static checking, as it has __attribute__ ((__malloc__)), __attribute__ ((__malloc__ (free, 1))), and __attribute__ ((__returns_nonnull__)), whereas xreallocarray doesn't have these.

I noticed this when converting GNU diffutils to use ximalloc etc, and this this convinced me to add xinmalloc, by installing the attached patch. I plan to use this in GNU diffutils and probably other apps.

Should we change xreallocarray to always return nonnull? We could then add __attribute__ ((__returns_nonnull__)) to its declaration. This might help performance and/or static checking a bit. The only downside I can see is that xreallocarray's semantics would differ a bit more from glibc reallocarray's.

Attachment: 0001-xalloc-new-function-xinmalloc.patch
Description: Text Data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]