Skip to content

Commit

Permalink
Backport get_custom_object_zval() / alloc_object() from the php7 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaud-lb committed Mar 1, 2016
1 parent bd3231a commit 9476a33
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 35 deletions.
9 changes: 5 additions & 4 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "Zend/zend_exceptions.h"
#include "ext/spl/spl_exceptions.h"
Expand Down Expand Up @@ -89,7 +90,7 @@ static zend_object_value kafka_conf_new(zend_class_entry *class_type TSRMLS_DC)
zend_object_value retval;
kafka_conf_object *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -102,7 +103,7 @@ static zend_object_value kafka_conf_new(zend_class_entry *class_type TSRMLS_DC)

kafka_conf_object * get_kafka_conf_object(zval *zconf TSRMLS_DC)
{
kafka_conf_object *oconf = (kafka_conf_object*)zend_object_store_get_object(zconf TSRMLS_CC);
kafka_conf_object *oconf = get_custom_object_zval(kafka_conf_object, zconf);

if (!oconf->type) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Conf::__construct() has not been called" TSRMLS_CC);
Expand Down Expand Up @@ -221,7 +222,7 @@ PHP_METHOD(RdKafka__Conf, __construct)
return;
}

intern = (kafka_conf_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
intern = get_custom_object_zval(kafka_conf_object, getThis());
intern->type = KAFKA_CONF;
intern->u.conf = rd_kafka_conf_new();

Expand Down Expand Up @@ -445,7 +446,7 @@ PHP_METHOD(RdKafka__TopicConf, __construct)
return;
}

