• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jbboehr / php-handlebars / 11087218624

28 Sep 2024 09:41PM UTC coverage: 93.421%. Remained the same
11087218624

push

github

jbboehr
Modernize CI configuration, add PHP 8.4

4 of 4 new or added lines in 1 file covered. (100.0%)

3 existing lines in 1 file now uncovered.

1420 of 1520 relevant lines covered (93.42%)

430734.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.4
/src/php_handlebars.c
1

2
#ifdef HAVE_CONFIG_H
3
#include "config.h"
4
#endif
5

6
#include <stdio.h>
7
#include <setjmp.h>
8
#include <talloc.h>
9
#include <handlebars.h>
10
#include <string.h>
11

12
#include "Zend/zend_API.h"
13
#include "Zend/zend_constants.h"
14
#include "Zend/zend_ini.h"
15
#include "Zend/zend_modules.h"
16
#include "Zend/zend_operators.h"
17
#include "main/php.h"
18
#include "main/php_ini.h"
19
#include "main/SAPI.h"
20
#include "ext/standard/info.h"
21

22
#include "php_handlebars.h"
23

24
#include "handlebars_cache.h"
25
#include "handlebars_string.h"
26

27
#pragma GCC diagnostic warning "-Wshadow"
28

29

30

31
/* {{{ Prototypes */
32
extern PHP_MINIT_FUNCTION(handlebars_exceptions);
33
extern PHP_MINIT_FUNCTION(handlebars_impl);
34
extern PHP_MINIT_FUNCTION(handlebars_options);
35
extern PHP_MINIT_FUNCTION(handlebars_registry);
36
extern PHP_MINIT_FUNCTION(handlebars_safe_string);
37
extern PHP_MINIT_FUNCTION(handlebars_utils);
38
extern PHP_MINIT_FUNCTION(handlebars_value);
39
extern PHP_MINIT_FUNCTION(handlebars_vm);
40
extern PHP_MSHUTDOWN_FUNCTION(handlebars_options);
41

42
#ifdef PHP_HANDLEBARS_ENABLE_AST
43
extern PHP_MINIT_FUNCTION(handlebars_compiler);
44
extern PHP_MINIT_FUNCTION(handlebars_parser);
45
extern PHP_MINIT_FUNCTION(handlebars_opcode);
46
extern PHP_MINIT_FUNCTION(handlebars_program);
47
extern PHP_MINIT_FUNCTION(handlebars_token);
48
extern PHP_MINIT_FUNCTION(handlebars_tokenizer);
49
#endif
50

51
ZEND_DECLARE_MODULE_GLOBALS(handlebars);
52

53
PHP_HANDLEBARS_API zend_bool handlebars_has_psr = 0;
54
/* }}} Prototypes */
55

56
/* {{{ php.ini directive registration */
57
PHP_INI_BEGIN()
58
    // @TODO FIXME (pool not working so set to zero)
59
    STD_PHP_INI_ENTRY("handlebars.pool_size", "0", PHP_INI_ALL, OnUpdateLong, pool_size, zend_handlebars_globals, handlebars_globals)
60
    STD_PHP_INI_BOOLEAN("handlebars.cache.enable", "1", PHP_INI_SYSTEM, OnUpdateBool, cache_enable, zend_handlebars_globals, handlebars_globals)
61
    STD_PHP_INI_BOOLEAN("handlebars.cache.enable_cli", "0", PHP_INI_SYSTEM, OnUpdateBool, cache_enable_cli, zend_handlebars_globals, handlebars_globals)
62
    STD_PHP_INI_ENTRY("handlebars.cache.backend", "mmap", PHP_INI_SYSTEM, OnUpdateString, cache_backend, zend_handlebars_globals, handlebars_globals)
63
    STD_PHP_INI_ENTRY("handlebars.cache.max_size", "67108864", PHP_INI_SYSTEM, OnUpdateLong, cache_max_size, zend_handlebars_globals, handlebars_globals)
64
    STD_PHP_INI_ENTRY("handlebars.cache.max_entries", "349529", PHP_INI_SYSTEM, OnUpdateLong, cache_max_entries, zend_handlebars_globals, handlebars_globals)
