Bug in the "get_bool" Function in "scripts/python3/telapy/api/masc.py"
Affected File:
scripts/python3/telapy/api/masc.py
Issue Description:
In the get_bool function, the following return statement is incorrect (line 445):
return val_c.value == val_c.value
This expression always returns True (unless val_c.value is NaN, which is not the case here), because it compares the value to itself. As a result, it does not correctly return the actual boolean value provided by the C_GET_BOOL_MASCARET API.
Proposed Fix: Replace the faulty line with:
return bool(val_c.value)
This properly converts the returned integer value (0 or 1) into a Python boolean (False or True).
Corrected Code:
def get_bool(self, var_name, i=0, j=0, k=0):
"""Get the boolean value of a Mascaret variable
Mascaret Api :meth:`C_GET_BOOL_MASCARET`
@param var_name (str) name of the Mascaret variable
@param i (int) first index of the Mascaret variable
@param j (int) second index of the Mascaret variable
@param k (int) third index of the Mascaret variable
@return (bool) scalar value
"""
var_name_c = (ctypes.c_char_p * 1)(var_name.encode('utf8'))
id_masc_c = (ctypes.c_int * 1)(self.id_masc)
val_c = ctypes.c_int()
i_c = ctypes.c_int(i)
j_c = ctypes.c_int(j)
k_c = ctypes.c_int(k)
self.logger.debug('Getting {}...'.format(var_name))
self.error = self.libmascaret.C_GET_BOOL_MASCARET(
id_masc_c, var_name_c, ctypes.byref(i_c), ctypes.byref(j_c),
ctypes.byref(k_c), ctypes.byref(val_c))
self.logger.debug('Value: val={}.'.format(val_c.value))
return bool(val_c.value)