koffi 2.12.2 → 2.12.4

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 (35) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/build/koffi/darwin_arm64/koffi.node +0 -0
  3. package/build/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/koffi/freebsd_x64/koffi.node +0 -0
  7. package/build/koffi/linux_arm64/koffi.node +0 -0
  8. package/build/koffi/linux_armhf/koffi.node +0 -0
  9. package/build/koffi/linux_ia32/koffi.node +0 -0
  10. package/build/koffi/linux_loong64/koffi.node +0 -0
  11. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  12. package/build/koffi/linux_x64/koffi.node +0 -0
  13. package/build/koffi/musl_arm64/koffi.node +0 -0
  14. package/build/koffi/musl_x64/koffi.node +0 -0
  15. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  16. package/build/koffi/openbsd_x64/koffi.node +0 -0
  17. package/build/koffi/win32_arm64/koffi.node +0 -0
  18. package/build/koffi/win32_ia32/koffi.node +0 -0
  19. package/build/koffi/win32_x64/koffi.node +0 -0
  20. package/index.d.ts +226 -143
  21. package/index.js +9 -9
  22. package/indirect.js +9 -9
  23. package/package.json +2 -2
  24. package/src/core/base/base.cc +515 -78
  25. package/src/core/base/base.hh +56 -11
  26. package/src/core/base/crc.inc +2232 -0
  27. package/src/core/base/crc_gen.py +109 -0
  28. package/src/core/base/unicode.inc +426 -0
  29. package/src/core/{unicode/generate.py → base/unicode_gen.py} +84 -19
  30. package/src/koffi/CMakeLists.txt +0 -1
  31. package/src/koffi/src/ffi.cc +0 -1
  32. package/src/koffi/src/parser.cc +0 -1
  33. package/src/core/unicode/xid.cc +0 -52
  34. package/src/core/unicode/xid.hh +0 -29
  35. package/src/core/unicode/xid.inc +0 -465
@@ -51,16 +51,44 @@ LICENSE_HEADER = """// Copyright (C) 2025 Niels Martignène <niels.martignene@p
51
51
  // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
52
52
  // OTHER DEALINGS IN THE SOFTWARE."""
53
53
 
54
- XidResult = namedtuple('XidResult', ['version', 'id_start', 'id_continue'])
54
+ WcWidthResult = namedtuple('WcWidthResult', ['null', 'wide'])
55
+ XidResult = namedtuple('XidResult', ['id_start', 'id_continue'])
55
56
 
56
- def parse_properties_xid(text):
57
+ def parse_version(core):
58
+ lines = iter(core.splitlines())
59
+ version = next(lines).strip("\n\r \t#") + ' -- ' + next(lines).strip("\n\r \t#")
60
+
61
+ return version
62
+
63
+ def parse_properties_wcwidth(core, asian):
64
+ null = []
65
+ wide = []
66
+
67
+ for (chars, parts, comments) in parse_properties(core):
68
+ if comments[0] in ['Me', 'Mn', 'Mc', 'Cf', 'Zl', 'Zp']:
69
+ null.extend(chars)
70
+ for (chars, parts, comments) in parse_properties(asian):
71
+ if parts[1] in ['F', 'W'] and not comments[0] in ['Mn', 'Mc']:
72
+ wide.extend(chars)
73
+
74
+ return WcWidthResult(null = compress(null),
75
+ wide = compress(wide))
76
+
77
+ def parse_properties_xid(core):
57
78
  id_start = []
58
79
  id_continue = []
59
80
 
60
- lines = iter(text.splitlines())
61
- version = next(lines).strip("\n\r \t#") + ' -- ' + next(lines).strip("\n\r \t#")
81
+ for (chars, parts, comments) in parse_properties(core):
82
+ if parts[1] == 'ID_Start':
83
+ id_start.extend(chars)
84
+ elif parts[1] == 'ID_Continue':
85
+ id_continue.extend(chars)
62
86
 
63
- for line in lines:
87
+ return XidResult(id_start = compress(id_start),
88
+ id_continue = compress(id_continue))
89
+
90
+ def parse_properties(text):
91
+ for line in text.splitlines():
64
92
  line = line.strip()
65
93
 
66
94
  if not line or line[0] == '#':
@@ -69,29 +97,61 @@ def parse_properties_xid(text):
69
97
  parts = [part.strip() for part in re.split('[;#]', line)]
70
98
  if len(parts) < 3:
71
99
  continue
100
+ comments = parts[2].split(' ')
72
101
 
73
102
  if '..' in parts[0]:
74
103
  start, end = parts[0].split('..')
75
104
  else:
76
105
  start, end = parts[0], parts[0]
77
106
  start, end = int(start, 16), int(end, 16)
107
+ chars = list(range(start, end + 1))
78
108
 
79
- if parts[1] == 'ID_Start':
80
- id_start.append((start, end + 1))
81
- elif parts[1] == 'ID_Continue':
82
- id_continue.append((start, end + 1))
109
+ yield (chars, parts, comments)
110
+
111
+ def compress(chars):
112
+ ranges = []
113
+
114
+ if chars:
115
+ chars = sorted(set(chars))
116
+ iterator = iter(chars)
83
117
 
84
- return XidResult(version = version, id_start = id_start, id_continue = id_continue)
118
+ prev = next(iterator)
119
+ start = prev
85
120
 
