[libcxx] r302330 - Fix lgamma_r linking errors on Windows. It appears the normal lgamma function is thread safe anyway

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri May 5 19:58:43 PDT 2017


Author: ericwf
Date: Fri May  5 21:58:43 2017
New Revision: 302330

URL: http://llvm.org/viewvc/llvm-project?rev=302330&view=rev
Log:
Fix lgamma_r linking errors on Windows. It appears the normal lgamma function is thread safe anyway

Modified:
    libcxx/trunk/include/random

Modified: libcxx/trunk/include/random
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/random?rev=302330&r1=302329&r2=302330&view=diff
==============================================================================
--- libcxx/trunk/include/random (original)
+++ libcxx/trunk/include/random Fri May  5 21:58:43 2017
@@ -3997,7 +3997,18 @@ public:
         {return !(__x == __y);}
 };
 
+#ifndef _LIBCPP_MSVCRT
 extern "C" double lgamma_r(double, int *);
+#endif
+
+inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) {
+#if defined(_LIBCPP_MSVCRT)
+  return lgamma(__d);
+#else
+  int __sign;
+  return lgamma_r(__d, &__sign);
+#endif
+}
 
 template<class _IntType>
 binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const double __p)
@@ -4005,11 +4016,10 @@ binomial_distribution<_IntType>::param_t
 {
     if (0 < __p_ && __p_ < 1)
     {
-    	int __sign;
         __r0_ = static_cast<result_type>((__t_ + 1) * __p_);
-        __pr_ = _VSTD::exp(lgamma_r(__t_ + 1., &__sign) - 
-                           lgamma_r(__r0_ + 1., &__sign) -
-                           lgamma_r(__t_ - __r0_ + 1., &__sign) + __r0_ * _VSTD::log(__p_) +
+        __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) -
+                           __libcpp_lgamma(__r0_ + 1.) -
+                           __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) +
                            (__t_ - __r0_) * _VSTD::log(1 - __p_));
         __odds_ratio_ = __p_ / (1 - __p_);
     }




More information about the cfe-commits mailing list