Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60085 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 14181 invoked from network); 17 Apr 2012 16:12:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2012 16:12:43 -0000 Authentication-Results: pb1.pair.com smtp.mail=yader.hernandez@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yader.hernandez@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: yader.hernandez@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:53243] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DA/38-03996-9769D8F4 for ; Tue, 17 Apr 2012 12:12:42 -0400 Received: by obbup16 with SMTP id up16so1820455obb.29 for ; Tue, 17 Apr 2012 09:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=guM3iFw+R2Z2UTWFKomOcqc1DzshCIvaN/SBt55lSqM=; b=NEEkENEkEjlmNf3UHGggEF6vEPKtZ6oTbHVWGDVkzNMDPkdsWl4Ze0zywstX1o9raP UpWOybA7OyQxGcOHvi/aTanYoqBEnRr7r2Ur9T7tFFRngHPtsy5hXk2PJ+w5jOSmZf5H wTeDr121F5snSi4WLAThhhdcNmaDePOcdFZvnCfw3qN0XKUbMG7KhELxbBNizTQIiDag WCCEmhlWSkyIKm5qcEBAp4yFoJ1TDE/CDLVo3rV0FSnF9WME4ILR/Jg88Hm7aEKk6DT2 lNneVTBUn1NvwDjkeMB4jMewlZFnGA/UAF3s/JW75lcWGrziXw+87tNxbmMSHoh37DV9 l4Ow== MIME-Version: 1.0 Received: by 10.182.192.39 with SMTP id hd7mr22004615obc.47.1334679158744; Tue, 17 Apr 2012 09:12:38 -0700 (PDT) Received: by 10.60.147.199 with HTTP; Tue, 17 Apr 2012 09:12:38 -0700 (PDT) In-Reply-To: References: Date: Tue, 17 Apr 2012 09:12:38 -0700 Message-ID: To: Laruence Cc: PHP Developers Mailing List Content-Type: multipart/alternative; boundary=14dae9399c5d25684d04bde2352c Subject: Re: [PHP-DEV] EXC_BAD_ACCESS, Could not access memory zval array type From: yader.hernandez@gmail.com (Yader Hernandez) --14dae9399c5d25684d04bde2352c Content-Type: text/plain; charset=ISO-8859-1 On Tue, Apr 17, 2012 at 12:06 AM, Laruence wrote: > Hi: > > you can core dump the backtrace, then exam the related hash table to > find out what's going wrong there. So the problem doesn't seem to be with contains() at all. The problem is actually coming from another method I implemented called ArrayList::append(mixed $element). I figured it out by calling contains first and I noticed it didn't cause a segfault. appends() seems rather trivial but I guess I was wrong: /* {{{ proto public boolean ArrayList::append(mixed $element) Add an element to the end of the list */ ZEND_METHOD(arraymap_class, append) { zval *object = getThis(); zval *element; arraylist_object *intern; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &element) == FAILURE) { RETURN_FALSE; } intern = (arraylist_object *) zend_object_store_get_object(object TSRMLS_CC); if (add_next_index_zval(intern->elements, element) == SUCCESS) { Z_ADDREF_P(element); /* increases ref count */ intern->size++; RETURN_TRUE; } RETURN_FALSE; } This method returns true, as expected. > 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) > fixed. > 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]) > > Returns true if this list contains the specified element. */ > > ZEND_METHOD(arraymap_class, contains) { > > zval *element; > > zend_bool strict = 0; /* strict comparison or not */ > > > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &element, > > &strict) == FAILURE) { > > RETURN_FALSE; > > } > > > > zval *this = getThis(); > > arraylist_object *intern; > > > > intern = (arraylist_object *) zend_object_store_get_object(this > > TSRMLS_CC); > > > > /* Don't use "ht" as a variable, it's already being used. All > ZEND_METHOD > > have "ht" defined. */ > > HashTable *hash_table = Z_ARRVAL_P(intern->elements); > > HashPosition pos; > > zval **current; > > zval res; /* comparison result */ > > > > int (*is_equal_func)(zval *, zval *, zval * TSRMLS_DC) = > > is_equal_function; > > > > if (strict) { > > is_equal_func = is_identical_function; > > } > > > > zend_hash_internal_pointer_reset_ex(hash_table, &pos); > > > > while (zend_hash_get_current_data_ex(hash_table, (void **)¤t, > &pos) > > == SUCCESS) { > > is_equal_func(&res, element, *current TSRMLS_CC); > > > > if (Z_LVAL(res)) { > > RETURN_TRUE; > > } > > > > zend_hash_move_forward_ex(hash_table, &pos); > > } > > > > RETURN_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 > that > > seems correct too: > > > > static zend_object_value create_arraylist_object(zend_class_entry *ce > > TSRMLS_DC) /* {{{ */ > > { > > zend_object_value retval; > > arraylist_object *intern; > > > > intern = emalloc(sizeof(arraylist_object)); > > > > intern->size = 0; > > > > zend_object_std_init(&intern->std, ce TSRMLS_CC); > > > > ALLOC_INIT_ZVAL(intern->elements); > > array_init(intern->elements); > > > > intern->std.ce = ce; > > > > object_properties_init(&intern->std, ce); > > > > retval.handle = zend_objects_store_put(intern, NULL, > > destroy_arraylist_object, NULL TSRMLS_CC); > > retval.handlers = &arraylist_object_handlers; > > > > return retval; > > } > > /* }}} */ > > > > I'm not getting any compilation errors or any type of warnings. > Everything > > seems to be glueing itself correctly. > > > > I'm hoping someone can see what I'm doing wrong so that I can move > forward > > with this. > > > > thanks! > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/ > --14dae9399c5d25684d04bde2352c--