Skip to content

Commit 5aaed18

Browse files
committed
Clean up includes, protos, and source layout in BSON classes
1 parent 2804f3e commit 5aaed18

File tree

13 files changed

+225
-478
lines changed

13 files changed

+225
-478
lines changed

src/BSON/Binary.c

Lines changed: 25 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,42 +15,28 @@
1515
*/
1616

1717
#ifdef HAVE_CONFIG_H
18-
# include "config.h"
18+
# include "config.h"
1919
#endif
2020

21-
/* External libs */
22-
#include <bson.h>
23-
#include <mongoc.h>
24-
25-
/* PHP Core stuff */
2621
#include <php.h>
27-
#include <php_ini.h>
2822
#include <ext/standard/base64.h>
29-
#include <ext/standard/info.h>
3023
#include <Zend/zend_interfaces.h>
3124
#include <Zend/zend_operators.h>
32-
#include <ext/spl/spl_iterators.h>
3325
#include <ext/standard/php_var.h>
3426
#if PHP_VERSION_ID >= 70000
3527
# include <zend_smart_str.h>
3628
#else
3729
# include <ext/standard/php_smart_str.h>
3830
#endif
39-
/* Our Compatability header */
40-
#include "phongo_compat.h"
4131

42-
/* Our stuffz */
32+
#include "phongo_compat.h"
4333
#include "php_phongo.h"
44-
#include "php_bson.h"
45-
4634

4735
zend_class_entry *php_phongo_binary_ce;
4836

49-
static zend_object_handlers php_phongo_handler_binary;
50-
5137
/* Initialize the object and return whether it was successful. An exception will
5238
* be thrown on error. */
53-
static bool php_phongo_binary_init(php_phongo_binary_t *intern, const char *data, phongo_zpp_char_len data_len, phongo_long type TSRMLS_DC)
39+
static bool php_phongo_binary_init(php_phongo_binary_t *intern, const char *data, phongo_zpp_char_len data_len, phongo_long type TSRMLS_DC) /* {{{ */
5440
{
5541
if (type < 0 || type > UINT8_MAX) {
5642
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Expected type to be an unsigned 8-bit integer, %" PHONGO_LONG_FORMAT " given", type);
@@ -62,11 +48,11 @@ static bool php_phongo_binary_init(php_phongo_binary_t *intern, const char *data
6248
intern->type = (uint8_t) type;
6349

6450
return true;
65-
}
51+
} /* }}} */
6652

6753
/* Initialize the object from a HashTable and return whether it was successful.
6854
* An exception will be thrown on error. */
69-
static bool php_phongo_binary_init_from_hash(php_phongo_binary_t *intern, HashTable *props TSRMLS_DC)
55+
static bool php_phongo_binary_init_from_hash(php_phongo_binary_t *intern, HashTable *props TSRMLS_DC) /* {{{ */
7056
{
7157
#if PHP_VERSION_ID >= 70000
7258
zval *data, *type;
@@ -86,9 +72,9 @@ static bool php_phongo_binary_init_from_hash(php_phongo_binary_t *intern, HashTa
8672

8773
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"data\" string and \"type\" integer fields", ZSTR_VAL(php_phongo_binary_ce->name));
8874
return false;
89-
}
75+
} /* }}} */
9076

91-
/* {{{ proto void Binary::__construct(string $data, int $type)
77+
/* {{{ proto void MongoDB\BSON\Binary::__construct(string $data, int $type)
9278
Construct a new BSON binary type */
9379
static PHP_METHOD(Binary, __construct)
9480
{
@@ -109,10 +95,9 @@ static PHP_METHOD(Binary, __construct)
10995
zend_restore_error_handling(&error_handling TSRMLS_CC);
11096

11197
php_phongo_binary_init(intern, data, data_len, type TSRMLS_CC);
112-
}
113-
/* }}} */
98+
} /* }}} */
11499

115-
/* {{{ proto void Binary::__set_state(array $properties)
100+
/* {{{ proto void MongoDB\BSON\Binary::__set_state(array $properties)
116101
*/
117102
static PHP_METHOD(Binary, __set_state)
118103
{
@@ -130,10 +115,9 @@ static PHP_METHOD(Binary, __set_state)
130115
props = Z_ARRVAL_P(array);
131116

132117
php_phongo_binary_init_from_hash(intern, props TSRMLS_CC);
133-
}
134-
/* }}} */
118+
} /* }}} */
135119

136-
/* {{{ proto string Binary::__toString()
120+
/* {{{ proto string MongoDB\BSON\Binary::__toString()
137121
Return the Binary's data string. */
138122
static PHP_METHOD(Binary, __toString)
139123
{
@@ -146,10 +130,9 @@ static PHP_METHOD(Binary, __toString)
146130
intern = Z_BINARY_OBJ_P(getThis());
147131

148132
PHONGO_RETURN_STRINGL(intern->data, intern->data_len);
149-
}
150-
/* }}} */
133+
} /* }}} */
151134

