Trap potential exception generated by char* to bytes casts
This commit is contained in:
@ -27,16 +27,24 @@ cdef class OBIDMS_column_seq(OBIDMS_column):
|
||||
if strcmp(value, OBISeq_NA) == 0 :
|
||||
result = None
|
||||
else :
|
||||
result = <bytes> value
|
||||
free(value)
|
||||
try:
|
||||
result = <bytes> value
|
||||
finally:
|
||||
free(value)
|
||||
return result
|
||||
|
||||
cpdef set_line(self, index_t line_nb, object value):
|
||||
cdef bytes value_b
|
||||
|
||||
if value is None :
|
||||
value_b = OBISeq_NA
|
||||
else :
|
||||
elif isinstance(value, bytes) :
|
||||
value_b = value
|
||||
elif isinstance(value, str) :
|
||||
value_b = str2bytes(value)
|
||||
else:
|
||||
raise TypeError('Sequence value must be of type Bytes, Str or None')
|
||||
|
||||
if obi_column_set_obiseq_with_elt_idx_in_view(self.view.pointer, (self.pointer)[0], line_nb, 0, value_b) < 0:
|
||||
raise Exception("Problem setting a value in a column")
|
||||
|
||||
@ -64,9 +72,10 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
|
||||
if strcmp(value, OBISeq_NA) == 0 :
|
||||
result = None
|
||||
else :
|
||||
result = <bytes> value
|
||||
# Be careful, we have to be sure that the cast copy the data in the python structure
|
||||
free(value)
|
||||
try:
|
||||
result = <bytes> value
|
||||
finally:
|
||||
free(value)
|
||||
return result
|
||||
|
||||
|
||||
@ -85,8 +94,10 @@ cdef class OBIDMS_column_multi_elts_seq(OBIDMS_column_multi_elts):
|
||||
if strcmp(value, OBISeq_NA) == 0 :
|
||||
value_in_result = None
|
||||
else :
|
||||
value_in_result = <bytes> value
|
||||
free(value)
|
||||
try:
|
||||
value_in_result = <bytes> value
|
||||
finally:
|
||||
free(value)
|
||||
result[self.elements_names[i]] = value_in_result
|
||||
if all_NA and (value_in_result is not None) :
|
||||
all_NA = False
|
||||
|
Reference in New Issue
Block a user