├── rust_fib.h ├── rust_fib_test.c ├── rust_fib.php ├── php_fib.php ├── rust_fib.rs ├── config.m4 ├── php_rust_fib.h └── rust_fib.c /rust_fib.h: -------------------------------------------------------------------------------- 1 | #ifndef __RUST_FIB 2 | #define __RUST_FIB 3 | 4 | unsigned long rust_fib(unsigned long at); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /rust_fib_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rust_fib.h" 3 | 4 | int main(int argc, char *argv[]) { 5 | printf("%d\n", rust_fib(46)); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /rust_fib.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | if(!extension_loaded('rust_fib')) { 5 | dl('rust_fib.' . PHP_SHLIB_SUFFIX); 6 | } 7 | 8 | for ($i = 0; $i < 100000; $i ++) { 9 | confirm_rust_fib_compiled(92); 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /php_fib.php: -------------------------------------------------------------------------------- 1 | usize { 4 | if at == 0 { 5 | return 0; 6 | } else if at == 1 { 7 | return 1; 8 | } 9 | 10 | let mut total = 1; 11 | let mut parent = 1; 12 | let mut gp = 0; 13 | for _ in 1 .. at { 14 | total = parent + gp; 15 | gp = parent; 16 | parent = total; 17 | } 18 | 19 | return total; 20 | } 21 | 22 | #[no_mangle] 23 | pub extern "C" fn rust_fib(at: usize) -> usize { 24 | fib(at) 25 | } 26 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension rust_fib 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 | PHP_ARG_WITH(rust_fib, for rust_fib support, 11 | Make sure that the comment is aligned: 12 | [ --with-rust_fib Include rust_fib support]) 13 | 14 | dnl Otherwise use enable: 15 | 16 | dnl PHP_ARG_ENABLE(rust_fib, whether to enable rust_fib support, 17 | dnl Make sure that the comment is aligned: 18 | dnl [ --enable-rust_fib Enable rust_fib support]) 19 | 20 | if test "$PHP_RUST_FIB" != "no"; then 21 | dnl Write more examples of tests here... 22 | 23 | dnl # --with-rust_fib -> check with-path 24 | dnl SEARCH_PATH="/usr/local /usr" # you might want to change this 25 | dnl SEARCH_FOR="/include/rust_fib.h" # you most likely want to change this 26 | dnl if test -r $PHP_RUST_FIB/$SEARCH_FOR; then # path given as parameter 27 | dnl RUST_FIB_DIR=$PHP_RUST_FIB 28 | dnl else # search default path list 29 | dnl AC_MSG_CHECKING([for rust_fib files in default path]) 30 | dnl for i in $SEARCH_PATH ; do 31 | dnl if test -r $i/$SEARCH_FOR; then 32 | dnl RUST_FIB_DIR=$i 33 | dnl AC_MSG_RESULT(found in $i) 34 | dnl fi 35 | dnl done 36 | dnl fi 37 | dnl 38 | dnl if test -z "$RUST_FIB_DIR"; then 39 | dnl AC_MSG_RESULT([not found]) 40 | dnl AC_MSG_ERROR([Please reinstall the rust_fib distribution]) 41 | dnl fi 42 | 43 | dnl # --with-rust_fib -> add include path 44 | dnl PHP_ADD_INCLUDE($RUST_FIB_DIR/include) 45 | 46 | dnl # --with-rust_fib -> check for lib and symbol presence 47 | dnl LIBNAME=rust_fib # you may want to change this 48 | dnl LIBSYMBOL=rust_fib # you most likely want to change this 49 | 50 | dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 51 | dnl [ 52 | dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $RUST_FIB_DIR/$PHP_LIBDIR, RUST_FIB_SHARED_LIBADD) 53 | dnl AC_DEFINE(HAVE_RUST_FIBLIB,1,[ ]) 54 | dnl ],[ 55 | dnl AC_MSG_ERROR([wrong rust_fib lib version or lib not found]) 56 | dnl ],[ 57 | dnl -L$RUST_FIB_DIR/$PHP_LIBDIR -lm 58 | dnl ]) 59 | dnl 60 | PHP_SUBST(RUST_FIB_SHARED_LIBADD) 61 | 62 | PHP_ADD_LIBRARY_WITH_PATH(rust_fib, ., RUST_FIB_SHARED_LIBADD) 63 | 64 | PHP_NEW_EXTENSION(rust_fib, rust_fib.c, $ext_shared) 65 | fi 66 | -------------------------------------------------------------------------------- /php_rust_fib.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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_RUST_FIB_H 22 | #define PHP_RUST_FIB_H 23 | 24 | extern zend_module_entry rust_fib_module_entry; 25 | #define phpext_rust_fib_ptr &rust_fib_module_entry 26 | 27 | #define PHP_RUST_FIB_VERSION "0.1.0" /* Replace with version number for your extension */ 28 | 29 | #ifdef PHP_WIN32 30 | # define PHP_RUST_FIB_API __declspec(dllexport) 31 | #elif defined(__GNUC__) && __GNUC__ >= 4 32 | # define PHP_RUST_FIB_API __attribute__ ((visibility("default"))) 33 | #else 34 | # define PHP_RUST_FIB_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(rust_fib) 46 | long global_value; 47 | char *global_string; 48 | ZEND_END_MODULE_GLOBALS(rust_fib) 49 | */ 50 | 51 | /* In every utility function you add that needs to use variables 52 | in php_rust_fib_globals, call TSRMLS_FETCH(); after declaring other 53 | variables used by that function, or better yet, pass in TSRMLS_CC 54 | after the last function argument and declare your utility function 55 | with TSRMLS_DC after the last declared argument. Always refer to 56 | the globals in your function as RUST_FIB_G(variable). You are 57 | encouraged to rename these macros something shorter, see 58 | examples in any other php module directory. 59 | */ 60 | 61 | #ifdef ZTS 62 | #define RUST_FIB_G(v) TSRMG(rust_fib_globals_id, zend_rust_fib_globals *, v) 63 | #else 64 | #define RUST_FIB_G(v) (rust_fib_globals.v) 65 | #endif 66 | 67 | #endif /* PHP_RUST_FIB_H */ 68 | 69 | 70 | /* 71 | * Local variables: 72 | * tab-width: 4 73 | * c-basic-offset: 4 74 | * End: 75 | * vim600: noet sw=4 ts=4 fdm=marker 76 | * vim<600: noet sw=4 ts=4 77 | */ 78 | -------------------------------------------------------------------------------- /rust_fib.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 5 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2015 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 "php_ini.h" 27 | #include "ext/standard/info.h" 28 | #include "php_rust_fib.h" 29 | #include "rust_fib.h" 30 | 31 | /* If you declare any globals in php_rust_fib.h uncomment this: 32 | ZEND_DECLARE_MODULE_GLOBALS(rust_fib) 33 | */ 34 | 35 | /* True global resources - no need for thread safety here */ 36 | static int le_rust_fib; 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("rust_fib.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_rust_fib_globals, rust_fib_globals) 43 | STD_PHP_INI_ENTRY("rust_fib.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_rust_fib_globals, rust_fib_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_rust_fib_compiled(string arg) 54 | Return a string to confirm that the module is compiled in */ 55 | PHP_FUNCTION(confirm_rust_fib_compiled) 56 | { 57 | long number; 58 | 59 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &number) == FAILURE) { 60 | return; 61 | } 62 | 63 | RETURN_LONG(rust_fib(number)); 64 | } 65 | /* }}} */ 66 | /* The previous line is meant for vim and emacs, so it can correctly fold and 67 | unfold functions in source code. See the corresponding marks just before 68 | function definition, where the functions purpose is also documented. Please 69 | follow this convention for the convenience of others editing your code. 70 | */ 71 | 72 | 73 | /* {{{ php_rust_fib_init_globals 74 | */ 75 | /* Uncomment this function if you have INI entries 76 | static void php_rust_fib_init_globals(zend_rust_fib_globals *rust_fib_globals) 77 | { 78 | rust_fib_globals->global_value = 0; 79 | rust_fib_globals->global_string = NULL; 80 | } 81 | */ 82 | /* }}} */ 83 | 84 | /* {{{ PHP_MINIT_FUNCTION 85 | */ 86 | PHP_MINIT_FUNCTION(rust_fib) 87 | { 88 | /* If you have INI entries, uncomment these lines 89 | REGISTER_INI_ENTRIES(); 90 | */ 91 | return SUCCESS; 92 | } 93 | /* }}} */ 94 | 95 | /* {{{ PHP_MSHUTDOWN_FUNCTION 96 | */ 97 | PHP_MSHUTDOWN_FUNCTION(rust_fib) 98 | { 99 | /* uncomment this line if you have INI entries 100 | UNREGISTER_INI_ENTRIES(); 101 | */ 102 | return SUCCESS; 103 | } 104 | /* }}} */ 105 | 106 | /* Remove if there's nothing to do at request start */ 107 | /* {{{ PHP_RINIT_FUNCTION 108 | */ 109 | PHP_RINIT_FUNCTION(rust_fib) 110 | { 111 | return SUCCESS; 112 | } 113 | /* }}} */ 114 | 115 | /* Remove if there's nothing to do at request end */ 116 | /* {{{ PHP_RSHUTDOWN_FUNCTION 117 | */ 118 | PHP_RSHUTDOWN_FUNCTION(rust_fib) 119 | { 120 | return SUCCESS; 121 | } 122 | /* }}} */ 123 | 124 | /* {{{ PHP_MINFO_FUNCTION 125 | */ 126 | PHP_MINFO_FUNCTION(rust_fib) 127 | { 128 | php_info_print_table_start(); 129 | php_info_print_table_header(2, "rust_fib support", "enabled"); 130 | php_info_print_table_end(); 131 | 132 | /* Remove comments if you have entries in php.ini 133 | DISPLAY_INI_ENTRIES(); 134 | */ 135 | } 136 | /* }}} */ 137 | 138 | /* {{{ rust_fib_functions[] 139 | * 140 | * Every user visible function must have an entry in rust_fib_functions[]. 141 | */ 142 | const zend_function_entry rust_fib_functions[] = { 143 | PHP_FE(confirm_rust_fib_compiled, NULL) /* For testing, remove later. */ 144 | PHP_FE_END /* Must be the last line in rust_fib_functions[] */ 145 | }; 146 | /* }}} */ 147 | 148 | /* {{{ rust_fib_module_entry 149 | */ 150 | zend_module_entry rust_fib_module_entry = { 151 | STANDARD_MODULE_HEADER, 152 | "rust_fib", 153 | rust_fib_functions, 154 | PHP_MINIT(rust_fib), 155 | PHP_MSHUTDOWN(rust_fib), 156 | NULL, 157 | NULL, 158 | PHP_MINFO(rust_fib), 159 | PHP_RUST_FIB_VERSION, 160 | STANDARD_MODULE_PROPERTIES 161 | }; 162 | /* }}} */ 163 | 164 | #ifdef COMPILE_DL_RUST_FIB 165 | ZEND_GET_MODULE(rust_fib) 166 | #endif 167 | 168 | /* 169 | * Local variables: 170 | * tab-width: 4 171 | * c-basic-offset: 4 172 | * End: 173 | * vim600: noet sw=4 ts=4 fdm=marker 174 | * vim<600: noet sw=4 ts=4 175 | */ 176 | --------------------------------------------------------------------------------