Skip to content

Conversation

@tatokis
Copy link
Contributor

@tatokis tatokis commented Nov 25, 2020

The HLSL parser uses locale-aware functions to parse the shaders, which results in errors parsing all shaders under certain locales.

For example, when a decimal point on a float is denoted by a , instead of a ..
This results in

projectM/presets/presets_milkdrop_200/Geiss - Cosmic Dust 2 - cloud journey.milk(88) : Syntax error: expected ',' near '.'
Failed to parse HLSL(step2) Comp shader

This PR does something similar to dfd335f but for HLSLParser.

#endif
}

static inline double iss_strtod(const char * in, char ** end) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, using either of those would bring in another dependency, which isn't really a good idea for only this specific thing. I'm also not sure if those libraries support getting the end of the float in the string, which is needed for the parser.
I may be wrong though as I am not familiar with either of those, and I only had a quick glance at the links.

Additionally, as mentioned, the rest of the code does the same thing, which is why I think it's the best course of action.

int Parser::string_to_float(char * string, float * float_ptr)
{
if (*string == 0)
return PROJECTM_PARSE_ERROR;
std::istringstream iss(string);
iss.imbue(std::locale("C"));
iss >> (*float_ptr);
if (!iss.fail()) {
return PROJECTM_SUCCESS;
}
(*float_ptr) = 0;
return PROJECTM_PARSE_ERROR;
}

#endif
}

static inline double iss_strtod(const char * in, char ** end) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let the compiler decide for itself if it wants to inline this or not: is my advice.

alternativelhy you can use an anonymous namespace instead of static

// what would be a static before
} // anonymous namespace

Copy link
Contributor Author

@tatokis tatokis Dec 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, inline is a suggestion to the compiler. It doesn't force it to do anything. The static was there to make inlining it easier, as when used on a function like this. It makes it accessible only inside that source file/translation unit.
I do agree though. It was only done like that because it's used in that specific place.

If you think it's better, I can make it a normal function that's part of the class, private or public.

@tatokis tatokis force-pushed the hlslparser-c-locale branch from 2afbbf8 to 52f8764 Compare December 5, 2020 06:20
@revmischa
Copy link
Member

Good to merge?

@revmischa
Copy link
Member

Ok, thanks a lot for this improvement!

@revmischa revmischa merged commit a113be0 into projectM-visualizer:master Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants