Ejemplo n.º 1
0
 def __init__(self, method_name, wrapper_name, wrapper_body=None,
              flags=('METH_VARARGS', 'METH_KEYWORDS')):
     super(CustomCppMethodWrapper, self).__init__(method_name, ReturnValue.new('void'), [])
     self.wrapper_base_name = wrapper_name
     self.wrapper_actual_name = wrapper_name
     self.meth_flags = list(flags)
     self.wrapper_body = wrapper_body
Ejemplo n.º 2
0
 def __init__(self,
              method_name,
              wrapper_name,
              wrapper_body=None,
              flags=('METH_VARARGS', 'METH_KEYWORDS')):
     super(CustomCppMethodWrapper, self).__init__(method_name,
                                                  ReturnValue.new('void'),
                                                  [])
     self.wrapper_base_name = wrapper_name
     self.wrapper_actual_name = wrapper_name
     self.meth_flags = list(flags)
     self.wrapper_body = wrapper_body
Ejemplo n.º 3
0
 def __init__(self, function_name, wrapper_name, wrapper_body=None, flags=("METH_VARARGS", "METH_KEYWORDS")):
     """
     :param function_name: name for function, Python side
     :param wrapper_name: name of the C wrapper function
     :param wrapper_body: if not None, the function wrapper is generated containing this parameter value as function body
     """
     super(CustomFunctionWrapper, self).__init__(function_name, ReturnValue.new("void"), [])
     self.wrapper_base_name = wrapper_name
     self.wrapper_actual_name = wrapper_name
     self.meth_flags = list(flags)
     self.wrapper_body = wrapper_body
     self.wrapper_args = ["PyObject *args", "PyObject *kwargs", "PyObject **return_exception"]
     self.wrapper_return = "PyObject *"