65
    STD_PHP_INI_ENTRY("handlebars.cache.max_age", "-1", PHP_INI_SYSTEM, OnUpdateLong, cache_max_age, zend_handlebars_globals, handlebars_globals)
66
    STD_PHP_INI_ENTRY("handlebars.cache.save_path", "/tmp/php-handlebars-cache", PHP_INI_SYSTEM, OnUpdateString, cache_save_path, zend_handlebars_globals, handlebars_globals)
67
    STD_PHP_INI_BOOLEAN("handlebars.cache.stat", "1", PHP_INI_SYSTEM, OnUpdateBool, cache_stat, zend_handlebars_globals, handlebars_globals)
68
PHP_INI_END()
69
/* }}} */
70

71
/* {{{ Argument Info */
72
ZEND_BEGIN_ARG_INFO_EX(handlebars_cache_reset_args, ZEND_SEND_BY_VAL, 0, 0)
73
ZEND_END_ARG_INFO()
74
/* }}} Argument Info */
75

76
/* {{{ proto void handlebars_cache_reset(void) */
77
PHP_FUNCTION(handlebars_cache_reset)
4✔
78
{
79
    if (HANDLEBARS_G(cache_enable) && HANDLEBARS_G(cache)) {
4✔
80
        handlebars_cache_reset(HANDLEBARS_G(cache));
4✔
81
        RETURN_TRUE;
4✔
82
    } else {
83
        RETURN_FALSE;
×
84
    }
85
}
86
/* }}} */
87

88
/* {{{ PHP_MINIT_FUNCTION */
89
static PHP_RINIT_FUNCTION(handlebars)
2,582✔
90
{
91
#if defined(COMPILE_DL_HANDLEBARS) && defined(ZTS)
92
    ZEND_TSRMLS_CACHE_UPDATE();
93
#endif
94

95
    return SUCCESS;
2,582✔
96
}
97
/* }}} */
98

99
/* {{{ PHP_MINIT_FUNCTION */
100
const char *PHP_HANDLEBARS_MOTD =
101
    "Think not that I am come to send peace on earth: I came not to send peace, but a sword. Matthew 10:34";
102

