Re: Segmentation Fault when trying to call zend_new_array.

From: Date: Wed, 26 Aug 2020 07:28:53 +0000
Subject: Re: Segmentation Fault when trying to call zend_new_array.
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-111687@lists.php.net to get a copy of this message
Yes, it does. I recompiled php now with --configure --enable-embed=static and wrote a simple script: #include <stdlib.h> #include <stdio.h> #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 <ivanzanev477@gmail.com> 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. >

« previous php.internals (#111687) next »