Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115151 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 81632 invoked from network); 26 Jun 2021 08:48:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Jun 2021 08:48:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EEDE71804C3 for ; Sat, 26 Jun 2021 02:08:00 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail02.x-net.at (mail02.x-net.at [83.65.141.138]) (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 ; Sat, 26 Jun 2021 02:07:59 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail02.x-net.at (Postfix) with ESMTP id 8AF663803E5 for ; Sat, 26 Jun 2021 11:07:56 +0200 (CEST) Received: from mail02.x-net.at ([127.0.0.1]) by localhost (mail02.x-net.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 6OoelQ4NLgjz for ; Sat, 26 Jun 2021 11:07:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail02.x-net.at (Postfix) with ESMTP id 2ED06380419 for ; Sat, 26 Jun 2021 11:07:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at x-t.at Received: from mail02.x-net.at ([127.0.0.1]) by localhost (mail02.x-net.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ynv_Mr0BLHLk for ; Sat, 26 Jun 2021 11:07:52 +0200 (CEST) Received: from [127.0.0.1] (91.141.32.115.wireless.dyn.drei.com [91.141.32.115]) by mail02.x-net.at (Postfix) with ESMTPSA id EA682380418 for ; Sat, 26 Jun 2021 11:07:51 +0200 (CEST) Date: Sat, 26 Jun 2021 11:07:52 +0200 To: PHP internals User-Agent: K-9 Mail for Android In-Reply-To: References: Message-ID: <3FA73380-87D3-4DFA-862B-970DB2F53D4A@dafert.at> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Add Random Extension (before: Add Random class) From: mel@dafert.at (Mel Dafert) On 26 June 2021 02:39:52 CEST, Go Kudo wrote: >Hello Internals=2E > >RFC has been reorganized for finalization=2E > >https://wiki=2Ephp=2Enet/rfc/rng_extension > >The changes from the previous version are as follows: > >- Changed again to a class-based approach=2E The argument can be omitted,= in >which case an instance of XorShift128Plus will be created automatically= =2E >- Future scope was specified in the RFC and the functionality was separat= ed >as a Random extension=2E >- Changed to separate it as a Random extension and use the appropriate >namespace=2E >- In order to extend the versatility of the final class, Random, a >RandomInterface has been added, similar in approach to the >DateTimeInterface=2E > >I've done a tidy implementation to make this final, but I'm currently >suffering from error detection by Valgrind for unknown reasons=2E > >Implementation is here: https://github=2Ecom/php/php-src/pull/7079 > >This can be reproduced with the following code=2E > >```sh ># Success >$ valgrind =2E/sapi/cli/php -r '$random =3D new Random(); $random->nextIn= t();' >=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=2E >=3D=3D95522=3D=3D Using Valgrind-3=2E14=2E0 and LibVEX; rerun with -h for= copyright info >=3D=3D95522=3D=3D Command: =2E/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 =2E/sapi/cli/php -r '$random =3D new Random(); $random->nextIn= t() >=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=2E >=3D=3D95395=3D=3D Using Valgrind-3=2E14=2E0 and LibVEX; rerun with -h for= copyright info >=3D=3D95395=3D=3D Command: =2E/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=2Eh:27024) >=3D=3D95395=3D=3D by 0x99AC27: execute_ex (zend_vm_execute=2Eh:57236) >=3D=3D95395=3D=3D by 0x99C902: zend_execute (zend_vm_execute=2Eh:59026= ) >=3D=3D95395=3D=3D by 0x8DB6B4: zend_eval_stringl (zend_execute_API=2Ec= :1191) >=3D=3D95395=3D=3D by 0x8DB861: zend_eval_stringl_ex (zend_execute_API= =2Ec:1233) >=3D=3D95395=3D=3D by 0x8DB8D6: zend_eval_string_ex (zend_execute_API= =2Ec:1243) >=3D=3D95395=3D=3D by 0xA4DAE4: do_cli (php_cli=2Ec:995) >=3D=3D95395=3D=3D by 0xA4E8E2: main (php_cli=2Ec: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=2E From the code, it looks like memory management is bein= g >done properly=2E > >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=2E > >Regards, >Go Kudo >Hello Internals=2E > >RFC has been reorganized for finalization=2E > >https://wiki=2Ephp=2Enet/rfc/rng_extension I think this is a good reorganization=2E I would like to point out that this does not quite follow the Namespace Po= licy (https://wiki=2Ephp=2Enet/rfc/namespaces_in_bundled_extensions): Notably it says: > All symbols defined in the extension should be part of the extension's t= op-level > namespace or a sub-namespace=2E This means that the Random class and RandomInterface interface should be Random\Random and Random\RandomInterface respectively=2E The symbols in the Random\NumberGenerator sub-namespace are okay, as per the policy=2E Note, however, that the policy says "should", and if there is a good argum= ent made, the guidelines must not be followed=2E