Skip to content

Commit 8a590f0

Browse files
committed
refactor: use in-house macros for building native addon bindings
--- 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: passed - 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: na - task: lint_c_benchmarks status: na - 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 24d35f8 commit 8a590f0

File tree

4 files changed

+19
-113
lines changed

4 files changed

+19
-113
lines changed

lib/node_modules/@stdlib/math/base/special/cpolar/benchmark/benchmark.native.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
var resolve = require( 'path' ).resolve;
2424
var bench = require( '@stdlib/bench' );
2525
var uniform = require( '@stdlib/random/base/uniform' );
26-
var isArray = require( '@stdlib/assert/is-array' );
26+
var isFloat64Array = require( '@stdlib/assert/is-float64array' );
2727
var Complex128 = require( '@stdlib/complex/float64/ctor' );
2828
var tryRequire = require( '@stdlib/utils/try-require' );
2929
var pkg = require( './../package.json' ).name;
@@ -57,8 +57,8 @@ bench( pkg+'::native', opts, function benchmark( b ) {
5757
}
5858
}
5959
b.toc();
60-
if ( !isArray( y ) ) {
61-
b.fail( 'should return an array' );
60+
if ( !isFloat64Array( y ) ) {
61+
b.fail( 'should return a Float64Array' );
6262
}
6363
b.pass( 'benchmark finished' );
6464
b.end();

lib/node_modules/@stdlib/math/base/special/cpolar/lib/native.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ var addon = require( './../src/addon.node' );
3131
*
3232
* @private
3333
* @param {Complex128} z - complex number
34-
* @returns {Array<number>} absolute value and phase (in radians)
34+
* @returns {Float64Array} absolute value and phase (in radians)
3535
*
3636
* @example
3737
* var Complex128 = require( '@stdlib/complex/float64/ctor' );
3838
*
3939
* var o = cpolar( new Complex128( 5.0, 3.0 ) );
40-
* // returns [ ~5.83, ~0.5404 ]
40+
* // returns <Float64Array>[ ~5.83, ~0.5404 ]
4141
*/
4242
function cpolar( z ) {
43-
var out = new Float64Array( 2 );
44-
addon( out, z );
45-
return [ out[ 0 ], out[ 1 ] ];
43+
var o = new Float64Array( 2 );
44+
addon( z, o );
45+
return o;
4646
}
4747

4848

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
"libpath": [],
3838
"dependencies": [
3939
"@stdlib/napi/argv",
40+
"@stdlib/napi/argv-complex128",
41+
"@stdlib/napi/argv-float64array",
42+
"@stdlib/napi/export",
4043
"@stdlib/complex/float64/ctor",
4144
"@stdlib/complex/float64/reim",
4245
"@stdlib/math/base/special/cphase",

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

Lines changed: 8 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
#include "stdlib/math/base/special/cpolar.h"
2020
#include "stdlib/napi/argv.h"
21+
#include "stdlib/napi/argv_complex128.h"
22+
#include "stdlib/napi/argv_float64array.h"
23+
#include "stdlib/napi/export.h"
2124
#include <node_api.h>
2225

2326
/**
@@ -28,111 +31,11 @@
2831
* @return Node-API value
2932
*/
3033
static napi_value addon( napi_env env, napi_callback_info info ) {
31-
napi_status status;
32-
33-
// Get callback arguments:
34-
size_t argc = 2;
35-
napi_value argv[ 2 ];
36-
status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
37-
assert( status == napi_ok );
38-
39-
// Check whether we were provided the correct number of arguments:
40-
if ( argc < 2 ) {
41-
status = napi_throw_error( env, NULL, "invalid invocation. Insufficient arguments." );
42-
assert( status == napi_ok );
43-
return NULL;
44-
}
45-
if ( argc > 2 ) {
46-
status = napi_throw_error( env, NULL, "invalid invocation. Too many arguments." );
47-
assert( status == napi_ok );
48-
return NULL;
49-
}
50-
51-
bool res;
52-
status = napi_is_typedarray( env, argv[ 0 ], &res );
53-
assert( status == napi_ok );
54-
if ( res == false ) {
55-
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float64Array." );
56-
assert( status == napi_ok );
57-
return NULL;
58-
}
59-
60-
// Get the first element out
61-
napi_typedarray_type vtype0;
62-
size_t len;
63-
void *Out;
64-
status = napi_get_typedarray_info( env, argv[ 0 ], &vtype0, &len, &Out, NULL, NULL );
65-
assert( status == napi_ok );
66-
if ( vtype0 != napi_float64_array ) {
67-
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must be a Float64Array." );
68-
assert( status == napi_ok );
69-
return NULL;
70-
}
71-
if ( len != 2 ) {
72-
status = napi_throw_range_error( env, NULL, "invalid argument. First argument must have 2 elements." );
73-
assert( status == napi_ok );
74-
return NULL;
75-
}
76-
77-
// Get the real component
78-
napi_value xre;
79-
status = napi_get_named_property( env, argv[ 1 ], "re", &xre );
80-
assert( status == napi_ok );
81-
82-
napi_valuetype xretype;
83-
status = napi_typeof( env, xre, &xretype );
84-
assert( status == napi_ok );
85-
if ( xretype != napi_number ) {
86-
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have a real component which is a number." );
87-
assert( status == napi_ok );
88-
return NULL;
89-
}
90-
91-
// Get the imaginary component
92-
napi_value xim;
93-
status = napi_get_named_property( env, argv[ 1 ], "im", &xim );
94-
assert( status == napi_ok );
95-
96-
napi_valuetype ximtype;
97-
status = napi_typeof( env, xim, &ximtype );
98-
assert( status == napi_ok );
99-
if ( ximtype != napi_number ) {
100-
status = napi_throw_type_error( env, NULL, "invalid argument. First argument must have an imaginary component which a number." );
101-
assert( status == napi_ok );
102-
return NULL;
103-
}
104-
105-
double re;
106-
status = napi_get_value_double( env, xre, &re );
107-
assert( status == napi_ok );
108-
109-
double im;
110-
status = napi_get_value_double( env, xim, &im );
111-
assert( status == napi_ok );
112-
113-
double cabs;
114-
double cphase;
115-
stdlib_base_cpolar( stdlib_complex128( re, im ), &cabs, &cphase );
116-
117-
double *op = (double *)Out;
118-
op[ 0 ] = cabs;
119-
op[ 1 ] = cphase;
120-
34+
STDLIB_NAPI_ARGV( env, info, argv, argc, 2 );
35+
STDLIB_NAPI_ARGV_COMPLEX128( env, z, argv, 0 );
36+
STDLIB_NAPI_ARGV_FLOAT64ARRAY( env, o, olen, argv, 1 );
37+
stdlib_base_cpolar( z, &o[ 0 ], &o[ 1 ] );
12138
return NULL;
12239
}
12340

124-
/**
125-
* Initializes a Node-API module.
126-
*
127-
* @param env environment under which the function is invoked
128-
* @param exports exports object
129-
* @return main export
130-
*/
131-
static napi_value init( napi_env env, napi_value exports ) {
132-
napi_value fcn;
133-
napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn );
134-
assert( status == napi_ok );
135-
return fcn;
136-
}
137-
138-
NAPI_MODULE( NODE_GYP_MODULE_NAME, init )
41+
STDLIB_NAPI_MODULE_EXPORT_FCN( addon )

0 commit comments

Comments
 (0)