Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorClément Foucault <foucault.clem@gmail.com>2022-03-19 23:53:51 +0300
committerClément Foucault <foucault.clem@gmail.com>2022-03-20 00:05:34 +0300
commit36b02c3815af8f76aa9d7ce017fd00b66e8b1965 (patch)
tree6369092fee4f16de582ff1f0f1f2b6f0f6a86ff8 /source
parent472fc0c55848b2e2d428cfb4f7debb80a4e12081 (diff)
GPUSource: Fix failure case in the enum preprocessor
Some C headers might define the typedefs of the enum themselves. Even if they are guarded by preprocessor `#if`, our enum preprocessor has no idea of the validity of the statement. So we just bypass if there is a typedef just before any `enum` keywords. Note that the typedef matching is quite fragile.
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/intern/gpu_shader_dependency.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_shader_dependency.cc b/source/blender/gpu/intern/gpu_shader_dependency.cc
index 59481b514eb..2c6845334d3 100644
--- a/source/blender/gpu/intern/gpu_shader_dependency.cc
+++ b/source/blender/gpu/intern/gpu_shader_dependency.cc
@@ -189,7 +189,7 @@ struct GPUSource {
{
const StringRefNull input = source;
std::string output;
- int64_t cursor = 0;
+ int64_t cursor = -1;
int64_t last_pos = 0;
const bool is_cpp = filename.endswith(".hh");
@@ -204,10 +204,14 @@ struct GPUSource {
}
while (true) {
- cursor = find_keyword(input, "enum ", cursor);
+ cursor = find_keyword(input, "enum ", cursor + 1);
if (cursor == -1) {
break;
}
+ /* Skip matches like `typedef enum myEnum myType;` */
+ if (cursor >= 8 && input.substr(cursor - 8, 8) == "typedef ") {
+ continue;
+ }
/* Output anything between 2 enums blocks. */
output += input.substr(last_pos, cursor - last_pos);