Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C extension #97

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5f3af36
ext jsonmachine init implementation
halaxa May 6, 2023
f88836f
Build fix
halaxa May 7, 2023
45c64f9
Build now includes extension build
halaxa May 7, 2023
a42b80a
Fixed the 'input device is not a TTY' by removing '-it' from the dock…
halaxa May 7, 2023
3009536
Added forgotten test file
halaxa May 7, 2023
559fd73
docker run for ext-build unified with the rest of the system
halaxa May 7, 2023
f4d875f
Skip 'make install' on compiled extension to avoid access problems
halaxa May 7, 2023
c1a41a6
Added git to php images for edge cases when composer needs it.
halaxa May 7, 2023
275863f
Ext build tweaks
halaxa May 10, 2023
1eceb61
size_t i for array iteration
halaxa May 10, 2023
96db016
Fixed env expansion
halaxa May 10, 2023
42940ca
Added *.loT to .gitignore
halaxa May 10, 2023
9953ab5
Fixed variable expansion
halaxa May 13, 2023
011bebc
Removed functions from original skeleton
halaxa May 13, 2023
734f883
Added C Iterator skeleton to move ExtTokens.php implementation comple…
halaxa May 13, 2023
dae6da9
ExtTokens stub correctly iterates over a inner iterator
halaxa May 14, 2023
3a35cb6
Class ExtTokens implemented in C
halaxa May 14, 2023
2e14840
make cs-fix
halaxa Jun 3, 2023
3185ba7
Scalar zvals replaced with native C types
halaxa Jun 3, 2023
96edf7b
inlined jsonmachine_next_token + removed its PHP mirror
halaxa Jun 8, 2023
f2caa61
chunk length memoization
halaxa Jun 9, 2023
48f8525
Removed temporary do-while
halaxa Jun 9, 2023
e464523
C class ExtTokens throws PHP's JsonMachineException
halaxa Aug 14, 2023
c957e58
Commited a forgotten line
halaxa Aug 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ phpunit.xml
clover.xml
src/AutoloadStub.php
.env
*~
*.log

