Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111691 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22255 invoked from network); 26 Aug 2020 08:57:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Aug 2020 08:57:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C70A21804B4 for ; Wed, 26 Aug 2020 01:00:55 -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_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-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 01:00:55 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id j15so471865lfg.7 for ; Wed, 26 Aug 2020 01:00:55 -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=TFItYFt6n5kch9uT2rqFjtBuJMikbA25RJN+PqFH2Yw=; b=b2BcqTCxnJUkZLekbxTHz5UnuL03HemRfCsV71UGt1gehuiIng3JJVowD8+alxhgrD Vs/7D/fAQYFKVjoyagk5AHd78HTXrUxoQ/dg/iblfFjqVFZsqP7pZSqtnTnEla8tlXSY Ov7NqnrDHRzN2QExtQVeS+FnXEypsoUnn/jf0Gte7NwwPcZtnSYF0lNMJt1klvZkorxA nRk3kGeFKKNCEPcTYwTW8w/f6qmO/ikorbwP7x3vI8/vbK6P034eRS6j2PzcHyJRnaN1 9crsveX79AnuA9lLcbR24Yl0hdmnh3ENk66mPRf4tN+LqyTiANTKbvNxLc00AmExBRr5 lQHA== 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=TFItYFt6n5kch9uT2rqFjtBuJMikbA25RJN+PqFH2Yw=; b=A3XEvOjANmpKhkBQM1GPHze8LwKp/UMpfgc3AaTaHXm7CjPV12G1AXllGUB3qSsrCX ltgelet7177pHgHwj/4OvY5/17Ibama4Y+Hh1l+Co4VFvayTG5Z66IFIJgurL0wJwOvS cqCs7CAjoJ8ewwOQ9PiBsonwNdtoQirxO3H4pOQicUwPw8mRl+kH0lRU3kxV/WV5SKaj Opm7JIyhEBgEwak7ZlpW+hc7u6/dlC/jEfltZDh/uSqBfCI6zFR53hQAED6VS2xiZeMU YhhMRxjMaE0unq5oS14bHjLvtOIkMhwnFO8gw+JKDcYGC3VBt22SEaPRWRtXwTYQTEqV u0yg== X-Gm-Message-State: AOAM5312x6M0XdOY4UAp3jRRpnhLfoHJPEsLIACnQbnyqkyd16GKnoLK nbJywOJtURIj5UmSxInoZj/GcNBm2LmQ9gArah0= X-Google-Smtp-Source: ABdhPJxAaOqivsHcYNMd/ocu84xXUfnEYouIvpuXa+EiDYP3PkI0ri+T1zTZiXND3e5NQEAQ7jmVSM+ojQLY1sfSZsg= X-Received: by 2002:a19:5042:: with SMTP id z2mr6603792lfj.171.1598428850713; Wed, 26 Aug 2020 01:00:50 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 Aug 2020 10:00:34 +0200 Message-ID: To: Ivan Zanev Cc: Levi Morrison , PHP internals Content-Type: multipart/alternative; boundary="000000000000d8795d05adc3371b" Subject: Re: [PHP-DEV] Segmentation Fault when trying to call zend_new_array. From: alexinbeijing@gmail.com (Alex) --000000000000d8795d05adc3371b Content-Type: text/plain; charset="UTF-8" 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 ". 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 > > 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. > > > --000000000000d8795d05adc3371b--