152-
/* {{{ proto string Binary::getData()
135+
/* {{{ proto string MongoDB\BSON\Binary::getData()
153136
*/
154137
static PHP_METHOD(Binary, getData)
155138
{
@@ -163,10 +146,9 @@ static PHP_METHOD(Binary, getData)
163146
}
164147

165148
PHONGO_RETURN_STRINGL(intern->data, intern->data_len);
166-
}
167-
/* }}} */
149+
} /* }}} */
168150

169-
/* {{{ proto integer Binary::getType()
151+
/* {{{ proto integer MongoDB\BSON\Binary::getType()
170152
*/
171153
static PHP_METHOD(Binary, getType)
172154
{
@@ -180,10 +162,9 @@ static PHP_METHOD(Binary, getType)
180162
}
181163

182164
RETURN_LONG(intern->type);
183-
}
184-
/* }}} */
165+
} /* }}} */
185166

186-
/* {{{ proto array Binary::jsonSerialize()
167+
/* {{{ proto array MongoDB\BSON\Binary::jsonSerialize()
187168
*/
188169
static PHP_METHOD(Binary, jsonSerialize)
189170
{
@@ -216,10 +197,9 @@ static PHP_METHOD(Binary, jsonSerialize)
216197

217198
type_len = snprintf(type, sizeof(type), "%02x", intern->type);
218199
ADD_ASSOC_STRINGL(return_value, "$type", type, type_len);
219-
}
220-
/* }}} */
200+
} /* }}} */
221201

222-
/* {{{ proto string Binary::serialize()
202+
/* {{{ proto string MongoDB\BSON\Binary::serialize()
223203
*/
224204
static PHP_METHOD(Binary, serialize)
225205
{
@@ -258,10 +238,9 @@ static PHP_METHOD(Binary, serialize)
258238

259239
smart_str_free(&buf);
260240
zval_ptr_dtor(&retval);
261-
}
262-
/* }}} */
241+
} /* }}} */
263242

264-
/* {{{ proto string Binary::unserialize(string $serialized)
243+
/* {{{ proto void MongoDB\BSON\Binary::unserialize(string $serialized)
265244
*/
266245
static PHP_METHOD(Binary, unserialize)
267246
{
@@ -305,12 +284,9 @@ static PHP_METHOD(Binary, unserialize)
305284
php_phongo_binary_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
306285
#endif
307286
zval_ptr_dtor(&props);
308-
}
309-
/* }}} */
310-
311-
312-
/* {{{ BSON\Binary */
287+
} /* }}} */
313288

289+
/* {{{ MongoDB\BSON\Binary function entries */
314290
ZEND_BEGIN_ARG_INFO_EX(ai_Binary___construct, 0, 0, 2)
315291
ZEND_ARG_INFO(0, data)
316292
ZEND_ARG_INFO(0, type)
@@ -338,11 +314,11 @@ static zend_function_entry php_phongo_binary_me[] = {
338314
PHP_ME(Binary, getType, ai_Binary_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
339315
PHP_FE_END
340316
};
341-
342317
/* }}} */
343318

319+
/* {{{ MongoDB\BSON\Binary object handlers */
320+
static zend_object_handlers php_phongo_handler_binary;
344321

345-
/* {{{ php_phongo_binary_t object handlers */
346322
static void php_phongo_binary_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
347323
{
348324
php_phongo_binary_t *intern = Z_OBJ_BINARY(object);

src/BSON/Decimal128.c

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,23 @@
1515
*/
1616

1717
#ifdef HAVE_CONFIG_H
18-
# include "config.h"
18+
# include "config.h"
1919
#endif
2020

21-
/* External libs */
22-
#include <bson.h>
23-
#include <mongoc.h>
24-
25-
/* PHP Core stuff */
2621
#include <php.h>
27-
#include <php_ini.h>
28-
#include <ext/standard/info.h>
2922
#include <Zend/zend_interfaces.h>
30-
#include <ext/spl/spl_iterators.h>
3123
#include <ext/standard/php_var.h>
3224
#if PHP_VERSION_ID >= 70000
3325
# include <zend_smart_str.h>
3426
#else
3527
# include <ext/standard/php_smart_str.h>
3628
#endif
37-
/* Our Compatability header */
38-
#include "phongo_compat.h"
3929

40-
/* Our stuffz */
30+
#include "phongo_compat.h"
4131
#include "php_phongo.h"
42-
#include "php_bson.h"
43-
4432

4533
zend_class_entry *php_phongo_decimal128_ce;
4634

47-
static zend_object_handlers php_phongo_handler_decimal128;
48-
4935
/* Initialize the object and return whether it was successful. An exception will
5036
* be thrown on error. */
5137
static bool php_phongo_decimal128_init(php_phongo_decimal128_t *intern, const char *value TSRMLS_DC) /* {{{ */
@@ -58,7 +44,7 @@ static bool php_phongo_decimal128_init(php_phongo_decimal128_t *intern, const ch
5844
intern->initialized = true;
5945

6046
return true;
61-
}
47+
} /* }}} */
6248

6349
/* Initialize the object from a HashTable and return whether it was successful.
6450
* An exception will be thrown on error. */
@@ -80,9 +66,9 @@ static bool php_phongo_decimal128_init_from_hash(php_phongo_decimal128_t *intern
8066

8167
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "%s initialization requires \"dec\" string field", ZSTR_VAL(php_phongo_decimal128_ce->name));
8268
return false;
83-
}
69+
} /* }}} */
8470

