From f3fc5e4b2540c6a9a82a9e8f6817dc938c63b736 Mon Sep 17 00:00:00 2001 From: ArtemNabok Date: Tue, 2 Oct 2018 14:30:23 +0300 Subject: [PATCH 1/5] fixed bug when GC removes dependent buffers, due to lost references --- lib/struct.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/struct.js b/lib/struct.js index 25fc033..72431a5 100644 --- a/lib/struct.js +++ b/lib/struct.js @@ -169,6 +169,12 @@ function set (buffer, offset, value) { // optimization: copy the buffer contents directly rather // than going through the ref-struct constructor value['ref.buffer'].copy(buffer, offset, 0, this.size) + if (value['ref.buffer']._refs) { + if (!buffer._refs) { + buffer._refs = [] + } + buffer._refs = buffer._refs.concat(value['ref.buffer']._refs) + } } else { if (offset > 0) { buffer = buffer.slice(offset) From 60d0ed18fb968860c06e14248ba92d22b22ae55b Mon Sep 17 00:00:00 2001 From: Aleksey Smolenchuk Date: Thu, 25 Apr 2019 14:41:45 -0700 Subject: [PATCH 2/5] Support Node v12.0.0 --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 98b3409..fdd6e41 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "c++", "ffi" ], - "version": "1.1.0", + "version": "2.0.0", "author": "Nathan Rajlich (http://tootallnate.net)", "repository": { "type": "git", @@ -18,16 +18,16 @@ "main": "./lib/struct.js", "license": "MIT", "scripts": { - "test": "node-gyp rebuild --directory test && mocha -gc --reporter spec" + "test": "node-gyp rebuild --directory test && mocha -gc-global --expose-gc --reporter spec" }, "dependencies": { - "debug": "2", - "ref": "1" + "debug": "4", + "ref": "lxe/ref#node-12" }, "devDependencies": { - "bindings": "~1.2.0", + "bindings": "~1.5.0", "nan": "2", "mocha": "*", - "ref-array": "~1.1.2" + "ref-array": "lxe/ref-array#node-12" } } From 4cd676f07f74277c9d37be12362892269b218ebe Mon Sep 17 00:00:00 2001 From: ZFail Date: Sun, 9 Jun 2019 22:55:38 +0300 Subject: [PATCH 3/5] - typings --- index.d.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..b45012d --- /dev/null +++ b/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for ref-struct +// Project: https://github.com/TooTallNate/ref-struct +// Definitions by: Paul Loyd +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +import ref = require('ref'); + +/** + * This is the `constructor` of the Struct type that gets returned. + * + * Invoke it with `new` to create a new Buffer instance backing the struct. + * Pass it an existing Buffer instance to use that as the backing buffer. + * Pass in an Object containing the struct fields to auto-populate the + * struct with the data. + * + * @constructor + */ +interface StructType extends ref.Type { + /** Pass it an existing Buffer instance to use that as the backing buffer. */ + new (arg: Buffer, data?: {}): any; + new (data?: {}): any; + /** Pass it an existing Buffer instance to use that as the backing buffer. */ + (arg: Buffer, data?: {}): any; + (data?: {}): any; + + fields: { [key: string]: { type: ref.Type } }; + + /** + * Adds a new field to the struct instance with the given name and type. + * Note that this function will throw an Error if any instances of the struct + * type have already been created, therefore this function must be called at the + * beginning, before any instances are created. + */ + defineProperty(name: string, type: ref.Type): void; + + /** + * Adds a new field to the struct instance with the given name and type. + * Note that this function will throw an Error if any instances of the struct + * type have already been created, therefore this function must be called at the + * beginning, before any instances are created. + */ + defineProperty(name: string, type: string): void; + + /** + * Custom for struct type instances. + * @override + */ + toString(): string; +} + +/** The struct type meta-constructor. */ +declare var StructType: { + new (fields?: object, opt?: object): StructType; + new (fields?: any[]): StructType; + (fields?: object, opt?: object): StructType; + (fields?: any[]): StructType; +} + +export = StructType; From bab1e154a717bc9735440705c41150b815a011c8 Mon Sep 17 00:00:00 2001 From: AntonGorunov Date: Sat, 22 Feb 2020 22:13:41 +0300 Subject: [PATCH 4/5] mark ref & ref-array as peerDependencies to add support for Nodejs 13 & Electron 8 --- package.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fdd6e41..2ab50b0 100644 --- a/package.json +++ b/package.json @@ -21,13 +21,15 @@ "test": "node-gyp rebuild --directory test && mocha -gc-global --expose-gc --reporter spec" }, "dependencies": { - "debug": "4", - "ref": "lxe/ref#node-12" + "debug": "4" + }, + "peerDependencies": { + "ref": "*", + "ref-array": "*" }, "devDependencies": { "bindings": "~1.5.0", "nan": "2", - "mocha": "*", - "ref-array": "lxe/ref-array#node-12" + "mocha": "*" } } From 4847c4a717078459dd55eb0b93d9a703bcb9e193 Mon Sep 17 00:00:00 2001 From: ZFail Date: Wed, 26 Feb 2020 16:14:09 +0300 Subject: [PATCH 5/5] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2ab50b0..cac4f52 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "c++", "ffi" ], - "version": "2.0.0", + "version": "2.0.1", "author": "Nathan Rajlich (http://tootallnate.net)", "repository": { "type": "git",