rpm  5.4.14
rpmps-py.c
Go to the documentation of this file.
1 
4 /*@-modunconnomods -evalorderuncon @*/
5 
6 #include "system.h"
7 
8 #include <rpmio.h>
9 #include <rpmiotypes.h> /* XXX fnpyKey */
10 #include <rpmtypes.h>
11 #include <rpmtag.h>
12 #define _RPMPS_INTERNAL /* XXX rpmps needs iterator */
13 
14 #include "rpmdebug-py.c"
15 
16 #include "rpmps-py.h"
17 
18 #include "debug.h"
19 
20 /*@access FILE @*/
21 /*@access rpmps @*/
22 /*@access rpmProblem @*/
23 
24 static PyObject *
25 rpmps_iter(rpmpsObject * s)
26  /*@modifies s @*/
27 {
28 if (_rpmps_debug < 0)
29 fprintf(stderr, "*** rpmps_iter(%p)\n", s);
31  Py_INCREF(s);
32  return (PyObject *)s;
33 }
34 
35 /*@null@*/
36 static PyObject *
37 rpmps_iternext(rpmpsObject * s)
38  /*@modifies s @*/
39 {
40  PyObject * result = NULL;
41 
42 if (_rpmps_debug < 0)
43 fprintf(stderr, "*** rpmps_iternext(%p) ps %p psi %p\n", s, s->ps, s->psi);
44 
45  /* Reset loop indices on 1st entry. */
46  if (s->psi == NULL)
47  s->psi = rpmpsInitIterator(s->ps);
48 
49  /* If more to do, return a problem set string. */
50  if (rpmpsNextIterator(s->psi) >= 0)
51  result = Py_BuildValue("s", rpmProblemString(rpmpsProblem(s->psi)));
52  else
53  s->psi = rpmpsFreeIterator(s->psi);
54 
55  return result;
56 }
57 
64 
65 /*@null@*/
66 static PyObject *
67 rpmps_Debug(/*@unused@*/ rpmpsObject * s, PyObject * args,
68  PyObject * kwds)
69  /*@globals _Py_NoneStruct @*/
70  /*@modifies _Py_NoneStruct @*/
71 {
72  char * kwlist[] = {"debugLevel", NULL};
73 
74  if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", kwlist, &_rpmps_debug))
75  return NULL;
76 
78  return Py_None;
79 }
80 
81 static int
82 rpmps_Append(rpmpsObject * s, PyObject * value)
83 {
84  char *pkgNEVR, *altNEVR, *str1;
85  unsigned long ulong1;
86  int ignoreProblem;
88  fnpyKey key;
89 
90  if (!PyArg_ParseTuple(value, "ssOiisN:rpmps value tuple",
91  &pkgNEVR, &altNEVR, &key,
92  &type, &ignoreProblem, &str1,
93  &ulong1))
94  {
95  return -1;
96  }
97  rpmpsAppend(s->ps, type, pkgNEVR, key, str1, NULL, altNEVR, ulong1);
98  return 0;
99 }
100 
103 /*@-fullinitblock@*/
104 /*@unchecked@*/ /*@observer@*/
105 static struct PyMethodDef rpmps_methods[] = {
106  {"Debug", (PyCFunction)rpmps_Debug, METH_VARARGS|METH_KEYWORDS,
107  NULL},
108  {"Append", (PyCFunction)rpmps_Append, METH_VARARGS|METH_KEYWORDS,
109  NULL},
110  {NULL, NULL} /* sentinel */
111 };
112 /*@=fullinitblock@*/
113 
114 /* ---------- */
115 
116 static void
117 rpmps_dealloc(rpmpsObject * s)
118  /*@modifies s @*/
119 {
120 if (_rpmps_debug < 0)
121 fprintf(stderr, "*** rpmps_dealloc(%p)\n", s);
122  if (s) {
123  s->ps = rpmpsFree(s->ps);
124  PyObject_Del(s);
125  }
126 }
127 
128 static int
129 rpmps_print(rpmpsObject * s, FILE * fp, /*@unused@*/ int flags)
130  /*@globals fileSystem @*/
131  /*@modifies s, fp, fileSystem @*/
132 {
133 if (_rpmps_debug < 0)
134 fprintf(stderr, "*** rpmps_print(%p,%p,%x)\n", s, (void *)fp, flags);
135  if (s && s->ps)
136  rpmpsPrint(fp, s->ps);
137  return 0;
138 }
139 
140 static PyObject * rpmps_getattro(PyObject * o, PyObject * n)
141  /*@*/
142 {
143 if (_rpmps_debug < 0)
144 fprintf(stderr, "*** rpmps_getattro(%p,%p)\n", o, n);
145  return PyObject_GenericGetAttr(o, n);
146 }
147 
148 static int rpmps_setattro(PyObject * o, PyObject * n, PyObject * v)
149  /*@*/
150 {
151 if (_rpmps_debug < 0)
152 fprintf(stderr, "*** rpmps_setattro(%p,%p,%p)\n", o, n, v);
153  return PyObject_GenericSetAttr(o, n, v);
154 }
155 
156 static int
157 rpmps_length(rpmpsObject * s)
158  /*@*/
159 {
160  int rc;
162 if (_rpmps_debug < 0)
163 fprintf(stderr, "*** rpmps_length(%p) rc %d\n", s, rc);
164  return rc;
165 }
166 
167 /*@null@*/
168 static PyObject *
169 rpmps_subscript(rpmpsObject * s, PyObject * key)
170  /*@*/
171 {
172  PyObject * result = NULL;
173  rpmpsi psi;
174  int ix;
175  int i;
176 
177  if (!PyInt_Check(key)) {
178 if (_rpmps_debug < 0)
179 fprintf(stderr, "*** rpmps_subscript(%p[%s],%p[%s])\n", s, lbl(s), key, lbl(key));
180  PyErr_SetString(PyExc_TypeError, "integer expected");
181  return NULL;
182  }
183 
184  ix = (int) PyInt_AsLong(key);
185  /* XXX range check */
186 
187  psi = rpmpsInitIterator(s->ps);
188  while ((i = rpmpsNextIterator(psi)) >= 0) {
189  if (i != ix)
190  continue;
191  result = Py_BuildValue("s", rpmProblemString(rpmpsProblem(psi)));
192 if (_rpmps_debug < 0)
193 fprintf(stderr, "*** rpmps_subscript(%p,%p) %s\n", s, key, PyString_AsString(result));
194  break;
195  }
196  psi = rpmpsFreeIterator(psi);
197 
198  return result;
199 }
200 
201 #define PERMIT_RPMPS_SUBSCRIPT /* XXX likely buggy */
202 #if defined(PERMIT_RPMPS_SUBSCRIPT)
203 static int
204 rpmps_ass_sub(rpmpsObject * s, PyObject * key, PyObject * value)
205  /*@modifies s @*/
206 {
207  rpmps ps;
208  int ix;
209 
210  if (!PyArg_Parse(key, "i:ass_sub", &ix)) {
211  PyErr_SetString(PyExc_TypeError, "rpmps key type must be integer");
212  return -1;
213  }
214 
215  /* XXX get rid of negative indices */
216  if (ix < 0) ix = -ix;
217 
218  ps = s->ps;
219 
220 if (_rpmps_debug < 0)
221 fprintf(stderr, "*** rpmps_ass_sub(%p[%s],%p[%s],%p[%s]) ps %p[%d:%d:%d]\n", s, lbl(s), key, lbl(key), value, lbl(value), ps, ix, ps->numProblems, ps->numProblemsAlloced);
222 
223  if (value == NULL) {
224  if (ix < ps->numProblems) {
225  rpmProblem op = ps->probs + ix;
226 
227  op->pkgNEVR = _free(op->pkgNEVR);
228  op->altNEVR = _free(op->altNEVR);
229  op->str1 = _free(op->str1);
230 
231  if ((ix+1) == ps->numProblems)
232  memset(op, 0, sizeof(*op));
233  else
234  memmove(op, op+1, (ps->numProblems - ix) * sizeof(*op));
235  if (ps->numProblems > 0)
236  ps->numProblems--;
237  }
238  } else {
239  rpmProblem p = memset(alloca(sizeof(*p)), 0, sizeof(*p));
240  unsigned long ulong1 = p->ulong1;
241 
242  if (!PyArg_ParseTuple(value, "ssOiisN:rpmps value tuple",
243  &p->pkgNEVR, &p->altNEVR, &p->key,
244  &p->type, &p->ignoreProblem, &p->str1,
245  &ulong1))
246  {
247  return -1;
248  }
249 
250 /*@-branchstate@*/
251  if (ix >= ps->numProblems) {
252  /* XXX force append for indices out of range. */
253  rpmpsAppend(s->ps, p->type, p->pkgNEVR, p->key,
254  p->str1, NULL, p->altNEVR, ulong1);
255  } else {
256  rpmProblem op = ps->probs + ix;
257 
258  op->pkgNEVR = _free(op->pkgNEVR);
259  op->altNEVR = _free(op->altNEVR);
260  op->str1 = _free(op->str1);
261 
262  p->pkgNEVR = (p->pkgNEVR && *p->pkgNEVR ? xstrdup(p->pkgNEVR) : NULL);
263  p->altNEVR = (p->altNEVR && *p->altNEVR ? xstrdup(p->altNEVR) : NULL);
264  p->str1 = (p->str1 && *p->str1 ? xstrdup(p->str1) : NULL);
265 
266  *op = *p; /* structure assignment */
267  }
268 /*@=branchstate@*/
269  }
270 
271  return 0;
272 }
273 #endif
274 
275 static PyMappingMethods rpmps_as_mapping = {
276  (lenfunc) rpmps_length, /* mp_length */
277  (binaryfunc) rpmps_subscript, /* mp_subscript */
278 #if defined(PERMIT_RPMPS_SUBSCRIPT)
279  (objobjargproc) rpmps_ass_sub, /* mp_ass_subscript */
280 #endif
281 };
282 
285 static int rpmps_init(rpmpsObject * s, PyObject *args, PyObject *kwds)
286  /*@modifies s @*/
287 {
288  char * kwlist[] = {NULL};
289 
290 if (_rpmps_debug < 0)
291 fprintf(stderr, "*** rpmps_init(%p,%p,%p)\n", s, args, kwds);
292 
293  if (!PyArg_ParseTupleAndKeywords(args, kwds, ":rpmps_init", kwlist))
294  return -1;
295 
296  s->ps = rpmpsCreate();
297  s->psi = NULL;
298 
299  return 0;
300 }
301 
304 static void rpmps_free(/*@only@*/ rpmpsObject * s)
305  /*@modifies s @*/
306 {
307 if (_rpmps_debug)
308 fprintf(stderr, "%p -- ps %p\n", s, s->ps);
309  s->ps = rpmpsFree(s->ps);
310 
311  PyObject_Del((PyObject *)s);
312 }
313 
316 static PyObject * rpmps_alloc(PyTypeObject * subtype, int nitems)
317  /*@*/
318 {
319  PyObject * s = PyType_GenericAlloc(subtype, nitems);
320 
321 if (_rpmps_debug < 0)
322 fprintf(stderr, "*** rpmps_alloc(%p,%d) ret %p\n", subtype, nitems, s);
323  return s;
324 }
325 
328 /*@null@*/
329 static PyObject * rpmps_new(PyTypeObject * subtype, PyObject *args, PyObject *kwds)
330  /*@*/
331 {
332  rpmpsObject * s = (void *) PyObject_New(rpmpsObject, subtype);
333 
334  /* Perform additional initialization. */
335  if (rpmps_init(s, args, kwds) < 0) {
336  rpmps_free(s);
337  return NULL;
338  }
339 
340 if (_rpmps_debug)
341 fprintf(stderr, "%p ++ ps %p\n", s, s->ps);
342 
343  return (PyObject *)s;
344 }
345 
348 /*@unchecked@*/ /*@observer@*/
349 static char rpmps_doc[] =
350 "";
351 
352 /*@-fullinitblock@*/
353 PyTypeObject rpmps_Type = {
354  PyObject_HEAD_INIT(&PyType_Type)
355  0, /* ob_size */
356  "rpm.ps", /* tp_name */
357  sizeof(rpmpsObject), /* tp_basicsize */
358  0, /* tp_itemsize */
359  /* methods */
360  (destructor) rpmps_dealloc, /* tp_dealloc */
361  (printfunc) rpmps_print, /* tp_print */
362  (getattrfunc)0, /* tp_getattr */
363  (setattrfunc)0, /* tp_setattr */
364  (cmpfunc)0, /* tp_compare */
365  (reprfunc)0, /* tp_repr */
366  0, /* tp_as_number */
367  0, /* tp_as_sequence */
368  &rpmps_as_mapping, /* tp_as_mapping */
369  (hashfunc)0, /* tp_hash */
370  (ternaryfunc)0, /* tp_call */
371  (reprfunc)0, /* tp_str */
372  (getattrofunc) rpmps_getattro, /* tp_getattro */
373  (setattrofunc) rpmps_setattro, /* tp_setattro */
374  0, /* tp_as_buffer */
375  Py_TPFLAGS_DEFAULT, /* tp_flags */
376  rpmps_doc, /* tp_doc */
377 #if Py_TPFLAGS_HAVE_ITER
378  0, /* tp_traverse */
379  0, /* tp_clear */
380  (richcmpfunc)0, /* tp_richcompare */
381  0, /* tp_weaklistoffset */
382  (getiterfunc) rpmps_iter, /* tp_iter */
383  (iternextfunc) rpmps_iternext, /* tp_iternext */
384  rpmps_methods, /* tp_methods */
385  0, /* tp_members */
386  0, /* tp_getset */
387  0, /* tp_base */
388  0, /* tp_dict */
389  0, /* tp_descr_get */
390  0, /* tp_descr_set */
391  0, /* tp_dictoffset */
392  (initproc) rpmps_init, /* tp_init */
393  (allocfunc) rpmps_alloc, /* tp_alloc */
394  (newfunc) rpmps_new, /* tp_new */
395  (freefunc) rpmps_free, /* tp_free */
396  0, /* tp_is_gc */
397 #endif
398 };
399 /*@=fullinitblock@*/
400 
401 /* ---------- */
402 
404 {
405  return s->ps;
406 }
407 
408 rpmpsObject *
410 {
411  rpmpsObject * s = PyObject_New(rpmpsObject, &rpmps_Type);
412 
413  if (s == NULL)
414  return NULL;
415  s->ps = ps;
416  s->psi = NULL;
417  return s;
418 }
419 /*@=modunconnomods =evalorderuncon @*/
struct rpmpsi_s * rpmpsi
Definition: rpmps.h:29
char * kwlist[]
Definition: rpmal-py.c:27
static int rpmps_init(rpmpsObject *s, PyObject *args, PyObject *kwds)
Definition: rpmps-py.c:285
rpmps psFromPs(rpmpsObject *s)
Definition: rpmps-py.c:403
const char * rpmProblemString(const rpmProblem prob)
Return formatted string representation of a problem.
Definition: rpmps.c:231
rpmpsObject * rpmps_Wrap(rpmps ps)
Definition: rpmps-py.c:409
op pkgNEVR
Definition: rpmps-py.c:258
static PyObject *int type
Definition: rpmmi-py.c:151
void rpmpsAppend(rpmps ps, rpmProblemType type, const char *pkgNEVR, fnpyKey key, const char *dn, const char *bn, const char *altNEVR, rpmuint64_t ulong1)
Append a problem to current set of problems.
Definition: rpmps.c:123
char * xstrdup(const char *str)
Definition: rpmmalloc.c:321
static PyObject * rpmps_Debug(rpmpsObject *s, PyObject *args, PyObject *kwds)
Definition: rpmps-py.c:67
return Py_None
Definition: rpmal-py.c:55
static VALUE rpmps_print(VALUE s)
Definition: rpmps-rb.c:63
rpmpsi rpmpsFreeIterator(rpmpsi psi)
Destroy problem set iterator.
Definition: rpmps.c:91
PyObject * args
Definition: rpmts-py.c:200
int rc
Definition: poptALL.c:670
void rpmpsPrint(FILE *fp, rpmps ps)
Print problems to file handle.
Definition: rpmps.c:346
op altNEVR
Definition: rpmps-py.c:259
unsigned long ulong1
Definition: rpmps-py.c:240
enum rpmProblemType_e rpmProblemType
Enumerate transaction set problem types.
int _rpmps_debug
Definition: rpmps.c:26
long int value
Definition: rpmds.c:2712
op str1
Definition: rpmps-py.c:260
struct rpmps_s * rpmps
Transaction problems found while processing a transaction set/.
Definition: rpmps.h:25
static int rpmps_Append(rpmpsObject *s, PyObject *value)
Definition: rpmps-py.c:82
pid_t result
Definition: rpmsq.c:737
int rpmpsNumProblems(rpmps ps)
Return number of problems in set.
Definition: rpmps.c:70
char * alloca()
memset(_r, 0, sizeof(*_r))
PyTypeObject rpmps_Type
Definition: rpmps-py.c:353
int ix
Definition: rpmps-py.c:174
char * p
Definition: macro.c:413
rpmps rpmpsCreate(void)
Create a problem set.
Definition: rpmps.c:61
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
int rpmpsNextIterator(rpmpsi psi)
Return next problem set iterator index.
Definition: rpmps.c:100
static int rpmps_setattro(PyObject *o, PyObject *n, PyObject *v)
Definition: rpmps-py.c:148
key
Definition: macro.c:383
char * o
Definition: macro.c:745
rpmps ps
Definition: rpmps-py.h:19
rpmpsi rpmpsInitIterator(rpmps ps)
Initialize problem set iterator.
Definition: rpmps.c:78
static struct PyMethodDef rpmps_methods[]
Definition: rpmps-py.c:105
struct rpmpsObject_s rpmpsObject
* op
Definition: rpmps-py.c:266
rpmpsi psi
Definition: rpmps-py.h:21
char * n
Definition: macro.c:744
static PyObject * rpmps_alloc(PyTypeObject *subtype, int nitems)
Definition: rpmps-py.c:316
static PyObject *s psi
Definition: rpmps-py.c:30
static PyMappingMethods rpmps_as_mapping
Definition: rpmps-py.c:275
rpmps rpmpsFree(rpmps ps)
Destroy a problem set.
static char rpmps_doc[]
Definition: rpmps-py.c:349
return Py_BuildValue("i", pkgKey)
const char * s
Definition: poptALL.c:734
rpmProblem rpmpsProblem(rpmpsi psi)
Return current problem from problem set.
Definition: rpmps.c:114
static PyObject * rpmps_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
Definition: rpmps-py.c:329
ps
Definition: rpmts-py.c:548
const void * fnpyKey
Definition: rpmiotypes.h:121
PyObject_Del(s)
int flags
Definition: fnmatch.c:282
struct rpmProblem_s * rpmProblem
Raw data for an element of a problem set.
Definition: rpmps.h:20
static PyObject * rpmps_getattro(PyObject *o, PyObject *n)
Definition: rpmps-py.c:140
return NULL
Definition: poptALL.c:613
int
Save source and expand field into target.
Definition: rpmds.c:2709
static void rpmps_free(rpmpsObject *s)
Definition: rpmps-py.c:304
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
int i
Definition: spec.c:743
Py_INCREF(Py_None)
static int nitems
Definition: rpmcache.c:81