Exemple #1
0
    def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
        """
        Generates the wrapper code

        :param code_sink: a CodeSink instance that will receive the generated code
        :param wrapper_name: name of wrapper function
        """

        if self.throw:  # Bug #780945
            self.return_value.REQUIRES_ASSIGNMENT_CONSTRUCTOR = False
            self.reset_code_generation_state()

        if wrapper_name is None:
            self.wrapper_actual_name = self.wrapper_base_name
        else:
            self.wrapper_actual_name = wrapper_name
        tmp_sink = codesink.MemoryCodeSink()
        self.generate_body(tmp_sink)

        flags = self.get_py_method_def_flags()
        self.wrapper_args = []
        if 'METH_VARARGS' in flags:
            if self.self_parameter_pystruct is None:
                self_param = 'PyObject * PYBINDGEN_UNUSED(dummy)'
            else:
                self_param = '%s *self' % self.self_parameter_pystruct
            self.wrapper_args.append(self_param)
            self.wrapper_args.append("PyObject *args")
            if 'METH_KEYWORDS' in flags:
                self.wrapper_args.append("PyObject *kwargs")
        self.wrapper_args.extend(extra_wrapper_params)
        self.wrapper_return = "PyObject *"
        self.write_open_wrapper(code_sink)
        tmp_sink.flush_to(code_sink)
        self.write_close_wrapper(code_sink)
Exemple #2
0
    def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
        """
        Generates the wrapper code
        code_sink -- a CodeSink instance that will receive the generated code
        method_name -- actual name the method will get
        extra_wrapper_params -- extra parameters the wrapper function should receive

        Returns the corresponding PyMethodDef entry string.
        """
        class_ = self.class_
        #assert isinstance(class_, CppClass)
        tmp_sink = codesink.MemoryCodeSink()

        self.generate_body(tmp_sink, gen_call_params=[class_])

        if wrapper_name is None:
            self.wrapper_actual_name = self.wrapper_base_name
        else:
            self.wrapper_actual_name = wrapper_name

        self.get_wrapper_signature(self.wrapper_actual_name,
                                   extra_wrapper_params)
        self.write_open_wrapper(code_sink)  #, add_static=self.static_decl)
        tmp_sink.flush_to(code_sink)
        self.write_close_wrapper(code_sink)
Exemple #3
0
    def generate(self, code_sink):
        """
        code_sink -- a CodeSink instance that will receive the generated code
        """

        tmp_sink = codesink.MemoryCodeSink()
        self.generate_body(tmp_sink)
        code_sink.writeln("static PyObject* %s(%s *self)" %
                          (self.c_function_name, self.container.iter_pystruct))
        code_sink.writeln('{')
        code_sink.indent()
        tmp_sink.flush_to(code_sink)
        code_sink.unindent()
        code_sink.writeln('}')
Exemple #4
0
 def generate(self, code_sink):
     """
     :param code_sink: a CodeSink instance that will receive the generated code
     """
     tmp_sink = codesink.MemoryCodeSink()
     self.generate_body(tmp_sink)
     code_sink.writeln(
         "static PyObject* %s(%s *self, void * PYBINDGEN_UNUSED(closure))" %
         (self.c_function_name, self.class_.pystruct))
     code_sink.writeln('{')
     code_sink.indent()
     tmp_sink.flush_to(code_sink)
     code_sink.unindent()
     code_sink.writeln('}')
Exemple #5
0
    def generate(self, code_sink, wrapper_name=None, extra_wrapper_params=()):
        """
        Generates the wrapper code
        :param code_sink: a CodeSink instance that will receive the generated code
        :returns: the wrapper function name.

        """

        if self.visibility == 'private':
            raise utils.SkipWrapper("Class %r has a private constructor ->"
                                    " cannot generate a constructor for it" %
                                    self._class.full_name)
        elif self.visibility == 'protected':
            if self._class.helper_class is None:
                raise utils.SkipWrapper(
                    "Class %r has a protected constructor and no helper class"
                    " -> cannot generate a constructor for it" %
                    self._class.full_name)

        #assert isinstance(class_, CppClass)
        tmp_sink = codesink.MemoryCodeSink()

        assert self._class is not None
        self.generate_body(tmp_sink, gen_call_params=[self._class])

        assert ((self.parse_params.get_parameters() == ['""'])
                or self.parse_params.get_keywords() is not None), \
               ("something went wrong with the type handlers;"
                " constructors need parameter names, "
                "yet no names were given for the class %s constructor"
                % self._class.name)

        if wrapper_name is None:
            self.wrapper_actual_name = self.wrapper_base_name
        else:
            self.wrapper_actual_name = wrapper_name

        self.wrapper_return = 'static int'
        self.wrapper_args = [
            "%s *self" % self._class.pystruct, "PyObject *args",
            "PyObject *kwargs"
        ]
        self.wrapper_args.extend(extra_wrapper_params)

        self.write_open_wrapper(code_sink)
        tmp_sink.flush_to(code_sink)
        code_sink.writeln('return 0;')
        self.write_close_wrapper(code_sink)