Skip to content

Commit 1120b30

Browse files
committed
simplify
1 parent 421ca3c commit 1120b30

File tree

2 files changed

+11
-24
lines changed

2 files changed

+11
-24
lines changed

src/BSON/ObjectID.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ static zend_function_entry php_phongo_objectid_me[] = {
127127

128128

129129
/* {{{ Other functions */
130-
zend_object_handlers* php_phongo_handlers_objectid() /* {{{ */
131-
{
132-
return &php_phongo_handler_objectid;
133-
} /* }}} */
134130
static int php_phongo_objectid_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
135131
{
136132
php_phongo_objectid_t *intern1;
@@ -157,14 +153,13 @@ zend_object_value php_phongo_objectid_create_object(zend_class_entry *class_type
157153
zend_object_value retval;
158154
php_phongo_objectid_t *intern = NULL;
159155

160-
intern = (php_phongo_objectid_t *)emalloc(sizeof(php_phongo_objectid_t));
161-
memset(intern, 0, sizeof(php_phongo_objectid_t));
156+
intern = (php_phongo_objectid_t *)ecalloc(1, sizeof *intern);
162157

163158
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
164159
object_properties_init(&intern->std, class_type);
165160

166161
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_objectid_free_object, NULL TSRMLS_CC);
167-
retval.handlers = php_phongo_handlers_objectid();
162+
retval.handlers = &php_phongo_handler_objectid;
168163

169164
return retval;
170165
} /* }}} */
@@ -173,17 +168,17 @@ zend_object_value php_phongo_objectid_create_object(zend_class_entry *class_type
173168
/* {{{ PHP_MINIT_FUNCTION */
174169
PHP_MINIT_FUNCTION(ObjectID)
175170
{
176-
(void)type; /* We don't care if we are loaded via dl() or extension= */
171+
(void)type;(void)module_number;
177172
zend_class_entry ce;
178173

179174
INIT_NS_CLASS_ENTRY(ce, "BSON", "ObjectID", php_phongo_objectid_me);
180-
ce.create_object = php_phongo_objectid_create_object;
181175
php_phongo_objectid_ce = zend_register_internal_class(&ce TSRMLS_CC);
176+
php_phongo_objectid_ce->create_object = php_phongo_objectid_create_object;
182177

178+
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_phongo_type_ce);
183179

184180
memcpy(&php_phongo_handler_objectid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
185181
php_phongo_handler_objectid.compare_objects = php_phongo_objectid_compare_objects;
186-
zend_class_implements(php_phongo_objectid_ce TSRMLS_CC, 1, php_phongo_type_ce);
187182

188183

189184
return SUCCESS;

src/MongoDB/Server.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,6 @@ static zend_function_entry php_phongo_server_me[] = {
429429

430430

431431
/* {{{ Other functions */
432-
zend_object_handlers* php_phongo_handlers_server() /* {{{ */
433-
{
434-
return &php_phongo_handler_server;
435-
} /* }}} */
436432
static int php_phongo_server_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
437433
{
438434
php_phongo_server_t *intern1;
@@ -461,9 +457,6 @@ static void php_phongo_server_free_object(void *object TSRMLS_DC) /* {{{ */
461457

462458
mongoc_client_destroy(intern->client);
463459

464-
if (intern->host) {
465-
//efree(intern->host);
466-
}
467460
zend_object_std_dtor(&intern->std TSRMLS_CC);
468461

469462
efree(intern);
@@ -472,16 +465,15 @@ static void php_phongo_server_free_object(void *object TSRMLS_DC) /* {{{ */
472465
zend_object_value php_phongo_server_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
473466
{
474467
zend_object_value retval;
475-
php_phongo_server_t *intern;
468+
php_phongo_server_t *intern = NULL;
476469

477-
intern = (php_phongo_server_t *)emalloc(sizeof(php_phongo_server_t));
478-
memset(intern, 0, sizeof(php_phongo_server_t));
470+
intern = (php_phongo_server_t *)ecalloc(1, sizeof *intern);
479471

480472
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
481473
object_properties_init(&intern->std, class_type);
482474

483475
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_server_free_object, NULL TSRMLS_CC);
484-
retval.handlers = php_phongo_handlers_server();
476+
retval.handlers = &php_phongo_handler_server;
485477

486478
return retval;
487479
} /* }}} */
@@ -490,17 +482,17 @@ zend_object_value php_phongo_server_create_object(zend_class_entry *class_type T
490482
/* {{{ PHP_MINIT_FUNCTION */
491483
PHP_MINIT_FUNCTION(Server)
492484
{
493-
(void)type; /* We don't care if we are loaded via dl() or extension= */
485+
(void)type;(void)module_number;
494486
zend_class_entry ce;
495487

496488
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "Server", php_phongo_server_me);
497-
ce.create_object = php_phongo_server_create_object;
498489
php_phongo_server_ce = zend_register_internal_class(&ce TSRMLS_CC);
490+
php_phongo_server_ce->create_object = php_phongo_server_create_object;
499491
php_phongo_server_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
500492

501-
502493
memcpy(&php_phongo_handler_server, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
503494
php_phongo_handler_server.compare_objects = php_phongo_server_compare_objects;
495+
504496
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_MONGOS"), 0x01 TSRMLS_CC);
505497
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_STANDALONE"), 0x02 TSRMLS_CC);
506498
zend_declare_class_constant_long(php_phongo_server_ce, ZEND_STRL("TYPE_ARBITER"), 0x03 TSRMLS_CC);

0 commit comments

Comments
 (0)