Ejemplo n.º 4
0
 def __init__(self,
              function_name,
              wrapper_name,
              wrapper_body=None,
              flags=('METH_VARARGS', 'METH_KEYWORDS')):
     """
     :param function_name: name for function, Python side
     :param wrapper_name: name of the C wrapper function
     :param wrapper_body: if not None, the function wrapper is generated containing this parameter value as function body
     """
     super(CustomFunctionWrapper, self).__init__(function_name,
                                                 ReturnValue.new('void'),
                                                 [])
     self.wrapper_base_name = wrapper_name
     self.wrapper_actual_name = wrapper_name
     self.meth_flags = list(flags)
     self.wrapper_body = wrapper_body
     self.wrapper_args = [
         "PyObject *args", "PyObject *kwargs", "PyObject **return_exception"
     ]
     self.wrapper_return = "PyObject *"
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 __init__(
        self,
        method_name,
        return_value,
        parameters,
        is_static=False,
        template_parameters=(),
        is_virtual=None,
        is_const=False,
        unblock_threads=None,
        is_pure_virtual=False,
        custom_template_method_name=None,
        visibility="public",
        custom_name=None,
        deprecated=False,
        docstring=None,
        throw=(),
    ):
        """
        Create an object the generates code to wrap a C++ class method.

        :param return_value: the method return value
        :type  return_value: L{ReturnValue}

        :param method_name: name of the method

        :param parameters: the method parameters
        :type parameters: list of :class:`pybindgen.typehandlers.base.Parameter`

        :param is_static: whether it is a static method

        :param template_parameters: optional list of template parameters needed to invoke the method
        :type template_parameters: list of strings, each element a template parameter expression

        :param is_virtual: whether the method is virtual (pure or not)

        :param is_const: whether the method has a const modifier on it

        :param unblock_threads: whether to release the Python GIL
            around the method call or not.  If None or omitted, use
            global settings.  Releasing the GIL has a small
            performance penalty, but is recommended if the method is
            expected to take considerable time to complete, because
            otherwise no other Python thread is allowed to run until
            the method completes.

        :param is_pure_virtual: whether the method is defined as "pure
          virtual", i.e. virtual method with no default implementation
          in the class being wrapped.

        :param custom_name: alternate name to give to the method, in python side.

        :param custom_template_method_name: (deprecated) same as parameter 'custom_name'.

        :param visibility: visibility of the method within the C++ class
        :type visibility: a string (allowed values are 'public', 'protected', 'private')

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

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

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

        # bug 399870
        if is_virtual is None:
            is_virtual = is_pure_virtual

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

        if unblock_threads is None:
            unblock_threads = settings.unblock_threads

        assert visibility in ["public", "protected", "private"]
        self.visibility = visibility
        self.method_name = method_name
        self.is_static = is_static
        self.is_virtual = is_virtual
        self.is_pure_virtual = is_pure_virtual
        self.is_const = is_const
        self.template_parameters = template_parameters

        self.custom_name = custom_name or custom_template_method_name

        # self.static_decl = True
        self._class = None
        self._helper_class = None
        self.docstring = docstring
        self.wrapper_base_name = None
        self.wrapper_actual_name = None
        self.return_value = None
        self.parameters = None

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

        super(CppMethod, self).__init__(
            return_value, parameters, "return NULL;", "return NULL;", unblock_threads=unblock_threads
        )
        self.deprecated = deprecated

        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.º 7
0
def _get_dummy_container():
    return Container('dummy', ReturnValue.new('void'),
                     'list')  # Container instance
Ejemplo n.º 8
0
def _get_dummy_container():
    return Container('dummy', ReturnValue.new('void'), 'list') # Container instance
Ejemplo n.º 9
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.º 10
0
    def __init__(self,
                 method_name,
                 return_value,
                 parameters,
                 is_static=False,
                 template_parameters=(),
                 is_virtual=None,
                 is_const=False,
                 unblock_threads=None,
                 is_pure_virtual=False,
                 custom_template_method_name=None,
                 visibility='public',
                 custom_name=None,
                 deprecated=False,
                 docstring=None,
                 throw=()):
        """
        Create an object the generates code to wrap a C++ class method.

        :param return_value: the method return value
        :type  return_value: L{ReturnValue}

        :param method_name: name of the method

        :param parameters: the method parameters
        :type parameters: list of :class:`pybindgen.typehandlers.base.Parameter`

        :param is_static: whether it is a static method

        :param template_parameters: optional list of template parameters needed to invoke the method
        :type template_parameters: list of strings, each element a template parameter expression

        :param is_virtual: whether the method is virtual (pure or not)

        :param is_const: whether the method has a const modifier on it

        :param unblock_threads: whether to release the Python GIL
            around the method call or not.  If None or omitted, use
            global settings.  Releasing the GIL has a small
            performance penalty, but is recommended if the method is
            expected to take considerable time to complete, because
            otherwise no other Python thread is allowed to run until
            the method completes.

        :param is_pure_virtual: whether the method is defined as "pure
          virtual", i.e. virtual method with no default implementation
          in the class being wrapped.

        :param custom_name: alternate name to give to the method, in python side.

        :param custom_template_method_name: (deprecated) same as parameter 'custom_name'.

        :param visibility: visibility of the method within the C++ class
        :type visibility: a string (allowed values are 'public', 'protected', 'private')

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

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

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

        # bug 399870
        if is_virtual is None:
            is_virtual = is_pure_virtual

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

        if unblock_threads is None:
            unblock_threads = settings.unblock_threads

        assert visibility in ['public', 'protected', 'private']
        self.visibility = visibility
        self.method_name = method_name
        self.is_static = is_static
        self.is_virtual = is_virtual
        self.is_pure_virtual = is_pure_virtual
        self.is_const = is_const
        self.template_parameters = template_parameters

        self.custom_name = (custom_name or custom_template_method_name)

        #self.static_decl = True
        self._class = None
        self._helper_class = None
        self.docstring = docstring
        self.wrapper_base_name = None
        self.wrapper_actual_name = None
        self.return_value = None
        self.parameters = None

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

        super(CppMethod, self).__init__(return_value,
                                        parameters,
                                        "return NULL;",
                                        "return NULL;",
                                        unblock_threads=unblock_threads)
        self.deprecated = deprecated

        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)