Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Use strtod_l to force the C locale
Browse files Browse the repository at this point in the history
The normal strtod is locale-sensitive which means that on locales that
don’t use the full stop (.) as a separator it won’t be able to parse
doubles in the script properly. This patch makes it create a C locale
on the vr_config and use it via strtod_l. This function is a GLIBC
extension so it is conditionally compiled when using GLIBC.

Fixes #34
  • Loading branch information
bpeel committed Oct 3, 2018
1 parent ea67091 commit 626b679
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 51 deletions.
1 change: 1 addition & 0 deletions Android.mk
Expand Up @@ -43,6 +43,7 @@ VKRUNNER_SRC_FILES := vkrunner/vr-allocate-store.c \
vkrunner/vr-script.c \
vkrunner/vr-source.c \
vkrunner/vr-stream.c \
vkrunner/vr-strtof.c \
vkrunner/vr-subprocess.c \
vkrunner/vr-temp-file.c \
vkrunner/vr-test.c \
Expand Down
2 changes: 2 additions & 0 deletions vkrunner/CMakeLists.txt
Expand Up @@ -49,6 +49,8 @@ set(VKRUNNER_SOURCE_FILES
vr-source.c
vr-stream.c
vr-stream.h
vr-strtof.c
vr-strtof.h
vr-temp-file.c
vr-temp-file.h
vr-util.c
Expand Down
3 changes: 3 additions & 0 deletions vkrunner/vr-config.h
Expand Up @@ -29,13 +29,16 @@
#include <stdbool.h>
#include "vr-result.h"
#include "vr-callback.h"
#include "vr-strtof.h"

struct vr_config {
bool show_disassembly;

vr_callback_error error_cb;
vr_callback_inspect inspect_cb;
void *user_data;

struct vr_strtof_data strtof_data;
};

#endif /* VR_CONFIG_H */
4 changes: 4 additions & 0 deletions vkrunner/vr-executor.c
Expand Up @@ -169,6 +169,8 @@ vr_executor_new(void)
{
struct vr_executor *executor = vr_calloc(sizeof *executor);

vr_strtof_init(&executor->config.strtof_data);

return executor;
}

Expand Down Expand Up @@ -318,5 +320,7 @@ vr_executor_free(struct vr_executor *executor)
{
free_context(executor);

vr_strtof_destroy(&executor->config.strtof_data);

vr_free(executor);
}
22 changes: 15 additions & 7 deletions vkrunner/vr-hex.c
Expand Up @@ -37,7 +37,9 @@
* pattern to generate a float value.
*/
float
vr_hex_strtof(const char *nptr, char **endptr)
vr_hex_strtof(const struct vr_strtof_data *data,
const char *nptr,
char **endptr)
{
/* skip spaces and tabs */
while (*nptr == ' ' || *nptr == '\t')
Expand All @@ -52,7 +54,7 @@ vr_hex_strtof(const char *nptr, char **endptr)
x.u = strtoul(nptr, endptr, 16);
return x.f;
} else {
return strtod(nptr, endptr);
return vr_strtod(data, nptr, endptr);
}
}

Expand All @@ -61,7 +63,9 @@ vr_hex_strtof(const char *nptr, char **endptr)
* pattern to generate a double value.
*/
double
vr_hex_strtod(const char *nptr, char **endptr)
vr_hex_strtod(const struct vr_strtof_data *data,
const char *nptr,
char **endptr)
{
/* skip spaces and tabs */
while (*nptr == ' ' || *nptr == '\t')
Expand All @@ -76,7 +80,7 @@ vr_hex_strtod(const char *nptr, char **endptr)
x.u64 = strtoull(nptr, endptr, 16);
return x.d;
} else {
return strtod(nptr, endptr);
return vr_strtod(data, nptr, endptr);
}
}

Expand All @@ -85,7 +89,9 @@ vr_hex_strtod(const char *nptr, char **endptr)
* generate a signed int value.
*/
int
vr_hex_strtol(const char *nptr, char **endptr)
vr_hex_strtol(const struct vr_strtof_data *data,
const char *nptr,
char **endptr)
{
/* skip spaces and tabs */
while (*nptr == ' ' || *nptr == '\t')
Expand All @@ -109,7 +115,9 @@ vr_hex_strtol(const char *nptr, char **endptr)
* hex bit pattern to generate a half float value.
*/
uint16_t
vr_hex_strtohf(const char *nptr, char **endptr)
vr_hex_strtohf(const struct vr_strtof_data *data,
const char *nptr,
char **endptr)
{
/* skip spaces and tabs */
while (*nptr == ' ' || *nptr == '\t')
Expand All @@ -124,6 +132,6 @@ vr_hex_strtohf(const char *nptr, char **endptr)
return u;
}
} else {
return vr_half_float_from_float(strtod(nptr, endptr));
return vr_half_float_from_float(vr_strtod(data, nptr, endptr));
}
}
17 changes: 13 additions & 4 deletions vkrunner/vr-hex.h
Expand Up @@ -25,17 +25,26 @@
#define VR_HEX_H

#include <stdint.h>
#include "vr-strtof.h"

float
vr_hex_strtof(const char *nptr, char **endptr);
vr_hex_strtof(const struct vr_strtof_data *data,
const char *nptr,
char **endptr);

double
vr_hex_strtod(const char *nptr, char **endptr);
vr_hex_strtod(const struct vr_strtof_data *data,
const char *nptr,
char **endptr);

int
vr_hex_strtol(const char *nptr, char **endptr);
vr_hex_strtol(const struct vr_strtof_data *data,
const char *nptr,
char **endptr);

uint16_t
vr_hex_strtohf(const char *nptr, char **endptr);
vr_hex_strtohf(const struct vr_strtof_data *data,
const char *nptr,
char **endptr);

#endif /* VR_HEX_H */

0 comments on commit 626b679

Please sign in to comment.