aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-09-02 10:03:38 +0200
committerMattias Andrée <maandree@operamail.com>2014-09-02 10:03:38 +0200
commit22045dfb614da1ecd9192937c609591e4bdb606d (patch)
tree70513c9c0895714a9cd61aadfc7b6fe3a634568c
parentderp (diff)
downloadpylibgamma-22045dfb614da1ecd9192937c609591e4bdb606d.tar.gz
pylibgamma-22045dfb614da1ecd9192937c609591e4bdb606d.tar.bz2
pylibgamma-22045dfb614da1ecd9192937c609591e4bdb606d.tar.xz
m
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--.gitignore1
-rw-r--r--src/c.pyx37
-rw-r--r--src/libgamma_error.py2
-rw-r--r--src/libgamma_method.py2
-rw-r--r--src/libgamma_native_error.pyx15
5 files changed, 17 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index 70874ee..cbc0dc0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,5 +15,4 @@ __pycache__/
*.gch
*.py[co]
src/*_native_*.c
-src/c.c
diff --git a/src/c.pyx b/src/c.pyx
deleted file mode 100644
index f38ce6a..0000000
--- a/src/c.pyx
+++ /dev/null
@@ -1,37 +0,0 @@
-# -*- python -*-
-'''
-pylibgamma — Python 3 wrapper for libgamma
-Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
-
-This library is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this library. If not, see <http://www.gnu.org/licenses/>.
-'''
-
-cimport cython
-
-from libc.string cimport strerror as c_strerror
-
-
-def strerror(error : int) -> str:
- '''
- Get a textual description of an error.
-
- @param error The number of the error.
- @return The description of the error.
- '''
- cdef const char* text
- cdef bytes bs
- text = c_strerror(<int>error)
- bs = text
- return bs.decode('utf-8', 'strict')
-
diff --git a/src/libgamma_error.py b/src/libgamma_error.py
index 0012a21..afefd5e 100644
--- a/src/libgamma_error.py
+++ b/src/libgamma_error.py
@@ -464,7 +464,7 @@ def create_error(error_code : int) -> Exception:
error_code = ctypes.get_errno()
if error_code >= 0:
- import c
+ import libgamma_native_error as c
e = OSError()
e.errno = error_code
e.strerror = c.strerror(e.errno)
diff --git a/src/libgamma_method.py b/src/libgamma_method.py
index 1c14049..0e71950 100644
--- a/src/libgamma_method.py
+++ b/src/libgamma_method.py
@@ -780,7 +780,7 @@ class GammaRamps:
else:
raise ValueError('invalid gamma ramp depth')
if isinstance(ramp_struct, int):
- import c
+ import libgamma_native_error as c
error = OSError()
error.errno = ramp_struct
error.strerror = c.strerror(error.errno)
diff --git a/src/libgamma_native_error.pyx b/src/libgamma_native_error.pyx
index d88f7fe..5c419cc 100644
--- a/src/libgamma_native_error.pyx
+++ b/src/libgamma_native_error.pyx
@@ -20,6 +20,7 @@ along with this library. If not, see <http://www.gnu.org/licenses/>.
cimport cython
from posix.unistd cimport gid_t
+from libc.string cimport strerror as c_strerror
cdef extern gid_t libgamma_group_gid
@@ -184,3 +185,17 @@ def libgamma_native_value_of_error(name : str) -> int:
bs = name.encode('utf-8') + bytes([0])
return int(libgamma_value_of_error(bs))
+
+def strerror(error : int) -> str:
+ '''
+ Get a textual description of an error.
+
+ @param error The number of the error.
+ @return The description of the error.
+ '''
+ cdef const char* text
+ cdef bytes bs
+ text = c_strerror(<int>error)
+ bs = text
+ return bs.decode('utf-8', 'strict')
+