# ext compiling
*.gch
*.lo
*.o
*.so
libtool
compiled-files-sum
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ help:
@grep -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-15s\033[0m\t%s\n", $$1, $$2}'


build: tests-all cs-check ## Run all necessary stuff before commit.
build: ext-build tests-all cs-check ## Run all necessary stuff before commit.


tests: CMD=composer tests -- $(ARGS)
Expand Down Expand Up @@ -107,3 +107,15 @@ release: .env build

docker-run: ## Run a command in a latest JSON Machine PHP docker container. Ex.: make docker-run CMD="php -v"
@$(call DOCKER_RUN,$(LATEST_PHP),$(CMD))

EXT_BUILD_POST_CMD=composer performance-tests
ext-build: ## Build JSON Machine's PHP extension for production and run performance tests
docker build --tag json-machine-ext --build-arg debug=$(DEBUG) ext/build
./build/docker-run.sh \
"json-machine-ext" \
"$$PWD" \
"cd /project/ext/jsonmachine; phpize && ./configure $(DEBUG) && make clean && make && cd /project && composer tests -- --colors=always --stop-on-failure --filter \\\\JsonMachineTest\\\\ExtTokensTest && composer performance-tests"
#"cd /project/ext/jsonmachine; phpize && ./configure $(DEBUG) && make clean && make && cd /project && valgrind php /project/jnt.php"

ext-build-debug: DEBUG=--enable-debug
ext-build-debug: ext-build ## Build JSON Machine's PHP extension for development and run tests
1 change: 1 addition & 0 deletions build/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ printf "
make \
bash \
linux-headers \
git \
&& wget http://pear.php.net/go-pear.phar && php go-pear.phar \
&& pecl install xdebug-$XDEBUG_VERSION \
&& docker-php-ext-enable xdebug \
Expand Down
6 changes: 3 additions & 3 deletions build/docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ shift
PROJECT_DIR=$1
shift

docker run --rm \
docker run $DOCKER_RUN_OPTS --rm \
--name "$CONTAINER_NAME" \
--volume "$PROJECT_DIR:/usr/src/json-machine" \
--volume "$PROJECT_DIR:/project" \
--volume "/tmp:/tmp" \
--workdir "/usr/src/json-machine" \
--workdir "/project" \
--user "$(id -u):$(id -g)" \
--env COMPOSER_CACHE_DIR=/tmp \
"$CONTAINER_NAME" \
Expand Down
47 changes: 47 additions & 0 deletions ext/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Use phusion/baseimage as base image. To make your builds reproducible, make
# sure you lock down to a specific version, not to `latest`!
# See https://github.com/phusion/baseimage-docker/blob/master/Changelog.md for
# a list of version numbers.
FROM phusion/baseimage:focal-1.0.0

# Use baseimage-docker's init system.
CMD ["/sbin/my_init"]

# ...put your own build instructions here...
RUN apt update && apt-get install -y \
build-essential \
autoconf \
automake \
bison \
flex \
re2c \
gdb \
libtool \
make \
pkgconf \
valgrind \
git \
libxml2-dev \
libsqlite3-dev \
wget \
libssl-dev \
;

# Clean up APT when done.
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

WORKDIR /usr/src
RUN git clone https://github.com/php/php-src.git

ARG debug
RUN cd php-src \
&& git checkout php-8.0.9 \
&& ./buildconf --force \
&& ./configure $debug --enable-mbstring --disable-mbregex --with-openssl \
&& make -j`nproc` \
&& make install
RUN rm -rf php-src
COPY php.ini /usr/local/lib/php.ini

RUN wget https://getcomposer.org/download/2.2.18/composer.phar -O /usr/local/bin/composer \
&& chmod +x /usr/local/bin/composer
14 changes: 14 additions & 0 deletions ext/build/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
date.timezone=GMT
max_execution_time=30
memory_limit=128M

error_reporting=E_ALL | E_STRICT ; catch all error and warnings
display_errors=1
log_errors=1

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.protect_memory=1 ; catch invalid updates of shared memory

extension=/project/ext/jsonmachine/modules/jsonmachine.so
37 changes: 37 additions & 0 deletions ext/jsonmachine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*.lo
*.la
*.dep
*.loT
.libs
acinclude.m4
aclocal.m4
autom4te.cache
build
config.guess
config.h
config.h.in
config.log
config.nice
config.status
config.sub
configure
configure.ac
configure.in
include
install-sh
libtool
ltmain.sh
Makefile
Makefile.fragments
Makefile.global
Makefile.objects
missing
mkinstalldirs
modules
run-tests.php
tests/**/*.diff
tests/**/*.out
tests/**/*.php
tests/**/*.exp
tests/**/*.log
tests/**/*.sh
94 changes: 94 additions & 0 deletions ext/jsonmachine/config.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
dnl config.m4 for extension jsonmachine

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary.

dnl If your extension references something external, use 'with':

dnl PHP_ARG_WITH([jsonmachine],
dnl [for jsonmachine support],
dnl [AS_HELP_STRING([--with-jsonmachine],
dnl [Include jsonmachine support])])

dnl Otherwise use 'enable':

PHP_ARG_ENABLE([jsonmachine],
[whether to enable jsonmachine support],
[AS_HELP_STRING([--enable-jsonmachine],
[Enable jsonmachine support])],
[no])

if test "$PHP_JSONMACHINE" != "no"; then
dnl Write more examples of tests here...

dnl Remove this code block if the library does not support pkg-config.
dnl PKG_CHECK_MODULES([LIBFOO], [foo])
dnl PHP_EVAL_INCLINE($LIBFOO_CFLAGS)
dnl PHP_EVAL_LIBLINE($LIBFOO_LIBS, JSONMACHINE_SHARED_LIBADD)

dnl If you need to check for a particular library version using PKG_CHECK_MODULES,
dnl you can use comparison operators. For example:
dnl PKG_CHECK_MODULES([LIBFOO], [foo >= 1.2.3])
dnl PKG_CHECK_MODULES([LIBFOO], [foo < 3.4])
dnl PKG_CHECK_MODULES([LIBFOO], [foo = 1.2.3])

dnl Remove this code block if the library supports pkg-config.
dnl --with-jsonmachine -> check with-path
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
dnl SEARCH_FOR="/include/jsonmachine.h" # you most likely want to change this
dnl if test -r $PHP_JSONMACHINE/$SEARCH_FOR; then # path given as parameter
dnl JSONMACHINE_DIR=$PHP_JSONMACHINE
dnl else # search default path list
dnl AC_MSG_CHECKING([for jsonmachine files in default path])
dnl for i in $SEARCH_PATH ; do
dnl if test -r $i/$SEARCH_FOR; then
dnl JSONMACHINE_DIR=$i
dnl AC_MSG_RESULT(found in $i)
dnl fi
dnl done
dnl fi
dnl
dnl if test -z "$JSONMACHINE_DIR"; then
dnl AC_MSG_RESULT([not found])
dnl AC_MSG_ERROR([Please reinstall the jsonmachine distribution])
dnl fi

dnl Remove this code block if the library supports pkg-config.
dnl --with-jsonmachine -> add include path
dnl PHP_ADD_INCLUDE($JSONMACHINE_DIR/include)

dnl Remove this code block if the library supports pkg-config.
dnl --with-jsonmachine -> check for lib and symbol presence
dnl LIBNAME=JSONMACHINE # you may want to change this
dnl LIBSYMBOL=JSONMACHINE # you most likely want to change this

dnl If you need to check for a particular library function (e.g. a conditional
dnl or version-dependent feature) and you are using pkg-config:
dnl PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
dnl [
dnl AC_DEFINE(HAVE_JSONMACHINE_FEATURE, 1, [ ])
dnl ],[
dnl AC_MSG_ERROR([FEATURE not supported by your jsonmachine library.])
dnl ], [
dnl $LIBFOO_LIBS
dnl ])

dnl If you need to check for a particular library function (e.g. a conditional
dnl or version-dependent feature) and you are not using pkg-config:
dnl PHP_CHECK_LIBRARY($LIBNAME, $LIBSYMBOL,
dnl [
dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $JSONMACHINE_DIR/$PHP_LIBDIR, JSONMACHINE_SHARED_LIBADD)
dnl AC_DEFINE(HAVE_JSONMACHINE_FEATURE, 1, [ ])
dnl ],[
dnl AC_MSG_ERROR([FEATURE not supported by your jsonmachine library.])
dnl ],[
dnl -L$JSONMACHINE_DIR/$PHP_LIBDIR -lm
dnl ])
dnl
dnl PHP_SUBST(JSONMACHINE_SHARED_LIBADD)

dnl In case of no dependencies
AC_DEFINE(HAVE_JSONMACHINE, 1, [ Have jsonmachine support ])

PHP_NEW_EXTENSION(jsonmachine, jsonmachine.c, $ext_shared)
fi
7 changes: 7 additions & 0 deletions ext/jsonmachine/config.w32
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ARG_ENABLE('jsonmachine', 'jsonmachine support', 'no');

if (PHP_JSONMACHINE != 'no') {
AC_DEFINE('HAVE_JSONMACHINE', 1, 'jsonmachine support enabled');

EXTENSION('jsonmachine', 'jsonmachine.c', null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1');
}
Loading