Skip to contentSkip to conversation

libselinux: add a const to suppress a build warning with Python 3.7

PATCH In review Nicolas Iooss 2 participants 5 messages Aug 19, 2018 – Aug 22, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 libselinux: add a const to suppress a build warning with Python 3.7

On systems using Python 3.7, when compiling libselinux Python wrappers (with "make install-pywrap"), the following warning is reported by gcc:

audit2why.c: In function ‘analyze’:
audit2why.c:364:11: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
permstr = _PyUnicode_AsString( strObj );
^

Make permstr "const char *" in order to suppress this warning.

---
 libselinux/src/audit2why.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libselinux/src/audit2why.c +1 -1
index 0331fdfd8df9..5a1e69a8269b 100644
@@ -354,7 +354,7 @@ static PyObject *analyze(PyObject *self __attribute__((unused)) , PyObject *args
 	/* iterate over items of the list, grabbing strings, and parsing
 	   for numbers */
 	for (i=0; i<numlines; i++){
-		char *permstr;
+		const char *permstr;
 
 		/* grab the string object from the next element of the list */
 		strObj = PyList_GetItem(listObj, i); /* Can't fail */
Signature · 1 line
2.18.0
#1 lore raw

PATCH 2/3 Travis-CI: upgrade to Ubuntu 16.04 LTS Xenial Xerus

Ubuntu 14.04 uses SWIG 2.0.11 which produces Python files which contain lines ending with a semicolon:

    __del__ = lambda self : None;

Ubuntu 16.04 uses SWIG 3.0.8, which does not put a semicolon. Moreover Travis CI only support Python 3.7 with Ubuntu 16.04. The reason for this is clearly stated on
https://docs.travis-ci.com/user/languages/python/#development-releases-support :

Recent Python branches require OpenSSL 1.0.2+. As this library is not available for Trusty, 3.7, 3.7-dev, 3.8-dev, and nightly do not work (or use outdated archive).

Enabling Python 3.7 in Travis CI build matrix is therefore another reason to upgrade .travis.yml to Ubuntu 16.04. As this new template does not support Python 3.4 nor 3.5, and does not support PyPy2.7 yet, drop them from the build matrix.

---
 .travis.yml | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)
.travis.yml +17 -19
index 09dd4749975e..00d0c54a68d7 100644
@@ -11,34 +11,35 @@ compiler:
 env:
   matrix:
     # Test the last version of Python and Ruby together, with some linkers
-    - PYVER=python3.6 RUBYLIBVER=2.5.1
-    - PYVER=python3.6 RUBYLIBVER=2.5.1 TEST_FLAGS_OVERRIDE=1
-    - PYVER=python3.6 RUBYLIBVER=2.5.1 LINKER=gold
-    - PYVER=python3.6 RUBYLIBVER=2.5.1 LINKER=bfd
+    - PYVER=python3.7 RUBYLIBVER=2.5.1
+    - PYVER=python3.7 RUBYLIBVER=2.5.1 TEST_FLAGS_OVERRIDE=1
+    - PYVER=python3.7 RUBYLIBVER=2.5.1 LINKER=gold
+    - PYVER=python3.7 RUBYLIBVER=2.5.1 LINKER=bfd
 
     # Test several Python versions
     - PYVER=python2.7 RUBYLIBVER=2.5.1
-    - PYVER=python3.3 RUBYLIBVER=2.5.1
-    - PYVER=python3.4 RUBYLIBVER=2.5.1
     - PYVER=python3.5 RUBYLIBVER=2.5.1
-    - PYVER=pypy RUBYLIBVER=2.5.1
-    - PYVER=pypy3 RUBYLIBVER=2.5.1
+    - PYVER=python3.6 RUBYLIBVER=2.5.1
+    # pypy2.7 seems not to be available in Travis-CI Xenial template yet.
+    # https://github.com/travis-ci/travis-ci/issues/9542
+    #- PYVER=pypy RUBYLIBVER=2.5.1
+    - PYVER=pypy3.5 RUBYLIBVER=2.5.1
 
     # Test several Ruby versions
-    - PYVER=python3.6 RUBYLIBVER=2.4
-    - PYVER=python3.6 RUBYLIBVER=2.3
-    - PYVER=python3.6 RUBYLIBVER=2.2
+    - PYVER=python3.7 RUBYLIBVER=2.4
+    - PYVER=python3.7 RUBYLIBVER=2.3
+    - PYVER=python3.7 RUBYLIBVER=2.2
 
 matrix:
   exclude:
     - compiler: clang
-      env: PYVER=python3.6 RUBYLIBVER=2.5.1 LINKER=gold
+      env: PYVER=python3.7 RUBYLIBVER=2.5.1 LINKER=gold
     - compiler: clang
-      env: PYVER=python3.6 RUBYLIBVER=2.5.1 LINKER=bfd
+      env: PYVER=python3.7 RUBYLIBVER=2.5.1 LINKER=bfd
 
-# Use Travis-CI Ubuntu 14.04 Trusty infrastructure, "full image" variant
+# Use Travis-CI Ubuntu 16.04 Xenial Xerus infrastructure, "full image" variant
 sudo: required
-dist: trusty
+dist: xenial
 
 # Install SELinux userspace utilities dependencies
 addons:
@@ -78,7 +79,7 @@ install:
   # Download the required python version if it is not installed
   - VIRTUAL_ENV="$HOME/virtualenv/$PYVER"
   - if ! [ -d "$VIRTUAL_ENV" ] ; then
-        curl --retry 10 -o python.tar.bz2 "https://s3.amazonaws.com/travis-python-archives/binaries/ubuntu/14.04/x86_64/${PYVER/python/python-}.tar.bz2" &&
+        curl --retry 10 -o python.tar.bz2 "https://s3.amazonaws.com/travis-python-archives/binaries/ubuntu/16.04/x86_64/${PYVER/python/python-}.tar.bz2" &&
         sudo tar xjf python.tar.bz2 --directory / &&
         rm python.tar.bz2 ;
     fi
@@ -87,9 +88,6 @@ install:
   - $VIRTUAL_ENV/bin/pip install flake8
 
 before_script:
-  # clang on Travis-CI 14.04 environment is too old to support -Wdouble-promotion
-  - if "$CC" --version |grep -q clang; then sed 's/ -Wdouble-promotion / /' -i libselinux/src/Makefile libselinux/utils/Makefile ; fi
-
   # Build and install in a temporary directory to run tests
   - export DESTDIR="$TRAVIS_BUILD_DIR/installdir"
 
Signature · 1 line
2.18.0
#2 lore raw

PATCH 3/3 python: remove semicolon from end of lines

In reply to Nicolas Iooss

Python does not need to end a statement with a semicolon. Doing this gets reported by linters such as flake8 ("E703 statement ends with a semicolon").

Remove such semicolons in the code and enable this warning in scripts/run-flake8.

---
 python/sepolgen/src/sepolgen/audit.py | 2 +-
 python/sepolgen/src/sepolgen/yacc.py  | 8 ++++----
 python/sepolicy/sepolicy/manpage.py   | 2 +-
 scripts/run-flake8                    | 1 -
 4 files changed, 6 insertions(+), 7 deletions(-)
python/sepolgen/src/sepolgen/audit.py +1 -1
index daed58ce9643..4adb851f3e93 100644
@@ -258,7 +258,7 @@ class AVCMessage(AuditMessage):
         if (scontext, tcontext, self.tclass, access_tuple) in avcdict.keys():
             self.type, self.data = avcdict[(scontext, tcontext, self.tclass, access_tuple)]
         else:
-            self.type, self.data = audit2why.analyze(scontext, tcontext, self.tclass, self.accesses);
+            self.type, self.data = audit2why.analyze(scontext, tcontext, self.tclass, self.accesses)
             if self.type == audit2why.NOPOLICY:
                 self.type = audit2why.TERULE
             if self.type == audit2why.BADTCON:
python/sepolgen/src/sepolgen/yacc.py +4 -4
index f00635469af1..afef174849f2 100644
@@ -1864,10 +1864,10 @@ del _lr_action_items
 """)
             
         else:
-            f.write("\n_lr_action = { ");
+            f.write("\n_lr_action = { ")
             for k,v in _lr_action.items():
                 f.write("(%r,%r):%r," % (k[0],k[1],v))
-            f.write("}\n");
+            f.write("}\n")
 
         if smaller:
             # Factor out names to try and make smaller
@@ -1901,10 +1901,10 @@ for _k, _v in _lr_goto_items.items():
 del _lr_goto_items
 """)
         else:
-            f.write("\n_lr_goto = { ");
+            f.write("\n_lr_goto = { ")
             for k,v in _lr_goto.items():
                 f.write("(%r,%r):%r," % (k[0],k[1],v))                    
-            f.write("}\n");
+            f.write("}\n")
 
         # Write production table
         f.write("_lr_productions = [\n")
python/sepolicy/sepolicy/manpage.py +1 -1
index cb211ba083ca..cfcb7c3932d7 100755
@@ -539,7 +539,7 @@ class ManPage:
                     self.fd = fd
                     self.man_page_path = man_page_path
             except KeyError:
-                continue;
+                continue
             self.attributes[domain_type] = next(sepolicy.info(sepolicy.TYPE, ("%s") % domain_type))["attributes"]
 
         self._header()
scripts/run-flake8 +0 -1
index 8a1f490b8a62..207edd20dd89 100755
@@ -14,7 +14,6 @@ IGNORE_LIST=''
 IGNORE_LIST="$IGNORE_LIST,W191" # indentation contains tabs
 
 IGNORE_LIST="$IGNORE_LIST,E101" # indentation contains mixed spaces and tabs
-IGNORE_LIST="$IGNORE_LIST,E703" # statement ends with a semicolon
 IGNORE_LIST="$IGNORE_LIST,E711" # comparison to None should be 'if cond is not None:'
 IGNORE_LIST="$IGNORE_LIST,E712" # comparison to False should be 'if cond is False:' or 'if not cond:'
 IGNORE_LIST="$IGNORE_LIST,E722" # do not use bare 'except'
