[MOAB-dev] r3139 - MOAB/trunk/tools/iMesh/python

jvporter at wisc.edu jvporter at wisc.edu
Mon Sep 14 18:47:29 CDT 2009


Author: jvporter
Date: 2009-09-14 18:47:29 -0500 (Mon, 14 Sep 2009)
New Revision: 3139

Modified:
   MOAB/trunk/tools/iMesh/python/iBase_Python.h
   MOAB/trunk/tools/iMesh/python/iMesh.c
   MOAB/trunk/tools/iMesh/python/iMesh_Python.h
Log:
Finalize C/C++ API for iMesh


Modified: MOAB/trunk/tools/iMesh/python/iBase_Python.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/iBase_Python.h	2009-09-14 22:50:22 UTC (rev 3138)
+++ MOAB/trunk/tools/iMesh/python/iBase_Python.h	2009-09-14 23:47:29 UTC (rev 3139)
@@ -81,7 +81,7 @@
 #define NPY_IBASETAG        (*(int*)         IBase_API[5])
 
 
-#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)
+#if !defined(NO_IMPORT_IBASE) && !defined(NO_IMPORT)
 static int import_iBase(void)
 {
     PyObject *module = PyImport_ImportModule("itaps.iBase");

Modified: MOAB/trunk/tools/iMesh/python/iMesh.c
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh.c	2009-09-14 22:50:22 UTC (rev 3138)
+++ MOAB/trunk/tools/iMesh/python/iMesh.c	2009-09-14 23:47:29 UTC (rev 3139)
@@ -1,3 +1,4 @@
+#define _IMESH_MODULE
 #include "errors.h"
 #include "common.h"
 #include "iMesh_Python.h"
@@ -6,10 +7,10 @@
 static enum iBase_TagValueType char_to_type(char c);
 static char type_to_char(enum iBase_TagValueType t);
 
+static PyTypeObject iMesh_Type;
 static PyTypeObject iMeshIter_Type;
 static PyTypeObject iMeshEntitySet_Type;
 static int NPY_IMESHENTSET;
-
 static PyTypeObject iMeshTag_Type;
 static int NPY_IMESHTAG;
 
@@ -1080,6 +1081,24 @@
     import_array();
     import_iBase();
 
+    /***** register C API *****/
+    static void *IMesh_API[6];
+    PyObject *api_obj;
+
+    /* Initialize the C API pointer array */
+    IMesh_API[0] = &iMesh_Type;
+    IMesh_API[1] = &iMeshIter_Type;
+    IMesh_API[2] = &iMeshEntitySet_Type;
+    IMesh_API[3] = &NPY_IMESHENTSET;
+    IMesh_API[4] = &iMeshTag_Type;
+    IMesh_API[5] = &NPY_IMESHTAG;
+
+    /* Create a CObject containing the API pointer array's address */
+    api_obj = PyCObject_FromVoidPtr(IMesh_API,NULL);
+
+    if(api_obj != NULL)
+        PyModule_AddObject(m, "_C_API", api_obj);
+
     /***** import helper module *****/
     if( (g_helper_module = PyImport_ImportModule("itaps.helpers")) == NULL)
         return;

Modified: MOAB/trunk/tools/iMesh/python/iMesh_Python.h
===================================================================
--- MOAB/trunk/tools/iMesh/python/iMesh_Python.h	2009-09-14 22:50:22 UTC (rev 3138)
+++ MOAB/trunk/tools/iMesh/python/iMesh_Python.h	2009-09-14 23:47:29 UTC (rev 3139)
@@ -60,6 +60,60 @@
     ( ((iMeshTag_Object*)(o))->mesh )
 
 
+#ifndef _IMESH_MODULE
+
+#if defined(PY_IMESH_UNIQUE_SYMBOL)
+#define IMesh_API PY_IMESH_UNIQUE_SYMBOL
+#endif
+
+#if defined(NO_IMPORT) || defined(NO_IMPORT_IMESH)
+extern void **IMesh_API;
+#elif defined(PY_IMESH_UNIQUE_SYMBOL)
+void **IMesh_API;
+#else
+static void **IMesh_API = NULL;
+#endif
+
+#define iMesh_Type          (*(PyTypeObject*)IMesh_API[0])
+#define iMeshIter_Type      (*(PyTypeObject*)IMesh_API[1])
+#define iMeshEntitySet_Type (*(PyTypeObject*)IMesh_API[2])
+#define NPY_IMESHENTSET     (*(int*)         IMesh_API[3])
+#define iMeshTag_Type       (*(PyTypeObject*)IMesh_API[4])
+#define NPY_IMESHTAG        (*(int*)         IMesh_API[5])
+
+
+
+#if !defined(NO_IMPORT_IMESH) && !defined(NO_IMPORT)
+static int import_iMesh(void)
+{
+    PyObject *module = PyImport_ImportModule("itaps.iMesh");
+    PyObject *c_api = NULL;
+
+    if(module == NULL)
+        return -1;
+
+    c_api = PyObject_GetAttrString(module,"_C_API");
+    if(c_api == NULL)
+    {
+        Py_DECREF(module);
+        return -2;
+    }
+
+    if(PyCObject_Check(c_api))
+        IMesh_API = (void **)PyCObject_AsVoidPtr(c_api);
+
+    Py_DECREF(c_api);
+    Py_DECREF(module);
+
+    if(IMesh_API == NULL)
+        return -3;
+    return 0;
+}
+#endif
+
+#endif
+
+
 #ifdef __cplusplus
 } // extern "C"
 #endif



More information about the moab-dev mailing list