msgpackr-extract 2.0.0-beta → 2.0.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,12 +1,25 @@
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
- "target_name": "msgpackr-extract",
9
- "win_delay_load_hook": "false",
22
+ "target_name": "extract",
10
23
  "sources": [
11
24
  "src/extract.cpp",
12
25
  ],
@@ -38,6 +51,12 @@
38
51
  "-O3"
39
52
  ],
40
53
  }],
54
+ ["enable_v8!='false'", {
55
+ "defines": ["ENABLE_V8_API=1"]
56
+ }],
57
+ ["enable_pointer_compression=='true'", {
58
+ "defines": ["V8_COMPRESS_POINTERS", "V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE"],
59
+ }],
41
60
  ],
42
61
  }
43
62
  ]
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": "2.0.0-beta",
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 --optional-packages --napi --target 12.22.7",
15
- "prebuild": "prebuildify --optional-packages --napi --target 12.22.7",
16
- "prebuild-libc": "prebuildify --optional-packages --napi --tag-libc --target 12.22.7",
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 ../.. && npm publish --otp %OTP%",
18
- "test": "node ./index.js"
19
- },
20
- "main": "./index.js",
21
- "gypfile": true,
22
- "dependencies": {
23
- "node-gyp-build": "kriszyp/node-gyp-build#optional-packages"
24
- },
25
- "devDependencies": {
26
- "prebuildify": "kriszyp/prebuildify#optional-packages",
27
- "prebuildify-ci": "^1.0.5"
28
- }
29
- }
1
+ {
2
+ "name": "msgpackr-extract",
3
+ "author": "Kris Zyp",
4
+ "version": "2.0.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-optional-packages",
13
+ "recompile": "node-gyp rebuild",
14
+ "before-publish": "prebuildify-ci download && prebuildify --target 16.14.2 && set ENABLE_V8_FUNCTIONS=false&& prebuildify --platform-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 --platform-packages --napi --tag-libc --target 16.14.2",
17
+ "publish-all": "cd prebuilds/win32-x64 && npm publish --access public && cd ../darwin-x64 && npm publish --access public && cd ../darwin-arm64 && npm publish --access public && cd ../linux-x64 && npm publish --access public && cd ../linux-arm64 && npm publish --access public && cd ../linux-arm && npm publish --access public && cd ../.. && npm publish --access public",
18
+ "test": "node ./index.js"
19
+ },
20
+ "main": "./index.js",
21
+ "gypfile": true,
22
+ "dependencies": {
23
+ "node-gyp-build-optional-packages": "5.0.2"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "/src",
28
+ "/*.gyp"
29
+ ],
30
+ "optionalDependencies": {
31
+ "@msgpackr-extract/msgpackr-extract-darwin-arm64": "2.0.2",
32
+ "@msgpackr-extract/msgpackr-extract-darwin-x64": "2.0.2",
33
+ "@msgpackr-extract/msgpackr-extract-linux-arm": "2.0.2",
34
+ "@msgpackr-extract/msgpackr-extract-linux-arm64": "2.0.2",
35
+ "@msgpackr-extract/msgpackr-extract-linux-x64": "2.0.2",
36
+ "@msgpackr-extract/msgpackr-extract-win32-x64": "2.0.2"
37
+ },
38
+ "devDependencies": {
39
+ "prebuildify": "kriszyp/prebuildify#optional-packages",
40
+ "prebuildify-ci": "^1.0.5"
41
+ }
42
+ }
package/src/extract.cpp CHANGED
@@ -6,6 +6,9 @@ times as necessary to get more strings. This must be partially capable of parsin
6
6
  find the string tokens and determine their position and length. All strings are decoded as UTF-8.
7
7
  */
8
8
  #include <node_api.h>
9
+ #if ENABLE_V8_API
10
+ #include <v8.h>
11
+ #endif
9
12
 
10
13
  #ifndef thread_local
11
14
  #ifdef __GNUC__
