1

I am on integration of a c library to python application. and i need to pass a list of variables from python size to a wrapper of C lib(which i am calling) just for understanding, i have written a small program:
After loading shared lib in python app. In Python side:

 c_args = [5,6]
 PyPrintVal(c_args)

In C side:

PyPrintVal(PyObject *c_args)
{
 int i=0;
 int j=0;
 printf("In eINoiseRemoval\n");
 if (!PyArg_ParseTuple(c_args, "ii", &i,&j))
 { fprintf(stderr, "error in parsing\n");
 return -1;
 }
 printf(i1=%d j=%d\n, i,j)
}

then I am getting segmentation fault ? Is there anything left?
for that i am looking http://docs.python.org/2/extending/extending.html#a-simple-example

but not getting any answer. Thanks

asked Oct 8, 2013 at 9:10
4
  • Call PyPrintVal(*c_args). Commented Oct 8, 2013 at 9:12
  • I mean: call PyPrintVal(*c_args) in python side. Commented Oct 8, 2013 at 9:21
  • right ctypes. from ctypes import * ; handle=CDLL( "example.so" ); PyPrintVal=handle.PyPrintVal; PyPrintVal.argtypes = [py_object] Commented Oct 8, 2013 at 9:27
  • thanks falsetru, done !! by PyList_GetItem(,) call. Commented Oct 8, 2013 at 12:41

1 Answer 1

1

You can use gdb to find out exactly where this segfault is:

$ gdb python
......
> set args my_python_script.py
> run
.......
Segmentation Fault
> where

This will give you a stack trace and point you to the exact location of the segfault.

answered Oct 8, 2013 at 9:28
Sign up to request clarification or add additional context in comments.

1 Comment

and now it looks like this i = PyInt_AsLong(PyList_GetItem(c_Arg, 0)); i = PyInt_AsLong(PyList_GetItem(c_Arg, 0)); printf(i=%d j=%d\n, i,j); output i=5 j=6

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.