diff --git a/libsemanage/src/.gitignore b/libsemanage/src/.gitignore index 232f7876..b1d65181 100644 --- a/libsemanage/src/.gitignore +++ b/libsemanage/src/.gitignore @@ -1,2 +1,3 @@ semanageswig_wrap.c +semanageswig_python_exception.i semanage.py diff --git a/libsemanage/src/Makefile b/libsemanage/src/Makefile index e54788a6..d21e972e 100644 --- a/libsemanage/src/Makefile +++ b/libsemanage/src/Makefile @@ -36,7 +36,7 @@ LIBVERSION = 1 LIBA=libsemanage.a TARGET=libsemanage.so LIBPC=libsemanage.pc -SWIGIF= semanageswig_python.i +SWIGIF= semanageswig_python.i semanageswig_python_exception.i SWIGRUBYIF= semanageswig_ruby.i SWIGCOUT= semanageswig_wrap.c SWIGRUBYCOUT= semanageswig_ruby_wrap.c @@ -47,7 +47,7 @@ SWIGFILES=$(SWIGSO) semanage.py SWIGRUBYSO=_rubysemanage.so LIBSO=$(TARGET).$(LIBVERSION) -GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) +GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) semanageswig_python_exception.i SRCS= $(filter-out $(GENERATED),$(wildcard *.c)) OBJS= $(patsubst %.c,%.o,$(SRCS)) conf-scan.o conf-parse.o @@ -92,6 +92,9 @@ $(LIBSO): $(LOBJS) $(LIBPC): $(LIBPC).in sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@ +semanageswig_python_exception.i: ../include/semanage/semanage.h + bash exception.sh > $@ + conf-scan.c: conf-scan.l conf-parse.h $(LEX) $(LFLAGS) -t $< > $@ diff --git a/libsemanage/src/exception.sh b/libsemanage/src/exception.sh new file mode 100644 index 00000000..8693fb78 --- /dev/null +++ b/libsemanage/src/exception.sh @@ -0,0 +1,14 @@ +function except() { +echo " +%exception $1 { + \$action + if (result < 0) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } +} +" +} +gcc -x c -c - -aux-info temp.aux < ../include/semanage/semanage.h +for i in `awk '/extern int/ { print $6 }' temp.aux`; do except $i ; done +rm -f -- temp.aux -.o diff --git a/libsemanage/src/semanageswig_python.i b/libsemanage/src/semanageswig_python.i index 96c670c2..c074f5f0 100644 --- a/libsemanage/src/semanageswig_python.i +++ b/libsemanage/src/semanageswig_python.i @@ -460,4 +460,5 @@ $1 = &temp; } +%include "semanageswig_python_exception.i" %include "semanageswig.i"