From 7c4ccbedfd6ba234b064aafdfaaa3e3507266003 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Tue, 23 Mar 2004 01:07:07 +0000 Subject: [PATCH] fix compiler warning git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5788 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Lib/python/std_common.i | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/SWIG/Lib/python/std_common.i b/SWIG/Lib/python/std_common.i index 297b9df8c..dcd6f9c47 100644 --- a/SWIG/Lib/python/std_common.i +++ b/SWIG/Lib/python/std_common.i @@ -214,7 +214,7 @@ namespace swigpy { typedef Type value_type; static value_type as(PyObject *obj, bool throw_error) { value_type *v = 0; - int res = obj ? asptr(obj, &v) : 0; + int res = (obj ? asptr(obj, &v) : 0) && v; if (res) { if (res == SWIG_NEWOBJ) { value_type r(*v); @@ -224,6 +224,8 @@ namespace swigpy { return *v; } } else { + // Uninitialized return value, no Type() constructor required. + static value_type *v_def = (Type*) malloc(sizeof(Type)); std::string msg = "a value of type '"; msg += swigpy::type_name(); msg += "' is expected"; @@ -231,6 +233,7 @@ namespace swigpy { PyErr_SetString(PyExc_TypeError, msg.c_str()); } if (throw_error) throw std::invalid_argument(msg); + return *v_def; } } }; @@ -412,12 +415,12 @@ namespace swigpy { #ifdef SWIG_STD_EXTEND_COMPARISON %define %std_extcomp(Class,T) - %apply_if(SWIG_EqualType(T), %std_equal_methods(std::Class)) - %apply_if(SWIG_OrderType(T), %std_order_methods(std::Class)) + %evalif(SWIG_EqualType(T), %std_equal_methods(std::Class)) + %evalif(SWIG_OrderType(T), %std_order_methods(std::Class)) %enddef %define %_std_extcomp_2(Class,T,U) - %apply_if2(SWIG_EqualType(T),SWIG_EqualType(U),%std_equal_methods(std::Class)) - %apply_if2(SWIG_OrderType(T),SWIG_EqualType(U),%std_order_methods(std::Class)) + %evalif_2(SWIG_EqualType(T),SWIG_EqualType(U),%std_equal_methods(std::Class)) + %evalif_2(SWIG_OrderType(T),SWIG_EqualType(U),%std_order_methods(std::Class)) %enddef %define %std_extcomp_2(Class,T,...) %_std_extcomp_2(Class,T,__VA_ARGS__)