Re: svn commit: r1917082 - /apr/apr/trunk/buffer/apr_buffer.c

Yann Ylavic <[email protected]>
Newsgroups gmane.comp.apache.apr.devel
Message-ID <CAKQ1sVOoDxSXu5CKnhwaf=TaZp7ZBH9MtzZAM-EJsckXFC+3Ng@mail.gmail.com>
On Thu, Apr 18, 2024 at 3:58 PM Graham Leggett <[email protected]> wrote:
>
> On 18 Apr 2024, at 13:15, Yann Ylavic <[email protected]> wrote:
>
>> But let me plead again for a much simpler ->size of type apr_size_t,
>> checked against APR_BUFFER_MAX=APR_SIZE_MAX/2 wherever an apr_buffer_t
>> is initialized, using the high bit of ->size for string vs plain
>> buffer, and then getting rid of off_t/ssize_t plus all the fancy
>> signed arithmetics in the apr_buffer code (we don't care about the
>> sizeof(off_t) or anything like that anymore)..
>
> I looked at it, and it was more confusing.

There is also another completely obvious alternative which is:

typedef struct
{
    union {
        char *str;
        void *mem;
    } d;
    apr_size_t size;
    unsigned int flags;
} apr_buffer_t;

which also makes ->size directly usable without a helper, but you want
the type to be to words only?

If so maybe:

typedef struct
{
    union {
        char *str;
        void *mem;
    } d;
#if APR_SIZEOF_VOIDP == 8
#   define APR_BUFFER_SIZE_WIDTH 63
#else
#   define APR_BUFFER_SIZE_WIDTH 31
#endif
   apr_size_t size:APR_BUFFER_SIZE_WIDTH,
               zero_terminated:1;
} apr_buffer_t;

One could still use buf->size directly.

Regards;
Yann.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.