Skip to content

Commit

Permalink
CHG: Move to c++11 and use std:shared_ptr rather than boost
Browse files Browse the repository at this point in the history
Fixes the Nexus Player x86 crashes
  • Loading branch information
koying committed Feb 10, 2015
1 parent e82d519 commit d3c46d2
Show file tree
Hide file tree
Showing 214 changed files with 673 additions and 379 deletions.
4 changes: 3 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ AC_CONFIG_HEADERS([xbmc/config.h])
AH_TOP([#pragma once])
m4_include([m4/ax_prog_cc_for_build.m4])
m4_include([m4/ax_prog_cxx_for_build.m4])
m4_include([m4/ax_cxx_compile_stdcxx_11.m4])
m4_include([m4/ax_python_devel.m4])
m4_include([m4/xbmc_arch.m4])

Expand Down Expand Up @@ -579,6 +580,7 @@ PASSED_CXXFLAGS=$CXXFLAGS # Hack to override autoconf default values
AC_PROG_CXX
AX_PROG_CXX_FOR_BUILD
CXXFLAGS="$PASSED_CXXFLAGS $DEFAULT_COMPILE_FLAGS"
AX_CXX_COMPILE_STDCXX_11(,[optional])
AC_PROG_LIBTOOL
AC_PROG_AWK
AC_PROG_LN_S
Expand Down Expand Up @@ -928,7 +930,7 @@ AC_CHECK_HEADER([sys/inotify.h], AC_DEFINE([HAVE_INOTIFY],[1],[Define if we have

# Checks for boost headers using CXX instead of CC
AC_LANG_PUSH([C++])
AC_CHECK_HEADER([boost/shared_ptr.hpp],, AC_MSG_ERROR($missing_library))
AC_CHECK_HEADER([boost/circular_buffer.hpp],, AC_MSG_ERROR($missing_library))
AC_LANG_POP([C++])

# Python
Expand Down
142 changes: 142 additions & 0 deletions m4/ax_cxx_compile_stdcxx_11.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# ============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
# ============================================================================
#
# SYNOPSIS
#
# AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
#
# DESCRIPTION
#
# Check for baseline language coverage in the compiler for the C++11
# standard; if necessary, add switches to CXXFLAGS to enable support.
#
# The first argument, if specified, indicates whether you insist on an
# extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
# -std=c++11). If neither is specified, you get whatever works, with
# preference for an extended mode.
#
# The second argument, if specified 'mandatory' or if left unspecified,
# indicates that baseline C++11 support is required and that the macro
# should error out if no mode with that support is found. If specified
# 'optional', then configuration proceeds regardless, after defining
# HAVE_CXX11 if and only if a supporting mode is found.
#
# LICENSE
#
# Copyright (c) 2008 Benjamin Kosnik <[email protected]>
# Copyright (c) 2012 Zack Weinberg <[email protected]>
# Copyright (c) 2013 Roy Stogner <[email protected]>
# Copyright (c) 2014 Alexey Sokolov <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 4

m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
template <typename T>
struct check
{
static_assert(sizeof(int) <= sizeof(T), "not big enough");
};
struct Base {
virtual void f() {}
};
struct Child : public Base {
virtual void f() {}
};
typedef check<check<bool>> right_angle_brackets;
int a;
decltype(a) b;
typedef check<int> check_type;
check_type c;
check_type&& cr = static_cast<check_type&&>(c);
auto d = a;
auto l = [](){};
]])

AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
m4_if([$1], [], [],
[$1], [ext], [],
[$1], [noext], [],
[m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
[$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
[$2], [optional], [ax_cxx_compile_cxx11_required=false],
[m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
AC_LANG_PUSH([C++])dnl
ac_success=no
AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
ax_cv_cxx_compile_cxx11,
[AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[ax_cv_cxx_compile_cxx11=yes],
[ax_cv_cxx_compile_cxx11=no])])
if test x$ax_cv_cxx_compile_cxx11 = xyes; then
ac_success=yes
fi
m4_if([$1], [noext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=gnu++11 -std=gnu++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
m4_if([$1], [ext], [], [dnl
if test x$ac_success = xno; then
for switch in -std=c++11 -std=c++0x; do
cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
$cachevar,
[ac_save_CXXFLAGS="$CXXFLAGS"
CXXFLAGS="$CXXFLAGS $switch"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
[eval $cachevar=yes],
[eval $cachevar=no])
CXXFLAGS="$ac_save_CXXFLAGS"])
if eval test x\$$cachevar = xyes; then
CXXFLAGS="$CXXFLAGS $switch"
ac_success=yes
break
fi
done
fi])
AC_LANG_POP([C++])
if test x$ax_cxx_compile_cxx11_required = xtrue; then
if test x$ac_success = xno; then
AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
fi
else
if test x$ac_success = xno; then
HAVE_CXX11=0
AC_MSG_NOTICE([No compiler with C++11 support was found])
else
HAVE_CXX11=1
AC_DEFINE(HAVE_CXX11,1,
[define if the compiler supports basic C++11 syntax])
fi
AC_SUBST(HAVE_CXX11)
fi
])
4 changes: 2 additions & 2 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ bool CApplication::LoadSkin(const std::string& skinID)
AddonPtr addon;
if (CAddonMgr::Get().GetAddon(skinID, addon, ADDON_SKIN))
{
if (LoadSkin(boost::dynamic_pointer_cast<ADDON::CSkinInfo>(addon)))
if (LoadSkin(std::dynamic_pointer_cast<ADDON::CSkinInfo>(addon)))
return true;
}
CLog::Log(LOGERROR, "failed to load requested skin '%s'", skinID.c_str());
Expand Down Expand Up @@ -1852,7 +1852,7 @@ void CApplication::UnloadSkin(bool forReload /* = false */)

g_infoManager.Clear();

// The g_SkinInfo boost shared_ptr ought to be reset here
// The g_SkinInfo shared_ptr ought to be reset here
// but there are too many places it's used without checking for NULL
// and as a result a race condition on exit can cause a crash.
}
Expand Down
4 changes: 2 additions & 2 deletions xbmc/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace ADDON
{
class CSkinInfo;
class IAddon;
typedef boost::shared_ptr<IAddon> AddonPtr;
typedef std::shared_ptr<IAddon> AddonPtr;
}

namespace MEDIA_DETECT
Expand Down Expand Up @@ -408,7 +408,7 @@ class CApplication : public CXBApplicationEx, public IPlayerCallback, public IMs
virtual bool OnSettingUpdate(CSetting* &setting, const char *oldSettingId, const TiXmlNode *oldSettingNode);

bool LoadSkin(const std::string& skinID);
bool LoadSkin(const boost::shared_ptr<ADDON::CSkinInfo>& skin);
bool LoadSkin(const std::shared_ptr<ADDON::CSkinInfo>& skin);

/*!
\brief Delegates the action to all registered action handlers.
Expand Down
6 changes: 3 additions & 3 deletions xbmc/ApplicationMessenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void CApplicationMessenger::Cleanup()
void CApplicationMessenger::SendMessage(ThreadMessage& message, bool wait)
{
message.waitEvent.reset();
boost::shared_ptr<CEvent> waitEvent;
std::shared_ptr<CEvent> waitEvent;
if (wait)
{ // check that we're not being called from our application thread, else we'll be waiting
// forever!
Expand Down Expand Up @@ -212,7 +212,7 @@ void CApplicationMessenger::ProcessMessages()
//Leave here as the message might make another
//thread call processmessages or sendmessage

boost::shared_ptr<CEvent> waitEvent = pMsg->waitEvent;
std::shared_ptr<CEvent> waitEvent = pMsg->waitEvent;
lock.Leave(); // <- see the large comment in SendMessage ^

ProcessMessage(pMsg);
Expand Down Expand Up @@ -879,7 +879,7 @@ void CApplicationMessenger::ProcessWindowMessages()

// leave here in case we make more thread messages from this one

boost::shared_ptr<CEvent> waitEvent = pMsg->waitEvent;
std::shared_ptr<CEvent> waitEvent = pMsg->waitEvent;
lock.Leave(); // <- see the large comment in SendMessage ^

ProcessMessage(pMsg);
Expand Down
4 changes: 2 additions & 2 deletions xbmc/ApplicationMessenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "guilib/WindowIDs.h"
#include "threads/Thread.h"
#include <boost/shared_ptr.hpp>
#include <memory>

#include <queue>
#include "utils/GlobalsHandling.h"
Expand Down Expand Up @@ -121,7 +121,7 @@ typedef struct
int param2;
std::string strParam;
std::vector<std::string> params;
boost::shared_ptr<CEvent> waitEvent;
std::shared_ptr<CEvent> waitEvent;
void* lpVoid;
}
ThreadMessage;
Expand Down
Loading

0 comments on commit d3c46d2

Please sign in to comment.