Signed-off-by: Matteo Bruni <mbruni(a)codeweavers.com>
---
v2: Don't duplicate parse_integer().
Supersedes 235242.
This fixes arithmetic-int.shader_test on 32-bit Linux for
me.
libs/vkd3d-shader/hlsl.l | 6 ++---
libs/vkd3d-shader/preproc.y | 34 +-----------------------
libs/vkd3d-shader/vkd3d_shader_main.c | 32 ++++++++++++++++++++++
libs/vkd3d-shader/vkd3d_shader_private.h | 2 ++
4 files changed, 38 insertions(+), 36 deletions(-)
diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l
index 267c8c30..ff7b712f 100644
--- a/libs/vkd3d-shader/hlsl.l
+++ b/libs/vkd3d-shader/hlsl.l
@@ -197,15 +197,15 @@ row_major {return KW_ROW_MAJOR; }
return C_FLOAT;
}
0x[0-9a-fA-F]+ {
- sscanf(yytext, "0x%x", &yylval->intval);
+ yylval->intval = vkd3d_parse_integer(yytext);
return C_INTEGER;
}
0[0-7]+ {
- sscanf(yytext, "0%o", &yylval->intval);
+ yylval->intval = vkd3d_parse_integer(yytext);
return C_INTEGER;
}
[0-9]+ {
- yylval->intval = (atoi(yytext));
+ yylval->intval = vkd3d_parse_integer(yytext);
return C_INTEGER;
}
diff --git a/libs/vkd3d-shader/preproc.y b/libs/vkd3d-shader/preproc.y
index 3f02ac03..009c35ff 100644
--- a/libs/vkd3d-shader/preproc.y
+++ b/libs/vkd3d-shader/preproc.y
@@ -165,38 +165,6 @@ static bool preproc_push_if(struct preproc_ctx *ctx, bool condition)
return true;
}
-static int char_to_int(char c)
-{
- if ('0' <= c && c <= '9')
- return c - '0';
- if ('A' <= c && c <= 'F')
- return c - 'A' + 10;
- if ('a' <= c && c <= 'f')
- return c - 'a' + 10;
- return -1;
-}
-
-static uint32_t preproc_parse_integer(const char *s)
-{
- uint32_t base = 10, ret = 0;
- int digit;
-
- if (*s == '0')
- {
- base = 8;
- ++s;
- if (*s == 'x' || *s == 'X')
- {
- base = 16;
- ++s;
- }
- }
-
- while ((digit = char_to_int(*s++)) >= 0)
- ret = ret * base + (uint32_t)digit;
- return ret;
-}
-
static int default_open_include(const char *filename, bool local,
const char *parent_data, void *context, struct vkd3d_shader_code *out)
{
@@ -691,7 +659,7 @@ directive
primary_expr
: T_INTEGER
{
- $$ = preproc_parse_integer($1);
+ $$ = vkd3d_parse_integer($1);
vkd3d_free($1);
}
| T_IDENTIFIER
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c
index 62baf17f..6fd32435 100644
--- a/libs/vkd3d-shader/vkd3d_shader_main.c
+++ b/libs/vkd3d-shader/vkd3d_shader_main.c
@@ -24,6 +24,38 @@
VKD3D_DEBUG_ENV_NAME("VKD3D_SHADER_DEBUG");
+static inline int char_to_int(char c)
+{
+ if ('0' <= c && c <= '9')
+ return c - '0';
+ if ('A' <= c && c <= 'F')
+ return c - 'A' + 10;
+ if ('a' <= c && c <= 'f')
+ return c - 'a' + 10;
+ return -1;
+}
+
+uint32_t vkd3d_parse_integer(const char *s)
+{
+ uint32_t base = 10, ret = 0;
+ int digit;
+
+ if (*s == '0')
+ {
+ base = 8;
+ ++s;
+ if (*s == 'x' || *s == 'X')
+ {
+ base = 16;
+ ++s;
+ }
+ }
+
+ while ((digit = char_to_int(*s++)) >= 0)
+ ret = ret * base + (uint32_t)digit;
+ return ret;
+}
+
void vkd3d_string_buffer_init(struct vkd3d_string_buffer *buffer)
{
buffer->buffer_size = 16;
diff --git a/libs/vkd3d-shader/vkd3d_shader_private.h b/libs/vkd3d-shader/vkd3d_shader_private.h
index 29e178cc..8bde5523 100644
--- a/libs/vkd3d-shader/vkd3d_shader_private.h
+++ b/libs/vkd3d-shader/vkd3d_shader_private.h
@@ -1035,6 +1035,8 @@ static inline size_t bytecode_get_size(struct vkd3d_bytecode_buffer *buffer)
return buffer->size;
}
+uint32_t vkd3d_parse_integer(const char *s);
+
struct vkd3d_shader_message_context
{
enum vkd3d_shader_log_level log_level;
--
2.35.1