forked from stuartherbert/php-xxhash
-
Notifications
You must be signed in to change notification settings - Fork 10
/
php_xxhash.c
87 lines (71 loc) · 1.66 KB
/
php_xxhash.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_xxhash.h"
#include "xxhash.c"
#ifdef COMPILE_DL_XXHASH
ZEND_GET_MODULE(xxhash);
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE();
#endif
#endif
PHP_MINFO_FUNCTION(xxhash)
{
php_info_print_table_start();
php_info_print_table_header(2, "xxhash support", "enabled");
php_info_print_table_row(2, "extension version", PHP_XXHASH_VERSION);
php_info_print_table_row(2, "xxhash release", "r40");
php_info_print_table_end();
}
PHP_FUNCTION(xxhash32)
{
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
unsigned int sum;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE || arg_len < 1) {
return;
}
// compute the checksum
sum = XXH32(arg, arg_len, 0);
//convert to a hex string
strg = strpprintf(0, "%08x", sum);
// return the checksum
RETURN_STR(strg);
}
PHP_FUNCTION(xxhash64)
{
char *arg = NULL;
size_t arg_len, len;
zend_string *strg;
unsigned long long sum;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE || arg_len < 1) {
return;
}
// compute the checksum
sum = XXH64(arg, arg_len, 0);
//convert to a hex string
strg = strpprintf(0, "%08x%08x", (U32)(sum >> 32), (U32)sum);
// return the checksum
RETURN_STR(strg);
}
const zend_function_entry xxhash_functions[] = {
ZEND_FE(xxhash32, NULL)
ZEND_FE(xxhash64, NULL)
PHP_FE_END
};
zend_module_entry xxhash_module_entry = {
STANDARD_MODULE_HEADER,
"xxhash",
xxhash_functions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(xxhash),
PHP_XXHASH_VERSION,
STANDARD_MODULE_PROPERTIES
};