From 381380c93c648804caf9984754ed57b82e632251 Mon Sep 17 00:00:00 2001 From: Mark Florisson <markflorisson88@gmail.com> Date: Wed, 24 Aug 2011 12:22:57 +0200 Subject: [PATCH] Silence some warnings --- Cython/Compiler/Code.py | 3 ++- Cython/Compiler/MemoryView.py | 8 ++++++-- Cython/Compiler/Symtab.py | 3 ++- Cython/Utility/MemoryView.pyx | 9 ++++++++- Cython/Utility/MemoryView_C.c | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 70b3367da..bcf97b7d7 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -1466,7 +1466,8 @@ class CCodeWriter(object): if type.is_pyobject: self.putln("%s = NULL;" % decl) elif type.is_memoryviewslice: - self.putln("%s = { 0 };" % decl) + import MemoryView + self.putln("%s = %s;" % (decl, MemoryView.memslice_entry_init)) else: self.putln("%s;" % decl) diff --git a/Cython/Compiler/MemoryView.py b/Cython/Compiler/MemoryView.py index 47fbd40b1..f1cddb851 100644 --- a/Cython/Compiler/MemoryView.py +++ b/Cython/Compiler/MemoryView.py @@ -60,6 +60,8 @@ _spec_to_abbrev = { 'follow' : '_', } +memslice_entry_init = "{ 0, 0, { 0 }, { 0 }, { 0 } }" + memview_name = u'memoryview' memview_typeptr_cname = '__pyx_memoryview_type' memview_objstruct_cname = '__pyx_memoryview_obj' @@ -529,7 +531,8 @@ class CopyFuncUtilCode(object): mode = 'fortran' contig_flag = memview_f_contiguous - context = dict( + C = dict( + context, copy_name=self.copy_func_name, mode=mode, sizeof_dtype="sizeof(%s)" % self.from_memview.dtype.declaration_code(''), @@ -539,7 +542,7 @@ class CopyFuncUtilCode(object): _, copy_code = UtilityCode.load_as_string("MemviewSliceCopyTemplate", from_file="MemoryView_C.c", - context=context) + context=C) code.put(copy_code) @@ -915,6 +918,7 @@ context = { 'memview_struct_name': memview_objstruct_cname, 'max_dims': Options.buffer_max_dims, 'memviewslice_name': memviewslice_cname, + 'memslice_init': memslice_entry_init, } memviewslice_declare_code = load_memview_c_utility( "MemviewSliceStruct", diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index fa934a241..8b266998b 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -383,7 +383,8 @@ class Scope(object): entries[name] = entry if type.is_memoryviewslice: - entry.init = "{ 0, 0 }" + import MemoryView + entry.init = MemoryView.memslice_entry_init entry.scope = self entry.visibility = visibility diff --git a/Cython/Utility/MemoryView.pyx b/Cython/Utility/MemoryView.pyx index 030b0d4a4..4934e0c90 100644 --- a/Cython/Utility/MemoryView.pyx +++ b/Cython/Utility/MemoryView.pyx @@ -174,6 +174,9 @@ cdef extern from "pythread.h": int PyThread_acquire_lock(PyThread_type_lock, int mode) nogil void PyThread_release_lock(PyThread_type_lock) nogil +cdef extern from "string.h": + void *memset(void *b, int c, size_t len) + cdef extern from *: int __Pyx_GetBuffer(object, Py_buffer *, int) except -1 void __Pyx_ReleaseBuffer(Py_buffer *) @@ -415,9 +418,13 @@ cdef tuple _unellipsify(object index, int ndim): cdef memoryview memview_slice(memoryview memview, object indices): cdef int new_ndim = 0, suboffset_dim = -1, dim cdef bint negative_step - cdef {{memviewslice_name}} dst, src + cdef {{memviewslice_name}} src, dst cdef {{memviewslice_name}} *p_src + # dst is copied by value in memoryview_fromslice -- initialize it + # src is never copied + memset(&dst, 0, sizeof(dst)) + cdef _memoryviewslice memviewsliceobj assert memview.view.ndim > 0 diff --git a/Cython/Utility/MemoryView_C.c b/Cython/Utility/MemoryView_C.c index e447850d6..03f2ed88c 100644 --- a/Cython/Utility/MemoryView_C.c +++ b/Cython/Utility/MemoryView_C.c @@ -49,7 +49,7 @@ static CYTHON_INLINE char *__pyx_memviewslice_index_full(const char *bufp, Py_ss /////////////// ObjectToMemviewSlice /////////////// static CYTHON_INLINE {{memviewslice_name}} {{funcname}}(PyObject *obj) { - {{memviewslice_name}} result = {0}; + {{memviewslice_name}} result = {{memslice_init}}; struct __pyx_memoryview_obj *memview = \ (struct __pyx_memoryview_obj *) __pyx_memoryview_new(obj, {{buf_flag}}); @@ -336,7 +336,7 @@ static __Pyx_memviewslice {{copy_name}}(const __Pyx_memviewslice from_mvs) { __Pyx_RefNannyDeclarations int i; - __Pyx_memviewslice new_mvs = {0, 0}; + __Pyx_memviewslice new_mvs = {{memslice_init}}; struct __pyx_memoryview_obj *from_memview = from_mvs.memview; Py_buffer *buf = &from_memview->view; PyObject *shape_tuple = 0; -- 2.30.9