Skip to content

Commit fd32278

Browse files
Paul Cercueiljmcorgan
Paul Cercueil
authored andcommitted
Add config check for Xrand48() functions
This fixes some compile errors under MinGW, which does not provide those functions. Signed-off-by: Paul Cercueil <[email protected]>
1 parent 9fd93c0 commit fd32278

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

cmake/msvc/config.h

-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,4 @@ static inline float rintf(float x){return (x > 0.0f)? floorf(x + 0.5f) : ceilf(x
6161
static inline long int random (void) { return rand(); }
6262
static inline void srandom (unsigned int seed) { srand(seed); }
6363

64-
#define srand48(seed) srand(seed)
65-
#define drand48() (double(rand()) / RAND_MAX)
66-
6764
#endif // _MSC_CONFIG_H_ ]

gr-analog/lib/fastnoise_source_X_impl.cc.t

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ namespace gr {
144144

145145
@TYPE@ @IMPL_NAME@::sample()
146146
{
147-
#ifdef __USE_GNU
147+
#ifdef HAVE_RAND48
148148
size_t idx = lrand48() % d_samples.size();
149149
#else
150150
size_t idx = rand() % d_samples.size();
@@ -153,7 +153,7 @@ namespace gr {
153153
}
154154

155155
#ifndef FASTNOISE_RANDOM_SIGN
156-
#ifdef _MSC_VER
156+
#ifndef HAVE_RAND48
157157
#define FASTNOISE_RANDOM_SIGN ((rand()%2==0)?1:-1)
158158
#else
159159
#define FASTNOISE_RANDOM_SIGN ((lrand48()%2==0)?1:-1)

gr-blocks/lib/ConfigChecks.cmake

+7
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,10 @@ CHECK_CXX_SOURCE_COMPILES("
8989
" HAVE_COSF
9090
)
9191
GR_ADD_COND_DEF(HAVE_COSF)
92+
93+
CHECK_CXX_SOURCE_COMPILES("
94+
#include <stdlib.h>
95+
int main(){srand48(0); drand48(); lrand48(); return 0;}
96+
" HAVE_RAND48
97+
)
98+
GR_ADD_COND_DEF(HAVE_RAND48)

gr-blocks/lib/test_tag_variable_rate_ff_impl.cc

+12
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ namespace gr {
5757
d_new_in = 0;
5858
d_last_out = 0;
5959

60+
#ifdef HAVE_RAND48
6061
srand48(time(NULL));
62+
#else
63+
srand(time(NULL));
64+
#endif
6165
}
6266

6367
test_tag_variable_rate_ff_impl::~test_tag_variable_rate_ff_impl()
@@ -78,7 +82,11 @@ namespace gr {
7882
GR_LOG_DEBUG(d_logger, boost::format("noutput_items: %1%") % noutput_items);
7983

8084
if(d_update_once) {
85+
#ifdef HAVE_RAND48
8186
if(drand48() > 0.5) {
87+
#else
88+
if (rand() > RAND_MAX / 2) {
89+
#endif
8290
d_rrate += d_update_step;
8391
}
8492
else {
@@ -95,7 +103,11 @@ namespace gr {
95103
while(i < ninput_items[0]) {
96104

97105
if(!d_update_once) {
106+
#ifdef HAVE_RAND48
98107
if(drand48() > 0.5) {
108+
#else
109+
if (rand() > RAND_MAX / 2) {
110+
#endif
99111
d_rrate += d_update_step;
100112
}
101113
else {

0 commit comments

Comments
 (0)