Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111693 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30873 invoked from network); 26 Aug 2020 10:15:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Aug 2020 10:15:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6B1811804D9 for ; Wed, 26 Aug 2020 02:18:43 -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=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 ; Wed, 26 Aug 2020 02:18:43 -0700 (PDT) Received: by mail-qk1-f173.google.com with SMTP id n129so1243567qkd.6 for ; Wed, 26 Aug 2020 02:18:43 -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 :cc; bh=qA2pUkChD161Dwv29BBy/vY+sEbgVzESFDIzGghdOjI=; b=bG2jUe/ZAT5hAg+F78Hnapy0OpGslU3xCOPpc6Hdq+3mm8Kn1AGMtfAsxTkjqFWmQ5 RXLzrUGGyBX2SGUUBjTEOMgn57S3fMR2cAW7RVP8ibzr47OAiXsaRDaZ5VTNsXaTHKkM JuAxNrEw5q9iyca5nUC+mzGsC73GmK3tm/dfxbvyaR2nTNNN9O9UMyqrYH1czS/l34Iw 2hy0OhxIDuRJEIh9v4e9BGD62aXw0hRxkGEQ9Y+NEiKKtmeyYjfxoMEsro3rcii+Kpy0 /WSbCbRbXpC05AGrM1fRYnuVU5jzos31Co7Ewajzvq9znZm08K//GMp6jj+IQRjBPmlA BXkQ== 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:cc; bh=qA2pUkChD161Dwv29BBy/vY+sEbgVzESFDIzGghdOjI=; b=HHnRfw884Oy5CeM5X41XHNwhHMV/5WB6se38TxCIHaasuWIwyGEoS6cuSNwoIeh7M/ Bo/kj9PxPrkNWDIS31fVNdg3V6CNM4orupTZIAi0g1xQP7+QujthEXshJp5eaTovmXtV TUgaY6r1eF+tv+4KXn1Y82GgFeHB6yng/785KhaNscDLPQtDxKXgduS+EBdp1hCFEfj3 8lEnjdXJUkNMa31Vg/CW1GR7CfvWEmonIFUwN7hU6hiu9zPLtq8XWqic5hAxdjEt7DuY uQyJOjeKmmYDqp/KIOdyovE8jWmbbnI6PGNbbvO+eduGVaujPADzEms+GFl/1RMML2RK NbDw== X-Gm-Message-State: AOAM5324Crjrl2cMP8CwCH7Fb2RY/Zwl2g4hdhIdI/gKiGYf2wY38IR+ wK7dpsZrHthTbhA/EkhdGh8kz2akAlCZjVWpsQ== X-Google-Smtp-Source: ABdhPJycmrGnGhQWW20BKbwQ2A56rIFyxg2yu4FTpkwfQqpg9PASLCm5d+kEya7OUWE5O33WV4zWrtMTDdSO14Z6Mvk= X-Received: by 2002:a37:7245:: with SMTP id n66mr13216696qkc.83.1598433521786; Wed, 26 Aug 2020 02:18:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 Aug 2020 12:18:32 +0300 Message-ID: To: Alex Cc: Levi Morrison , PHP internals Content-Type: multipart/alternative; boundary="0000000000004365db05adc44e58" Subject: Re: [PHP-DEV] Segmentation Fault when trying to call zend_new_array. From: ivanzanev477@gmail.com (Ivan Zanev) --0000000000004365db05adc44e58 Content-Type: text/plain; charset="UTF-8" Thank you! On Wed, Aug 26, 2020 at 11:00 AM Alex wrote: > Dear Ivan, > > Some suggestions: > > - Build your own copy of the PHP embed library using ./configure > --enable-embed=shared or ./configure --enable-embed=static. Link against > that. > - If it doesn't work, get some already-working sample code for use of the > PHP embed SAPI and modify it rather than starting from scratch. > - If you are still struggling, run your test under gdb so you can get a > stack trace when it segfaults. It's as simple as "gdb --args invocation here>". Make sure that both the PHP embed SAPI and your own test > code were compiled with debug info enabled. > > Alex > > > > On Wed, Aug 26, 2020 at 9:29 AM Ivan Zanev wrote: > >> Yes, it does. >> >> I recompiled php now with >> >> --configure --enable-embed=static >> >> and wrote a simple script: >> >> #include >> #include >> >> #include "sapi/embed/php_embed.h" >> >> int main(int argc, char *argv[]) { >> php_embed_init(argc, argv); >> >> HashTable *ht = zend_new_array(15); >> >> return 0; >> } >> >> Compiled with the following command: >> >> gcc -I./Zend -I. -I./TSRM -I./main Zend/*.c TSRM/TSRM.c test-embed.c -ldl >> -lm -lphp7 -g >> >> The segmentation fault problem still occurs, when calling php_embed_init. >> >> Not sure if that's a problem of libphp7.so which I installed via apt or it >> is something related to a missing piece in the test-embed.c script I >> wrote? >> >> On Tue, Aug 25, 2020 at 2:39 PM Levi Morrison < >> levi.morrison@datadoghq.com> >> wrote: >> >> > On Tue, Aug 25, 2020 at 5:31 AM Ivan Zanev >> wrote: >> > > >> > > Hello, >> > > >> > > I'm trying to learn a bit more about HashTable in PHP internally and >> how >> > > memory is allocated when generating arrays with various sizes. I >> created >> > a >> > > simple C script that would call >> > > >> > > HashTable *ht = zend_new_array(15); >> > > >> > > However, when I compile the script with gcc, I get segmentation fault; >> > gdb >> > > tells that the problem is located within _emalloc_56, specifically: >> > > >> > > 2535 if (UNEXPECTED(AG(mm_heap)->use_custom_heap)) { >> > > >> > > That's how I compiled the script: >> > > gcc -I./Zend -I. -I./TSRM -I./main Zend/*.c TSRM/TSRM.c test.c -ldl >> -lm >> > -g >> > > >> > > For the configuration I used: >> > > ./configure >> > > >> > > Could you please guide me in the right direction? Is there something I >> > > should do before calling zend_new_array? >> > > >> > > Sincerely, >> > > Ivan >> > >> > Does `test.c` include a main? If so you probably want to use the embed >> > SAPI. If not then you probably want to build it as an extension. >> > >> > --0000000000004365db05adc44e58--