Rev 197: Fix bug #1080843, handle modules that don't have a proper name. in http://bazaar.launchpad.net/%2Bbranch/meliae

John Arbash Meinel john at arbash-meinel.com
Tue Nov 20 10:46:45 UTC 2012


At http://bazaar.launchpad.net/%2Bbranch/meliae

------------------------------------------------------------
revno: 197
revision-id: john at arbash-meinel.com-20121120104637-cg12pvmslmr9he6m
parent: john at arbash-meinel.com-20111101152557-za1zfbsgf1w7hpnt
fixes bug: https://launchpad.net/bugs/1080843
author: trbs <v.oostveen at gmail.com>
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: meliae
timestamp: Tue 2012-11-20 10:46:37 +0000
message:
  Fix bug #1080843, handle modules that don't have a proper name.
  Just treat it as empty, but don't segfault when you have one.
-------------- next part --------------
=== modified file 'meliae/_scanner_core.c'
--- a/meliae/_scanner_core.c	2010-08-10 00:58:56 +0000
+++ b/meliae/_scanner_core.c	2012-11-20 10:46:37 +0000
@@ -463,6 +463,7 @@
     Py_ssize_t size;
     int retval;
     int do_traverse;
+    char *name;
 
     if (info->nodump != NULL && 
         info->nodump != Py_None
@@ -498,8 +499,13 @@
     _write_to_ref_info(info, ", \"size\": " SSIZET_FMT, _size_of(c_obj));
     //  HANDLE __name__
     if (PyModule_Check(c_obj)) {
-        _write_static_to_info(info, ", \"name\": ");
-        _dump_json_c_string(info, PyModule_GetName(c_obj), -1);
+        name = PyModule_GetName(c_obj);
+        if (name == NULL) {
+            PyErr_Clear();
+        } else {
+            _write_static_to_info(info, ", \"name\": ");
+            _dump_json_c_string(info, name, -1);
+        }
     } else if (PyFunction_Check(c_obj)) {
         _write_static_to_info(info, ", \"name\": ");
         _dump_string(info, ((PyFunctionObject *)c_obj)->func_name);

=== modified file 'meliae/tests/test__scanner.py'
--- a/meliae/tests/test__scanner.py	2011-03-22 10:32:12 +0000
+++ b/meliae/tests/test__scanner.py	2012-11-20 10:46:37 +0000
@@ -544,6 +544,14 @@
         f = local_frame()
         self.assertDumpInfo(f)
 
+    def test_fakemodule(self):
+        class FakeModule(types.ModuleType):
+            def __init__(self, dct):
+                self.__tmp = None
+                del self.__tmp
+        fm = FakeModule({})
+        self.assertDumpInfo(fm)
+
 
 class TestGetReferents(tests.TestCase):
 



More information about the bazaar-commits mailing list