intern = (kafka_conf_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
intern = get_custom_object_zval(kafka_conf_object, getThis());
intern->type = KAFKA_TOPIC_CONF;
intern->u.topic_conf = rd_kafka_topic_conf_new();

Expand Down
8 changes: 4 additions & 4 deletions kafka_consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static zend_object_value kafka_consumer_new(zend_class_entry *class_type TSRMLS_

static object_intern * get_object(zval *zconsumer TSRMLS_DC) /* {{{ */
{
object_intern *oconsumer = (object_intern*)zend_object_store_get_object(zconsumer TSRMLS_CC);
object_intern *oconsumer = get_custom_object_zval(object_intern, zconsumer);

if (!oconsumer->rk) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\KafkaConsumer::__construct() has not been called");
Expand Down Expand Up @@ -123,7 +123,7 @@ PHP_METHOD(RdKafka__KafkaConsumer, __construct)
return;
}

intern = (object_intern*)zend_object_store_get_object(getThis() TSRMLS_CC);
intern = get_custom_object_zval(object_intern, getThis());

conf_intern = get_kafka_conf_object(zconf TSRMLS_CC);
if (conf_intern) {
Expand Down Expand Up @@ -171,7 +171,7 @@ PHP_METHOD(RdKafka__KafkaConsumer, __destruct)
return;
}

intern = (object_intern*)zend_object_store_get_object(getThis() TSRMLS_CC);
intern = get_custom_object_zval(object_intern, getThis());

if (intern->rk) {
err = rd_kafka_consumer_close(intern->rk);
Expand Down Expand Up @@ -620,7 +620,7 @@ PHP_METHOD(RdKafka__KafkaConsumer, newTopic)
return;
}

topic_intern = (kafka_topic_object*)zend_object_store_get_object(return_value TSRMLS_CC);
topic_intern = get_custom_object_zval(kafka_topic_object, return_value);
if (!topic_intern) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "php.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "metadata_collection.h"
#include "metadata_topic.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ static zend_object_value kafka_metadata_new(zend_class_entry *class_type TSRMLS_
zend_object_value retval;
object_intern *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -81,7 +82,7 @@ static zend_object_value kafka_metadata_new(zend_class_entry *class_type TSRMLS_

static object_intern * get_object(zval *zmetadata TSRMLS_DC)
{
object_intern *ometadata = (object_intern*)zend_object_store_get_object(zmetadata TSRMLS_CC);
object_intern *ometadata = get_custom_object_zval(object_intern, zmetadata);

if (!ometadata->metadata) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Metadata::__construct() has not been called");
Expand Down Expand Up @@ -247,7 +248,7 @@ void kafka_metadata_init(zval *return_value, const rd_kafka_metadata_t *metadata
return;
}

intern = (object_intern*)zend_object_store_get_object(return_value TSRMLS_CC);
intern = get_custom_object_zval(object_intern, return_value);
if (!intern) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions metadata_broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "php.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "ext/spl/spl_iterators.h"
#include "Zend/zend_interfaces.h"
Expand Down Expand Up @@ -57,7 +58,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /
zend_object_value retval;
object_intern *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -70,7 +71,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /

static object_intern * get_object(zval *zmt TSRMLS_DC)
{
object_intern *omt = (object_intern*)zend_object_store_get_object(zmt TSRMLS_CC);
object_intern *omt = get_custom_object_zval(object_intern, zmt);

if (!omt->metadata_broker) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Metadata\\Broker::__construct() has not been called");
Expand Down Expand Up @@ -199,7 +200,7 @@ void kafka_metadata_broker_ctor(zval *return_value, zval *zmetadata, const void
return;
}

intern = (object_intern*)zend_object_store_get_object(return_value TSRMLS_CC);
intern = get_custom_object_zval(object_intern, return_value);
if (!intern) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions metadata_collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "php.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "ext/spl/spl_iterators.h"
#include "Zend/zend_interfaces.h"
Expand Down Expand Up @@ -62,7 +63,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /
zend_object_value retval;
object_intern *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -75,7 +76,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /

static object_intern * get_object(zval *zmti TSRMLS_DC)
{
object_intern *omti = (object_intern*)zend_object_store_get_object(zmti TSRMLS_CC);
object_intern *omti = get_custom_object_zval(object_intern, zmti);

if (!omti->items) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Metadata\\Collection::__construct() has not been called" TSRMLS_CC);
Expand Down Expand Up @@ -290,7 +291,7 @@ void kafka_metadata_collection_init(zval *return_value, zval *zmetadata, const v
return;
}

intern = (object_intern*)zend_object_store_get_object(return_value TSRMLS_CC);
intern = get_custom_object_zval(object_intern, return_value);
if (!intern) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions metadata_partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "php.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "ext/spl/spl_iterators.h"
#include "Zend/zend_interfaces.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /
zend_object_value retval;
object_intern *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -71,7 +72,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /

static object_intern * get_object(zval *zmt TSRMLS_DC)
{
object_intern *omt = (object_intern*)zend_object_store_get_object(zmt TSRMLS_CC);
object_intern *omt = get_custom_object_zval(object_intern, zmt);

if (!omt->metadata_partition) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Metadata\\Partition::__construct() has not been called");
Expand Down Expand Up @@ -254,7 +255,7 @@ void kafka_metadata_partition_ctor(zval *return_value, zval *zmetadata, const vo
return;
}

intern = (object_intern*)zend_object_store_get_object(return_value TSRMLS_CC);
intern = get_custom_object_zval(object_intern, return_value);
if (!intern) {
return;
}
Expand Down
7 changes: 4 additions & 3 deletions metadata_topic.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "php.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "ext/spl/spl_iterators.h"
#include "Zend/zend_interfaces.h"
Expand Down Expand Up @@ -64,7 +65,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /
zend_object_value retval;
object_intern *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -77,7 +78,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /

static object_intern * get_object(zval *zmt TSRMLS_DC)
{
object_intern *omt = (object_intern*)zend_object_store_get_object(zmt TSRMLS_CC);
object_intern *omt = get_custom_object_zval(object_intern, zmt);

if (!omt->metadata_topic) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Metadata\\Topic::__construct() has not been called");
Expand Down Expand Up @@ -212,7 +213,7 @@ void kafka_metadata_topic_ctor(zval *return_value, zval *zmetadata, const void *
return;
}

intern = (object_intern*)zend_object_store_get_object(return_value TSRMLS_CC);
intern = get_custom_object_zval(object_intern, return_value);
if (!intern) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "php.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "ext/spl/spl_iterators.h"
#include "Zend/zend_interfaces.h"
Expand Down Expand Up @@ -51,7 +52,7 @@ static zend_object_value kafka_queue_new(zend_class_entry *class_type TSRMLS_DC)
zend_object_value retval;
kafka_queue_object *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -64,7 +65,7 @@ static zend_object_value kafka_queue_new(zend_class_entry *class_type TSRMLS_DC)

kafka_queue_object * get_kafka_queue_object(zval *zrkqu TSRMLS_DC)
{
kafka_queue_object *orkqu = (kafka_queue_object*)zend_object_store_get_object(zrkqu TSRMLS_CC);
kafka_queue_object *orkqu = get_custom_object_zval(kafka_queue_object, zrkqu);

if (!orkqu->rkqu) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Queue::__construct() has not been called" TSRMLS_CC);
Expand Down
13 changes: 7 additions & 6 deletions rdkafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "Zend/zend_exceptions.h"
#include "ext/spl/spl_exceptions.h"
Expand Down Expand Up @@ -83,7 +84,7 @@ static void kafka_init(zval *this_ptr, rd_kafka_type_t type, zval *zconf TSRMLS_
kafka_conf_object *conf_intern;
rd_kafka_conf_t *conf = NULL;

intern = (kafka_object*)zend_object_store_get_object(this_ptr TSRMLS_CC);
intern = get_custom_object_zval(kafka_object, this_ptr);
intern->type = type;

if (zconf) {
Expand Down Expand Up @@ -112,7 +113,7 @@ static zend_object_value kafka_new(zend_class_entry *class_type TSRMLS_DC) /* {{
zend_object_value retval;
kafka_object *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -125,7 +126,7 @@ static zend_object_value kafka_new(zend_class_entry *class_type TSRMLS_DC) /* {{

static kafka_object * get_kafka_object(zval *zrk TSRMLS_DC)
{
kafka_object *ork = (kafka_object*)zend_object_store_get_object(zrk TSRMLS_CC);
kafka_object *ork = get_custom_object_zval(kafka_object, zrk);

if (!ork->rk) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Kafka::__construct() has not been called" TSRMLS_CC);
Expand Down Expand Up @@ -307,7 +308,7 @@ PHP_METHOD(RdKafka__Kafka, newQueue)
return;
}

queue_intern = (kafka_queue_object*)zend_object_store_get_object(return_value TSRMLS_CC);
queue_intern = get_custom_object_zval(kafka_queue_object, return_value);
if (!queue_intern) {
return;
}
Expand Down Expand Up @@ -373,7 +374,7 @@ PHP_METHOD(RdKafka__Kafka, newTopic)
return;
}

topic_intern = (kafka_topic_object*)zend_object_store_get_object(return_value TSRMLS_CC);
topic_intern = get_custom_object_zval(kafka_topic_object, return_value);
if (!topic_intern) {
return;
}
Expand Down Expand Up @@ -486,7 +487,7 @@ PHP_METHOD(RdKafka__Kafka, __destruct)
return;
}

intern = (kafka_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
intern = get_custom_object_zval(kafka_object, getThis());
if (intern->rk) {
while (rd_kafka_outq_len(intern->rk) > 0) {
rd_kafka_poll(intern->rk, 50);
Expand Down
5 changes: 3 additions & 2 deletions topic.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "php.h"
#include "php_rdkafka.h"
#include "php_rdkafka_priv.h"
#include "librdkafka/rdkafka.h"
#include "ext/spl/spl_iterators.h"
#include "Zend/zend_interfaces.h"
Expand Down Expand Up @@ -59,7 +60,7 @@ static zend_object_value kafka_topic_new(zend_class_entry *class_type TSRMLS_DC)
zend_object_value retval;
kafka_topic_object *intern;

intern = ecalloc(1, sizeof(*intern));
intern = alloc_object(intern, class_type);
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
object_properties_init(&intern->std, class_type);

Expand All @@ -72,7 +73,7 @@ static zend_object_value kafka_topic_new(zend_class_entry *class_type TSRMLS_DC)

kafka_topic_object * get_kafka_topic_object(zval *zrkt TSRMLS_DC)
{
kafka_topic_object *orkt = (kafka_topic_object*)zend_object_store_get_object(zrkt TSRMLS_CC);
kafka_topic_object *orkt = get_custom_object_zval(kafka_topic_object, zrkt);

if (!orkt->rkt) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\Topic::__construct() has not been called" TSRMLS_CC);
Expand Down
4 changes: 2 additions & 2 deletions topic_partition.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static zend_object_value create_object(zend_class_entry *class_type TSRMLS_DC) /

static object_intern * get_object(zval *z TSRMLS_DC) /* {{{ */
{
object_intern * intern = (object_intern*)zend_object_store_get_object(z TSRMLS_CC);
object_intern * intern = get_custom_object_zval(object_intern, z);

if (!intern->topic) {
zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "RdKafka\\TopicPartition::__construct() has not been called");
Expand Down Expand Up @@ -115,7 +115,7 @@ void kafka_topic_partition_init(zval *zobj, char * topic, int32_t partition, int
{
object_intern *intern;

intern = (object_intern*)zend_object_store_get_object(zobj TSRMLS_CC);
intern = get_custom_object_zval(object_intern, zobj);
if (!intern) {
return;
}
Expand Down

0 comments on commit 9476a33

Please sign in to comment.