Hey,

ADT is the Abstract Data Type extension available on cvs.php.net, module
name "adt."  I'm nearing an alpha, but have one outstanding issue.  ADT
itself provides both a functional and an object oriented interface. The
following example shows the two ways you can use a stack.

Functional
--
<?php
$stack = adt_stack_new();
for ($i = 0; $i < 100; ++$i) {
    adt_stack_push($stack, $i);
}

var_dump(adt_stack_pop($stack));
adt_stack_free($stack);
?>

Object Oriented
--
<?php
$stack = new adt_stack();
for ($i = 0; $i < 100; ++$i) {
    $stack->push($i);
}

var_dump($stack->pop());
$stack->destroy();
?>

ADT works fine with Zend Engine version 1, however, when using Zend
Engine 2, the code segfaults when registering a new object:

zend_hash_apply_with_argument (ht=0x0, apply_func=0x81117a0
<zval_update_constant>, argument=0x0)
    at /home/sterling/work/os/php/php5/Zend/zend_hash.c:702
702             HASH_PROTECT_RECURSION(ht);
(gdb) bt
#0  zend_hash_apply_with_argument (ht=0x0, apply_func=0x81117a0
<zval_update_constant>, argument=0x0)
    at /home/sterling/work/os/php/php5/Zend/zend_hash.c:702
#1  0x081196fa in _object_and_properties_init (arg=0x402c3a8c,
class_type=0x8171000, properties=0x0)
    at /home/sterling/work/os/php/php5/Zend/zend_API.c:588
#2  0x0811971b in _object_init_ex (arg=0x402c3a8c, class_type=0x8171000)
    at /home/sterling/work/os/php/php5/Zend/zend_API.c:610
#3  0x0806591c in adt_register_resource (tptr=0x81b67c0, le_id=15,
r_id=0x402c2d2c, obj=0x402c3a8c, cp=0x8171000, 
    id=0x81b67d0) at
/home/sterling/work/os/php/php5/ext/adt/php_adt.c:127
#4  0x08067a5e in zif_adt_stack_new (ht=0, return_value=0x402c3aac,
this_ptr=0x402c3a8c, return_value_used=0)
    at /home/sterling/work/os/php/php5/ext/adt/php_stack.c:53
#5  0x081276cc in zend_do_fcall_common_helper (execute_data=0xbfffd730,
op_array=0x402c21ac)
    at /home/sterling/work/os/php/php5/Zend/zend_execute.c:2566
#6  0x0812426f in execute (op_array=0x402c21ac) at
/home/sterling/work/os/php/php5/Zend/zend_execute.c:1218
#7  0x081188f3 in zend_execute_scripts (type=8, retval=0x0,
file_count=3)
    at /home/sterling/work/os/php/php5/Zend/zend.c:996
#8  0x080f57e8 in php_execute_script (primary_file=0xbffffa10) at
/home/sterling/work/os/php/php5/main/main.c:1691
#9  0x0812c4ed in main (argc=2, argv=0xbffffaa4) at
/home/sterling/work/os/php/php5/sapi/cli/php_cli.c:753

The relevant code relating to this segfault is:

object_init_ex(obj, cp);

where obj is the zval * returned by getThis(), and cp represents a
zend_class_entry *, registered by the following code.

    INIT_CLASS_ENTRY(stack_class_entry, "adt_stack",
stack_class_functions);
    zend_register_internal_class(&stack_class_entry TSRMLS_CC);

and stack_class_entry is of type zend_class_entry.  cp is therefore a
pointer to the global stack_class_entry.  I'm running the non-threadsafe
version of php.

How can I make this code run with PHP 5?

-Sterling


-- 
"C makes it easy to shoot yourself in the foot; C++ makes it harder,  
 but when you do, it blows away your whole leg." 
    - Bjarne Stroustrup

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to