On Thu, Apr 18, 2024 at 3:58 PM Graham Leggett <minf...@sharp.fm> wrote: > > On 18 Apr 2024, at 13:15, Yann Ylavic <ylavic....@gmail.com> 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.