koffi 2.5.7 → 2.5.9

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.
Files changed (78) hide show
  1. package/CHANGELOG.md +17 -100
  2. package/build/{2.5.7/koffi_darwin_arm64 → koffi/darwin_arm64}/koffi.node +0 -0
  3. package/build/{2.5.7/koffi_darwin_x64 → koffi/darwin_x64}/koffi.node +0 -0
  4. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  5. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  6. package/build/{2.5.7/koffi_freebsd_x64 → koffi/freebsd_x64}/koffi.node +0 -0
  7. package/build/koffi/linux_arm32hf/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_riscv64hf64/koffi.node +0 -0
  11. package/build/{2.5.7/koffi_linux_x64 → koffi/linux_x64}/koffi.node +0 -0
  12. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  13. package/build/{2.5.7/koffi_openbsd_x64 → koffi/openbsd_x64}/koffi.node +0 -0
  14. package/build/koffi/win32_arm64/koffi.node +0 -0
  15. package/build/{2.5.7/koffi_win32_ia32 → koffi/win32_ia32}/koffi.node +0 -0
  16. package/build/{2.5.7/koffi_win32_x64 → koffi/win32_x64}/koffi.node +0 -0
  17. package/doc/conf.py +15 -7
  18. package/doc/contribute.md +2 -2
  19. package/doc/index.rst +1 -0
  20. package/doc/packaging.md +60 -0
  21. package/doc/pyproject.toml +1 -1
  22. package/doc/start.md +9 -3
  23. package/doc/static/custom.css +41 -1
  24. package/doc/static/node_c.webp +0 -0
  25. package/doc/static/opensans/LICENSE.txt +202 -0
  26. package/doc/static/opensans/OpenSans.css +39 -0
  27. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff +0 -0
  28. package/doc/static/opensans/OpenSans_v17_Latin_Bold.woff2 +0 -0
  29. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff +0 -0
  30. package/doc/static/opensans/OpenSans_v17_Latin_BoldItalic.woff2 +0 -0
  31. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff +0 -0
  32. package/doc/static/opensans/OpenSans_v17_Latin_Italic.woff2 +0 -0
  33. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff +0 -0
  34. package/doc/static/opensans/OpenSans_v17_Latin_Regular.woff2 +0 -0
  35. package/doc/templates/logo.html +3 -0
  36. package/package.json +3 -3
  37. package/src/cnoke/assets/FindCNoke.cmake +16 -0
  38. package/src/core/libcc/libcc.cc +67 -13
  39. package/src/core/libcc/libcc.hh +24 -13
  40. package/src/index.d.ts +4 -0
  41. package/src/index.js +51 -10
  42. package/src/koffi/CMakeLists.txt +6 -0
  43. package/src/koffi/examples/electron-builder/README.md +23 -0
  44. package/src/koffi/examples/electron-builder/package.json +21 -0
  45. package/src/koffi/examples/electron-builder/src/app.js +20 -0
  46. package/src/koffi/examples/electron-builder/src/index.html +143 -0
  47. package/src/koffi/examples/electron-builder/src/preload.js +5 -0
  48. package/src/koffi/examples/electron-forge/README.md +25 -0
  49. package/src/koffi/examples/electron-forge/forge.config.js +43 -0
  50. package/src/koffi/examples/electron-forge/package.json +37 -0
  51. package/src/koffi/examples/electron-forge/src/index.css +7 -0
  52. package/src/koffi/examples/electron-forge/src/index.html +143 -0
  53. package/src/koffi/examples/electron-forge/src/main.js +52 -0
  54. package/src/koffi/examples/electron-forge/src/preload.js +5 -0
  55. package/src/koffi/examples/electron-forge/src/renderer.js +31 -0
  56. package/src/koffi/examples/electron-forge/webpack.main.config.js +11 -0
  57. package/src/koffi/examples/electron-forge/webpack.renderer.config.js +13 -0
  58. package/src/koffi/examples/electron-forge/webpack.rules.js +35 -0
  59. package/src/koffi/examples/nwjs/README.md +20 -0
  60. package/src/koffi/examples/nwjs/package.json +11 -0
  61. package/src/koffi/examples/nwjs/src/index.html +145 -0
  62. package/src/koffi/examples/nwjs/src/package.json +9 -0
  63. package/src/koffi/src/ffi.cc +1 -0
  64. package/build/2.5.7/koffi_freebsd_arm64/koffi.node +0 -0
  65. package/build/2.5.7/koffi_freebsd_ia32/koffi.node +0 -0
  66. package/build/2.5.7/koffi_linux_arm32hf/koffi.node +0 -0
  67. package/build/2.5.7/koffi_linux_arm64/koffi.node +0 -0
  68. package/build/2.5.7/koffi_linux_ia32/koffi.node +0 -0
  69. package/build/2.5.7/koffi_linux_riscv64hf64/koffi.node +0 -0
  70. package/build/2.5.7/koffi_openbsd_ia32/koffi.node +0 -0
  71. package/build/2.5.7/koffi_win32_arm64/koffi.node +0 -0
  72. package/doc/favicon.png +0 -0
  73. /package/build/{2.5.7/koffi_win32_arm64 → koffi/win32_arm64}/koffi.exp +0 -0
  74. /package/build/{2.5.7/koffi_win32_arm64 → koffi/win32_arm64}/koffi.lib +0 -0
  75. /package/build/{2.5.7/koffi_win32_ia32 → koffi/win32_ia32}/koffi.exp +0 -0
  76. /package/build/{2.5.7/koffi_win32_ia32 → koffi/win32_ia32}/koffi.lib +0 -0
  77. /package/build/{2.5.7/koffi_win32_x64 → koffi/win32_x64}/koffi.exp +0 -0
  78. /package/build/{2.5.7/koffi_win32_x64 → koffi/win32_x64}/koffi.lib +0 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,39 @@
