Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111683 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95061 invoked from network); 25 Aug 2020 12:36:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Aug 2020 12:36:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 64C5F1804DA for ; Tue, 25 Aug 2020 04:39:37 -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,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-il1-f176.google.com (mail-il1-f176.google.com [209.85.166.176]) (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 ; Tue, 25 Aug 2020 04:39:36 -0700 (PDT) Received: by mail-il1-f176.google.com with SMTP id r13so10105048iln.0 for ; Tue, 25 Aug 2020 04:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=n8LMI3BeIqPbZ1lo1/Nb3RYoLWSWkPJ3p/X0Yd+iB48=; b=QgxYhSgtUiM9517d/JAGtlhk4ukrvApOu/C/o+7C+S2MRo2PIARC58fnkbhIswpX3q 3b1cxN3vQxyo3b7qKbG8rvQDRMHk3I22Dd6yMTqUUa4zLLmtabzdogSoRgeRJ+3RBwEz 3QOlWfpG5bzc5GyDntktizNUHzjLQveVHQE6Q= 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=n8LMI3BeIqPbZ1lo1/Nb3RYoLWSWkPJ3p/X0Yd+iB48=; b=PkMPy7o3Bn8mBv3HMRMOcoN8Hu+b5OniRQ85hbWj3xx4nzuBHaDFSf5eAwmdycXlTT ONh9U1sEo3BEkghkBtcStaoNqmvm132UQJVq9r1YUDNwow08eBXePyWpa0Z1t7lktiGC ApWvDl4TpRw1xqpz8fQag5ba50WNptLsNTZ8NIit02KzmGLvAhFwrHZ7LnJfZZJ5126c UqrzjpFYwhAFhiNM8AKnR96QzjEVPHYyx0VvDMEo2purVO0/8kpszRbkzy+Eygq4QcYg xa9Y6uIAs4bunsESFo1uCcumVvV3kv2K131H4tyFtyvL/FckoZGPqIThkI6SLxExV3bC lyVg== X-Gm-Message-State: AOAM5321fRkaofUJxwAZl2qNG59bsc40evT16xIkQmmjgk3NdsMZHhsF IuFpQF85C8YruTWg3m3Sb/iPQLoP1YpOozqikHtLtw== X-Google-Smtp-Source: ABdhPJy5bU3OgX5cD/8hh8wNaZEleIhrUm/7wchaOK6DJxf73VcYnDDuA2hOfAZkatAXQPB63GQqNqyC8VMdShw6ruc= X-Received: by 2002:a92:9881:: with SMTP id a1mr9108622ill.232.1598355575273; Tue, 25 Aug 2020 04:39:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Levi Morrison Date: Tue, 25 Aug 2020 05:39:24 -0600 Message-ID: To: Ivan Zanev Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Segmentation Fault when trying to call zend_new_array. From: internals@lists.php.net ("Levi Morrison via internals") 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.