Problems with embedding + extending

Aloysio Paiva de Figueiredo aloysio at impa.br
Thu Dec 5 07:55:34 EST 2002


The following (example) program aborts in the Py_Finalize() call. I can't
figure out why. Can anyone help me?

-------------------------------------------------------------------------
#include <Python.h>

static PyObject *alfa_out(PyObject *self, PyObject *args)
{
  char *s;

  if (!PyArg_ParseTuple(args, "s", &s)) {
    return NULL;
  }

  fprintf(stdout, s);
 
  return Py_None;
}

static PyMethodDef AlfaMethods[] = {
  {"out", alfa_out, METH_VARARGS, "Print something." },
  { NULL, NULL, 0, NULL}
};

void initalfa(void)
{
  Py_InitModule("alfa", AlfaMethods);
}

char test_program[] = 
"import alfa\n" \
" \n"\
"for i in range(10): \n" \
"  alfa.out(str(i) + '\\n') \n" \
" \n";

int main(void) {
  Py_Initialize();
  initalfa();

  printf(test_program);

  PyRun_SimpleString(test_program);

  Py_Finalize();
}
---------------------------------------------------------------------------------





More information about the Python-list mailing list