Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111687 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15350 invoked from network); 26 Aug 2020 08:26:01 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Aug 2020 08:26:01 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F2F691804C0 for ; Wed, 26 Aug 2020 00:29:06 -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-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (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 00:29:06 -0700 (PDT) Received: by mail-qt1-f175.google.com with SMTP id o22so704941qtt.13 for ; Wed, 26 Aug 2020 00:29:06 -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=N/Hc8iNHVxaGeu0+z7sEpiztAldn0s4+Vfat2JueMaY=; b=qaag9t/BEjJ6Bl/Z31YdWM0FzwB95rUsc7dJiJDpliPVU6OwJOjbzZueiFq4dzYPBh +gxP6KFn9h7h6djl9CqJA8Vgc0/hPBTKBShW7RZxsTe9LkEQ9BvU9LuWghuB+XxBIa70 ugRXL/vM6Iue64Nk2pxoydQADzL5Qj9SPIzdIivk+YC48acMNxBu6aJzwBGcIfOpy2Uq U+WFWOc2oLZI4UguEgRPZ+lESn/F0vzSUn4C/Jjk2KGg7Kt/LcZBNICWTKe97zaFBS8L TOc4lApuE1j1o2Pyyo5ftbbp6EBUJZ++zez4HM3eml/u8+KWbUvuute4tt10n4OLBFXH skyw== 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=N/Hc8iNHVxaGeu0+z7sEpiztAldn0s4+Vfat2JueMaY=; b=nIMv2PkWAmCI3gpejIAJLBQJ8r5fw3dCvQ1PjU4sLg6bSE4GCnC5dYYe6z9wS2hfCD sV3b/TM7bbii0kfY7Oqux7cz9R/UKLZQb8dosM4W43XWKqROSsINaDHzcJw0DJTvhsTR xPRd8DpC53BchwTHwJPeKN64fEsyc5Jo+zJJBQXEDnCfK8SFfradi8Jp0PsY9m6Py8FP ZjkMdTr6Fo88aZ4XkGBkkE/IhDbzWNo5MQ/YkEUwOmkcr6A97aQyFe/KEOz1LBmea70p V/AnLdzeos0Ize78Z+Td0la69bRIRF6BRTZv/CcSJIVvdxNWubmEXVwNsBaRqJ2N6EeP KYrg== X-Gm-Message-State: AOAM532Q3ey+x86fvXvSt9yvtiDtTnNW/hAqpttavdf6HlbxPu8RqnFr lMmRQXTrdP61hx2wKezA5wrl8IU0RAs68Ifxaw== X-Google-Smtp-Source: ABdhPJwvtdC9ykfTDYXHw5K8+5BcdSCOukW2qi5aCSX8BJNnBmEpbXkBeAp77U+U4yu51pzmBUsJLXBBAawr0SDxp/8= X-Received: by 2002:ac8:5143:: with SMTP id h3mr12509699qtn.229.1598426943518; Wed, 26 Aug 2020 00:29:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 Aug 2020 10:28:53 +0300 Message-ID: To: Levi Morrison Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000002afc1005adc2c6ef" Subject: Re: [PHP-DEV] Segmentation Fault when trying to call zend_new_array. From: ivanzanev477@gmail.com (Ivan Zanev) --0000000000002afc1005adc2c6ef Content-Type: text/plain; charset="UTF-8" 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 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. > --0000000000002afc1005adc2c6ef--