Skip to content

Instantly share code, notes, and snippets.

@ynkdir
Created January 24, 2014 12:34
Show Gist options
  • Save ynkdir/8596449 to your computer and use it in GitHub Desktop.
Save ynkdir/8596449 to your computer and use it in GitHub Desktop.
PyIter_Check() does not work when -Bsymbolic-functions is used.
// BUILD:
// cc `python-config --cflags` -o a.out test.c `python-config --ldflags`
// cc `python-config --cflags` -fPIE -o a-pie.out test.c `python-config --ldflags`
//
// PyIter_Check() does not work when -Bsymbolic-functions is used.
// On Ubuntu, -Bsymbolic-functions is included in compile flag.
// Workaround is -fPIE.
//
// https://bugs.launchpad.net/ubuntu/+source/python2.7/+bug/1196047
// https://groups.google.com/forum/?fromgroups=#!searchin/vim_dev/tests/vim_dev/CEaL812aLNI/aSuZ0Jin8BQJ
#include <Python.h>
static PyObject*
isiterator(PyObject *self, PyObject *args)
{
PyObject *o;
if(!PyArg_Parse(args, "O", &o))
return NULL;
return Py_BuildValue("i", PyIter_Check(o));
}
static PyMethodDef EmbMethods[] = {
{"isiterator", isiterator, METH_O, ""},
{NULL, NULL, 0, NULL}
};
int
main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
Py_InitModule("emb", EmbMethods);
PyRun_SimpleString("import emb\n"
"class C(object):\n"
" pass\n"
"if emb.isiterator(C()) == 0:\n"
" print('ok')\n"
"else:\n"
" print('ng')\n");
Py_Finalize();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment