mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-10 17:05:21 +00:00
de7d9de5ae
The previous two call helper macro copied the entire input struct to output struct. In particular this did not keep the .type and .next fields intact. Rather than trying to keep those intact, each struct type should have its own fill function, only filling in the data we actually want to fill in.
67 lines
3.2 KiB
C
67 lines
3.2 KiB
C
// Copyright 2018-2019, Collabora, Ltd.
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
/*!
|
|
* @file
|
|
* @brief Two call helper functions.
|
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
* @ingroup oxr_main
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
#define OXR_TWO_CALL_HELPER(log, cnt_input, cnt_output, output, count, data, \
|
|
sval) \
|
|
do { \
|
|
if (cnt_output == NULL) { \
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
|
|
#cnt_output); \
|
|
} \
|
|
*cnt_output = count; \
|
|
\
|
|
if (cnt_input == 0) { \
|
|
return sval; \
|
|
} \
|
|
if (cnt_input < count) { \
|
|
return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, \
|
|
#cnt_input); \
|
|
} \
|
|
for (uint32_t i = 0; i < count; i++) { \
|
|
(output)[i] = (data)[i]; \
|
|
} \
|
|
return sval; \
|
|
} while (false)
|
|
|
|
//! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs
|
|
#define OXR_TWO_CALL_FILL_IN_HELPER(log, cnt_input, cnt_output, \
|
|
output_structs, count, fill_fn, \
|
|
source_structs, sval) \
|
|
do { \
|
|
if (cnt_output == NULL) { \
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
|
|
#cnt_output); \
|
|
} \
|
|
*cnt_output = count; \
|
|
\
|
|
if (cnt_input == 0) { \
|
|
return sval; \
|
|
} \
|
|
if (cnt_input < count) { \
|
|
return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, \
|
|
#cnt_input); \
|
|
} \
|
|
for (uint32_t i = 0; i < count; i++) { \
|
|
fill_fn(&output_structs[i], &source_structs[i]); \
|
|
} \
|
|
return sval; \
|
|
} while (false)
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|