1#pragma once
2
3/*
4 * Function arguments helpers
5 */
6
7#include <stdarg.h>
8
9#include <pw_types.h>
10#include <pw_interfaces.h>
11#include <pw_status.h>
12#include <pw_task.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18/*
19 * Argument validation
20 */
21static inline bool pw_validate(PwValuePtr value, uint16_t type_id)
22{
23 if (_pw_likely(pw_is_subtype(value, type_id))) {
24 return true;
25 }
26 if (pw_is_error(value)) {
27 pw_set_status(pw_clone(value));
28 } else {
29 pw_set_status(PwStatus(PW_ERROR_INCOMPATIBLE_TYPE));
30 }
31 return false;
32}
33
34
35static inline void _pw_destroy_args(va_list ap)
36/*
37 * Helper for functions that accept values created on stack during function call.
38 * Such values cannot be automatically cleaned on error, the callee
39 * should do that.
40 * See pw_array(), pw_array_append_va, PwMap(), pw_map_update_va
41 */
42{
43 for (;;) {{
44 PwValue arg = va_arg(ap, _PwValue);
45 if (pw_is_va_end(&arg)) {
46 break;
47 }
48 }}
49}
50
51#ifdef __cplusplus
52}
53#endif