libsepol: break circular include
PATCH 1/3 libsepol: break circular include
Since struct type_set is forward declared including policydb/policydb.h is not necessary and creates a circular include.
Also drop the unnecessary forward declaration of struct policydb.
--- libsepol/include/sepol/policydb/constraint.h | 3 --- 1 file changed, 3 deletions(-)
libsepol/include/sepol/policydb/constraint.h +0 -3
@@ -18,7 +18,6 @@#ifndef _SEPOL_POLICYDB_CONSTRAINT_H_#define _SEPOL_POLICYDB_CONSTRAINT_H_ -#include <sepol/policydb/policydb.h> #include <sepol/policydb/ebitmap.h> #include <sepol/policydb/flask_types.h>
@@ -70,8 +69,6 @@ typedef struct constraint_node {struct constraint_node *next;/* next constraint */ } constraint_node_t; -struct policydb ; -extern int constraint_expr_init (constraint_expr_t * expr);extern void constraint_expr_destroy (constraint_expr_t * expr);
Signature · 1 line
2.36.1
PATCH 2/3 libsepol: include necessary headers in headers
Include policydb header file required for typedef policydb_t.
This is for example helpful when working with an IDE, which needs to resolve those symbols.
--- libsepol/include/sepol/policydb/util.h | 2 ++ libsepol/src/mls.h | 1 + 2 files changed, 3 insertions(+)
libsepol/include/sepol/policydb/util.h +2 -0
@@ -23,6 +23,8 @@ #ifndef __SEPOL_UTIL_H__ #define __SEPOL_UTIL_H__ +#include <sepol/policydb/policydb.h> + #ifdef __cplusplus extern "C" { #endif
libsepol/src/mls.h +1 -0
@@ -25,6 +25,7 @@#include "policydb_internal.h" #include <sepol/policydb/context.h> +#include <sepol/policydb/policydb.h> #include "handle.h" extern int mls_from_string(sepol_handle_t * handle,
Signature · 1 line
2.36.1
PATCH 3/3 libsepol: enclose macro parameters and replacement lists in parentheses
In reply to Christian Göttsche--- libsepol/include/sepol/errcodes.h | 13 ++++++------- libsepol/include/sepol/policydb/policydb.h | 10 +++++----- libsepol/src/kernel_to_cil.c | 2 +- libsepol/src/module_to_cil.c | 2 +- libsepol/src/util.c | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-)
libsepol/include/sepol/errcodes.h +6 -7
@@ -16,15 +16,14 @@ extern "C" {* codes that don't map to system error codes should be defined * outside of the range of system error codes. */ -#define SEPOL_ERR -1 -#define SEPOL_ENOTSUP -2/* feature not supported in module language */ -#define SEPOL_EREQ -3/* requirements not met */ +#define SEPOL_ERR (-1) +#define SEPOL_ENOTSUP (-2)/* feature not supported in module language */ +#define SEPOL_EREQ (-3)/* requirements not met */ /* Error codes that map to system error codes */ -#define SEPOL_ENOMEM -ENOMEM -#define SEPOL_ERANGE -ERANGE -#define SEPOL_EEXIST -EEXIST -#define SEPOL_ENOENT -ENOENT +#define SEPOL_ENOMEM (-ENOMEM) +#define SEPOL_EEXIST (-EEXIST) +#define SEPOL_ENOENT (-ENOENT) #ifdef __cplusplus }
libsepol/include/sepol/policydb/policydb.h +5 -5
@@ -251,9 +251,9 @@ typedef struct class_perm_node {struct class_perm_node *next; } class_perm_node_t; -#define xperm_test (x, p) (UINT32_C(1) & (p[x >> 5] >> (x & 0x1f))) -#define xperm_set (x, p) (p[x >> 5] |= (UINT32_C(1) << (x & 0x1f))) -#define xperm_clear (x, p) (p[x >> 5] &= ~(UINT32_C(1) << (x & 0x1f))) +#define xperm_test (x, p) (UINT32_C(1) & ((p)[(x) >> 5] >> ((x) & 0x1f))) +#define xperm_set (x, p) ((p)[(x) >> 5] |= (UINT32_C(1) << ((x) & 0x1f))) +#define xperm_clear (x, p) ((p)[(x) >> 5] &= ~(UINT32_C(1) << ((x) & 0x1f)))#define EXTENDED_PERMS_LEN 8 typedef struct av_extended_perms {
@@ -795,9 +795,9 @@ extern int policydb_set_target_platform(policydb_t *p, int platform);#define policydb_has_boundary_feature (p) \ (((p)->policy_type == POLICY_KERN \ - && p->policyvers >= POLICYDB_VERSION_BOUNDARY) || \ + && (p)->policyvers >= POLICYDB_VERSION_BOUNDARY) || \ ((p)->policy_type != POLICY_KERN \ - && p->policyvers >= MOD_POLICYDB_VERSION_BOUNDARY)) + && (p)->policyvers >= MOD_POLICYDB_VERSION_BOUNDARY))/* the config flags related to unknown classes/perms are bits 2 and 3 */ #define DENY_UNKNOWN SEPOL_DENY_UNKNOWN
libsepol/src/kernel_to_cil.c +1 -1
@@ -1626,7 +1626,7 @@ exit:return rc; } -#define next_bit_in_range (i, p) ((i + 1 < sizeof(p)*8) && xperm_test((i + 1), p)) +#define next_bit_in_range (i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p))static char *xperms_to_str (avtab_extended_perms_t *xperms) {
libsepol/src/module_to_cil.c +1 -1
@@ -624,7 +624,7 @@ exit:return rc; } -#define next_bit_in_range (i, p) ((i + 1 < sizeof(p)*8) && xperm_test((i + 1), p)) +#define next_bit_in_range (i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p))static int xperms_to_cil (const av_extended_perms_t *xperms) {
libsepol/src/util.c +1 -1
@@ -124,7 +124,7 @@ char *sepol_av_to_string(policydb_t * policydbp, uint32_t tclass,return avbuf; } -#define next_bit_in_range (i, p) ((i + 1 < sizeof(p)*8) && xperm_test((i + 1), p)) +#define next_bit_in_range (i, p) (((i) + 1 < sizeof(p)*8) && xperm_test(((i) + 1), p))char *sepol_extended_perms_to_string (avtab_extended_perms_t *xperms) {
Signature · 1 line
2.36.1
Quoted 7 lines · Christian Göttsche
Since
struct type_setis forward declared includingpolicydb/policydb.his not necessary and creates a circular include.Also drop the unnecessary forward declaration of
struct policydb.Signed-off-by Christian Göttsche <[email protected]>
For these three patches:
Quoted 28 lines
--- libsepol/include/sepol/policydb/constraint.h | 3 --- 1 file changed, 3 deletions(-)libsepol/include/sepol/policydb/constraint.h +0
-4@@ -18,7 +18,6 @@#ifndef _SEPOL_POLICYDB_CONSTRAINT_H_#define _SEPOL_POLICYDB_CONSTRAINT_H_ -#include <sepol/policydb/policydb.h> #include <sepol/policydb/ebitmap.h> #include <sepol/policydb/flask_types.h> @@ -70,8 +69,6 @@ typedef struct constraint_node {struct constraint_node *next;/* next constraint */ } constraint_node_t; -struct policydb ; -extern int constraint_expr_init (constraint_expr_t * expr);extern void constraint_expr_destroy (constraint_expr_t * expr); --2.36.1
Quoted 7 lines · James Carter
Quoted 4 lines · Christian Göttsche
Since
struct type_setis forward declared includingpolicydb/policydb.his not necessary and creates a circular include.
Quoted 7 lines
Quoted 3 lines
Also drop the unnecessary forward declaration of
struct policydb.Signed-off-by Christian Göttsche <[email protected]>For these three patches:
Acked-by James Carter <[email protected]>
These three patches have been merged.
Thanks,
Jim
Quoted 28 lines
Quoted 28 lines
--- libsepol/include/sepol/policydb/constraint.h | 3 --- 1 file changed, 3 deletions(-)libsepol/include/sepol/policydb/constraint.h +0
-4@@ -18,7 +18,6 @@#ifndef _SEPOL_POLICYDB_CONSTRAINT_H_#define _SEPOL_POLICYDB_CONSTRAINT_H_ -#include <sepol/policydb/policydb.h> #include <sepol/policydb/ebitmap.h> #include <sepol/policydb/flask_types.h> @@ -70,8 +69,6 @@ typedef struct constraint_node {struct constraint_node *next;/* next constraint */ } constraint_node_t; -struct policydb ; -extern int constraint_expr_init (constraint_expr_t * expr);extern void constraint_expr_destroy (constraint_expr_t * expr); --2.36.1