| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <common.h> |
| 23 |
#include <types.h> |
| 24 |
|
| 25 |
#if defined( HAVE_STDLIB_H ) || defined( HAVE_WINAPI ) |
| 26 |
#include <stdlib.h> |
| 27 |
#endif |
| 28 |
|
| 29 |
#include "pyvhdi_disk_types.h" |
| 30 |
#include "pyvhdi_libvhdi.h" |
| 31 |
#include "pyvhdi_python.h" |
| 32 |
#include "pyvhdi_unused.h" |
| 33 |
|
| 34 |
PyTypeObject pyvhdi_disk_types_type_object = { |
| 35 |
PyVarObject_HEAD_INIT( NULL, 0 ) |
| 36 |
|
| 37 |
|
| 38 |
"pyvhdi.disk_types", |
| 39 |
|
| 40 |
sizeof( pyvhdi_disk_types_t ), |
| 41 |
|
| 42 |
0, |
| 43 |
|
| 44 |
(destructor) pyvhdi_disk_types_free, |
| 45 |
|
| 46 |
0, |
| 47 |
|
| 48 |
0, |
| 49 |
|
| 50 |
0, |
| 51 |
|
| 52 |
0, |
| 53 |
|
| 54 |
0, |
| 55 |
|
| 56 |
0, |
| 57 |
|
| 58 |
0, |
| 59 |
|
| 60 |
0, |
| 61 |
|
| 62 |
0, |
| 63 |
|
| 64 |
0, |
| 65 |
|
| 66 |
0, |
| 67 |
|
| 68 |
0, |
| 69 |
|
| 70 |
0, |
| 71 |
|
| 72 |
0, |
| 73 |
|
| 74 |
Py_TPFLAGS_DEFAULT, |
| 75 |
|
| 76 |
"pyvhdi disk types object (wraps LIBVHDI_DISK_TYPES)", |
| 77 |
|
| 78 |
0, |
| 79 |
|
| 80 |
0, |
| 81 |
|
| 82 |
0, |
| 83 |
|
| 84 |
0, |
| 85 |
|
| 86 |
0, |
| 87 |
|
| 88 |
0, |
| 89 |
|
| 90 |
0, |
| 91 |
|
| 92 |
0, |
| 93 |
|
| 94 |
0, |
| 95 |
|
| 96 |
0, |
| 97 |
|
| 98 |
0, |
| 99 |
|
| 100 |
0, |
| 101 |
|
| 102 |
0, |
| 103 |
|
| 104 |
0, |
| 105 |
|
| 106 |
(initproc) pyvhdi_disk_types_init, |
| 107 |
|
| 108 |
0, |
| 109 |
|
| 110 |
0, |
| 111 |
|
| 112 |
0, |
| 113 |
|
| 114 |
0, |
| 115 |
|
| 116 |
NULL, |
| 117 |
|
| 118 |
NULL, |
| 119 |
|
| 120 |
NULL, |
| 121 |
|
| 122 |
NULL, |
| 123 |
|
| 124 |
NULL, |
| 125 |
|
| 126 |
0 |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
int pyvhdi_disk_types_init_type( |
| 133 |
PyTypeObject *type_object ) |
| 134 |
{ |
| 135 |
PyObject *value_object = NULL; |
| 136 |
|
| 137 |
if( type_object == NULL ) |
| 138 |
{ |
| 139 |
return( -1 ); |
| 140 |
} |
| 141 |
type_object->tp_dict = PyDict_New(); |
| 142 |
|
| 143 |
if( type_object->tp_dict == NULL ) |
| 144 |
{ |
| 145 |
return( -1 ); |
| 146 |
} |
| 147 |
#if PY_MAJOR_VERSION >= 3 |
| 148 |
value_object = PyLong_FromLong( |
| 149 |
LIBVHDI_DISK_TYPE_FIXED ); |
| 150 |
#else |
| 151 |
value_object = PyInt_FromLong( |
| 152 |
LIBVHDI_DISK_TYPE_FIXED ); |
| 153 |
#endif |
| 154 |
if( PyDict_SetItemString( |
| 155 |
type_object->tp_dict, |
| 156 |
"FIXED", |
| 157 |
value_object ) != 0 ) |
| 158 |
{ |
| 159 |
goto on_error; |
| 160 |
} |
| 161 |
#if PY_MAJOR_VERSION >= 3 |
| 162 |
value_object = PyLong_FromLong( |
| 163 |
LIBVHDI_DISK_TYPE_DYNAMIC ); |
| 164 |
#else |
| 165 |
value_object = PyInt_FromLong( |
| 166 |
LIBVHDI_DISK_TYPE_DYNAMIC ); |
| 167 |
#endif |
| 168 |
if( PyDict_SetItemString( |
| 169 |
type_object->tp_dict, |
| 170 |
"DYNAMIC", |
| 171 |
value_object ) != 0 ) |
| 172 |
{ |
| 173 |
goto on_error; |
| 174 |
} |
| 175 |
#if PY_MAJOR_VERSION >= 3 |
| 176 |
value_object = PyLong_FromLong( |
| 177 |
LIBVHDI_DISK_TYPE_DIFFERENTIAL ); |
| 178 |
#else |
| 179 |
value_object = PyInt_FromLong( |
| 180 |
LIBVHDI_DISK_TYPE_DIFFERENTIAL ); |
| 181 |
#endif |
| 182 |
if( PyDict_SetItemString( |
| 183 |
type_object->tp_dict, |
| 184 |
"DIFFERENTIAL", |
| 185 |
value_object ) != 0 ) |
| 186 |
{ |
| 187 |
goto on_error; |
| 188 |
} |
| 189 |
return( 1 ); |
| 190 |
|
| 191 |
on_error: |
| 192 |
if( type_object->tp_dict != NULL ) |
| 193 |
{ |
| 194 |
Py_DecRef( |
| 195 |
type_object->tp_dict ); |
| 196 |
|
| 197 |
type_object->tp_dict = NULL; |
| 198 |
} |
| 199 |
return( -1 ); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
PyObject *pyvhdi_disk_types_new( |
| 206 |
void ) |
| 207 |
{ |
| 208 |
pyvhdi_disk_types_t *definitions_object = NULL; |
| 209 |
static char *function = "pyvhdi_disk_types_new"; |
| 210 |
|
| 211 |
definitions_object = PyObject_New( |
| 212 |
struct pyvhdi_disk_types, |
| 213 |
&pyvhdi_disk_types_type_object ); |
| 214 |
|
| 215 |
if( definitions_object == NULL ) |
| 216 |
{ |
| 217 |
PyErr_Format( |
| 218 |
PyExc_MemoryError, |
| 219 |
"%s: unable to create definitions object.", |
| 220 |
function ); |
| 221 |
|
| 222 |
goto on_error; |
| 223 |
} |
| 224 |
if( pyvhdi_disk_types_init( |
| 225 |
definitions_object ) != 0 ) |
| 226 |
{ |
| 227 |
PyErr_Format( |
| 228 |
PyExc_MemoryError, |
| 229 |
"%s: unable to initialize definitions object.", |
| 230 |
function ); |
| 231 |
|
| 232 |
goto on_error; |
| 233 |
} |
| 234 |
return( (PyObject *) definitions_object ); |
| 235 |
|
| 236 |
on_error: |
| 237 |
if( definitions_object != NULL ) |
| 238 |
{ |
| 239 |
Py_DecRef( |
| 240 |
(PyObject *) definitions_object ); |
| 241 |
} |
| 242 |
return( NULL ); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
int pyvhdi_disk_types_init( |
| 249 |
pyvhdi_disk_types_t *definitions_object ) |
| 250 |
{ |
| 251 |
static char *function = "pyvhdi_disk_types_init"; |
| 252 |
|
| 253 |
if( definitions_object == NULL ) |
| 254 |
{ |
| 255 |
PyErr_Format( |
| 256 |
PyExc_TypeError, |
| 257 |
"%s: invalid definitions object.", |
| 258 |
function ); |
| 259 |
|
| 260 |
return( -1 ); |
| 261 |
} |
| 262 |
return( 0 ); |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
void pyvhdi_disk_types_free( |
| 268 |
pyvhdi_disk_types_t *definitions_object ) |
| 269 |
{ |
| 270 |
struct _typeobject *ob_type = NULL; |
| 271 |
static char *function = "pyvhdi_disk_types_free"; |
| 272 |
|
| 273 |
if( definitions_object == NULL ) |
| 274 |
{ |
| 275 |
PyErr_Format( |
| 276 |
PyExc_TypeError, |
| 277 |
"%s: invalid definitions object.", |
| 278 |
function ); |
| 279 |
|
| 280 |
return; |
| 281 |
} |
| 282 |
ob_type = Py_TYPE( |
| 283 |
definitions_object ); |
| 284 |
|
| 285 |
if( ob_type == NULL ) |
| 286 |
{ |
| 287 |
PyErr_Format( |
| 288 |
PyExc_ValueError, |
| 289 |
"%s: missing ob_type.", |
| 290 |
function ); |
| 291 |
|
| 292 |
return; |
| 293 |
} |
| 294 |
if( ob_type->tp_free == NULL ) |
| 295 |
{ |
| 296 |
PyErr_Format( |
| 297 |
PyExc_ValueError, |
| 298 |
"%s: invalid ob_type - missing tp_free.", |
| 299 |
function ); |
| 300 |
|
| 301 |
return; |
| 302 |
} |
| 303 |
ob_type->tp_free( |
| 304 |
(PyObject*) definitions_object ); |
| 305 |
} |
| 306 |
|