86
- def write_xid_header(xid, f):
121
+ for c in iterator:
122
+ if c != prev + 1:
123
+ ranges.append((start, prev + 1))
124
+ start = c
125
+ prev = c
126
+
127
+ end = chars[-1] + 1
128
+ ranges.append((start, end))
129
+
130
+ return ranges
131
+
132
+ def write_header(version, wcwidth, xid, f):
87
133
  f.write(f"""{LICENSE_HEADER}
88
134
 
89
- // This file is autogenerated by generator.py
90
- // Version: {xid.version}
135
+ // This file is autogenerated by unicode_gen.py
136
+ // Version: {version}
91
137
 
92
138
  namespace RG {{
93
139
 
94
- static const int32_t XidStartTable[] = {{""")
140
+ static const int32_t WcWidthNull[] = {{""")
141
+ for i, v in enumerate(wcwidth.null):
142
+ if i % 5 == 0: f.write('\n ')
143
+ f.write(f' 0x{v[0]:05X}, 0x{v[1]:05X}{"," if i + 1 < len(wcwidth.null) else ""}')
144
+ f.write("""
145
+ };
146
+
147
+ static const int32_t WcWidthWide[] = {""")
148
+ for i, v in enumerate(wcwidth.wide):
149
+ if i % 5 == 0: f.write('\n ')
150
+ f.write(f' 0x{v[0]:05X}, 0x{v[1]:05X}{"," if i + 1 < len(wcwidth.wide) else ""}')
151
+ f.write("""
152
+ };
153
+
154
+ static const int32_t XidStartTable[] = {""")
95
155
  for i, v in enumerate(xid.id_start):
96
156
  if i % 5 == 0: f.write('\n ')
97
157
  f.write(f' 0x{v[0]:05X}, 0x{v[1]:05X}{"," if i + 1 < len(xid.id_start) else ""}')
@@ -116,9 +176,14 @@ if __name__ == "__main__":
116
176
 
117
177
  url = args.url.strip('/') + '/ucd/'
118
178
 
119
- # XID
120
179
  with urllib.request.urlopen(url + 'DerivedCoreProperties.txt') as f:
121
- text = f.read().decode('UTF-8')
122
- xid = parse_properties_xid(text)
123
- with open(os.path.join(args.output_dir, 'xid.inc'), 'w') as f:
124
- write_xid_header(xid, f)
180
+ core = f.read().decode('UTF-8')
181
+ with urllib.request.urlopen(url + 'EastAsianWidth.txt') as f:
182
+ asian = f.read().decode('UTF-8')
183
+
184
+ version = parse_version(core)
185
+ wcwidth = parse_properties_wcwidth(core, asian)
186
+ xid = parse_properties_xid(core)
187
+
188
+ with open(os.path.join(args.output_dir, 'unicode.inc'), 'w') as f:
189
+ write_header(version, wcwidth, xid, f)
@@ -77,7 +77,6 @@ set(KOFFI_SRC
77
77
  src/util.cc
78
78
  src/win32.cc
79
79
  ../../src/core/base/base.cc
80
- ../../src/core/unicode/xid.cc
81
80
  )
82
81
  if(CMAKE_SIZEOF_VOID_P EQUAL 8)
83
82
  # CMAKE_SYSTEM_PROCESSOR is wrong on Windows ARM64
@@ -20,7 +20,6 @@
20
20
  // OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  #include "src/core/base/base.hh"
23
- #include "src/core/unicode/xid.hh"
24
23
  #include "ffi.hh"
25
24
  #include "call.hh"
26
25
  #include "parser.hh"
@@ -20,7 +20,6 @@
20
20
  // OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
22
  #include "src/core/base/base.hh"
23
- #include "src/core/unicode/xid.hh"
24
23
  #include "ffi.hh"
25
24
  #include "parser.hh"
26
25
 
@@ -1,52 +0,0 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
-
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
-
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
-
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- #include "src/core/base/base.hh"
23
- #include "xid.inc"
24
-
25
- namespace RG {
26
-
27
- static bool TestUnicodeTable(Span<const int32_t> table, int32_t uc)
28
- {
29
- RG_ASSERT(table.len > 0);
30
- RG_ASSERT(table.len % 2 == 0);
31
-
32
- auto it = std::upper_bound(table.begin(), table.end(), uc,
33
- [](int32_t uc, int32_t x) { return uc < x; });
34
- Size idx = it - table.ptr;
35
-
36
- // Each pair of value in table represents a valid interval
37
- return idx & 0x1;
38
- }
39
-
40
- bool IsXidStart(int32_t uc)
41
- {
42
- bool match = IsAsciiAlpha(uc) || uc == '_' || TestUnicodeTable(XidStartTable, uc);
43
- return match;
44
- }
45
-
46
- bool IsXidContinue(int32_t uc)
47
- {
48
- bool match = IsAsciiAlphaOrDigit(uc) || uc == '_' || TestUnicodeTable(XidContinueTable, uc);
49
- return match;
50
- }
51
-
52
- }
@@ -1,29 +0,0 @@
1
- // Copyright (C) 2025 Niels Martignène <niels.martignene@protonmail.com>
2
-
3
- // Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- // this software and associated documentation files (the “Software”), to deal in
5
- // the Software without restriction, including without limitation the rights to use,
6
- // copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
7
- // Software, and to permit persons to whom the Software is furnished to do so,
8
- // subject to the following conditions:
9
-
10
- // The above copyright notice and this permission notice shall be included in all
11
- // copies or substantial portions of the Software.
12
-
13
- // THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
14
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- // OTHER DEALINGS IN THE SOFTWARE.
21
-
22
- #include "src/core/base/base.hh"
23
-
24
- namespace RG {
25
-
26
- bool IsXidStart(int32_t uc);
27
- bool IsXidContinue(int32_t uc);
28
-
29
- }