An OUTARG() macro for optional return values
The OUTARG() macro avoids a fair amount of tedious boilerplate. I have included a Coccinelle semantic patch to use OUTARG() where appropriate. The patch needs a #include in `openssl_shim.c` in order to work.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
@@
|
||||
type T;
|
||||
identifier fun;
|
||||
identifier arg;
|
||||
expression val;
|
||||
@@
|
||||
fun(..., T *arg, ...) {
|
||||
...
|
||||
- if (arg != NULL) {
|
||||
- *arg = val;
|
||||
- }
|
||||
+ OUTARG(arg, val);
|
||||
...
|
||||
}
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include "openssl_shim.h"
|
||||
|
||||
#include <isc/util.h>
|
||||
|
||||
#if !HAVE_RSA_SET0_KEY && OPENSSL_VERSION_NUMBER < 0x30000000L
|
||||
/* From OpenSSL 1.1.0 */
|
||||
int
|
||||
|
||||
@@ -34,16 +34,6 @@
|
||||
#define STRUCT_FLEX_SIZE(pointer, member, count) \
|
||||
(sizeof(*(pointer)) + sizeof(*(pointer)->member) * (count))
|
||||
|
||||
/*
|
||||
* XXXFANF this should probably be in <isc/util.h> too
|
||||
*/
|
||||
#define OUTARG(ptr, val) \
|
||||
({ \
|
||||
if ((ptr) != NULL) { \
|
||||
*(ptr) = (val); \
|
||||
} \
|
||||
})
|
||||
|
||||
#define HISTO_MAGIC ISC_MAGIC('H', 's', 't', 'o')
|
||||
#define HISTO_VALID(p) ISC_MAGIC_VALID(p, HISTO_MAGIC)
|
||||
#define HISTOMULTI_MAGIC ISC_MAGIC('H', 'g', 'M', 't')
|
||||
|
||||
@@ -96,6 +96,16 @@
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
|
||||
|
||||
/*
|
||||
* Optional return values, or out-arguments
|
||||
*/
|
||||
#define OUTARG(ptr, val) \
|
||||
({ \
|
||||
if ((ptr) != NULL) { \
|
||||
*(ptr) = (val); \
|
||||
} \
|
||||
})
|
||||
|
||||
/*%
|
||||
* Use this in translation units that would otherwise be empty, to
|
||||
* suppress compiler warnings.
|
||||
|
||||
Reference in New Issue
Block a user