Skip to content

Commit

Permalink
Add method interception and improve error handling
Browse files Browse the repository at this point in the history
Added method interception capabilities including new interface and argument declarations for method interceptors. Also improved error handling by introducing detailed error messages and checking for memory allocation failures, ensuring robustness and easier debugging.
  • Loading branch information
koriym committed Nov 4, 2024
1 parent ac02039 commit 2cd229f
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 112 deletions.
43 changes: 6 additions & 37 deletions config.m4
Original file line number Diff line number Diff line change
@@ -1,57 +1,26 @@
dnl $Id$
dnl config.m4 for extension rayaop

dnl Include PECL configuration macro
dnl link https://github.com/php/pecl-tools/blob/master/autoconf/pecl.m4
sinclude(./autoconf/pecl.m4)
PHP_ARG_ENABLE(rayaop, whether to enable rayaop,
[ --enable-rayaop Enable rayaop])

dnl Include macro for detecting PHP executable
dnl link https://github.com/php/pecl-tools/blob/master/autoconf/php-executable.m4
sinclude(./autoconf/php-executable.m4)

dnl Initialize PECL extension
dnl link https://github.com/php/pecl-tools/blob/master/pecl.m4#L229
PECL_INIT([rayaop])

dnl Add configuration option to enable the extension
dnl link https://www.gnu.org/software/autoconf/manual/autoconf-2.68/html_node/External-Shell-Variables.html
PHP_ARG_ENABLE(rayaop, whether to enable rayaop, [ --enable-rayaop Enable rayaop])

dnl Process if the extension is enabled
if test "$PHP_RAYAOP" != "no"; then
dnl Define whether the extension is enabled
dnl link https://www.gnu.org/software/autoconf/manual/autoconf-2.68/html_node/Defining-Variables.html
AC_DEFINE(HAVE_RAYAOP, 1, [whether rayaop is enabled])

dnl Add new PHP extension
dnl link https://www.phpinternalsbook.com/build_system/build_system.html
PHP_NEW_EXTENSION(rayaop, rayaop.c, $ext_shared)

dnl Add Makefile fragment
dnl link https://www.phpinternalsbook.com/build_system/build_system.html#php-add-makefile-fragment
PHP_ADD_MAKEFILE_FRAGMENT

dnl Add instruction to install header files
dnl link https://www.phpinternalsbook.com/build_system/build_system.html#php-install-headers
PHP_INSTALL_HEADERS([ext/rayaop], [php_rayaop.h])

dnl Add quiet mode option
PHP_ARG_ENABLE(rayaop-quiet, whether to suppress experimental notices,
[ --enable-rayaop-quiet Suppress experimental notices], no, yes)
[ --enable-rayaop-quiet Suppress experimental notices], no, yes)

if test "$PHP_RAYAOP_QUIET" != "no"; then
AC_DEFINE(RAYAOP_QUIET, 1, [Whether to suppress experimental notices])
AC_DEFINE(RAYAOP_QUIET, 1, [Whether to suppress experimental notices])
fi

dnl Add AddressSanitizer flags
dnl Add the AddressSanitizer runtime library path
PHP_ADD_LIBRARY_WITH_PATH([clang_rt.asan_osx_dynamic], [/opt/homebrew/opt/llvm/lib/clang/14.0.0/lib/darwin], [RAYAOP_SHARED_LIBADD])
AC_DEFINE(HAVE_ASAN, 1, [Define if you have AddressSanitizer])

dnl Add compiler and linker flags
CFLAGS="-g -O0 -fsanitize=address $CFLAGS"
LDFLAGS="-fsanitize=address $LDFLAGS"

dnl Add include and library paths
PHP_ADD_INCLUDE([/opt/homebrew/opt/llvm/include])
PHP_ADD_LIBPATH([/opt/homebrew/opt/llvm/lib])
fi
fi
20 changes: 19 additions & 1 deletion php_rayaop.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
#include "TSRM.h"
#endif

/* Version and namespace definitions */
/* Constants */
#define MAX_EXECUTION_DEPTH 100
#define PHP_RAYAOP_VERSION "1.0.0"
#define RAYAOP_NS "Ray\\Aop\\"

Expand All @@ -35,6 +36,20 @@
#define RAYAOP_E_INVALID_HANDLER 3
#define RAYAOP_E_MAX_DEPTH_EXCEEDED 4

/* Argument information declarations */
ZEND_BEGIN_ARG_INFO_EX(arginfo_method_intercept, 0, 0, 3)
ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, method_name, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, interceptor, Ray\\Aop\\MethodInterceptorInterface, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_method_intercept_init, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_enable_method_intercept, 0, 1, IS_VOID, 0)
ZEND_ARG_TYPE_INFO(0, enable, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

/* Debug mode configuration */
#ifdef RAYAOP_DEBUG
#define PHP_RAYAOP_DEBUG_PRINT(fmt, ...) \
Expand All @@ -58,6 +73,9 @@
extern zend_module_entry rayaop_module_entry;
#define phpext_rayaop_ptr &rayaop_module_entry

/* Interface class entry */
extern zend_class_entry *ray_aop_method_interceptor_interface_ce;

/* Windows DLL export */
#ifdef PHP_WIN32
#define PHP_RAYAOP_API __declspec(dllexport)
Expand Down
Loading

0 comments on commit 2cd229f

Please sign in to comment.