Skip to content

Commit 89ad748

Browse files
committed
Add: init repo
0 parents  commit 89ad748

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+5844
-0
lines changed

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.deps
2+
*.lo
3+
*.la
4+
.libs
5+
acinclude.m4
6+
aclocal.m4
7+
autom4te.cache
8+
build
9+
configure.ac
10+
config.guess
11+
config.h
12+
config.h.in
13+
config.log
14+
config.nice
15+
config.status
16+
config.sub
17+
configure
18+
configure.in
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
36+
.vscode

CREDITS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
study

EXPERIMENTAL

Whitespace-only changes.

config.m4

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
PHP_ARG_ENABLE(study, whether to enable study support,
2+
Make sure that the comment is aligned:
3+
[ --enable-study Enable study support])
4+
5+
# AC_CANONICAL_HOST
6+
7+
if test "$PHP_STUDY" != "no"; then
8+
PHP_ADD_LIBRARY(pthread)
9+
STUDY_ASM_DIR="thirdparty/boost/asm/"
10+
CFLAGS="-Wall -pthread $CFLAGS"
11+
12+
AS_CASE([$host_os],
13+
[linux*], [STUDY_OS="LINUX"],
14+
[]
15+
)
16+
17+
AS_CASE([$host_cpu],
18+
[x86_64*], [STUDY_CPU="x86_64"],
19+
[x86*], [STUDY_CPU="x86"],
20+
[i?86*], [STUDY_CPU="x86"],
21+
[arm*], [STUDY_CPU="arm"],
22+
[aarch64*], [STUDY_CPU="arm64"],
23+
[arm64*], [STUDY_CPU="arm64"],
24+
[]
25+
)
26+
27+
if test "$STUDY_CPU" = "x86_64"; then
28+
if test "$STUDY_OS" = "LINUX"; then
29+
STUDY_CONTEXT_ASM_FILE="x86_64_sysv_elf_gas.S"
30+
fi
31+
elif test "$STUDY_CPU" = "x86"; then
32+
if test "$STUDY_OS" = "LINUX"; then
33+
STUDY_CONTEXT_ASM_FILE="i386_sysv_elf_gas.S"
34+
fi
35+
elif test "$STUDY_CPU" = "arm"; then
36+
if test "$STUDY_OS" = "LINUX"; then
37+
STUDY_CONTEXT_ASM_FILE="arm_aapcs_elf_gas.S"
38+
fi
39+
elif test "$STUDY_CPU" = "arm64"; then
40+
if test "$STUDY_OS" = "LINUX"; then
41+
STUDY_CONTEXT_ASM_FILE="arm64_aapcs_elf_gas.S"
42+
fi
43+
elif test "$STUDY_CPU" = "mips32"; then
44+
if test "$STUDY_OS" = "LINUX"; then
45+
STUDY_CONTEXT_ASM_FILE="mips32_o32_elf_gas.S"
46+
fi
47+
fi
48+
49+
study_source_file="\
50+
study.c \
51+
${STUDY_ASM_DIR}make_${STUDY_CONTEXT_ASM_FILE} \
52+
${STUDY_ASM_DIR}jump_${STUDY_CONTEXT_ASM_FILE}
53+
"
54+
55+
PHP_NEW_EXTENSION(study, $study_source_file, $ext_shared, ,, cxx)
56+
57+
PHP_ADD_INCLUDE([$ext_srcdir])
58+
PHP_ADD_INCLUDE([$ext_srcdir/include])
59+
60+
PHP_INSTALL_HEADERS([ext/study], [*.h config.h include/*.h thirdparty/*.h])
61+
62+
PHP_REQUIRE_CXX()
63+
64+
CXXFLAGS="$CXXFLAGS -Wall -Wno-unused-function -Wno-deprecated -Wno-deprecated-declarations"
65+
CXXFLAGS="$CXXFLAGS -std=c++11"
66+
67+
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/boost)
68+
PHP_ADD_BUILD_DIR($ext_builddir/thirdparty/boost/asm)
69+
fi

include/.gitkeep

Whitespace-only changes.

make.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
phpize --clean
2+
phpize
3+
./configure
4+
make
5+
make install

php_study.h

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 7 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2016 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+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
/* $Id$ */
20+
21+
#ifndef PHP_STUDY_H
22+
#define PHP_STUDY_H
23+
24+
extern zend_module_entry study_module_entry;
25+
#define phpext_study_ptr &study_module_entry
26+
27+
#define PHP_STUDY_VERSION "0.1.0" /* Replace with version number for your extension */
28+
29+
#ifdef PHP_WIN32
30+
# define PHP_STUDY_API __declspec(dllexport)
31+
#elif defined(__GNUC__) && __GNUC__ >= 4
32+
# define PHP_STUDY_API __attribute__ ((visibility("default")))
33+
#else
34+
# define PHP_STUDY_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(study)
46+
zend_long global_value;
47+
char *global_string;
48+
ZEND_END_MODULE_GLOBALS(study)
49+
*/
50+
51+
/* Always refer to the globals in your function as STUDY_G(variable).
52+
You are encouraged to rename these macros something shorter, see
53+
examples in any other php module directory.
54+
*/
55+
#define STUDY_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(study, v)
56+
57+
#if defined(ZTS) && defined(COMPILE_DL_STUDY)
58+
ZEND_TSRMLS_CACHE_EXTERN()
59+
#endif
60+
61+
#endif /* PHP_STUDY_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+
*/

study.c

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| PHP Version 7 |
4+
+----------------------------------------------------------------------+
5+
| Copyright (c) 1997-2016 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+
| [email protected] so we can mail you a copy immediately. |
14+
+----------------------------------------------------------------------+
15+
| Author: |
16+
+----------------------------------------------------------------------+
17+
*/
18+
19+
#ifdef HAVE_CONFIG_H
20+
#include "config.h"
21+
#endif
22+
23+
#include "php.h"
24+
#include "php_ini.h"
25+
#include "ext/standard/info.h"
26+
#include "php_study.h"
27+
#include <pthread.h>
28+
29+
static void (*orig_interrupt_function)(zend_execute_data *execute_data);
30+
31+
void schedule();
32+
static void create_scheduler_thread();
33+
static void new_interrupt_function(zend_execute_data *execute_data);
34+
35+
void init()
36+
{
37+
orig_interrupt_function = zend_interrupt_function;
38+
zend_interrupt_function = new_interrupt_function;
39+
}
40+
41+
static void new_interrupt_function(zend_execute_data *execute_data)
42+
{
43+
php_printf("yeild coroutine\n");
44+
if (orig_interrupt_function)
45+
{
46+
orig_interrupt_function(execute_data);
47+
}
48+
}
49+
50+
void schedule()
51+
{
52+
while (1)
53+
{
54+
EG(vm_interrupt) = 1;
55+
usleep(5000);
56+
}
57+
}
58+
59+
static void create_scheduler_thread()
60+
{
61+
pthread_t pidt;
62+
63+
if (pthread_create(&pidt, NULL, (void * (*)(void *)) schedule, NULL) < 0)
64+
{
65+
php_printf("pthread_create[PHPCoroutine Scheduler] failed");
66+
}
67+
}
68+
69+
PHP_FUNCTION(start_interrupt) {
70+
init();
71+
create_scheduler_thread();
72+
};
73+
74+
PHP_FUNCTION(test) {
75+
zend_string *str;
76+
77+
str = zend_string_init("foo", strlen("foo"), 0);
78+
php_printf("This is my string: %s\n", ZSTR_VAL(str));
79+
php_printf("It is %zd char long\n", ZSTR_LEN(str));
80+
81+
zend_string_release(str);
82+
};
83+
84+
PHP_MINIT_FUNCTION(study)
85+
{
86+
return SUCCESS;
87+
}
88+
89+
PHP_MSHUTDOWN_FUNCTION(study)
90+
{
91+
return SUCCESS;
92+
}
93+
94+
PHP_RINIT_FUNCTION(study)
95+
{
96+
#if defined(COMPILE_DL_STUDY) && defined(ZTS)
97+
ZEND_TSRMLS_CACHE_UPDATE();
98+
#endif
99+
return SUCCESS;
100+
}
101+
102+
PHP_RSHUTDOWN_FUNCTION(study)
103+
{
104+
return SUCCESS;
105+
}
106+
107+
PHP_MINFO_FUNCTION(study)
108+
{
109+
php_info_print_table_start();
110+
php_info_print_table_header(2, "study support", "enabled");
111+
php_info_print_table_end();
112+
}
113+
114+
const zend_function_entry study_functions[] = {
115+
PHP_FE(start_interrupt, NULL)
116+
PHP_FE(test, NULL)
117+
PHP_FE_END
118+
};
119+
120+
zend_module_entry study_module_entry = {
121+
STANDARD_MODULE_HEADER,
122+
"study",
123+
study_functions,
124+
PHP_MINIT(study),
125+
PHP_MSHUTDOWN(study),
126+
PHP_RINIT(study),
127+
PHP_RSHUTDOWN(study),
128+
PHP_MINFO(study),
129+
PHP_STUDY_VERSION,
130+
STANDARD_MODULE_PROPERTIES
131+
};
132+
133+
#ifdef COMPILE_DL_STUDY
134+
#ifdef ZTS
135+
ZEND_TSRMLS_CACHE_DEFINE()
136+
#endif
137+
ZEND_GET_MODULE(study)
138+
#endif

study.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
$br = (php_sapi_name() == "cli")? "":"<br>";
3+
4+
if(!extension_loaded('study')) {
5+
dl('study.' . PHP_SHLIB_SUFFIX);
6+
}
7+
$module = 'study';
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+
?>

tests/001.phpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Check for study presence
3+
--SKIPIF--
4+
<?php if (!extension_loaded("study")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
echo "study extension is available";
8+
/*
9+
you can add regression tests for your extension here
10+
11+
the output of your test code has to be equal to the
12+
text in the --EXPECT-- section below for the tests
13+
to pass, differences between the output and the
14+
expected text are interpreted as failure
15+
16+
see php7/README.TESTING for further information on
17+
writing regression tests
18+
*/
19+
?>
20+
--EXPECT--
21+
study extension is available

0 commit comments

Comments
 (0)