Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Backports:SLE-15:Update
kicad
kicad-boost-1_61-boost-context-changes.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File kicad-boost-1_61-boost-context-changes.patch of Package kicad
From 06d4894fdbeb00727cdcc667b8899ad73d8eb1c2 Mon Sep 17 00:00:00 2001 From: Michael Steinberg <michsteinb@gmail.com> Date: Tue, 5 Jul 2016 00:14:32 +0200 Subject: boost::context fixes to make it compatible with boost 1.61 Index: common/tool/tool_manager.cpp =================================================================== --- common/tool/tool_manager.cpp.orig +++ common/tool/tool_manager.cpp @@ -528,7 +528,7 @@ void TOOL_MANAGER::dispatchInternal( con } } - BOOST_FOREACH( TOOL_STATE* st, m_toolState | boost::adaptors::map_values ) + BOOST_FOREACH( TOOL_STATE* st, ( m_toolState | boost::adaptors::map_values ) ) { // no state handler in progress - check if there are any transitions (defined by // Go() method that match the event. @@ -542,11 +542,11 @@ void TOOL_MANAGER::dispatchInternal( con if( st->cofunc ) st->Push(); + st->cofunc = new COROUTINE<int, const TOOL_EVENT&>( tr.second ); + // as the state changes, the transition table has to be set up again st->transitions.clear(); - st->cofunc = new COROUTINE<int, const TOOL_EVENT&>( tr.second ); - // got match? Run the handler. st->cofunc->Call( aEvent ); Index: include/tool/coroutine.h =================================================================== --- include/tool/coroutine.h.orig +++ include/tool/coroutine.h @@ -3,6 +3,7 @@ * * Copyright (C) 2013 CERN * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> + * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,10 +28,53 @@ #include <cstdlib> -#include <boost/context/fcontext.hpp> #include <boost/version.hpp> +#include <type_traits> -#include "delegate.h" +#if BOOST_VERSION < 106100 +#include <boost/context/fcontext.hpp> +#else +#include <boost/context/execution_context.hpp> +#include <boost/context/protected_fixedsize_stack.hpp> +#endif + +/** + * Note: in the history of boost, two changes to the context interface happened. + * [1.54, 1.56) + * http://www.boost.org/doc/libs/1_55_0/libs/context/doc/html/context/context/boost_fcontext.html + * intptr_t jump_fcontext( + * fcontext_t* ofc, + * fcontext_t const* nfc, + * intptr_t vp, + * bool preserve_fpu = true + * ); + * + * fcontext_t* make_fcontext( + * void* sp, + * std::size_t size, + * void (*fn)(intptr_t) + * ); + * + * [1.56, 1.61) + * http://www.boost.org/doc/libs/1_56_0/libs/context/doc/html/context/context/boost_fcontext.html + * intptr_t jump_fcontext( + * fcontext_t* ofc, + * fcontext_t nfc, <----- + * intptr_t vp, + * bool preserve_fpu = true + * ); + * + * fcontext_t make_fcontext( <----- + * void* sp, + * std::size_t size, + * void(*fn)(intptr_t) + * ); + * + * [1.61, oo) + * http://www.boost.org/doc/libs/1_61_0/libs/context/doc/html/context/ecv2.html + * fcontext_t is hidden away behind the boost::execution_context(_v2) and the stack is created on behalf of + * the user. + */ /** * Class COROUNTINE. @@ -53,13 +97,12 @@ * See coroutine_example.cpp for sample code. */ -template <class ReturnType, class ArgType> +template <typename ReturnType, typename ArgType> class COROUTINE { public: COROUTINE() : - m_saved( NULL ), m_self( NULL ), m_stack( NULL ), m_stackSize( c_defaultStackSize ), - m_running( false ) + COROUTINE( nullptr ) { } @@ -68,9 +111,8 @@ public: * Creates a coroutine from a member method of an object */ template <class T> - COROUTINE( T* object, ReturnType(T::* ptr)( ArgType ) ) : - m_func( object, ptr ), m_self( NULL ), m_saved( NULL ), m_stack( NULL ), - m_stackSize( c_defaultStackSize ), m_running( false ) + COROUTINE( T* object, ReturnType(T::*ptr)( ArgType ) ) : + COROUTINE( std::bind( ptr, object, std::placeholders::_1 ) ) { } @@ -78,29 +120,29 @@ public: * Constructor * Creates a coroutine from a delegate object */ - COROUTINE( DELEGATE<ReturnType, ArgType> aEntry ) : - m_func( aEntry ), m_saved( NULL ), m_self( NULL ), m_stack( NULL ), - m_stackSize( c_defaultStackSize ), m_running( false ) - { - // Avoid not initialized members, and make static analysers quiet - m_args = 0; - m_retVal = 0; + COROUTINE( std::function<ReturnType(ArgType)> aEntry ) : + m_func( std::move( aEntry ) ), + m_running( false ), + m_args( 0 ), +#if BOOST_VERSION < 106100 // -> m_callee = void* or void** + m_callee( nullptr ), +#endif + m_retVal( 0 ) + { } ~COROUTINE() { - if( m_saved ) - delete m_saved; + } -#if BOOST_VERSION >= 105600 - if( m_self ) - delete m_self; +private: +#if BOOST_VERSION < 106100 + using context_type = boost::context::fcontext_t; +#else + using context_type = boost::context::execution_context<COROUTINE*>; #endif - if( m_stack ) - free( m_stack ); - } - +public: /** * Function Yield() * @@ -110,7 +152,7 @@ public: */ void Yield() { - jump( m_self, m_saved, 0 ); + jumpOut(); } /** @@ -122,7 +164,20 @@ public: void Yield( ReturnType& aRetVal ) { m_retVal = aRetVal; - jump( m_self, m_saved, 0 ); + jumpOut(); + } + + /** + * Function Resume() + * + * Resumes execution of a previously yielded coroutine. + * @return true, if the coroutine has yielded again and false if it has finished its + * execution (returned). + */ + bool Resume() + { + jumpIn(); + return m_running; } /** @@ -130,9 +185,9 @@ public: * * Defines the entry point for the coroutine, if not set in the constructor. */ - void SetEntry( DELEGATE<ReturnType, ArgType> aEntry ) + void SetEntry( std::function<ReturnType(ArgType)> aEntry ) { - m_func = aEntry; + m_func = std::move( aEntry ); } /* Function Call() @@ -143,43 +198,37 @@ public: */ bool Call( ArgType aArgs ) { + assert( m_func ); + assert( !m_callee ); + + m_args = &aArgs; + +#if BOOST_VERSION < 106100 + assert( m_stack == nullptr ); + // fixme: Clean up stack stuff. Add a guard - m_stack = malloc( c_defaultStackSize ); + size_t stackSize = c_defaultStackSize; + m_stack.reset( new char[stackSize] ); // align to 16 bytes - void* sp = (void*) ( ( ( (ptrdiff_t) m_stack ) + m_stackSize - 0xf ) & ( ~0x0f ) ); + void* sp = (void*) ( ( ( (ptrdiff_t) m_stack.get() ) + stackSize - 0xf ) & ( ~0x0f ) ); // correct the stack size - m_stackSize -= ( (size_t) m_stack + m_stackSize - (size_t) sp ); - - assert( m_self == NULL ); - assert( m_saved == NULL ); + stackSize -= size_t( ( (ptrdiff_t) m_stack.get() + stackSize) - (ptrdiff_t) sp ); - m_args = &aArgs; -#if BOOST_VERSION >= 105600 - m_self = new boost::context::fcontext_t(); - *m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); + m_callee = boost::context::make_fcontext( sp, stackSize, callerStub ); #else - m_self = boost::context::make_fcontext( sp, m_stackSize, callerStub ); + m_callee = context_type( + std::allocator_arg_t(), + boost::context::protected_fixedsize_stack( c_defaultStackSize ), + &COROUTINE::callerStub + ); #endif - m_saved = new boost::context::fcontext_t(); m_running = true; - // off we go! - jump( m_saved, m_self, reinterpret_cast<intptr_t>( this ) ); - return m_running; - } - /** - * Function Resume() - * - * Resumes execution of a previously yielded coroutine. - * @return true, if the coroutine has yielded again and false if it has finished its - * execution (returned). - */ - bool Resume() - { - jump( m_saved, m_self, 0 ); + // off we go! + jumpIn(); return m_running; } @@ -208,61 +257,82 @@ private: static const int c_defaultStackSize = 2000000; // fixme: make configurable /* real entry point of the coroutine */ +#if BOOST_VERSION < 106100 static void callerStub( intptr_t aData ) { // get pointer to self - COROUTINE<ReturnType, ArgType>* cor = reinterpret_cast<COROUTINE<ReturnType, ArgType>*>( aData ); + COROUTINE* cor = reinterpret_cast<COROUTINE*>( aData ); // call the coroutine method - cor->m_retVal = cor->m_func( *cor->m_args ); + cor->m_retVal = cor->m_func( *(cor->m_args) ); cor->m_running = false; // go back to wherever we came from. - jump( cor->m_self, cor->m_saved, 0 ); // reinterpret_cast<intptr_t>( this )); + cor->jumpOut(); } +#else + /* real entry point of the coroutine */ + static context_type callerStub( context_type caller, COROUTINE* cor ) + { + cor->m_caller = std::move( caller ); + + // call the coroutine method + cor->m_retVal = cor->m_func( *(cor->m_args) ); + cor->m_running = false; + + // go back to wherever we came from. + return std::move( cor->m_caller ); + } +#endif - ///> Wrapper for jump_fcontext to assure compatibility between different boost versions - static inline intptr_t jump(boost::context::fcontext_t* aOld, boost::context::fcontext_t* aNew, - intptr_t aP, bool aPreserveFPU = true ) + void jumpIn() { -#if BOOST_VERSION >= 105600 - return boost::context::jump_fcontext( aOld, *aNew, aP, aPreserveFPU ); +#if BOOST_VERSION < 105600 + boost::context::jump_fcontext( &m_caller, m_callee, reinterpret_cast<intptr_t>(this) ); +#elif BOOST_VERSION < 106100 + boost::context::jump_fcontext( &m_caller, m_callee, reinterpret_cast<intptr_t>(this) ); #else - return boost::context::jump_fcontext( aOld, aNew, aP, aPreserveFPU ); + auto result = m_callee( this ); + m_callee = std::move( std::get<0>( result ) ); #endif } - template <typename T> - struct strip_ref + void jumpOut() { - typedef T result; - }; +#if BOOST_VERSION < 105600 + boost::context::jump_fcontext( m_callee, &m_caller, 0 ); +#elif BOOST_VERSION < 106100 + boost::context::jump_fcontext( &m_callee, m_caller, 0 ); +#else + auto result = m_caller( nullptr ); + m_caller = std::move( std::get<0>( result ) ); +#endif + } - template <typename T> - struct strip_ref<T&> - { - typedef T result; - }; + std::function<ReturnType(ArgType)> m_func; - DELEGATE<ReturnType, ArgType> m_func; + bool m_running; + +#if BOOST_VERSION < 106100 + ///< coroutine stack + std::unique_ptr<char[]> m_stack; +#endif ///< pointer to coroutine entry arguments. Stripped of references ///< to avoid compiler errors. - typename strip_ref<ArgType>::result* m_args; - ReturnType m_retVal; + typename std::remove_reference<ArgType>::type* m_args; ///< saved caller context - boost::context::fcontext_t* m_saved; + context_type m_caller; ///< saved coroutine context - boost::context::fcontext_t* m_self; - - ///< coroutine stack - void* m_stack; - - size_t m_stackSize; +#if BOOST_VERSION < 105600 + context_type* m_callee; +#else + context_type m_callee; +#endif - bool m_running; + ReturnType m_retVal; }; #endif Index: include/tool/tool_base.h =================================================================== --- include/tool/tool_base.h.orig +++ include/tool/tool_base.h @@ -3,6 +3,7 @@ * * Copyright (C) 2013 CERN * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> + * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -31,7 +32,7 @@ #include <tool/tool_event.h> #include <tool/tool_settings.h> -#include <tool/delegate.h> +#include <functional> class EDA_ITEM; class TOOL_MANAGER; @@ -53,7 +54,9 @@ enum TOOL_TYPE /// Unique identifier for tools typedef int TOOL_ID; -typedef DELEGATE<int, const TOOL_EVENT&> TOOL_STATE_FUNC; + +using TOOL_STATE_FUNC = std::function<int(const TOOL_EVENT&)>; + /** * Class TOOL_BASE Index: include/tool/tool_interactive.h =================================================================== --- include/tool/tool_interactive.h.orig +++ include/tool/tool_interactive.h @@ -3,6 +3,7 @@ * * Copyright (C) 2013 CERN * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> + * Copyright (C) 2016 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -113,7 +114,7 @@ template <class T> void TOOL_INTERACTIVE::Go( int (T::* aStateFunc)( const TOOL_EVENT& ), const TOOL_EVENT_LIST& aConditions ) { - TOOL_STATE_FUNC sptr( static_cast<T*>( this ), aStateFunc ); + TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 ); goInternal( sptr, aConditions ); } Index: include/tool/delegate.h =================================================================== --- include/tool/delegate.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * This program source code file is part of KiCad, a free EDA CAD application. - * - * Copyright (C) 2013 CERN - * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, you may find one here: - * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html - * or you may search the http://www.gnu.org website for the version 2 license, - * or you may write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#ifndef __DELEGATE_H -#define __DELEGATE_H - - -/** - * class DELEGATE - * A trivial delegate (pointer to member method of an object) pattern implementation. - * Check delegate_example.cpp for a coding sample. - */ - -template <class ReturnType, class Arg> -class DELEGATE -{ -public: - typedef ReturnType (DELEGATE<ReturnType, Arg>::* MemberPointer)( Arg ); - typedef ReturnType _ReturnType; - typedef Arg _ArgType; - - DELEGATE() - { - } - - template <class T> - DELEGATE( T* aObject, ReturnType(T::* aPtr)( Arg ) ) - { - m_ptr = reinterpret_cast<MemberPointer>( aPtr ); - m_object = reinterpret_cast<void*>( aObject ); - }; - - - ReturnType operator()( Arg aA ) const - { - DELEGATE<ReturnType, Arg>* casted = reinterpret_cast<DELEGATE<ReturnType, Arg>*>( m_object ); - return (casted->*m_ptr)( aA ); - } - -private: - MemberPointer m_ptr; - void* m_object; -}; - -/** - * Class DELEGATE0 - * Same as DELEGATE, but with no arguments. - */ -template <class ReturnType> -class DELEGATE0 -{ -public: - typedef ReturnType ( DELEGATE0<ReturnType>::* MemberPointer )(); - typedef ReturnType _ReturnType; - - DELEGATE0() - { - } - - template <class T> - DELEGATE0( T* aObject, ReturnType(T::* aPtr)() ) - { - m_ptr = reinterpret_cast<MemberPointer>( aPtr ); - m_object = reinterpret_cast<void*>( aObject ); - }; - - - ReturnType operator()() const - { - DELEGATE0<ReturnType>* casted = reinterpret_cast<DELEGATE0<ReturnType>*>( m_object ); - return ( casted->*m_ptr )(); - } - -private: - MemberPointer m_ptr; - void* m_object; -}; - -#endif
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor