Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102030 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18383 invoked from network); 12 Apr 2018 20:34:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Apr 2018 20:34:56 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.175 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.223.175 mail-io0-f175.google.com Received: from [209.85.223.175] ([209.85.223.175:47047] helo=mail-io0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5B/58-36099-FE2CFCA5 for ; Thu, 12 Apr 2018 16:34:56 -0400 Received: by mail-io0-f175.google.com with SMTP id t13so300637ioc.13 for ; Thu, 12 Apr 2018 13:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=hh6/+1jwtfS1+Wy32F02f5AsLdaxxrVFO27OdAwICFU=; b=CP6GAMPr/GhBlWiXIt8UJ45Y0mttmylNFCraZh3GWM2lBwdlLXzTF0MM2UNohhU8Xq qjGzUpoAJn7iJ22Gm47uxA6wMZrifT/IjXFmsKqWqzTmu2fYsSOVriuBni8QZx053PSQ YZ7IjYrlBrbw/CfsaRcKfA1dRzh5C47ZkrK6GZ0Qqyso0lfHufK/ijiDCJd5z0bdShkl JNjbC3O9KOX6XoVFbCEnpxdZBtNg73mG4PuC3qFvZMeOeYiqgmbeWDcjV914CVlg4Dcv XCaYIG1dRwtnePBULoStj9de/xcQxFeFM/B5hdniyKiYQOE3g7tqbAh3p11PvczvVGt5 0xmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=hh6/+1jwtfS1+Wy32F02f5AsLdaxxrVFO27OdAwICFU=; b=F0toKPxPuTQzi/sH/JQ2NYrRatH+TLnQYPnGQWNSMPFVwsM+ZxFfRcIb7hTh0oY0tO vT/KKgiBOJb6QvazL7DG5jT7yEzYi3Gr1yD56NYOwyRgPfyBso+hbCwP1z9trTeTYRdc LcTy+5VwxW3QP1G83PXr0ss5xJoTRJCdoHE1dhwWkO4iG+GakUiPC2b3wmOEgLGBVQsy qqKJ3Kal5Hpp5NUPRxbRn+AfZXxNuieqnULErbqd3p0sSe4XgD7HK1vy41LF8Ah8+KDv gFelQpP8bDYEbvAR9HM4j62mv9d8PmjjaoJZJyBpL51bNtKb6kGTYIMlDzH/xz/DPsPd tAmA== X-Gm-Message-State: ALQs6tC17FRSdGbmX9mPRd3hW3zaRI3P78+muy6lk4GtuGaCPrWSbNLB Subx91zf2o4jN6UdnRsAF8C2XVN2BIukTLlEf2AB3g== X-Google-Smtp-Source: AIpwx48f/xyhd/Kypt7klTuSIgHpPdnmhFGezevAeHJth9+FqAilEagv2tKPIV/+kX4blwZ1BAOBRGspm+dtWs0OOYc= X-Received: by 10.107.37.5 with SMTP id l5mr10292071iol.47.1523565293422; Thu, 12 Apr 2018 13:34:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.154.76 with HTTP; Thu, 12 Apr 2018 13:34:52 -0700 (PDT) In-Reply-To: <1695946.AXCnACv0zz@titania.liwjatan.org> References: <1695946.AXCnACv0zz@titania.liwjatan.org> Date: Thu, 12 Apr 2018 22:34:52 +0200 Message-ID: To: Heinz Wiesinger Cc: internals Content-Type: multipart/alternative; boundary="001a1140f4181b67130569acb0dc" Subject: Re: [PHP-DEV] Request-global hashtable initialization From: nikita.ppv@gmail.com (Nikita Popov) --001a1140f4181b67130569acb0dc Content-Type: text/plain; charset="UTF-8" On Thu, Apr 12, 2018 at 9:53 PM, Heinz Wiesinger wrote: > Hi everyone! > > I ventured into writing my first PHP extension and did pretty well so far > following the existing documentation and example code inside the php > source. > > However, I hit an odd bug in my code that I can't quite explain. I'm > obviously > missing something and I hope someone here can point me in the right > direction > :) > > I'd like to set up a request global hashtable. For now I'm running > ALLOC_HASHTABLE() and zend_hash_init() inside PHP_GINIT_FUNCTION. I then > have > a user function that's supposed to add entries to that hashtable and > another > user function that reads entries from the hashtable. > > I tested with code passed directly on the command line (using php -r) and > that > works just like I would expect it too. The value gets written to the > hashtable > and I can read it afterwards from the other function. I also verified it's > the > same value that I first stored, so from what I can tell the basic > functionality is good. > > When I take the same testcode and write it into a file, and then run php on > that file, execution aborts trying to allocate almost 2GB of memory when > trying to store the value in the hashtable (using zend_hash_update()). I > can > see PHP_GINIT_FUNCTION being executed in that case as well so I'd assume > the > hashtable is setup just fine. Yet something is different. > > What's the difference between " php -r '' " and "php test.php" in that > regard? > > I uploaded my current state of the extension to github in case someone > would > like to take a closer look at the code: https://github.com/pprkut/ > autoload-psr > > Thanks in advance! > > Grs, > Heinz > https://github.com/pprkut/autoload-psr/blob/27cfc53c864116cf0b65b8f7e69464e15b3fdef5/autoload_psr.c#L175 should be using ZVAL_STR_COPY. The hashtable API does not automatically incref stored values. I'd suggest running under USE_ZEND_ALLOC=0 valgrind to check for further memory issues. Differences in the mode of execution are likely just incidental. Nikita --001a1140f4181b67130569acb0dc--