Skip to content

Commit 5d7445e

Browse files
authored
Merge pull request #47 from true-async/46-problems-when-trying-to-compile-the-extension-in-shared-mode
46 problems when trying to compile the extension in shared mode
2 parents 8719108 + c7df904 commit 5d7445e

File tree

10 files changed

+80
-75
lines changed

10 files changed

+80
-75
lines changed

async.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
#include "async_API.h"
3030
#include "async_arginfo.h"
3131
#include "zend_interfaces.h"
32-
#ifdef PHP_ASYNC_LIBUV
3332
#include "libuv_reactor.h"
34-
#endif
3533

3634
zend_class_entry *async_ce_awaitable = NULL;
3735
zend_class_entry *async_ce_timeout = NULL;
@@ -889,8 +887,6 @@ static PHP_GINIT_FUNCTION(async)
889887
#endif
890888

891889
async_globals->reactor_started = false;
892-
893-
#ifdef PHP_ASYNC_LIBUV
894890
async_globals->signal_handlers = NULL;
895891
async_globals->signal_events = NULL;
896892
async_globals->process_events = NULL;
@@ -906,7 +902,6 @@ static PHP_GINIT_FUNCTION(async)
906902
async_globals->uvloop_wakeup = NULL;
907903
async_globals->pid_queue = NULL;
908904
#endif
909-
#endif
910905
}
911906

912907
/* {{{ PHP_GSHUTDOWN_FUNCTION */
@@ -932,23 +927,16 @@ ZEND_MINIT_FUNCTION(async)
932927
// async_register_future_ce();
933928

934929
async_scheduler_startup();
935-
936930
async_api_register();
937-
938-
#ifdef PHP_ASYNC_LIBUV
939931
async_libuv_reactor_register();
940-
#endif
941932

942933
return SUCCESS;
943934
}
944935

945936
ZEND_MSHUTDOWN_FUNCTION(async)
946937
{
947938
// async_scheduler_shutdown();
948-
949-
#ifdef PHP_ASYNC_LIBUV
950939
// async_libuv_shutdown();
951-
#endif
952940

953941
return SUCCESS;
954942
}
@@ -959,11 +947,7 @@ PHP_MINFO_FUNCTION(async)
959947
php_info_print_table_header(2, "Module", PHP_ASYNC_NAME);
960948
php_info_print_table_row(2, "Version", PHP_ASYNC_VERSION);
961949
php_info_print_table_row(2, "Support", "Enabled");
962-
#ifdef PHP_ASYNC_LIBUV
963950
php_info_print_table_row(2, "LibUv Reactor", "Enabled");
964-
#else
965-
php_info_print_table_row(2, "LibUv Reactor", "Disabled");
966-
#endif
967951
php_info_print_table_end();
968952
}
969953

