Ejemplo n.º 1
0
 def _add_function_obj(self, wrapper):
     assert isinstance(wrapper, Function)
     name = utils.ascii(wrapper.custom_name)
     if name is None:
         name = self.c_function_name_transformer(wrapper.function_name)
         name = utils.get_mangled_name(name, wrapper.template_parameters)
     try:
         overload = self.functions[name]
     except KeyError:
         overload = OverloadedFunction(name)
         self.functions[name] = overload
     wrapper.module = self
     wrapper.section = self.current_section
     overload.add(wrapper)
Ejemplo n.º 2
0
 def _add_function_obj(self, wrapper):
     assert isinstance(wrapper, Function)
     name = utils.ascii(wrapper.custom_name)
     if name is None:
         name = self.c_function_name_transformer(wrapper.function_name)
         name = utils.get_mangled_name(name, wrapper.template_parameters)
     try:
         overload = self.functions[name]
     except KeyError:
         overload = OverloadedFunction(name)
         self.functions[name] = overload
     wrapper.module = self
     wrapper.section = self.current_section
     overload.add(wrapper)
Ejemplo n.º 3
0
    def __init__(
        self,
        function_name,
        return_value,
        parameters,
        docstring=None,
        unblock_threads=None,
        template_parameters=(),
        custom_name=None,
        deprecated=False,
        foreign_cpp_namespace=None,
        throw=(),
    ):
        """
        :param function_name: name of the C function
        :param return_value: the function return value
        :type return_value: L{ReturnValue}
        :param parameters: the function parameters
        :type parameters: list of L{Parameter}

        :param custom_name: an alternative name to give to this
           function at python-side; if omitted, the name of the
           function in the python module will be the same name as the
           function in C++ (minus namespace).

        :param deprecated: deprecation state for this API:
          - False: Not deprecated
          - True: Deprecated
          - "message": Deprecated, and deprecation warning contains the given message

        :param foreign_cpp_namespace: if set, the function is assumed
          to belong to the given C++ namespace, regardless of the C++
          namespace of the python module it will be added to.

        :param throw: list of C++ exceptions that the function may throw
        :type throw: list of L{CppException}
        """
        self.stack_where_defined = traceback.extract_stack()

        if unblock_threads is None:
            unblock_threads = settings.unblock_threads

        ## backward compatibility check
        if isinstance(return_value, str) and isinstance(function_name, ReturnValue):
            warnings.warn(
                "Function has changed API; see the API documentation (but trying to correct...)",
                DeprecationWarning,
                stacklevel=2,
            )
            function_name, return_value = return_value, function_name

        if return_value is None:
            return_value = ReturnValue.new("void")

        return_value = utils.eval_retval(return_value, self)
        parameters = [utils.eval_param(param, self) for param in parameters]

        super(Function, self).__init__(
            return_value,
            parameters,
            parse_error_return="return NULL;",
            error_return="return NULL;",
            unblock_threads=unblock_threads,
        )
        self.deprecated = deprecated
        self.foreign_cpp_namespace = foreign_cpp_namespace
        self._module = None
        function_name = utils.ascii(function_name)
        self.function_name = function_name
        self.wrapper_base_name = None
        self.wrapper_actual_name = None
        self.docstring = docstring
        self.self_parameter_pystruct = None
        self.template_parameters = template_parameters
        self.custom_name = custom_name
        self.mangled_name = utils.get_mangled_name(function_name, self.template_parameters)
        for t in throw:
            assert isinstance(t, CppException)
        self.throw = list(throw)
        self.custodians_and_wards = []  # list of (custodian, ward, postcall)
        cppclass_typehandlers.scan_custodians_and_wards(self)
Ejemplo n.º 4
0
 def set_custom_name(self, custom_name):
     if custom_name is None:
         self.mangled_name = utils.get_mangled_name(self.method_name, self.template_parameters)
     else:
         self.mangled_name = custom_name
Ejemplo n.º 5
0
    def __init__(self,
                 function_name,
                 return_value,
                 parameters,
                 docstring=None,
                 unblock_threads=None,
                 template_parameters=(),
                 custom_name=None,
                 deprecated=False,
                 foreign_cpp_namespace=None,
                 throw=()):
        """
        :param function_name: name of the C function
        :param return_value: the function return value
        :type return_value: L{ReturnValue}
        :param parameters: the function parameters
        :type parameters: list of L{Parameter}

        :param custom_name: an alternative name to give to this
           function at python-side; if omitted, the name of the
           function in the python module will be the same name as the
           function in C++ (minus namespace).

        :param deprecated: deprecation state for this API:
          - False: Not deprecated
          - True: Deprecated
          - "message": Deprecated, and deprecation warning contains the given message

        :param foreign_cpp_namespace: if set, the function is assumed
          to belong to the given C++ namespace, regardless of the C++
          namespace of the python module it will be added to.

        :param throw: list of C++ exceptions that the function may throw
        :type throw: list of L{CppException}
        """
        self.stack_where_defined = traceback.extract_stack()

        if unblock_threads is None:
            unblock_threads = settings.unblock_threads

        ## backward compatibility check
        if isinstance(return_value, str) and isinstance(
                function_name, ReturnValue):
            warnings.warn(
                "Function has changed API; see the API documentation (but trying to correct...)",
                DeprecationWarning,
                stacklevel=2)
            function_name, return_value = return_value, function_name

        if return_value is None:
            return_value = ReturnValue.new('void')

        return_value = utils.eval_retval(return_value, self)
        parameters = [utils.eval_param(param, self) for param in parameters]

        super(Function, self).__init__(return_value,
                                       parameters,
                                       parse_error_return="return NULL;",
                                       error_return="return NULL;",
                                       unblock_threads=unblock_threads)
        self.deprecated = deprecated
        self.foreign_cpp_namespace = foreign_cpp_namespace
        self._module = None
        function_name = utils.ascii(function_name)
        self.function_name = function_name
        self.wrapper_base_name = None
        self.wrapper_actual_name = None
        self.docstring = docstring
        self.self_parameter_pystruct = None
        self.template_parameters = template_parameters
        self.custom_name = custom_name
        self.mangled_name = utils.get_mangled_name(function_name,
                                                   self.template_parameters)
        for t in throw:
            assert isinstance(t, CppException)
        self.throw = list(throw)
        self.custodians_and_wards = []  # list of (custodian, ward, postcall)
        cppclass_typehandlers.scan_custodians_and_wards(self)
Ejemplo n.º 6
0
 def set_custom_name(self, custom_name):
     if custom_name is None:
         self.mangled_name = utils.get_mangled_name(
             self.method_name, self.template_parameters)
     else:
         self.mangled_name = custom_name