Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1208, typesafe definition of osal_id_t #1209

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/os/inc/common_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,24 @@ extern "C"
typedef size_t cpusize;
typedef ptrdiff_t cpudiff;

#ifdef OSAL_OMIT_DEPRECATED
/**
* A type to be used for OSAL resource identifiers.
* This is a type-safe ID, and cannot be implicitly converted to an integer.
* Use the provided inline functions in osapi-idmap.h to interpret ID values.
*/
typedef uint32_t osal_id_t;
typedef struct
{
uint32_t v;
} osal_id_t;
#else

/**
* A type to be used for OSAL resource identifiers.
* This typedef is backward compatible with the IDs from older versions of OSAL
*/
typedef uint32 osal_id_t;
#endif

/**
* A type used to represent a number of blocks or buffers
Expand Down
12 changes: 10 additions & 2 deletions src/os/inc/osapi-idmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@
*/
static inline unsigned long OS_ObjectIdToInteger(osal_id_t object_id)
{
#ifdef OSAL_OMIT_DEPRECATED
return object_id.v;
#else
return object_id;
#endif
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -98,7 +102,11 @@ static inline unsigned long OS_ObjectIdToInteger(osal_id_t object_id)
*/
static inline osal_id_t OS_ObjectIdFromInteger(unsigned long value)
{
#ifdef OSAL_OMIT_DEPRECATED
return (osal_id_t) {value};
#else
return (osal_id_t)value;
#endif
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -119,7 +127,7 @@ static inline osal_id_t OS_ObjectIdFromInteger(unsigned long value)
*/
static inline bool OS_ObjectIdEqual(osal_id_t object_id1, osal_id_t object_id2)
{
return (object_id1 == object_id2);
return (OS_ObjectIdToInteger(object_id1) == OS_ObjectIdToInteger(object_id2));
}

/*-------------------------------------------------------------------------------------*/
Expand All @@ -140,7 +148,7 @@ static inline bool OS_ObjectIdEqual(osal_id_t object_id1, osal_id_t object_id2)
*/
static inline bool OS_ObjectIdDefined(osal_id_t object_id)
{
return (object_id != 0);
return (OS_ObjectIdToInteger(object_id) != 0);
}

/*-------------------------------------------------------------------------------------*/
Expand Down