[D3DCOMPILER_43] Fix a MSVC-x64 warning about dxbc_init() (#1173)
[reactos.git] / dll / directx / wine / d3dcompiler_43 / utils.c
index aedfdce..be0adbb 100644 (file)
  *
  */
 
+#include "config.h"
+#include "wine/port.h"
+
+#include <stdio.h>
+
 #include "d3dcompiler_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3dcompiler);
@@ -552,7 +557,7 @@ HRESULT dxbc_add_section(struct dxbc *dxbc, DWORD tag, const char *data, DWORD d
     return S_OK;
 }
 
-HRESULT dxbc_init(struct dxbc *dxbc, UINT size)
+HRESULT dxbc_init(struct dxbc *dxbc, unsigned int size)
 {
     TRACE("dxbc %p, size %u.\n", dxbc, size);
 
@@ -1149,7 +1154,7 @@ static BOOL expr_compatible_data_types(struct hlsl_type *t1, struct hlsl_type *t
 
 static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hlsl_base_type t2)
 {
-    enum hlsl_base_type types[] =
+    static const enum hlsl_base_type types[] =
     {
         HLSL_TYPE_BOOL,
         HLSL_TYPE_INT,
@@ -1160,7 +1165,7 @@ static enum hlsl_base_type expr_common_base_type(enum hlsl_base_type t1, enum hl
     };
     int t1_idx = -1, t2_idx = -1, i;
 
-    for (i = 0; i < sizeof(types) / sizeof(types[0]); ++i)
+    for (i = 0; i < ARRAY_SIZE(types); ++i)
     {
         /* Always convert away from HLSL_TYPE_HALF */
         if (t1 == types[i])
@@ -1696,28 +1701,6 @@ static int compare_hlsl_types_rb(const void *key, const struct wine_rb_entry *en
     return strcmp(name, type->name);
 }
 
-static inline void *d3dcompiler_alloc_rb(size_t size)
-{
-    return d3dcompiler_alloc(size);
-}
-
-static inline void *d3dcompiler_realloc_rb(void *ptr, size_t size)
-{
-    return d3dcompiler_realloc(ptr, size);
-}
-
-static inline void d3dcompiler_free_rb(void *ptr)
-{
-    d3dcompiler_free(ptr);
-}
-static const struct wine_rb_functions hlsl_type_rb_funcs =
-{
-    d3dcompiler_alloc_rb,
-    d3dcompiler_realloc_rb,
-    d3dcompiler_free_rb,
-    compare_hlsl_types_rb,
-};
-
 void push_scope(struct hlsl_parse_ctx *ctx)
 {
     struct hlsl_scope *new_scope = d3dcompiler_alloc(sizeof(*new_scope));
@@ -1729,12 +1712,7 @@ void push_scope(struct hlsl_parse_ctx *ctx)
     }
     TRACE("Pushing a new scope\n");
     list_init(&new_scope->vars);
-    if (wine_rb_init(&new_scope->types, &hlsl_type_rb_funcs) == -1)
-    {
-        ERR("Failed to initialize types rbtree.\n");
-        d3dcompiler_free(new_scope);
-        return;
-    }
+    wine_rb_init(&new_scope->types, compare_hlsl_types_rb);
     new_scope->upper = ctx->cur_scope;
     ctx->cur_scope = new_scope;
     list_add_tail(&ctx->scopes, &new_scope->entry);
@@ -1844,14 +1822,6 @@ static int compare_function_decl_rb(const void *key, const struct wine_rb_entry
     return 0;
 }
 
-static const struct wine_rb_functions hlsl_ir_function_decl_rb_funcs =
-{
-    d3dcompiler_alloc_rb,
-    d3dcompiler_realloc_rb,
-    d3dcompiler_free_rb,
-    compare_function_decl_rb,
-};
-
 static int compare_function_rb(const void *key, const struct wine_rb_entry *entry)
 {
     const char *name = key;
@@ -1860,18 +1830,9 @@ static int compare_function_rb(const void *key, const struct wine_rb_entry *entr
     return strcmp(name, func->name);
 }
 
-static const struct wine_rb_functions function_rb_funcs =
-{
-    d3dcompiler_alloc_rb,
-    d3dcompiler_realloc_rb,
-    d3dcompiler_free_rb,
-    compare_function_rb,
-};
-
 void init_functions_tree(struct wine_rb_tree *funcs)
 {
-    if (wine_rb_init(&hlsl_ctx.functions, &function_rb_funcs) == -1)
-        ERR("Failed to initialize functions rbtree.\n");
+    wine_rb_init(&hlsl_ctx.functions, compare_function_rb);
 }
 
 static const char *debug_base_type(const struct hlsl_type *type)
@@ -1982,7 +1943,7 @@ static const char *debug_node_type(enum hlsl_ir_node_type type)
         "HLSL_IR_SWIZZLE",
     };
 
-    if (type >= sizeof(names) / sizeof(names[0]))
+    if (type >= ARRAY_SIZE(names))
         return "Unexpected node type";
     return names[type];
 }
@@ -2508,11 +2469,7 @@ void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_fu
             TRACE("Function %s redeclared as a user defined function.\n", debugstr_a(name));
             func->intrinsic = intrinsic;
             wine_rb_destroy(&func->overloads, free_function_decl_rb, NULL);
-            if (wine_rb_init(&func->overloads, &hlsl_ir_function_decl_rb_funcs) == -1)
-            {
-                ERR("Failed to initialize function rbtree.\n");
-                return;
-            }
+            wine_rb_init(&func->overloads, compare_function_decl_rb);
         }
         decl->func = func;
         if ((old_entry = wine_rb_get(&func->overloads, decl->parameters)))
@@ -2526,7 +2483,7 @@ void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_fu
                 d3dcompiler_free(name);
                 return;
             }
-            wine_rb_remove(&func->overloads, decl->parameters);
+            wine_rb_remove(&func->overloads, old_entry);
             free_function_decl(old_decl);
         }
         wine_rb_put(&func->overloads, decl->parameters, &decl->entry);
@@ -2535,13 +2492,7 @@ void add_function_decl(struct wine_rb_tree *funcs, char *name, struct hlsl_ir_fu
     }
     func = d3dcompiler_alloc(sizeof(*func));
     func->name = name;
-    if (wine_rb_init(&func->overloads, &hlsl_ir_function_decl_rb_funcs) == -1)
-    {
-        ERR("Failed to initialize function rbtree.\n");
-        d3dcompiler_free(name);
-        d3dcompiler_free(func);
-        return;
-    }
+    wine_rb_init(&func->overloads, compare_function_decl_rb);
     decl->func = func;
     wine_rb_put(&func->overloads, decl->parameters, &decl->entry);
     func->intrinsic = intrinsic;