Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115148 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49714 invoked from network); 26 Jun 2021 00:21:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Jun 2021 00:21:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C25B1804CC for ; Fri, 25 Jun 2021 17:40:07 -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-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 ; Fri, 25 Jun 2021 17:40:06 -0700 (PDT) Received: by mail-ej1-f42.google.com with SMTP id gn32so17894453ejc.2 for ; Fri, 25 Jun 2021 17:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=8VH5sqIyEshzfUK68eYrcehhtS1+o0zJZJJAipyGnO8=; b=GhqdsugmfwkHJKA6W9dvPU7So/ID6rb30xYPFl1kpYeCCNUaLh1nURwFKq9cjHcqVt DR0F91OPw0DnaxqM/PhIG7+s5aC/LWFLBMYW2AB04z0AqDzjGuSWNTKnLvIGPApRparF w1ckl5c+A172ZznhA8AEuKMibkr44GgLYk3yeoNMG7FLqzempyMHtl99XsyTCcAnSMCy aDEyZjjDzm/DTkb7TN/hmXaVSVM93u/pILaYF3A6uDIiYOIn9p1C2EHobf08WLc8Zkpr A4mF9GQrKZgHpM8omzLTC0B3KyDBvXl1gjxk9NkIhiUmqAg4Z5h+0n2yH9KkQii1tE3t eFGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=8VH5sqIyEshzfUK68eYrcehhtS1+o0zJZJJAipyGnO8=; b=C7H052EoC3BPMA3f4gVma8b9jisF2tQ3OKG/mJZI2iMbv98UWAo/pJseurgfNviyzE kh9Fq/KmGwqMz4K0fip4otv6236hRbe+5LkTOfOlY4bwGTF3x/1N9VSlxQPP5757qi10 39hLXHCoVms+jGBar3KzqCnBm0nkUA1glHbDkr5LTT/Oo4SB4xTXbEsfc09kI8ARzrW1 zznHnD7wthKEDf3M+yopMqyBfQGxuw5bqMG1FKb5scW4yuMvi9QM2VALZHDWYLgF7REq FUIyMfMmVwZf3PAxDswZQFLo4uEF9mkmd2yJvaVxxslKRE/uFssvc+Hb6iA7PRBmwvbO +YQA== X-Gm-Message-State: AOAM53046cb0DZXKFYSF7geQu09dElKUZk+aEekeCpyHlXvzUGa5PXHE Xbkp70vpP/9NH1dZy+wxluHq2UrbUyyi6xbqIOYUEpWiY1ntmg== X-Google-Smtp-Source: ABdhPJy/zBhkoEYGbmP9txTY0uSrZdVCAumW0fVOS9JxZZDccVD3rUw2WWS1hgOdf3UXBh4H3RUMUafDspK6lnoid6g= X-Received: by 2002:a17:907:788d:: with SMTP id ku13mr13372997ejc.245.1624668002944; Fri, 25 Jun 2021 17:40:02 -0700 (PDT) MIME-Version: 1.0 Date: Sat, 26 Jun 2021 09:39:52 +0900 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000031894e05c5a07fd3" Subject: [RFC] Add Random Extension (before: Add Random class) From: zeriyoshi@gmail.com (Go Kudo) --00000000000031894e05c5a07fd3 Content-Type: text/plain; charset="UTF-8" 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, in 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 = new Random(); $random->nextInt();' ==95522== Memcheck, a memory error detector ==95522== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==95522== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info ==95522== Command: ./sapi/cli/php -r $random\ =\ new\ Random();\ $random-\>nextInt(); ==95522== ==95522== ==95522== HEAP SUMMARY: ==95522== in use at exit: 1,286 bytes in 32 blocks ==95522== total heap usage: 28,445 allocs, 28,413 frees, 4,333,047 bytes allocated ==95522== ==95522== LEAK SUMMARY: ==95522== definitely lost: 0 bytes in 0 blocks ==95522== indirectly lost: 0 bytes in 0 blocks ==95522== possibly lost: 0 bytes in 0 blocks ==95522== still reachable: 1,286 bytes in 32 blocks ==95522== suppressed: 0 bytes in 0 blocks ==95522== Rerun with --leak-check=full to see details of leaked memory ==95522== ==95522== For counts of detected and suppressed errors, rerun with: -v ==95522== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) # Fail $ valgrind ./sapi/cli/php -r '$random = new Random(); $random->nextInt() === $random->nextInt();' ==95395== Memcheck, a memory error detector ==95395== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==95395== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info ==95395== Command: ./sapi/cli/php -r $random\ =\ new\ Random();\ $random-\>nextInt()\ ===\ $random-\>nextInt(); ==95395== ==95395== Conditional jump or move depends on uninitialised value(s) ==95395== at 0x966925: ZEND_IS_IDENTICAL_SPEC_VAR_VAR_HANDLER (zend_vm_execute.h:27024) ==95395== by 0x99AC27: execute_ex (zend_vm_execute.h:57236) ==95395== by 0x99C902: zend_execute (zend_vm_execute.h:59026) ==95395== by 0x8DB6B4: zend_eval_stringl (zend_execute_API.c:1191) ==95395== by 0x8DB861: zend_eval_stringl_ex (zend_execute_API.c:1233) ==95395== by 0x8DB8D6: zend_eval_string_ex (zend_execute_API.c:1243) ==95395== by 0xA4DAE4: do_cli (php_cli.c:995) ==95395== by 0xA4E8E2: main (php_cli.c:1366) ==95395== ==95395== ==95395== HEAP SUMMARY: ==95395== in use at exit: 1,286 bytes in 32 blocks ==95395== total heap usage: 28,445 allocs, 28,413 frees, 4,333,070 bytes allocated ==95395== ==95395== LEAK SUMMARY: ==95395== definitely lost: 0 bytes in 0 blocks ==95395== indirectly lost: 0 bytes in 0 blocks ==95395== possibly lost: 0 bytes in 0 blocks ==95395== still reachable: 1,286 bytes in 32 blocks ==95395== suppressed: 0 bytes in 0 blocks ==95395== Rerun with --leak-check=full to see details of leaked memory ==95395== ==95395== For counts of detected and suppressed errors, rerun with: -v ==95395== Use --track-origins=yes to see where uninitialised values come from ==95395== 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 --00000000000031894e05c5a07fd3--