103
static PHP_MINIT_FUNCTION(handlebars)
2,582✔
104
{
105
    int flags = CONST_CS | CONST_PERSISTENT;
2,582✔
106
    const char * version = handlebars_version_string();
2,582✔
107

108
    REGISTER_INI_ENTRIES();
2,582✔
109

110
    // Register constants
111
    if (zend_hash_str_exists(&module_registry, "psr", sizeof("psr") - 1)) {
2,582✔
UNCOV
112
        handlebars_has_psr = 1;
×
113
    }
114
    REGISTER_LONG_CONSTANT("Handlebars\\PSR", handlebars_has_psr, flags);
2,582✔
115

116
    REGISTER_STRING_CONSTANT("Handlebars\\VERSION", (char *) PHP_HANDLEBARS_VERSION, flags);
2,582✔
117
    REGISTER_STRING_CONSTANT("Handlebars\\LIBVERSION", (char *) version, flags);
2,582✔
118
    REGISTER_STRING_CONSTANT("Handlebars\\LIBVERSION2", (char *) HANDLEBARS_VERSION_STRING, flags);
2,582✔
119
    REGISTER_STRING_CONSTANT("Handlebars\\MOTD", (char *) PHP_HANDLEBARS_MOTD, flags);
2,582✔
120

121
    // Setup root contexts
122
    HANDLEBARS_G(root) = talloc_new(NULL);
2,582✔
123
    HANDLEBARS_G(context) = handlebars_context_ctor_ex(HANDLEBARS_G(root));
2,582✔
124

125
    // Setup cache
126
    if( !HANDLEBARS_G(cache_enable_cli) && 0 == strcmp(sapi_module.name, "cli") ) {
2,582✔
127
        HANDLEBARS_G(cache_enable) = false;
2,552✔
128
    }
129

130
    // Save jmp
131
    jmp_buf buf;
132

133
    if( handlebars_setjmp_ex(HANDLEBARS_G(context), &buf) ) {
2,582✔
UNCOV
134
        HANDLEBARS_G(cache_enable) = 0;
×
135
    }
136

137
    const char * backend = NULL;
2,582✔
138
    if (HANDLEBARS_G(cache_enable)) {
2,582✔
139
        backend = HANDLEBARS_G(cache_backend);
26✔
140
        if( strcmp(backend, "simple") == 0 ) {
26✔
141
            HANDLEBARS_G(cache) = handlebars_cache_simple_ctor(HANDLEBARS_G(context));
12✔
142
#ifdef HANDLEBARS_HAVE_LMDB
143
        } else if( strcmp(backend, "lmdb") == 0 ) {
14✔
144
            HANDLEBARS_G(cache) = handlebars_cache_lmdb_ctor(HANDLEBARS_G(context), HANDLEBARS_G(cache_save_path));
4✔
145
#endif
146
#ifdef HANDLEBARS_HAVE_PTHREAD
147
        } else if( strcmp(backend, "mmap") == 0 ) {
10✔
148
            HANDLEBARS_G(cache) = handlebars_cache_mmap_ctor(HANDLEBARS_G(context), HANDLEBARS_G(cache_max_size), HANDLEBARS_G(cache_max_entries));
10✔
149
#endif
150
        } else {
UNCOV
151
            backend = NULL;
×
152
        }
153
        // @TODO FIXME
154
        // if( strcmp(backend, "mmap") != 0 ) {
155
        //     HANDLEBARS_G(cache)->max_entries = (size_t) HANDLEBARS_G(cache_max_entries);
156
        //     HANDLEBARS_G(cache)->max_size = (size_t) HANDLEBARS_G(cache_max_size);
157
        // }
158
        // HANDLEBARS_G(cache)->max_age = (double) HANDLEBARS_G(cache_max_age);
159
    }
160

161
    if (backend) {
2,582✔
162
        REGISTER_STRING_CONSTANT("Handlebars\\CACHE_BACKEND", (char *) backend, flags);
26✔
163
    } else {
164
#ifdef REGISTER_NULL_CONSTANT
165
        REGISTER_NULL_CONSTANT("Handlebars\\CACHE_BACKEND", flags);
2,556✔
166
#else
167
        REGISTER_LONG_CONSTANT("Handlebars\\CACHE_BACKEND", 0, flags);
168
#endif
169
    }
170

171
    // Call other MINIT functions
172
    PHP_MINIT(handlebars_registry)(INIT_FUNC_ARGS_PASSTHRU); // must be before impl
2,582✔
173
    PHP_MINIT(handlebars_impl)(INIT_FUNC_ARGS_PASSTHRU); // must be before vm
2,582✔
174
    PHP_MINIT(handlebars_exceptions)(INIT_FUNC_ARGS_PASSTHRU);
2,582✔
175
    PHP_MINIT(handlebars_options)(INIT_FUNC_ARGS_PASSTHRU);
2,582✔
176
    PHP_MINIT(handlebars_safe_string)(INIT_FUNC_ARGS_PASSTHRU);
2,582✔
177
    PHP_MINIT(handlebars_utils)(INIT_FUNC_ARGS_PASSTHRU);
2,582✔
178
    PHP_MINIT(handlebars_value)(INIT_FUNC_ARGS_PASSTHRU);
2,582✔
179
    PHP_MINIT(handlebars_vm)(INIT_FUNC_ARGS_PASSTHRU);
2,582✔
180

181
#ifdef PHP_HANDLEBARS_ENABLE_AST
182
    PHP_MINIT(handlebars_compiler)(INIT_FUNC_ARGS_PASSTHRU);
183
    PHP_MINIT(handlebars_opcode)(INIT_FUNC_ARGS_PASSTHRU);
184
    PHP_MINIT(handlebars_parser)(INIT_FUNC_ARGS_PASSTHRU);
185
    PHP_MINIT(handlebars_program)(INIT_FUNC_ARGS_PASSTHRU);
186
    PHP_MINIT(handlebars_token)(INIT_FUNC_ARGS_PASSTHRU);
187
    PHP_MINIT(handlebars_tokenizer)(INIT_FUNC_ARGS_PASSTHRU);
188
#endif
189

190
    return SUCCESS;
2,582✔
191
}
192
/* }}} */
193

