hi @MRAB i try again,it not ok. test files: 1.cpython.cpp ---c call python maintenance.py 2.maintenance.py python maintenance.py call pycapsule.cpp(dll) the code file,see attachment. At 2018-02-21 11:18:18, "MRAB" <python at mrabarnett.plus.com> wrote: >On 2018-02-21 02:28, 赵亚 wrote: > >This "python-dev" list is for development of the Python language itself. >I think that this message should instead have been sent to "python-list". > >> 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); >> ...... > >Is this C code calling the function 'test' in the Python code? > >If yes, are you sure that lpPyContext should be in pArgs at index 1 and >not at index 0? > >The function 'test' expects argument 0 => lpContext, argument 1 => >lpRequest, argument 2 => lpAnswer. > >> 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; >> >> } >> >> 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? >> >_______________________________________________ >Python-Dev mailing list >Python-Dev at python.org >https://mail.python.org/mailman/listinfo/python-dev >Unsubscribe: https://mail.python.org/mailman/options/python-dev/zhaoya881010%40163.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/097f7fd5/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: maintenance.py Type: application/octet-stream Size: 512 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/097f7fd5/attachment.obj> -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: cpython.cpp URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/097f7fd5/attachment.ksh> -------------- next part -------------- A non-text attachment was scrubbed... Name: cpython.h Type: application/octet-stream Size: 208 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/097f7fd5/attachment-0001.obj> -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: pycapsule.cpp URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/097f7fd5/attachment-0001.ksh> -------------- next part -------------- A non-text attachment was scrubbed... Name: pycapsule.def Type: application/octet-stream Size: 160 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/097f7fd5/attachment-0002.obj> -------------- next part -------------- A non-text attachment was scrubbed... Name: pycapsule.h Type: application/octet-stream Size: 566 bytes Desc: not available URL: <http://mail.python.org/pipermail/python-dev/attachments/20180221/097f7fd5/attachment-0003.obj>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4