Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:40433 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19857 invoked from network); 10 Sep 2008 10:52:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Sep 2008 10:52:42 -0000 Authentication-Results: pb1.pair.com header.from=esnafrao@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=esnafrao@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 72.14.246.247 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: esnafrao@gmail.com X-Host-Fingerprint: 72.14.246.247 ag-out-0708.google.com Received: from [72.14.246.247] ([72.14.246.247:15977] helo=ag-out-0708.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/04-30769-AF6A7C84 for ; Wed, 10 Sep 2008 06:52:42 -0400 Received: by ag-out-0708.google.com with SMTP id 22so6526261agd.4 for ; Wed, 10 Sep 2008 03:52:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type:references; bh=/BnNs3udaz28x3WrIlELg5tym91SUdu5MpV8Ston4N0=; b=xjBx0e+GswhCbaB191l/y2mu7UM2gdJKGpzSmbNgP6gEyPXHX1nzwP7wNqC8GIiwtz NmENhRzgcouuQV3Cq9LSRuklmbYhLvcYUPTZH0UihH+CEQ0Spfz1zw+GcixBsKGnfmSd R5AssfFRecMbQm8aujkQR97bvze6mL2GGtAG0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:references; b=cDwIrTcpqNmeJ2vxFCHcL7rHDyy1MuB4VaglxbVH66ETrOFQcBOol0RWFODUjimfia 6OWw81vp7fDYHjVCNsewvEY5qWoIzfrjnBxBWL0HV12xcIKvon6A+gdRStFDM6N97vle G0nS9PAP0RMRABK9GwL8CChv/T90K1KL5lRjo= Received: by 10.67.115.2 with SMTP id s2mr6472055ugm.49.1221043958924; Wed, 10 Sep 2008 03:52:38 -0700 (PDT) Received: by 10.66.238.3 with HTTP; Wed, 10 Sep 2008 03:52:38 -0700 (PDT) Message-ID: <2a149c8c0809100352o754661eenee3544378224234a@mail.gmail.com> Date: Wed, 10 Sep 2008 12:52:38 +0200 To: "Marcus Boerger" Cc: "PHP Developers Mailing List" In-Reply-To: <2a149c8c0809100251g2dc6d459ma68f01c4a6ac8d80@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_28426_10847039.1221043958919" References: <2a149c8c0809080958j12ddbf84l2f0b533569d69557@mail.gmail.com> <564726435.20080908235504@marcus-boerger.de> <2a149c8c0809100251g2dc6d459ma68f01c4a6ac8d80@mail.gmail.com> Subject: Re: [PHP-DEV] array and call_user_function From: esnafrao@gmail.com ("mr esnafrao") ------=_Part_28426_10847039.1221043958919 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I have solved the problem. I had confused the functions hash_* with the funtions array_*. This works: MAKE_STD_ZVAL(hash); array_init(hash); g_hash_table_iter_init (&iter, m->params); while (g_hash_table_iter_next (&iter, &key, &value)) { add_assoc_string(hash, key, value, 0); } Thanks for your help and your patience :) AntP 2008/9/10 mr esnafrao > Thanks for your response, but I'm unable to make it work. I have changed > the code, and it works with strings and even with arrays, but not with > hashes: Am I missing something? > > zval *hash; > zval **args[2], *func, *retval; > zval *str; > > MAKE_STD_ZVAL(retval); > MAKE_STD_ZVAL(func); > ZVAL_STRING(func, estrdup(handler), 0); > > MAKE_STD_ZVAL(str); > ZVAL_STRING(str, estrdup(m->sender), 0); > > MAKE_STD_ZVAL(hash); > ALLOC_HASHTABLE(hash); > zend_hash_init(hash, 0, NULL, NULL, 1); > g_hash_table_iter_init (&iter, m->params); > while (g_hash_table_iter_next (&iter, &key, &value)) { > zend_hash_add(hash, > g_strdup(key), > strlen(key), > g_strdup(value), > strlen(value), > NULL); > } > > args[0] = &hash; > args[1] = &str; > if (call_user_function_ex(EG(function_table), > NULL, > func, > retval, > 2, > &args, > 0, > NULL TSRMLS_CC) == FAILURE) { > g_debug("error calling method: %s", handler); > } > ... > Thanks a lot! > AntP > > 2008/9/8 Marcus Boerger > >> Hello mr, >> >> Monday, September 8, 2008, 6:58:19 PM, you wrote: >> >> > Hi all, >> > I'm having problems passing an array to the function call_user_function >> as >> > parameter. This is the code: >> >> > zval *args[3], *func, *retval; >> >> args maust be *** not ** >> >> > MAKE_STD_ZVAL(func); >> > MAKE_STD_ZVAL(retval); >> > MAKE_STD_ZVAL(args[0]); >> > MAKE_STD_ZVAL(args[1]); >> > MAKE_STD_ZVAL(args[2]); >> > ALLOC_HASHTABLE(args[2]); >> >> > // creates hash and fills >> > zend_hash_init(args[2], 0, NULL, NULL, 0); >> > g_hash_table_iter_init (&iter, m->params); >> > while (g_hash_table_iter_next (&iter, &key, &value)) { >> > zend_hash_add(args[2], key, strlen(key), value, strlen(value), >> > NULL); >> > } >> >> > ZVAL_STRING(args[0], estrdup(m->sender), 0); >> > ZVAL_STRING(args[1], estrdup(m->cmd), 0); >> > ZVAL_STRING(func, estrdup(handler), 0); >> >> > if (call_user_function(EG(function_table), >> > NULL, >> > func, >> > retval, 3, >> > args TSRMLS_CC) == FAILURE) { >> > g_debug("error calling method: %s", handler); >> > } >> >> > zval_dtor(retval); >> > zval_dtor(func); >> > zval_dtor(args[0]); >> > zval_dtor(args[1]); >> > zend_hash_destroy(args[2]); >> > FREE_HASHTABLE(args[2]); >> args[2] is wrong and anyway all three need to be zval_ptr_dtor() >> >> marcus >> >> > I suppose that the problem is the conversion between the Hash and the >> zval, >> > but I don't know how to do it. >> >> > Thanks in advance :) >> > regards >> >> >> >> Best regards, >> Marcus >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > ------=_Part_28426_10847039.1221043958919--