forked from dred86/php-xxhash
-
Notifications
You must be signed in to change notification settings - Fork 2
/
php_xxhash.c
97 lines (79 loc) · 1.83 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
88
89
90
91
92
93
94
95
96
97
#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", "v0.6.1");
php_info_print_table_end();
}
PHP_FUNCTION(xxhash32)
{
char *arg = NULL;
unsigned long long seed = 0;
size_t arg_len, len;
zend_string *strg;
unsigned int sum;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &arg, &arg_len, &seed) == FAILURE || arg_len < 1) {
return;
}
if (!seed) {
seed = 0;
}
// compute the checksum
sum = XXH32(arg, arg_len, seed);
//convert to a hex string
strg = strpprintf(0, "%08x", sum);
// return the checksum
RETURN_STR(strg);
}
PHP_FUNCTION(xxhash64)
{
char *arg = NULL;
unsigned long long seed = 0;
size_t arg_len, len;
zend_string *strg;
unsigned long long sum;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &arg, &arg_len, &seed) == FAILURE || arg_len < 1) {
return;
}
if (!seed) {
seed = 0;
}
// compute the checksum
sum = XXH64(arg, arg_len, seed);
//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
};