msgpackr-extract 1.1.0-napi → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/binding.gyp CHANGED
@@ -1,8 +1,22 @@
1
1
  {
2
2
  "variables": {
3
3
  "os_linux_compiler%": "gcc",
4
+ "enable_v8%": "true",
5
+ "enable_pointer_compression%": "false",
4
6
  "build_v8_with_gn": "false"
5
7
  },
8
+ "conditions": [
9
+ ['OS=="win"', {
10
+ "variables": {
11
+ "enable_v8%": "<!(echo %ENABLE_V8_FUNCTIONS%)",
12
+ }
13
+ }],
14
+ ['OS!="win"', {
15
+ "variables": {
16
+ "enable_v8%": "<!(echo $ENABLE_V8_FUNCTIONS)",
17
+ }
18
+ }]
19
+ ],
6
20
  "targets": [
7
21
  {
8
22
  "target_name": "msgpackr-extract",
@@ -11,8 +25,6 @@
11
25
  "src/extract.cpp",
12
26
  ],
13
27
  "defines": [ "NAPI_DISABLE_CPP_EXCEPTIONS" ],
14
- "include_dirs" : ["<!(node -p \"require('node-addon-api').include_dir\")"],
15
- "dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
16
28
  "conditions": [
17
29
  ["OS=='linux'", {
18
30
  "variables": {
@@ -40,6 +52,12 @@
40
52
  "-O3"
41
53
  ],
42
54
  }],
55
+ ["enable_v8!='false'", {
56
+ "defines": ["ENABLE_V8_API=1"]
57
+ }],
58
+ ["enable_pointer_compression=='true'", {
59
+ "defines": ["V8_COMPRESS_POINTERS", "V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE"],
60
+ }],
43
61
  ],
44
62
  }
45
63
  ]
package/index.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('node-gyp-build')(__dirname)
1
+ module.exports = require('node-gyp-build-optional-packages')(__dirname);
package/package.json CHANGED
@@ -1,29 +1,42 @@
1
- {
2
- "name": "msgpackr-extract",
3
- "author": "Kris Zyp",
4
- "version": "1.1.0-napi",
5
- "description": "Node addon for string extraction for msgpackr",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "http://github.com/kriszyp/msgpackr-extract"
10
- },
11
- "scripts": {
12
- "install": "node-gyp-build",
13
- "recompile": "node-gyp build",
14
- "before-publish": "prebuildify-ci download && prebuildify --napi --target 12.22.7",
15
- "prebuild": "prebuildify --napi --target 12.22.7",
16
- "prebuild-musl": "prebuildify --napi --libc musl --tag-libc --target 12.22.7",
17
- "prebuild-arm64": "prebuildify --napi --arch=arm64 --tag-libc --target 12.22.7", "test": ""
18
- },
19
- "main": "./index.js",
20
- "gypfile": true,
21
- "dependencies": {
22
- "node-addon-api": "^4.3.0",
23
- "node-gyp-build": "^4.2.3"
24
- },
25
- "devDependencies": {
26
- "prebuildify": "^5.0.0",
27
- "prebuildify-ci": "^1.0.5"
28
- }
29
- }
1
+ {
2
+ "name": "msgpackr-extract",
3
+ "author": "Kris Zyp",
4
+ "version": "1.1.2",
5
+ "description": "Node addon for string extraction for msgpackr",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "http://github.com/kriszyp/msgpackr-extract"
10
+ },
11
+ "scripts": {
12
+ "install": "node-gyp-build",
13
+ "recompile": "node-gyp build",
14
+ "before-publish": "prebuildify-ci download && prebuildify --target 16.14.2 && set ENABLE_V8_FUNCTIONS=false&& prebuildify --optional-packages --napi --target 16.14.2 && node set-optional-deps.cjs",
15
+ "prebuild": "prebuildify --target 16.14.2",
16
+ "prebuild-libc": "prebuildify --tag-libc --target 16.14.2 && ENABLE_V8_FUNCTIONS=false prebuildify --optional-packages --napi --tag-libc --target 16.14.2",
17
+ "publish-all": "cd prebuilds/win32-x64 && npm publish --otp %OTP% && cd ../darwin-x64 && npm publish --otp %OTP% && cd ../darwin-arm64 && npm publish --otp %OTP% && cd ../linux-x64 && npm publish --otp %OTP% && cd ../linux-arm64 && npm publish --otp %OTP% && cd ../linux-arm && npm publish --otp %OTP% && cd ../.. && npm publish --otp %OTP%",
18
+ "test": "node ./index.js"
19
+ },
20
+ "main": "./index.js",
21
+ "gypfile": true,
22
+ "dependencies": {
23
+ "node-gyp-build-optional-packages": "^4.3.0"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "/src",
28
+ "/*.gyp"
29
+ ],
30
+ "optionalDependencies": {
31
+ "msgpackr-extract-darwin-arm64": "1.1.0",
32
+ "msgpackr-extract-darwin-x64": "1.1.0",
33
+ "msgpackr-extract-linux-arm": "1.1.0",
34
+ "msgpackr-extract-linux-arm64": "1.1.0",
35
+ "msgpackr-extract-linux-x64": "1.1.0",
36
+ "msgpackr-extract-win32-x64": "1.1.0"
37
+ },
38
+ "devDependencies": {
39
+ "prebuildify": "kriszyp/prebuildify#optional-packages",
40
+ "prebuildify-ci": "^1.0.5"
41
+ }
42
+ }
package/src/extract.cpp CHANGED
@@ -5,10 +5,10 @@ provides much better performance. This will parse and produce up to 256 strings
5
5
  times as necessary to get more strings. This must be partially capable of parsing MessagePack so it can know where to