1
+ /* open-sans-regular - latin */
2
+ @font-face {
3
+ font-family: 'Open Sans';
4
+ font-style: normal;
5
+ font-weight: 400;
6
+ src: local('Open Sans Regular'), local('OpenSans-Regular'),
7
+ url('OpenSans_v17_Latin_Regular.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
8
+ url('OpenSans_v17_Latin_Regular.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
9
+ }
10
+
11
+ /* open-sans-italic - latin */
12
+ @font-face {
13
+ font-family: 'Open Sans';
14
+ font-style: italic;
15
+ font-weight: 400;
16
+ src: local('Open Sans Italic'), local('OpenSans-Italic'),
17
+ url('OpenSans_v17_Latin_Italic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
18
+ url('OpenSans_v17_Latin_Italic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
19
+ }
20
+
21
+ /* open-sans-700 - latin */
22
+ @font-face {
23
+ font-family: 'Open Sans';
24
+ font-style: normal;
25
+ font-weight: 700;
26
+ src: local('Open Sans Bold'), local('OpenSans-Bold'),
27
+ url('OpenSans_v17_Latin_Bold.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
28
+ url('OpenSans_v17_Latin_Bold.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
29
+ }
30
+
31
+ /* open-sans-700italic - latin */
32
+ @font-face {
33
+ font-family: 'Open Sans';
34
+ font-style: italic;
35
+ font-weight: 700;
36
+ src: local('Open Sans Bold Italic'), local('OpenSans-BoldItalic'),
37
+ url('OpenSans_v17_Latin_BoldItalic.woff2') format('woff2'), /* Chrome 26+, Opera 23+, Firefox 39+ */
38
+ url('OpenSans_v17_Latin_BoldItalic.woff') format('woff'); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
39
+ }
@@ -0,0 +1,3 @@
1
+ <div style="text-align: center; padding: 1em;">
2
+ <a href="/"><img class="sidebar-logo" style="width: 128px;" src="_static/node_c.webp" alt="Logo"/></a>
3
+ </div>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koffi",
3
- "version": "2.5.7",
4
- "stable": "2.5.7",
3
+ "version": "2.5.9",
4
+ "stable": "2.5.9",
5
5
  "description": "Fast and simple C FFI (foreign function interface) for Node.js",
6
6
  "keywords": [
7
7
  "foreign",
@@ -27,6 +27,6 @@
27
27
  "cnoke": {
28
28
  "napi": 8,
29
29
  "require": "./src/index.js",
30
- "output": "build/{{version}}/koffi_{{platform}}_{{arch}}"
30
+ "output": "build/{{version}}/{{platform}}_{{arch}}"
31
31
  }
32
32
  }
@@ -48,8 +48,12 @@ if(USE_UNITY_BUILDS)
48
48
  set(unity_file_cpp "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_unity.cpp")
49
49
  file(REMOVE ${unity_file_c} ${unity_file_cpp})
50
50
 
51
+ set(c_definitions "")
52
+ set(cpp_definitions "")
53
+
51
54
  foreach(src ${sources})
52
55
  get_source_file_property(language ${src} LANGUAGE)
56
+ get_property(definitions SOURCE ${src} PROPERTY COMPILE_DEFINITIONS)
53
57
  if(IS_ABSOLUTE ${src})
54
58
  set(src_full ${src})
55
59
  else()
@@ -58,17 +62,29 @@ if(USE_UNITY_BUILDS)
58
62
  if(language STREQUAL "C")
59
63
  set_source_files_properties(${src} PROPERTIES HEADER_FILE_ONLY 1)
60
64
  file(APPEND ${unity_file_c} "#include \"${src_full}\"\n")
65
+ if (definitions)
66
+ set(c_definitions "${c_definitions} ${definitions}")
67
+ endif()
61
68
  elseif(language STREQUAL "CXX")
62
69
  set_source_files_properties(${src} PROPERTIES HEADER_FILE_ONLY 1)
63
70
  file(APPEND ${unity_file_cpp} "#include \"${src_full}\"\n")
71
+ if (definitions)
72
+ set(cpp_definitions "${cpp_definitions} ${definitions}")
73
+ endif()
64
74
  endif()
65
75
  endforeach()
66
76
 
67
77
  if(EXISTS ${unity_file_c})
68
78
  target_sources(${TARGET} PRIVATE ${unity_file_c})
79
+ if(c_definitions)
80
+ set_source_files_properties(${unity_file_c} PROPERTIES COMPILE_DEFINITIONS ${c_definitions})
81
+ endif()
69
82
  endif()
70
83
  if(EXISTS ${unity_file_cpp})
71
84
  target_sources(${TARGET} PRIVATE ${unity_file_cpp})
85
+ if(cpp_definitions)
86
+ set_source_files_properties(${unity_file_cpp} PROPERTIES COMPILE_DEFINITIONS ${cpp_definitions})
87
+ endif()
72
88
  endif()
73
89
 
74
90
  target_compile_definitions(${TARGET} PRIVATE -DUNITY_BUILD=1)
@@ -3804,17 +3804,29 @@ struct PendingIO {
3804
3804
  }
3805
3805
  };
3806
3806
 
3807
- bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()> in_func,
3807
+ bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
3808
+ FunctionRef<Span<const uint8_t>()> in_func,
3808
3809
  FunctionRef<void(Span<uint8_t> buf)> out_func, int *out_code)
3809
3810
  {
3810
3811
  STARTUPINFOW si = {};
3811
3812
 
3813
+ BlockAllocator temp_alloc;
3814
+
3812
3815
  // Convert command line
3813
- Span<wchar_t> cmd_line_w = AllocateSpan<wchar_t>(nullptr, 2 * strlen(cmd_line) + 1);
3814
- RG_DEFER { ReleaseSpan(nullptr, cmd_line_w); };
3816
+ Span<wchar_t> cmd_line_w = AllocateSpan<wchar_t>(&temp_alloc, 2 * strlen(cmd_line) + 1);
3815
3817
  if (ConvertUtf8ToWin32Wide(cmd_line, cmd_line_w) < 0)
3816
3818
  return false;
3817
3819
 
3820
+ // Convert work directory
3821
+ Span<wchar_t> work_dir_w;
3822
+ if (work_dir) {
3823
+ work_dir_w = AllocateSpan<wchar_t>(&temp_alloc, 2 * strlen(work_dir) + 1);
3824
+ if (ConvertUtf8ToWin32Wide(work_dir, work_dir_w) < 0)
3825
+ return false;
3826
+ } else {
3827
+ work_dir_w = {};
3828
+ }
3829
+
3818
3830
  // Detect CTRL+C and CTRL+BREAK events
3819
3831
  if (!InitConsoleCtrlHandler())
3820
3832
  return false;
@@ -3887,7 +3899,7 @@ bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()>
3887
3899
 
3888
3900
  PROCESS_INFORMATION pi = {};
3889
3901
  if (!CreateProcessW(nullptr, cmd_line_w.ptr, nullptr, nullptr, TRUE, CREATE_NEW_PROCESS_GROUP,
3890
- nullptr, nullptr, &si, &pi)) {
3902
+ nullptr, work_dir_w.ptr, &si, &pi)) {
3891
3903
  LogError("Failed to start process: %1", GetWin32ErrorString());
3892
3904
  return false;
3893
3905
  }
@@ -4096,7 +4108,8 @@ void CloseDescriptorSafe(int *fd_ptr)
4096
4108
  *fd_ptr = -1;
4097
4109
  }
4098
4110
 
4099
- bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()> in_func,
4111
+ bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
4112
+ FunctionRef<Span<const uint8_t>()> in_func,
4100
4113
  FunctionRef<void(Span<uint8_t> buf)> out_func, int *out_code)
4101
4114
  {
4102
4115
  // Create read pipes
@@ -4169,9 +4182,14 @@ bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()>
4169
4182
  return false;
4170
4183
  }
4171
4184
 
4172
- const char *argv[] = {"sh", "-c", cmd_line, nullptr};
4173
- if ((errno = posix_spawn(&pid, "/bin/sh", &file_actions, nullptr,
4174
- const_cast<char **>(argv), environ))) {
4185
+ if (work_dir) {
4186
+ const char *argv[] = {"env", "-C", work_dir, "sh", "-c", cmd_line, nullptr };
4187
+ errno = posix_spawn(&pid, "/bin/env", &file_actions, nullptr, const_cast<char **>(argv), environ);
4188
+ } else {
4189
+ const char *argv[] = {"sh", "-c", cmd_line, nullptr};
4190
+ errno = posix_spawn(&pid, "/bin/sh", &file_actions, nullptr, const_cast<char **>(argv), environ);
4191
+ }
4192
+ if (errno) {
4175
4193
  LogError("Failed to start process: %1", strerror(errno));
4176
4194
  return false;
4177
4195
  }
@@ -4311,7 +4329,8 @@ bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()>
4311
4329
 
4312
4330
  #endif
4313
4331
 
4314
- bool ExecuteCommandLine(const char *cmd_line, Span<const uint8_t> in_buf, Size max_len,
4332
+ bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
4333
+ Span<const uint8_t> in_buf, Size max_len,
4315
4334
  HeapArray<uint8_t> *out_buf, int *out_code)
4316
4335
  {
4317
4336
  Size start_len = out_buf->len;
@@ -4333,8 +4352,8 @@ bool ExecuteCommandLine(const char *cmd_line, Span<const uint8_t> in_buf, Size m
4333
4352
  // Don't f*ck up the log
4334
4353
  bool warned = false;
4335
4354
 
4336
- bool success = ExecuteCommandLine(cmd_line, [&]() { return in_buf; },
4337
- [&](Span<uint8_t> buf) {
4355
+ bool success = ExecuteCommandLine(cmd_line, work_dir, [&]() { return in_buf; },
4356
+ [&](Span<uint8_t> buf) {
4338
4357
  if (out_buf->len - start_len <= max_len - buf.len) {
4339
4358
  out_buf->Append(buf);
4340
4359
  } else if (!warned) {
@@ -4349,6 +4368,40 @@ bool ExecuteCommandLine(const char *cmd_line, Span<const uint8_t> in_buf, Size m
4349
4368
  return true;
4350
4369
  }
4351
4370
 
4371
+ Size ReadCommandOutput(const char *cmd_line, Span<char> out_output)
4372
+ {
4373
+ Size total_len = 0;
4374
+ const auto write = [&](Span<uint8_t> buf) {
4375
+ Size copy = std::min(out_output.len - total_len, buf.len);
4376
+
4377
+ memcpy_safe(out_output.ptr + total_len, buf.ptr, copy);
4378
+ total_len += copy;
4379
+ };
4380
+
4381
+ int exit_code;
4382
+ if (!ExecuteCommandLine(cmd_line, nullptr, MakeSpan((const uint8_t *)nullptr, 0), write, &exit_code))
4383
+ return -1;
4384
+ if (exit_code) {
4385
+ LogDebug("Command '%1 failed (exit code: %2)", cmd_line, exit_code);
4386
+ return -1;
4387
+ }
4388
+
4389
+ return total_len;
4390
+ }
4391
+
4392
+ bool ReadCommandOutput(const char *cmd_line, HeapArray<char> *out_output)
4393
+ {
4394
+ int exit_code;
4395
+ if (!ExecuteCommandLine(cmd_line, nullptr, {}, Kilobytes(4), out_output, &exit_code))
4396
+ return false;
4397
+ if (exit_code) {
4398
+ LogDebug("Command '%1 failed (exit code: %2)", cmd_line, exit_code);
4399
+ return false;
4400
+ }
4401
+
4402
+ return true;
4403
+ }
4404
+
4352
4405
  #ifdef _WIN32
4353
4406
 
4354
4407
  static HANDLE wait_msg_event = CreateEvent(nullptr, TRUE, FALSE, nullptr);
@@ -5114,7 +5167,9 @@ restart:
5114
5167
  int GetRandomIntSafe(int min, int max)
5115
5168
  {
5116
5169
  int range = max - min;
5117
- RG_ASSERT(range >= 2);
5170
+
5171
+ if (range < 2) [[unlikely]]
5172
+ return min;
5118
5173
 
5119
5174
  unsigned int treshold = (UINT_MAX - UINT_MAX % range);
5120
5175
 
@@ -6882,7 +6937,6 @@ bool ReloadAssets()
6882
6937
  asset_copy.data = AllocateSpan<uint8_t>(&assets_alloc, asset.data.len);
6883
6938
  memcpy_safe((void *)asset_copy.data.ptr, asset.data.ptr, (size_t)asset.data.len);
6884
6939
  asset_copy.compression_type = asset.compression_type;
6885
- asset_copy.source_map = DuplicateString(asset.source_map, &assets_alloc).ptr;
6886
6940
 
6887
6941
  assets.Append(asset_copy);
6888
6942
  }
@@ -4022,14 +4022,18 @@ bool CreatePipe(int pfd[2]);
4022
4022
  void CloseDescriptorSafe(int *fd_ptr);
4023
4023
  #endif
4024
4024
 
4025
- bool ExecuteCommandLine(const char *cmd_line, FunctionRef<Span<const uint8_t>()> in_func,
4025
+ bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
4026
+ FunctionRef<Span<const uint8_t>()> in_func,
4026
4027
  FunctionRef<void(Span<uint8_t> buf)> out_func, int *out_code);
4027
- bool ExecuteCommandLine(const char *cmd_line, Span<const uint8_t> in_buf, Size max_len,
4028
+ bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
4029
+ Span<const uint8_t> in_buf, Size max_len,
4028
4030
  HeapArray<uint8_t> *out_buf, int *out_code);
4029
4031
 
4030
- static inline bool ExecuteCommandLine(const char *cmd_line, int *out_code)
4031
- { return ExecuteCommandLine(cmd_line, {}, {}, out_code); }
4032
- static inline bool ExecuteCommandLine(const char *cmd_line, Span<const uint8_t> in_buf,
4032
+ // Simple variants
4033
+ static inline bool ExecuteCommandLine(const char *cmd_line, const char *work_dir, int *out_code)
4034
+ { return ExecuteCommandLine(cmd_line, work_dir, {}, {}, out_code); }
4035
+ static inline bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
4036
+ Span<const uint8_t> in_buf,
4033
4037
  FunctionRef<void(Span<uint8_t> buf)> out_func, int *out_code)
4034
4038
  {
4035
4039
  const auto read_once = [&]() {
@@ -4038,18 +4042,27 @@ static inline bool ExecuteCommandLine(const char *cmd_line, Span<const uint8_t>
4038
4042
  return buf;
4039
4043
  };
4040
4044
 
4041
- return ExecuteCommandLine(cmd_line, read_once, out_func, out_code);
4045
+ return ExecuteCommandLine(cmd_line, work_dir, read_once, out_func, out_code);
4042
4046
  }
4043
- static inline bool ExecuteCommandLine(const char *cmd_line, Span<const char> in_buf,
4047
+
4048
+ // Char variants
4049
+ static inline bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
4050
+ Span<const char> in_buf,
4044
4051
  FunctionRef<void(Span<char> buf)> out_func, int *out_code)
4045
4052
  {
4046
4053
  const auto write = [&](Span<uint8_t> buf) { out_func(buf.As<char>()); };
4047
- return ExecuteCommandLine(cmd_line, in_buf.As<const uint8_t>(), write, out_code);
4054
+ return ExecuteCommandLine(cmd_line, work_dir, in_buf.As<const uint8_t>(), write, out_code);
4048
4055
  }
4049
- static inline bool ExecuteCommandLine(const char *cmd_line, Span<const char> in_buf, Size max_len,
4056
+ static inline bool ExecuteCommandLine(const char *cmd_line, const char *work_dir,
4057
+ Span<const char> in_buf, Size max_len,
4050
4058
  HeapArray<char> *out_buf, int *out_code)
4051
- { return ExecuteCommandLine(cmd_line, in_buf.As<const uint8_t>(), max_len,
4052
- (HeapArray<uint8_t> *)out_buf, out_code); }
4059
+ {
4060
+ return ExecuteCommandLine(cmd_line, work_dir, in_buf.As<const uint8_t>(), max_len,
4061
+ (HeapArray<uint8_t> *)out_buf, out_code);
4062
+ }
4063
+
4064
+ Size ReadCommandOutput(const char *cmd_line, Span<char> out_output);
4065
+ bool ReadCommandOutput(const char *cmd_line, HeapArray<char> *out_output);
4053
4066
 
4054
4067
  void WaitDelay(int64_t delay);
4055
4068
 
@@ -4700,8 +4713,6 @@ struct AssetInfo {
4700
4713
  CompressionType compression_type;
4701
4714
  Span<const uint8_t> data;
4702
4715
 
4703
- const char *source_map;
4704
-
4705
4716
  RG_HASHTABLE_HANDLER(AssetInfo, name);
4706
4717
  };
4707
4718
 
package/src/index.d.ts CHANGED
@@ -79,6 +79,8 @@ declare module 'koffi' {
79
79
 
80
80
  thiscall(definition: string): KoffiFunction;
81
81
  thiscall(name: string, result: TypeSpec, arguments: TypeSpec[]): KoffiFunction;
82
+
83
+ unload(): void;
82
84
  }
83
85
 
84
86
  export function struct(name: string, def: Record<string, TypeSpecWithAlignment>): IKoffiCType;
@@ -149,4 +151,6 @@ declare module 'koffi' {
149
151
  export const os: {
150
152
  errno: Record<string, number>
151
153
  };
154
+
155
+ export const types: Record<string, IKoffiCType>;
152
156
  }
package/src/index.js CHANGED
@@ -38,20 +38,61 @@ if (process.versions.napi == null || process.versions.napi < pkg.cnoke.napi) {
38
38
  }
39
39
 
40
40
  let arch = cnoke.determine_arch();
41
- let filenames = [__dirname + `/../build/${pkg.version}/koffi_${process.platform}_${arch}/koffi.node`];
41
+ let triplet = `${process.platform}_${arch}`;
42
42
 
43
- if (process.resourcesPath != null) {
44
- filenames.push(
45
- process.resourcesPath + `/koffi/${pkg.version}/koffi_${process.platform}_${arch}/koffi.node`,
46
- process.resourcesPath + `/build/${pkg.version}/koffi_${process.platform}_${arch}/koffi.node`
47
- );
43
+ let native = null;
44
+
45
+ // Try an explicit list with static strings to help bundlers
46
+ try {
47
+ switch (triplet) {
48
+ case 'darwin_arm64': { native = require('../build/koffi/darwin_arm64/koffi.node'); } break;
49
+ case 'darwin_x64': { native = require('../build/koffi/darwin_x64/koffi.node'); } break;
50
+ case 'freebsd_arm46': { native = require('../build/koffi/freebsd_arm46/koffi.node'); } break;
51
+ case 'freebsd_ia32': { native = require('../build/koffi/freebsd_ia32/koffi.node'); } break;
52
+ case 'freebsd_x64': { native = require('../build/koffi/freebsd_x64/koffi.node'); } break;
53
+ case 'linux_arm32hf': { native = require('../build/koffi/linux_arm32hf/koffi.node'); } break;
54
+ case 'linux_arm64': { native = require('../build/koffi/linux_arm64/koffi.node'); } break;
55
+ case 'linux_ia32': { native = require('../build/koffi/linux_ia32/koffi.node'); } break;
56
+ case 'linux_risc64hf64': { native = require('../build/koffi/linux_risc64hf64/koffi.node'); } break;
57
+ case 'linux_x64': { native = require('../build/koffi/linux_x64/koffi.node'); } break;
58
+ case 'openbsd_ia32': { native = require('../build/koffi/openbsd_ia32/koffi.node'); } break;
59
+ case 'openbsd_x64': { native = require('../build/koffi/openbsd_x64/koffi.node'); } break;
60
+ case 'win32_arm64': { native = require('../build/koffi/win32_arm64/koffi.node'); } break;
61
+ case 'win32_ia32': { native = require('../build/koffi/win32_ia32/koffi.node'); } break;
62
+ case 'win32_x64': { native = require('../build/koffi/win32_x64/koffi.node'); } break;
63
+ }
64
+ } catch (err) {
65
+ // Go on!
48
66
  }
49
67
 
50
- let filename = filenames.find(filename => fs.existsSync(filename));
51
- if (filename == null)
52
- throw new Error('Cannot find the native Koffi module; did you bundle it correctly?');
68
+ // And now, search everywhere we know
69
+ if (native == null) {
70
+ let names = [
71
+ `/koffi/${process.platform}_${arch}/koffi.node`,
72
+ `/node_modules/koffi/build/koffi/${process.platform}_${arch}/koffi.node`
73
+ ];
74
+
75
+ for (let name of names) {
76
+ if (fs.existsSync(__dirname + name)) {
77
+ native = require(__dirname + name);
78
+ break;
79
+ }
80
+ }
53
81
 
54
- let native = require(filename);
82
+ if (native == null && process.resourcesPath != null) {
83
+ for (let name of names) {
84
+ if (fs.existsSync(process.resourcesPath + name)) {
85
+ native = require(process.resourcesPath + name);
86
+ break;
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ if (native == null)
93
+ throw new Error('Cannot find the native Koffi module; did you bundle it correctly?');
94
+ if (native.version != pkg.version)
95
+ throw new Error('Mismatched native Koffi modules');
55
96
 
56
97
  module.exports = {
57
98
  ...native,
@@ -47,6 +47,12 @@ endif()
47
47
 
48
48
  # ---- Koffi ----
49
49
 
50
+ file(READ ${CMAKE_CURRENT_SOURCE_DIR}/package.json PKG)
51
+ string(REGEX MATCH "\"version\": \"([^\"]+)\"" XX "${PKG}")
52
+ set(KOFFI_VERSION ${CMAKE_MATCH_1})
53
+
54
+ set_source_files_properties(src/ffi.cc PROPERTIES COMPILE_DEFINITIONS VERSION=${KOFFI_VERSION})
55
+
50
56
  set(KOFFI_SRC
51
57
  src/call.cc
52
58
  src/ffi.cc