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:
Tony Finch
2023-04-06 17:22:37 +01:00
parent ff34a1f117
commit 36943c7c1c
4 changed files with 26 additions and 10 deletions
+14
View File
@@ -0,0 +1,14 @@
@@
type T;
identifier fun;
identifier arg;
expression val;
@@
fun(..., T *arg, ...) {
...
- if (arg != NULL) {
- *arg = val;
- }
+ OUTARG(arg, val);
...
}
+2
View File
@@ -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
-10
View File
@@ -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')
+10
View File
@@ -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.