Skip to content

Commit

Permalink
Raise python exception on macro expand errors
Browse files Browse the repository at this point in the history
Use the more expressive rpmExpandMacros() for python's macro
expansion so we can actually do errors via exceptions.
  • Loading branch information
pmatilai committed Jan 19, 2017
1 parent 4d80761 commit 80095bc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions python/rpmmacro-py.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <rpm/rpmmacro.h>

#include "header-py.h" /* XXX for pyrpmError, doh */
#include "rpmmacro-py.h"

PyObject *
Expand Down Expand Up @@ -37,7 +38,7 @@ PyObject *
rpmmacro_ExpandMacro(PyObject * self, PyObject * args, PyObject * kwds)
{
const char *macro;
PyObject *res;
PyObject *res = NULL;
int num = 0;
char * kwlist[] = {"macro", "numeric", NULL};

Expand All @@ -47,8 +48,11 @@ rpmmacro_ExpandMacro(PyObject * self, PyObject * args, PyObject * kwds)
if (num) {
res = Py_BuildValue("i", rpmExpandNumeric(macro));
} else {
char *str = rpmExpand(macro, NULL);
res = Py_BuildValue("s", str);
char *str = NULL;
if (rpmExpandMacros(NULL, macro, &str, 0) < 0)
PyErr_SetString(pyrpmError, "error expanding macro");
else
res = Py_BuildValue("s", str);
free(str);
}
return res;
Expand Down

0 comments on commit 80095bc

Please sign in to comment.