Skip to content

Commit ba256d4

Browse files
authored
Merge pull request #314 from stesie/issue-313
Fix build against recent V8 6.0 versions
2 parents f87cf9f + 4baf9e9 commit ba256d4

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

Vagrantfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Vagrant.configure("2") do |config|
3737
end
3838
}
3939

40-
%w{5.9.35}.each { |version|
40+
%w{5.9.35 6.0.318}.each { |version|
4141
config.vm.define "v8-#{version}" do |i|
4242
i.vm.synced_folder ".", "/data/v8js"
4343

@@ -75,7 +75,7 @@ Vagrant.configure("2") do |config|
7575
7676
# Install to /opt/libv8-#{version}/
7777
sudo mkdir -p /opt/libv8-#{version}/{lib,include}
78-
sudo cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin /opt/libv8-#{version}/lib/
78+
sudo cp out.gn/x64.release/lib*.so out.gn/x64.release/*_blob.bin out.gn/x64.release/icudtl.dat /opt/libv8-#{version}/lib/
7979
sudo cp -R include/* /opt/libv8-#{version}/include/
8080
SHELL
8181
end

config.m4

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,22 @@ if test "$PHP_V8JS" != "no"; then
9292
AC_MSG_CHECKING([for libv8_libplatform])
9393
AC_DEFUN([V8_CHECK_LINK], [
9494
save_LIBS="$LIBS"
95-
LIBS="$LIBS $1 -lv8_libplatform -lv8"
96-
AC_LINK_IFELSE([AC_LANG_PROGRAM([
97-
namespace v8 {
98-
namespace platform {
99-
enum class IdleTaskSupport { kDisabled, kEnabled };
100-
void* CreateDefaultPlatform($2);
101-
}
102-
}
103-
], [ v8::platform::CreateDefaultPlatform(); ])], [
104-
dnl libv8_libplatform.so found
105-
AC_MSG_RESULT(found)
106-
V8JS_SHARED_LIBADD="$1 -lv8_libplatform $V8JS_SHARED_LIBADD"
107-
$3
108-
], [ $4 ])
95+
LIBS="$LIBS $1 -lv8_libplatform -lv8"
96+
AC_LINK_IFELSE([AC_LANG_PROGRAM([
97+
#include <libplatform/libplatform.h>
98+
], [ v8::platform::CreateDefaultPlatform(); ])], [
99+
dnl libv8_libplatform.so found
100+
AC_MSG_RESULT(found)
101+
V8JS_SHARED_LIBADD="$1 -lv8_libplatform $V8JS_SHARED_LIBADD"
102+
$3
103+
], [ $4 ])
109104
LIBS="$save_LIBS"
110105
])
111106

112-
V8_CHECK_LINK([], [int thread_pool_size = 0, IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled], [], [
113-
V8_CHECK_LINK([], [int thread_pool_size = 0], [], [
114-
V8_CHECK_LINK([-lv8_libbase], [int thread_pool_size = 0, IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled], [], [
115-
V8_CHECK_LINK([-lv8_libbase], [int thread_pool_size = 0], [], [
116-
AC_MSG_ERROR([could not find libv8_libplatform library])
117-
])
118-
])
119-
])
107+
V8_CHECK_LINK([], [], [], [
108+
V8_CHECK_LINK([-lv8_libbase], [], [], [
109+
AC_MSG_ERROR([could not find libv8_libplatform library])
110+
])
120111
])
121112

122113

@@ -183,6 +174,23 @@ int main ()
183174
V8_SEARCH_BLOB([snapshot_blob.bin], [PHP_V8_SNAPSHOT_BLOB_PATH])
184175

185176

177+
dnl
178+
dnl Check for v8::ArrayBuffer::Allocator::NewDefaultAllocator
179+
dnl
180+
AC_CACHE_CHECK([for v8::ArrayBuffer::Allocator::NewDefaultAllocator], ac_cv_has_default_allocator, [
181+
AC_LINK_IFELSE([AC_LANG_PROGRAM([
182+
#include <v8.h>
183+
], [ v8::ArrayBuffer::Allocator::NewDefaultAllocator(); ])], [
184+
ac_cv_has_default_allocator=yes
185+
], [
186+
ac_cv_has_default_allocator=no
187+
])
188+
])
189+
if test "x$ac_cv_has_default_allocator" = "xno"; then
190+
AC_DEFINE([USE_INTERNAL_ALLOCATOR], [1],
191+
[Define unless v8::ArrayBuffer::Allocator::NewDefaultAllocator is usable.])
192+
fi
193+
186194
AC_LANG_RESTORE
187195
LIBS=$old_LIBS
188196
LDFLAGS="$old_LDFLAGS"

v8js_class.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct v8js_jsext {
7171
};
7272
/* }}} */
7373

74+
#ifdef USE_INTERNAL_ALLOCATOR
7475
class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
7576
public:
7677
virtual void* Allocate(size_t length) {
@@ -80,6 +81,7 @@ class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
8081
virtual void* AllocateUninitialized(size_t length) { return malloc(length); }
8182
virtual void Free(void* data, size_t) { free(data); }
8283
};
84+
#endif /** USE_INTERNAL_ALLOCATOR */
8385

8486

8587
static void v8js_free_storage(zend_object *object) /* {{{ */
@@ -201,6 +203,10 @@ static void v8js_free_storage(zend_object *object) /* {{{ */
201203
c->modules_base.~vector();
202204

203205
zval_ptr_dtor(&c->zval_snapshot_blob);
206+
207+
#ifndef USE_INTERNAL_ALLOCATOR
208+
delete c->create_params.array_buffer_allocator;
209+
#endif
204210
}
205211
/* }}} */
206212

@@ -353,8 +359,12 @@ static PHP_METHOD(V8Js, __construct)
353359

354360
new (&c->create_params) v8::Isolate::CreateParams();
355361

362+
#ifdef USE_INTERNAL_ALLOCATOR
356363
static ArrayBufferAllocator array_buffer_allocator;
357364
c->create_params.array_buffer_allocator = &array_buffer_allocator;
365+
#else
366+
c->create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
367+
#endif
358368

359369
new (&c->snapshot_blob) v8::StartupData();
360370
if (snapshot_blob) {

0 commit comments

Comments
 (0)