-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinspect-descriptor.c
More file actions
38 lines (25 loc) · 1021 Bytes
/
inspect-descriptor.c
File metadata and controls
38 lines (25 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <Python.h>
#include "stdio.h"
PyTypeObject * create_type(const char * name){
PyObject * args, * dict, * value;
PyTypeObject * new_type;
args = PyTuple_New(3);
PyTuple_SetItem(args, 0, PyUnicode_FromString(name));
PyTuple_SetItem(args, 1, PyTuple_New(0));
dict = PyDict_New();
value = PyUnicode_FromString("haha");
PyDict_SetItem(dict, PyUnicode_FromString("__get__"), value);
PyTuple_SetItem(args, 2, dict);
new_type = (PyTypeObject *)PyType_Type.tp_new(&PyType_Type, args, NULL);
return new_type;
}
int main(int argc, char * argv[]){
PyTypeObject * new_type, * new_type1;
Py_Initialize();
new_type = create_type("MyType");
new_type1 = create_type("MyType1");
printf("new type name %s, %lx.\n", new_type->tp_name, (unsigned long)new_type->tp_descr_get);
printf("new type name %s, %lx.\n", new_type1->tp_name, (unsigned long)new_type1->tp_descr_get);
printf("type type name %s, %lx.\n", PyType_Type.tp_name, (unsigned long)PyType_Type.tp_descr_get);
return 0;
}