[ccan] [PATCH] bitmap: Allow bitmap type to be forward declared
Kirill Smelkov
kirr at nexedi.com
Tue Oct 22 18:53:26 AEDT 2019
On Tue, Oct 22, 2019 at 04:25:20PM +1100, David Gibson wrote:
> On Mon, Oct 21, 2019 at 03:09:20PM +0000, Kirill Smelkov wrote:
> > Currently bitmap type is defined via untagged struct which makes it
> > impossible to forward declare it. Forward-declaring is useful since all
> > bitmap functions only use bitmap* and in public user-visible
> > headers/datastructures it is enough to indicate that a data field with
> > bitmap pointer is there, whereas bitmap.h can be included only in
> > implementation.
> >
> > Beside that some headers are included by both C and C++ parts of a
> > project, and when ccan/bitmap.h is processed by C++ compiler it gives:
> >
> > ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_alloc(long unsigned int)’:
> > ./3rdparty/ccan/ccan/bitmap/bitmap.h:201:15: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive]
> > return malloc(bitmap_sizeof(nbits));
> > ~~~~~~^~~~~~~~~~~~~~~~~~~~~~
> > ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_realloc0(bitmap*, long unsigned int, long unsigned int)’:
> > ./3rdparty/ccan/ccan/bitmap/bitmap.h:227:18: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive]
> > bitmap = realloc(bitmap, bitmap_sizeof(nbits));
> > ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ./3rdparty/ccan/ccan/bitmap/bitmap.h: In function ‘bitmap* bitmap_realloc1(bitmap*, long unsigned int, long unsigned int)’:
> > ./3rdparty/ccan/ccan/bitmap/bitmap.h:238:18: error: invalid conversion from ‘void*’ to ‘bitmap*’ [-fpermissive]
> > bitmap = realloc(bitmap, bitmap_sizeof(nbits));
> >
> > -> Give to users ability not to force-include ccan/bitmap.h by
> > forward-declaring bitmaps like this:
> >
> > typedef struct bitmap bitmap;
> > ...
> > struct MyStruct {
> > bitmap *my_bitmap;
> > };
> >
> > Cc: David Gibson <david at gibson.dropbear.id.au>
> > Signed-off-by: Kirill Smelkov <kirr at nexedi.com>
>
> Applied, thanks.
Thanks.
More information about the ccan
mailing list