6
6
  find the string tokens and determine their position and length. All strings are decoded as UTF-8.
7
7
  */
8
- #include <napi.h>
9
8
  #include <node_api.h>
10
-
11
- using namespace Napi;
9
+ #if ENABLE_V8_API
10
+ #include <v8.h>
11
+ #endif
12
12
 
13
13
  #ifndef thread_local
14
14
  #ifdef __GNUC__
@@ -25,17 +25,25 @@ using namespace Napi;
25
25
  const int MAX_TARGET_SIZE = 255;
26
26
  typedef int (*token_handler)(uint8_t* source, int position, int size);
27
27
  token_handler tokenTable[256] = {};
28
+ napi_value unexpectedEnd(napi_env env) {
29
+ napi_value returnValue;
30
+ napi_get_undefined(env, &returnValue);
31
+ napi_throw_type_error(env, NULL, "Unexpected end of buffer reading string");
32
+ return returnValue;
33
+ }
34
+
28
35
  class Extractor {
29
36
  public:
30
37
  napi_value target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
31
-
38
+ // napi_ref targetArray; // could consider reenabling this optimization for napi
39
+ bool hasTargetArray = false;
32
40
  uint8_t* source;
33
41
  int position = 0;
34
42
  int writePosition = 0;
35
43
  int stringStart = 0;
36
44
  int lastStringEnd = 0;
37
45
 
38
- void readString(Env env, int length, bool allowStringBlocks) {
46
+ void readString(napi_env env, int length, bool allowStringBlocks) {
39
47
  int start = position;
40
48
  int end = position + length;
41
49
  if (allowStringBlocks) { // for larger strings, we don't bother to check every character for being latin, and just go right to creating a new string
@@ -76,7 +84,7 @@ public:
76
84
  lastStringEnd = end;
77
85
  }
78
86
 
79
- napi_value extractStrings(Env env, int startingPosition, int size, uint8_t* inputSource) {
87
+ napi_value extractStrings(napi_env env, int startingPosition, int size, uint8_t* inputSource) {
80
88
  writePosition = 0;
81
89
  lastStringEnd = 0;
82
90
  position = startingPosition;
@@ -89,8 +97,7 @@ public:
89
97
  // fixstr, we want to convert this
90
98
  token -= 0xa0;
91
99
  if (token + position > size) {
92
- TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
93
- return env.Null();
100
+ return unexpectedEnd(env);
94
101
  }
95
102
  readString(env,token, true);
96
103
  if (writePosition >= MAX_TARGET_SIZE)
@@ -98,39 +105,33 @@ public:
98
105
  } else if (token <= 0xdb && token >= 0xd9) {
99
106
  if (token == 0xd9) { //str 8
100
107
  if (position >= size) {
101
- TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
102
- return env.Null();
108
+ return unexpectedEnd(env);
103
109
  }
104
110
  int length = source[position++];
105
111
  if (length + position > size) {
106
- TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
107
- return env.Null();
112
+ return unexpectedEnd(env);
108
113
  }
109
114
  readString(env,length, true);
110
115
  } else if (token == 0xda) { //str 16
111
116
  if (2 + position > size) {
112
- TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
113
- return env.Null();
117
+ return unexpectedEnd(env);
114
118
  }
115
119
  int length = source[position++] << 8;
116
120
  length += source[position++];
117
121
  if (length + position > size) {
118
- TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
119
- return env.Null();
122
+ return unexpectedEnd(env);
120
123
  }
121
124
  readString(env,length, false);
122
125
  } else { //str 32
123
126
  if (4 + position > size) {
124
- TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
125
- return env.Null();
127
+ return unexpectedEnd(env);
126
128
  }
127
129
  int length = source[position++] << 24;
128
130
  length += source[position++] << 16;
129
131
  length += source[position++] << 8;
130
132
  length += source[position++];
131
133
  if (length + position > size) {
132
- TypeError::New(env, "Unexpected end of buffer reading string").ThrowAsJavaScriptException();
133
- return env.Null();
134
+ return unexpectedEnd(env);
134
135
  }
135
136
  readString(env, length, false);
136
137
  }
@@ -143,8 +144,7 @@ public:
143
144
  } else {
144
145
  position = tokenTable[token](source, position, size);
145
146
  if (position < 0) {
146
- TypeError::New(env, "Unexpected end of buffer").ThrowAsJavaScriptException();
147
- return env.Null();
147
+ return unexpectedEnd(env);
148
148
  }
149
149
  }
150
150
  }
@@ -154,19 +154,38 @@ public:
154
154
  napi_value value;
155
155
  napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
156
156
  if (writePosition == 0) {
157
+ /*if (!hasTargetArray) {
158
+ hasTargetArray = true;
159
+ napi_create_reference(env, array, 1, &targetArray);
160
+ }*/
157
161
  return value;
158
162
  }
159
163
  target[writePosition++] = value;
160
164
  } else if (writePosition == 1) {
165
+ /*if (!hasTargetArray) {
166
+ hasTargetArray = true;
167
+ napi_create_reference(env, array, 1, &targetArray);
168
+ }*/
161
169
  return target[0];
162
170
  }
163
171
  napi_value array;
172
+ #if ENABLE_V8_API
173
+ v8::Local<v8::Array> v8Array = v8::Array::New(v8::Isolate::GetCurrent(), (v8::Local<v8::Value>*) target, writePosition);
174
+ memcpy(&array, &v8Array, sizeof(array));
175
+ #else
164
176
  napi_create_array_with_length(env, writePosition, &array);
165
- //Array array = Array::New(env, writePosition);
177
+ /*if (hasTargetArray) {
178
+ napi_get_reference_value(env, targetArray, &array);
179
+ hasTargetArray = false;
180
+ }*/
166
181
  for (int i = 0; i < writePosition; i++) {
167
182
  napi_set_element(env, array, i, target[i]);
168
- //array.Set(i, target[i]);
169
- }
183
+ }/*
184
+ napi_value length;
185
+ napi_create_int32(env, i, &length);
186
+ return length;
187
+ napi_set_element(env, array, i, undefined); */
188
+ #endif
170
189
  return array;
171
190
  }
