iD8DBQFI7y2SlVw7T9GIvRsRArcbAKCjmewtdkEiahPXTHhhCU My9D7NEgCfYTIQ dE7a69MTHmR / 3WUUSCzoSmc = = Outo ----- END PGP SIGNATURE ----- 解决方案 10月10日,5:24 * am,Gordon Allott< gordall ... @ gmail.comwrote: 你好:) 各种不兼容的结果让我需要某种方式 提取空指针指向的地址使用PyCObject_FromVoidPtr将$ 指针暴露给python 创建PyCObject的代码如下: * * tmp = PyCObject_FromVoidPtr(info.info.x11.display,NULL); * * PyDict_SetItemString(dict," display",tmp); * * Py_DECREF( tmp); 您是否尝试过: tmp = PyLong_FromLong((long)info.info.x11.display) ; PyDict_SetItemString(dict," display",tmp); Py_DECREF(tmp); 或者尝试: PyCObject_AsVoidPtr(tmp); Aaron" Castironpi" Brady写道: 你试过吗: tmp = PyLong_FromLong((long)info.info.x11.display) ; PyDict_SetItemString(dict," display",tmp); Py_DECREF(tmp); 或者尝试: PyCObject_AsVoidPtr(tmp); - http://mail.python.org/mailman/listinfo/python-list 问题是我不能编辑C代码 - 我可以并且可能 向项目提交补丁但我还需要一个解决方案,工作原理来自 the python事情的一面。 - Gord Allott(go********@gmail.com) --- --BEGIN PGP SIGNATURE ----- 版本:GnuPG v1.4.6(GNU / Linux) 评论:使用GnuPG和Mozilla - http://enigmail.mozdev.org iD8DBQFI74sQlVw7T9GIvRsRAtw + AJ4i0lte6DnzeJ6Nm + BbaY GUCDDEIQCeIW4m rlzxbYBLYI4j3hFceifTuLM = = nfIm ---- -END PGP SIGNATURE ----- 10月10日12:04 * pm,Gordon Allott< gordall ... @ gmail.comwrote : Aaron" Castironpi" Brady写道: 你试过: tmp = PyLong_FromLong((long) info.info.x11.display); PyDict_SetItemString(dict," display",tmp); Py_DECREF(tmp); 或者也可以尝试: PyCObject_AsVoidPtr(tmp); - http:/ /mail.python.org/mailman/listinfo/python-list 问题是我无法编辑C代码 - 我可以而且可能 向项目提交一个补丁,但是我还需要一个解决方案,它可以在 的python方面工作。 我明白了。如果我理解,你在字典中有一个PyCObject。 查看''ctypes''模块并尝试调用PyCObject_AsVoidPtr。它的返回类型应该是''c_void_p'',你可以使用''result.value''来获得原始指针。 Hello :)The result of various incompatibilities has left me needing to somehowextract the address that a null pointer is pointing to with the nullpointer being exposed to python via PyCObject_FromVoidPtrthe code that creates the PyCObject is as follows:tmp = PyCObject_FromVoidPtr (info.info.x11.display, NULL);PyDict_SetItemString (dict, "display", tmp);Py_DECREF (tmp);which is exposed to python via a dictionary (the ''display'' key). pythonidentifies that its a PyCObject but doesn''t give any way to expose thefunctionality. Essentially I am after the address that the void pointer''info.info.x11.display'' points to (as a long type)As far as I can tell ctypes will only expose the pyObject type to me andnot actually let me deal with the data I am after, but being rather newto ctypes I''m not sure weather this is correct.--Gord Allott (go********@gmail.com)-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.4.6 (GNU/Linux)Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.orgiD8DBQFI7y2SlVw7T9GIvRsRArcbAKCjmewtdkEiahPXTHhhCU My9D7NEgCfYTIQdE7a69MTHmR/3WUUSCzoSmc==Outo-----END PGP SIGNATURE----- 解决方案 On Oct 10, 5:24*am, Gordon Allott <gordall...@gmail.comwrote:Hello :)The result of various incompatibilities has left me needing to somehowextract the address that a null pointer is pointing to with the nullpointer being exposed to python via PyCObject_FromVoidPtrthe code that creates the PyCObject is as follows:* * tmp = PyCObject_FromVoidPtr (info.info.x11.display, NULL);* * PyDict_SetItemString (dict, "display", tmp);* * Py_DECREF (tmp);Did you try:tmp= PyLong_FromLong( ( long ) info.info.x11.display );PyDict_SetItemString (dict, "display", tmp);Py_DECREF (tmp);Or also try:PyCObject_AsVoidPtr( tmp );Aaron "Castironpi" Brady wrote:Did you try:tmp= PyLong_FromLong( ( long ) info.info.x11.display );PyDict_SetItemString (dict, "display", tmp);Py_DECREF (tmp);Or also try:PyCObject_AsVoidPtr( tmp );-- http://mail.python.org/mailman/listinfo/python-listthe problem is that I can''t edit the C code - well I can and mightsubmit a patch to the project but I also need a solution that works fromthe python side of things.--Gord Allott (go********@gmail.com)-----BEGIN PGP SIGNATURE-----Version: GnuPG v1.4.6 (GNU/Linux)Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.orgiD8DBQFI74sQlVw7T9GIvRsRAtw+AJ4i0lte6DnzeJ6Nm+BbaY GUCDDEIQCeIW4mrlzxbYBLYI4j3hFceifTuLM==nfIm-----END PGP SIGNATURE----- On Oct 10, 12:04*pm, Gordon Allott <gordall...@gmail.comwrote:Aaron "Castironpi" Brady wrote: Did you try: tmp= PyLong_FromLong( ( long ) info.info.x11.display ); PyDict_SetItemString (dict, "display", tmp); Py_DECREF (tmp); Or also try: PyCObject_AsVoidPtr( tmp ); -- http://mail.python.org/mailman/listinfo/python-listthe problem is that I can''t edit the C code - well I can and mightsubmit a patch to the project but I also need a solution that works fromthe python side of things.I see. If I understand, you have a PyCObject in a dictionary.Look at the ''ctypes'' module and try calling PyCObject_AsVoidPtr. Itsreturn type should be ''c_void_p'', and you can use ''result.value'' toget the original pointer. 这篇关于使用ctypes从PyCObject中提取空指针地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 02:01