From d86d4532b522ccefa6f720655834f1041a3369cf Mon Sep 17 00:00:00 2001 From: Ash Vardanian <1983160+ashvardanian@users.noreply.github.com> Date: Thu, 18 Jan 2024 22:55:58 +0000 Subject: [PATCH] Fix: JS compilation and missing symbols --- CONTRIBUTING.md | 6 ++++++ binding.gyp | 8 +++++++- include/stringzilla/stringzilla.h | 2 +- javascript/lib.c | 7 ++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2f828474..316956bf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -188,6 +188,12 @@ Before you ship, please make sure the packaging works. cibuildwheel --platform linux ``` +## Contributing in JavaScript + +```bash +npm ci && npm test +``` + ## Roadmap The project is in its early stages of development. diff --git a/binding.gyp b/binding.gyp index 746b4a80..572036b6 100644 --- a/binding.gyp +++ b/binding.gyp @@ -4,7 +4,13 @@ "target_name": "stringzilla", "sources": ["javascript/lib.c"], "include_dirs": ["include"], - "cflags": ["-std=c99", "-Wno-unknown-pragmas", "-Wno-maybe-uninitialized"], + "cflags": [ + "-std=c99", + "-Wno-unknown-pragmas", + "-Wno-maybe-uninitialized", + "-Wno-cast-function-type", + "-Wno-unused-function", + ], } ] } diff --git a/include/stringzilla/stringzilla.h b/include/stringzilla/stringzilla.h index 4ace725d..0b46dea8 100644 --- a/include/stringzilla/stringzilla.h +++ b/include/stringzilla/stringzilla.h @@ -219,7 +219,7 @@ * Debugging and testing. */ #ifndef SZ_DEBUG -#ifndef NDEBUG +#ifndef NDEBUG // This means "Not using DEBUG information". #define SZ_DEBUG 1 #else #define SZ_DEBUG 0 diff --git a/javascript/lib.c b/javascript/lib.c index 18623c9c..c468c8f8 100644 --- a/javascript/lib.c +++ b/javascript/lib.c @@ -7,9 +7,11 @@ * @copyright Copyright (c) 2023 * @see NodeJS docs: https://nodejs.org/api/n-api.html */ +#include // `printf` for debug builds +#include // `malloc` to export strings into UTF-8 + +#include // `napi_*` functions -#include // `napi_*` functions -#include // `malloc` #include // `sz_*` functions napi_value indexOfAPI(napi_env env, napi_callback_info info) { @@ -74,7 +76,6 @@ napi_value countAPI(napi_env env, napi_callback_info info) { size_t count = 0; if (needle.length == 0 || haystack.length == 0 || haystack.length < needle.length) { count = 0; } - else if (needle.length == 1) { count = sz_count_char(haystack.start, haystack.length, needle.start); } else if (overlap) { while (haystack.length) { sz_cptr_t ptr = sz_find(haystack.start, haystack.length, needle.start, needle.length);