key.c: Populate `KeyDataStructured' from the keywords.
[catacomb-python] / catacomb.c
index c1e91ff..d994347 100644 (file)
@@ -44,7 +44,6 @@ PyObject *mexp_common(PyObject *me, PyObject *arg,
 
   if (PyTuple_GET_SIZE(arg) == 1)
     arg = PyTuple_GET_ITEM(arg, 0);
-  Py_INCREF(arg);
   if (!PySequence_Check(arg)) TYERR("not a sequence");
   n = PySequence_Size(arg); if (n < 0) goto end;
   if (!n) { z = id(me); goto end; }
@@ -93,7 +92,6 @@ end:
       drop(vv);
     xfree(v);
   }
-  Py_DECREF(arg);
   return (z);
 }
 
@@ -321,7 +319,22 @@ static void init_random(void)
 #endif
 }
 
-EXPORT void init_base(void)
+#ifdef PY3
+static PyModuleDef moddef = {
+  PyModuleDef_HEAD_INIT,
+  "catacomb._base",                    /* @m_name@ */
+  "Low-level module for Catacomb bindings.  Use `catacomb' instead.",
+                                       /* @m_doc@ */
+  0,                                   /* @m_size@ */
+  0,                                   /* @m_methods@ */
+  0,                                   /* @m_slots@ */
+  0,                                   /* @m_traverse@ */
+  0,                                   /* @m_clear@ */
+  0                                    /* @m_free@ */
+};
+#endif
+
+EXPORT PyMODINIT_FUNC PY23(init_base, PyInit__base)(void)
 {
   PyObject *mod;
 
@@ -330,10 +343,18 @@ EXPORT void init_base(void)
   INIT_MODULES;
   INITTYPE(thingtab, root);
   init_random();
+#ifdef PY3
+  moddef.m_methods = donemethods();
+  mod = PyModule_Create(&moddef);
+#else
   mod = Py_InitModule("catacomb._base", donemethods());
+#endif
   INSERT_MODULES;
   INSERT("_MiscTable", thingtab_pytype);
   INSERT("smallprimes", smallprimes());
+#ifdef PY3
+  return (mod);
+#endif
 }
 
 /*----- That's all, folks -------------------------------------------------*/