Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124816 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id CEC721A00B7 for ; Tue, 6 Aug 2024 20:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1722975830; bh=hqd7/OOO9R9cMgviFu7Qw2LdxJtFZZ3ORdn+6PWUexE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dCLYNOG89b46rBoI8DoSqXVZp+6ODFh6ozpadH2sN5NCZREDbSC/AfoLh30U7oV0I 5Ck4kLMX9DF16GnpBL38Cj53ZPx1RtbQ+zHhKFyJPfTbkg61gay0tKdEGKC31UdHom lUCvTPqvUeYkurvDID5DNF4tqQSIiWiju1oT/8tnhJVJBZaJR5VOEKFMzcbRrEfC0T /OhbIFW4UXTWVmQgPr86YnPzW4SjDKQJkdcGmZgffFq/ne8ORlG//BXTrtSa2NTxNR ucBti3eeG2gSY9zLCsb7X7z/whjHU/wYF3pz8biSbLdreIjY1pdghxOWW0zgHOybYe 4aSXnSRt7KlFg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3418B180055 for ; Tue, 6 Aug 2024 20:23:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 6 Aug 2024 20:23:48 +0000 (UTC) Received: by mail-vs1-f42.google.com with SMTP id ada2fe7eead31-4928d2f45e2so344699137.0 for ; Tue, 06 Aug 2024 13:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722975726; x=1723580526; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=hqd7/OOO9R9cMgviFu7Qw2LdxJtFZZ3ORdn+6PWUexE=; b=mKEdLE5Lcbnf4qB3SE0eoHvD+Sh6hRAyiVuGfHQ73O/J66Q9WAhgA+k4Lmu+i2UqOM LDYDe/wbpoU0VENMHRPsqcYdhM/pj6eQXP78UhF/5BcuyP3sGdyxn3AGRyIYzx+m8Cs5 LH13scsPFrKjEbxBnBlebgi1pblQk57mVGp8dKyDGCnRLsD4s1eMIdK9K4+Ai7uN9mXS tGWeyWoosvozoMWo0Eq4UFebWwCySpu3F3UPO3w9evqAW5wMuSGqyjAfL5/ywY7sPDWi nkvkTpOkPmDs6YQ4DPFBNuNt230Z3en25ASe9wKTSIxHNFEeShOdXLL6sp/IHesFCBqD 6kgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722975726; x=1723580526; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hqd7/OOO9R9cMgviFu7Qw2LdxJtFZZ3ORdn+6PWUexE=; b=Tp/dC8oPMxRFteaLT8/Y5M/y3iBZ7q/YaGsC+gZCEQ6BdvzengRnIJL9x9KuMBKL53 m8ak3IagbR72y3vONDpyLHgpFGJ4R5JB9FrUe5yOvCc0KJNH4m1OxvTZhwuuR9STrbvS 23orjvR2aj+kjXrJ8K3RrkaHz5T7TxV7qGLajyNuC22QHqh2gR8jw4yZI5e0Qiq2ohf9 qNLTcgqCwiE1/LVXrkIBeMsnOs0uqWzWYD9widUvXN5HkjbjkXwMTOq0baVsC8uP7MZn ztlzZAETfA/Kv8ze3vnpXLMsW1cEAhnUEFu4mdbDH39MYTo0n0kpPIOxLpXYpu98Woli U9oQ== X-Gm-Message-State: AOJu0Yw+5jmof6OvpERhXjQ6hFQ/suWOQr/Zu/3jEx8bqtwc/k8iU+In vhZbjzEs86I+8sJ3MicqUqIBPUEh+imG1snbL4+TvuVv5JOuANbzhvWfepxLAf1j6QlEu65zZSR zqqJZYPRxWdKEr6l+1lNoWmJSGCla+g== X-Google-Smtp-Source: AGHT+IEyRi9Hfh2dm2I9lR9h+77x2KMf2SrEfpilimygNMfq7OtTuu7MEL6ZXfFaSK3WVTJ+x7g5W065D9YfOy3J8AE= X-Received: by 2002:a05:6102:32c7:b0:48f:de23:14f0 with SMTP id ada2fe7eead31-4945bde6c85mr20979484137.8.1722975726112; Tue, 06 Aug 2024 13:22:06 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 6 Aug 2024 14:21:56 -0600 Message-ID: Subject: Re: [PHP-DEV] Require C11 in PHP 8.4 To: Ilija Tovilo Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000001c98fc061f098c6f" From: lnearwaju@gmail.com (Lanre) --0000000000001c98fc061f098c6f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Aug 1, 2024 at 4:01=E2=80=AFPM Ilija Tovilo wrote: > Hi everyone > > We've gotten a bug report about compile errors in the PHP 8.4 alpha on > old C99 compilers (and on some modern compilers when passing the > -std=3Dc99 flag). Specifically, C99 does not support typedef > redeclarations, which is a C11 feature. > > ```c > // some_header.h > typedef struct _zval_struct zval; > void some_func(zval *zv); > > // zend_types.h > struct _zval_struct { ... }; > typedef struct _zval_struct zval; > ``` > > Some headers might want to forward declare zval so that zend_types.h > doesn't have to be included. The two primary reasons you might want to > avoid that are 1. to reduce compile times if the header is very large > and 2. to prevent recursive header dependencies. > > However, in C99 this code is actually illegal if both of these headers > end up being included, because redeclarations of typedefs are not > allowed. To fix it, the typedef must be removed and the signatures > must refer to the struct directly. > > ```c > // some_header.h > struct _zval_struct; > void some_func(struct _zval_struct *zv); > ``` > > I started fixing these in a PR [1] which required more changes than > expected. After a short discourse, we were wondering whether it might > be better to switch to a newer C standard instead. Our coding > standards [2] currently specify that compiling php-src requires C99. > The Unix installation page on php.net [3] claims it is ANSI C, which > is certainly outdated. There have been suggestions to require C11 for > a while, which should be well supported by all compilers shipped with > maintained distributions. > > GCC gained support for C11 in 4.7 [4], LLVM Clang in 3.1, both > released in 2012. For context, Debian Bullseye comes with GCC 10.2 > [5], Ubuntu Focal Fossa comes with GCC 9.3 [6], RHEL 8 comes with GCC > 8.x [7]. The biggest blocker in the past was MSVC, which has finally > added C11 support in Visual Studio 2019 [8]. Technically, Visual > Studio 2015 and 2017 are still supported by Microsoft [9], but > according to Christoph they are no longer used for PHP builds since > version 8. > > Hence, it seems like it would be ok to bump our C compiler requirement > to C11. We'd like to make this change before beta 1 if there are no > objections. There are no immediate plans to make non-optional use of > other C11 features, although that is conceivable at some point. > > Another benefit brought up by Christoph is that C11 relegated the > requirement for the compiler to support VLAs (variable-length arrays) > which was never implemented by MSVC, technically not complying with > the currently required standard. > > If you do have any concerns, please let me know. > > Ilija > > [1] https://github.com/php/php-src/pull/15079 > [2] [ > https://github.com/php/php-src/blob/8b6f14a9a221599b076e4bc3570f013a7e65a= a21/CODING_STANDARDS.md?plain=3D1#L12](https://github.com/php/php-src/blob/= 8b6f14a9a221599b076e4bc3570f013a7e65aa21/CODING_STANDARDS.md?plain=3D1#L12) > [3] https://www.php.net/manual/en/install.unix.php > [4] https://stackoverflow.com/a/16256596 > [5] https://packages.debian.org/bullseye/gcc > [6] https://packages.ubuntu.com/focal/gcc > [7] https://access.redhat.com/solutions/19458 > [8] > https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriv= ing-in-msvc/ > [9] > https://learn.microsoft.com/en-us/visualstudio/productinfo/vs-servicing Would now be a good time to consider switching to cmake? Peter(petk) has a cmake build system on his github that just needs to be touched up. --0000000000001c98fc061f098c6f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, Aug 1, 2024 at 4:01=E2=80=AFPM Il= ija Tovilo <= tovilo.ilija@gmail.com> wrote:
Hi everyone

We've gotten a bug report about compile errors in the PHP 8.4 alpha on<= br> old C99 compilers (and on some modern compilers when passing the
-std=3Dc99 flag). Specifically, C99 does not support typedef
redeclarations, which is a C11 feature.

```c
// some_header.h
typedef struct _zval_struct zval;
void some_func(zval *zv);

// zend_types.h
struct _zval_struct { ... };
typedef struct _zval_struct zval;
```

Some headers might want to forward declare zval so that zend_types.h
doesn't have to be included. The two primary reasons you might want to<= br> avoid that are 1. to reduce compile times if the header is very large
and 2. to prevent recursive header dependencies.

However, in C99 this code is actually illegal if both of these headers
end up being included, because redeclarations of typedefs are not
allowed. To fix it, the typedef must be removed and the signatures
must refer to the struct directly.

```c
// some_header.h
struct _zval_struct;
void some_func(struct _zval_struct *zv);
```

I started fixing these in a PR [1] which required more changes than
expected. After a short discourse, we were wondering whether it might
be better to switch to a newer C standard instead. Our coding
standards [2] currently specify that compiling php-src requires C99.
The Unix installation page on php.net [3] claims it is ANSI C, which
is certainly outdated. There have been suggestions to require C11 for
a while, which should be well supported by all compilers shipped with
maintained distributions.

GCC gained support for C11 in 4.7 [4], LLVM Clang in 3.1, both
released in 2012. For context, Debian Bullseye comes with GCC 10.2
[5], Ubuntu Focal Fossa comes with GCC 9.3 [6], RHEL 8 comes with GCC
8.x [7]. The biggest blocker in the past was MSVC, which has finally
added C11 support in Visual Studio 2019 [8]. Technically, Visual
Studio 2015 and 2017 are still supported by Microsoft [9], but
according to Christoph they are no longer used for PHP builds since
version 8.

Hence, it seems like it would be ok to bump our C compiler requirement
to C11. We'd like to make this change before beta 1 if there are no
objections. There are no immediate plans to make non-optional use of
other C11 features, although that is conceivable at some point.

Another benefit brought up by Christoph is that C11 relegated the
requirement for the compiler to support VLAs (variable-length arrays)
which was never implemented by MSVC, technically not complying with
the currently required standard.

If you do have any concerns, please let me know.

Ilija

[1] https://github.com/php/php-src/pull/15079
[2] [https://github.com/p= hp/php-src/blob/8b6f14a9a221599b076e4bc3570f013a7e65aa21/CODING_STANDARDS.m= d?plain=3D1#L12](https://github.com/php/php-src/blob/8b6f14a9a221599b076e4b= c3570f013a7e65aa21/CODING_STANDARDS.md?plain=3D1#L12)
[3] https://www.php.net/manual/en/install.unix.php=
[4] https://stackoverflow.com/a/16256596
[5] https://packages.debian.org/bullseye/gcc
[6] https://packages.ubuntu.com/focal/gcc
[7] https://access.redhat.com/solutions/19458
[8] https://dev= blogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/<= /a>
[9]
https://learn.microsoft.c= om/en-us/visualstudio/productinfo/vs-servicing

Would now be a good time to consider switching to cmake? Peter(petk= ) has a cmake build system on his github that just needs to be touched up.<= /div>
--0000000000001c98fc061f098c6f--