Esempio n. 1
0
    def put_code(self, output):
        code = output['utility_code_def']
        proto = output['utility_code_proto']

        proto.put(Buffer.dedent("""\
                static __Pyx_memviewslice %s(const __Pyx_memviewslice from_mvs); /* proto */
        """ % self.copy_func_name))

        copy_contents_name = get_copy_contents_name(self.from_memview, self.to_memview)

        if self.to_memview.is_c_contig:
            mode = 'c'
            contig_flag = memview_c_contiguous
        elif self.to_memview.is_f_contig:
            mode = 'fortran'
            contig_flag = memview_f_contiguous

        C = dict(
            context,
            copy_name=self.copy_func_name,
            mode=mode,
            sizeof_dtype="sizeof(%s)" % self.from_memview.dtype.declaration_code(''),
            contig_flag=contig_flag,
            copy_contents_name=copy_contents_name
        )

        _, copy_code = TempitaUtilityCode.load_as_string(
                    "MemviewSliceCopyTemplate",
                    from_file="MemoryView_C.c",
                    context=C)
        code.put(copy_code)
Esempio n. 2
0
def load_memview_c_utility(util_code_name, context=None, **kwargs):
    if context is None:
        return UtilityCode.load(util_code_name, "MemoryView_C.c", **kwargs)
    else:
        return TempitaUtilityCode.load(util_code_name,
                                       "MemoryView_C.c",
                                       context=context,
                                       **kwargs)
Esempio n. 3
0
def load_buffer_utility(util_code_name, context=None, **kwargs):
    if context is None:
        return UtilityCode.load(util_code_name, "Buffer.c", **kwargs)
    else:
        return TempitaUtilityCode.load(util_code_name,
                                       "Buffer.c",
                                       context=context,
                                       **kwargs)
Esempio n. 4
0
    def put_code(self, output):
        code = output['utility_code_def']
        proto_code = output['utility_code_proto']
        env = output.module_node.scope
        cython_scope = env.context.cython_scope

        # Search all types for __getbuffer__ overloads
        types = []
        visited_scopes = set()

        def find_buffer_types(scope):
            if scope in visited_scopes:
                return
            visited_scopes.add(scope)
            for m in scope.cimported_modules:
                find_buffer_types(m)
            for e in scope.type_entries:
                if isinstance(e.utility_code_definition, CythonUtilityCode):
                    continue
                t = e.type
                if t.is_extension_type:
                    if scope is cython_scope and not e.used:
                        continue
                    release = get = None
                    for x in t.scope.pyfunc_entries:
                        if x.name == u"__getbuffer__": get = x.func_cname
                        elif x.name == u"__releasebuffer__":
                            release = x.func_cname
                    if get:
                        types.append((t.typeptr_cname, get, release))

        find_buffer_types(env)

        proto, impl = TempitaUtilityCode.load_as_string(
            "GetAndReleaseBuffer",
            from_file="Buffer.c",
            context=dict(types=types))

        proto_code.putln(proto)
        code.putln(impl)
Esempio n. 5
0
File: Buffer.py Progetto: 87/cython
    def put_code(self, output):
        code = output['utility_code_def']
        proto_code = output['utility_code_proto']
        env = output.module_node.scope
        cython_scope = env.context.cython_scope
        
        # Search all types for __getbuffer__ overloads
        types = []
        visited_scopes = set()
        def find_buffer_types(scope):
            if scope in visited_scopes:
                return
            visited_scopes.add(scope)
            for m in scope.cimported_modules:
                find_buffer_types(m)
            for e in scope.type_entries:
                if isinstance(e.utility_code_definition, CythonUtilityCode):
                    continue
                t = e.type
                if t.is_extension_type:
                    if scope is cython_scope and not e.used:
                        continue
                    release = get = None
                    for x in t.scope.pyfunc_entries:
                        if x.name == u"__getbuffer__": get = x.func_cname
                        elif x.name == u"__releasebuffer__": release = x.func_cname
                    if get:
                        types.append((t.typeptr_cname, get, release))

        find_buffer_types(env)

        proto, impl = TempitaUtilityCode.load_as_string(
            "GetAndReleaseBuffer", from_file="Buffer.c",
            context=dict(types=types))

        proto_code.putln(proto)
        code.putln(impl)
Esempio n. 6
0
def load_memview_c_utility(util_code_name, context=None, **kwargs):
    if context is None:
        return UtilityCode.load(util_code_name, "MemoryView_C.c", **kwargs)
    else:
        return TempitaUtilityCode.load(util_code_name, "MemoryView_C.c",
                                       context=context, **kwargs)
Esempio n. 7
0
 def load_slice_util(name, dict):
     proto, impl = TempitaUtilityCode.load_as_string(
                 name, "MemoryView_C.c", context=dict)
     return impl
Esempio n. 8
0
File: Buffer.py Progetto: 87/cython
def load_buffer_utility(util_code_name, context=None, **kwargs):
    if context is None:
        return UtilityCode.load(util_code_name, "Buffer.c", **kwargs)
    else:
        return TempitaUtilityCode.load(util_code_name, "Buffer.c", context=context, **kwargs)
Esempio n. 9
0
 def load_slice_util(name, dict):
     proto, impl = TempitaUtilityCode.load_as_string(name,
                                                     "MemoryView_C.c",
                                                     context=dict)
     return impl