Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59453 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29459 invoked from network); 8 Apr 2012 06:36:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Apr 2012 06:36:45 -0000 Authentication-Results: pb1.pair.com header.from=yader.hernandez@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yader.hernandez@gmail.com; spf=pass; 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:56970] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F2/35-29109-CF1318F4 for ; Sun, 08 Apr 2012 02:36:45 -0400 Received: by obbeh20 with SMTP id eh20so5035818obb.29 for ; Sat, 07 Apr 2012 23:36:42 -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:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=IMWYQGCNOKIipIFHWZyv2881QixAWTJ0wlTFeCKb7mc=; b=XnDWsyxEsXF8a/Xqq+qu5QHrrJPaR8V3xqlIiPeeD2VZD0YDkLUoAhLIBy5QCioG5u 2lHxZ48dVZze6iiXmTInLUF1vdApf04KCsNcF3tK1nm+4R9Uzzji77MF7BMfG1N9nCql 90j+YpyBB4q5MtfqKjb6HBEFaKtNVdsbJRpgvX+gJSDobOv049IN+xrZ7mVV0Yfa7jZi XUlmw0K9yiLwpeiEGavmlJjavMyqKuwyx3er9z974TBs0qC6LqqTIzldv6tkNSe5fbc4 /+F2D+JAUPwD36jiCEtYRIFFDGsbcUmxhIDEAkaNxvcoM4JDCrSR7yS3Bp1g8QjqIfPj BgWQ== MIME-Version: 1.0 Received: by 10.182.192.39 with SMTP id hd7mr4431214obc.47.1333867002133; Sat, 07 Apr 2012 23:36:42 -0700 (PDT) Sender: yader.hernandez@gmail.com Received: by 10.60.147.199 with HTTP; Sat, 7 Apr 2012 23:36:42 -0700 (PDT) In-Reply-To: <2489245882729818767@unknownmsgid> References: <1333834026.4220.6.camel@guybrush> <2489245882729818767@unknownmsgid> Date: Sat, 7 Apr 2012 23:36:42 -0700 X-Google-Sender-Auth: RfgLOAQaEMj1PltN1pa5SrmHUB8 Message-ID: To: Xinchen Hui Cc: PHP Internals Content-Type: multipart/alternative; boundary=14dae9399c5dd6fe7e04bd251caa Subject: Re: [PHP-DEV] how do you create a private property as an array in a class From: proxilabs@gmail.com (Matthew Hernandez) --14dae9399c5dd6fe7e04bd251caa Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks. How can I valgrind my extension? Google isn't bringing up many php extension topics :/ I can't figure out why I keep getting a seg fault: typedef struct _foo_object { zend_object std; zval *elements; } foo_object; static foo_object *foo_object_ptr; PHP_MINIT_FUNCTION(foo_class) { foo_object_ptr =3D emalloc(sizeof(foo_object)); MAKE_STD_ZVAL(foo_object_ptr->elements); array_init(foo_object_ptr->elements); return SUCCESS; } MAKE_STD_ZVAL(foo_object_ptr->elements); array_init(foo_object_ptr->elements); These two lines are causing the seg fault, I'm trying to understand why. On Sat, Apr 7, 2012 at 8:41 PM, Xinchen Hui wrote: > hi=EF=BC=9A > You can refer to ext spl array > > Thanks > > Sent from my iPhone > > =E5=9C=A8 2012-4-8=EF=BC=8C7:12=EF=BC=8CMatthew Hernandez =E5=86=99=E9=81=93=EF=BC=9A > > > Here's what I have so far: > > > > typedef struct _foo_class_object { > > zend_object std; > > zval *elements; > > int size; > > } foo_class_object; > > > > static foo_class_object *foo_class_object_ptr; > > static zend_class_entry *foo_class_ptr; > > > > ZEND_METHOD(foo_class, __construct) { > > foo_class_object_ptr =3D (foo_class_object > > *)zend_object_store_get_object(getThis() TSRMLS_CC); > > > > array_init(foo_class_object_ptr->elements); > > } > > > > ZEND_METHOD(foo_class, add) { > > zval *this =3D getThis(); > > zval *item; > > > > if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &item) =3D=3D > > FAILURE) { > > RETURN_FALSE; > > } > > > > add_next_index_zval(foo_class_object_ptr->elements, item); > > > > RETURN_TRUE; > > } > > > > However, this doesn't work. when you call FooClass::add it causes a > > segfault. I'm sure I'm abusing something :) > > > > thx > > > > On Sat, Apr 7, 2012 at 2:38 PM, Matthew Hernandez >wrote: > > > >> Hi Johannes, > >> > >> Yes I just found out that I should extend instead of the approach I wa= s > >> thinking about. > >> > >> So I created this: > >> > >> typedef struct _foo_object { > >> zend_object std; > >> zval *array; > >> int size; > >> } foo_object; > >> > >> So the question is how do I correctly pass foo_object around so that I > can > >> manipulate *array ? Having a private variable would mean calling > getThis() > >> and handling it that way would be trivial. > >> > >> Are there any examples I could see? I'm using the slides from your > >> presentation in 2009 to help me. > >> > >> thanks > >> > >> On Sat, Apr 7, 2012 at 2:27 PM, Johannes Schl=C3=BCter < > johannes@schlueters.de>wrote: > >> > >>> Hi, > >>> > >>> On Sat, 2012-04-07 at 11:23 -0700, Matthew Hernandez wrote: > >>>> This is my first extension I'm working on. I'm trying to make a clas= s > >>>> available to the user space with 1 private property that is an array= . > >>> > >>> The first question is: Why? - Why add the overhead of creating such a= n > >>> array if it is private? In most cases it is better to extend the > >>> zend_object in C (struct my_object { zend_object inner; type > >>> some_data;}) to hold private data. If you want to show it in var_dump > or > >>> a debugger you could implement a debug_info hook. > >>> > >>> johannes > >>> > >>> > >>> > >> > --14dae9399c5dd6fe7e04bd251caa--