Commit b4415d5c authored by Berk Onat's avatar Berk Onat

Fixed numpy initialization bug at C functions.

parent f3504d61
......@@ -38,7 +38,12 @@ molfile_plugin_t** plugin_list;
#define PyInt_AsLong PyLong_AsLong
#define PyString_FromString PyBytes_FromString
#define PyInt_FromLong PyLong_FromLong
int initNumpyArray(void){
if(PyArray_API == NULL)
{
import_array();
}
}
void del_molfile_plugin_list(PyObject* molcapsule)
{
plugin_list = (molfile_plugin_t**) PyMolfileCapsule_AsVoidPtr(molcapsule);
......@@ -52,6 +57,12 @@ void del_molfile_file_handle(PyObject* molcapsule)
Py_XDECREF(molcapsule);
}
#else
void initNumpyArray(void){
if(PyArray_API == NULL)
{
import_array();
}
}
void del_molfile_plugin_list(void* molcapsule)
{
plugin_list = (molfile_plugin_t**) PyMolfileCapsule_AsVoidPtr((PyObject*)molcapsule);
......@@ -201,7 +212,7 @@ PyObject * molfile_plugin_info(PyObject* molcapsule, int plugin_no) {
PyObject* read_fill_structure(PyObject* molpack, PyObject* prototype)
{
//Py_Initialize();
import_array();
initNumpyArray();
int options = 0;
molfile_plugin_t* plugin;
void* file_handle;
......@@ -264,7 +275,7 @@ PyObject* read_fill_structure(PyObject* molpack, PyObject* prototype)
PyObject* read_fill_bonds(PyObject* molpack)
{
import_array();
initNumpyArray();
int options = 0;
molfile_plugin_t* plugin;
void* file_handle;
......@@ -359,7 +370,7 @@ PyObject* read_fill_bonds(PyObject* molpack)
PyObject* read_fill_angles(PyObject* molpack)
{
import_array();
initNumpyArray();
int options = 0;
molfile_plugin_t* plugin;
void* file_handle;
......@@ -558,7 +569,7 @@ PyObject* read_fill_angles(PyObject* molpack)
PyObject* read_fill_next_timestep(PyObject* molpack)
{
import_array();
initNumpyArray();
molfile_plugin_t* plugin;
void* file_handle;
int numatoms, status;
......
......@@ -22,6 +22,12 @@ extern "C"
#endif
#if PY_VERSION_HEX >= 0x03000000
#define NUMPY_IMPORT_ARRAY_RETVAL NULL
#else
#define NUMPY_IMPORT_ARRAY_RETVAL
#endif
#include "molfile_plugin.h"
#include "libmolfile_plugin.h"
#include "vmdplugin.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment