This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pycapsule:PyObject * is NULL pointer
Type: crash Stage: resolved
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, paul.moore, steve.dower, tim.golden, zach.ware, zhaoya
Priority: normal Keywords:

Created on 2018-02-20 04:48 by zhaoya, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg312399 - (view) Author: zhaoya (zhaoya) Date: 2018-02-20 04:48
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
    pycapsule.hello()
    pycapsule.GetContext(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;
		
	}


i hope c call python  pass void* ,and python call c pass void* ,but the capsule call no success.
msg312425 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-02-20 18:02
What is the definition of FUNCTION_CALL_MODE? And if it is anything other than "stdcall", change "ctypes.windll" to "ctypes.cdll" and try again.

You should also consider posting this to python-list, as it is almost certainly a problem in your DLL and not in Python itself.
msg312452 - (view) Author: zhaoya (zhaoya) Date: 2018-02-21 01:59
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.
msg401309 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-09-07 16:56
Python 2.7 is no longer maintained. If you are seeing this problem on a new version (>= 3.9), please create a new issue with full instructions how to reproduce it.
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77062
2021-09-07 16:56:06iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg401309

resolution: out of date
stage: resolved
2018-02-21 01:59:50zhaoyasetmessages: + msg312452
2018-02-20 18:02:35steve.dowersetmessages: + msg312425
2018-02-20 04:48:12zhaoyacreate