-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathphp_crc_fast.h
More file actions
98 lines (75 loc) · 2.77 KB
/
Copy pathphp_crc_fast.h
File metadata and controls
98 lines (75 loc) · 2.77 KB
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
98
/* crc_fast extension for PHP */
/* Copyright 2025 Don MacAskill. Licensed under MIT or Apache-2.0. */
#ifndef PHP_CRC_FAST_H
# define PHP_CRC_FAST_H
#ifdef __cplusplus
extern "C" {
#endif
#include "php.h"
#ifdef __cplusplus
}
#endif
#include "libcrc_fast.h"
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
extern zend_module_entry crc_fast_module_entry;
#ifdef __cplusplus
}
#endif
# define phpext_crc_fast_ptr &crc_fast_module_entry
# define PHP_CRC_FAST_VERSION "1.1.0"
# if defined(ZTS) && defined(COMPILE_DL_CRC_FAST)
ZEND_TSRMLS_CACHE_EXTERN()
# endif
typedef struct _php_crc_fast_digest_obj {
CrcFastDigestHandle *digest;
zend_long algorithm;
bool is_custom; // Whether using custom parameters
CrcFastParams custom_params; // Custom parameters if is_custom is true
zend_object std; // MUST be last
} php_crc_fast_digest_obj;
/* Use container_of pattern instead of offset macros */
#define container_of(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
static inline php_crc_fast_digest_obj *php_crc_fast_digest_from_obj(zend_object *obj) {
return container_of(obj, php_crc_fast_digest_obj, std);
}
#define Z_CRC_FAST_DIGEST_P(zv) php_crc_fast_digest_from_obj(Z_OBJ_P(zv))
/* Define the CrcFast\Params class */
typedef struct _php_crc_fast_params_obj {
CrcFastParams params;
uint64_t *keys_storage; // Allocated storage for keys array
zend_object std;
} php_crc_fast_params_obj;
static inline php_crc_fast_params_obj *php_crc_fast_params_from_obj(zend_object *obj) {
return container_of(obj, php_crc_fast_params_obj, std);
}
#define Z_CRC_FAST_PARAMS_P(zv) php_crc_fast_params_from_obj(Z_OBJ_P(zv))
/* Algorithm constants that will be exposed to PHP, with room for expansion */
// CRC-32
#define PHP_CRC_FAST_CRC32_AIXM 10000
#define PHP_CRC_FAST_CRC32_AUTOSAR 10010
#define PHP_CRC_FAST_CRC32_BASE91D 10020
#define PHP_CRC_FAST_CRC32_BZIP2 10030
#define PHP_CRC_FAST_CRC32_CDROM_EDC 10040
#define PHP_CRC_FAST_CRC32_CKSUM 10050
#define PHP_CRC_FAST_CRC32_ISCSI 10060
#define PHP_CRC_FAST_CRC32_ISO_HDLC 10070
#define PHP_CRC_FAST_CRC32_JAMCRC 10080
#define PHP_CRC_FAST_CRC32_MEF 10090
#define PHP_CRC_FAST_CRC32_MPEG2 10100
// this is a special flower, just to handle PHP's `hash('crc32')` operation,
// which is actually byte-reversed CRC-32/BZIP2
#define PHP_CRC_FAST_CRC32_PHP 10200
#define PHP_CRC_FAST_CRC32_XFER 10300
// CRC-64
#define PHP_CRC_FAST_CRC64_ECMA182 20000
#define PHP_CRC_FAST_CRC64_GO_ISO 20010
#define PHP_CRC_FAST_CRC64_MS 20020
#define PHP_CRC_FAST_CRC64_NVME 20030
#define PHP_CRC_FAST_CRC64_REDIS 20040
#define PHP_CRC_FAST_CRC64_WE 20050
#define PHP_CRC_FAST_CRC64_XZ 20060
#endif /* PHP_CRC_FAST_H */