Signature · 1 line
2.18.0
#3 lore raw

Re: [PATCH 3/3] python: remove semicolon from end of lines

Ack on these as well

Quoted 104 lines · Nicolas Iooss

Python does not need to end a statement with a semicolon. Doing this gets reported by linters such as flake8 ("E703 statement ends with a semicolon").

Remove such semicolons in the code and enable this warning in scripts/run-flake8.

---
 python/sepolgen/src/sepolgen/audit.py | 2 +-
 python/sepolgen/src/sepolgen/yacc.py  | 8 ++++----
 python/sepolicy/sepolicy/manpage.py   | 2 +-
 scripts/run-flake8                    | 1 -
 4 files changed, 6 insertions(+), 7 deletions(-)
python/sepolgen/src/ renamed from python/sepolgen/src/sepolgen/audit.py +0 -0

sepolgen/audit.py
index daed58ce9643..4adb851f3e93 100644

python/sepolgen/src/sepolgen/audit.py +0 -0
@@ -258,7 +258,7 @@ class AVCMessage(AuditMessage):
         if (scontext, tcontext, self.tclass, access_tuple) in

avcdict.keys():
self.type, self.data = avcdict[(scontext, tcontext,
self.tclass, access_tuple)]
else:
- self.type, self.data = audit2why.analyze(scontext, tcontext,
self.tclass, self.accesses);
+ self.type, self.data = audit2why.analyze(scontext, tcontext,
self.tclass, self.accesses)

             if self.type == audit2why.NOPOLICY:
                 self.type = audit2why.TERULE
             if self.type == audit2why.BADTCON:
python/sepolgen/src/ renamed from python/sepolgen/src/sepolgen/yacc.py +0 -0

sepolgen/yacc.py
index f00635469af1..afef174849f2 100644

python/sepolgen/src/sepolgen/yacc.py +4 -4
@@ -1864,10 +1864,10 @@ del _lr_action_items
 """)
 
         else:
-            f.write("\n_lr_action = { ");
+            f.write("\n_lr_action = { ")
             for k,v in _lr_action.items():
                 f.write("(%r,%r):%r," % (k[0],k[1],v))
-            f.write("}\n");
+            f.write("}\n")
 
         if smaller:
             # Factor out names to try and make smaller
@@ -1901,10 +1901,10 @@ for _k, _v in _lr_goto_items.items():
 del _lr_goto_items
 """)
         else:
-            f.write("\n_lr_goto = { ");
+            f.write("\n_lr_goto = { ")
             for k,v in _lr_goto.items():
                 f.write("(%r,%r):%r," % (k[0],k[1],v))
-            f.write("}\n");
+            f.write("}\n")
 
         # Write production table
         f.write("_lr_productions = [\n")
python/sepolicy/sepolicy/manpage.py +1 -1
index cb211ba083ca..cfcb7c3932d7 100755
@@ -539,7 +539,7 @@ class ManPage:
                     self.fd = fd
                     self.man_page_path = man_page_path
             except KeyError:
-                continue;
+                continue
             self.attributes[domain_type] = next(sepolicy.info(sepolicy.TYPE,

("%s") % domain_type))["attributes"]

         self._header()
scripts/run-flake8 +0 -0
index 8a1f490b8a62..207edd20dd89 100755
@@ -14,7 +14,6 @@ IGNORE_LIST=''
 IGNORE_LIST="$IGNORE_LIST,W191" # indentation contains tabs
 
 IGNORE_LIST="$IGNORE_LIST,E101" # indentation contains mixed spaces and

tabs
-IGNORE_LIST="$IGNORE_LIST,E703" # statement ends with a semicolon
IGNORE_LIST="$IGNORE_LIST,E711" # comparison to None should be 'if cond
is not None:'
IGNORE_LIST="$IGNORE_LIST,E712" # comparison to False should be 'if cond
is False:' or 'if not cond:'
IGNORE_LIST="$IGNORE_LIST,E722" # do not use bare 'except'
--
2.18.0

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected]. To get help, send an email containing "help" to [email protected].

#4 lore raw

Re: [PATCH 3/3] python: remove semicolon from end of lines

Quoted 2 lines · William Roberts

Ack on these as well

Thanks, I applied these patches and the previous ones I sent.

Nicolas

Quoted 96 lines · Nicolas Iooss
Quoted 92 lines

Python does not need to end a statement with a semicolon. Doing this gets reported by linters such as flake8 ("E703 statement ends with a semicolon").

Remove such semicolons in the code and enable this warning in scripts/run-flake8.

---
 python/sepolgen/src/sepolgen/audit.py | 2 +-
 python/sepolgen/src/sepolgen/yacc.py  | 8 ++++----
 python/sepolicy/sepolicy/manpage.py   | 2 +-
 scripts/run-flake8                    | 1 -
 4 files changed, 6 insertions(+), 7 deletions(-)
python/sepolgen/src/sepolgen/audit.py +1 -1
index daed58ce9643..4adb851f3e93 100644
@@ -258,7 +258,7 @@ class AVCMessage(AuditMessage):
         if (scontext, tcontext, self.tclass, access_tuple) in avcdict.keys():
             self.type, self.data = avcdict[(scontext, tcontext, self.tclass, access_tuple)]
         else:
-            self.type, self.data = audit2why.analyze(scontext, tcontext, self.tclass, self.accesses);
+            self.type, self.data = audit2why.analyze(scontext, tcontext, self.tclass, self.accesses)
             if self.type == audit2why.NOPOLICY:
                 self.type = audit2why.TERULE
             if self.type == audit2why.BADTCON:
python/sepolgen/src/sepolgen/yacc.py +4 -4
index f00635469af1..afef174849f2 100644
@@ -1864,10 +1864,10 @@ del _lr_action_items
 """)
 
         else:
-            f.write("\n_lr_action = { ");
+            f.write("\n_lr_action = { ")
             for k,v in _lr_action.items():
                 f.write("(%r,%r):%r," % (k[0],k[1],v))
-            f.write("}\n");
+            f.write("}\n")
 
         if smaller:
             # Factor out names to try and make smaller
@@ -1901,10 +1901,10 @@ for _k, _v in _lr_goto_items.items():
 del _lr_goto_items
 """)
         else:
-            f.write("\n_lr_goto = { ");
+            f.write("\n_lr_goto = { ")
             for k,v in _lr_goto.items():
                 f.write("(%r,%r):%r," % (k[0],k[1],v))
-            f.write("}\n");
+            f.write("}\n")
 
         # Write production table
         f.write("_lr_productions = [\n")
python/sepolicy/sepolicy/manpage.py +1 -1
index cb211ba083ca..cfcb7c3932d7 100755
@@ -539,7 +539,7 @@ class ManPage:
                     self.fd = fd
                     self.man_page_path = man_page_path
             except KeyError:
-                continue;
+                continue
             self.attributes[domain_type] = next(sepolicy.info(sepolicy.TYPE, ("%s") % domain_type))["attributes"]
 
         self._header()
scripts/run-flake8 +0 -2
index 8a1f490b8a62..207edd20dd89 100755
@@ -14,7 +14,6 @@ IGNORE_LIST=''
 IGNORE_LIST="$IGNORE_LIST,W191" # indentation contains tabs
 
 IGNORE_LIST="$IGNORE_LIST,E101" # indentation contains mixed spaces and tabs
-IGNORE_LIST="$IGNORE_LIST,E703" # statement ends with a semicolon
 IGNORE_LIST="$IGNORE_LIST,E711" # comparison to None should be 'if cond is not None:'
 IGNORE_LIST="$IGNORE_LIST,E712" # comparison to False should be 'if cond is False:' or 'if not cond:'
 IGNORE_LIST="$IGNORE_LIST,E722" # do not use bare 'except'
--

2.18.0

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to [email protected].