Skip to content

Commit cca14c3

Browse files
chore: updating addon
1 parent 55a3989 commit cca14c3

File tree

3 files changed

+91
-29
lines changed

3 files changed

+91
-29
lines changed

lib/node_modules/@stdlib/math/base/special/minmax/benchmark/c/native/benchmark.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ static double benchmark( void ) {
9595
double max;
9696
double x[ 100 ];
9797
double y[ 100 ];
98-
double z;
9998
double t;
10099
int i;
101100

@@ -106,7 +105,7 @@ static double benchmark( void ) {
106105

107106
t = tic();
108107
for ( i = 0; i < ITERATIONS; i++ ) {
109-
z = stdlib_base_minmax( x[ i%100 ], y[ i%100 ], &min, &max );
108+
stdlib_base_minmax( x[ i%100 ], y[ i%100 ], &min, &max );
110109
if ( max != max || min != min ) {
111110
printf( "should not return NaN\n" );
112111
break;

lib/node_modules/@stdlib/math/base/special/minmax/manifest.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636
"libraries": [],
3737
"libpath": [],
3838
"dependencies": [
39-
"@stdlib/napi/argv",
40-
"@stdlib/napi/argv-double",
41-
"@stdlib/napi/argv-float64array",
42-
"@stdlib/napi/create-double",
43-
"@stdlib/napi/export",
4439
"@stdlib/math/base/assert/is-nan",
4540
"@stdlib/math/base/assert/is-negative-zero"
4641
]
@@ -56,11 +51,6 @@
5651
"libraries": [],
5752
"libpath": [],
5853
"dependencies": [
59-
"@stdlib/napi/argv",
60-
"@stdlib/napi/argv-double",
61-
"@stdlib/napi/argv-float64array",
62-
"@stdlib/napi/create-double",
63-
"@stdlib/napi/export",
6454
"@stdlib/math/base/assert/is-nan",
6555
"@stdlib/math/base/assert/is-negative-zero"
6656
]
@@ -76,11 +66,6 @@
7666
"libraries": [],
7767
"libpath": [],
7868
"dependencies": [
79-
"@stdlib/napi/argv",
80-
"@stdlib/napi/argv-double",
81-
"@stdlib/napi/argv-float64array",
82-
"@stdlib/napi/create-double",
83-
"@stdlib/napi/export",
8469
"@stdlib/math/base/assert/is-nan",
8570
"@stdlib/math/base/assert/is-negative-zero"
8671
]

lib/node_modules/@stdlib/math/base/special/minmax/src/addon.c

Lines changed: 90 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
*/
1818

1919
#include "stdlib/math/base/special/minmax.h"
20-
#include "stdlib/napi/argv.h"
21-
#include "stdlib/napi/argv_double.h"
22-
#include "stdlib/napi/argv_float64array.h"
23-
#include "stdlib/napi/create_double.h"
24-
#include "stdlib/napi/export.h"
20+
#include <stdint.h>
21+
#include <assert.h>
2522
#include <node_api.h>
2623

2724
/**
@@ -32,20 +29,101 @@
3229
* @return Node-API value
3330
*/
3431
static napi_value addon( napi_env env, napi_callback_info info ) {
35-
STDLIB_NAPI_ARGV( env, info, argv, argc, 3 );
36-
STDLIB_NAPI_ARGV_DOUBLE( env, x, argv, 0 );
37-
STDLIB_NAPI_ARGV_DOUBLE( env, y, argv, 1 );
38-
STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, z, zlen, argv, 2 );
32+
napi_status status;
33+
34+
// Get callback arguments:
35+
size_t argc = 3;
36+
napi_value argv[ 3 ];
37+
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
38+
assert( status == napi_ok );
39+
40+
// Check whether we were provided the correct number of arguments:
41+
if ( argc < 3 ) {
42+
status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
43+
assert( status == napi_ok );
44+
return NULL;
45+
}
46+
if ( argc > 3 ) {
47+
status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
48+
assert( status == napi_ok );
49+
return NULL;
50+
}
51+
52+
bool res;
53+
status = napi_is_typedarray( env, argv[ 0 ], &res );
54+
assert( status == napi_ok );
55+
if ( res == false ) {
56+
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float64Array." );
57+
assert( status == napi_ok );
58+
return NULL;
59+
}
60+
61+
napi_valuetype vtype1;
62+
status = napi_typeof( env, argv[ 1 ], &vtype1 );
63+
assert( status == napi_ok );
64+
if ( vtype1 != napi_number ) {
65+
status = napi_throw_type_error( env, NULL, "invalid argument. Second argument must be a number." );
66+
assert( status == napi_ok );
67+
return NULL;
68+
}
69+
70+
napi_valuetype vtype2;
71+
status = napi_typeof( env, argv[ 2 ], &vtype2 );
72+
assert( status == napi_ok );
73+
if ( vtype2 != napi_number ) {
74+
status = napi_throw_type_error( env, NULL, "invalid argument. Third argument must be a number." );
75+
assert( status == napi_ok );
76+
return NULL;
77+
}
78+
79+
napi_typedarray_type vtype0;
80+
size_t len;
81+
void *Out;
82+
status = napi_get_typedarray_info( env, argv[ 0 ], &vtype0, &len, &Out, NULL, NULL );
83+
assert( status == napi_ok );
84+
if ( vtype0 != napi_float64_array ) {
85+
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float64Array." );
86+
assert( status == napi_ok );
87+
return NULL;
88+
}
89+
if ( len != 2 ) {
90+
status = napi_throw_range_error( env, NULL, "invalid argument. First argument must have 2 elements." );
91+
assert( status == napi_ok );
92+
return NULL;
93+
}
94+
95+
double value1;
96+
status = napi_get_value_double( env, argv[ 1 ], &value1 );
97+
assert( status == napi_ok );
98+
99+
double value2;
100+
status = napi_get_value_double( env, argv[ 2 ], &value2 );
101+
assert( status == napi_ok );
39102

40103
double min;
41104
double max;
42-
stdlib_base_minmax( x, y, &min, &max );
105+
stdlib_base_minmax( value1, value2, &min, &max );
43106

44-
double *op = (double *)z;
107+
double *op = (double *)Out;
45108
op[ 0 ] = min;
46109
op[ 1 ] = max;
47110

48111
return NULL;
49112
}
50113

51-
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )
114+
/**
115+
* Initializes a Node-API module.
116+
*
117+
* @private
118+
* @param env environment under which the function is invoked
119+
* @param exports exports object
120+
* @return main export
121+
*/
122+
static napi_value init( napi_env env, napi_value exports ) {
123+
napi_value fcn;
124+
napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
125+
assert( status == napi_ok );
126+
return fcn;
127+
}
128+
129+
NAPI_MODULE( NODE_GYP_MODULE_NAME, init )

0 commit comments

Comments
 (0)