Skip to content

Commit

Permalink
Fix inconsistent management of ExtSuffix in INIT macros (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel authored Dec 3, 2024
1 parent 860a541 commit d22ced3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gen/cheader.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ typedef struct WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}} {
/**
* Initializer for @ref WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}}.
*/
#define WGPU_{{.Name | ConstantCase}}_CALLBACK_INFO{{$.ExtSuffix}}_INIT _wgpu_MAKE_INIT_STRUCT(WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}}, { \
#define WGPU_{{.Name | ConstantCase}}_CALLBACK_INFO{{if $.ExtSuffix}}_{{$.ExtSuffix}}{{end}}_INIT _wgpu_MAKE_INIT_STRUCT(WGPU{{.Name | PascalCase}}CallbackInfo{{$.ExtSuffix}}, { \
/*.nextInChain=*/NULL _wgpu_COMMA \
{{- if eq .Style "callback_mode" }}
/*.mode=*/WGPUCallbackMode_WaitAnyOnly _wgpu_COMMA \
Expand Down
12 changes: 10 additions & 2 deletions gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,11 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string
return literal("NULL")
} else {
typ := strings.TrimPrefix(member.Type, "struct.")
return ref("WGPU_" + ConstantCase(typ) + "_INIT")
return ref("WGPU_" + ConstantCase(typ) + g.ConstantExtSuffix() + "_INIT")
}
case strings.HasPrefix(member.Type, "callback."):
typ := strings.TrimPrefix(member.Type, "callback.")
return ref("WGPU_" + ConstantCase(typ) + "_CALLBACK_INFO_INIT")
return ref("WGPU_" + ConstantCase(typ) + "_CALLBACK_INFO" + g.ConstantExtSuffix() + "_INIT")
case strings.HasPrefix(member.Type, "object."):
return literal("NULL")
case strings.HasPrefix(member.Type, "array<"):
Expand All @@ -607,3 +607,11 @@ func (g *Generator) DefaultValue(member ParameterType, isDocString bool) string
panic("invalid prefix: " + member.Type + " in member " + member.Name)
}
}

func (g *Generator) ConstantExtSuffix() string {
if g.ExtSuffix != "" {
return "_" + ConstantCase(g.ExtSuffix)
} else {
return ""
}
}

0 comments on commit d22ced3

Please sign in to comment.