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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#include "fdisk.h"
static PyMemberDef Label_members[] = {
{ NULL }
};
static void Label_dealloc(LabelObject *self)
{
Py_TYPE(self)->tp_free((PyObject *) self);
}
static PyObject *Label_new(PyTypeObject *type,
PyObject *args __attribute__((unused)),
PyObject *kwds __attribute__((unused)))
{
LabelObject *self = (LabelObject*) type->tp_alloc(type, 0);
if (self) {
self->lb = NULL;
}
return (PyObject *)self;
}
#define Label_HELP "Label(context=None)"
static int Label_init(LabelObject *self, PyObject *args, PyObject *kwds)
{
ContextObject *cxt = NULL;
struct fdisk_label *lb;
char *kwlist[] = {
"context",
NULL
};
if (!PyArg_ParseTupleAndKeywords(args,
kwds, "|O!", kwlist,
&ContextType, &cxt)) {
PyErr_SetString(PyExc_TypeError, "Error");
return -1;
}
if (cxt && (lb = fdisk_get_label(cxt->cxt, NULL))) {
self->lb = lb;
}
return 0;
}
static PyMethodDef Label_methods[] = {
{NULL}
};
static PyObject *Label_get_type(LabelObject *self)
{
return PyLong_FromLong(fdisk_label_get_type(self->lb));
}
static PyObject *Label_get_name(LabelObject *self)
{
return PyObjectResultStr(fdisk_label_get_name(self->lb));
}
static PyGetSetDef Label_getseters[] = {
{"type", (getter)Label_get_type, NULL, "label type", NULL},
{"name", (getter)Label_get_name, NULL, "label name", NULL},
{NULL}
};
static PyObject *Label_repr(LabelObject *self)
{
return PyUnicode_FromFormat("<libfdisk.Label object at %p, name=%s>",
self, fdisk_label_get_name(self->lb));
}
PyTypeObject LabelType = {
PyVarObject_HEAD_INIT(NULL, 0)
"libfdisk.Label", /*tp_name*/
sizeof(LabelObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)Label_dealloc, /*tp_dealloc*/
0, /*tp_print*/
NULL, /*tp_getattr*/
NULL, /*tp_setattr*/
NULL, /*tp_compare*/
(reprfunc) Label_repr,
NULL, /*tp_as_number*/
NULL, /*tp_as_sequence*/
NULL, /*tp_as_mapping*/
NULL, /*tp_hash */
NULL, /*tp_call*/
NULL, /*tp_str*/
NULL, /*tp_getattro*/
NULL, /*tp_setattro*/
NULL, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
Label_HELP, /* tp_doc */
NULL, /* tp_traverse */
NULL, /* tp_clear */
NULL, /* tp_richcompare */
0, /* tp_weaklistoffset */
NULL, /* tp_iter */
NULL, /* tp_iternext */
Label_methods, /* tp_methods */
Label_members, /* tp_members */
Label_getseters, /* tp_getset */
NULL, /* tp_base */
NULL, /* tp_dict */
NULL, /* tp_descr_get */
NULL, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)Label_init, /* tp_init */
NULL, /* tp_alloc */
Label_new, /* tp_new */
};
PyObject *PyObjectResultLabel(struct fdisk_label *lb)
{
LabelObject *result;
if (!lb) {
PyErr_SetString(PyExc_AssertionError, "lb assert failed");
return NULL;
}
result = PyObject_New(LabelObject, &LabelType);
if (!result) {
PyErr_SetString(PyExc_MemoryError, "Couldn't allocate Label object");
return NULL;
}
/* Py_INCREF(result); */
result->lb = lb;
return (PyObject *) result;
}
void Label_AddModuleObject(PyObject *mod)
{
if (PyType_Ready(&LabelType) < 0)
return;
Py_INCREF(&LabelType);
PyModule_AddObject(mod, "Label", (PyObject *)&LabelType);
}
|