minor changes to _build_translations_cache(), remove unneeded NULL checks and use...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 21 Jan 2013 02:40:36 +0000 (02:40 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 21 Jan 2013 02:40:36 +0000 (02:40 +0000)
source/blender/python/intern/bpy_app_translations.c

index 6e9f12ec5292d1585ea26c259fb9999aba9bb8a4..8a7140cf79262a8ad1237dea350aa82d8b4d0103 100644 (file)
@@ -177,13 +177,21 @@ static void _build_translations_cache(PyObject *py_messages, const char *locale)
                                PyObject *tmp;
                                const char *msgctxt = NULL, *msgid = NULL;
 
-                               tmp = PyTuple_GetItem(pykey, 0);
-                               if (tmp && PyUnicode_Check(tmp) && !PyUnicode_READY(tmp)) {
-                                       msgctxt = (const char *)PyUnicode_AsUTF8(tmp);
+                               if ((PyTuple_CheckExact(pykey) == false) ||
+                                   (PyTuple_GET_SIZE(pykey) != 2) ||
+                                   (PyUnicode_Check(trans) == false))
+                               {
+                                       /* TODO, we should error here */
+                                       continue;
+                               }
+
+                               tmp = PyTuple_GET_ITEM(pykey, 0);
+                               if (PyUnicode_Check(tmp)) {
+                                       msgctxt = _PyUnicode_AsString(tmp);
                                }
-                               tmp = PyTuple_GetItem(pykey, 1);
-                               if (tmp && PyUnicode_Check(tmp) && !PyUnicode_READY(tmp)) {
-                                       msgid = (const char *)PyUnicode_AsUTF8(tmp);
+                               tmp = PyTuple_GET_ITEM(pykey, 1);
+                               if (PyUnicode_Check(tmp)) {
+                                       msgid = _PyUnicode_AsString(tmp);
                                }
 
                                if (!(msgctxt && msgid)) {
@@ -197,9 +205,7 @@ static void _build_translations_cache(PyObject *py_messages, const char *locale)
                                        continue;
                                }
 
-                               if (trans && PyUnicode_Check(trans) && !PyUnicode_READY(trans)) {
-                                       BLI_ghash_insert(_translations_cache, key, BLI_strdup((const char *)PyUnicode_AsUTF8(trans)));
-                               }
+                               BLI_ghash_insert(_translations_cache, key, BLI_strdup(_PyUnicode_AsString(trans)));
                        }
                }
        }