2
我正在創建一個python c擴展,但在查找我想要做的文檔時遇到困難。我基本上想創建一個指向cstruct的指針,並能夠訪問該指針。示例代碼如下。任何幫助,將不勝感激。訪問PyObject的底層結構
typedef struct{
int x;
int y;
} Point;
typedef struct {
PyObject_HEAD
Point* my_point;
} PointObject;
static PyTypeObject PointType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
"point", /*tp_name*/
sizeof(PointObject), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
"point objects", /* tp_doc */
};
static PyObject* set_point(PyObject* self, PyObject* args)
{
PyObject* point;
if (!PyArg_ParseTuple(args, "O", &point))
{
return NULL;
}
//code to access my_point
}
亞歷克斯,我能得到我還是有點失落了如何做到這一點的來源。 – Pat 2010-08-09 01:23:31
OK,@user,我剛剛編輯我的A,以便根據您的要求添加源代碼。 – 2010-08-09 01:31:58