85-
/* {{{ proto void Decimal128::__construct(string $value)
71+
/* {{{ proto void MongoDB\BSON\Decimal128::__construct(string $value)
8672
Construct a new BSON Decimal128 type */
8773
static PHP_METHOD(Decimal128, __construct)
8874
{
@@ -102,10 +88,9 @@ static PHP_METHOD(Decimal128, __construct)
10288
zend_restore_error_handling(&error_handling TSRMLS_CC);
10389

10490
php_phongo_decimal128_init(intern, value TSRMLS_CC);
105-
}
106-
/* }}} */
91+
} /* }}} */
10792

108-
/* {{{ proto void Decimal128::__set_state(array $properties)
93+
/* {{{ proto void MongoDB\BSON\Decimal128::__set_state(array $properties)
10994
*/
11095
static PHP_METHOD(Decimal128, __set_state)
11196
{
@@ -123,10 +108,9 @@ static PHP_METHOD(Decimal128, __set_state)
123108
props = Z_ARRVAL_P(array);
124109

125110
php_phongo_decimal128_init_from_hash(intern, props TSRMLS_CC);
126-
}
127-
/* }}} */
111+
} /* }}} */
128112

129-
/* {{{ proto string Decimal128::__toString()
113+
/* {{{ proto string MongoDB\BSON\Decimal128::__toString()
130114
*/
131115
static PHP_METHOD(Decimal128, __toString)
132116
{
@@ -142,10 +126,9 @@ static PHP_METHOD(Decimal128, __toString)
142126
bson_decimal128_to_string(&intern->decimal, outbuf);
143127

144128
PHONGO_RETURN_STRING(outbuf);
145-
}
146-
/* }}} */
129+
} /* }}} */
147130

148-
/* {{{ proto array Decimal128::jsonSerialize()
131+
/* {{{ proto array MongoDB\BSON\Decimal128::jsonSerialize()
149132
*/
150133
static PHP_METHOD(Decimal128, jsonSerialize)
151134
{
@@ -161,10 +144,9 @@ static PHP_METHOD(Decimal128, jsonSerialize)
161144
array_init_size(return_value, 1);
162145
bson_decimal128_to_string(&intern->decimal, outbuf);
163146
ADD_ASSOC_STRING(return_value, "$numberDecimal", outbuf);
164-
}
165-
/* }}} */
147+
} /* }}} */
166148

167-
/* {{{ proto string Decimal128::serialize()
149+
/* {{{ proto string MongoDB\BSON\Decimal128::serialize()
168150
*/
169151
static PHP_METHOD(Decimal128, serialize)
170152
{
@@ -203,10 +185,9 @@ static PHP_METHOD(Decimal128, serialize)
203185

204186
smart_str_free(&buf);
205187
zval_ptr_dtor(&retval);
206-
}
207-
/* }}} */
188+
} /* }}} */
208189

209-
/* {{{ proto string Decimal128::unserialize(string $serialized)
190+
/* {{{ proto void MongoDB\BSON\Decimal128::unserialize(string $serialized)
210191
*/
211192
static PHP_METHOD(Decimal128, unserialize)
212193
{
@@ -250,12 +231,9 @@ static PHP_METHOD(Decimal128, unserialize)
250231
php_phongo_decimal128_init_from_hash(intern, HASH_OF(props) TSRMLS_CC);
251232
#endif
252233
zval_ptr_dtor(&props);
253-
}
254-
/* }}} */
255-
256-
257-
/* {{{ BSON\Decimal128 */
234+
} /* }}} */
258235

236+
/* {{{ MongoDB\BSON\Decimal128 function entries */
259237
ZEND_BEGIN_ARG_INFO_EX(ai_Decimal128___construct, 0, 0, 1)
260238
ZEND_ARG_INFO(0, value)
261239
ZEND_END_ARG_INFO()
@@ -280,11 +258,11 @@ static zend_function_entry php_phongo_decimal128_me[] = {
280258
PHP_ME(Decimal128, unserialize, ai_Decimal128_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
281259
PHP_FE_END
282260
};
283-
284261
/* }}} */
285262

263+
/* {{{ MongoDB\BSON\Decimal128 object handlers */
264+
static zend_object_handlers php_phongo_handler_decimal128;
286265

287-
/* {{{ php_phongo_decimal128_t object handlers */
288266
static void php_phongo_decimal128_free_object(phongo_free_object_arg *object TSRMLS_DC) /* {{{ */
289267
{
290268
php_phongo_decimal128_t *intern = Z_OBJ_DECIMAL128(object);

0 commit comments

Comments
 (0)