Commits

Ronald Oussoren committed 8385146

Issue #109: environment variables

* Minor cleanup of the code that sets LC_CTYPE in the environment.

The variable is now only set when needed (that is, when
running Python 3 and there is no LC_CTYPE variable in the
environment)

* Rebuild the i386, x86_64 and intel binaries, the others still
have to be rebuild but I can't do that right now.

Comments (0)

Files changed (12)

doc/changelog.rst

 py2app 0.7.4
 ------------
 
+- The i386, x86_64 and intel stub binaries are now compiled with clang on OSX 10.8,
+  instead of an older version of GCC. The other stub versions still are compiled
+  on OSX 10.6.
+
 - Issue #111: The site.py generated by py2app now contains a USER_SITE variable
   (with a default value of ``None``) because some software tries to import the
   value.

py2app/apptemplate/prebuilt/main-i386

Binary file modified.

py2app/apptemplate/prebuilt/main-intel

Binary file modified.

py2app/apptemplate/prebuilt/main-x86_64

Binary file modified.

py2app/apptemplate/setup.py

         'name': 'main-x86_64',
         'target': '10.5',
         'cflags': '-g -isysroot / -arch x86_64',
-        'cc': 'gcc-4.2',
+        'cc': '/usr/bin/clang',
     },
     {
         'name': 'main-fat3',
         'name': 'main-intel',
         'target': '10.5',
         'cflags': '-g -isysroot / -arch i386 -arch x86_64',
-        'cc': 'gcc-4.2',
+        'cc': '/usr/bin/clang',
     },
     {
         'name': 'main-i386',
-        'target': '10.3',
-        'cflags': '-g -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386',
-        'cc': 'gcc-4.0',
+        'target': '10.4',
+        'cflags': '-g -isysroot / -arch i386',
+        'cc': '/usr/bin/clang',
     },
     {
         'name': 'main-ppc',

py2app/apptemplate/src/main.c

 #undef OPT_LOOKUP
 #undef LOOKUP
 
-    /*
-     * When apps are started from the Finder (or anywhere
-     * except from the terminal), the LANG and LC_* variables
-     * aren't set in the environment. This confuses Py_Initialize
-     * when it tries to import the codec for UTF-8,
-     * therefore explicitly set the locale.
-     *
-     * Also set the LC_CTYPE environment variable because Py_Initialize
-     * resets the locale information using the environment :-(
-     */
-    curlocale = setlocale(LC_ALL, NULL);
-    if (curlocale != NULL) {
-      curlocale = strdup(curlocale);
-      if (curlocale == NULL) {
-        (void)report_error("cannot save locale information");
-	return -1;
-      }
-    }
-    setlocale(LC_ALL, "en_US.UTF-8");
+    if (isPy3K) {
+	    /*
+	     * When apps are started from the Finder (or anywhere
+	     * except from the terminal), the LANG and LC_* variables
+	     * aren't set in the environment. This confuses Py_Initialize
+	     * when it tries to import the codec for UTF-8,
+	     * therefore explicitly set the locale.
+	     *
+	     * Also set the LC_CTYPE environment variable because Py_Initialize
+	     * resets the locale information using the environment :-(
+	     */
+	    curlocale = setlocale(LC_ALL, NULL);
+	    if (curlocale != NULL) {
+	      curlocale = strdup(curlocale);
+	      if (curlocale == NULL) {
+		(void)report_error("cannot save locale information");
+		return -1;
+	      }
+	    }
+	    setlocale(LC_ALL, "en_US.UTF-8");
 
-    curenv = getenv("LC_CTYPE");
-    if (curenv) {
-	curenv = strdup(curenv);
-	if (!curenv) {
-	    (void)report_error("cannot save LC_CTYPE");
-	}
-    }
-    setenv("LC_CTYPE", "en_US.UTF-8", 1);
+	    curenv = getenv("LC_CTYPE");
+	    if (curenv == NULL) {
+		setenv("LC_CTYPE", "en_US.UTF-8", 1);
+	    }
 
-    if (isPy3K) {
-    	wchar_t w_pythonInterpreter[PATH_MAX+1];
-    	mbstowcs(w_pythonInterpreter, c_pythonInterpreter, PATH_MAX+1);
-    	py2app_Py_SetProgramName((char*)w_pythonInterpreter);
+	    wchar_t w_pythonInterpreter[PATH_MAX+1];
+    	    mbstowcs(w_pythonInterpreter, c_pythonInterpreter, PATH_MAX+1);
+    	    py2app_Py_SetProgramName((char*)w_pythonInterpreter);
 
 
     } else {
     /*
      * Reset the environment and locale information
      */
-    if (curenv) {
-	    setenv("LC_CTYPE", curenv, 1);
-	    free(curenv);
-    } else {
-	    unsetenv("LC_CTYPE");
+    if (isPy3K) {
+	    if (curenv == NULL) {
+		unsetenv("LC_CTYPE");
+	    }
+
+	    setlocale(LC_CTYPE, curlocale);
+	    free(curlocale);
     }
 
-    setlocale(LC_CTYPE, curlocale);
-    free(curlocale);
-
     py2app_CFStringGetCString(
         mainScript, c_mainScript,
         sizeof(c_mainScript), kCFStringEncodingUTF8);

py2app/bundletemplate/prebuilt/main-i386

Binary file modified.

py2app/bundletemplate/prebuilt/main-intel

Binary file modified.

py2app/bundletemplate/prebuilt/main-x86_64

Binary file modified.

py2app/bundletemplate/setup.py

         'name': 'main-x86_64',
         'target': '10.5',
         'cflags': '-isysroot / -arch x86_64',
-        'cc': 'gcc-4.2',
+        'cc': 'clang',
     },
     {
         'name': 'main-fat3',
         'name': 'main-intel',
         'target': '10.5',
         'cflags': '-isysroot / -arch i386 -arch x86_64',
-        'cc': 'gcc-4.2',
+        'cc': 'clang',
     },
     {
         'name': 'main-i386',
         'target': '10.3',
         #'cflags': '-isysroot @@XCODE_ROOT@@/SDKs/MacOSX10.4u.sdk -arch i386',
-        'cflags': '-arch i386',
-        'cc': 'gcc-4.2',
+        'cflags': '-arch i386 -isysroot /',
+        'cc': 'clang',
     },
     {
         'name': 'main-ppc',

py2app/bundletemplate/src/main.m

      * Also set the LC_CTYPE environment variable because Py_Initialize
      * reset the locale information using the environment :-(
      */
-    curlocale = setlocale(LC_ALL, NULL);
-    if (curlocale != NULL) {
-	curlocale = strdup(curlocale);
-	if (curlocale == NULL) {
-		(void)report_error(ERR_CANNOT_SAVE_LOCALE);
-		return -1;
-	}
+    if (isPy3k) {
+        curlocale = setlocale(LC_ALL, NULL);
+        if (curlocale != NULL) {
+            curlocale = strdup(curlocale);
+            if (curlocale == NULL) {
+                    (void)report_error(ERR_CANNOT_SAVE_LOCALE);
+                    return -1;
+            }
+        }
+        setlocale(LC_ALL, "en_US.UTF-8");
+
+        curenv = getenv("LC_CTYPE");
+        if (!curenv) {
+            setenv("LC_CTYPE", "en_US.UTF-8", 1);
+        }
     }
-    setlocale(LC_ALL, "en_US.UTF-8");
-
-    curenv = getenv("LC_CTYPE");
-    if (curenv) {
-            curenv = strdup(curenv);
-    }
-
 
 
     // Set up the environment variables to be transferred
     Py_Initialize();
     PyEval_InitThreads();
 
-    /*
-     * Reset the environment and locale information
-     */
-    setlocale(LC_CTYPE, curlocale);
-    free(curlocale);
+    if (isPy3k) {
+        /*
+         * Reset the environment and locale information
+         */
+        setlocale(LC_CTYPE, curlocale);
+        free(curlocale);
 
-    if (curenv) {
-	setenv("LC_CTYPE", curenv, 1);
-        free(curenv);
-    } else {
-        unsetenv("LC_CTYPE");
+        if (!curenv) {
+            unsetenv("LC_CTYPE");
+        }
     }
 
 

py2app_tests/test_lsenvironment.py

         self.assertEqual(env['KNIGHT'], 'ni!')
         self.assertEqual(env['EXTRA_VAR'], 'hello world')
         self.assertEqual(env['LANG'], 'nl_NL.latin1')
-        self.assertEqual(env['LC_CTYPE'], 'nl_NL.utf-8')
+        self.assertEqual(env['LC_CTYPE'], 'nl_NL.UTF-8')
 
 if __name__ == "__main__":
     unittest.main()