From: Axel R. <ro...@us...> - 2017-03-11 09:15:09
|
Update of /cvsroot/sdif/Easdif/swig/python In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv22025/swig/python Modified Files: CMakeLists.txt easdif-python.i Log Message: Summary: Version 1.4.29 - improved Python 3 support Correctly handle differences in iterator interfaces of python 2 and python 3 Index: easdif-python.i =================================================================== RCS file: /cvsroot/sdif/Easdif/swig/python/easdif-python.i,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** easdif-python.i 26 Aug 2014 14:38:24 -0000 1.19 --- easdif-python.i 11 Mar 2017 09:15:07 -0000 1.20 *************** *** 6,9 **** --- 6,15 ---- // // $Log$ + // Revision 1.20 2017/03/11 09:15:07 roebel + // Summary: Version 1.4.29 - improved Python 3 support + // + // Correctly handle differences in iterator interfaces of python 2 and + // python 3 + // // Revision 1.19 2014/08/26 14:38:24 roebel // Added special exception specification for OpenRead to be able to catch the SDIFBadHeader exception. *************** *** 154,160 **** --- 160,170 ---- } + + + %define NEXT_INTERFACE_SUPPORT(NEXT_FUN_NAME) %{ #include "easdif/easdif.h" + // proxy class for frame that provides Frame iterator with storage location for iterator position struct *************** *** 164,169 **** FrameIt(const Easdif::SDIFFrame& in ) : mpOriFrame(&in), mIterPos(0) {} ~FrameIt() {} const Easdif::SDIFMatrix& ! next() { if(mIterPos < static_cast<int>(mpOriFrame->GetNbMatrix())) return mpOriFrame->GetMatrix(mIterPos++); --- 174,180 ---- FrameIt(const Easdif::SDIFFrame& in ) : mpOriFrame(&in), mIterPos(0) {} ~FrameIt() {} + const Easdif::SDIFMatrix& ! NEXT_FUN_NAME() { if(mIterPos < static_cast<int>(mpOriFrame->GetNbMatrix())) return mpOriFrame->GetMatrix(mIterPos++); *************** *** 172,176 **** }; - %} --- 183,186 ---- *************** *** 196,200 **** // but a pointer to a new Frame so we cannot modify the entity by means of the // frames in a loop ! %exception Easdif::SDIFEntity::next() { try { $action --- 206,211 ---- // but a pointer to a new Frame so we cannot modify the entity by means of the // frames in a loop ! ! %exception Easdif::SDIFEntity::NEXT_FUN_NAME() { try { $action *************** *** 206,210 **** } ! %newobject Easdif::SDIFEntity::next; %extend Easdif::SDIFEntity{ Easdif::SDIFEntity& --- 217,222 ---- } ! %newobject Easdif::SDIFEntity::NEXT_FUN_NAME; ! %extend Easdif::SDIFEntity{ Easdif::SDIFEntity& *************** *** 217,221 **** // prefer to work with pointers in python Easdif::SDIFFrame* ! next() { //allocate new frame Easdif::SDIFFrame *localFrame = new(Easdif::SDIFFrame); --- 229,233 ---- // prefer to work with pointers in python Easdif::SDIFFrame* ! NEXT_FUN_NAME() { //allocate new frame Easdif::SDIFFrame *localFrame = new(Easdif::SDIFFrame); *************** *** 235,239 **** // but a pointer to a new Matrix. This avoids problems with the missing reference counting // that would arise if teh original frame disappears before the matrix ! %exception Easdif::SDIFFrame::next() { try { $action --- 247,251 ---- // but a pointer to a new Matrix. This avoids problems with the missing reference counting // that would arise if teh original frame disappears before the matrix ! %exception Easdif::SDIFFrame::NEXT_FUN_NAME() { try { $action *************** *** 245,249 **** } ! %newobject Easdif::SDIFFrame::next; %newobject Easdif::SDIFFrame::copy; %extend Easdif::SDIFFrame { --- 257,261 ---- } ! %newobject Easdif::SDIFFrame::NEXT_FUN_NAME; %newobject Easdif::SDIFFrame::copy; %extend Easdif::SDIFFrame { *************** *** 254,262 **** // prefer to work with pointers in python Easdif::SDIFMatrix* ! next() { FrameIt * it = reinterpret_cast<FrameIt*>($self); Easdif::SDIFMatrix *pMat = new(Easdif::SDIFMatrix); try { ! *pMat = it->next(); } catch(...) { --- 266,274 ---- // prefer to work with pointers in python Easdif::SDIFMatrix* ! NEXT_FUN_NAME() { FrameIt * it = reinterpret_cast<FrameIt*>($self); Easdif::SDIFMatrix *pMat = new(Easdif::SDIFMatrix); try { ! *pMat = it->NEXT_FUN_NAME(); } catch(...) { *************** *** 271,277 **** return new Easdif::SDIFFrame(*$self); } - } %extend Easdif::FrameType{ PyObject* __str__() { --- 283,297 ---- return new Easdif::SDIFFrame(*$self); } } + %enddef + + #ifdef SWIG_PYTHON_3 + NEXT_INTERFACE_SUPPORT(__next__) + #else + NEXT_INTERFACE_SUPPORT(next) + #endif + + %extend Easdif::FrameType{ PyObject* __str__() { Index: CMakeLists.txt =================================================================== RCS file: /cvsroot/sdif/Easdif/swig/python/CMakeLists.txt,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** CMakeLists.txt 3 Dec 2015 18:03:01 -0000 1.23 --- CMakeLists.txt 11 Mar 2017 09:15:06 -0000 1.24 *************** *** 56,60 **** IF(PYTHON_VERSION_MAJOR EQUAL 3) MESSAGE("ENABLE SWIG Python 3 flag") ! SET(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} "-py3" ) ENDIF(PYTHON_VERSION_MAJOR EQUAL 3) --- 56,60 ---- IF(PYTHON_VERSION_MAJOR EQUAL 3) MESSAGE("ENABLE SWIG Python 3 flag") ! SET(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} "-py3" "-DSWIG_PYTHON_3=1") ENDIF(PYTHON_VERSION_MAJOR EQUAL 3) |