From 9c0e9a7828b694569637015ab13b138b5aede09a Mon Sep 17 00:00:00 2001 From: sashimacs <130169373+sashimacs@users.noreply.github.com> Date: Thu, 4 May 2023 13:31:55 -0400 Subject: [PATCH 1/3] Cross-platform support in native module. --- CMakeLists.txt | 2 +- hotfuzz-module.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 376e5db..bbd5541 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,7 +25,7 @@ find_package(Threads REQUIRED) add_library(hotfuzz-module MODULE hotfuzz-module.c) set_target_properties(hotfuzz-module PROPERTIES - C_STANDARD 99 + C_STANDARD 11 POSITION_INDEPENDENT_CODE ON PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}) diff --git a/hotfuzz-module.c b/hotfuzz-module.c index a8c8b1e..99a5efb 100644 --- a/hotfuzz-module.c +++ b/hotfuzz-module.c @@ -10,7 +10,7 @@ #include #include #include -#include +#include #define MIN(a, b) ({ __typeof__(a) _a = (a), _b = (b); _a < _b ? _a : _b; }) #define MAX(a, b) ({ __typeof__(a) _a = (a), _b = (b); _a > _b ? _a : _b; }) @@ -369,7 +369,7 @@ int emacs_module_init(struct emacs_runtime *rt) { return 2; static struct Data data; - data.max_workers = get_nprocs(); + data.max_workers = sysconf(_SC_NPROCESSORS_ONLN); if (!(data.workers = malloc(data.max_workers * sizeof *data.workers))) return 1; From e0bfd2bb6264481ba0f5481408e8c9d51e61d930 Mon Sep 17 00:00:00 2001 From: sashimacs <130169373+sashimacs@users.noreply.github.com> Date: Thu, 4 May 2023 13:32:07 -0400 Subject: [PATCH 2/3] Workaround support function for consult-multi issues with module. --- hotfuzz.el | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/hotfuzz.el b/hotfuzz.el index 900d6b5..cd02602 100644 --- a/hotfuzz.el +++ b/hotfuzz.el @@ -138,6 +138,53 @@ HAYSTACK has to be a match according to `hotfuzz-filter'." (add-face-text-property i (1+ i) 'completions-common-part nil haystack)))) haystack) +(defmacro hotfuzz--dash-each (list &rest body) + "Evaluate BODY for each element of LIST and return nil. +Each element of LIST in turn is bound to `it' and its index +within LIST to `it-index' before evaluating BODY. +This is the anaphoric counterpart to `-each'." + (let ((l (make-symbol "list")) + (i (make-symbol "i"))) + `(let ((,l ,list) + (,i 0)) + (while ,l + (let ((it (pop ,l)) (it-index ,i)) + (ignore it it-index) + ,@body) + (setq ,i (1+ ,i)))))) + +(defmacro hotfuzz--dash-keep (form list) + "Eval FORM for each item in LIST and return the non-nil results. +Like `--filter', but returns the non-nil results of FORM instead +of the corresponding elements of LIST. Each element of LIST in +turn is bound to `it' and its index within LIST to `it-index' +before evaluating FORM. +This is the anaphoric counterpart to `-keep'." + (let ((r (make-symbol "result")) + (m (make-symbol "mapped"))) + `(let (,r) + (hotfuzz--dash-each ,list (let ((,m ,form)) (when ,m (push ,m ,r)))) + (nreverse ,r)))) + +(defun hotfuzz--fix-tofu-chars (orig-fun string candidates &optional ignore-case) + "Workaround tofu chars (in e.g. consult) for native module filtering." + (let* + ((table (make-hash-table :test #'eq :size (length candidates))) + (cands + (hotfuzz--dash-keep + (when (stringp it) + (let ((encoded (encode-coding-string it 'no-conversion 'nocopy))) + (setf (gethash encoded table) it) + (and (< (length encoded) hotfuzz--max-haystack-len) encoded))) + candidates)) + (raw-str (encode-coding-string string 'no-conversion 'nocopy)) + (ans + (let + ((gc-cons-threshold most-positive-fixnum) + (gc-cons-percentage 1.0)) + (funcall orig-fun raw-str cands ignore-case)))) + (hotfuzz--dash-keep (gethash it table) ans))) + ;;;###autoload (defun hotfuzz-filter (string candidates) "Filter CANDIDATES that match STRING and sort by the match costs. From eed712a40b1720c2cf2204ab53a78b7a77397f97 Mon Sep 17 00:00:00 2001 From: sashimacs <130169373+sashimacs@users.noreply.github.com> Date: Thu, 4 May 2023 14:09:05 -0400 Subject: [PATCH 3/3] Credit dash.el for helper functions. --- hotfuzz.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hotfuzz.el b/hotfuzz.el index cd02602..d92ff47 100644 --- a/hotfuzz.el +++ b/hotfuzz.el @@ -142,7 +142,9 @@ HAYSTACK has to be a match according to `hotfuzz-filter'." "Evaluate BODY for each element of LIST and return nil. Each element of LIST in turn is bound to `it' and its index within LIST to `it-index' before evaluating BODY. -This is the anaphoric counterpart to `-each'." +This is the anaphoric counterpart to `-each'. + +Shamelessly lifted from dash: https://github.com/magnars/dash.el" (let ((l (make-symbol "list")) (i (make-symbol "i"))) `(let ((,l ,list) @@ -159,7 +161,9 @@ Like `--filter', but returns the non-nil results of FORM instead of the corresponding elements of LIST. Each element of LIST in turn is bound to `it' and its index within LIST to `it-index' before evaluating FORM. -This is the anaphoric counterpart to `-keep'." +This is the anaphoric counterpart to `-keep'. + +Shamelessly lifted from dash: https://github.com/magnars/dash.el" (let ((r (make-symbol "result")) (m (make-symbol "mapped"))) `(let (,r)