From nobody Mon Feb 9 20:09:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1498158929907828.1095168150182; Thu, 22 Jun 2017 12:15:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B862C07454E; Thu, 22 Jun 2017 19:15:28 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B67BD68D46; Thu, 22 Jun 2017 19:15:27 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 388BC184383E; Thu, 22 Jun 2017 19:15:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5MJEFqO013758 for ; Thu, 22 Jun 2017 15:14:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 76E0E600C8; Thu, 22 Jun 2017 19:14:15 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71B8219658 for ; Thu, 22 Jun 2017 19:14:13 +0000 (UTC) Received: from mail-qk0-f180.google.com (mail-qk0-f180.google.com [209.85.220.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0375843A25 for ; Thu, 22 Jun 2017 19:14:12 +0000 (UTC) Received: by mail-qk0-f180.google.com with SMTP id d14so19992947qkb.1 for ; Thu, 22 Jun 2017 12:14:11 -0700 (PDT) Received: from dawid-fedora.datto.lan ([47.19.105.250]) by smtp.gmail.com with ESMTPSA id g39sm1837145qtc.12.2017.06.22.12.14.10 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Jun 2017 12:14:10 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0B862C07454E Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0B862C07454E Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=datto-com.20150623.gappssmtp.com header.i=@datto-com.20150623.gappssmtp.com header.b="NgOFnc+m" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0375843A25 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=datto.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dzamirski@datto.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0375843A25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datto-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=3F+DFXvokWcMfxyG5gOV68QhQNSc+iMButqJULfCykc=; b=NgOFnc+mrKcvu176bXPJRZjggCgEvwMO1Jd7B9Xp+p6qCbwepYJYPHuuWxJVdvV+GP leMUPl4Tls71o1t6ykUSOUl6E7zQih5UvHA5cN/z91igJhd/t/PgCADKm31FzouiJ6wz 9+B9GEH6bwZ3noeplylRlk8sQUmZ0Y11zpvsrdGQVcLHoEQcOh9K3648Fv35Zel45hDk u6AU8Wwz0fZI7i1WVoUeOKoEzV2CWe1fZ8fTMyauYf6a2rxRYiypQnudc7xE4fkqbx7U fiJGwbbUcmXoPPUbefKgMJ7aAeysPDlJKnnXG3iuC+n0/e557R1LFB7Q3IAEm534z+ey P8Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=3F+DFXvokWcMfxyG5gOV68QhQNSc+iMButqJULfCykc=; b=GG832g6ePP9GJJ/YBdObjCfT/zj81x/DRRbUm+NYaxWJvgy37Fl/F5AbIb5/oDesIs ed5iazLSbES3SPhUpQF9GwkslvvtQ7o+dESyqbXa9DRQmZ0FkDWljtxkCCuJLYgtCUg5 jSc02yfp5mdHpRj/1ey58jJIbOAXjljOwTq5ASja/B9rNwVEDCe7io6cjoZvnY8AxKzR YShA+gfH8zvs+B65pCyMg56NyqYj1ZThPbiS+mUI4M865vX0RbdDlil6F+98x7Lc1zXQ WlTzqCEMWsMKgX1YQ7jsVtbQA22RoRuIO7JPZoUa2HC4D7voRQRcq80yLBBkz4O8z+un UUtw== X-Gm-Message-State: AKS2vOxZzejWxpTRtt/l3nHd06t6ddWISHtRnbXf7//xvimJclYlNkji k9jNIrty5iiqk/bbxuj/eA== X-Received: by 10.55.155.141 with SMTP id d135mr4535273qke.11.1498158851021; Thu, 22 Jun 2017 12:14:11 -0700 (PDT) From: Dawid Zamirski To: libvir-list@redhat.com Date: Thu, 22 Jun 2017 15:14:04 -0400 Message-Id: <20170622191407.15570-5-dzamirski@datto.com> In-Reply-To: <20170622191407.15570-1-dzamirski@datto.com> References: <20170622191407.15570-1-dzamirski@datto.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 22 Jun 2017 19:14:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 22 Jun 2017 19:14:12 +0000 (UTC) for IP:'209.85.220.180' DOMAIN:'mail-qk0-f180.google.com' HELO:'mail-qk0-f180.google.com' FROM:'dzamirski@datto.com' RCPT:'' X-RedHat-Spam-Score: 0.369 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.220.180 mail-qk0-f180.google.com 209.85.220.180 mail-qk0-f180.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [libvirt-php PATCH 4/7] fix libvirt_doman_get_connect implementation. X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 22 Jun 2017 19:15:28 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This function must bump refcount of the returned resource because it just returns the one that was registered with libvirt_connect call, otherwise it would sefgault if calling code called this function more than once and the return of the first call would be GCd before the 2nd call. --- src/libvirt-php.c | 18 ++++++------------ src/libvirt-php.h | 14 +++++++++----- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/libvirt-php.c b/src/libvirt-php.c index 73466f1..89b17bb 100644 --- a/src/libvirt-php.c +++ b/src/libvirt-php.c @@ -2177,13 +2177,8 @@ PHP_FUNCTION(libvirt_connect) resource_change_counter(INT_RESOURCE_CONNECTION, NULL, conn->conn, 1 T= SRMLS_CC); DPRINTF("%s: Connection to %s established, returning %p\n", PHPFUNC, u= rl, conn->conn); =20 -#if PHP_MAJOR_VERSION >=3D 7 - conn->resource_id =3D zend_register_resource(conn, le_libvirt_connecti= on); - ZVAL_RES(return_value, conn->resource_id); -#else - ZEND_REGISTER_RESOURCE(return_value, conn, le_libvirt_connection); - conn->resource_id =3D Z_LVAL_P(return_value); -#endif + VIRT_REGISTER_RESOURCE(conn, le_libvirt_connection); + conn->resource =3D VIRT_RESOURCE_HANDLE(return_value); } =20 /* @@ -7216,11 +7211,10 @@ PHP_FUNCTION(libvirt_domain_get_connect) conn =3D domain->conn; if (conn->conn =3D=3D NULL) RETURN_FALSE; -#if PHP_MAJOR_VERSION >=3D 7 - ZVAL_RES(return_value, conn->resource_id); -#else - RETURN_RESOURCE(conn->resource_id); -#endif + + VIRT_RETURN_RESOURCE(conn->resource); + /* since we're returning already registered resource, bump refcount */ + Z_ADDREF_P(return_value); } =20 /* diff --git a/src/libvirt-php.h b/src/libvirt-php.h index 0422661..ed6a8bc 100644 --- a/src/libvirt-php.h +++ b/src/libvirt-php.h @@ -122,6 +122,7 @@ typedef uint64_t arch_uint; #if PHP_MAJOR_VERSION >=3D 7 typedef size_t strsize_t; typedef zend_resource virt_resource; +typedef virt_resource *virt_resource_handle; =20 #define VIRT_RETURN_RESOURCE(_resource) \ RETVAL_RES(_resource) @@ -135,6 +136,9 @@ typedef zend_resource virt_resource; add_next_index_zval(return_value, &zret); \ } while(0) =20 +#define VIRT_RESOURCE_HANDLE(_resource) \ + Z_RES_P(_resource) + #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ if ((_state =3D (_type)zend_fetch_resource(Z_RES_P(*_zval), _name, _le= )) =3D=3D NULL) { \ RETURN_FALSE; \ @@ -179,6 +183,7 @@ typedef int strsize_t; typedef long zend_long; typedef unsigned long zend_ulong; typedef zend_rsrc_list_entry virt_resource; +typedef long virt_resource_handle; =20 #define VIRT_RETURN_RESOURCE(_resource) \ RETVAL_RESOURCE((long) _resource) @@ -193,6 +198,9 @@ typedef zend_rsrc_list_entry virt_resource; add_next_index_zval(return_value, zret); \ } while(0) =20 +#define VIRT_RESOURCE_HANDLE(_resource) \ + Z_LVAL_P(_resource) + #define VIRT_FETCH_RESOURCE(_state, _type, _zval, _name, _le) \ ZEND_FETCH_RESOURCE(_state, _type, _zval, -1, _name, _le); =20 @@ -298,11 +306,7 @@ typedef struct tVMNetwork { /* Libvirt-php types */ typedef struct _php_libvirt_connection { virConnectPtr conn; -#if PHP_MAJOR_VERSION >=3D 7 - zend_resource *resource_id; -#else - long resource_id; -#endif + virt_resource_handle resource; } php_libvirt_connection; =20 typedef struct _php_libvirt_stream { --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list