Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Commit 001a918

Browse files
committed
first commit
0 parents  commit 001a918

17 files changed

+326
-0
lines changed

.gitignore

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
*.lo
2+
*.la
3+
.libs
4+
acinclude.m4
5+
aclocal.m4
6+
autom4te.cache
7+
build
8+
config.guess
9+
config.h
10+
config.h.in
11+
config.log
12+
config.nice
13+
config.status
14+
config.sub
15+
configure
16+
configure.ac
17+
configure.in
18+
include
19+
install-sh
20+
libtool
21+
ltmain.sh
22+
Makefile
23+
Makefile.fragments
24+
Makefile.global
25+
Makefile.objects
26+
missing
27+
mkinstalldirs
28+
modules
29+
run-tests.php
30+
tests/*/*.diff
31+
tests/*/*.out
32+
tests/*/*.php
33+
tests/*/*.exp
34+
tests/*/*.log
35+
tests/*/*.sh

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# php-ext-helloworld-src

config.m4

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
dnl config.m4 for extension helloworld
2+
3+
dnl Comments in this file start with the string 'dnl'.
4+
dnl Remove where necessary.
5+
6+
dnl If your extension references something external, use 'with':
7+
8+
dnl PHP_ARG_WITH([helloworld],
9+
dnl [for helloworld support],
10+
dnl [AS_HELP_STRING([--with-helloworld],
11+
dnl [Include helloworld support])])
12+
13+
dnl Otherwise use 'enable':
14+
15+
PHP_ARG_ENABLE([helloworld],
16+
[whether to enable helloworld support],
17+
[AS_HELP_STRING([--enable-helloworld],
18+
[Enable helloworld support])],
19+
[no])
20+
21+
if test "$PHP_HELLOWORLD" != "no"; then
22+
dnl Write more examples of tests here...
23+
24+
dnl Remove this code block if the library does not support pkg-config.
25+
dnl PKG_CHECK_MODULES([LIBFOO], [foo])
26+
dnl PHP_EVAL_INCLINE($LIBFOO_CFLAGS)
27+
dnl PHP_EVAL_LIBLINE($LIBFOO_LIBS, HELLOWORLD_SHARED_LIBADD)
28+
29+
dnl If you need to check for a particular library version using PKG_CHECK_MODULES,
30+
dnl you can use comparison operators. For example:
31+
dnl PKG_CHECK_MODULES([LIBFOO], [foo >= 1.2.3])
32+
dnl PKG_CHECK_MODULES([LIBFOO], [foo < 3.4])
33+
dnl PKG_CHECK_MODULES([LIBFOO], [foo = 1.2.3])
34+
35+
dnl Remove this code block if the library supports pkg-config.
36+
dnl --with-helloworld -> check with-path
37+
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
38+
dnl SEARCH_FOR="/include/helloworld.h" # you most likely want to change this
39+
dnl if test -r $PHP_HELLOWORLD/$SEARCH_FOR; then # path given as parameter
40+
dnl HELLOWORLD_DIR=$PHP_HELLOWORLD
41+
dnl else # search default path list
42+
dnl AC_MSG_CHECKING([for helloworld files in default path])
43+
dnl for i in $SEARCH_PATH ; do
44+
dnl if test -r $i/$SEARCH_FOR; then
45+
dnl HELLOWORLD_DIR=$i
46+
dnl AC_MSG_RESULT(found in $i)
47+
dnl fi
48+
dnl done
49+
dnl fi
50+
dnl
51+
dnl if test -z "$HELLOWORLD_DIR"; then
52+
dnl AC_MSG_RESULT([not found])
53+
dnl AC_MSG_ERROR([Please reinstall the helloworld distribution])
54+
dnl fi
55+
56+
dnl Remove this code block if the library supports pkg-config.
57+
dnl --with-helloworld -> add include path
58+
dnl PHP_ADD_INCLUDE($HELLOWORLD_DIR/include)
59+
60+
dnl Remove this code block if the library supports pkg-config.
61+
dnl --with-helloworld -> check for lib and symbol presence
62+
dnl LIBNAME=HELLOWORLD # you may want to change this
63+
dnl LIBSYMBOL=HELLOWORLD # you most likely want to change this
64+
65+
dnl If you need to check for a particular library function (e.g. a conditional
66+
dnl or version-dependent feature) and you are using pkg-config:
67+
dnl PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
68+
dnl [
69+
dnl AC_DEFINE(HAVE_HELLOWORLD_FEATURE, 1, [ ])
70+
dnl ],[
71+
dnl AC_MSG_ERROR([FEATURE not supported by your helloworld library.])
72+
dnl ], [
73+
dnl $LIBFOO_LIBS
74+
dnl ])
75+
76+
dnl If you need to check for a particular library function (e.g. a conditional
77+
dnl or version-dependent feature) and you are not using pkg-config:
78+
dnl PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
79+
dnl [
80+
dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $HELLOWORLD_DIR/$PHP_LIBDIR, HELLOWORLD_SHARED_LIBADD)
81+
dnl AC_DEFINE(HAVE_HELLOWORLD_FEATURE, 1, [ ])
82+
dnl ],[
83+
dnl AC_MSG_ERROR([FEATURE not supported by your helloworld library.])
84+
dnl ],[
85+
dnl -L$HELLOWORLD_DIR/$PHP_LIBDIR -lm
86+
dnl ])
87+
dnl
88+
dnl PHP_SUBST(HELLOWORLD_SHARED_LIBADD)
89+
90+
dnl In case of no dependencies
91+
AC_DEFINE(HAVE_HELLOWORLD, 1, [ Have helloworld support ])
92+
93+
PHP_NEW_EXTENSION(helloworld, helloworld.c, $ext_shared)
94+
fi

