Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54821 invoked from network); 2 Feb 2015 05:43:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Feb 2015 05:43:31 -0000 Authentication-Results: pb1.pair.com header.from=laruence@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=xinchen.h@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: xinchen.h@zend.com X-Host-Fingerprint: 209.85.215.42 mail-la0-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:61101] helo=mail-la0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/90-47540-18E0FC45 for ; Mon, 02 Feb 2015 00:43:30 -0500 Received: by mail-la0-f42.google.com with SMTP id ms9so37237066lab.1 for ; Sun, 01 Feb 2015 21:43:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=coUusLqQkZl/xPvcAFLnh+gHaIEQrdg27RiUsFOB6/I=; b=gfMknQIJ8bJaeVlUr/kqFo8NQzChgziylS9E7uD2HZSra0MyaDOO5u5T7mqH3UdatB oVZN/wnUomFaKshjJWmvzKihn2xTY7430cN3mL8i27ujSU2E49BDUoMEr6vUlrVkLLrV G1wgXGs4kYcJKAQg4qSX/UlZAAKq5usNM+UP90LmjEXCLdN+KLvgCa44EgOuPDLUtFpj d1bfc0amX84y604eyAMpZnhud8UukTJGeCqmJtVIPpkDLSxWnQMiV6MIMzn7VrissMY1 6Ld0dPZeMH3pJGXEF4Y0WrbGUMfH5RrABMnFINAzWPALB0F/GP52UgA5bBhZD7rraTbj qw2Q== X-Gm-Message-State: ALoCoQkN2SBDf3HEfRd9uaxTX7Yq1GsoBz3+042y3+PpGUQ1kke2HUIrBW9n/+4dcboOPGoB+oiCqK5+gNe30ehyto/EVX2eR9UxhW/5Bq3OdhcqRRXlHXceH4kLcJ/WcZrnQE40d6Yo+eLLrUIvzm8wII/LFrzCWg== X-Received: by 10.152.4.233 with SMTP id n9mr17965092lan.61.1422855806202; Sun, 01 Feb 2015 21:43:26 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPSA id zz10sm4172493lbb.13.2015.02.01.21.43.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 01 Feb 2015 21:43:25 -0800 (PST) Received: by mail-la0-f52.google.com with SMTP id ge10so37326902lab.11 for ; Sun, 01 Feb 2015 21:43:24 -0800 (PST) X-Received: by 10.152.5.2 with SMTP id o2mr17962380lao.5.1422855804543; Sun, 01 Feb 2015 21:43:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.114.28.193 with HTTP; Sun, 1 Feb 2015 21:43:04 -0800 (PST) In-Reply-To: References: Date: Mon, 2 Feb 2015 13:43:04 +0800 Message-ID: To: PHP Internals , Dmitry Stogov Content-Type: text/plain; charset=UTF-8 Subject: Re: [DICUSS]Cleanup resource handling APIs From: laruence@php.net (Xinchen Hui) On Mon, Feb 2, 2015 at 1:34 PM, Xinchen Hui wrote: > Hey: > > we used to use lval of zval as a handle to access resource type.. > > but now, we introduced a new type IS_RESOURCE, which make the > handle(id) sort of redundant . > > further more, the common usage when handling resource is like: > > if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &result, > &offset) == FAILURE) { > return; > } > ZEND_FETCH_RESOURCE(mysql_result, MYSQL_RES *, result, -1, "MySQL > result", le_result); > > as you can see, we use "r" to receive a IS_RESOURCE type, that > means, check the type in ZEND_FETCH_RESOURCE is overhead.. > > and: > > ZEND_API void *zend_fetch_resource(zval *passed_id, int default_id, > const char *resource_type_name, int *found_resource_type, int > num_resource_types, ...) > > we use va_args to passing resource type, that means, the rescue > type arguments can not be passed by register but by stack.. which is a > little low effiicient . > > so, I'd like propose a zend_resource handling API cleanup.. > > 1. DROP ZEND_REGISTER_RESOURCE/FETCH_RESOURCE. > > 2. add : > > ZEND_API void *zend_fetch_resource(zend_resource *res, const > char *resource_type_name, int resource_type); > ZEND_API void *zend_fetch_resource2(zend_resource *res, const char > *resource_type_name, int *found_type, int resource_type, int > resource_type2); > ZEND_API void *zend_fetch_resource_ex(zval *res, const char > *resource_type_name, int resource_type); > ZEND_API void *zend_fetch_resource2_ex(zval *res, const char > *resource_type_name, int *found_type, int resource_type, int > resource_type2); > > a underworking patch could be found at: > https://github.com/php/php-src/pull/1042 > > any ideas & objections? furthermore, I'd like to discuss remove the handle in zend_resource struct.. it may breaks some usage (use resource as long/double/string) case IS_RESOURCE: { char buf[sizeof("Resource id #") + MAX_LENGTH_OF_LONG]; int len; len = snprintf(buf, sizeof(buf), "Resource id #" ZEND_LONG_FMT, (zend_long)Z_RES_HANDLE_P(op)); return zend_string_init(buf, len, 0); } thanks > > thanks > > -- > Xinchen Hui > @Laruence > http://www.laruence.com/ -- Xinchen Hui @Laruence http://www.laruence.com/