Skip to content

Commit 153ecd4

Browse files
committed
code cleaning
1 parent bd3f0e4 commit 153ecd4

File tree

5 files changed

+24
-38
lines changed

5 files changed

+24
-38
lines changed

bdict.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ bdict::bdict(const bdict *that) : bitem() {
1818
for(zend_hash_internal_pointer_reset(that->_data);
1919
zend_hash_has_more_elements(that->_data) == SUCCESS;
2020
zend_hash_move_forward(that->_data)) {
21-
zval temp;
22-
ZVAL_OBJ(&temp, zend_container::bnode_object_clone(zend_hash_get_current_data(that->_data)));
21+
zval tmp;
22+
ZVAL_OBJ(&tmp, zend_container::bnode_object_clone(zend_hash_get_current_data(that->_data)));
2323
zend_string *_str_index;
2424
zend_ulong _num_index;
2525
zend_hash_get_current_key(that->_data, &_str_index, &_num_index);
26-
zend_hash_add(_data, _str_index, &temp);
26+
zend_hash_add(_data, _str_index, &tmp);
2727
}
2828
}
2929

@@ -55,9 +55,9 @@ bool bdict::has(const std::string &key) const {
5555
}
5656

5757
void bdict::set(const std::string &key, zval *value) {
58-
//zval temp;
59-
//temp = *value;
60-
//zval_copy_ctor(&temp);
58+
//zval tmp;
59+
//tmp = *value;
60+
//zval_copy_ctor(&tmp);
6161
std::string class_name = zend_container::bnode_object_get_class_name(value);
6262
zend_object *clone_object = NULL;
6363
if (class_name == "bdict" || class_name == "blist" ||
@@ -66,12 +66,12 @@ void bdict::set(const std::string &key, zval *value) {
6666
} else {
6767
return;
6868
}
69-
zval temp;
70-
ZVAL_OBJ(&temp, clone_object);
69+
zval tmp;
70+
ZVAL_OBJ(&tmp, clone_object);
7171
if (zend_hash_str_exists(_data, key.c_str(), key.length())) {
72-
zend_hash_str_update(_data, key.c_str(), key.length(), &temp);
72+
zend_hash_str_update(_data, key.c_str(), key.length(), &tmp);
7373
} else {
74-
zend_hash_str_add(_data, key.c_str(), key.length(), &temp);
74+
zend_hash_str_add(_data, key.c_str(), key.length(), &tmp);
7575
}
7676
}
7777

bencode.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ PHP_MINIT_FUNCTION(bencode)
555555
{
556556
REGISTER_INI_ENTRIES();
557557

558-
char *ini_ns_key = zend_container::get_cstring("bencode.namespace");
558+
char *ini_ns_key = estrdup("bencode.namespace");
559559
zend_bool ini_ns = zend_ini_long(ini_ns_key, strlen(ini_ns_key), 0);
560560
efree(ini_ns_key);
561561
do {
@@ -584,17 +584,12 @@ PHP_MSHUTDOWN_FUNCTION(bencode)
584584
return SUCCESS;
585585
}
586586

587-
static zend_function_entry bencode_functions[] = {
588-
PHP_FE(bencode_hello, NULL)
589-
{NULL, NULL, NULL}
590-
};
591-
592587
zend_module_entry bencode_module_entry = {
593588
#if ZEND_MODULE_API_NO >= 20010901
594589
STANDARD_MODULE_HEADER,
595590
#endif
596591
PHP_BENCODE_EXTNAME,
597-
bencode_functions, //FUNCTIONS
592+
NULL, //FUNCTIONS
598593
PHP_MINIT(bencode), //PHP_MINIT
599594
PHP_MSHUTDOWN(bencode), //PHP_MSHUTDOWN(bencode),
600595
NULL, //PHP_RINIT(bencode),
@@ -611,9 +606,3 @@ extern "C" {
611606
ZEND_GET_MODULE(bencode)
612607
}
613608
#endif
614-
615-
PHP_FUNCTION(bencode_hello)
616-
{
617-
php_printf("hello bencode!\n");
618-
RETURN_TRUE;
619-
}

blist.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ blist::blist(const blist *that) : bitem() {
1818
for(zend_hash_internal_pointer_reset(that->_data);
1919
zend_hash_has_more_elements(that->_data) == SUCCESS;
2020
zend_hash_move_forward(that->_data)) {
21-
zval temp;
22-
ZVAL_OBJ(&temp, zend_container::bnode_object_clone(zend_hash_get_current_data(that->_data)));
21+
zval tmp;
22+
ZVAL_OBJ(&tmp, zend_container::bnode_object_clone(zend_hash_get_current_data(that->_data)));
2323
zend_string *_str_index;
2424
zend_ulong _num_index;
2525
zend_hash_get_current_key(that->_data, &_str_index, &_num_index);
26-
zend_hash_index_add(_data, _num_index, &temp);
26+
zend_hash_index_add(_data, _num_index, &tmp);
2727
}
2828
}
2929

@@ -63,9 +63,9 @@ void blist::add(zval *value) {
6363
} else {
6464
return;
6565
}
66-
zval temp;
67-
ZVAL_OBJ(&temp, clone_object);
68-
zend_hash_next_index_insert(_data, &temp);
66+
zval tmp;
67+
ZVAL_OBJ(&tmp, clone_object);
68+
zend_hash_next_index_insert(_data, &tmp);
6969
}
7070

7171
void blist::set(const size_t &key, zval *value) {
@@ -77,12 +77,12 @@ void blist::set(const size_t &key, zval *value) {
7777
} else {
7878
return;
7979
}
80-
zval temp;
81-
ZVAL_OBJ(&temp, clone_object);
80+
zval tmp;
81+
ZVAL_OBJ(&tmp, clone_object);
8282
if (zend_hash_index_exists(_data, key)) {
83-
zend_hash_index_update(_data, key, &temp);
83+
zend_hash_index_update(_data, key, &tmp);
8484
} else {
85-
zend_hash_next_index_insert(_data, &temp);
85+
zend_hash_next_index_insert(_data, &tmp);
8686
}
8787
}
8888

bstr.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ zval * bstr::to_array(const bool include_meta) const {
5757
char *_type_data = estrdup("bstr");
5858
char *_length = estrdup("_length");
5959
char *_data = estrdup("_data");
60-
char *_data_data = (char *)emalloc(_value.length());
61-
strcpy(_data_data, _value.c_str());
60+
char *_data_data = zend_container::get_cstring(_value);
6261
add_assoc_string(zv, _type, _type_data);
6362
add_assoc_long(zv, _length, length());
6463
add_assoc_string(zv, _data, _data_data);
@@ -68,8 +67,7 @@ zval * bstr::to_array(const bool include_meta) const {
6867
efree(_data);
6968
efree(_data_data);
7069
} else {
71-
char *tmp = (char *)emalloc(_value.length());
72-
strcpy(tmp, _value.c_str());
70+
char *tmp = zend_container::get_cstring(_value);
7371
ZVAL_STRING(zv, tmp);
7472
efree(tmp);
7573
}

php_bencode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ extern "C" {
1414

1515
PHP_MINIT_FUNCTION(bencode);
1616
PHP_MSHUTDOWN_FUNCTION(bencode);
17-
PHP_FUNCTION(bencode_hello);
1817

1918
extern zend_module_entry bencode_module_entry;
2019
#define phpext_bencode_ptr &bencode_module_entry

0 commit comments

Comments
 (0)