Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60059 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44353 invoked from network); 17 Apr 2012 07:06:59 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2012 07:06:59 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:64772] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/A1-34429-0961D8F4 for ; Tue, 17 Apr 2012 03:06:56 -0400 Received: by vcbfo14 with SMTP id fo14so4577981vcb.29 for ; Tue, 17 Apr 2012 00:06:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=z4euBfIuhBTxlAdlud4Om0BBm8q8zwPBHORgURp42JM=; b=W7qECeDMVaz+7KZ2oEhLbp29eV4Z+laMaujx1dHpDUflRouHQGSBNUy28fFeIbEzRd s5028ACV2lluOsOzDzCs+4LJ+sSNUswi/d0D3xweT0cwQHh+dHgDOtdAYDpCkatJVAwx rxKHa58xZaP/LXvC1TrPy18kBc0KTwLb0SfMWVt4MEinOF4lsnPy1XAU7KssTKPprmHe +sETrkccJ1uE/y31amLGiPlXCRgiyGbdlU4dldsYvHXLaDses2MVKnQehLCrCleT5NNb QAN/w3SMDl/TLfEFBRvNLMfAAZiVrUvtWBS9OqlIKcMHAKu9mKi7ijuS7Fp6nUBc/ylV 41fg== Received: by 10.52.91.72 with SMTP id cc8mr6847554vdb.17.1334646413075; Tue, 17 Apr 2012 00:06:53 -0700 (PDT) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.220.180.203 with HTTP; Tue, 17 Apr 2012 00:06:32 -0700 (PDT) In-Reply-To: References: Date: Tue, 17 Apr 2012 15:06:32 +0800 X-Google-Sender-Auth: k0Zr3I4ETH7mcCAke4o-3xmthX4 Message-ID: To: Yader Hernandez Cc: PHP Developers Mailing List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] EXC_BAD_ACCESS, Could not access memory zval array type From: laruence@php.net (Laruence) Hi: you can core dump the backtrace, then exam the related hash table to find out what's going wrong there. and some maybe un-relevant issues: 1. plz put all var declarations at the begining of a block (C89) 2. do not use "this" keyword as variable name (it's C++ keyword) thanks On Tue, Apr 17, 2012 at 2:12 PM, Yader Hernandez wrote: > Hello, > > I'm trying to create an ArrayList as an extension. I'm currently > implementing ArrayList::contains(mixed $element) but I'm running into a > blocking issue. > > It's currently causing a segfault when you call contains. I've tried to > track down what I'm doing wrong, but I've had no luck with it. > > When running gdb this is what I get: > > Program received signal EXC_BAD_ACCESS, Could not access memory. > Reason: 13 at address: 0x00000000000000000x00000001005812ca in > _zend_is_inconsistent > > /* {{{ proto public boolean ArrayList::contain(mixed $element[, boolean > strict]) > =C2=A0Returns true if this list contains the specified element. */ > ZEND_METHOD(arraymap_class, contains) { > =C2=A0zval *element; > =C2=A0zend_bool strict =3D 0; =C2=A0 /* strict comparison or not */ > > =C2=A0if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &elemen= t, > &strict) =3D=3D FAILURE) { > =C2=A0 =C2=A0RETURN_FALSE; > =C2=A0} > > =C2=A0zval *this =3D getThis(); > =C2=A0arraylist_object *intern; > > =C2=A0intern =3D (arraylist_object *) zend_object_store_get_object(this > TSRMLS_CC); > > =C2=A0/* Don't use "ht" as a variable, it's already being used. All ZEND_= METHOD > have "ht" defined. */ > =C2=A0HashTable *hash_table =3D Z_ARRVAL_P(intern->elements); > =C2=A0HashPosition pos; > =C2=A0zval **current; > =C2=A0zval res; /* comparison result */ > > =C2=A0int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) =3D > is_equal_function; > > =C2=A0if (strict) { > =C2=A0 =C2=A0is_equal_func =3D is_identical_function; > =C2=A0} > > =C2=A0zend_hash_internal_pointer_reset_ex(hash_table, &pos); > > =C2=A0while (zend_hash_get_current_data_ex(hash_table, (void **)¤t,= &pos) > =3D=3D SUCCESS) { > =C2=A0 =C2=A0is_equal_func(&res, element, *current TSRMLS_CC); > > =C2=A0 =C2=A0if (Z_LVAL(res)) { > =C2=A0 =C2=A0 =C2=A0RETURN_TRUE; > =C2=A0 =C2=A0} > > =C2=A0 =C2=A0zend_hash_move_forward_ex(hash_table, &pos); > =C2=A0} > > =C2=A0RETURN_FALSE; > } > > I can't seem to spot any errors with this implementation. The next thing = I > thought that could be wrong is how I'm creating elements pointer, but tha= t > seems correct too: > > static zend_object_value create_arraylist_object(zend_class_entry *ce > TSRMLS_DC) /* {{{ */ > { > =C2=A0zend_object_value retval; > =C2=A0arraylist_object *intern; > > =C2=A0intern =3D emalloc(sizeof(arraylist_object)); > > =C2=A0intern->size =3D 0; > > =C2=A0zend_object_std_init(&intern->std, ce TSRMLS_CC); > > =C2=A0ALLOC_INIT_ZVAL(intern->elements); > =C2=A0array_init(intern->elements); > > =C2=A0intern->std.ce =3D ce; > > =C2=A0object_properties_init(&intern->std, ce); > > =C2=A0retval.handle =3D zend_objects_store_put(intern, NULL, > destroy_arraylist_object, NULL TSRMLS_CC); > =C2=A0retval.handlers =3D &arraylist_object_handlers; > > =C2=A0return retval; > } > /* }}} */ > > I'm not getting any compilation errors or any type of warnings. Everythin= g > seems to be glueing itself correctly. > > I'm hoping someone can see what I'm doing wrong so that I can move forwar= d > with this. > > thanks! --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/