From 40ea53a3e55ffe414912620484d0bea73af527ef Mon Sep 17 00:00:00 2001 From: Helmut Eller Date: Tue, 16 Jul 2024 09:54:59 +0200 Subject: [PATCH 1/3] Add a igc--set-commit-limit function * src/igc (Figc__set_commit_limit): New. (mps_res_to_string): New helper. (syms_of_igc): Register it. * test/src/igc-tests.el (set-commit-limit-test): New. --- src/igc.c | 35 +++++++++++++++++++++++++++++++++++ test/src/igc-tests.el | 15 +++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/igc.c b/src/igc.c index a74e62589a2..e29257650a8 100644 --- a/src/igc.c +++ b/src/igc.c @@ -4316,6 +4316,40 @@ igc_external_header (struct igc_header *h) return header_exthdr (h); } +static const char * +mps_res_to_string (mps_res_t res) +{ + switch (res) + { +#define RES_CASE(prefix, id, doc) \ + case prefix##id: \ + return #prefix #id " " doc; + _mps_RES_ENUM (RES_CASE, MPS_RES_); +#undef RES_CASE + default: + return NULL; + } +} + +DEFUN ("igc--set-commit-limit", Figc__set_commit_limit, + Sigc__set_commit_limit, 1, 1, 0, doc + : /* Set the arena commit limit to LIMIT. +LIMIT can be an integer (number of bytes) or nil (no limit). */) +(Lisp_Object limit) +{ + size_t nbytes + = NILP (limit) ? ~0 : check_uinteger_max (limit, SIZE_MAX - 1); + mps_res_t err = mps_arena_commit_limit_set (global_igc->arena, nbytes); + if (err != MPS_RES_OK) + { + const char *msg = mps_res_to_string (err); + xsignal3 (Qerror, + intern_c_string (Sigc__set_commit_limit.s.symbol_name), + make_fixnum (err), msg ? build_string (msg) : Qnil); + } + return Qnil; +} + static void make_arena (struct igc *gc) { @@ -4853,6 +4887,7 @@ syms_of_igc (void) defsubr (&Sigc_info); defsubr (&Sigc__roots); defsubr (&Sigc__collect); + defsubr (&Sigc__set_commit_limit); defsubr (&Sigc__add_extra_dependency); defsubr (&Sigc__remove_extra_dependency); DEFSYM (Qambig, "ambig"); diff --git a/test/src/igc-tests.el b/test/src/igc-tests.el index e69de29bb2d..59a0cb83909 100644 --- a/test/src/igc-tests.el +++ b/test/src/igc-tests.el @@ -0,0 +1,15 @@ +;;; igc-tests.el --- tests for src/igc.c -*- lexical-binding: t -*- + +(require 'ert) + +(ert-deftest set-commit-limit-test () + (should (equal (igc--set-commit-limit (ash 1 30)) nil)) + (should (equal (assoc-string "commit-limit" (igc-info)) + '("commit-limit" 1 1073741824 0))) + (should-error (igc--set-commit-limit -1) + :type 'args-out-of-range) + (should-error (igc--set-commit-limit (- (ash 1 64) 1)) + :type 'args-out-of-range) + (should (equal (igc--set-commit-limit nil) nil)) + (should (equal (assoc-string "commit-limit" (igc-info)) + '("commit-limit" 1 -1 0)))) -- 2.39.2