Skip to contentSkip to conversation

bitmap: Allow bitmap type to be forward declared

PATCH Applied Kirill Smelkov 2 participants 3 messages Oct 21, 2019 – Oct 22, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bitmap: Allow bitmap type to be forward declared

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;
    };
---
 ccan/bitmap/bitmap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ccan/bitmap/bitmap.h +1 -1
index beeb1e95..54382801 100644
@@ -21,7 +21,7 @@ typedef unsigned long bitmap_word;
 /*
  * We wrap each word in a structure for type checking.
  */
-typedef struct {
+typedef struct bitmap {
 	bitmap_word w;
 } bitmap;
 
Signature · 6 lines
2.20.1

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan
Applied
#1 lore raw
Quoted 25 lines · Kirill Smelkov

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:

Quoted 8 lines
    typedef struct bitmap bitmap;
    ...
    struct MyStruct {
        bitmap *my_bitmap;
    };

Applied, thanks.

Quoted 17 lines
---
 ccan/bitmap/bitmap.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ccan/bitmap/bitmap.h +1 -1
index beeb1e95..54382801 100644
@@ -21,7 +21,7 @@ typedef unsigned long bitmap_word;
 /*
  * We wrap each word in a structure for type checking.
  */
-typedef struct {
+typedef struct bitmap {
 	bitmap_word w;
 } bitmap;
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan

#2 lore raw
Quoted 32 lines · David Gibson
Quoted 31 lines · Kirill Smelkov

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;
    };
Quoted 4 lines
Quoted 2 lines

Applied, thanks.

Thanks.

_______________________________________________
ccan mailing list
[email protected]
https://lists.ozlabs.org/listinfo/ccan