mirror of
https://github.com/SELinuxProject/selinux
synced 2025-05-01 15:18:00 +00:00
libsemanage: throw exceptions in python rather than return NULL
Python doesn't really work on the basis of negative error code. It throws exceptions. This patch automatically generates little stub functions which will catch negative error codes and will throw exceptions in their place. Signed-off-by: Eric Paris <eparis@redhat.com> Acked-by: Dan Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
78d58d73b4
commit
9406ace82b
libsemanage/src
1
libsemanage/src/.gitignore
vendored
1
libsemanage/src/.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
semanageswig_wrap.c
|
||||
semanageswig_python_exception.i
|
||||
semanage.py
|
||||
|
@ -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 $< > $@
|
||||
|
||||
|
14
libsemanage/src/exception.sh
Normal file
14
libsemanage/src/exception.sh
Normal file
@ -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
|
@ -460,4 +460,5 @@
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%include "semanageswig_python_exception.i"
|
||||
%include "semanageswig.i"
|
||||
|
Loading…
Reference in New Issue
Block a user