[Python-Dev] pycapsule:PyObject * is NULL pointer

赵亚 zhaoya881010 at 163.com
Tue Feb 20 21:28:55 EST 2018

i have question:call,c-->python-->c. 
1.the c pointer void* abc="123" by pycapsule in the c code.
void* lpContext = "abc";
PyObject * lpPyContext = PyCapsule_New(lpContext, "Context",NULL);
PyTuple_SetItem(pArgs, 1, lpPyContext);
PyObject* pyResult = PyObject_CallObject(pFunc, pArgs);

2.c call python:

in the python code:
import ctypes
pycapsule = ctypes.windll.LoadLibrary("C:\Users\zhaoya16975\Documents\Visual Studio 2017\Projects\cpython\Release\pycapsule.dll")
def test( lpContext,lpRequest,lpAnswer):
    print lpContext
the lpContest is "<capsule object "Context" at 0x02747e00>"
but,i can't lpContext in the pycapsule.GetContest:
the capsule is null poniter,the GetContext no execute!!

void* FUNCTION_CALL_MODE GetContext(PyObject  *capsule) {
		printf(" GetContext......\n");
		//if (!PyCapsule_IsValid((PyObject *)capsule, "Context")) {
		//	printf(" the Capsule Context is no Valid\n");
		//	return NULL;
		//return PyCapsule_GetPointer((PyObject *)capsule, "Context");
		return NULL;

FUNCTION_CALL_MODE is __stdcall i think no problem.because, if GetContext(PyObject  *capsule) -->GetContext() is ok. PyObject  *capsule from python to c unknown error occurred.
i hope c call python pass void* ,and python call c pass void* ,but the capsule call no success?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/68e45c95/attachment-0001.html>

More information about the Python-Dev mailing list