Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119337 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 14028 invoked from network); 18 Jan 2023 21:19:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jan 2023 21:19:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0551E18054E for ; Wed, 18 Jan 2023 13:19:53 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 18 Jan 2023 13:19:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1674076791; bh=arzP8d2XClEiAAEa/k9xO/NqJ3C1lkrR5yUweOnT8dM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=mLA5o6yu6CetNbLeANYkAJWocubG3ydfnpZ6onhBmhb+s/C+DFWAjDBWKuZ4cSThX WGvWTpM2TO1nbWlHOCmdZqMI9Jlb11wgJEp35eM7sIvT9ZxOF0wXHs64OC2i2+99vN 2/zZX+wyxmq6YqiD2UBI9sH2MY2Ofr9yVWf5DYQsMKprF6qaVGRAqVvENat4TCOYUX 72+8E6kZFM65JMKY+5/k+9ZTJGVDqf+JimzT6B91zr9uXNwqmFu8NxsUvhjD8t/J2/ Q63nnueP/6eGqv6dueSq2dchPIPL85agNKk5eLyGltV5ibLVZXDSDyEd8Wwj1w0Dqf naZBlKorQ44rA== Message-ID: Date: Wed, 18 Jan 2023 22:19:50 +0100 MIME-Version: 1.0 Content-Language: en-US To: =?UTF-8?Q?Fl=c3=a1vio_Heleno?= Cc: internals@lists.php.net References: <8DA390C5-5E67-4847-A89F-1A8CCC6C5389@gmail.com> <419f4c45-8171-1051-8956-175283fb6669@bastelstu.be> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC: rules for #include directives From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 1/18/23 21:37, Flávio Heleno wrote: > This may be a silly question, but in that case, wouldn't #ifdef guards keep > the compiler from including/parsing a.h twice? It's complicated. Modern compilers may include an optimization for include guards (https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html), but those rules may only be applied fairly narrowly. I just recompiled gammasection.c in ext/random [1] which is a fairly simple file containing just a handful of files and traced the compiler with 'strace' for the 'openat' syscalls: In total 2488 openat syscalls (many of them resulting in ENOENT, because of multiple include paths) were performed by the compiler. Multiple of my system headers were opened several times, because the include guard optimization could not be applied to them. I'm also seeing duplicated PHP headers: > 20 "/usr/lib/gcc/x86_64-linux-gnu/9/include/stddef.h", > 13 "/usr/include/x86_64-linux-gnu/bits/mathcalls-narrow.h", > 11 "/usr/include/x86_64-linux-gnu/bits/wordsize.h", > 8 "/usr/include/x86_64-linux-gnu/bits/mathcalls.h", > 6 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h", > 5 "/usr/lib/gcc/x86_64-linux-gnu/9/include/limits.h", > 4 "/usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h", > 3 "/usr/include/assert.h", > 3 "./php-src/Zend/zend_hash.h", > 3 "./php-src/Zend/zend.h", > 2 "/usr/lib/gcc/x86_64-linux-gnu/9/include/stdarg.h", > 2 "/usr/lib/gcc/x86_64-linux-gnu/9/include/mm_malloc.h", > 2 "/usr/lib/gcc/x86_64-linux-gnu/9/include/emmintrin.h", > 2 "/usr/include/x86_64-linux-gnu/bits/long-double.h", > 2 "./php-src/Zend/zend_string.h", > 2 "./php-src/Zend/zend_stream.h", > 2 "./php-src/Zend/zend_stack.h", [1] https://github.com/php/php-src/blob/master/ext/random/gammasection.c > When a.h is *not* required by any of b.h, c.h nor foo.c, I agree that it > should *not* be included at all, but when any of them, Ideally the scope of each individual header would also be narrowed to reduce the number of required dependencies. Staying at the gammasection.c example from above: Ideally it should not be necessary to include the 20 kB zend_string.h twice, because the gammasection.c does not use strings at all. Likewise the 50 kB zend_hash.h is included three times and not used it all. With the amount of C files this adds up. Best regards Tim Düsterhus