<commit_before># docstrings not neede here (the type handler interfaces are fully
# documented in base.py) pylint: disable-msg=C0111

from base import ReturnValue, Parameter, \
     ReverseWrapperBase, ForwardWrapperBase


class BoolParam(Parameter):

    DIRECTIONS = [Parameter.DIRECTION_IN]
    CTYPES = ['bool']

    def convert_c_to_python(self, wrapper):
        assert isinstance(wrapper, ReverseWrapperBase)
        wrapper.build_params.add_parameter('N', ["PyBool_FromLong(%s)" % (self.value,)])

    def convert_python_to_c(self, wrapper):
        assert isinstance(wrapper, ForwardWrapperBase)
        name = wrapper.declarations.declare_variable(self.ctype_no_const, self.name)
        py_name = wrapper.declarations.declare_variable('PyObject *', 'py_'+self.name)
        wrapper.parse_params.add_parameter('O', ['&'+py_name], self.value)
        wrapper.before_call.write_code("%s = (bool) PyObject_IsTrue(%s);" % (name, py_name))
        wrapper.call_params.append(name)


class BoolReturn(ReturnValue):

    CTYPES = ['bool']

    def get_c_error_return(self):
        return "return false;"<commit_msg>Support default_value for boolean type handler<commit_after># docstrings not neede here (the type handler interfaces are fully
# documented in base.py) pylint: disable-msg=C0111

from base import ReturnValue, Parameter, \
     ReverseWrapperBase, ForwardWrapperBase


class BoolParam(Parameter):

    DIRECTIONS = [Parameter.DIRECTION_IN]
    CTYPES = ['bool']

    def convert_c_to_python(self, wrapper):
        assert isinstance(wrapper, ReverseWrapperBase)
        wrapper.build_params.add_parameter('N', ["PyBool_FromLong(%s)" % (self.value,)])

    def convert_python_to_c(self, wrapper):
        assert isinstance(wrapper, ForwardWrapperBase)
        name = wrapper.declarations.declare_variable(self.ctype_no_const, self.name)
        if self.default_value:
            py_name = wrapper.declarations.declare_variable('PyObject *', 'py_'+self.name)
        else:
            py_name = wrapper.declarations.declare_variable('PyObject *', 'py_'+self.name, 'NULL')
        wrapper.parse_params.add_parameter('O', ['&'+py_name], self.value, optional=(self.default_value is not None))
        if self.default_value:
            wrapper.before_call.write_code("%s = %s? (bool) PyObject_IsTrue(%s) : %s;" % (name, py_name, py_name, self.default_value))
        else:
            wrapper.before_call.write_code("%s = (bool) PyObject_IsTrue(%s);" % (name, py_name))
        wrapper.call_params.append(name)


class BoolReturn(ReturnValue):

    CTYPES = ['bool']

    def get_c_error_return(self):
        return "return false;"
{'fraction_non_alphanumeric': 0.11942554799697656, 'fraction_numerical': 0.0030234315948601664, 'mean_word_length': 4.022770398481973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6065432', 'n_tokens_mistral': 839, 'n_tokens_neox': 801, 'n_words': 163}