emnapi 0.31.0

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 (44) hide show
  1. package/CMakeLists.txt +160 -0
  2. package/LICENSE +21 -0
  3. package/README.md +875 -0
  4. package/cmake/wasm32.cmake +32 -0
  5. package/dist/library_napi.js +4784 -0
  6. package/include/common.h +26 -0
  7. package/include/emnapi.h +81 -0
  8. package/include/js_native_api.h +560 -0
  9. package/include/js_native_api_types.h +159 -0
  10. package/include/napi-inl.deprecated.h +186 -0
  11. package/include/napi-inl.h +6299 -0
  12. package/include/napi.h +3127 -0
  13. package/include/node_api.h +226 -0
  14. package/include/node_api_types.h +56 -0
  15. package/include/uv/threadpool.h +41 -0
  16. package/include/uv/unix.h +21 -0
  17. package/include/uv.h +134 -0
  18. package/index.d.ts +4 -0
  19. package/index.js +22 -0
  20. package/lib/wasm32/libdlmalloc.a +0 -0
  21. package/lib/wasm32/libemmalloc.a +0 -0
  22. package/lib/wasm32/libemnapi.a +0 -0
  23. package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
  24. package/lib/wasm32-emscripten/libemnapi.a +0 -0
  25. package/lib/wasm32-emscripten.txt +5 -0
  26. package/lib/wasm32-wasi/libemnapi.a +0 -0
  27. package/lib/wasm32-wasi.txt +4 -0
  28. package/lib/wasm32.txt +4 -0
  29. package/package.json +43 -0
  30. package/src/emnapi.c +1344 -0
  31. package/src/malloc/dlmalloc/dlmalloc.c +92 -0
  32. package/src/malloc/dlmalloc/malloc.c +6395 -0
  33. package/src/malloc/emmalloc/emmalloc.c +1551 -0
  34. package/src/malloc/memcpy.c +136 -0
  35. package/src/malloc/memset.c +98 -0
  36. package/src/malloc/sbrk.c +29 -0
  37. package/src/uv/queue.h +108 -0
  38. package/src/uv/threadpool.c +408 -0
  39. package/src/uv/unix/async.c +206 -0
  40. package/src/uv/unix/core.c +35 -0
  41. package/src/uv/unix/loop.c +36 -0
  42. package/src/uv/unix/thread.c +118 -0
  43. package/src/uv/uv-common.c +51 -0
  44. package/src/uv/uv-common.h +68 -0
@@ -0,0 +1,92 @@
1
+ // This file is a wrapper around malloc.c, which is the upstream source file.
2
+ // It sets configuration flags and controls which symbols are exported.
3
+
4
+ #include <stddef.h>
5
+
6
+ // Define configuration macros for dlmalloc.
7
+
8
+ // WebAssembly doesn't have mmap-style memory allocation.
9
+ #define HAVE_MMAP 0
10
+
11
+ // WebAssembly doesn't support shrinking linear memory.
12
+ #define MORECORE_CANNOT_TRIM 1
13
+
14
+ // Disable sanity checks to reduce code size.
15
+ #define ABORT __builtin_unreachable()
16
+
17
+ // If threads are enabled, enable support for threads.
18
+ #ifdef _REENTRANT
19
+ #define USE_LOCKS 1
20
+ #endif
21
+
22
+ // Make malloc deterministic.
23
+ #define LACKS_TIME_H 1
24
+
25
+ // Disable malloc statistics generation to reduce code size.
26
+ #define NO_MALLINFO 1
27
+ #define NO_MALLOC_STATS 1
28
+
29
+ // Align malloc regions to 16, to avoid unaligned SIMD accesses.
30
+ #define MALLOC_ALIGNMENT 16
31
+
32
+ // Declare errno values used by dlmalloc. We define them like this to avoid
33
+ // putting specific errno values in the ABI.
34
+ extern const int __ENOMEM;
35
+ #define ENOMEM __ENOMEM
36
+ extern const int __EINVAL;
37
+ #define EINVAL __EINVAL
38
+
39
+ // Define USE_DL_PREFIX so that we leave dlmalloc's names prefixed with 'dl'.
40
+ // We define them as "static", and we wrap them with public names below. This
41
+ // serves two purposes:
42
+ //
43
+ // One is to make it easy to control which symbols are exported; dlmalloc
44
+ // defines several non-standard functions and we wish to explicitly control
45
+ // which functions are part of our public-facing interface.
46
+ //
47
+ // The other is to protect against compilers optimizing based on the assumption
48
+ // that they know what functions with names like "malloc" do. Code in the
49
+ // implementation will call functions like "dlmalloc" and assume it can use
50
+ // the resulting pointers to access the metadata outside of the nominally
51
+ // allocated objects. However, if the function were named "malloc", compilers
52
+ // might see code like that and assume it has undefined behavior and can be
53
+ // optimized away. By using "dlmalloc" in the implementation, we don't need
54
+ // -fno-builtin to avoid this problem.
55
+ #define USE_DL_PREFIX 1
56
+ #define DLMALLOC_EXPORT static inline
57
+
58
+ // This isn't declared with DLMALLOC_EXPORT so make it static explicitly.
59
+ static size_t dlmalloc_usable_size(void*);
60
+
61
+ // Include the upstream dlmalloc's malloc.c.
62
+ #include "malloc.c"
63
+
64
+ // Export the public names.
65
+
66
+ void *malloc(size_t size) {
67
+ return dlmalloc(size);
68
+ }
69
+
70
+ void free(void *ptr) {
71
+ dlfree(ptr);
72
+ }
73
+
74
+ void *calloc(size_t nmemb, size_t size) {
75
+ return dlcalloc(nmemb, size);
76
+ }
77
+
78
+ void *realloc(void *ptr, size_t size) {
79
+ return dlrealloc(ptr, size);
80
+ }
81
+
82
+ int posix_memalign(void **memptr, size_t alignment, size_t size) {
83
+ return dlposix_memalign(memptr, alignment, size);
84
+ }
85
+
86
+ void* aligned_alloc(size_t alignment, size_t bytes) {
87
+ return dlmemalign(alignment, bytes);
88
+ }
89
+
90
+ size_t malloc_usable_size(void *ptr) {
91
+ return dlmalloc_usable_size(ptr);
92
+ }