Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:28174 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92916 invoked by uid 1010); 27 Feb 2007 22:03:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 92901 invoked from network); 27 Feb 2007 22:03:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2007 22:03:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=marco.cova@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=marco.cova@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.134.188 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: marco.cova@gmail.com X-Host-Fingerprint: 209.85.134.188 mu-out-0910.google.com Received: from [209.85.134.188] ([209.85.134.188:22648] helo=mu-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 98/7E-04907-3BAA4E54 for ; Tue, 27 Feb 2007 17:03:33 -0500 Received: by mu-out-0910.google.com with SMTP id i10so1802822mue for ; Tue, 27 Feb 2007 14:03:29 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=kkgS0SEHfXL8gr1RKjVBbMazhARSu1U9Z3kaNP7aRaIi9hsp35Gl+c6mQlsFMGekobnxVeaNwcrFhF9xM0zlqB/vkvAcd6m3hm2p8aQHrklu8ftaNdJCpRZPoq3Kkv2dwveMJMN/4OGuRd5dlL2UhsDxYK6e/IWTYhxAI5eqAow= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=uMhgDg0ypT2CwJR1eqFsL4/NTHNo+nrDV7zaJ09Dd7L0xQ90pAOePHwVAA/SvOn/xt5f2NjWyrrMSVolqii90d5zxW8M2F3AUXF+FGbu3w4//5Psy+rmQ1joJUrQP7/VYsRrYyUzicWPFyebo0jf41JGhDWl7Zl45w8Xoaz+akg= Received: by 10.82.175.2 with SMTP id x2mr2315955bue.1172613808850; Tue, 27 Feb 2007 14:03:28 -0800 (PST) Received: by 10.82.181.3 with HTTP; Tue, 27 Feb 2007 14:03:28 -0800 (PST) Message-ID: Date: Tue, 27 Feb 2007 14:03:28 -0800 To: internals@lists.php.net MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: custom handler for specific zend_ops From: marco.cova@gmail.com ("Marco Cova") Hi all. [Please, let me know if there is a better place to ask such questions.] In a Zend extension I'm working on, I need to perform some actions when certain instructions (zend_ops) are executed by the VM. Note that I'm interesting in specific instructions rather than instruction types, e.g., the first echo zend_op of a function as opposed to all echo instructions. Also, I want the handler to be invoked only when an interesting statement is executed (in other words, determining whether a zend_op is interesting must be done before execution). The way I currently do that is as follows: I override the zend_compile_file function to retrieve the zend_op_array of a file, identify the interesting statements in the array, and override their handler (the handler field in the zend_op struct) with my custom handler: The custom handler looks like this: int custom_handler(ZEND_OPCODE_HANDLE_ARGS) { // do my stuff .... return zend_vm_get_opcode_handler(execute_data->opline->opcode, execute_data->opline)(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); } where zend_get_opcode_handler is a copy-and-paste of the static function in zend_vm_execute.h While this seems to work (on the limited tests I've run) it also looks too hackish to be the correct way to do this ;-) So, here's the question: is there a better way to achieve the same result? I've looked at the USER_OPCODE API, but it seems to me that the API doesn't allow to specify a handler for specific zend_ops (but let me know if I'm wrong!) Thanks in advance, Marco