php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #62640
Patch mocking.patch revision 2012-07-23 13:31 UTC by lars at strojny dot net

Patch mocking.patch for amqp Bug #62640

Patch version 2012-07-23 13:31 UTC

Return to Bug #62640 | Download this patch
Patch Revisions:

Developer: lars@strojny.net

diff --git a/amqp_channel.c b/amqp_channel.c
index 94d0a77..b28c476 100644
--- a/amqp_channel.c
+++ b/amqp_channel.c
@@ -79,8 +79,7 @@ void amqp_channel_dtor(void *object TSRMLS_DC)
 	amqp_channel_object *channel = (amqp_channel_object*)object;
 	amqp_connection_object *connection;
 
-	connection = AMQP_GET_CONNECTION(channel);
-	
+	AMQP_ASSIGN_CONNECTION(connection, channel);
 	remove_channel_from_connection(connection, channel);
 	
 	/* Destroy the connection storage */
diff --git a/amqp_exchange.c b/amqp_exchange.c
index ddc090e..261187e 100644
--- a/amqp_exchange.c
+++ b/amqp_exchange.c
@@ -453,7 +453,7 @@ PHP_METHOD(amqp_exchange_class, declare)
 
 	exchange = (amqp_exchange_object *)zend_object_store_get_object(id TSRMLS_CC);
 
-	channel = AMQP_GET_CHANNEL(exchange);
+	AMQP_ASSIGN_CHANNEL(channel, exchange);
 	AMQP_VERIFY_CHANNEL(channel, "Could not declare exchange.");
 	
 	connection = AMQP_GET_CONNECTION(channel);
diff --git a/amqp_queue.c b/amqp_queue.c
index 5717e77..cc96fef 100644
--- a/amqp_queue.c
+++ b/amqp_queue.c
@@ -668,7 +668,7 @@ PHP_METHOD(amqp_queue_class, declare)
 		AMQP_SET_NAME(queue, name);
 	}
 
-	channel = AMQP_GET_CHANNEL(queue);
+	AMQP_ASSIGN_CHANNEL(channel, queue);
 	AMQP_VERIFY_CHANNEL(channel, "Could not declare queue.");
 	
 	connection = AMQP_GET_CONNECTION(channel);
diff --git a/php_amqp.h b/php_amqp.h
index 64e5b97..100fbe7 100644
--- a/php_amqp.h
+++ b/php_amqp.h
@@ -230,10 +230,22 @@ extern zend_class_entry *amqp_exception_class_entry,
 	efree(object); \
 
 #define AMQP_GET_CHANNEL(object) \
- 	(amqp_channel_object *) zend_object_store_get_object((object)->channel TSRMLS_CC); \
+	(amqp_channel_object *) zend_object_store_get_object((object)->channel TSRMLS_CC);
+
+#define AMQP_ASSIGN_CHANNEL(channel, object) \
+	if (!(object)->channel) { \
+		return; \
+	} \
+	channel = AMQP_GET_CHANNEL(object)
 
 #define AMQP_GET_CONNECTION(object) \
- 	(amqp_connection_object *) zend_object_store_get_object((object)->connection TSRMLS_CC); \
+	(amqp_connection_object *) zend_object_store_get_object((object)->connection TSRMLS_CC);
+
+#define AMQP_ASSIGN_CONNECTION(connection, object) \
+	if (!(object)->connection) { \
+		return; \
+	} \
+	connection = AMQP_GET_CONNECTION(object)
 
 #define AMQP_VERIFY_CHANNEL(channel, error) \
 	if ((channel)->is_connected != '\1') { \
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jun 15 20:01:23 2021 UTC