Skip to content

Commit c0a4aa0

Browse files
committed
New: first version of this extension
1 parent 58737ae commit c0a4aa0

File tree

6 files changed

+618
-0
lines changed

6 files changed

+618
-0
lines changed

config.m4

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
dnl $Id$
2+
dnl config.m4 for extension hexdump
3+
4+
dnl Comments in this file start with the string 'dnl'.
5+
dnl Remove where necessary. This file will not work
6+
dnl without editing.
7+
8+
dnl If your extension references something external, use with:
9+
10+
dnl PHP_ARG_WITH(hexdump, for hexdump support,
11+
dnl Make sure that the comment is aligned:
12+
dnl [ --with-hexdump Include hexdump support])
13+
14+
dnl Otherwise use enable:
15+
16+
PHP_ARG_ENABLE(xxhash, whether to enable xxhash support,
17+
dnl Make sure that the comment is aligned:
18+
[ --enable-xxhash Enable xxhash support])
19+
20+
if test "$PHP_XXHASH" != "no"; then
21+
dnl Write more examples of tests here...
22+
23+
PHP_NEW_EXTENSION(xxhash, php_xxhash.c, $ext_shared)
24+
fi

config.w32

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// $Id$
2+
// vim:ft=javascript
3+
4+
// If your extension references something external, use ARG_WITH
5+
// ARG_WITH("xxhash", "for xxhash support", "no");
6+
7+
// Otherwise, use ARG_ENABLE
8+
// ARG_ENABLE("xxhash", "enable xxhash support", "no");
9+
10+
if (PHP_XXHASH != "no") {
11+
EXTENSION("xxhash", "php_xxhash.c");
12+
}
13+

php_xxhash.c

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#ifdef HAVE_CONFIG_H
2+
#include "config.h"
3+
#endif
4+
5+
#include "php.h"
6+
#include "php_ini.h"
7+
#include "ext/standard/info.h"
8+
#include "php_xxhash.h"
9+
10+
#include "xxhash.c"
11+
12+
zend_function_entry xxhash_functions[] = {
13+
PHP_FE(xxhash32, NULL)
14+
{NULL, NULL, NULL}
15+
};
16+
17+
zend_module_entry xxhash_module_entry = {
18+
STANDARD_MODULE_HEADER,
19+
"xxhash",
20+
xxhash_functions,
21+
PHP_MINIT(xxhash),
22+
PHP_MSHUTDOWN(xxhash),
23+
NULL,
24+
NULL,
25+
PHP_MINFO(xxhash),
26+
PHP_XXHASH_VERSION,
27+
STANDARD_MODULE_PROPERTIES
28+
};
29+
30+
#ifdef COMPILE_DL_XXHASH
31+
ZEND_GET_MODULE(xxhash)
32+
#endif
33+
34+
PHP_MINIT_FUNCTION(xxhash)
35+
{
36+
return SUCCESS;
37+
}
38+
39+
PHP_MSHUTDOWN_FUNCTION(xxhash)
40+
{
41+
return SUCCESS;
42+
}
43+
44+
PHP_RINIT_FUNCTION(xxhash)
45+
{
46+
return SUCCESS;
47+
}
48+
49+
PHP_RSHUTDOWN_FUNCTION(xxhash)
50+
{
51+
return SUCCESS;
52+
}
53+
54+
PHP_MINFO_FUNCTION(xxhash)
55+
{
56+
php_info_print_table_start();
57+
php_info_print_table_header(2, "xxhash support", "enabled");
58+
php_info_print_table_row(2, "extension version", PHP_XXHASH_VERSION);
59+
php_info_print_table_row(2, "xxhash release", "http://code.google.com/p/xxhash/source/detail?r=6");
60+
php_info_print_table_end();
61+
}
62+
63+
PHP_FUNCTION(xxhash32)
64+
{
65+
char *arg1 = NULL;
66+
char *ret1 = NULL;
67+
int arg1_len;
68+
unsigned int sum;
69+
70+
/* parse the parameters */
71+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg1, &arg1_len) == FAILURE || arg1_len < 1)
72+
{
73+
RETURN_NULL();
74+
}
75+
76+
/* compute the checksum */
77+
sum = XXH32(arg1, arg1_len, 0);
78+
79+
/* return the checksum */
80+
RETURN_LONG((long)sum);
81+
}
82+
83+

php_xxhash.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef PHP_XXHASH_H
2+
#define PHP_XXHASH_H
3+
4+
#define PHP_XXHASH_VERSION "1.0.0"
5+
6+
extern zend_module_entry xxhash_module_entry;
7+
#define phpext_xxhash_ptr &xxhash_module_entry;
8+
9+
#if defined(PHP_WIN32) && defined(XXHASH_EXPORTS)
10+
#define PHP_XXHASH_API __declspec(dllexport)
11+
#else
12+
#define PHP_XXHASH_API PHPAPI
13+
#endif
14+
15+
#ifdef ZTS
16+
#include "TSRM.h"
17+
#endif
18+
19+
PHP_MINIT_FUNCTION(xxhash);
20+
PHP_MSHUTDOWN_FUNCTION(xxhash);
21+
PHP_RINIT_FUNCTION(xxhash);
22+
PHP_RSHUTDOWN_FUNCTION(xxhash);
23+
PHP_MINFO_FUNCTION(xxhash);
24+
25+
PHP_FUNCTION(xxhash32);
26+
27+
#endif /* PHP_XXHASH_H */
28+

0 commit comments

Comments
 (0)