From: William S F. <ws...@fu...> - 2013-02-08 19:05:46
|
On 31/01/13 20:39, Olivier Voyer wrote: > Thank you for the tip, William, but unfortunately it doesn't work. I > will keep the #pragma in the stafx.h, this is not really a problem. > > Maybe you can help me out with another similar problem. When I throw an > exception in C++ and want this exception to be caught in Python, I use > the following syntax in my C++ .h file: > > void Print() throw(CymError); > > Where CymError has been defined as an exception class with the following > command %feature("exceptionclass") CymErrorin the SWIG .i file. > > When I compile I receive this warning: > > warning C4290: C++ exception specification ignored except to indicate a > function is not __declspec(nothrow) > This just means the Microsoft compiler ignores this perfectly C++ compliant exception specification. > So I have to use #pragma warning( disable : 4290 ) to ignore these warnings. > That is about all you can do. > My question is: am I using the correct way of throwing exceptions in > C++/SWIG ? > Yes that is a valid approach. Otherwise use %exception. William > On Thu, Jan 31, 2013 at 3:15 PM, William S Fulton > <ws...@fu... <mailto:ws...@fu...>> wrote: > > Sounds like a problem with precompiled headers. What if you clean > your project completely of all temporary visual studio files and > start again with just the %begin containing the #include "stdafx.h" > and no pragma in stdafx.h. In order for precompiled headers to work > properly, all your .cpp files require the #include "stdafx.h", but > in all honesty I gave up using precompiled headers in Visual Studio > years ago as they never really worked properly and seemed to cause > various strange effects. > > William > > > On 31/01/13 19:58, Olivier Voyer wrote: > > William: I just checked and no, I don't define this macro in my > project. > I'm using SWIG with C++ to generate Python code. I've seen this > piece of > code in the wrapped C++ code, but it seems the > _CRT_SECURE_NO_DEPRECATE > isn't working. > > #if !defined(SWIG_NO_CRT_SECURE___NO_DEPRECATE) && > defined(_MSC_VER) && > !defined(_CRT_SECURE_NO___DEPRECATE) > # define _CRT_SECURE_NO_DEPRECATE > #endif > > David: I don't know why, but when I put the #pragma command in > the SWIG > .i file, it doens't work, the warning is still displayed. I have > to put > the #pragma command in stdafx.h and include it in the .i file, > and it works. > > %begin > %{ > #include "stdafx.h" > %} > > On Thu, Jan 31, 2013 at 2:44 PM, David Piepgrass > <dpi...@me... <mailto:dpi...@me...> > <mailto:dpiepgrass@mentoreng.__com > <mailto:dpi...@me...>>> wrote: > > > > I'm using SWIG in Visual Studio 2010 with C++ and when I > compile the > > > .cpp generated by SWIG I receive a bunch of warnings > concerning > > > deprecated functions (such as strcpy and strncpy). Is > there a > way to > > > correct that in SWIG, other than to ignore those > warnings in my > project? > > > Normally I try to avoid the #pragma command as much as > possible, but I > > > know #pragma warning(disable : 4996) would do the trick. > > > > > > 2>SWIG\swig_application_wrap.__cpp(692): warning > C4996: 'strcpy': > This > > > function or variable may be unsafe. Consider using > strcpy_s > instead. > > > To disable deprecation, use _CRT_SECURE_NO_WARNINGS. > See online > > help > > > for details. > > > 2> C:\Program Files (x86)\Microsoft Visual Studio > > > 10.0\VC\include\string.h(105) : see declaration of > 'strcpy' > > > 2>SWIG\swig_application_wrap.__cpp(717): warning C4996: > 'strncpy': This > > > function or variable may be unsafe. Consider using > strncpy_s > instead. > > > To disable deprecation, use _CRT_SECURE_NO_WARNINGS. > See online > > help > > > for details. > > > 2> C:\Program Files (x86)\Microsoft Visual Studio > > > 10.0\VC\include\string.h(188) : see declaration of > 'strncpy' > > > > > They may indeed by unsafe, but they are not deprecated > despite > what the > > compiler is saying. > > > > You should not see these warnings too as by default SWIG > does define > > _CRT_SECURE_NO_WARNINGS unless > > SWIG_NO_CRT_SECURE_NO___DEPRECATE is defined. This > approach could be > > tweaked given the new C11 macro __STDC_WANT_LIB_EXT1__. > Did you > > define the SWIG_NO_CRT_SECURE_NO___DEPRECATE macro? If > not, then > > something has gone wrong. Which language module are you > using? > > In my project I have to use these traditional C functions, and > defining _CRT_SECURE_NO_WARNINGS and > _CRT_NON_CONFORMING_SWPRINTFS > doesn't work reliably even if I put it in front of > everything else > in StdAfx.h. So thanks for the tip about #pragma warning, > Olivier! > You can of course put it at the beginning of the generated SWIG > wrapper with > > %insert("begin") > %{ > #pragma warning(disable : 4996) > %} > > > > > -- > *Olivier Voyer* > oliviervoyer.com <http://oliviervoyer.com> > <http://oliviervoyer.com/> > /L'aube d'un jour nouveau/ > / > / > > > > > > -- > *Olivier Voyer* > oliviervoyer.com <http://oliviervoyer.com/> > /L'aube d'un jour nouveau/ > / > / |