194
/* {{{ PHP_MSHUTDOWN_FUNCTION */
195
static PHP_MSHUTDOWN_FUNCTION(handlebars)
2,582✔
196
{
197
    UNREGISTER_INI_ENTRIES();
2,582✔
198

199
    PHP_MSHUTDOWN(handlebars_options)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
2,582✔
200

201
    return SUCCESS;
2,582✔
202
}
203
/* }}} */
204

205
/* {{{ PHP_MINFO_FUNCTION */
206
static PHP_MINFO_FUNCTION(handlebars)
8✔
207
{
208
    char buf[64];
209

210
    php_info_print_table_start();
8✔
211
    php_info_print_table_row(2, "Version", PHP_HANDLEBARS_VERSION);
8✔
212
    php_info_print_table_row(2, "Released", PHP_HANDLEBARS_RELEASE);
8✔
213
    php_info_print_table_row(2, "Authors", PHP_HANDLEBARS_AUTHORS);
8✔
214
    // @todo make spec version from libhandlebars function
215
    php_info_print_table_row(2, "Spec Version", PHP_HANDLEBARS_SPEC);
8✔
216
    php_info_print_table_row(2, "PSR support", handlebars_has_psr ? "active" : "inactive");
8✔
217
    php_info_print_table_row(2, "libhandlebars Version", handlebars_version_string());
8✔
218
    php_info_print_table_row(2, "libhandlebars Version (compile-time)", HANDLEBARS_VERSION_STRING);
8✔
219
    php_info_print_table_row(2, "libhandlebars Handlebars Spec Version", handlebars_spec_version_string());
8✔
220
    php_info_print_table_row(2, "libhandlebars Mustache Spec Version", handlebars_mustache_spec_version_string());
8✔
221
    php_info_print_table_row(2, "xxhash version",  HANDLEBARS_XXHASH_VERSION);
8✔
222

223
    snprintf(buf, sizeof(buf), "%zu", talloc_total_size(HANDLEBARS_G(root)));
8✔
224
    php_info_print_table_row(2, "Local memory usage", buf);
8✔
225
    php_info_print_table_end();
8✔
226

227
    if( HANDLEBARS_G(cache) ) {
8✔
228
        struct handlebars_cache_stat stat = handlebars_cache_stat(HANDLEBARS_G(cache));
4✔
229

230
#if defined(__GNUC__) && !defined(__clang__)
231
#pragma GCC diagnostic push
232
#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
233
#endif
234

235
        php_info_print_table_start();
4✔
236
        php_info_print_table_colspan_header(2, (char *) "Cache");
4✔
237

238
        php_info_print_table_row(2, "Backend", stat.name);
4✔
239

240
        snprintf(buf, sizeof(buf), "%zu", stat.total_size);
4✔
241
        php_info_print_table_row(2, "Block size", buf);
4✔
242

243
        snprintf(buf, sizeof(buf), "%zu", stat.total_table_size);
4✔
244
        php_info_print_table_row(2, "Table size", buf);
4✔
245

246
        snprintf(buf, sizeof(buf), "%zu", stat.total_entries);
4✔
247
        php_info_print_table_row(2, "Table entries", buf);
4✔
248

249
        snprintf(buf, sizeof(buf), "%zu", stat.current_entries);
4✔
250
        php_info_print_table_row(2, "Table entries used", buf);
4✔
251

252
        snprintf(buf, sizeof(buf), "%zu", stat.total_entries > 0 ? stat.total_entries - stat.current_entries : 0);
4✔
253
        php_info_print_table_row(2, "Table entries free", buf);
4✔
254

255
        snprintf(buf, sizeof(buf), "%zu", stat.total_data_size);
4✔
256
        php_info_print_table_row(2, "Data segment size", buf);
4✔
257

258
        snprintf(buf, sizeof(buf), "%zu", stat.current_data_size);
4✔
259
        php_info_print_table_row(2, "Data segment used", buf);
4✔
260

261
        snprintf(buf, sizeof(buf), "%zu", stat.total_data_size > 0 ? stat.total_data_size - stat.current_data_size : 0);
4✔
262
        php_info_print_table_row(2, "Data segment free", buf);
4✔
263

264
        snprintf(buf, sizeof(buf), "%zu", stat.hits);
4✔
265
        php_info_print_table_row(2, "Hits", buf);
4✔
266

267
        snprintf(buf, sizeof(buf), "%zu", stat.misses);
4✔
268
        php_info_print_table_row(2, "Misses", buf);
4✔
269

270
        snprintf(buf, sizeof(buf), "%zu", stat.refcount);
4✔
271
        php_info_print_table_row(2, "Refcount", buf);
4✔
272

273
        snprintf(buf, sizeof(buf), "%zu", stat.collisions);
4✔
274
        php_info_print_table_row(2, "Collisions", buf);
4✔
275

276
#if defined(__GNUC__) && !defined(__clang__)
277
#pragma GCC diagnostic pop
278
#endif
279

280
        php_info_print_table_end();
4✔
281
    }
282

283
    DISPLAY_INI_ENTRIES();
8✔
284

285
    php_info_print_box_start(0);
8✔
286
    PUTS(PHP_HANDLEBARS_MOTD);
8✔
287
    php_info_print_box_end();
8✔
288
}
8✔
289
/* }}} */
290

