From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?Miguel_=C3=81ngel_Arruga_Vivas?= Newsgroups: gmane.lisp.guile.devel Subject: [WIP: PATCH 0/2] memory leak + uselocale Date: Tue, 13 Oct 2020 21:11:59 +0200 Message-ID: <87h7qy0wlc.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15913"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Tue Oct 13 21:13:41 2020 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kSPjx-00041J-AJ for guile-devel@m.gmane-mx.org; Tue, 13 Oct 2020 21:13:41 +0200 Original-Received: from localhost ([::1]:49414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kSPjw-0000qF-6s for guile-devel@m.gmane-mx.org; Tue, 13 Oct 2020 15:13:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kSPjM-0000nh-Kp for guile-devel@gnu.org; Tue, 13 Oct 2020 15:13:04 -0400 Original-Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:53047) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kSPjK-0006fd-OT for guile-devel@gnu.org; Tue, 13 Oct 2020 15:13:04 -0400 Original-Received: by mail-wm1-x341.google.com with SMTP id e23so741070wme.2 for ; Tue, 13 Oct 2020 12:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:user-agent:mime-version; bh=VqckMotcWYgvfyIjwDcdzum2r8pwIoXLGnZB1QHU5Zk=; b=tpn/foxSmTpnxKyBmQrmyCUfpC0EKV6YcZPa4If4LeBjOZPqRFl0HkR3t0sZlt9meq wB121trCFGC1QLkLES1PkqfAihTwjZVaK915q7HnH4SIpeSW8iuudnBVZP3EZzznPPD9 dcWJgi8iuH/eIKAVTMKr6rMcdjoXYlhcsI1UuJlJomMZzLNImCrKkalDpahhqXv6zolW KAKOtBKl4iIcVJDMMokxxfvGZwxG6QrohFR6OsqkTx2jR956FTpd2YARWJKe71z8wsXE 8JsqU8EpdzL/wFGwViPInsT6KgzRi8o/pi6+3bJQh8oM1C3CXLuAhqa4wY2hj9c7ID4w 6mpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=VqckMotcWYgvfyIjwDcdzum2r8pwIoXLGnZB1QHU5Zk=; b=mkXATpbMmdc0dFAfEk6NybXE9EhWEawdUjPhVQr5XbydxvbWHSRr+BIxL5uF30LcxY ka/Agrq98rubpLiStuxWaosAM2zBu9WpeIG1p1KecGLe+VOHAkA0X0iAhk435raV8ZLn X2zl+ofvHeCnRoZVORtHluOEStyn8mVs6CqaC9eS/QOOPEu3qBC2sXHmNsIbnDO4ezAn DZVaA7lQUHpewc5BuhwkDtgCwgU0xrBBIS6YC4g5U+mkSwehVyGu92OlL8gvsSSJvfER yW6h8S6sWr4oZg4w1hNeyJMYt9Gfopycp8VmM2ME1vIh/DDxT8DZFjs2e18xb/2QJYpA 1f9w== X-Gm-Message-State: AOAM531wCVePmm3LeCdeTxdtN+OgKYijlKj22vlBcWaObHCi/86Q0slV u7GmYRIHtr+BFrWtcBu1Efui7TxgmH+q5g== X-Google-Smtp-Source: ABdhPJwEB+A5u1AqZHztc+mJgm7aRjpcnG94Roo7T/emSnPz1ixxyWuD8LJYVA7RC197tA9M0uXRLA== X-Received: by 2002:a05:600c:4147:: with SMTP id h7mr1199575wmm.45.1602616380280; Tue, 13 Oct 2020 12:13:00 -0700 (PDT) Original-Received: from unfall (218.139.134.37.dynamic.jazztel.es. [37.134.139.218]) by smtp.gmail.com with ESMTPSA id i9sm712244wma.47.2020.10.13.12.12.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 12:12:59 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::341; envelope-from=rosen644835@gmail.com; helo=mail-wm1-x341.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20592 Archived-At: --=-=-= Content-Type: text/plain Hi, everybody, I've been looking into giving some updates to certain interfaces that may be useful and uselocale was one of the first I thought---not the first, but the first for which I send a patch. Currently, i18n.c reads: /* XXX: We don't define it as `LC_GLOBAL_LOCALE' because of bugs as of glibc <= 2.11 not (yet) worked around by Gnulib. See http://sourceware.org/bugzilla/show_bug.cgi?id=11009 for details. */ I've checked the bug, and I think that the current behaviour of libc is completely compliant with POSIX. The only two positive mentions to LC_GLOBAL_LOCALE I've found are in uselocale[1] and duplocale[2] specifications, and the third explicitly says that it is undefined behaviour to provide it to newlocale[3] or freelocale[4]. I consider that they provide a complete framework for the use of this special object. In addition, exposing that kind of interface to the Scheme world seems quite forced, from my point of view. I propose an interface for uselocale that deduplicates the information from the unique return value, that is mandatory in the cold cold C world, to *two* values: first a boolean, that indicates if there is/was a thread-specific locale installed, and the locale in use before the call as the second value. If it's called without parameters just returns the value, while the following call: (uselocale #f) Is equivalent to the cryptic: setlocale (LC_GLOBAL_LOCALE); The usual interface: (uselocale anything-not-false) Provides a locale object that will be installed in the current locale, or fails if the type is not the adecuate or other system reason, of course. The returned value is always a smob that must enter the GC world, so the call to duplocale is needed anyway. Nonetheless, one of the main use cases would be the guarded execution idiom, so I also expose an interface called 'with-thread-locale'. The current implementation is in C with dynamic-wind underneath and a simple macro over it, but the documentation contains a possible implementation in Scheme too. It's only implemented it under USE_GNU_LOCALE_API and needs more work to be completely ready, as probably the function should be moved to the posix module (?), but the code it's working---as always, on my machine. And as a secondary ramification, looking into the other condition (when USE_GNU_LOCALE_API is not defined) I found something that seems to be a memory leak, but I don't know where to test it---I don't know which systems don't define it, nothing I have running right now at least. The order of the patches is the inverse of the mail, as I wrote the first before finishing the second, sorry if that causes any confusion. What do you think? Any ideas or points I may have missed? Suggestions? Happy hacking! Miguel -- [1] https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/uselocale.html [2] https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/duplocale.html [3] https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/newlocale.html [4] https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/functions/freelocale.html --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGyBAEBCgAdFiEEiIeExBRZrMuD5+hMY0xuiXn6vsIFAl+F/AAACgkQY0xuiXn6 vsLszAv2PS4v84AvZGFln69uEB+pBv830cYZrV3O8m/4w0Q9QxBn6TTi3d66zB4T oBWIFCFz7G3f6dKEnHkWvprMTbjcisejjng6PoRsbS2kZXE1A8cJyEv1Q1GZyHI6 oc8FqsBhOrSHO+sF5ZJqPszE1f6bgbrr+d4bo46m9QDvNzQEO7MiDQ7AHhtr34/4 s0+X9HRF95PV2E7IuxBQUWadXCTg3LJSFv7uBgBfE/zObChyni9jA+WqVG6p3p3L l9syOYBy1qbUNp1Yxy2s95UTin6o72mXiH/l98fTNERa44SJpNArCk3tq4E1m54w 8kIEyJf+dtuIrj7ocF2NrAcDShkybua4ZritrMQ6G2bEwYmIIdzf2B5oTHcWquAq VzNYPeAJdqzq+yASW5ppI44cGklPgudk/p1TDvIk4KyhbO8ldV7JYe84W3TA4a2a v9fvT851wX2QpcKZ77JbFLoP7fIj8A/uTH93rC6vB9jvj485UCUZ345X8WNt1Cpt jRM/wBE= =cD1g -----END PGP SIGNATURE----- --=-=-=--