[PATCH 013/155] libsemanage: throw exceptions in python rather than

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


This patch looks good to me. acked.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk45tNEACgkQrlYvE4MpobO9GACeOwLMRVBV/NzfXZk8tkX/R7Wb
7OYAoK2bplSL0MOS09xl+fCFP0O5CDZk
=N8UL
-----END PGP SIGNATURE-----
>From a35f859c810597f9daf4155f1fa1a6292b851be6 Mon Sep 17 00:00:00 2001
From: Eric Paris <eparis@xxxxxxxxxx>
Date: Wed, 29 Jun 2011 00:57:40 -0400
Subject: [PATCH 013/155] 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@xxxxxxxxxx>
---
 libsemanage/src/.gitignore            |    1 +
 libsemanage/src/Makefile              |    7 +++++--
 libsemanage/src/exception.sh          |   14 ++++++++++++++
 libsemanage/src/semanageswig_python.i |    1 +
 4 files changed, 21 insertions(+), 2 deletions(-)
 create mode 100644 libsemanage/src/exception.sh

diff --git a/libsemanage/src/.gitignore b/libsemanage/src/.gitignore
index 232f787..b1d6518 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 e54788a..d21e972 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 0000000..8693fb7
--- /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 96c670c..c074f5f 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"
-- 
1.7.6

Attachment: 0013-libsemanage-throw-exceptions-in-python-rather-than-r.patch.sig
Description: PGP signature


[Index of Archives]     [Selinux Refpolicy]     [Linux SGX]     [Fedora Users]     [Fedora Desktop]     [Yosemite Photos]     [Yosemite Camping]     [Yosemite Campsites]     [KDE Users]     [Gnome Users]

  Powered by Linux