Skip to content

Commit 40b01fb

Browse files
committed
fix: update include paths and refactor branching logic
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 5939fb1 commit 40b01fb

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

lib/node_modules/@stdlib/random/base/randu/benchmark/c/benchmark.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
#include "stdlib/random/base/randu.h"
20-
#include "stdlib/random/base.h"
20+
#include "stdlib/random/base/shared.h"
2121
#include <stdlib.h>
2222
#include <stdio.h>
2323
#include <stdint.h>

lib/node_modules/@stdlib/random/base/randu/examples/c/example.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
* limitations under the License.
1717
*/
1818

19+
#include "stdlib/random/base/shared.h"
20+
#include "stdlib/random/base/randu.h"
1921
#include <stdlib.h>
2022
#include <stdio.h>
21-
#include "stdlib/random/base.h"
22-
#include "stdlib/random/base/randu.h"
2323

2424
int main( void ) {
2525
int32_t i;

lib/node_modules/@stdlib/random/base/randu/include/stdlib/random/base/randu.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
#ifndef STDLIB_RANDOM_BASE_RANDU_H
2020
#define STDLIB_RANDOM_BASE_RANDU_H
2121

22-
// Note: keep project includes in alphabetical order...
22+
#include "stdlib/random/base/shared.h"
2323
#include <stdarg.h>
24-
#include "stdlib/random/base.h"
2524

2625
/*
2726
* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler.

lib/node_modules/@stdlib/random/base/randu/src/main.c

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@
1616
* limitations under the License.
1717
*/
1818

19-
// Note: keep project includes in alphabetical order...
20-
#include <stdlib.h>
21-
#include <stdint.h>
22-
#include <stdarg.h>
23-
#include "stdlib/random/base.h"
19+
#include "stdlib/random/base/randu.h"
20+
#include "stdlib/random/base/shared.h"
2421
#include "stdlib/random/base/minstd.h"
2522
#include "stdlib/random/base/minstd_shuffle.h"
2623
#include "stdlib/random/base/mt19937.h"
27-
#include "stdlib/random/base/randu.h"
24+
#include <stdlib.h>
25+
#include <stdint.h>
26+
#include <stdarg.h>
2827

2928
// Define the default PRNG:
3029
static const enum STDLIB_BASE_RANDOM_RANDU_PRNG STDLIB_BASE_RANDOM_RANDU_DEFAULT = STDLIB_BASE_RANDOM_RANDU_MT19937;
@@ -43,11 +42,11 @@ static const enum STDLIB_BASE_RANDOM_RANDU_PRNG STDLIB_BASE_RANDOM_RANDU_DEFAULT
4342
* @return pointer to a dynamically allocated PRNG or, if unable to allocate memory, a null pointer
4443
*
4544
* @example
45+
* #include "stdlib/random/base/randu.h"
46+
* #include "stdlib/random/base/shared.h"
4647
* #include <stdlib.h>
4748
* #include <stdio.h>
4849
* #include <stdint.h>
49-
* #include "stdlib/random/base.h"
50-
* #include "stdlib/random/base/randu.h"
5150
*
5251
* // Create a PRNG:
5352
* struct BasePRNGObject *obj = stdlib_base_random_randu_allocate( 0 );
@@ -73,11 +72,9 @@ static const enum STDLIB_BASE_RANDOM_RANDU_PRNG STDLIB_BASE_RANDOM_RANDU_DEFAULT
7372
*/
7473
struct BasePRNGObject * stdlib_base_random_randu_allocate( const int nargs, ... ) {
7574
enum STDLIB_BASE_RANDOM_RANDU_PRNG prng;
76-
struct BasePRNGObject *obj;
77-
7875
va_list args;
79-
va_start( args, nargs );
8076

77+
va_start( args, nargs );
8178
if ( nargs < 1 ) {
8279
prng = STDLIB_BASE_RANDOM_RANDU_DEFAULT;
8380
} else {
@@ -90,20 +87,25 @@ struct BasePRNGObject * stdlib_base_random_randu_allocate( const int nargs, ...
9087
} else {
9188
seed = rand();
9289
}
93-
obj = stdlib_base_random_minstd_allocate( seed );
94-
} else if ( prng == STDLIB_BASE_RANDOM_RANDU_MINSTD_SHUFFLE ) {
90+
va_end( args );
91+
return stdlib_base_random_minstd_allocate( seed );
92+
}
93+
if ( prng == STDLIB_BASE_RANDOM_RANDU_MINSTD_SHUFFLE ) {
9594
int32_t seed;
9695
if ( nargs > 1 ) {
9796
seed = va_arg( args, int32_t );
9897
} else {
9998
seed = rand();
10099
}
101-
obj = stdlib_base_random_minstd_shuffle_allocate( seed );
102-
} else if ( prng == STDLIB_BASE_RANDOM_RANDU_MT19937 ) {
100+
va_end( args );
101+
return stdlib_base_random_minstd_shuffle_allocate( seed );
102+
}
103+
if ( prng == STDLIB_BASE_RANDOM_RANDU_MT19937 ) {
104+
const uint32_t *seed;
103105
int64_t seed_length;
104-
uint32_t *seed;
106+
uint32_t tseed[ 1 ];
105107
if ( nargs < 2 ) {
106-
uint32_t tseed[] = { (uint32_t)rand() };
108+
tseed[ 0 ] = (uint32_t)rand();
107109
seed = tseed;
108110
seed_length = 1;
109111
} else if ( nargs == 3 ) {
@@ -114,13 +116,12 @@ struct BasePRNGObject * stdlib_base_random_randu_allocate( const int nargs, ...
114116
va_end( args );
115117
return NULL;
116118
}
117-
obj = stdlib_base_random_mt19937_allocate( seed, seed_length );
118-
} else {
119-
// How did we get here? A non-implemented PRNG?
120-
obj = NULL;
119+
va_end( args );
120+
return stdlib_base_random_mt19937_allocate( seed, seed_length );
121121
}
122+
// How did we get here? A non-implemented PRNG?
122123
va_end( args );
123-
return obj;
124+
return NULL;
124125
}
125126

126127
/**
@@ -134,11 +135,11 @@ struct BasePRNGObject * stdlib_base_random_randu_allocate( const int nargs, ...
134135
* @return pseudorandom number
135136
*
136137
* @example
138+
* #include "stdlib/random/base/randu.h"
139+
* #include "stdlib/random/base/shared.h"
137140
* #include <stdlib.h>
138141
* #include <stdio.h>
139142
* #include <stdint.h>
140-
* #include "stdlib/random/base.h"
141-
* #include "stdlib/random/base/randu.h"
142143
*
143144
* // Create a PRNG:
144145
* struct BasePRNGObject *obj = stdlib_base_random_randu_allocate( 0 );
@@ -172,11 +173,11 @@ double stdlib_base_random_randu( struct BasePRNGObject *obj ) {
172173
* @param obj PRNG object
173174
*
174175
* @example
176+
* #include "stdlib/random/base/randu.h"
177+
* #include "stdlib/random/base/shared.h"
175178
* #include <stdlib.h>
176179
* #include <stdio.h>
177180
* #include <stdint.h>
178-
* #include "stdlib/random/base.h"
179-
* #include "stdlib/random/base/randu.h"
180181
*
181182
* // Create a PRNG:
182183
* struct BasePRNGObject *obj = stdlib_base_random_randu_allocate( 0 );

0 commit comments

Comments
 (0)