Embedding Python in C - Segfault
<p>From reading another <a href="https://stackoverflow.com/questions/13942128/how-to-pass-an-array-from-c-to-an-embedded-python-script">post</a>, I am trying to embbed some some Python code into C:</p>

<p><strong>main.c</strong></p>

<pre><code>#include &lt;Python.h&gt;

int callModuleFunc(int array[], size_t size) {
    PyObject *mymodule = PyImport_ImportModule("py_function");
    PyObject *myfunc = PyObject_GetAttrString(mymodule, "printlist");
    PyObject *mylist = PyList_New(size);
    for (size_t i = 0; i != size; ++i) {
        PyList_SET_ITEM(mylist, i, PyInt_FromLong(array[i]));
    }
    PyObject *arglist = Py_BuildValue("(o)", mylist);
    PyObject *result = PyObject_CallObject(myfunc, arglist);
    int retval = (int)PyInt_AsLong(result);
    Py_DECREF(result);
    Py_DECREF(arglist);
    Py_DECREF(mylist);
    Py_DECREF(myfunc);
    Py_DECREF(mymodule);
    return retval;
}

int main(int argc, char *argv[])
{
    int a[] = {1,2,3,4};
    callModuleFunc(a, 4);
    return 0;
}
</code></pre>

<p><strong>py_function.py</strong></p>

<pre><code>'''py_function.py - Python source designed to '''
'''demonstrate the use of python embedding'''

def printlist(mylist):
    print mylist
</code></pre>

<p>Then I compiled with:</p>

<pre><code>gcc main.c -I/usr/include/python2.7 -lpython2.7
</code></pre>

<p>But then I ran the app, it gives me a segmentation fault error:</p>

<pre><code>/a.out
[1]    18890 segmentation fault  ./a.out
</code></pre>

<p>Is there something that I am missing?</p>