@@ -31,8 +34,7 @@ napi_value unexpectedEnd(napi_env env) {
31
34
 
32
35
  class Extractor {
33
36
  public:
34
- napi_value target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
35
- napi_ref targetArray;
37
+ // napi_ref targetArray; // could consider reenabling this optimization for napi
36
38
  bool hasTargetArray = false;
37
39
  uint8_t* source;
38
40
  int position = 0;
@@ -40,7 +42,7 @@ public:
40
42
  int stringStart = 0;
41
43
  int lastStringEnd = 0;
42
44
 
43
- void readString(napi_env env, int length, bool allowStringBlocks) {
45
+ void readString(napi_env env, int length, bool allowStringBlocks, napi_value* target) {
44
46
  int start = position;
45
47
  int end = position + length;
46
48
  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
@@ -81,7 +83,8 @@ public:
81
83
  lastStringEnd = end;
82
84
  }
83
85
 
84
- napi_value extractStrings(napi_env env, int startingPosition, int size, uint8_t* inputSource, napi_value array) {
86
+ napi_value extractStrings(napi_env env, int startingPosition, int size, uint8_t* inputSource) {
87
+ napi_value target[MAX_TARGET_SIZE + 1]; // leave one for the queued string
85
88
  writePosition = 0;
86
89
  lastStringEnd = 0;
87
90
  position = startingPosition;
@@ -96,7 +99,7 @@ public:
96
99
  if (token + position > size) {
97
100
  return unexpectedEnd(env);
98
101
  }
99
- readString(env,token, true);
102
+ readString(env, token, true, target);
100
103
  if (writePosition >= MAX_TARGET_SIZE)
101
104
  break;
102
105
  } else if (token <= 0xdb && token >= 0xd9) {
@@ -108,7 +111,7 @@ public:
108
111
  if (length + position > size) {
109
112
  return unexpectedEnd(env);
110
113
  }
111
- readString(env,length, true);
114
+ readString(env,length, true, target);
112
115
  } else if (token == 0xda) { //str 16
113
116
  if (2 + position > size) {
114
117
  return unexpectedEnd(env);
@@ -118,7 +121,7 @@ public:
118
121
  if (length + position > size) {
119
122
  return unexpectedEnd(env);
120
123
  }
121
- readString(env,length, false);
124
+ readString(env,length, false, target);
122
125
  } else { //str 32
123
126
  if (4 + position > size) {
124
127
  return unexpectedEnd(env);
@@ -130,7 +133,7 @@ public:
130
133
  if (length + position > size) {
131
134
  return unexpectedEnd(env);
132
135
  }
133
- readString(env, length, false);
136
+ readString(env, length, false, target);
134
137
  }
135
138
  if (writePosition >= MAX_TARGET_SIZE)
136
139
  break;
@@ -151,36 +154,23 @@ public:
151
154
  napi_value value;
152
155
  napi_create_string_latin1(env, (const char*) source + stringStart, lastStringEnd - stringStart, &value);
153
156
  if (writePosition == 0) {
154
- if (!hasTargetArray) {
155
- hasTargetArray = true;
156
- napi_create_reference(env, array, 1, &targetArray);
157
- }
158
157
  return value;
159
158
  }
160
159
  target[writePosition++] = value;
161
160
  } else if (writePosition == 1) {
162
- if (!hasTargetArray) {
163
- hasTargetArray = true;
164
- napi_create_reference(env, array, 1, &targetArray);
165
- }
166
161
  return target[0];
167
162
  }
168
- //napi_value array;
169
- //napi_get_reference_value(env, targetArray, &array);
170
- //napi_create_array_with_length(env, writePosition, &array);
171
- if (hasTargetArray) {
172
- napi_get_reference_value(env, targetArray, &array);
173
- hasTargetArray = false;
174
- }
175
- int i = 0;
176
- for (i = 0; i < writePosition; i++) {
163
+ napi_value array;
164
+ #if ENABLE_V8_API
165
+ v8::Local<v8::Array> v8Array = v8::Array::New(v8::Isolate::GetCurrent(), (v8::Local<v8::Value>*) target, writePosition);
166
+ memcpy(&array, &v8Array, sizeof(array));
167
+ #else
168
+ napi_create_array_with_length(env, writePosition, &array);
169
+ for (int i = 0; i < writePosition; i++) {
177
170
  napi_set_element(env, array, i, target[i]);
178
171
  }
179
- napi_value length;
180
- napi_create_int32(env, i, &length);
181
- return length;/*
182
- napi_set_element(env, array, i, undefined);
183
- return array;*/
172
+ #endif
173
+ return array;
184
174
  }
185
175
  };
186
176
 
@@ -262,8 +252,8 @@ void setupTokenTable() {
262
252
  }
263
253
  static thread_local Extractor* extractor;
264
254
  napi_value extractStrings(napi_env env, napi_callback_info info) {
265
- size_t argc = extractor->hasTargetArray ? 3 : 4;
266
- napi_value args[4];
255
+ size_t argc = 3;
256
+ napi_value args[3];
267
257
  napi_get_cb_info(env, info, &argc, args, NULL, NULL);
268
258
  uint32_t position;
269
259
  uint32_t size;
@@ -271,14 +261,12 @@ napi_value extractStrings(napi_env env, napi_callback_info info) {
271
261
  napi_get_value_uint32(env, args[1], &size);
272
262
  uint8_t* source;
273
263
  napi_get_typedarray_info(env, args[2], NULL, NULL, (void**) &source, NULL, NULL);
274
- return extractor->extractStrings(env, position, size, source, args[3]);
264
+ return extractor->extractStrings(env, position, size, source);
275
265
  }
276
266
  #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); }
277
- napi_value Init(napi_env env, napi_value exports) {
267
+ NAPI_MODULE_INIT() {
278
268
  extractor = new Extractor(); // create our thread-local extractor
279
269
  setupTokenTable();
280
270
  EXPORT_NAPI_FUNCTION("extractStrings", extractStrings);
281
271
  return exports;
282
272
  }
283
-
284
- 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,98 +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-libc
16
- if: startsWith(github.ref, 'refs/tags/')
17
- - run: npm run prebuild-libc
18
- if: startsWith(github.ref, 'refs/tags/')
19
- env:
20
- PREBUILD_ARCH: arm64
21
- - run: tar --create --format ustar --verbose --file=prebuild-darwin.tar -C prebuilds .
22
- if: startsWith(github.ref, 'refs/tags/')
23
- - name: Prebuild
24
- uses: softprops/action-gh-release@v1
25
- if: startsWith(github.ref, 'refs/tags/')
26
- with:
27
- files: prebuild-darwin.tar
28
- build-centos-7:
29
- #if: startsWith(github.ref, 'refs/tags/')
30
- runs-on: ubuntu-18.04
31
- container: quay.io/pypa/manylinux2014_x86_64
32
- steps:
33
- - run: ldd --version ldd
34
- - uses: actions/checkout@v2
35
- - name: Setup node
36
- uses: actions/setup-node@v2
37
- with:
38
- node-version: 12
39
- - run: npm install
40
- - run: npm run prebuild-libc
41
- - run: npm test
42
- - run: tar --create --verbose --file=prebuild-linux.tar -C prebuilds .
43
- - name: Prebuild
44
- if: startsWith(github.ref, 'refs/tags/')
45
- uses: softprops/action-gh-release@v1
46
- with:
47
- files: prebuild-linux.tar
48
- build-alpine:
49
- if: startsWith(github.ref, 'refs/tags/')
50
- runs-on: ubuntu-18.04
51
- container: node:12-alpine
52
- steps:
53
- - run: apk add python3 py3-pip build-base
54
- - uses: actions/checkout@v2
55
- - run: npm install
56
- - run: npm run prebuild-libc
57
- env:
58
- PREBUILD_LIBC: musl
59
- PREBUILD_ARCH: arm64
60
- CC: ${PWD}/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc
61
- CXX: ${PWD}/aarch64-linux-musl-cross/bin/aarch64-linux-musl-g++
62
- - run: npm run prebuild-libc
63
- env:
64
- PREBUILD_LIBC: musl
65
- - run: npm test
66
- - run: tar --create --verbose --file=prebuild-alpine.tar -C prebuilds .
67
- - name: Prebuild
68
- if: startsWith(github.ref, 'refs/tags/')
69
- uses: softprops/action-gh-release@v1
70
- with:
71
- files: prebuild-alpine.tar
72
- build-linux-arm64:
73
- if: startsWith(github.ref, 'refs/tags/')
74
- runs-on: ubuntu-18.04
75
- container: quay.io/pypa/manylinux_2_24_x86_64
76
- steps:
77
- - run: apt-get update
78
- - run: apt-get install -y gcc-aarch64-linux-gnu
79
- - run: apt-get install -y g++-aarch64-linux-gnu
80
- - run: ldd --version ldd
81
- - uses: actions/checkout@v2
82
- - name: Setup node
83
- uses: actions/setup-node@v2
84
- with:
85
- node-version: 12
86
- - run: npm install
87
- - run: npm run prebuild-libc
88
- if: startsWith(github.ref, 'refs/tags/')
89
- env:
90
- PREBUILD_ARCH: arm64
91
- CC: aarch64-linux-gnu-gcc
92
- CXX: aarch64-linux-gnu-g++
93
- - run: tar --create --verbose --file=prebuild-linux-arm64.tar -C prebuilds .
94
- - name: Prebuild
95
- if: startsWith(github.ref, 'refs/tags/')
96
- uses: softprops/action-gh-release@v1
97
- with:
98
- 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
- }
@@ -1 +0,0 @@
1
- Platform specific binary for msgpackr-extract on darwin OS with arm64 architecture
File without changes
@@ -1,11 +0,0 @@
1
- {
2
- "name": "msgpackr-extract-darwin-arm64",
3
- "version": "2.0.0-beta",
4
- "os": [
5
- "darwin"
6
- ],
7
- "cpu": [
8
- "arm64"
9
- ],
10
- "description": "Platform specific binary for msgpackr-extract on darwin OS with arm64 architecture"
11
- }
@@ -1 +0,0 @@
1
- Platform specific binary for msgpackr-extract on darwin OS with x64 architecture
File without changes
@@ -1,11 +0,0 @@
1
- {
2
- "name": "msgpackr-extract-darwin-x64",
3
- "version": "2.0.0-beta",
4
- "os": [
5
- "darwin"
6
- ],
7
- "cpu": [
8
- "x64"
9
- ],
10
- "description": "Platform specific binary for msgpackr-extract on darwin OS with x64 architecture"
11
- }
@@ -1 +0,0 @@
1
- Platform specific binary for msgpackr-extract on linux OS with arm64 architecture
File without changes
@@ -1,11 +0,0 @@
1
- {
2
- "name": "msgpackr-extract-linux-arm64",
3
- "version": "2.0.0-beta",
4
- "os": [
5
- "linux"
6
- ],
7
- "cpu": [
8
- "arm64"
9
- ],
10
- "description": "Platform specific binary for msgpackr-extract on linux OS with arm64 architecture"
11
- }
@@ -1 +0,0 @@
1
- Platform specific binary for msgpackr-extract on linux OS with x64 architecture
File without changes
@@ -1,11 +0,0 @@
1
- {
2
- "name": "msgpackr-extract-linux-x64",
3
- "version": "2.0.0-beta",
4
- "os": [
5
- "linux"
6
- ],
7
- "cpu": [
8
- "x64"
9
- ],
10
- "description": "Platform specific binary for msgpackr-extract on linux OS with x64 architecture"
11
- }
@@ -1 +0,0 @@
1
- Platform specific binary for msgpackr-extract on win32 OS with x64 architecture
File without changes
Binary file
@@ -1,11 +0,0 @@
1
- {
2
- "name": "msgpackr-extract-win32-x64",
3
- "version": "2.0.0-beta",
4
- "os": [
5
- "win32"
6
- ],
7
- "cpu": [
8
- "x64"
9
- ],
10
- "description": "Platform specific binary for msgpackr-extract on win32 OS with x64 architecture"
11
- }