[Libreoffice-commits] core.git: 2 commits - comphelper/source formula/Library_for.mk formula/source include/comphelper include/formula scaddins/Library_analysis.mk scaddins/source sc/source vcl/qa vcl/source
Caolán McNamara
caolanm at redhat.com
Fri Jul 10 00:58:47 PDT 2015
comphelper/source/misc/random.cxx | 7 ++
formula/Library_for.mk | 1
formula/source/core/api/random.cxx | 56 ------------------
include/comphelper/random.hxx | 3
include/formula/random.hxx | 31 ---------
sc/source/core/opencl/formulagroupcl.cxx | 4 -
sc/source/core/tool/interpr1.cxx | 3
scaddins/Library_analysis.mk | 1
scaddins/source/analysis/analysis.cxx | 4 -
vcl/qa/cppunit/graphicfilter/data/wmf/fail/hang-1.wmf |binary
vcl/source/filter/wmf/winwmf.cxx | 10 ++-
11 files changed, 22 insertions(+), 98 deletions(-)
New commits:
commit fd2749455fe25e24b448a44f9ada6113e5ac0d13
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Jul 10 08:40:42 2015 +0100
avoid endless loop with busted wmf
Change-Id: I104de360f2e861e959ad2dad434a768440877f6f
diff --git a/vcl/qa/cppunit/graphicfilter/data/wmf/fail/hang-1.wmf b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/hang-1.wmf
new file mode 100644
index 0000000..7ba05cb
Binary files /dev/null and b/vcl/qa/cppunit/graphicfilter/data/wmf/fail/hang-1.wmf differ
diff --git a/vcl/source/filter/wmf/winwmf.cxx b/vcl/source/filter/wmf/winwmf.cxx
index 343b74f..7b87f68 100644
--- a/vcl/source/filter/wmf/winwmf.cxx
+++ b/vcl/source/filter/wmf/winwmf.cxx
@@ -1394,9 +1394,13 @@ void WMFReader::ReadWMF()
}
}
}
- nPos += nRecSize * 2;
- if ( nPos <= nEndPos )
- pWMF->Seek( nPos );
+ const sal_uInt32 nAvailableBytes = nEndPos - nPos;
+ const sal_uInt32 nMaxPossibleRecordSize = nAvailableBytes/2;
+ if (nRecSize <= nMaxPossibleRecordSize)
+ {
+ nPos += nRecSize * 2;
+ pWMF->Seek(nPos);
+ }
else
pWMF->SetError( SVSTREAM_FILEFORMAT_ERROR );
}
commit 5b2f8231945fedc46425e00f1234dcac90628c1d
Author: Caolán McNamara <caolanm at redhat.com>
Date: Thu Jul 9 14:48:31 2015 +0100
add a SAL_RAND_REPEATABLE for repeatable random nums
merge the formula and comphelper ones together
Change-Id: I2e7e2cdb176afc6982e384fa1e007da5b914e6f0
diff --git a/comphelper/source/misc/random.cxx b/comphelper/source/misc/random.cxx
index 0c6e83e..a70a73e 100644
--- a/comphelper/source/misc/random.cxx
+++ b/comphelper/source/misc/random.cxx
@@ -39,6 +39,13 @@ struct RandomNumberGenerator
STD_RNG_ALGO global_rng;
RandomNumberGenerator()
{
+ bool bRepeatable = (getenv("SAL_RAND_REPEATABLE") != 0);
+ if (bRepeatable)
+ {
+ global_rng.seed(42);
+ return;
+ }
+
try
{
std::random_device rd;
diff --git a/formula/Library_for.mk b/formula/Library_for.mk
index cbdff46..ad7da5a 100644
--- a/formula/Library_for.mk
+++ b/formula/Library_for.mk
@@ -42,7 +42,6 @@ $(eval $(call gb_Library_add_exception_objects,for,\
formula/source/core/api/FormulaCompiler \
formula/source/core/api/FormulaOpCodeMapperObj \
formula/source/core/api/grammar \
- formula/source/core/api/random \
formula/source/core/api/services \
formula/source/core/api/token \
formula/source/core/api/vectortoken \
diff --git a/formula/source/core/api/random.cxx b/formula/source/core/api/random.cxx
deleted file mode 100644
index 727262f..0000000
--- a/formula/source/core/api/random.cxx
+++ /dev/null
@@ -1,56 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include <time.h>
-
-#include <random>
-
-#include <formula/random.hxx>
-#include <rtl/instance.hxx>
-
-namespace {
-
-struct CalcFormulaRandomGenerator
-{
- std::mt19937 aRng;
- CalcFormulaRandomGenerator()
- {
- // initialises the state of this RNG.
- // should only be called once.
- bool bRepeatable = (getenv("SC_RAND_REPEATABLE") != 0);
- aRng.seed(bRepeatable ? 42 : time(NULL));
- }
-};
-
-class theCalcFormulaRandomGenerator : public rtl::Static<CalcFormulaRandomGenerator, theCalcFormulaRandomGenerator> {};
-
-}
-
-namespace formula
-{
-
-namespace rng
-{
-
-double fRandom(double a, double b)
-{
- std::uniform_real_distribution<double> dist(a, b);
- return dist(theCalcFormulaRandomGenerator::get().aRng);
-}
-
-sal_Int32 nRandom(sal_Int32 a, sal_Int32 b)
-{
- std::uniform_int_distribution<sal_Int32> dist(a, b);
- return dist(theCalcFormulaRandomGenerator::get().aRng);
-}
-
-} // rng
-} // formula
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/random.hxx b/include/comphelper/random.hxx
index 080b5d2..218d616 100644
--- a/include/comphelper/random.hxx
+++ b/include/comphelper/random.hxx
@@ -18,6 +18,9 @@ namespace comphelper
namespace rng
{
+// These functions obey the SAL_RAND_REPEATABLE environment
+// variable: If it is set, use a fixed seed.
+
// note that uniform_int_distribution is inclusive of b, i.e. [a,b] while
// uniform_real_distribution is exclusive of b, i.e. [a,b), std::nextafter may be your friend there
diff --git a/include/formula/random.hxx b/include/formula/random.hxx
deleted file mode 100644
index d5d14f5..0000000
--- a/include/formula/random.hxx
+++ /dev/null
@@ -1,31 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#ifndef INCLUDED_FORMULA_RANDOM_HXX
-#define INCLUDED_FORMULA_RANDOM_HXX
-
-#include <formula/formuladllapi.h>
-
-namespace formula
-{
-
-namespace rng
-{
-
-// These two functions obey the SC_RAND_REPEATABLE environment
-// variable: If it is set, use a fixed seed.
-double FORMULA_DLLPUBLIC fRandom(double a, double b);
-sal_Int32 FORMULA_DLLPUBLIC nRandom(sal_Int32 a, sal_Int32 b);
-
-} // rng
-} // formula
-
-#endif // INCLUDED_FORMULA_RANDOM_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx
index 98c95e7..ed03cce 100644
--- a/sc/source/core/opencl/formulagroupcl.cxx
+++ b/sc/source/core/opencl/formulagroupcl.cxx
@@ -16,7 +16,7 @@
#include "tokenarray.hxx"
#include "compiler.hxx"
#include "interpre.hxx"
-#include <formula/random.hxx>
+#include <comphelper/random.hxx>
#include <formula/vectortoken.hxx>
#include "scmatrix.hxx"
@@ -738,7 +738,7 @@ threefry2x32 (threefry2x32_ctr_t in, threefry2x32_key_t k)\n\
/// Create buffer and pass the buffer to a given kernel
virtual size_t Marshal( cl_kernel k, int argno, int, cl_program ) SAL_OVERRIDE
{
- cl_int seed = formula::rng::nRandom(0, SAL_MAX_INT32);
+ cl_int seed = comphelper::rng::uniform_int_distribution(0, SAL_MAX_INT32);
// Pass the scalar result back to the rest of the formula kernel
SAL_INFO("sc.opencl", "Kernel " << k << " arg " << argno << ": cl_int: " << seed);
cl_int err = clSetKernelArg(k, argno, sizeof(cl_int), static_cast<void*>(&seed));
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index e1dfd2a..7892269 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -22,7 +22,6 @@
#include "scitems.hxx"
#include <editeng/langitem.hxx>
#include <editeng/justifyitem.hxx>
-#include <formula/random.hxx>
#include <osl/thread.h>
#include <svx/algitem.hxx>
#include <unotools/textsearch.hxx>
@@ -1653,7 +1652,7 @@ void ScInterpreter::ScPi()
void ScInterpreter::ScRandom()
{
- PushDouble(formula::rng::fRandom(0, 1));
+ PushDouble(::comphelper::rng::uniform_real_distribution());
}
void ScInterpreter::ScTrue()
diff --git a/scaddins/Library_analysis.mk b/scaddins/Library_analysis.mk
index 4946c5f..cafce60 100644
--- a/scaddins/Library_analysis.mk
+++ b/scaddins/Library_analysis.mk
@@ -33,7 +33,6 @@ $(eval $(call gb_Library_use_libraries,analysis,\
comphelper \
cppu \
cppuhelper \
- for \
sal \
tl \
i18nlangtag \
diff --git a/scaddins/source/analysis/analysis.cxx b/scaddins/source/analysis/analysis.cxx
index d6d3047..08ac862 100644
--- a/scaddins/source/analysis/analysis.cxx
+++ b/scaddins/source/analysis/analysis.cxx
@@ -22,8 +22,8 @@
#include "bessel.hxx"
#include <cppuhelper/factory.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/random.hxx>
#include <cppuhelper/supportsservice.hxx>
-#include <formula/random.hxx>
#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>
#include <rtl/math.hxx>
@@ -693,7 +693,7 @@ double SAL_CALL AnalysisAddIn::getRandbetween( double fMin, double fMax ) throw(
if( fMin > fMax )
throw lang::IllegalArgumentException();
- double fRet = floor(formula::rng::fRandom(fMin, nextafter(fMax+1, -DBL_MAX)));
+ double fRet = floor(comphelper::rng::uniform_real_distribution(fMin, nextafter(fMax+1, -DBL_MAX)));
RETURN_FINITE( fRet );
}
More information about the Libreoffice-commits
mailing list