291
/* {{{ PHP_GINIT_FUNCTION */
292
PHP_GINIT_FUNCTION(handlebars)
2,582✔
293
{
294
#if defined(COMPILE_DL_HANDLEBARS) && defined(ZTS)
295
        ZEND_TSRMLS_CACHE_UPDATE();
296
#endif
297
        memset(handlebars_globals, 0, sizeof(zend_handlebars_globals));
2,582✔
298
    handlebars_globals->pool_size = 0; // @TODO FIXME 128 * 1024;
2,582✔
299
    handlebars_globals->cache_enable = 1;
2,582✔
300
    handlebars_globals->cache_backend = "mmap";
2,582✔
301
    handlebars_globals->cache_save_path = "/tmp/php-handlebars-cache";
2,582✔
302
    handlebars_globals->cache_max_age = -1;
2,582✔
303
    handlebars_globals->cache_max_entries = 349529;
2,582✔
304
    handlebars_globals->cache_max_size = 52428800;
2,582✔
305
}
2,582✔
306
/* }}} */
307

308
/* {{{ handlebars_functions
309
 */
310
const zend_function_entry handlebars_functions[] = {
311
    PHP_FE(handlebars_cache_reset, handlebars_cache_reset_args)
312
    PHP_FE_END
313
};
314
/* }}} */
315

316
/* {{{ handlebars_deps
317
 */
318
static const zend_module_dep handlebars_deps[] = {
319
    ZEND_MOD_OPTIONAL("psr")
320
    ZEND_MOD_END
321
};
322
/* }}} */
323

324
/* {{{ Module Entry */
325
zend_module_entry handlebars_module_entry = {
326
    STANDARD_MODULE_HEADER_EX, NULL,
327
    handlebars_deps,                    /* Deps */
328
    PHP_HANDLEBARS_NAME,                /* Name */
329
    handlebars_functions,               /* Functions */
330
    PHP_MINIT(handlebars),              /* MINIT */
331
    PHP_MSHUTDOWN(handlebars),          /* MSHUTDOWN */
332
    PHP_RINIT(handlebars),              /* RINIT */
333
    NULL,                                                          /* RSHUTDOWN */
334
    PHP_MINFO(handlebars),              /* MINFO */
335
    PHP_HANDLEBARS_VERSION,             /* Version */
336
    PHP_MODULE_GLOBALS(handlebars),     /* Globals */
337
    PHP_GINIT(handlebars),              /* GINIT */
338
    NULL,
339
    NULL,
340
    STANDARD_MODULE_PROPERTIES_EX
341
};
342
#ifdef COMPILE_DL_HANDLEBARS
343
#if defined(ZTS)
344
    ZEND_TSRMLS_CACHE_DEFINE()
345
#endif
346
    ZEND_GET_MODULE(handlebars)      // Common for all PHP extensions which are build as shared modules
2,582✔
347
#endif
348
/* }}} */
349

350
/*
351
 * Local variables:
352
 * tab-width: 4
353
 * c-basic-offset: 4
354
 * End:
355
 * vim600: fdm=marker
356
 * vim: et sw=4 ts=4
357
 */
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc