FAQ
Can you explain to me why the following causes a segfault:

[code]
PHP_FUNCTION(sample_var_a_exists)
{
if (!zend_hash_exists(EG(active_symbol_table), "a", sizeof("a"))) {
RETURN_BOOL(0);
}
RETURN_BOOL(1);
}
[/code]

Note: the segfault only occurs when the sample_var_a_exists function is
called from within a userspace function:

[code]
$a = '';
var_dump(sample_var_a_exists()); // bool(true)

function x() {
var_dump(sample_var_a_exists()); // segmentation fault
}

x();
[/code]

Thanks.

Search Discussions

  • Scott MacVicar at Nov 1, 2009 at 9:21 pm

    On 1 Nov 2009, at 21:09, Mark Skilbeck wrote:

    Can you explain to me why the following causes a segfault:

    [code]
    PHP_FUNCTION(sample_var_a_exists)
    {
    if (!zend_hash_exists(EG(active_symbol_table), "a", sizeof("a"))) {
    RETURN_BOOL(0);
    }
    RETURN_BOOL(1);
    }
    [/code]

    Note: the segfault only occurs when the sample_var_a_exists function
    is called from within a userspace function:

    [code]
    $a = '';
    var_dump(sample_var_a_exists()); // bool(true)

    function x() {
    var_dump(sample_var_a_exists()); // segmentation fault
    }

    x()
    There is no symbol table as there are no variables. You should check
    if it's NULL before using zend_hash_exists.

    Scott
  • Mark Skilbeck at Nov 1, 2009 at 9:24 pm

    Scott MacVicar wrote:
    On 1 Nov 2009, at 21:09, Mark Skilbeck wrote:

    [snip]
    There is no symbol table as there are no variables. You should check if
    it's NULL before using zend_hash_exists.

    Scott
    Ah - of course.

    Thanks for that, Scott.
  • Mark Skilbeck at Nov 1, 2009 at 9:41 pm

    Scott MacVicar wrote:
    On 1 Nov 2009, at 21:09, Mark Skilbeck wrote:

    [snip]
    There is no symbol table as there are no variables. You should check if
    it's NULL before using zend_hash_exists.

    Scott
    Hi, Scott. I'm having trouble - I added the check to see if the symbol
    table i available, yet it returns false even if I have added variables
    within the function:

    [code]
    PHP_FUNCTION(sample_var_a_exists)
    {
    if (!EG(active_symbol_table) ||
    !zend_hash_exists(EG(active_symbol_table), "a", sizeof("a"))) {
    RETURN_BOOL(0);
    }
    RETURN_BOOL(1);
    }
    [/code]

    [code]
    $a = '';
    var_dump(sample_var_a_exists());

    function x() {
    $a = ''; // Add a symbol to the hash table.
    var_dump(sample_var_a_exists()); // Shows bool(false)
    }

    x();
    [/code]
  • Scott MacVicar at Nov 1, 2009 at 10:48 pm

    On 1 Nov 2009, at 21:41, Mark Skilbeck wrote:

    Scott MacVicar wrote:
    On 1 Nov 2009, at 21:09, Mark Skilbeck <markskilbeck@gmail.com>
    wrote:
    [snip]
    There is no symbol table as there are no variables. You should
    check if it's NULL before using zend_hash_exists.
    Scott
    Hi, Scott. I'm having trouble - I added the check to see if the
    symbol table i available, yet it returns false even if I have added
    variables within the function:

    [code]
    PHP_FUNCTION(sample_var_a_exists)
    {
    if (!EG(active_symbol_table) ||
    !zend_hash_exists(EG(active_symbol_table), "a", sizeof("a"))) {
    RETURN_BOOL(0);
    }
    RETURN_BOOL(1);
    }
    [/code]

    [code]
    $a = '';
    var_dump(sample_var_a_exists());

    function x() {
    $a = ''; // Add a symbol to the hash table.
    var_dump(sample_var_a_exists()); // Shows bool(false)
    }

    x();
    [/code]

    --
    You probably want the following to build the symbol table.

    if (!EG(active_symbol_table)) {
    zend_rebuild_symbol_table(TSRMLS_C);
    }

    Scott
  • Mark Skilbeck at Nov 1, 2009 at 11:15 pm

    Scott MacVicar wrote:
    On 1 Nov 2009, at 21:41, Mark Skilbeck wrote:

    Scott MacVicar wrote:
    On 1 Nov 2009, at 21:09, Mark Skilbeck wrote:
    [snip]
    There is no symbol table as there are no variables. You should check
    if it's NULL before using zend_hash_exists.
    Scott
    Hi, Scott. I'm having trouble - I added the check to see if the symbol
    table i available, yet it returns false even if I have added variables
    within the function:

    [code]
    PHP_FUNCTION(sample_var_a_exists)
    {
    if (!EG(active_symbol_table) ||
    !zend_hash_exists(EG(active_symbol_table), "a",
    sizeof("a"))) {
    RETURN_BOOL(0);
    }
    RETURN_BOOL(1);
    }
    [/code]

    [code]
    $a = '';
    var_dump(sample_var_a_exists());

    function x() {
    $a = ''; // Add a symbol to the hash table.
    var_dump(sample_var_a_exists()); // Shows bool(false)
    }

    x();
    [/code]

    --
    You probably want the following to build the symbol table.

    if (!EG(active_symbol_table)) {
    zend_rebuild_symbol_table(TSRMLS_C);
    }

    Scott
    Yes, that works. Do you know why we have to rebuild it? I'd assume that
    the symbol table was built automatically?
  • Mark Skilbeck at Nov 2, 2009 at 3:07 pm

    Mark Skilbeck wrote:
    Scott MacVicar wrote:
    On 1 Nov 2009, at 21:41, Mark Skilbeck wrote:

    Scott MacVicar wrote:
    On 1 Nov 2009, at 21:09, Mark Skilbeck wrote:
    [snip]
    There is no symbol table as there are no variables. You should check
    if it's NULL before using zend_hash_exists.
    Scott
    Hi, Scott. I'm having trouble - I added the check to see if the
    symbol table i available, yet it returns false even if I have added
    variables within the function:

    [code]
    PHP_FUNCTION(sample_var_a_exists)
    {
    if (!EG(active_symbol_table) ||
    !zend_hash_exists(EG(active_symbol_table), "a",
    sizeof("a"))) {
    RETURN_BOOL(0);
    }
    RETURN_BOOL(1);
    }
    [/code]

    [code]
    $a = '';
    var_dump(sample_var_a_exists());

    function x() {
    $a = ''; // Add a symbol to the hash table.
    var_dump(sample_var_a_exists()); // Shows bool(false)
    }

    x();
    [/code]

    --
    You probably want the following to build the symbol table.

    if (!EG(active_symbol_table)) {
    zend_rebuild_symbol_table(TSRMLS_C);
    }

    Scott
    Yes, that works. Do you know why we have to rebuild it? I'd assume that
    the symbol table was built automatically?
    Anyone?
  • Felipe Pena at Nov 2, 2009 at 3:39 pm
    2009/11/2 Mark Skilbeck <markskilbeck@gmail.com>
    Anyone?
    See:
    http://markmail.org/message/33ee6aitsyqxgu6x#query:+page:1+mid:33ee6aitsyqxgu6x+state:results


    >
    --
    Regards,
    Felipe Pena

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedNov 1, '09 at 9:10p
activeNov 2, '09 at 3:39p
posts8
users3
websitephp.net

People

Translate

site design / logo © 2022 Grokbase