Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Aug 21, 2024
1 parent 828b14d commit 8fb867d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
15 changes: 11 additions & 4 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ dnl config.m4 for extension phpy
PHP_ARG_WITH([python_dir],
[dir of python],
[AS_HELP_STRING([[--with-python-dir[=DIR]]],
[Specify python installation dir, default is /usr])], [no], [no])
[Specify python installation dir])], [no], [no])

PHP_ARG_WITH([python_version],
[version of python],
[AS_HELP_STRING([[--with-python-version[=VERSION]]],
[Specify version of python, or use default (ex: 3.12)])], [no], [no])
[Specify version of python])], [no], [no])

PHP_ARG_WITH([python_config],
[path of python_config],
[AS_HELP_STRING([[--with-python-config[=PATH]]],
[Specify path of python_config])], [no], [no])
[Specify path of python_config, the default is python3-config])], [no], [no])

PHP_ARG_ENABLE([phpy],
[whether to enable phpy support],
Expand Down Expand Up @@ -43,12 +43,19 @@ AC_DEFUN([GET_PYTHON_INCLUDES], [
fi
])

AC_DEFUN([GET_PYTHON_VERSION_WITH_PYTHON_DIR], [
PHP_PYTHON_VERSION=$("${PHP_PYTHON_DIR}/bin/python3" -c "import sys; print('%d.%d'%(sys.version_info.major, sys.version_info.minor))")
if test $? -ne 0; then
AC_MSG_ERROR([failed to execute `python3`])
fi
])

if test "$PHP_PHPY" != "no"; then
if test "$PHP_PYTHON_CONFIG" != "no"; then
GET_PYTHON_INCLUDES()
GET_PYTHON_LDFLAGS()
elif test "$PHP_PYTHON_DIR" != "no"; then
PHP_PYTHON_VERSION=$("${PHP_PYTHON_DIR}/bin/python" -c "import sys; print('%d.%d'%(sys.version_info.major, sys.version_info.minor))")
GET_PYTHON_VERSION_WITH_PYTHON_DIR()
AC_MSG_RESULT([Python DIR: ${PHP_PYTHON_DIR}])
AC_MSG_RESULT([Python Version: ${PHP_PYTHON_VERSION}])
PHP_ADD_INCLUDE("${PHP_PYTHON_DIR}/include/python${PHP_PYTHON_VERSION}")
Expand Down
12 changes: 6 additions & 6 deletions phpy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "php.h"
#include "ext/standard/info.h"
#include "php_phpy.h"
#include <patchlevel.h>

/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(phpy)
Expand All @@ -23,18 +22,19 @@ PHP_RINIT_FUNCTION(phpy)
extern PHP_MINIT_FUNCTION(phpy);
extern PHP_MSHUTDOWN_FUNCTION(phpy);
extern PHP_RSHUTDOWN_FUNCTION(phpy);
extern const char *phpy_get_python_version(void);

/* {{{ PHP_MINFO_FUNCTION */
PHP_MINFO_FUNCTION(phpy)
{
php_info_print_table_start();
php_info_print_table_header(2, "phpy support", "enabled");
php_info_print_table_row(2, "Copyright", "上海识沃网络科技有限公司");
php_info_print_table_start();
php_info_print_table_header(2, "phpy support", "enabled");
php_info_print_table_row(2, "Copyright", "上海识沃网络科技有限公司");
php_info_print_table_row(2, "Email", "[email protected]");
php_info_print_table_row(2, "Website", "https://www.swoole.com/");
php_info_print_table_row(2, "Extension Version", PHP_PHPY_VERSION);
php_info_print_table_row(2, "Python Version", PY_VERSION);
php_info_print_table_end();
php_info_print_table_row(2, "Python Version", phpy_get_python_version());
php_info_print_table_end();
}
/* }}} */

Expand Down
6 changes: 6 additions & 0 deletions src/php/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ PHP_RSHUTDOWN_FUNCTION(phpy) {
return SUCCESS;
}

BEGIN_EXTERN_C()
const char *phpy_get_python_version(void) {
return Py_GetVersion();
}
END_EXTERN_C()

ZEND_METHOD(PyCore, __callStatic) {
char *name;
size_t l_name;
Expand Down

0 comments on commit 8fb867d

Please sign in to comment.