[Mesa-dev] [PATCH] util: port _mesa_strto[df] to C

Erik Faye-Lund kusmabite at gmail.com
Mon Mar 16 15:12:28 PDT 2015


On Mon, Mar 16, 2015 at 10:13 PM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
> On 15/03/15 19:05, Erik Faye-Lund wrote:
>> _mesa_strtod and _mesa_strtof are only used from the GLSL compiler,
>> so the locale doesn't need to be initialized before the first context
>> gets initialized. So let's use explicit initialization from the
>> one-time init code instead of depending on a C++ compiler to initialize
>> at image-load time.
>>
>> Signed-off-by: Erik Faye-Lund <kusmabite at gmail.com>
>> ---
>>
>> Because of the recent discussion on libc++ and Mesa, I thought I'd
>> have a look into what parts of mesa depended on libc++, and I spotted
>> this file.
>>
>> In this case, it was rather trivial to port the code to plain C, making
>> it dead obvious that it doesn't depend on libc++. I'm not proposing all
>> C++ gets this treatment, but in this case it seems like a pretty
>> straight-forward way to make it obvious that this code does not depend
>> on libc++.
>>
> Fwiw this file/code should not cause any linkage to the C++ runtime,
> although it's a nice cleanup imho.
>
> There is a small catch though - _mesa_strtof can be used by the
> standalone glsl_compiler and perhaps glcpp.

Good point, so perhaps this on top?

---8<---
diff --git a/src/glsl/glcpp/glcpp.c b/src/glsl/glcpp/glcpp.c
index 5144516..c62f4ef 100644
--- a/src/glsl/glcpp/glcpp.c
+++ b/src/glsl/glcpp/glcpp.c
@@ -29,6 +29,7 @@
 #include "glcpp.h"
 #include "main/mtypes.h"
 #include "main/shaderobj.h"
+#include "util/strtod.h"

 extern int glcpp_parser_debug;

@@ -168,6 +169,8 @@ main (int argc, char *argv[])
  if (shader == NULL)
    return 1;

+ _mesa_locale_init();
+
  ret = glcpp_preprocess(ctx, &shader, &info_log, NULL, &gl_ctx);

  printf("%s", shader);
diff --git a/src/glsl/main.cpp b/src/glsl/main.cpp
index ccac839..b23b583 100644
--- a/src/glsl/main.cpp
+++ b/src/glsl/main.cpp
@@ -38,6 +38,7 @@
 #include "program/hash_table.h"
 #include "loop_analysis.h"
 #include "standalone_scaffolding.h"
+#include "util/strtod.h"

 static int glsl_version = 330;

@@ -52,6 +53,8 @@ initialize_context(struct gl_context *ctx, gl_api api)
 {
    initialize_context_to_defaults(ctx, api);

+   _mesa_locale_init();
+
    /* The standalone compiler needs to claim support for almost
     * everything in order to compile the built-in functions.
     */
---8<---


More information about the mesa-dev mailing list