访问对象内部结构中的指针
我正在使用 OpenSSL 库的 pyOpenSSL 接口,但它缺少我需要的一些功能,并且我不能或不想修改它以支持这些方法(出于各种原因)。
所以我想要实现的是检索 OpenSSL 对象指针。 之后,我将能够通过 ctypes 调用缺少的函数。 最好的方法是什么?
我已经发现我可以使用 id() 来获取指向 pyOpenSSL 对象的指针。 我怎样才能访问 ssl 变量呢?
来自 pyOpenSSL/connections.h:
typedef struct {
PyObject_HEAD
SSL *ssl;
ssl_ContextObj *context;
PyObject *socket;
PyThreadState *tstate;
PyObject *app_data;
} ssl_ConnectionObj;
I'm using the pyOpenSSL interface to the OpenSSL library but it is missing some functions I need and I can't or don't want to modify it to support these methods (for various reasons).
So what I want to achieve, is to retrieve the OpenSSL object pointer. After that, I will be able to call the missing functions through ctypes. What is the best method to do that ?
I have already found that I can use id() to get the pointer to the pyOpenSSL object. How can I access the ssl variable with that.
From pyOpenSSL/connections.h:
typedef struct {
PyObject_HEAD
SSL *ssl;
ssl_ContextObj *context;
PyObject *socket;
PyThreadState *tstate;
PyObject *app_data;
} ssl_ConnectionObj;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
指针在 Python 中并没有多大意义,因为你不能用它们做任何事情。 它们只是一个整数。 正如您所注意到的,您可以使用 id 方法获取对象的地址。 但这就是地址。 它不是一个指针,所以你不能用它做任何事情。
你也可以这样看:Python 中的一切都是指针。 pyOpenSSL 对象的变量是指针。 但它是指向 pyOpenSSL 对象的指针,而不是指向连接结构的指针。 您不太可能直接访问该结构。
所以你必须告诉我们你想做什么。 也许还有另一种解决方案。
Pointers doesn't really make much sense in Python, as you can't do anything with them. They would just be an integer. As you have noticed you can get the address of an object with the id method. But that's just what it is, the address. It's not a pointer, so you can't do anything with it.
You could also see it like this: Everything in Python are pointers. The variable you have for the pyOpenSSL object is the pointer. But it is the pointer to the pyOpenSSL-object, not to the connection structure. It's unlikely you can access that structure directly.
So you have to tell us what you want to do instead. Maybe there is another solution.