config.w32

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ARG_ENABLE('helloworld', 'helloworld support', 'no');
2+
3+
if (PHP_HELLOWORLD != 'no') {
4+
AC_DEFINE('HAVE_HELLOWORLD', 1, 'helloworld support enabled');
5+
6+
EXTENSION('helloworld', 'helloworld.c', null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
7+
}

helloworld.c

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/* helloworld extension for PHP */
2+
3+
#ifdef HAVE_CONFIG_H
4+
# include "config.h"
5+
#endif
6+
7+
#include "php.h"
8+
#include "ext/standard/info.h"
9+
#include "php_helloworld.h"
10+
#include "helloworld_arginfo.h"
11+
12+
/* For compatibility with older PHP versions */
13+
#ifndef ZEND_PARSE_PARAMETERS_NONE
14+
#define ZEND_PARSE_PARAMETERS_NONE() \
15+
ZEND_PARSE_PARAMETERS_START(0, 0) \
16+
ZEND_PARSE_PARAMETERS_END()
17+
#endif
18+
19+
PHP_FUNCTION(helloworld)
20+
{
21+
char *str = "World";
22+
size_t str_len = sizeof("World") - 1;
23+
// zend_string *result_val;
24+
25+
ZEND_PARSE_PARAMETERS_START(0, 1)
26+
Z_PARAM_OPTIONAL
27+
Z_PARAM_STRING(str, str_len)
28+
ZEND_PARSE_PARAMETERS_END();
29+
30+
// result_val = strpprintf(0, "Hello %s", str);
31+
32+
php_printf("Hello %s\n", str);
33+
34+
// RETURN_STR(retval);
35+
}
36+
37+
/* {{{ PHP_RINIT_FUNCTION */
38+
PHP_RINIT_FUNCTION(helloworld)
39+
{
40+
#if defined(ZTS) && defined(COMPILE_DL_HELLOWORLD)
41+
ZEND_TSRMLS_CACHE_UPDATE();
42+
#endif
43+
44+
return SUCCESS;
45+
}
46+
/* }}} */
47+
48+
/* {{{ PHP_MINFO_FUNCTION */
49+
PHP_MINFO_FUNCTION(helloworld)
50+
{
51+
php_info_print_table_start();
52+
php_info_print_table_header(2, "helloworld support", "enabled");
53+
php_info_print_table_end();
54+
}
55+
/* }}} */
56+
57+
/* {{{ helloworld_module_entry */
58+
zend_module_entry helloworld_module_entry = {
59+
STANDARD_MODULE_HEADER,
60+
"helloworld", /* Extension name */
61+
ext_functions, /* zend_function_entry */
62+
NULL, /* PHP_MINIT - Module initialization */
63+
NULL, /* PHP_MSHUTDOWN - Module shutdown */
64+
PHP_RINIT(helloworld), /* PHP_RINIT - Request initialization */
65+
NULL, /* PHP_RSHUTDOWN - Request shutdown */
66+
PHP_MINFO(helloworld), /* PHP_MINFO - Module info */
67+
PHP_HELLOWORLD_VERSION, /* Version */
68+
STANDARD_MODULE_PROPERTIES
69+
};
70+
/* }}} */
71+
72+
#ifdef COMPILE_DL_HELLOWORLD
73+
# ifdef ZTS
74+
ZEND_TSRMLS_CACHE_DEFINE()
75+
# endif
76+
ZEND_GET_MODULE(helloworld)
77+
#endif

helloworld.stub.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
/** @generate-function-entries */
4+
5+
function test1(): void {}
6+
7+
function test2(string $str = ""): string {}

helloworld_arginfo.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* This is a generated file, edit the .stub.php file instead.
2+
* Stub hash: 7eb3fd4083c98e6dffc8b02b6373b7ce9cbf228d */
3+
4+
// #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null)
5+
6+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_helloworld, 0, 0, IS_STRING, 0)
7+
ZEND_END_ARG_INFO()
8+
9+
ZEND_FUNCTION(helloworld);
10+
11+
static const zend_function_entry ext_functions[] = {
12+
ZEND_FE(helloworld, arginfo_helloworld)
13+
ZEND_FE_END
14+
};

