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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
|
/** \ingroup python
* \file python/rpmrc-py.c
*/
#include "system.h"
#include "Python.h"
#ifdef __LCLINT__
#undef PyObject_HEAD
#define PyObject_HEAD int _PyObjectHead;
#endif
#include "structmember.h"
/*@unchecked@*/
extern PyTypeObject PyDictIter_Type;
#include <rpmcli.h>
#include "rpmrc-py.h"
#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
#include "header-py.h" /* XXX debug only */
#include "rpmal-py.h" /* XXX debug only */
#include "rpmds-py.h" /* XXX debug only */
#include "rpmfd-py.h" /* XXX debug only */
#include "rpmfi-py.h" /* XXX debug only */
#include "rpmmi-py.h" /* XXX debug only */
#include "rpmte-py.h" /* XXX debug only */
#include "rpmts-py.h" /* XXX debug only */
#endif
#include "debug.h"
#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
/*@unchecked@*/
static int _rc_debug = 0;
#endif
/** \ingroup python
* \class Rpmrc
* \brief A python rpm.rc object encapsulates rpmlib configuration.
*/
/** \ingroup python
* \name Class: rpm.rc
*/
/*@{*/
/**
*/
PyObject * rpmrc_AddMacro(/*@unused@*/ PyObject * self, PyObject * args)
{
char * name, * val;
if (!PyArg_ParseTuple(args, "ss:AddMacro", &name, &val))
return NULL;
addMacro(NULL, name, NULL, val, -1);
Py_INCREF(Py_None);
return Py_None;
}
/**
*/
PyObject * rpmrc_DelMacro(/*@unused@*/ PyObject * self, PyObject * args)
{
char * name;
if (!PyArg_ParseTuple(args, "s:DelMacro", &name))
return NULL;
delMacro(NULL, name);
Py_INCREF(Py_None);
return Py_None;
}
#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
/**
*/
static const char * lbl(void * s)
/*@*/
{
PyObject * o = s;
if (o == NULL) return "null";
if (o->ob_type == &PyType_Type) return o->ob_type->tp_name;
if (o->ob_type == &PyClass_Type) return "Class";
if (o->ob_type == &PyComplex_Type) return "Complex";
if (o->ob_type == &PyDict_Type) return "Dict";
if (o->ob_type == &PyDictIter_Type) return "DictIter";
if (o->ob_type == &PyFile_Type) return "File";
if (o->ob_type == &PyFloat_Type) return "Float";
if (o->ob_type == &PyFunction_Type) return "Function";
if (o->ob_type == &PyInt_Type) return "Int";
if (o->ob_type == &PyList_Type) return "List";
if (o->ob_type == &PyLong_Type) return "Long";
if (o->ob_type == &PyMethod_Type) return "Method";
if (o->ob_type == &PyModule_Type) return "Module";
if (o->ob_type == &PyString_Type) return "String";
if (o->ob_type == &PyTuple_Type) return "Tuple";
if (o->ob_type == &PyType_Type) return "Type";
if (o->ob_type == &PyUnicode_Type) return "Unicode";
if (o->ob_type == &hdr_Type) return "hdr";
if (o->ob_type == &rpmal_Type) return "rpmal";
if (o->ob_type == &rpmds_Type) return "rpmds";
if (o->ob_type == &rpmfd_Type) return "rpmfd";
if (o->ob_type == &rpmfi_Type) return "rpmfi";
if (o->ob_type == &rpmmi_Type) return "rpmmi";
if (o->ob_type == &rpmrc_Type) return "rpmrc";
if (o->ob_type == &rpmte_Type) return "rpmte";
if (o->ob_type == &rpmts_Type) return "rpmts";
return "Unknown";
}
/**
*/
static PyObject *
rpmrc_getstate(rpmrcObject *s, PyObject *args)
/*@*/
{
if (!PyArg_ParseTuple(args, ":getstate"))
return NULL;
return PyInt_FromLong(s->state);
}
/**
*/
static PyObject *
rpmrc_setstate(rpmrcObject *s, PyObject *args)
/*@globals _Py_NoneStruct @*/
/*@modifies s, _Py_NoneStruct @*/
{
int state;
if (!PyArg_ParseTuple(args, "i:setstate", &state))
return NULL;
s->state = state;
Py_INCREF(Py_None);
return Py_None;
}
/**
*/
static void rpmrc_dealloc(PyObject * s)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_dealloc(%p[%s])\n", s, lbl(s));
PyDict_Type.tp_dealloc(s);
}
/**
*/
static int rpmrc_print(PyObject * s, FILE *fp, int flags)
/*@*/
{
/*@-formattype@*/
if (_rc_debug)
fprintf(stderr, "*** rpmrc_print(%p[%s],%p,%x)\n", s, lbl(s), fp, flags);
/*@=formattype@*/
return PyDict_Type.tp_print(s, fp, flags);
}
/**
*/
static int rpmrc_compare(PyObject * a, PyObject * b)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_compare(%p[%s],%p[%s])\n", a, lbl(a), b, lbl(b));
return PyDict_Type.tp_compare(a, b);
}
/**
*/
static PyObject * rpmrc_repr(PyObject * s)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_repr(%p[%s])\n", s, lbl(s));
return PyDict_Type.tp_repr(s);
}
/**
*/
static long rpmrc_hash(PyObject * s)
/*@*/
{
/* XXX dict objects are unhashable */
if (_rc_debug)
fprintf(stderr, "*** rpmrc_hash(%p[%s])\n", s, lbl(s));
return PyDict_Type.tp_hash(s);
}
/**
*/
static int
rpmrc_length(PyObject * s)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_length(%p[%s])\n", s, lbl(s));
return PyDict_Type.tp_as_mapping->mp_length(s);
}
/**
*/
static PyObject *
rpmrc_subscript(PyObject * s, PyObject * key)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_subscript(%p[%s], %p[%s])\n", s, lbl(s), key, lbl(key));
return PyDict_Type.tp_as_mapping->mp_subscript(s, key);
}
/**
*/
static int
rpmrc_ass_subscript(PyObject * s, PyObject * key, PyObject * value)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_ass_subscript(%p[%s], %p[%s], %p[%s])\n", s, lbl(s), key, lbl(key), value, lbl(value));
return PyDict_Type.tp_as_mapping->mp_ass_subscript(s, key, value);
}
/*@unchecked@*/ /*@observer@*/
static PyMappingMethods rpmrc_as_mapping = {
rpmrc_length, /* mp_length */
rpmrc_subscript, /* mp_subscript */
rpmrc_ass_subscript, /* mp_ass_subscript */
};
/**
*/
static PyObject * rpmrc_getattro (PyObject *s, PyObject *name)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_getattro(%p[%s], \"%s\")\n", s, lbl(s), PyString_AS_STRING(name));
return PyObject_GenericGetAttr(s, name);
}
/**
*/
static int rpmrc_setattro (PyObject *s, PyObject *name, PyObject * value)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_setattro(%p[%s], \"%s \", \"%s\")\n", s, lbl(s), PyString_AS_STRING(name), PyString_AS_STRING(value));
return PyDict_Type.tp_setattro(s, name, value);
}
/**
*/
/*@unchecked@*/ /*@observer@*/
static char rpmrc_doc[] =
"";
/**
*/
static int rpmrc_traverse(PyObject * s, visitproc visit, void *arg)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_traverse(%p[%s],%p,%p)\n", s, lbl(s), visit, arg);
return PyDict_Type.tp_traverse(s, visit, arg);
}
/**
*/
static int rpmrc_clear(PyObject * s)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_clear(%p[%s])\n", s, lbl(s));
return PyDict_Type.tp_clear(s);
}
/**
*/
static PyObject * rpmrc_richcompare(PyObject * v, PyObject * w, int op)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_richcompare(%p[%s],%p[%s],%x)\n", v, lbl(v), w, lbl(w), op);
return PyDict_Type.tp_richcompare(v, w, op);
}
/**
*/
static PyObject * rpmrc_iter(PyObject * s)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_iter(%p[%s])\n", s, lbl(s));
if (s->ob_type == &PyDictIter_Type)
return PyDictIter_Type.tp_iter(s);
return PyDict_Type.tp_iter(s);
}
/**
*/
static PyObject * rpmrc_iternext(PyObject * s)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_iternext(%p[%s])\n", s, lbl(s));
if (s->ob_type == &PyDictIter_Type)
return PyDictIter_Type.tp_iternext(s);
return NULL;
}
/**
*/
static PyObject * rpmrc_next(PyObject * s, PyObject *args)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_next(%p[%s],%p)\n", s, lbl(s), args);
if (s->ob_type == &PyDictIter_Type)
return PyDictIter_Type.tp_methods[0].ml_meth(s, args);
return NULL;
}
/*@-fullinitblock@*/
/*@unchecked@*/ /*@observer@*/
static PyMemberDef rpmrc_members[] = {
{"state", T_INT, offsetof(rpmrcObject, state), READONLY,
"an int variable for demonstration purposes"},
{0}
};
/*@=fullinitblock@*/
/** \ingroup python
*/
static int rpmrc_init(PyObject * s, PyObject *args, PyObject *kwds)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_init(%p[%s],%p,%p)\n", s, lbl(s), args, kwds);
if (PyDict_Type.tp_init(s, args, kwds) < 0)
return -1;
((rpmrcObject *)s)->state = 0;
return 0;
}
/** \ingroup python
*/
static void rpmrc_free(PyObject * s)
/*@*/
{
if (_rc_debug)
fprintf(stderr, "*** rpmrc_free(%p[%s])\n", s, lbl(s));
_PyObject_GC_Del(s);
}
/** \ingroup python
*/
static PyObject * rpmrc_alloc(PyTypeObject * subtype, int nitems)
/*@*/
{
PyObject * ns = PyType_GenericAlloc(subtype, nitems);
if (_rc_debug)
fprintf(stderr, "*** rpmrc_alloc(%p[%s},%d) ret %p[%s]\n", subtype, lbl(subtype), nitems, ns, lbl(ns));
return (PyObject *) ns;
}
/** \ingroup python
*/
static PyObject * rpmrc_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
/*@*/
{
PyObject * ns;
/* Derive an initialized dictionary of the appropriate size. */
ns = PyDict_Type.tp_new(&rpmrc_Type, args, kwds);
/* Perform additional initialization. */
if (rpmrc_init(ns, args, kwds) < 0) {
rpmrc_free(ns);
return NULL;
}
if (_rc_debug)
fprintf(stderr, "*** rpmrc_new(%p[%s],%p,%p) ret %p[%s]\n", subtype, lbl(subtype), args, kwds, ns, lbl(ns));
return ns;
}
#endif
/**
*/
/*@-fullinitblock@*/
/*@unchecked@*/ /*@observer@*/
static struct PyMethodDef rpmrc_methods[] = {
{ "addMacro", (PyCFunction) rpmrc_AddMacro, METH_VARARGS,
NULL },
{ "delMacro", (PyCFunction) rpmrc_DelMacro, METH_VARARGS,
NULL },
#if Py_TPFLAGS_HAVE_ITER /* XXX backport to python-1.5.2 */
{ "getstate", (PyCFunction) rpmrc_getstate, METH_VARARGS,
"getstate() -> state"},
{ "setstate", (PyCFunction) rpmrc_setstate, METH_VARARGS,
"setstate(state)"},
{ "next", (PyCFunction) rpmrc_next, METH_VARARGS,
"next() -- get the next value, or raise StopIteration"},
#endif
{NULL, NULL} /* sentinel */
};
/*@=fullinitblock@*/
/** \ingroup python
*/
/*@-fullinitblock@*/
#if Py_TPFLAGS_HAVE_ITER
PyTypeObject rpmrc_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
"rpm.rc", /* tp_name */
sizeof(rpmrcObject), /* tp_size */
0, /* tp_itemsize */
(destructor) rpmrc_dealloc, /* tp_dealloc */
rpmrc_print, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
rpmrc_compare, /* tp_compare */
rpmrc_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
&rpmrc_as_mapping, /* tp_as_mapping */
rpmrc_hash, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
(getattrofunc) rpmrc_getattro, /* tp_getattro */
(setattrofunc) rpmrc_setattro, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /* tp_flags */
rpmrc_doc, /* tp_doc */
rpmrc_traverse, /* tp_traverse */
rpmrc_clear, /* tp_clear */
rpmrc_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
rpmrc_iter, /* tp_iter */
rpmrc_iternext, /* tp_iternext */
rpmrc_methods, /* tp_methods */
rpmrc_members, /* tp_members */
0, /* tp_getset */
&PyDict_Type, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
rpmrc_init, /* tp_init */
rpmrc_alloc, /* tp_alloc */
rpmrc_new, /* tp_new */
rpmrc_free, /* tp_free */
0, /* tp_is_gc */
};
#else
PyTypeObject rpmrc_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /* ob_size */
"rpm.rc", /* tp_name */
sizeof(rpmrcObject), /* tp_size */
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 */
0, /* tp_flags */
0 /* tp_doc */
};
#endif
/*@=fullinitblock@*/
#if Py_TPFLAGS_HAVE_ITER
PyObject * rpmrc_Create(/*@unused@*/ PyObject * self, PyObject *args, PyObject *kwds)
{
return rpmrc_new(&rpmrc_Type, args, kwds);
}
#endif
/*@}*/
|