172
191
  };
@@ -247,29 +266,25 @@ void setupTokenTable() {
247
266
  return position + length;
248
267
  });
249
268
  }
250
-
251
269
  static thread_local Extractor* extractor;
252
-
253
- napi_value extractStrings(const CallbackInfo& info) {
254
- Env env = info.Env();
255
- int position = info[0].As<Number>();
256
- int size = info[1].As<Number>();
257
- if (info[2].IsTypedArray()) {
258
- TypedArray typedArray = info[2].As<TypedArray>();
259
- uint8_t* source = ((uint8_t*) typedArray.ArrayBuffer().Data()) + typedArray.ByteOffset();
260
- return extractor->extractStrings(env, position, size, source);
261
- }
262
- return env.Undefined();
270
+ napi_value extractStrings(napi_env env, napi_callback_info info) {
271
+ size_t argc = 3;
272
+ napi_value args[3];
273
+ napi_get_cb_info(env, info, &argc, args, NULL, NULL);
274
+ uint32_t position;
275
+ uint32_t size;
276
+ napi_get_value_uint32(env, args[0], &position);
277
+ napi_get_value_uint32(env, args[1], &size);
278
+ uint8_t* source;
279
+ napi_get_typedarray_info(env, args[2], NULL, NULL, (void**) &source, NULL, NULL);
280
+ return extractor->extractStrings(env, position, size, source);
263
281
  }
264
-
265
- Object Init(Env env, Object exports) {
282
+ #define EXPORT_NAPI_FUNCTION(name, func) { napi_property_descriptor desc = { name, 0, func, 0, 0, 0, (napi_property_attributes) (napi_writable | napi_configurable), 0 }; napi_define_properties(env, exports, 1, &desc); }
283
+ napi_value Init(napi_env env, napi_value exports) {
266
284
  extractor = new Extractor(); // create our thread-local extractor
267
285
  setupTokenTable();
268
- exports.Set(
269
- String::New(env, "extractStrings"),
270
- Function::New(env, extractStrings)
271
- );
286
+ EXPORT_NAPI_FUNCTION("extractStrings", extractStrings);
272
287
  return exports;
273
288
  }
274
289
 
275
- NODE_API_MODULE(extractor, Init)
290
+ NAPI_MODULE(extractor, Init)
@@ -1,19 +0,0 @@
1
- name: Test and Prebuild
2
- jobs:
3
- build:
4
- executor: my-ubuntu-exec
5
- steps:
6
- - uses: actions/checkout@v2
7
- - name: Setup node
8
- uses: actions/setup-node@v2
9
- with:
10
- node-version: 12
11
- - run: npm install
12
- - run: npm run prebuild
13
- - run: zip -r prebuild-darwin.zip prebuilds
14
- - run: hexdump "prebuilds/darwin-x64/node.abi93.node" | head -10
15
- - name: Prebuild
16
- uses: softprops/action-gh-release@v1
17
- if: startsWith(github.ref, 'refs/tags/')
18
- with:
19
- files: prebuild-darwin.zip
@@ -1,87 +0,0 @@
1
- name: Prebuild
2
- on: [push]
3
- jobs:
4
- build-test-macos:
5
- if: startsWith(github.ref, 'refs/tags/')
6
- runs-on: macos-11
7
- steps:
8
- - uses: actions/checkout@v2
9
- - name: Setup node
10
- uses: actions/setup-node@v2
11
- with:
12
- node-version: 12
13
- - run: npm install
14
- - run: npm test
15
- - run: npm run prebuild
16
- if: startsWith(github.ref, 'refs/tags/')
17
- - run: npm run prebuild-arm64
18
- if: startsWith(github.ref, 'refs/tags/')
19
- - run: tar --create --format ustar --verbose --file=prebuild-darwin.tar -C prebuilds .
20
- if: startsWith(github.ref, 'refs/tags/')
21
- - name: Prebuild
22
- uses: softprops/action-gh-release@v1
23
- if: startsWith(github.ref, 'refs/tags/')
24
- with:
25
- files: prebuild-darwin.tar
26
- build-centos-7:
27
- #if: startsWith(github.ref, 'refs/tags/')
28
- runs-on: ubuntu-18.04
29
- container: quay.io/pypa/manylinux2014_x86_64
30
- steps:
31
- - run: ldd --version ldd
32
- - uses: actions/checkout@v2
33
- - name: Setup node
34
- uses: actions/setup-node@v2
35
- with:
36
- node-version: 12
37
- - run: npm install
38
- - run: npm run prebuild
39
- - run: npm test
40
- - run: tar --create --verbose --file=prebuild-linux.tar -C prebuilds .
41
- - name: Prebuild
42
- if: startsWith(github.ref, 'refs/tags/')
43
- uses: softprops/action-gh-release@v1
44
- with:
45
- files: prebuild-linux.tar
46
- build-alpine:
47
- if: startsWith(github.ref, 'refs/tags/')
48
- runs-on: ubuntu-18.04
49
- container: node:12-alpine
50
- steps:
51
- - run: apk add python3 py3-pip build-base
52
- - uses: actions/checkout@v2
53
- - run: npm install
54
- - run: npm run prebuild-musl
55
- - run: npm test
56
- - run: tar --create --verbose --file=prebuild-alpine.tar -C prebuilds .
57
- - name: Prebuild
58
- if: startsWith(github.ref, 'refs/tags/')
59
- uses: softprops/action-gh-release@v1
60
- with:
61
- files: prebuild-alpine.tar
62
- build-linux-arm64:
63
- if: startsWith(github.ref, 'refs/tags/')
64
- runs-on: ubuntu-18.04
65
- container: quay.io/pypa/manylinux_2_24_x86_64
66
- steps:
67
- - run: apt-get update
68
- - run: apt-get install -y gcc-aarch64-linux-gnu
69
- - run: apt-get install -y g++-aarch64-linux-gnu
70
- - run: ldd --version ldd
71
- - uses: actions/checkout@v2
72
- - name: Setup node
73
- uses: actions/setup-node@v2
74
- with:
75
- node-version: 12
76
- - run: npm install
77
- - run: npm run prebuild-arm64
78
- if: startsWith(github.ref, 'refs/tags/')
79
- env:
80
- CC: aarch64-linux-gnu-gcc
81
- CXX: aarch64-linux-gnu-g++
82
- - run: tar --create --verbose --file=prebuild-linux-arm64.tar -C prebuilds .
83
- - name: Prebuild
84
- if: startsWith(github.ref, 'refs/tags/')
85
- uses: softprops/action-gh-release@v1
86
- with:
87
- files: prebuild-linux-arm64.tar
package/.travis.yml DELETED
@@ -1,30 +0,0 @@
1
- sudo: false
2
- language: node_js
3
- node_js:
4
- - node
5
- addons:
6
- apt:
7
- sources:
8
- - ubuntu-toolchain-r-test
9
- arch:
10
- - amd64
11
- - arm64
12
- os:
13
- - osx
14
- - linux
15
- osx_image: xcode12.5
16
- before_deploy:
17
- - ARCHIVE_NAME="${TRAVIS_TAG:-latest}-$TRAVIS_OS_NAME-`uname -m`.tar"
18
- - npm run prebuild
19
- - tar --create --verbose --file="$ARCHIVE_NAME" --directory "$TRAVIS_BUILD_DIR/prebuilds"
20
- .
21
- deploy:
22
- provider: releases
23
- draft: false
24
- prerelease: true
25
- file: "$ARCHIVE_NAME"
26
- skip_cleanup: true
27
- on:
28
- tags: true
29
- node: node
30
- api_key: '$GITHUB_API_KEY'
@@ -1,15 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "name": "(Windows) Attach",
9
- "type": "cppvsdbg",
10
- "request": "attach",
11
- "processId": "${command:pickProcess}",
12
- "internalConsoleOptions": "neverOpen"
13
- },
14
- ]
15
- }
Binary file
Binary file
Binary file