The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

st/oxr: adds more check/verify macros for two-call idiom

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2604>

+55 -12
+19
src/xrt/state_trackers/oxr/oxr_api_verify.h
··· 200 200 } \ 201 201 } while (false) 202 202 203 + #define OXR_VERIFY_TWO_CALL_ARRAY(log, inputCapacity, countOutput, array) \ 204 + do { \ 205 + OXR_VERIFY_ARG_NOT_NULL(log, countOutput); \ 206 + if (inputCapacity > 0) { \ 207 + OXR_VERIFY_ARG_NOT_NULL(log, array); \ 208 + } \ 209 + } while (false) 210 + 211 + #define OXR_VERIFY_TWO_CALL_ARRAY_AND_TYPE(log, inputCapacity, countOutput, array, type_enum) \ 212 + do { \ 213 + OXR_VERIFY_ARG_NOT_NULL(log, countOutput); \ 214 + if (inputCapacity > 0) { \ 215 + OXR_VERIFY_ARG_NOT_NULL(log, array); \ 216 + for (uint32_t i = 0; i < inputCapacity; ++i) { \ 217 + OXR_VERIFY_ARG_ARRAY_ELEMENT_TYPE(log, array, i, type_enum); \ 218 + } \ 219 + } \ 220 + } while (false) 221 + 203 222 #define OXR_VERIFY_SUBACTION_PATHS(log, count, paths) \ 204 223 do { \ 205 224 if (count > 0 && paths == NULL) { \
+36 -12
src/xrt/state_trackers/oxr/oxr_two_call.h
··· 14 14 extern "C" { 15 15 #endif 16 16 17 - 18 - #define OXR_TWO_CALL_HELPER(log, cnt_input, cnt_output, output, count, data, sval) \ 17 + #define OXR_TWO_CALL_CHECK_ONLY(log, cnt_input, cnt_output, count, sval) \ 19 18 do { \ 20 19 if ((cnt_output) == NULL) { \ 21 20 return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \ ··· 28 27 if ((cnt_input) < (uint32_t)(count)) { \ 29 28 return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \ 30 29 } \ 30 + } while (false) 31 + 32 + #define OXR_TWO_CALL_CHECK_GOTO(log, cnt_input, cnt_output, count, sval, goto_label) \ 33 + do { \ 34 + if ((cnt_output) == NULL) { \ 35 + sval = oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \ 36 + goto goto_label; \ 37 + } \ 38 + *(cnt_output) = (uint32_t)(count); \ 39 + \ 40 + if ((cnt_input) == 0) { \ 41 + goto goto_label; \ 42 + } \ 43 + if ((cnt_input) < (uint32_t)(count)) { \ 44 + sval = oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \ 45 + goto goto_label; \ 46 + } \ 47 + } while (false) 48 + 49 + #define OXR_TWO_CALL_HELPER(log, cnt_input, cnt_output, output, count, data, sval) \ 50 + do { \ 51 + OXR_TWO_CALL_CHECK_ONLY(log, cnt_input, cnt_output, count, sval); \ 52 + \ 31 53 for (uint32_t i = 0; i < (count); i++) { \ 32 54 (output)[i] = (data)[i]; \ 33 55 } \ ··· 37 59 //! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs 38 60 #define OXR_TWO_CALL_FILL_IN_HELPER(log, cnt_input, cnt_output, output_structs, count, fill_fn, source_structs, sval) \ 39 61 do { \ 40 - if (cnt_output == NULL) { \ 41 - return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, #cnt_output); \ 42 - } \ 43 - *cnt_output = count; \ 62 + OXR_TWO_CALL_CHECK_ONLY(log, cnt_input, cnt_output, count, sval); \ 44 63 \ 45 - if (cnt_input == 0) { \ 46 - return sval; \ 47 - } \ 48 - if (cnt_input < count) { \ 49 - return oxr_error(log, XR_ERROR_SIZE_INSUFFICIENT, #cnt_input); \ 50 - } \ 51 64 for (uint32_t i = 0; i < count; i++) { \ 52 65 fill_fn(&output_structs[i], &source_structs[i]); \ 53 66 } \ 54 67 return sval; \ 68 + } while (false) 69 + 70 + //! Calls fill_fn(&output_struct[i], &source_struct[i]) to fill output_structs 71 + #define OXR_TWO_CALL_FILL_IN_GOTO(log, cnt_input, cnt_output, output_structs, count, fill_macro, source_structs, sval, \ 72 + goto_label) \ 73 + do { \ 74 + OXR_TWO_CALL_CHECK_GOTO(log, cnt_input, cnt_output, count, sval, goto_label); \ 75 + \ 76 + for (uint32_t i = 0; i < count; i++) { \ 77 + fill_macro(output_structs[i], source_structs[i]); \ 78 + } \ 55 79 } while (false) 56 80 57 81 #ifdef __cplusplus