From 96edb762c748102c2b20159868b4a6a3792af18b Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Fri, 26 Oct 2018 07:43:23 +0200 Subject: [PATCH] Building Fix for a negative value check for gcc < 4.8 --- ChangeLog | 3 +++ README.md | 2 +- build.sh | 2 +- debian/watch | 2 +- examples/Makefile.gcc | 2 +- finalcut.spec.in | 4 ++-- src/Makefile.clang | 2 +- src/fstring.cpp | 2 +- src/include/final/fstring.h | 15 ++++++++------- src/include/final/ftypes.h | 25 +++++++++++++++++++++++++ test/Makefile.clang | 2 +- test/Makefile.gcc | 2 +- 12 files changed, 46 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 646e374b..3ef8115a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2018-10-26 Markus Gans + * Building Fix for a negative value check (gcc < 4.8) + 2018-10-21 Markus Gans * Moving static attributes from FApplication to FWidget diff --git a/README.md b/README.md index f2e74145..d340f9ca 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ Class digramm License ------- -GNU Lesser General Public License Version 3 +GNU Lesser General Public License Version 3 Please send bug reports to -------------------------- diff --git a/build.sh b/build.sh index da7b8863..229e1bbe 100755 --- a/build.sh +++ b/build.sh @@ -20,7 +20,7 @@ if [ "$CPU_COUNT" -eq 0 ] then if command -v nproc >/dev/null 2>&1 then - CPU_COUNT="$(nproc 2>/dev/null)" || CPU_COUNT="0" + CPU_COUNT="$(nproc 2>/dev/null)" || CPU_COUNT="0" fi fi diff --git a/debian/watch b/debian/watch index 88ef7b52..f53c4bc0 100644 --- a/debian/watch +++ b/debian/watch @@ -1,2 +1,2 @@ version=3 -opts=passive https://github.com/gansm/finalcut/archive/([\d.]+)\.tar.gz +opts=passive https://github.com/gansm/finalcut/archive/([\d.]+)\.tar.gz diff --git a/examples/Makefile.gcc b/examples/Makefile.gcc index ab5225fa..2b2bd5b9 100644 --- a/examples/Makefile.gcc +++ b/examples/Makefile.gcc @@ -34,7 +34,7 @@ debug: profile: $(MAKE) $(MAKEFILE) PROFILE="-pg" -.PHONY: clean +.PHONY: clean clean: $(RM) $(SRCS:%.cpp=%) *.gcno *.gcda *~ diff --git a/finalcut.spec.in b/finalcut.spec.in index 6a31b675..9bd96885 100644 --- a/finalcut.spec.in +++ b/finalcut.spec.in @@ -11,7 +11,7 @@ Name: @PACKAGE@ Version: @VERSION@ Release: %{buildno} License: LGPL-3.0 -Summary: The Final Cut +Summary: The Final Cut Url: https://github.com/gansm/finalcut/ Group: System/Libraries Source: finalcut-%{version}.tar.gz @@ -111,7 +111,7 @@ make %{?_smp_mflags} V=1 make install libdir=${RPM_BUILD_ROOT}%{_libdir}/ \ includedir=${RPM_BUILD_ROOT}%{_includedir} \ bindir=${RPM_BUILD_ROOT}%{_bindir} \ - docdir=${RPM_BUILD_ROOT}/%{_docdir}/finalcut/ + docdir=${RPM_BUILD_ROOT}/%{_docdir}/finalcut/ rm -f ${RPM_BUILD_ROOT}%{_libdir}/libfinal.la %post -n %{libsoname} -p /sbin/ldconfig diff --git a/src/Makefile.clang b/src/Makefile.clang index 4ee741bf..bf25e0e2 100644 --- a/src/Makefile.clang +++ b/src/Makefile.clang @@ -140,7 +140,7 @@ endif .cpp.o: $(CXX) -c $(CCXFLAGS) $(INCLUDES) -fpic -o $@ $< -all: dep $(OBJS) +all: dep $(OBJS) $(CXX) $(CCXFLAGS) $(INCLUDES) $(LDFLAGS) -shared -Wl,-soname,$(LIB).$(MAJOR) -o $(LIB).$(VERSION) $(OBJS) ln -s -f $(LIB).$(VERSION) libfinal.so.$(MAJOR) ln -s -f $(LIB).$(MAJOR) libfinal.so diff --git a/src/fstring.cpp b/src/fstring.cpp index bfff3f9d..e0118090 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -1192,7 +1192,7 @@ bool FString::operator > (const FString& s) const //---------------------------------------------------------------------- const FString& FString::insert (const FString& s, int pos) { - if ( pos < 0 || uInt(pos) > length ) + if ( isNegative(pos) || uInt(pos) > length ) throw std::out_of_range(""); _insert (uInt(pos), s.length, s.string); diff --git a/src/include/final/fstring.h b/src/include/final/fstring.h index 5371fd0b..f8aaac09 100644 --- a/src/include/final/fstring.h +++ b/src/include/final/fstring.h @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -134,9 +135,9 @@ class FString const FString& operator >> (float&); template - wchar_t& operator [] (IndexT); + wchar_t& operator [] (const IndexT); template - const wchar_t& operator [] (IndexT) const; + const wchar_t& operator [] (const IndexT) const; const FString& operator () (); bool operator < (const FString&) const; @@ -289,9 +290,9 @@ inline const char* FString::getClassName() //---------------------------------------------------------------------- template -inline wchar_t& FString::operator [] (IndexT pos) +inline wchar_t& FString::operator [] (const IndexT pos) { - if ( pos < 0 || pos >= IndexT(length) ) + if ( isNegative(pos) || pos >= IndexT(length) ) throw std::out_of_range(""); // Invalid index position return string[std::size_t(pos)]; @@ -299,9 +300,9 @@ inline wchar_t& FString::operator [] (IndexT pos) //---------------------------------------------------------------------- template -inline const wchar_t& FString::operator [] (IndexT pos) const +inline const wchar_t& FString::operator [] (const IndexT pos) const { - if ( pos < 0 || pos >= IndexT(length) ) + if ( isNegative(pos) || pos >= IndexT(length) ) throw std::out_of_range(""); // Invalid index position return string[std::size_t(pos)]; @@ -378,7 +379,7 @@ inline FString::iterator FString::end() const //---------------------------------------------------------------------- inline wchar_t FString::front() const { - assert( ! isEmpty() ); + assert ( ! isEmpty() ); return string[0]; } diff --git a/src/include/final/ftypes.h b/src/include/final/ftypes.h index dfec1be0..12d7d880 100644 --- a/src/include/final/ftypes.h +++ b/src/include/final/ftypes.h @@ -30,6 +30,7 @@ #include #include +#include #include #define null NULL @@ -60,6 +61,30 @@ typedef long double lDouble; namespace finalcut { +template +struct is_negative +{ + inline bool operator () (const T& x) + { + return x < 0; + } +}; + +template +struct is_negative +{ + inline bool operator () (const T&) + { + return false; + } +}; + +template +inline bool isNegative (const T& x) +{ + return is_negative::is_signed>()(x); +} + namespace fc { #pragma pack(push) diff --git a/test/Makefile.clang b/test/Makefile.clang index f5a3d725..5eef4ebc 100644 --- a/test/Makefile.clang +++ b/test/Makefile.clang @@ -33,7 +33,7 @@ debug: check: test test: debug - $(OBJS) | sed -e "s/ OK/\x1b[32m OK\x1b[0m/g" -e "s/ failed/\x1b[31m failed\x1b[0m/g" + $(OBJS) | sed -e "s/ OK/\x1b[32m OK\x1b[0m/g" -e "s/ failed/\x1b[31m failed\x1b[0m/g" profile: $(MAKE) $(MAKEFILE) PROFILE="-pg" diff --git a/test/Makefile.gcc b/test/Makefile.gcc index b7730b9b..9b502e44 100644 --- a/test/Makefile.gcc +++ b/test/Makefile.gcc @@ -33,7 +33,7 @@ debug: check: test test: debug - $(OBJS) | sed -e "s/ OK/\x1b[32m OK\x1b[0m/g" -e "s/ failed/\x1b[31m failed\x1b[0m/g" + $(OBJS) | sed -e "s/ OK/\x1b[32m OK\x1b[0m/g" -e "s/ failed/\x1b[31m failed\x1b[0m/g" profile: $(MAKE) $(MAKEFILE) PROFILE="-pg"