From a718081ebd1003de1ccc5915258b679268b747fc Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Fri, 7 Jul 2017 15:36:11 +0200 Subject: [PATCH] Bug with error handling: for now obi_errno needs to be passed to the function handling errors and exceptions, as it can't read the right value of the global obi_errno (Cython configuration problem?) --- .../dms/column/typed_column/bool.pyx | 18 ++-- .../dms/column/typed_column/char.pyx | 32 +++--- .../dms/column/typed_column/float.pyx | 42 ++++---- .../obitools3/dms/column/typed_column/int.pyx | 40 ++++---- .../dms/column/typed_column/qual.pyx | 97 +++++++++++-------- .../obitools3/dms/column/typed_column/seq.pyx | 47 +++++---- .../obitools3/dms/column/typed_column/str.pyx | 48 +++++---- python/obitools3/utils.pxd | 2 +- python/obitools3/utils.pyx | 6 +- 9 files changed, 188 insertions(+), 144 deletions(-) diff --git a/python/obitools3/dms/column/typed_column/bool.pyx b/python/obitools3/dms/column/typed_column/bool.pyx index 3c0b487..07930a2 100644 --- a/python/obitools3/dms/column/typed_column/bool.pyx +++ b/python/obitools3/dms/column/typed_column/bool.pyx @@ -1,5 +1,6 @@ #cython: language_level=3 +from obitools3.dms.capi.obierrno cimport obi_errno from ..column cimport register_column_class @@ -33,10 +34,11 @@ cdef class Column_bool(Column): cpdef object get_line(self, index_t line_nb): + global obi_errno cdef obibool_t value cdef object result value = obi_get_bool_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBIBool_NA : result = None else : @@ -45,15 +47,17 @@ cdef class Column_bool(Column): cpdef set_line(self, index_t line_nb, object value): + global obi_errno if value is None : value = OBIBool_NA if obi_set_bool_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") cdef class Column_multi_elts_bool(Column_multi_elts): cpdef object get_item(self, index_t line_nb, object elt_id) : + global obi_errno cdef obibool_t value cdef object result cdef bytes elt_name @@ -62,7 +66,7 @@ cdef class Column_multi_elts_bool(Column_multi_elts): else : elt_name = tobytes(elt_id) value = obi_get_bool_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIBool_NA : result = None else : @@ -70,6 +74,7 @@ cdef class Column_multi_elts_bool(Column_multi_elts): return result cpdef object get_line(self, index_t line_nb) : + global obi_errno cdef obibool_t value cdef object value_in_result cdef dict result @@ -79,7 +84,7 @@ cdef class Column_multi_elts_bool(Column_multi_elts): all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_bool_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBIBool_NA : value_in_result = None else : @@ -92,16 +97,17 @@ cdef class Column_multi_elts_bool(Column_multi_elts): return result cpdef set_item(self, index_t line_nb, object elt_id, object value) : + global obi_errno cdef bytes elt_name if value is None : value = OBIBool_NA if type(elt_id) == int : if obi_set_bool_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_bool_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") def register_class() : diff --git a/python/obitools3/dms/column/typed_column/char.pyx b/python/obitools3/dms/column/typed_column/char.pyx index 48b9ac0..7ae5e68 100644 --- a/python/obitools3/dms/column/typed_column/char.pyx +++ b/python/obitools3/dms/column/typed_column/char.pyx @@ -1,5 +1,6 @@ #cython: language_level=3 +from obitools3.dms.capi.obierrno cimport obi_errno from ..column cimport register_column_class @@ -32,10 +33,11 @@ cdef class Column_char(Column): comments=comments) cpdef object get_line(self, index_t line_nb): + global obi_errno cdef obichar_t value cdef object result value = obi_get_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBIChar_NA : result = None else : @@ -43,18 +45,20 @@ cdef class Column_char(Column): return result cpdef set_line(self, index_t line_nb, object value): + global obi_errno cdef obichar_t value_b if value is None : value_b = OBIChar_NA else : value_b = tobytes(value)[0] if obi_set_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") cdef class Column_multi_elts_char(Column_multi_elts): cpdef object get_item(self, index_t line_nb, object elt_id) : + global obi_errno cdef obichar_t value cdef object result cdef bytes elt_name @@ -63,7 +67,7 @@ cdef class Column_multi_elts_char(Column_multi_elts): else : elt_name = tobytes(elt_id) value = obi_get_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIChar_NA : result = None else : @@ -71,16 +75,17 @@ cdef class Column_multi_elts_char(Column_multi_elts): return result cpdef object get_line(self, index_t line_nb) : - cdef obichar_t value - cdef object value_in_result - cdef dict result - cdef index_t i - cdef bint all_NA + global obi_errno + cdef obichar_t value + cdef object value_in_result + cdef dict result + cdef index_t i + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBIChar_NA : value_in_result = None else : @@ -93,19 +98,20 @@ cdef class Column_multi_elts_char(Column_multi_elts): return result cpdef set_item(self, index_t line_nb, object elt_id, object value) : - cdef bytes elt_name - cdef obichar_t value_b + global obi_errno + cdef bytes elt_name + cdef obichar_t value_b if value is None : value_b = OBIChar_NA else : value_b = tobytes(value)[0] if type(elt_id) == int : if obi_set_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") def register_class(): diff --git a/python/obitools3/dms/column/typed_column/float.pyx b/python/obitools3/dms/column/typed_column/float.pyx index 14a2eca..50b7b24 100644 --- a/python/obitools3/dms/column/typed_column/float.pyx +++ b/python/obitools3/dms/column/typed_column/float.pyx @@ -1,5 +1,6 @@ #cython: language_level=3 +from obitools3.dms.capi.obierrno cimport obi_errno from ..column cimport register_column_class @@ -31,38 +32,39 @@ cdef class Column_float(Column): elements_names=elements_names, comments=comments) - cpdef object get_line(self, index_t line_nb): - cdef obifloat_t value - cdef object result + global obi_errno + cdef obifloat_t value + cdef object result value = obi_get_float_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBIFloat_NA : result = None else : result = value return result - cpdef set_line(self, index_t line_nb, object value): + global obi_errno if value is None : value = OBIFloat_NA if obi_set_float_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") cdef class Column_multi_elts_float(Column_multi_elts): cpdef object get_item(self, index_t line_nb, object elt_id) : - cdef obifloat_t value - cdef object result - cdef bytes elt_name + global obi_errno + cdef obifloat_t value + cdef object result + cdef bytes elt_name if type(elt_id) == int : value = obi_get_float_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id) else : elt_name = tobytes(elt_id) value = obi_get_float_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIFloat_NA : result = None else : @@ -70,16 +72,17 @@ cdef class Column_multi_elts_float(Column_multi_elts): return result cpdef object get_line(self, index_t line_nb) : - cdef obifloat_t value - cdef object value_in_result - cdef dict result - cdef index_t i - cdef bint all_NA + global obi_errno + cdef obifloat_t value + cdef object value_in_result + cdef dict result + cdef index_t i + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_float_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBIFloat_NA : value_in_result = None else : @@ -92,16 +95,17 @@ cdef class Column_multi_elts_float(Column_multi_elts): return result cpdef set_item(self, index_t line_nb, object elt_id, object value) : - cdef bytes elt_name + global obi_errno + cdef bytes elt_name if value is None : value = OBIFloat_NA if type(elt_id) == int : if obi_set_float_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_float_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") def register_class(): diff --git a/python/obitools3/dms/column/typed_column/int.pyx b/python/obitools3/dms/column/typed_column/int.pyx index 31bbb8f..b33c8d8 100644 --- a/python/obitools3/dms/column/typed_column/int.pyx +++ b/python/obitools3/dms/column/typed_column/int.pyx @@ -1,5 +1,6 @@ #cython: language_level=3 +from obitools3.dms.capi.obierrno cimport obi_errno from ..column cimport register_column_class @@ -34,10 +35,11 @@ cdef class Column_int(Column): cpdef object get_line(self, index_t line_nb): - cdef obiint_t value - cdef object result + global obi_errno + cdef obiint_t value + cdef object result value = obi_get_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBIInt_NA : result = None else : @@ -46,24 +48,26 @@ cdef class Column_int(Column): cpdef set_line(self, index_t line_nb, object value): + global obi_errno if value is None : value = OBIInt_NA if obi_set_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") cdef class Column_multi_elts_int(Column_multi_elts): cpdef object get_item(self, index_t line_nb, object elt_id) : - cdef obiint_t value - cdef object result - cdef bytes elt_name + global obi_errno + cdef obiint_t value + cdef object result + cdef bytes elt_name if type(elt_id) == int : value = obi_get_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id) else : elt_name = tobytes(elt_id) value = obi_get_int_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIInt_NA : result = None else : @@ -71,16 +75,17 @@ cdef class Column_multi_elts_int(Column_multi_elts): return result cpdef object get_line(self, index_t line_nb) : - cdef obiint_t value - cdef object value_in_result - cdef dict result - cdef index_t i - cdef bint all_NA + global obi_errno + cdef obiint_t value + cdef object value_in_result + cdef dict result + cdef index_t i + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBIInt_NA : value_in_result = None else : @@ -93,16 +98,17 @@ cdef class Column_multi_elts_int(Column_multi_elts): return result cpdef set_item(self, index_t line_nb, object elt_id, object value) : - cdef bytes elt_name + global obi_errno + cdef bytes elt_name if value is None : value = OBIInt_NA if type(elt_id) == int : if obi_set_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_int_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") def register_class(): diff --git a/python/obitools3/dms/column/typed_column/qual.pyx b/python/obitools3/dms/column/typed_column/qual.pyx index 89eae9d..106dcfa 100644 --- a/python/obitools3/dms/column/typed_column/qual.pyx +++ b/python/obitools3/dms/column/typed_column/qual.pyx @@ -1,5 +1,6 @@ #cython: language_level=3 +from obitools3.dms.capi.obierrno cimport obi_errno from ..column cimport register_column_class @@ -40,11 +41,12 @@ cdef class Column_qual(Column): cpdef object get_line(self, index_t line_nb): - cdef const uint8_t* value - cdef int value_length - cdef object result + global obi_errno + cdef const uint8_t* value + cdef int value_length + cdef object result value = obi_get_qual_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, &value_length) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBIQual_int_NA : result = None else : @@ -55,11 +57,12 @@ cdef class Column_qual(Column): cpdef object get_str_line(self, index_t line_nb): + global obi_errno cdef char* value cdef object result cdef int i value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBIQual_char_NA : result = None else : # TODO discuss @@ -69,45 +72,48 @@ cdef class Column_qual(Column): cpdef set_line(self, index_t line_nb, object value): - cdef uint8_t* value_b - cdef int value_length + global obi_errno + cdef uint8_t* value_b + cdef int value_length if value is None : if obi_set_qual_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, OBIQual_int_NA, 0) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") else : value_length = len(value) value_b = malloc(value_length * sizeof(uint8_t)) for i in range(value_length) : value_b[i] = value[i] if obi_set_qual_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b, value_length) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") free(value_b) cpdef set_str_line(self, index_t line_nb, object value): - cdef bytes value_b + global obi_errno + cdef bytes value_b if value is None : if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, OBIQual_char_NA) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") else : value_b = tobytes(value) if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") cdef class Column_multi_elts_qual(Column_multi_elts): cpdef object get_item(self, index_t line_nb, object elt_id): - cdef const uint8_t* value - cdef int value_length - cdef object result - cdef int i + global obi_errno + cdef const uint8_t* value + cdef int value_length + cdef object result + cdef int i if type(elt_id) == int : value = obi_get_qual_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, &value_length) else : elt_name = tobytes(elt_id) value = obi_get_qual_int_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, &value_length) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIQual_int_NA : result = None else : @@ -118,14 +124,15 @@ cdef class Column_multi_elts_qual(Column_multi_elts): cpdef object get_str_item(self, index_t line_nb, object elt_id): - cdef char* value - cdef object result + global obi_errno + cdef char* value + cdef object result if type(elt_id) == int : value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id) else : elt_name = tobytes(elt_id) value = obi_get_qual_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIQual_char_NA : result = None else : @@ -135,18 +142,19 @@ cdef class Column_multi_elts_qual(Column_multi_elts): cpdef object get_line(self, index_t line_nb) : - cdef const uint8_t* value - cdef int value_length - cdef object value_in_result - cdef dict result - cdef index_t i - cdef int j - cdef bint all_NA + global obi_errno + cdef const uint8_t* value + cdef int value_length + cdef object value_in_result + cdef dict result + cdef index_t i + cdef int j + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_qual_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i, &value_length) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBIQual_int_NA : value_in_result = None else : @@ -162,16 +170,17 @@ cdef class Column_multi_elts_qual(Column_multi_elts): cpdef object get_str_line(self, index_t line_nb) : - cdef char* value - cdef object value_in_result - cdef dict result - cdef index_t i - cdef bint all_NA + global obi_errno + cdef char* value + cdef object value_in_result + cdef dict result + cdef index_t i + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBIQual_char_NA : value_in_result = None else : @@ -186,9 +195,10 @@ cdef class Column_multi_elts_qual(Column_multi_elts): cpdef set_item(self, index_t line_nb, object elt_id, object value): - cdef uint8_t* value_b - cdef int value_length - cdef bytes elt_name + global obi_errno + cdef uint8_t* value_b + cdef int value_length + cdef bytes elt_name if value is None : value_b = OBIQual_int_NA @@ -201,19 +211,20 @@ cdef class Column_multi_elts_qual(Column_multi_elts): if type(elt_id) == int : if obi_set_qual_int_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b, value_length) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_qual_int_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b, value_length) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") if value is not None : free(value_b) cpdef set_str_item(self, index_t line_nb, object elt_id, object value): - cdef bytes value_b - cdef bytes elt_name + global obi_errno + cdef bytes value_b + cdef bytes elt_name if value is None : value_b = OBIQual_char_NA @@ -222,11 +233,11 @@ cdef class Column_multi_elts_qual(Column_multi_elts): if type(elt_id) == int : if obi_set_qual_char_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0 : - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_qual_char_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") diff --git a/python/obitools3/dms/column/typed_column/seq.pyx b/python/obitools3/dms/column/typed_column/seq.pyx index 94d3602..8f97776 100644 --- a/python/obitools3/dms/column/typed_column/seq.pyx +++ b/python/obitools3/dms/column/typed_column/seq.pyx @@ -1,5 +1,6 @@ #cython: language_level=3 +from obitools3.dms.capi.obierrno cimport obi_errno from ..column cimport register_column_class @@ -34,10 +35,11 @@ cdef class Column_seq(Column): cpdef object get_line(self, index_t line_nb): - cdef char* value - cdef object result + global obi_errno + cdef char* value + cdef object result value = obi_get_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBISeq_NA : result = None else : # TODO @@ -49,8 +51,9 @@ cdef class Column_seq(Column): cpdef set_line(self, index_t line_nb, object value): - cdef char* value_b - cdef bytes value_bytes + global obi_errno + cdef char* value_b + cdef bytes value_bytes if value is None : value_b = OBISeq_NA @@ -59,20 +62,21 @@ cdef class Column_seq(Column): value_b = value_bytes if obi_set_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") cdef class Column_multi_elts_seq(Column_multi_elts): cpdef object get_item(self, index_t line_nb, object elt_id) : - cdef char* value - cdef object result + global obi_errno + cdef char* value + cdef object result if type(elt_id) == int : value = obi_get_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id) else : elt_name = tobytes(elt_id) value = obi_get_seq_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBISeq_NA : result = None else : @@ -84,16 +88,17 @@ cdef class Column_multi_elts_seq(Column_multi_elts): cpdef object get_line(self, index_t line_nb) : - cdef char* value - cdef object value_in_result - cdef dict result - cdef index_t i - cdef bint all_NA + global obi_errno + cdef char* value + cdef object value_in_result + cdef dict result + cdef index_t i + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBISeq_NA : value_in_result = None else : @@ -110,10 +115,10 @@ cdef class Column_multi_elts_seq(Column_multi_elts): cpdef set_item(self, index_t line_nb, object elt_id, object value): - - cdef bytes elt_name - cdef char* value_b - cdef bytes value_bytes + global obi_errno + cdef bytes elt_name + cdef char* value_b + cdef bytes value_bytes if value is None : value_b = OBISeq_NA @@ -123,12 +128,12 @@ cdef class Column_multi_elts_seq(Column_multi_elts): if type(elt_id) == int : if obi_set_seq_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_seq_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") def register_class(): diff --git a/python/obitools3/dms/column/typed_column/str.pyx b/python/obitools3/dms/column/typed_column/str.pyx index a876e9e..1b4f263 100644 --- a/python/obitools3/dms/column/typed_column/str.pyx +++ b/python/obitools3/dms/column/typed_column/str.pyx @@ -1,5 +1,6 @@ #cython: language_level=3 +from obitools3.dms.capi.obierrno cimport obi_errno from ..column cimport register_column_class @@ -32,10 +33,11 @@ cdef class Column_str(Column): cpdef object get_line(self, index_t line_nb): - cdef const_char_p value - cdef object result + global obi_errno + cdef const_char_p value + cdef object result value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0) - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem getting a value from a column") if value == OBIStr_NA : result = None else : @@ -44,8 +46,9 @@ cdef class Column_str(Column): cpdef set_line(self, index_t line_nb, object value): - cdef char* value_b - cdef bytes value_bytes + global obi_errno + cdef char* value_b + cdef bytes value_bytes if value is None : value_b = OBIStr_NA @@ -54,20 +57,21 @@ cdef class Column_str(Column): value_b = value_bytes if obi_set_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, 0, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=None, error_message="Problem setting a value in a column") cdef class Column_multi_elts_str(Column_multi_elts): cpdef object get_item(self, index_t line_nb, object elt_id) : - cdef const_char_p value - cdef object result + global obi_errno + cdef const_char_p value + cdef object result if type(elt_id) == int : value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id) else : elt_name = tobytes(elt_id) value = obi_get_str_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name) - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem getting a value from a column") if value == OBIStr_NA : result = None else : @@ -76,16 +80,17 @@ cdef class Column_multi_elts_str(Column_multi_elts): cpdef object get_line(self, index_t line_nb) : - cdef const_char_p value - cdef object value_in_result - cdef dict result - cdef index_t i - cdef bint all_NA + global obi_errno + cdef const_char_p value + cdef object value_in_result + cdef dict result + cdef index_t i + cdef bint all_NA result = {} all_NA = True for i in range(self.nb_elements_per_line) : value = obi_get_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, i) - obi_errno_to_exception(line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=i, error_message="Problem getting a value from a column") if value == OBIStr_NA : value_in_result = None else : @@ -99,10 +104,11 @@ cdef class Column_multi_elts_str(Column_multi_elts): cpdef set_item(self, index_t line_nb, object elt_id, object value): - cdef bytes elt_name - cdef char* value_b - cdef bytes value_bytes - + global obi_errno + cdef bytes elt_name + cdef char* value_b + cdef bytes value_bytes + if value is None : value_b = OBIStr_NA else : @@ -111,11 +117,11 @@ cdef class Column_multi_elts_str(Column_multi_elts): if type(elt_id) == int : if obi_set_str_with_elt_idx_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_id, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") else : elt_name = tobytes(elt_id) if obi_set_str_with_elt_name_and_col_p_in_view(self._view.pointer(), self.pointer(), line_nb, elt_name, value_b) < 0: - obi_errno_to_exception(line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") + obi_errno_to_exception(obi_errno, line_nb=line_nb, elt_id=elt_id, error_message="Problem setting a value in a column") def register_class(): diff --git a/python/obitools3/utils.pxd b/python/obitools3/utils.pxd index f52eac9..3a6db25 100644 --- a/python/obitools3/utils.pxd +++ b/python/obitools3/utils.pxd @@ -2,7 +2,7 @@ from obitools3.dms.capi.obitypes cimport obitype_t, index_t -cdef obi_errno_to_exception(index_t line_nb=*, object elt_id=*, str error_message=*) +cdef obi_errno_to_exception(int obi_errno, index_t line_nb=*, object elt_id=*, str error_message=*) cdef bytes str2bytes(str string) cdef str bytes2str(bytes string) diff --git a/python/obitools3/utils.pyx b/python/obitools3/utils.pyx index 72162ce..5d5cbdc 100644 --- a/python/obitools3/utils.pyx +++ b/python/obitools3/utils.pyx @@ -11,12 +11,12 @@ from obitools3.dms.capi.obitypes cimport is_a_DNA_seq, \ OBI_STR, \ index_t -from obitools3.dms.capi.obierrno cimport obi_errno, \ - OBI_LINE_IDX_ERROR, \ +from obitools3.dms.capi.obierrno cimport OBI_LINE_IDX_ERROR, \ OBI_ELT_IDX_ERROR + #obi_errno -cdef obi_errno_to_exception(index_t line_nb=-1, object elt_id=None, str error_message=None) : +cdef obi_errno_to_exception(int obi_errno, index_t line_nb=-1, object elt_id=None, str error_message=None) : global obi_errno if obi_errno > 0 : if obi_errno == OBI_LINE_IDX_ERROR :