php_helloworld.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* helloworld extension for PHP */
2+
3+
#ifndef PHP_HELLOWORLD_H
4+
# define PHP_HELLOWORLD_H
5+
6+
extern zend_module_entry helloworld_module_entry;
7+
# define phpext_helloworld_ptr &helloworld_module_entry
8+
9+
# define PHP_HELLOWORLD_VERSION "0.1.0"
10+
11+
# if defined(ZTS) && defined(COMPILE_DL_HELLOWORLD)
12+
ZEND_TSRMLS_CACHE_EXTERN()
13+
# endif
14+
15+
#endif /* PHP_HELLOWORLD_H */

tests/001.phpt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Check if helloworld is loaded
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('helloworld')) {
6+
echo 'skip';
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
echo 'The extension "helloworld" is available';
12+
?>
13+
--EXPECT--
14+
The extension "helloworld" is available

tests/002.phpt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
test1() Basic test
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('helloworld')) {
6+
echo 'skip';
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
$ret = test1();
12+
13+
var_dump($ret);
14+
?>
15+
--EXPECT--
16+
The extension helloworld is loaded and working!
17+
NULL

tests/003.diff

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
001+ Fatal error: Uncaught Error: Call to undefined function helloworld_test2() in /home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tests/003.php:2
2+
002+ Stack trace:
3+
001- string(11) "Hello World"
4+
002- string(9) "Hello PHP"
5+
003+ #0 {main}
6+
004+ thrown in /home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tests/003.php on line 2

tests/003.exp

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
string(11) "Hello World"
2+
string(9) "Hello PHP"

tests/003.log

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
---- EXPECTED OUTPUT
3+
string(11) "Hello World"
4+
string(9) "Hello PHP"
5+
---- ACTUAL OUTPUT
6+
Fatal error: Uncaught Error: Call to undefined function helloworld_test2() in /home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tests/003.php:2
7+
Stack trace:
8+
#0 {main}
9+
thrown in /home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tests/003.php on line 2
10+
---- FAILED

tests/003.out

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fatal error: Uncaught Error: Call to undefined function helloworld_test2() in /home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tests/003.php:2
2+
Stack trace:
3+
#0 {main}
4+
thrown in /home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tests/003.php on line 2

tests/003.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
var_dump(helloworld_test2());
3+
var_dump(helloworld_test2('PHP'));
4+
?>

tests/003.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
helloworld_test2() Basic test
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('helloworld')) {
6+
echo 'skip';
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
var_dump(helloworld_test2());
12+
var_dump(helloworld_test2('PHP'));
13+
?>
14+
--EXPECT--
15+
string(11) "Hello World"
16+
string(9) "Hello PHP"

tests/003.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
/usr/bin/php7.4 -n -c '/home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tmp-php.ini' -d "output_handler=" -d "open_basedir=" -d "disable_functions=" -d "output_buffering=Off" -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0" -d "html_errors=0" -d "track_errors=0" -d "report_memleaks=1" -d "report_zend_debug=0" -d "docref_root=" -d "docref_ext=.html" -d "error_prepend_string=" -d "error_append_string=" -d "auto_prepend_file=" -d "auto_append_file=" -d "ignore_repeated_errors=0" -d "precision=14" -d "memory_limit=128M" -d "log_errors_max_len=0" -d "opcache.fast_shutdown=0" -d "opcache.file_update_protection=0" -d "opcache.revalidate_freq=0" -d "zend.assertions=1" -d "zend.exception_ignore_args=0" -d "extension_dir=/home/nekoimi/developer/cpp-project/php-src/ext/helloworld/modules/" -d "extension=helloworld.so" -d "session.auto_start=0" -d "zlib.output_compression=Off" -f "/home/nekoimi/developer/cpp-project/php-src/ext/helloworld/tests/003.php" 2>&1

0 commit comments

Comments
 (0)