config.m4

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if test "$PHP_ASYNC" = "yes"; then
1111
dnl Register extension source files.
1212
PHP_NEW_EXTENSION([async],
1313
[async.c coroutine.c scope.c scheduler.c exceptions.c iterator.c async_API.c \
14-
context.c \
14+
context.c libuv_reactor.c \
1515
internal/allocator.c internal/circular_buffer.c \
1616
zend_common.c],
1717
$ext_shared)
@@ -32,7 +32,6 @@ if test "$PHP_ASYNC" = "yes"; then
3232
LIBUV_LIBLINE=`$PKG_CONFIG libuv --libs`
3333
LIBUV_VERSION=`$PKG_CONFIG libuv --modversion`
3434
AC_MSG_RESULT(from pkgconfig: found version $LIBUV_VERSION)
35-
AC_DEFINE(PHP_ASYNC_LIBUV,1,[ ])
3635
else
3736
AC_MSG_ERROR(system libuv must be upgraded to version >= 1.44.0 (fixes UV_RUN_ONCE busy loop issue))
3837
fi
@@ -57,7 +56,6 @@ if test "$PHP_ASYNC" = "yes"; then
5756
PHP_CHECK_LIBRARY(uv, uv_version,
5857
[
5958
PHP_ADD_LIBRARY_WITH_PATH(uv, $UV_DIR/$PHP_LIBDIR, UV_SHARED_LIBADD)
60-
AC_DEFINE(PHP_ASYNC_LIBUV,1,[ ])
6159
],[
6260
AC_MSG_ERROR([wrong uv library version or library not found])
6361
],[
@@ -74,8 +72,8 @@ if test "$PHP_ASYNC" = "yes"; then
7472

7573
dnl Link against needed libraries.
7674
PHP_ADD_LIBRARY([uv], 1, ASYNC_SHARED_LIBADD)
75+
PHP_SUBST(ASYNC_SHARED_LIBADD)
7776

78-
dnl Add libuv-specific reactor code.
79-
PHP_ADD_SOURCES([ext/async], [libuv_reactor.c])
77+
dnl Install libuv-specific reactor headers.
8078
PHP_INSTALL_HEADERS([ext/async], [libuv_reactor.h])
8179
fi

config.w32

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,11 @@ ARG_ENABLE('async', 'Enable True Async', 'no');
44

55
if (PHP_ASYNC == "yes") {
66

7-
if(typeof PHP_ASYNC_API == "undefined" && typeof PHP_EXPERIMENTAL_ASYNC_API != "undefined") {
8-
var PHP_ASYNC_API = PHP_EXPERIMENTAL_ASYNC_API;
9-
}
10-
11-
if (!PHP_ASYNC_API || PHP_ASYNC_API != "yes") {
12-
ERROR("PHP TRUE ASYNC API is required. Please configure PHP with --with-async-api.");
13-
}
14-
15-
EXTENSION("async", "async.c coroutine.c scope.c scheduler.c exceptions.c iterator.c async_API.c");
16-
ADD_SOURCES("ext/async","zend_common.c context.c");
7+
EXTENSION("async", "async.c coroutine.c scope.c scheduler.c exceptions.c iterator.c async_API.c zend_common.c context.c libuv_reactor.c");
178
ADD_SOURCES("ext/async/internal", "allocator.c circular_buffer.c");
189

1910
ADD_FLAG("CFLAGS", "/D PHP_ASYNC");
11+
ADD_FLAG("CFLAGS", "/D ASYNC_EXPORTS");
2012

2113
PHP_INSTALL_HEADERS("ext/async", "php_async.h");
2214
PHP_INSTALL_HEADERS("ext/async", "coroutine.h");
@@ -26,17 +18,14 @@ if (PHP_ASYNC == "yes") {
2618
PHP_INSTALL_HEADERS("ext/async", "iterator.h");
2719
PHP_INSTALL_HEADERS("ext/async", "async_API.h");
2820
PHP_INSTALL_HEADERS("ext/async", "context.h");
21+
PHP_INSTALL_HEADERS("ext/async", "libuv_reactor.h");
2922

3023
if (CHECK_HEADER_ADD_INCLUDE("libuv/uv.h", "CFLAGS_UV", PHP_PHP_BUILD + "\\include")
3124
&& CHECK_LIB("libuv.lib", "libuv")) {
3225

3326
// Note: libuv >= 1.44.0 is required for UV_RUN_ONCE busy loop fix
3427
// For Windows builds, manually verify libuv version meets requirements
35-
36-
PHP_INSTALL_HEADERS("ext/async", "libuv_reactor.h");
3728

38-
ADD_SOURCES("ext/async", "libuv_reactor.c");
39-
ADD_FLAG("CFLAGS", "/D PHP_ASYNC_LIBUV");
4029
ADD_FLAG("LIBS", "libuv.lib Dbghelp.lib Userenv.lib");
4130
} else {
4231
ERROR("Libuv components are not found. The search was performed in the directory: '" + PHP_PHP_BUILD +

context.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#ifndef CONTEXT_H
1717
#define CONTEXT_H
1818

19+
#include "php_async.h"
1920
#include <Zend/zend_async_API.h>
2021

2122
typedef struct _async_context_s async_context_t;
@@ -40,7 +41,7 @@ async_context_t *async_context_new(void);
4041
void async_context_dispose(async_context_t *context);
4142

4243
// Class entry
43-
extern zend_class_entry *async_ce_context;
44+
PHP_ASYNC_API extern zend_class_entry *async_ce_context;
4445
void async_register_context_ce(void);
4546

4647

coroutine.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
#ifndef COROUTINE_H
1717
#define COROUTINE_H
1818

19+
#include "php_async_api.h"
1920
#include <Zend/zend_async_API.h>
2021

2122
ZEND_STACK_ALIGNED void async_coroutine_execute(zend_fiber_transfer *transfer);
22-
extern zend_class_entry *async_ce_coroutine;
23+
PHP_ASYNC_API extern zend_class_entry *async_ce_coroutine;
2324

2425
typedef struct _async_coroutine_s async_coroutine_t;
2526

exceptions.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
| Author: Edmond |
1414
+----------------------------------------------------------------------+
1515
*/
16+
#include "php_async.h"
1617
#include "exceptions.h"
1718

1819
#include <zend_API.h>
@@ -68,7 +69,7 @@ void async_register_exceptions_ce(void)
6869
async_ce_composite_exception = register_class_Async_CompositeException(zend_ce_exception);
6970
}
7071

71-
zend_object *async_new_exception(zend_class_entry *exception_ce, const char *format, ...)
72+
PHP_ASYNC_API zend_object *async_new_exception(zend_class_entry *exception_ce, const char *format, ...)
7273
{
7374
zval exception, message_val;
7475

@@ -95,7 +96,7 @@ zend_object *async_new_exception(zend_class_entry *exception_ce, const char *for
9596
return Z_OBJ(exception);
9697
}
9798

98-
ZEND_API ZEND_COLD zend_object *async_throw_error(const char *format, ...)
99+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_error(const char *format, ...)
99100
{
100101
va_list args;
101102
va_start(args, format);
@@ -115,7 +116,7 @@ ZEND_API ZEND_COLD zend_object *async_throw_error(const char *format, ...)
115116
return obj;
116117
}
117118

118-
ZEND_API ZEND_COLD zend_object *async_throw_cancellation(const char *format, ...)
119+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_cancellation(const char *format, ...)
119120
{
120121
const zend_object *previous_exception = EG(exception);
121122

@@ -142,7 +143,7 @@ ZEND_API ZEND_COLD zend_object *async_throw_cancellation(const char *format, ...
142143
return obj;
143144
}
144145

145-
ZEND_API ZEND_COLD zend_object *async_throw_input_output(const char *format, ...)
146+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_input_output(const char *format, ...)
146147
{
147148
format = format ? format : "An input/output error occurred.";
148149

@@ -162,7 +163,7 @@ ZEND_API ZEND_COLD zend_object *async_throw_input_output(const char *format, ...
162163
return obj;
163164
}
164165

165-
ZEND_API ZEND_COLD zend_object *async_throw_timeout(const char *format, const zend_long timeout)
166+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_timeout(const char *format, const zend_long timeout)
166167
{
167168
format = format ? format : "A timeout of %u microseconds occurred";
168169

@@ -175,7 +176,7 @@ ZEND_API ZEND_COLD zend_object *async_throw_timeout(const char *format, const ze
175176
}
176177
}
177178

178-
ZEND_API ZEND_COLD zend_object *async_throw_poll(const char *format, ...)
179+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_poll(const char *format, ...)
179180
{
180181
va_list args;
181182
va_start(args, format);
@@ -193,15 +194,14 @@ ZEND_API ZEND_COLD zend_object *async_throw_poll(const char *format, ...)
193194
return obj;
194195
}
195196

196-
ZEND_API ZEND_COLD zend_object *async_new_composite_exception(void)
197+
PHP_ASYNC_API ZEND_COLD zend_object *async_new_composite_exception(void)
197198
{
198199
zval composite;
199200
object_init_ex(&composite, async_ce_composite_exception);
200201
return Z_OBJ(composite);
201202
}
202203

203-
ZEND_API ZEND_COLD void
204-
async_composite_exception_add_exception(zend_object *composite, zend_object *exception, bool transfer)
204+
PHP_ASYNC_API void async_composite_exception_add_exception(zend_object *composite, zend_object *exception, bool transfer)
205205
{
206206
if (composite == NULL || exception == NULL) {
207207
return;
@@ -321,7 +321,7 @@ void async_apply_exception(zend_object **to_exception)
321321
}
322322
}
323323

324-
void async_rethrow_exception(zend_object *exception)
324+
PHP_ASYNC_API void async_rethrow_exception(zend_object *exception)
325325
{
326326
if (EG(current_execute_data)) {
327327
zend_throw_exception_internal(exception);

exceptions.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,31 @@
1919
#include <zend_portability.h>
2020
#include <zend_property_hooks.h>
2121
#include <Zend/zend_async_API.h>
22+
#include "php_async_api.h"
2223

2324
BEGIN_EXTERN_C()
2425

25-
extern zend_class_entry *async_ce_async_exception;
26-
extern zend_class_entry *async_ce_cancellation_exception;
27-
extern zend_class_entry *async_ce_input_output_exception;
28-
extern zend_class_entry *async_ce_timeout_exception;
29-
extern zend_class_entry *async_ce_poll_exception;
30-
extern zend_class_entry *async_ce_dns_exception;
31-
extern zend_class_entry *async_ce_composite_exception;
26+
PHP_ASYNC_API extern zend_class_entry *async_ce_async_exception;
27+
PHP_ASYNC_API extern zend_class_entry *async_ce_cancellation_exception;
28+
PHP_ASYNC_API extern zend_class_entry *async_ce_input_output_exception;
29+
PHP_ASYNC_API extern zend_class_entry *async_ce_timeout_exception;
30+
PHP_ASYNC_API extern zend_class_entry *async_ce_poll_exception;
31+
PHP_ASYNC_API extern zend_class_entry *async_ce_dns_exception;
32+
PHP_ASYNC_API extern zend_class_entry *async_ce_composite_exception;
3233

3334
void async_register_exceptions_ce(void);
34-
ZEND_API ZEND_COLD zend_object *async_new_exception(zend_class_entry *exception_ce, const char *format, ...);
35-
ZEND_API ZEND_COLD zend_object *async_throw_error(const char *format, ...);
36-
ZEND_API ZEND_COLD zend_object *async_throw_cancellation(const char *format, ...);
37-
ZEND_API ZEND_COLD zend_object *async_throw_input_output(const char *format, ...);
38-
ZEND_API ZEND_COLD zend_object *async_throw_timeout(const char *format, const zend_long timeout);
39-
ZEND_API ZEND_COLD zend_object *async_throw_poll(const char *format, ...);
40-
ZEND_API ZEND_COLD zend_object *async_new_composite_exception(void);
41-
ZEND_API void async_composite_exception_add_exception(zend_object *composite, zend_object *exception, bool transfer);
35+
PHP_ASYNC_API ZEND_COLD zend_object *async_new_exception(zend_class_entry *exception_ce, const char *format, ...);
36+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_error(const char *format, ...);
37+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_cancellation(const char *format, ...);
38+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_input_output(const char *format, ...);
39+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_timeout(const char *format, const zend_long timeout);
40+
PHP_ASYNC_API ZEND_COLD zend_object *async_throw_poll(const char *format, ...);
41+
PHP_ASYNC_API ZEND_COLD zend_object *async_new_composite_exception(void);
42+
PHP_ASYNC_API void async_composite_exception_add_exception(zend_object *composite, zend_object *exception, bool transfer);
4243
bool async_spawn_and_throw(zend_object *exception, zend_async_scope_t *scope, int32_t priority);
4344
void async_apply_exception_to_context(zend_object *exception);
4445
zend_object *async_extract_exception(void);
45-
void async_rethrow_exception(zend_object *exception);
46+
PHP_ASYNC_API void async_rethrow_exception(zend_object *exception);
4647
void async_apply_exception(zend_object **to_exception);
4748

4849
END_EXTERN_C()

php_async.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@
1818

1919
#include <php.h>
2020

21-
#ifdef PHP_ASYNC_LIBUV
2221
#ifdef PHP_WIN32
2322
#include "libuv/uv.h"
2423
#else
2524
#include <uv.h>
2625
#endif
27-
#endif
2826

2927
#include "coroutine.h"
3028
#include "internal/circular_buffer.h"
@@ -38,12 +36,14 @@
3836
extern zend_module_entry async_module_entry;
3937
#define phpext_async_ptr &async_module_entry
4038

41-
extern zend_class_entry *async_ce_awaitable;
42-
extern zend_class_entry *async_ce_timeout;
39+
#include "php_async_api.h"
40+
41+
PHP_ASYNC_API extern zend_class_entry *async_ce_awaitable;
42+
PHP_ASYNC_API extern zend_class_entry *async_ce_timeout;
4343

44-
#define PHP_ASYNC_NAME "TrueAsync"
45-
#define PHP_ASYNC_VERSION "0.5.0"
46-
#define PHP_ASYNC_NAME_VERSION "TrueAsync v0.5.0"
44+
#define PHP_ASYNC_NAME "true_async"
45+
#define PHP_ASYNC_VERSION "0.4.0"
46+
#define PHP_ASYNC_NAME_VERSION "true async v0.4.0"
4747

4848
typedef struct
4949
{
@@ -82,7 +82,6 @@ zend_async_context_t *root_context;
8282
/* The default concurrency */
8383
int default_concurrency;
8484

85-
#ifdef PHP_ASYNC_LIBUV
8685
/* The reactor */
8786
uv_loop_t uvloop;
8887
bool reactor_started;
@@ -101,7 +100,6 @@ uv_async_t *uvloop_wakeup;
101100
/* Circular buffer of libuv_process_t ptr */
102101
circular_buffer_t *pid_queue;
103102
#endif
104-
#endif
105103

106104
#ifdef PHP_WIN32
107105
#endif

php_async_api.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| Copyright (c) The PHP Group |
4+
+----------------------------------------------------------------------+
5+
| This source file is subject to version 3.01 of the PHP license, |
6+
| that is bundled with this package in the file LICENSE, and is |
7+
| available through the world-wide-web at the following url: |
8+
| https://www.php.net/license/3_01.txt |
9+
| If you did not receive a copy of the PHP license and are unable to |
10+
| obtain it through the world-wide-web, please send a note to |
11+
| [email protected] so we can mail you a copy immediately. |
12+
+----------------------------------------------------------------------+
13+
| Author: Edmond |
14+
+----------------------------------------------------------------------+
15+
*/
16+
#ifndef PHP_ASYNC_API_H
17+
#define PHP_ASYNC_API_H
18+
19+
#ifdef PHP_WIN32
20+
# ifdef ASYNC_EXPORTS
21+
# define PHP_ASYNC_API __declspec(dllexport)
22+
# else
23+
# define PHP_ASYNC_API __declspec(dllimport)
24+
# endif
25+
#else
26+
# if defined(__GNUC__) && __GNUC__ >= 4
27+
# define PHP_ASYNC_API __attribute__ ((visibility("default")))
28+
# else
29+
# define PHP_ASYNC_API
30+
# endif
31+
#endif
32+
33+
#endif // PHP_ASYNC_API_H

0 commit comments

Comments
 (0)