From 400cb65161002f556b87f8197044941257d4d78d Mon Sep 17 00:00:00 2001 From: Alban Browaeys Date: Mon, 7 Feb 2011 00:00:34 +0100 Subject: [PATCH] Fix server glx version parsing for non english locales. We send a non localized string "1.4" for version 1.4 to atof which expect a localized form. For locales with dot as the decimal separator it works though for others it leads to improper code path. Introduce a _glXtrtof to use instead. It a rough copy of _mesa_strtof. --- include/GL/glimports.h | 53 +++++++++++++++++++++ src/gallium/state_trackers/egl/x11/glxinit.c | 38 +++++++++------ src/glx/Makefile | 3 +- src/glx/glimports.c | 64 ++++++++++++++++++++++++++ src/glx/glxext.c | 37 +++++++++------ 5 files changed, 164 insertions(+), 31 deletions(-) create mode 100644 include/GL/glimports.h create mode 100644 src/glx/glimports.c diff --git a/include/GL/glimports.h b/include/GL/glimports.h new file mode 100644 index 0000000..1015a9d --- /dev/null +++ b/include/GL/glimports.h @@ -0,0 +1,53 @@ +/* + * Mesa 3-D graphics library + * Version: 7.5 + * + * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/** + * \file glimports.h + * Standard C library function wrappers. + * + * This file provides wrappers for the standard C library functions + * strtof for now. + */ + + +#ifndef GLIMPORTS_H +#define GLIMPORTS_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern float +_glXStrtof( const char *s, char **end ); + + + +#ifdef __cplusplus +} +#endif + + +#endif /* IMPORTS_H */ + diff --git a/src/gallium/state_trackers/egl/x11/glxinit.c b/src/gallium/state_trackers/egl/x11/glxinit.c index df8370f..dbb6569 100644 --- a/src/gallium/state_trackers/egl/x11/glxinit.c +++ b/src/gallium/state_trackers/egl/x11/glxinit.c @@ -15,6 +15,7 @@ #include #include +#include "GL/glimports.h" #include "GL/glxproto.h" #include "GL/glxtokens.h" #include "GL/gl.h" /* for GL types needed by __GLcontextModes */ @@ -519,6 +520,8 @@ getFBConfigs(__GLXscreenConfigs *psc, __GLXdisplayPrivate *priv, int screen) xGLXVendorPrivateWithReplyReq *vpreq; xGLXGetFBConfigsReply reply; Display *dpy = priv->dpy; + char *end; + GLfloat number; psc->serverGLXexts = __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); @@ -526,21 +529,26 @@ getFBConfigs(__GLXscreenConfigs *psc, __GLXdisplayPrivate *priv, int screen) LockDisplay(dpy); psc->configs = NULL; - if (atof(priv->serverGLXversion) >= 1.3) { - GetReq(GLXGetFBConfigs, fb_req); - fb_req->reqType = priv->majorOpcode; - fb_req->glxCode = X_GLXGetFBConfigs; - fb_req->screen = screen; - } - else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) { - GetReqExtra(GLXVendorPrivateWithReply, - sz_xGLXGetFBConfigsSGIXReq + - sz_xGLXVendorPrivateWithReplyReq, vpreq); - sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; - sgi_req->reqType = priv->majorOpcode; - sgi_req->glxCode = X_GLXVendorPrivateWithReply; - sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; - sgi_req->screen = screen; + number = (GLfloat) _glXStrtof(priv->serverGLXversion, &end); + if (end && end > priv->serverGLXversion) { + if (number >= 1.3) { + GetReq(GLXGetFBConfigs, fb_req); + fb_req->reqType = priv->majorOpcode; + fb_req->glxCode = X_GLXGetFBConfigs; + fb_req->screen = screen; + } + else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) { + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXGetFBConfigsSGIXReq + + sz_xGLXVendorPrivateWithReplyReq, vpreq); + sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; + sgi_req->reqType = priv->majorOpcode; + sgi_req->glxCode = X_GLXVendorPrivateWithReply; + sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; + sgi_req->screen = screen; + } + else + goto out; } else goto out; diff --git a/src/glx/Makefile b/src/glx/Makefile index 3d92ebb..c04fa87 100644 --- a/src/glx/Makefile +++ b/src/glx/Makefile @@ -43,7 +43,8 @@ SOURCES = \ glxhash.c \ dri2_glx.c \ dri2.c \ - applegl_glx.c + applegl_glx.c \ + glimports.c ifeq ($(SHARED_GLAPI),1) diff --git a/src/glx/glimports.c b/src/glx/glimports.c new file mode 100644 index 0000000..9014cad --- /dev/null +++ b/src/glx/glimports.c @@ -0,0 +1,64 @@ +/** + * \file glimports.c + * Standard C library function wrappers. + * + * Imports are services which the device driver or window system or + * operating system provides. + * + */ + +/* + * Mesa 3-D graphics library + * Version: 7.1 + * + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "GL/glimports.h" + +#ifdef _GNU_SOURCE +#include +#ifdef __APPLE__ +#include +#endif +#endif + +/**********************************************************************/ +/** \name String */ +/*@{*/ + +/** Wrapper around strtof() */ +float +_glXStrtof( const char *s, char **end ) +{ +#if defined(_GNU_SOURCE) && !defined(__CYGWIN__) && !defined(__FreeBSD__) + static locale_t loc = NULL; + if (!loc) { + loc = newlocale(LC_CTYPE_MASK, "C", NULL); + } + return strtof_l(s, end, loc); +#elif defined(_ISOC99_SOURCE) || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) + return strtof(s, end); +#else + return (float)strtod(s, end); +#endif +} + +/*@}*/ diff --git a/src/glx/glxext.c b/src/glx/glxext.c index 25d266e..c04fe55 100644 --- a/src/glx/glxext.c +++ b/src/glx/glxext.c @@ -46,6 +46,7 @@ #include "apple_visual.h" #endif #include "glxextensions.h" +#include "GL/glimports.h" #ifdef USE_XCB #include @@ -663,6 +664,8 @@ static GLboolean xGLXVendorPrivateWithReplyReq *vpreq; xGLXGetFBConfigsReply reply; Display *dpy = priv->dpy; + char *end; + GLfloat number; psc->serverGLXexts = __glXQueryServerString(dpy, priv->majorOpcode, screen, GLX_EXTENSIONS); @@ -670,21 +673,25 @@ static GLboolean LockDisplay(dpy); psc->configs = NULL; - if (atof(priv->serverGLXversion) >= 1.3) { - GetReq(GLXGetFBConfigs, fb_req); - fb_req->reqType = priv->majorOpcode; - fb_req->glxCode = X_GLXGetFBConfigs; - fb_req->screen = screen; - } - else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) { - GetReqExtra(GLXVendorPrivateWithReply, - sz_xGLXGetFBConfigsSGIXReq - - sz_xGLXVendorPrivateWithReplyReq, vpreq); - sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; - sgi_req->reqType = priv->majorOpcode; - sgi_req->glxCode = X_GLXVendorPrivateWithReply; - sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; - sgi_req->screen = screen; + number = (GLfloat) _glXStrtof(priv->serverGLXversion, &end); + if (end && end > priv->serverGLXversion) { + if (number >= 1.3) { + GetReq(GLXGetFBConfigs, fb_req); + fb_req->reqType = priv->majorOpcode; + fb_req->glxCode = X_GLXGetFBConfigs; + fb_req->screen = screen; + } + else if (strstr(psc->serverGLXexts, "GLX_SGIX_fbconfig") != NULL) { + GetReqExtra(GLXVendorPrivateWithReply, + sz_xGLXGetFBConfigsSGIXReq - + sz_xGLXVendorPrivateWithReplyReq, vpreq); + sgi_req = (xGLXGetFBConfigsSGIXReq *) vpreq; + sgi_req->reqType = priv->majorOpcode; + sgi_req->glxCode = X_GLXVendorPrivateWithReply; + sgi_req->vendorCode = X_GLXvop_GetFBConfigsSGIX; + sgi_req->screen = screen; + } else + goto out; } else goto out; -- 1.7.2.3