使用ctypes从PyCObject中提取空指针地址 [英] extracting null pointer address from PyCObject with ctypes
问题描述
你好:)
各种不兼容的结果让我需要某种方式
提取空指针指向的地址为null
指针通过pyCObject_FromVoidPtr暴露给python
创建PyCObject的代码如下:
tmp = PyCObject_FromVoidPtr(info .info.x11.display,NULL);
PyDict_SetItemString(dict," display",tmp);
Py_DECREF(tmp);
>
通过字典(''display''键)暴露给python。 python
标识它是一个PyCObject但是没有给出任何方式来公开
功能。基本上我是在地址之后,无效指针
''info.info.x11.display''指向(作为长型)
As我可以告诉ctypes只会向我公开pyObject类型和
实际上并没有让我处理我之后的数据,而是相当新的
到ctypes我我不确定天气是否正确。
-
Gord Allott(去******** @ gmail.com)< br $>
----- BEGIN PGP SIGNATURE -----
版本:GnuPG v1.4.6(GNU / Linux)
评论:使用GnuPG与Mozilla合作 - http://enigmail.mozdev.org
>
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 somehow
extract the address that a null pointer is pointing to with the null
pointer being exposed to python via PyCObject_FromVoidPtr
the 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). python
identifies that its a PyCObject but doesn''t give any way to expose the
functionality. 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 and
not actually let me deal with the data I am after, but being rather new
to 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.org
iD8DBQFI7y2SlVw7T9GIvRsRArcbAKCjmewtdkEiahPXTHhhCU My9D7NEgCfYTIQ
dE7a69MTHmR/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 somehow
extract the address that a null pointer is pointing to with the null
pointer being exposed to python via PyCObject_FromVoidPtr
the 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 might
submit a patch to the project but I also need a solution that works from
the 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.org
iD8DBQFI74sQlVw7T9GIvRsRAtw+AJ4i0lte6DnzeJ6Nm+BbaY GUCDDEIQCeIW4m
rlzxbYBLYI4j3hFceifTuLM=
=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-list
the problem is that I can''t edit the C code - well I can and might
submit a patch to the project but I also need a solution that works from
the 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. Its
return type should be ''c_void_p'', and you can use ''result.value'' to
get the original pointer.
这篇关于使用ctypes从PyCObject中提取空指针地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!