├── .gitignore ├── README ├── bitmap.c ├── bitmap.h ├── bitmap_5.c ├── bitmap_7.c ├── bitmap_declare.c ├── bitmap_method.c ├── config.m4 ├── config.w32 ├── php_bitmap.c ├── php_bitmap.php └── php_php_bitmap.h /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | autom4te.cache 3 | modules 4 | *~ 5 | *.swp 6 | *.lo 7 | *.la 8 | .deps 9 | .libs 10 | *.log 11 | test.* 12 | Makefile 13 | Makefile.fragments 14 | Makefile.global 15 | Makefile.objects 16 | acinclude.m4 17 | aclocal.m4 18 | autom4te.cache 19 | build 20 | config.cache 21 | config.guess 22 | config.h 23 | config.h.in 24 | config.log 25 | config.nice 26 | config.status 27 | config.sub 28 | configure 29 | configure.in 30 | conftest 31 | conftest.c 32 | include 33 | install-sh 34 | libtool 35 | ltmain.sh 36 | missing 37 | mkinstalldirs 38 | modules 39 | scan_makefile_in.awk 40 | *.dsw 41 | *.plg 42 | *.opt 43 | *.ncb 44 | Release 45 | Release_inline 46 | Debug 47 | Release_TS 48 | Release_TSDbg 49 | Release_TS_inline 50 | Debug_TS 51 | run-tests.php 52 | cscope.out 53 | php_bitmap.loT 54 | tests/*.log 55 | tests/*.out 56 | tests/*.diff 57 | tests/*.php 58 | tests/*.exp 59 | tests/*.sh 60 | tests/*/*.log 61 | tests/*/*.out 62 | tests/*/*.diff 63 | tests/*/*.php 64 | tests/*/*.exp 65 | tests/*/*.sh 66 | tests/*/*/*.log 67 | tests/*/*/*.out 68 | tests/*/*/*.diff 69 | tests/*/*/*.php 70 | tests/*/*/*.exp 71 | tests/*/*/*.sh 72 | tmp-php.ini 73 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | A php version bitmap extension 2 | 3 | install: 4 | phpize 5 | ./configure --enable-php_bitmap 6 | make 7 | make install 8 | 9 | usage: 10 | $foo = new PhpBitmap(); 11 | $foo->setBit(1); 12 | $foo->setBit(100); 13 | $foo->getBit(1); 14 | echo $foo->dumpBit(); 15 | var_export($foo->getBytes()); 16 | 17 | You can init bits from string too. 18 | 19 | $foo = new PhpBitmap('a'); 20 | $foo->dumpBit(); 21 | -------------------------------------------------------------------------------- /bitmap.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | 4 | #if ZEND_MODULE_API_NO > 20131226 5 | #include "bitmap_7.c" 6 | #else 7 | #include "bitmap_5.c" 8 | #endif 9 | -------------------------------------------------------------------------------- /bitmap.h: -------------------------------------------------------------------------------- 1 | #ifndef BITMAP_CLASS_H 2 | #define BITMAP_CLASS_H 3 | typedef struct { 4 | zend_object object; 5 | char *bytes; 6 | size_t size; 7 | 8 | } php_bitmap_base_t; 9 | 10 | 11 | void php_bitmap_init_class(); 12 | 13 | #if ZEND_MODULE_API_NO > 20131226 14 | static void php_bitmap_base_free(zend_object *object); 15 | #else 16 | static void php_bitmap_base_free(php_bitmap_base_t *intern TSRMLS_CC); 17 | #endif 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /bitmap_5.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "bitmap.h" 4 | 5 | 6 | #if ZEND_MODULE_API_NO > 20060613 7 | # define BITMAP_METHOD_BASE(className, name) zim_##className##_##name 8 | #else 9 | # define BITMAP_METHOD_BASE(className, name) zif_##className##_##name 10 | #endif 11 | 12 | #define Z_BITMAP_INTERN(intern, obj) {\ 13 | intern = (php_bitmap_base_t *)zend_object_store_get_object(obj TSRMLS_CC);\ 14 | } 15 | 16 | #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) 17 | # define FREE_OBJECT_EXTRA(base) {\ 18 | zend_object_std_dtor(&base->object TSRMLS_CC);\ 19 | efree(base);\ 20 | } 21 | #else 22 | # define FREE_OBJECT_EXTRA(base) {\ 23 | if (base->object.properties) {\ 24 | zend_hash_destory(base->object.properties);\ 25 | free_hashTable(base->object.properties);\ 26 | }\ 27 | efree(base);\ 28 | } 29 | #endif 30 | 31 | #define GET_BITMAP_THIS(obj) obj 32 | 33 | #define MALLOC_BITMAP_BASE_T emalloc(sizeof(php_bitmap_base_t)); 34 | 35 | #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 0) 36 | # define INIT_BITMAP_OBJECT(base, ce) zend_object_std_init(&base->object, ce TSRMLS_CC); 37 | #else 38 | # define INIT_BITMAP_OBJECT(base, ce) {\ 39 | ALLOC_HASHTABLE(base->object.properties);\ 40 | zend_hash_init(base->object.properties, 0, NULL, ZVAL_PTR_DTOR, 0);\ 41 | base->object.ce = ce;\ 42 | } 43 | #endif 44 | 45 | #if PHP_API_VERSION < 20100412 46 | # define INIT_BITMAP_PROPERTIES(base, ce){\ 47 | zval *tmp;\ 48 | zend_hash_copy(\ 49 | base->object.properties, &ce->default_properties,\ 50 | (copy_ctor_func_t)zval_add_ref, (void *)&tmp, sizeof(zval *));\ 51 | } 52 | #else 53 | # define INIT_BITMAP_PROPERTIES(base, ce) {\ 54 | object_properties_init(&base->object, ce);\ 55 | } 56 | #endif 57 | 58 | #define BITMAP_DECLARE_RETVAL zend_object_value BITMAP_NEW_RETVAL; 59 | 60 | #define BITMAP_NEW_RETVAL retval 61 | #define BITMAP_NEW_RETVAL_TYPE zend_object_value 62 | #define BITMAP_INIT_HANDLER(base) {\ 63 | BITMAP_NEW_RETVAL.handle = zend_objects_store_put(\ 64 | base, (zend_objects_store_dtor_t)zend_objects_destroy_object,\ 65 | (zend_objects_free_object_storage_t)php_bitmap_base_free,\ 66 | NULL TSRMLS_CC);\ 67 | retval.handlers = zend_get_std_object_handlers();\ 68 | } 69 | 70 | #define BITMAP_RETURN_STRING(s, l) RETVAL_STRINGL(s, l ,1); 71 | 72 | #include "bitmap_declare.c" 73 | 74 | 75 | BITMAP_NEW_RETVAL_TYPE php_bitmap_base_new(zend_class_entry *ce) /* {{{ */ { 76 | BITMAP_DECLARE_RETVAL; 77 | php_bitmap_base_t *intern = MALLOC_BITMAP_BASE_T; 78 | intern->size = 8; 79 | intern->bytes = ecalloc(1, intern->size); 80 | INIT_BITMAP_OBJECT(intern, ce); 81 | INIT_BITMAP_PROPERTIES(intern, ce); 82 | BITMAP_INIT_HANDLER(intern); 83 | return BITMAP_NEW_RETVAL; 84 | } 85 | 86 | static void php_bitmap_base_free(php_bitmap_base_t *intern TSRMLS_CC) /* {{{ */ { 87 | efree(intern->bytes); 88 | FREE_OBJECT_EXTRA(intern); 89 | } 90 | 91 | #include "bitmap_method.c" 92 | 93 | void php_bitmap_init_class() /* {{{ */ { 94 | zend_class_entry ce; 95 | TSRMLS_FETCH(); 96 | /* base */ 97 | INIT_CLASS_ENTRY(ce, "PhpBitmap", bitmap_base_methods); 98 | bitmap_ce = zend_register_internal_class(&ce); 99 | bitmap_ce->create_object = php_bitmap_base_new; 100 | } 101 | -------------------------------------------------------------------------------- /bitmap_7.c: -------------------------------------------------------------------------------- 1 | #include "php.h" 2 | 3 | #include "bitmap.h" 4 | 5 | #define BITMAP_RETURN_STRING(s, l) RETVAL_STRINGL(s, l); 6 | 7 | zend_object_handlers bitmap_handlers; 8 | #include "bitmap_declare.c" 9 | 10 | static inline php_bitmap_base_t *bitmap_base_fetch_object(zend_object *obj) { 11 | return (php_bitmap_base_t *)((char*)(obj) - XtOffsetOf(php_bitmap_base_t, object)); 12 | } 13 | 14 | #define Z_BITMAP_INTERN(intern, obj) {\ 15 | intern = (php_bitmap_base_t *)((char*)(obj) - XtOffsetOf(php_bitmap_base_t, object));\ 16 | } 17 | #define Z_BITMAP_BASE_P(zv) php_bitmap_fetch_object(Z_OBJ_P((zv))) 18 | 19 | #define GET_BITMAP_THIS(obj) Z_OBJ_P(obj) 20 | 21 | zend_object *php_bitmap_base_new(zend_class_entry *ce) /* {{{ */ { 22 | php_bitmap_base_t *intern = ecalloc(1, sizeof(php_bitmap_base_t) + zend_object_properties_size(ce)); 23 | intern->size = 8; 24 | intern->bytes = ecalloc(1, intern->size); 25 | zend_object_std_init(&intern->object, ce); 26 | object_properties_init(&intern->object, ce); 27 | intern->object.handlers = &bitmap_handlers; 28 | 29 | return &intern->object; 30 | } 31 | 32 | static void php_bitmap_base_free(zend_object *object) /* {{{ */ { 33 | php_bitmap_base_t *intern = bitmap_base_fetch_object(object); 34 | 35 | if (!intern) { 36 | return; 37 | } 38 | efree(intern->bytes); 39 | zend_object_std_dtor(&intern->object); 40 | } 41 | 42 | #include "bitmap_method.c" 43 | 44 | void php_bitmap_init_class() /* {{{ */ { 45 | zend_class_entry ce; 46 | 47 | /* base */ 48 | INIT_CLASS_ENTRY(ce, "PhpBitmap", bitmap_base_methods); 49 | bitmap_ce = zend_register_internal_class(&ce); 50 | bitmap_ce->create_object = php_bitmap_base_new; 51 | memcpy(&bitmap_handlers, zend_get_std_object_handlers(),sizeof bitmap_handlers); 52 | bitmap_handlers.offset = XtOffsetOf(php_bitmap_base_t, object); 53 | bitmap_handlers.free_obj = php_bitmap_base_free; 54 | } 55 | -------------------------------------------------------------------------------- /bitmap_declare.c: -------------------------------------------------------------------------------- 1 | #ifndef __bitmap_declare_c 2 | #define __bitmap_declare_c 3 | //common 4 | static zend_class_entry *bitmap_ce; 5 | 6 | static ZEND_METHOD(bitmap, __construct); 7 | static ZEND_METHOD(bitmap, setBit); 8 | static ZEND_METHOD(bitmap, getBit); 9 | static ZEND_METHOD(bitmap, dumpBit); 10 | static ZEND_METHOD(bitmap, getBytes); 11 | 12 | ZEND_BEGIN_ARG_INFO_EX(arginfo_bitmap_base___construct, 0, 0, 1) 13 | ZEND_ARG_INFO(0, str) 14 | ZEND_END_ARG_INFO() 15 | 16 | 17 | ZEND_BEGIN_ARG_INFO_EX(arginfo_bitmap_base_getBit, 0, 0, 1) 18 | ZEND_ARG_INFO(0, offset) 19 | ZEND_END_ARG_INFO() 20 | 21 | ZEND_BEGIN_ARG_INFO_EX(arginfo_bitmap_base_dumpBit, 0, 0, 1) 22 | ZEND_ARG_INFO(0, offset) 23 | ZEND_END_ARG_INFO() 24 | 25 | ZEND_BEGIN_ARG_INFO_EX(arginfo_bitmap_base_setBit, 0, 0, 2) 26 | ZEND_ARG_INFO(0, offset) 27 | ZEND_ARG_INFO(0, value) 28 | ZEND_END_ARG_INFO() 29 | 30 | ZEND_BEGIN_ARG_INFO_EX(arginfo_bitmap_base_getBytes, 0, 0, 0) 31 | ZEND_END_ARG_INFO() 32 | 33 | static zend_function_entry bitmap_base_methods[] = { 34 | ZEND_ME(bitmap, __construct, arginfo_bitmap_base___construct, ZEND_ACC_PUBLIC) 35 | ZEND_ME(bitmap, setBit, arginfo_bitmap_base_setBit, ZEND_ACC_PUBLIC) 36 | ZEND_ME(bitmap, getBit, arginfo_bitmap_base_getBit, ZEND_ACC_PUBLIC) 37 | ZEND_ME(bitmap, dumpBit, arginfo_bitmap_base_dumpBit, ZEND_ACC_PUBLIC) 38 | ZEND_ME(bitmap, getBytes, arginfo_bitmap_base_getBytes, ZEND_ACC_PUBLIC) 39 | {NULL, NULL, NULL} 40 | }; 41 | #endif 42 | -------------------------------------------------------------------------------- /bitmap_method.c: -------------------------------------------------------------------------------- 1 | static int bitmap_get_byte_addr(php_bitmap_base_t *intern, size_t index, char **pos, char *rm) { 2 | size_t byteIndex; 3 | short offset, i; 4 | unsigned char mask = 0x80; 5 | if (index <= 0) { 6 | return 0; 7 | } 8 | byteIndex = (size_t)floor((index - 1) / 8); 9 | offset = (index - 1) % 8; 10 | for (i = 0; i < offset; i++) { 11 | mask = mask >> 1; 12 | } 13 | *rm = mask; 14 | *pos = intern->bytes + byteIndex; 15 | return 1; 16 | } 17 | 18 | 19 | static int bitmap_resize_byte_map(php_bitmap_base_t *intern, size_t size) { 20 | size_t oldSize = intern->size; 21 | if (oldSize > size) { 22 | return 1; 23 | } 24 | char *newBytes = ecalloc(1, size); 25 | memcpy(newBytes, intern->bytes, intern->size); 26 | efree(intern->bytes); 27 | intern->bytes = newBytes; 28 | intern->size = size; 29 | return 0; 30 | } 31 | 32 | static ZEND_METHOD(bitmap, getBit) { 33 | php_bitmap_base_t *intern; 34 | int offset, index, byteIndex, i; 35 | char* pos, rm; 36 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { 37 | return; 38 | } 39 | 40 | Z_BITMAP_INTERN(intern, GET_BITMAP_THIS(getThis())); 41 | if (index > intern->size) { 42 | RETURN_FALSE; 43 | } 44 | 45 | bitmap_get_byte_addr(intern, index, &pos, &rm); 46 | char result = *pos & rm ? '1' : '0'; 47 | BITMAP_RETURN_STRING(&result, 1); 48 | } 49 | 50 | 51 | static ZEND_METHOD(bitmap, setBit) { 52 | php_bitmap_base_t *intern; 53 | int offset, index, byteIndex, i; 54 | char *pos, rm; 55 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { 56 | return; 57 | } 58 | Z_BITMAP_INTERN(intern, GET_BITMAP_THIS(getThis())); 59 | size_t byteOffset = (size_t)floor((index - 1) / 8); 60 | if (byteOffset >= intern->size) { 61 | bitmap_resize_byte_map(intern, byteOffset * 2); 62 | } 63 | 64 | bitmap_get_byte_addr(intern, index, &pos, &rm); 65 | *pos = *pos | rm; 66 | } 67 | 68 | static ZEND_METHOD(bitmap, dumpBit) { 69 | php_bitmap_base_t *intern; 70 | Z_BITMAP_INTERN(intern, GET_BITMAP_THIS(getThis())); 71 | short j, count; 72 | size_t total, i; 73 | total = intern->size * sizeof(char) * 8; 74 | char *result = ecalloc(1, total); 75 | for (i = 0; i < intern->size; i ++) { 76 | count = 0; 77 | for (j = 0x80; j > 0; j /= 2) { 78 | result[i * 8 + count] = intern->bytes[i] & j ? '1' : '0'; 79 | count ++; 80 | } 81 | } 82 | BITMAP_RETURN_STRING(result, total); 83 | efree(result); 84 | } 85 | 86 | static ZEND_METHOD(bitmap, getBytes) { 87 | php_bitmap_base_t *intern; 88 | Z_BITMAP_INTERN(intern, GET_BITMAP_THIS(getThis())); 89 | BITMAP_RETURN_STRING(intern->bytes, intern->size); 90 | } 91 | 92 | static ZEND_METHOD(bitmap, __construct) /* {{{ */ { 93 | php_bitmap_base_t *intern; 94 | int len = 0; 95 | char *str; 96 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &str, &len) == FAILURE) { 97 | return; 98 | } 99 | if (len == 0) { 100 | return; 101 | } 102 | Z_BITMAP_INTERN(intern, GET_BITMAP_THIS(getThis())); 103 | if (len >= intern->size) { 104 | char *newBytes = ecalloc(1, len); 105 | efree(intern->bytes); 106 | intern->bytes = newBytes; 107 | intern->size = len; 108 | } 109 | memcpy(intern->bytes, str, len); 110 | } 111 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension php_bitmap 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(php_bitmap, for php_bitmap support, 11 | dnl Make sure that the comment is aligned: 12 | dnl [ --with-php_bitmap Include php_bitmap support]) 13 | 14 | dnl Otherwise use enable: 15 | 16 | PHP_ARG_ENABLE(php_bitmap, whether to enable php_bitmap support, 17 | Make sure that the comment is aligned: 18 | [ --enable-php_bitmap Enable php_bitmap support]) 19 | 20 | echo $PHP_PHP_BITMAP 21 | if test "$PHP_PHP_BITMAP" != "no"; then 22 | dnl Write more examples of tests here... 23 | 24 | dnl # --with-php_bitmap -> check with-path 25 | dnl SEARCH_PATH="/usr/local /usr" # you might want to change this 26 | dnl SEARCH_FOR="/include/php_bitmap.h" # you most likely want to change this 27 | dnl if test -r $PHP_PHP_BITMAP/$SEARCH_FOR; then # path given as parameter 28 | dnl PHP_BITMAP_DIR=$PHP_PHP_BITMAP 29 | dnl else # search default path list 30 | dnl AC_MSG_CHECKING([for php_bitmap files in default path]) 31 | dnl for i in $SEARCH_PATH ; do 32 | dnl if test -r $i/$SEARCH_FOR; then 33 | dnl PHP_BITMAP_DIR=$i 34 | dnl AC_MSG_RESULT(found in $i) 35 | dnl fi 36 | dnl done 37 | dnl fi 38 | dnl 39 | dnl if test -z "$PHP_BITMAP_DIR"; then 40 | dnl AC_MSG_RESULT([not found]) 41 | dnl AC_MSG_ERROR([Please reinstall the php_bitmap distribution]) 42 | dnl fi 43 | 44 | dnl # --with-php_bitmap -> add include path 45 | dnl PHP_ADD_INCLUDE($PHP_BITMAP_DIR/include) 46 | 47 | dnl # --with-php_bitmap -> check for lib and symbol presence 48 | dnl LIBNAME=php_bitmap # you may want to change this 49 | dnl LIBSYMBOL=php_bitmap # you most likely want to change this 50 | 51 | dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 52 | dnl [ 53 | dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $PHP_BITMAP_DIR/$PHP_LIBDIR, PHP_BITMAP_SHARED_LIBADD) 54 | AC_DEFINE(HAVE_PHP_BITMAPLIB,1,[ ]) 55 | dnl ],[ 56 | dnl AC_MSG_ERROR([wrong php_bitmap lib version or lib not found]) 57 | dnl ],[ 58 | dnl -L$PHP_BITMAP_DIR/$PHP_LIBDIR -lm 59 | dnl ]) 60 | dnl 61 | dnl PHP_SUBST(PHP_BITMAP_SHARED_LIBADD) 62 | 63 | PHP_NEW_EXTENSION(php_bitmap, bitmap.c php_bitmap.c, $ext_shared) 64 | fi 65 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // $Id$ 2 | // vim:ft=javascript 3 | 4 | // If your extension references something external, use ARG_WITH 5 | // ARG_WITH("php_bitmap", "for php_bitmap support", "no"); 6 | 7 | // Otherwise, use ARG_ENABLE 8 | // ARG_ENABLE("php_bitmap", "enable php_bitmap support", "no"); 9 | 10 | if (PHP_PHP_BITMAP != "no") { 11 | EXTENSION("php_bitmap", "php_bitmap.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /php_bitmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2017 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | #include "config.h" 23 | #endif 24 | 25 | #include "php.h" 26 | #include "bitmap.h" 27 | #include "php_ini.h" 28 | #include "ext/standard/info.h" 29 | #include "php_php_bitmap.h" 30 | 31 | /* If you declare any globals in php_php_bitmap.h uncomment this: 32 | ZEND_DECLARE_MODULE_GLOBALS(php_bitmap) 33 | */ 34 | 35 | /* True global resources - no need for thread safety here */ 36 | static int le_php_bitmap; 37 | 38 | /* {{{ PHP_INI 39 | */ 40 | /* Remove comments and fill if you need to have entries in php.ini 41 | PHP_INI_BEGIN() 42 | STD_PHP_INI_ENTRY("php_bitmap.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_php_bitmap_globals, php_bitmap_globals) 43 | STD_PHP_INI_ENTRY("php_bitmap.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_php_bitmap_globals, php_bitmap_globals) 44 | PHP_INI_END() 45 | */ 46 | /* }}} */ 47 | 48 | /* Remove the following function when you have successfully modified config.m4 49 | so that your module can be compiled into PHP, it exists only for testing 50 | purposes. */ 51 | 52 | /* Every user-visible function in PHP should document itself in the source */ 53 | /* {{{ proto string confirm_php_bitmap_compiled(string arg) 54 | Return a string to confirm that the module is compiled in */ 55 | PHP_FUNCTION(confirm_php_bitmap_compiled) 56 | { 57 | 58 | } 59 | /* }}} */ 60 | /* The previous line is meant for vim and emacs, so it can correctly fold and 61 | unfold functions in source code. See the corresponding marks just before 62 | function definition, where the functions purpose is also documented. Please 63 | follow this convention for the convenience of others editing your code. 64 | */ 65 | 66 | 67 | /* {{{ php_php_bitmap_init_globals 68 | */ 69 | /* Uncomment this function if you have INI entries 70 | static void php_php_bitmap_init_globals(zend_php_bitmap_globals *php_bitmap_globals) 71 | { 72 | php_bitmap_globals->global_value = 0; 73 | php_bitmap_globals->global_string = NULL; 74 | } 75 | */ 76 | /* }}} */ 77 | 78 | /* {{{ PHP_MINIT_FUNCTION 79 | */ 80 | PHP_MINIT_FUNCTION(php_bitmap) 81 | { 82 | /* If you have INI entries, uncomment these lines 83 | REGISTER_INI_ENTRIES(); 84 | */ 85 | php_bitmap_init_class(); 86 | return SUCCESS; 87 | } 88 | /* }}} */ 89 | 90 | /* {{{ PHP_MSHUTDOWN_FUNCTION 91 | */ 92 | PHP_MSHUTDOWN_FUNCTION(php_bitmap) 93 | { 94 | /* uncomment this line if you have INI entries 95 | UNREGISTER_INI_ENTRIES(); 96 | */ 97 | return SUCCESS; 98 | } 99 | /* }}} */ 100 | 101 | /* Remove if there's nothing to do at request start */ 102 | /* {{{ PHP_RINIT_FUNCTION 103 | */ 104 | PHP_RINIT_FUNCTION(php_bitmap) 105 | { 106 | #if defined(COMPILE_DL_PHP_BITMAP) && defined(ZTS) 107 | ZEND_TSRMLS_CACHE_UPDATE(); 108 | #endif 109 | return SUCCESS; 110 | } 111 | /* }}} */ 112 | 113 | /* Remove if there's nothing to do at request end */ 114 | /* {{{ PHP_RSHUTDOWN_FUNCTION 115 | */ 116 | PHP_RSHUTDOWN_FUNCTION(php_bitmap) 117 | { 118 | return SUCCESS; 119 | } 120 | /* }}} */ 121 | 122 | /* {{{ PHP_MINFO_FUNCTION 123 | */ 124 | PHP_MINFO_FUNCTION(php_bitmap) 125 | { 126 | php_info_print_table_start(); 127 | php_info_print_table_header(2, "php_bitmap support", "enabled"); 128 | php_info_print_table_end(); 129 | 130 | /* Remove comments if you have entries in php.ini 131 | DISPLAY_INI_ENTRIES(); 132 | */ 133 | } 134 | /* }}} */ 135 | 136 | /* {{{ php_bitmap_functions[] 137 | * 138 | * Every user visible function must have an entry in php_bitmap_functions[]. 139 | */ 140 | const zend_function_entry php_bitmap_functions[] = { 141 | PHP_FE(confirm_php_bitmap_compiled, NULL) /* For testing, remove later. */ 142 | PHP_FE_END /* Must be the last line in php_bitmap_functions[] */ 143 | }; 144 | /* }}} */ 145 | 146 | /* {{{ php_bitmap_module_entry 147 | */ 148 | zend_module_entry php_bitmap_module_entry = { 149 | STANDARD_MODULE_HEADER, 150 | "php_bitmap", 151 | php_bitmap_functions, 152 | PHP_MINIT(php_bitmap), 153 | PHP_MSHUTDOWN(php_bitmap), 154 | PHP_RINIT(php_bitmap), /* Replace with NULL if there's nothing to do at request start */ 155 | PHP_RSHUTDOWN(php_bitmap), /* Replace with NULL if there's nothing to do at request end */ 156 | PHP_MINFO(php_bitmap), 157 | PHP_PHP_BITMAP_VERSION, 158 | STANDARD_MODULE_PROPERTIES 159 | }; 160 | /* }}} */ 161 | 162 | #ifdef COMPILE_DL_PHP_BITMAP 163 | #ifdef ZTS 164 | ZEND_TSRMLS_CACHE_DEFINE() 165 | #endif 166 | ZEND_GET_MODULE(php_bitmap) 167 | #endif 168 | -------------------------------------------------------------------------------- /php_bitmap.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | if(!extension_loaded('php_bitmap')) { 5 | dl('php_bitmap.' . PHP_SHLIB_SUFFIX); 6 | } 7 | $module = 'php_bitmap'; 8 | $functions = get_extension_funcs($module); 9 | echo "Functions available in the test extension:$br\n"; 10 | foreach($functions as $func) { 11 | echo $func."$br\n"; 12 | } 13 | echo "$br\n"; 14 | $function = 'confirm_' . $module . '_compiled'; 15 | if (extension_loaded($module)) { 16 | $str = $function($module); 17 | } else { 18 | $str = "Module $module is not compiled into PHP"; 19 | } 20 | echo "$str\n"; 21 | ?> 22 | -------------------------------------------------------------------------------- /php_php_bitmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2017 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | /* $Id$ */ 20 | 21 | #ifndef PHP_PHP_BITMAP_H 22 | #define PHP_PHP_BITMAP_H 23 | 24 | extern zend_module_entry php_bitmap_module_entry; 25 | #define phpext_php_bitmap_ptr &php_bitmap_module_entry 26 | 27 | #define PHP_PHP_BITMAP_VERSION "0.1.0" /* Replace with version number for your extension */ 28 | 29 | #ifdef PHP_WIN32 30 | # define PHP_PHP_BITMAP_API __declspec(dllexport) 31 | #elif defined(__GNUC__) && __GNUC__ >= 4 32 | # define PHP_PHP_BITMAP_API __attribute__ ((visibility("default"))) 33 | #else 34 | # define PHP_PHP_BITMAP_API 35 | #endif 36 | 37 | #ifdef ZTS 38 | #include "TSRM.h" 39 | #endif 40 | 41 | /* 42 | Declare any global variables you may need between the BEGIN 43 | and END macros here: 44 | 45 | ZEND_BEGIN_MODULE_GLOBALS(php_bitmap) 46 | zend_long global_value; 47 | char *global_string; 48 | ZEND_END_MODULE_GLOBALS(php_bitmap) 49 | */ 50 | 51 | /* Always refer to the globals in your function as PHP_BITMAP_G(variable). 52 | You are encouraged to rename these macros something shorter, see 53 | examples in any other php module directory. 54 | */ 55 | #define PHP_BITMAP_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(php_bitmap, v) 56 | 57 | #if defined(ZTS) && defined(COMPILE_DL_PHP_BITMAP) 58 | ZEND_TSRMLS_CACHE_EXTERN() 59 | #endif 60 | 61 | #endif /* PHP_PHP_BITMAP_H */ 62 | 63 | 64 | /* 65 | * Local variables: 66 | * tab-width: 4 67 | * c-basic-offset: 4 68 | * End: 69 | * vim600: noet sw=4 ts=4 fdm=marker 70 | * vim<600: noet sw=4 ts=4 71 | */ 72 | --------------------------------------------------------------------------------