Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115364 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 55247 invoked from network); 8 Jul 2021 09:28:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jul 2021 09:28:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A98A81804DA for ; Thu, 8 Jul 2021 02:50:34 -0700 (PDT) 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,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 8 Jul 2021 02:50:34 -0700 (PDT) Received: by mail-ej1-f46.google.com with SMTP id bg14so8516609ejb.9 for ; Thu, 08 Jul 2021 02:50:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Xg6LcIU3HMXY0thpGGikvINYF2Fd9GQPOgg9C/F4ntE=; b=hVePyrH/9hy9P4jOK/JcvAYWGdMu51AVf/zIefEbeoXzxDQTOO0nRtstcODscdy7He Iy2+5tum8hbycjsmnF+5f0Ns/Ytpwxw2VEnYLhE5OXaM2WCghlfqAo0vDhw//UWf8dw3 LeXe4POi1Q+YbwMOOXhMz13MJQ1L9+4SKdii7E1tCiVcm9smJMER1nOFEBRWnrQ0nfeg MQixOLG9X1QWZ0Tke6Ib51k6TUBwgWoMLw3qk1+EafKwzKbQ17jiBF+tRGq3Du3vkB44 KhCEoPPiRPxt8yc3eezZOrGKTfedHjZTCWWCwisuGk+a+zMQyE4+LUQZT8p4NYZPl7LA LbQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Xg6LcIU3HMXY0thpGGikvINYF2Fd9GQPOgg9C/F4ntE=; b=KPJOZhIKazKs53iLeqN7Q550BGvAijbU/aP80h79QYHTBO02rlt0THvz0YpMjlRykV hjB+eL4iZTGgN2wHTvVEPOSNYBL2a5zm3CZf6WOZBM4cMvH+VNGNRpiOzaLe6XQUXjDI VIUCw9NIwoMZYAummZsmg8fxszzMNh1Y5U1IAboEc45VeTYkG2pXu9hNHSczGyGJ6rPD +LqzgoisYgodfDcX1HUMFUxhhEH1fbvLR0Xi/eGvoGrGBqzBZDbZwBqI9VENeYFazH9R TFyQFyMPefSxLyBV1wUnqnanc41DeuH4L3pui+MI1Sr/Fzz/lDOxg5hmU7XCXkl8ryAc Sz2w== X-Gm-Message-State: AOAM5306BvqTLtwKJHVHi1AnzL3gWbCiOiCsmDHhiDkdSS4qhJhLVCoy E8mFRWEWVRdUhaMILHSsKQlXD9AMBgijFafgAWuDa0OrymM= X-Google-Smtp-Source: ABdhPJwkE836YXw5Ttd7tBN1i5o9dcqHPdAHXfPmLpmu9gT97la7j9Rp7PLAB8ZTFF+04vGwow6Mxy4+VwLnKpo5GUU= X-Received: by 2002:a17:906:5d07:: with SMTP id g7mr29648214ejt.29.1625737831710; Thu, 08 Jul 2021 02:50:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 8 Jul 2021 18:50:20 +0900 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000f5032905c6999556" Subject: Re: [RFC] Add Random Extension (before: Add Random class) From: zeriyoshi@gmail.com (Go Kudo) --000000000000f5032905c6999556 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello Internals. I mistakenly thought there was still time, but voting for a new RFC for PHP 8.1 has already closed. I believe that an object-scoped random number generator is a necessity for PHP and I will continue to work on it. We will continue to improve the RFC. I will also work on getting it published in PECL so that features are available quickly. Regards, Go Kudo 2021=E5=B9=B46=E6=9C=8826=E6=97=A5(=E5=9C=9F) 9:39 Go Kudo : > Hello Internals. > > RFC has been reorganized for finalization. > > https://wiki.php.net/rfc/rng_extension > > The changes from the previous version are as follows: > > - Changed again to a class-based approach. The argument can be omitted, i= n > which case an instance of XorShift128Plus will be created automatically. > - Future scope was specified in the RFC and the functionality was > separated as a Random extension. > - Changed to separate it as a Random extension and use the appropriate > namespace. > - In order to extend the versatility of the final class, Random, a > RandomInterface has been added, similar in approach to the > DateTimeInterface. > > I've done a tidy implementation to make this final, but I'm currently > suffering from error detection by Valgrind for unknown reasons. > > Implementation is here: https://github.com/php/php-src/pull/7079 > > This can be reproduced with the following code. > > ```sh > # Success > $ valgrind ./sapi/cli/php -r '$random =3D new Random(); $random->nextInt(= );' > =3D=3D95522=3D=3D Memcheck, a memory error detector > =3D=3D95522=3D=3D Copyright (C) 2002-2017, and GNU GPL'd, by Julian Sewar= d et al. > =3D=3D95522=3D=3D Using Valgrind-3.14.0 and LibVEX; rerun with -h for cop= yright > info > =3D=3D95522=3D=3D Command: ./sapi/cli/php -r $random\ =3D\ new\ Random();= \ > $random-\>nextInt(); > =3D=3D95522=3D=3D > =3D=3D95522=3D=3D > =3D=3D95522=3D=3D HEAP SUMMARY: > =3D=3D95522=3D=3D in use at exit: 1,286 bytes in 32 blocks > =3D=3D95522=3D=3D total heap usage: 28,445 allocs, 28,413 frees, 4,333,= 047 bytes > allocated > =3D=3D95522=3D=3D > =3D=3D95522=3D=3D LEAK SUMMARY: > =3D=3D95522=3D=3D definitely lost: 0 bytes in 0 blocks > =3D=3D95522=3D=3D indirectly lost: 0 bytes in 0 blocks > =3D=3D95522=3D=3D possibly lost: 0 bytes in 0 blocks > =3D=3D95522=3D=3D still reachable: 1,286 bytes in 32 blocks > =3D=3D95522=3D=3D suppressed: 0 bytes in 0 blocks > =3D=3D95522=3D=3D Rerun with --leak-check=3Dfull to see details of leaked= memory > =3D=3D95522=3D=3D > =3D=3D95522=3D=3D For counts of detected and suppressed errors, rerun wit= h: -v > =3D=3D95522=3D=3D ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 = from 0) > > # Fail > $ valgrind ./sapi/cli/php -r '$random =3D new Random(); $random->nextInt(= ) > =3D=3D=3D $random->nextInt();' > =3D=3D95395=3D=3D Memcheck, a memory error detector > =3D=3D95395=3D=3D Copyright (C) 2002-2017, and GNU GPL'd, by Julian Sewar= d et al. > =3D=3D95395=3D=3D Using Valgrind-3.14.0 and LibVEX; rerun with -h for cop= yright > info > =3D=3D95395=3D=3D Command: ./sapi/cli/php -r $random\ =3D\ new\ Random();= \ > $random-\>nextInt()\ =3D=3D=3D\ $random-\>nextInt(); > =3D=3D95395=3D=3D > =3D=3D95395=3D=3D Conditional jump or move depends on uninitialised value= (s) > =3D=3D95395=3D=3D at 0x966925: ZEND_IS_IDENTICAL_SPEC_VAR_VAR_HANDLER > (zend_vm_execute.h:27024) > =3D=3D95395=3D=3D by 0x99AC27: execute_ex (zend_vm_execute.h:57236) > =3D=3D95395=3D=3D by 0x99C902: zend_execute (zend_vm_execute.h:59026) > =3D=3D95395=3D=3D by 0x8DB6B4: zend_eval_stringl (zend_execute_API.c:1= 191) > =3D=3D95395=3D=3D by 0x8DB861: zend_eval_stringl_ex (zend_execute_API.= c:1233) > =3D=3D95395=3D=3D by 0x8DB8D6: zend_eval_string_ex (zend_execute_API.c= :1243) > =3D=3D95395=3D=3D by 0xA4DAE4: do_cli (php_cli.c:995) > =3D=3D95395=3D=3D by 0xA4E8E2: main (php_cli.c:1366) > =3D=3D95395=3D=3D > =3D=3D95395=3D=3D > =3D=3D95395=3D=3D HEAP SUMMARY: > =3D=3D95395=3D=3D in use at exit: 1,286 bytes in 32 blocks > =3D=3D95395=3D=3D total heap usage: 28,445 allocs, 28,413 frees, 4,333,= 070 bytes > allocated > =3D=3D95395=3D=3D > =3D=3D95395=3D=3D LEAK SUMMARY: > =3D=3D95395=3D=3D definitely lost: 0 bytes in 0 blocks > =3D=3D95395=3D=3D indirectly lost: 0 bytes in 0 blocks > =3D=3D95395=3D=3D possibly lost: 0 bytes in 0 blocks > =3D=3D95395=3D=3D still reachable: 1,286 bytes in 32 blocks > =3D=3D95395=3D=3D suppressed: 0 bytes in 0 blocks > =3D=3D95395=3D=3D Rerun with --leak-check=3Dfull to see details of leaked= memory > =3D=3D95395=3D=3D > =3D=3D95395=3D=3D For counts of detected and suppressed errors, rerun wit= h: -v > =3D=3D95395=3D=3D Use --track-origins=3Dyes to see where uninitialised va= lues come > from > =3D=3D95395=3D=3D ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 = from 0) > ``` > > However, the detection is internal to the Zend VM and the cause has not > been identified. From the code, it looks like memory management is being > done properly. > > I have a somewhat tricky way of allocating memory to make the process > common, do I need to give some hints to Valgrind? > > If you know, I would appreciate your advice on this issue. > > Regards, > Go Kudo > --000000000000f5032905c6999556--