Open DejvBayer opened 3 months ago
I created a preview of this feature for vkFFT_InitializeApp module in: https://github.com/DejvBayer/VkFFT/tree/goto-error-handling
I think it shortens the code quite a bit and makes it more focused on what is being done.
Hello,
Sorry, I don't see how this shortens code significantly. It adds many jumps and often the VKFFT_CHECK and VKFFT_CHECK_RESULT behavior is different from the proposed base function - sometimes they have to also clear local resources. I also feel like using goto will raise quite some red flags in people's eyes. I personally like it when everything is located nearby so having an additional line but avoiding full file jumps is fine by me. If more people decide that your approach is better we can come back to discussing it in the future.
Best regards, Dmitrii
Hi,
I suggest creating a
vkFFT_Error
module, whereVkFFTResult
type definition andgetVkFFTErrorString(...)
function would be moved. Plus the module would contain new macrosVKFFT_CHECK(...)
andVKFFT_CHECK_RESULT(...)
.The idea is that the library could use a error handling machanism base on
goto
. Here is the original code:And here is the proposed error handling mechanism. It creates
broken
andbrokenNoDelete
labels that are used when an error occures. The benefit is that the code is more readible and you needn't to writedeleteVkFFT
each time.However I think that we can take this idea further and define those 2 macros. In each function a
resFFT
variable shall be defined as it will be used to pass the error code.false
theresFFT
variable is set tovkfftResult
error and it jumps to the specified lable where the resources should be released.VkFFTResult
. It is first evaluated into a temporary variable and if the expression was unsuccessful, it sets up theresFFT
variable and jumps to thelabel
.define VKFFT_CHECK_RESULT(vkfftExpr, label) \
do { \ VkFFTResult _resFFT = (vkfftExpr); \ if (_resFFT != VKFFT_SUCCESS) { \ resFFT = _resFFT; \ goto label; \ } \ } while (0)
I think that this change would shorten the code very much and will also improve the overall code quality. Plus we can define macros for backend's error values like
VKFFT_CHECK_RESULT_CUDA
orVKFFT_CHECK_RESULT_HIP
.