From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id f9e6276e for ; Thu, 9 Jan 2020 13:16:48 +0000 (UTC) Received: (qmail 17885 invoked by alias); 9 Jan 2020 13:16:42 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45271 Received: (qmail 18109 invoked by uid 1010); 9 Jan 2020 13:16:42 -0000 X-Qmail-Scanner-Diagnostics: from out5-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25684. spamassassin: 3.4.2. Clear:RC:0(66.111.4.29):SA:0(-2.6/5.0):. Processed in 4.81119 secs); 09 Jan 2020 13:16:42 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvdeiuddgvdejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggugfgjfgesth ektddttderudenucfhrhhomhepffgrnhhivghlucfuhhgrhhgrfhcuoegurdhssegurghn ihgvlhdrshhhrghhrghfrdhnrghmvgeqnecukfhppeejledrudektddrheejrdduudelne curfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhn rghmvgenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Date: Thu, 9 Jan 2020 13:15:53 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: Re: [PATCH] find RLIM_NLIMITS correctly on Cygwin Message-ID: <20200109131553.hqetnd45sc43z6xb@tarpaulin.shahaf.local2> References: <82F8CDE0-C95C-4D31-ABFC-EBB3C97799F3@kba.biglobe.ne.jp> <1B509B1C-A670-482F-9D88-2145E15D03A1@kba.biglobe.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1B509B1C-A670-482F-9D88-2145E15D03A1@kba.biglobe.ne.jp> User-Agent: NeoMutt/20170113 (1.7.2) Jun T wrote on Thu, Jan 09, 2020 at 19:32:17 +0900: > > > 2020/01/09 6:33, Daniel Shahaf wrote: > > > > I don't object to the patch, but we should think about actually using > > a C preprocessor to parse header files, otherwise we'd just be playing > > whack-a-mole as OS's use more features of C syntax in their header files. > > Yes, but ... > > When rlimits.awk finds an unknown macro RLIMIT_???, for example > > #define RLIMIT_FOO 8 > > then it sets recs[8]="FOO", and this enables the limit builtin to print > the resource name as "FOO". *If* we need this feature, it would not be > easy to achieve by using C preprocessor alone. Yeah, the C preprocessor can't discover RLIMIT_* macros we don't know about in advance, I agree. For that we'd need awk(1) or similar (maybe just «grep -o 'RLIMIT_[^ ]*'»). Maybe something along these lines: [[[ static const struct { const char *symbol; const char *name; int type; int value; } rlimits[] = { #ifdef RLIMIT_CPU { "CPU", "cputime", ZLIMTYPE_TIME, RLIMIT_CPU }, #endif #ifdef RLIMIT_DATA { "DATA", "datasize", ZLIMTYPE_MEMORY, RLIMIT_DATA }, #endif #include "unknown-limits.h" { NULL } }; ]]] where unknown-limits.h is generated (by awk(1)) as: [[[ #ifdef RLIMIT_FOO { "FOO", "FOO", ZLIMTYPE_UNKNOWN, RLIMIT_FOO }, #endif #ifdef RLIMIT_BAR { "BAR", "BAR", ZLIMTYPE_UNKNOWN, RLIMIT_BAR }, #endif ]]] All limits we know about will be in the first file; any limits we don't know about will be in the second file This way the numerical calculations would be done by the preprocessor, and we'd not be assuming that the integer values of RLIMIT_* macros are sequential and start from zero. (Though apparently that assumption happens to be true on current OS's) Cheers, Daniel