Skip to content

Commit b8f7d9f

Browse files
author
Hartmut Holzgraefe
committed
wrap all PHPAPI prototypes into BEGIN_EXTERN_C/END_EXTERN_C blocks
(else they won't be usable from C++ extensions)
1 parent 1727c6a commit b8f7d9f

8 files changed

Lines changed: 41 additions & 5 deletions

File tree

main/php_memory_streams.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
#define php_stream_temp_create_rel(mode, max_memory_usage) _php_stream_temp_create((mode), (max_memory_usage) STREAMS_REL_CC TSRMLS_CC)
3939
#define php_stream_temp_open(mode, max_memory_usage, buf, length) _php_stream_temp_open((mode), (max_memory_usage), (buf), (length) STREAMS_CC TSRMLS_CC)
4040

41-
41+
BEGIN_EXTERN_C()
4242
PHPAPI php_stream *_php_stream_memory_create(int mode STREAMS_DC TSRMLS_DC);
4343
PHPAPI php_stream *_php_stream_memory_open(int mode, char *buf, size_t length STREAMS_DC TSRMLS_DC);
4444
PHPAPI char *_php_stream_memory_get_buffer(php_stream *stream, size_t *length STREAMS_DC TSRMLS_DC);
4545

4646
PHPAPI php_stream *_php_stream_temp_create(int mode, size_t max_memory_usage STREAMS_DC TSRMLS_DC);
4747
PHPAPI php_stream *_php_stream_temp_open(int mode, size_t max_memory_usage, char *buf, size_t length STREAMS_DC TSRMLS_DC);
48+
END_EXTERN_C()
4849

4950
extern php_stream_ops php_stream_memory_ops;
5051
extern php_stream_ops php_stream_temp_ops;

main/php_network.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262
/* like strerror, but caller must efree the returned string,
6363
* unless buf is not NULL.
6464
* Also works sensibly for win32 */
65+
BEGIN_EXTERN_C()
6566
PHPAPI char *php_socket_strerror(long err, char *buf, size_t bufsize);
67+
END_EXTERN_C()
6668

6769
#ifdef HAVE_NETINET_IN_H
6870
# include <netinet/in.h>
@@ -120,6 +122,7 @@ typedef struct {
120122
} php_sockaddr_storage;
121123
#endif
122124

125+
BEGIN_EXTERN_C()
123126
PHPAPI php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short port,
124127
int socktype, int asynchronous, struct timeval *timeout, char **error_string,
125128
int *error_code
@@ -163,7 +166,7 @@ PHPAPI int php_network_get_peer_name(php_socket_t sock,
163166

164167
PHPAPI void php_any_addr(int family, php_sockaddr_storage *addr, unsigned short port);
165168
PHPAPI int php_sockaddr_size(php_sockaddr_storage *addr);
166-
169+
END_EXTERN_C()
167170

168171
struct _php_netstream_data_t {
169172
php_socket_t socket;
@@ -177,6 +180,7 @@ PHPAPI extern php_stream_ops php_stream_socket_ops;
177180
extern php_stream_ops php_stream_generic_socket_ops;
178181
#define PHP_STREAM_IS_SOCKET (&php_stream_socket_ops)
179182

183+
BEGIN_EXTERN_C()
180184
PHPAPI php_stream *_php_stream_sock_open_from_socket(php_socket_t socket, const char *persistent_id STREAMS_DC TSRMLS_DC );
181185
/* open a connection to a host using php_hostconnect and return a stream */
182186
PHPAPI php_stream *_php_stream_sock_open_host(const char *host, unsigned short port,
@@ -193,6 +197,7 @@ PHPAPI void php_network_populate_name_from_sockaddr(
193197

194198
PHPAPI int php_network_parse_network_address_with_port(const char *addr,
195199
long addrlen, struct sockaddr *sa, socklen_t *sl TSRMLS_DC);
200+
END_EXTERN_C()
196201

197202
#define php_stream_sock_open_from_socket(socket, persistent) _php_stream_sock_open_from_socket((socket), (persistent) STREAMS_CC TSRMLS_CC)
198203
#define php_stream_sock_open_host(host, port, socktype, timeout, persistent) _php_stream_sock_open_host((host), (port), (socktype), (timeout), (persistent) STREAMS_CC TSRMLS_CC)

main/php_open_temporary_file.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#ifndef PHP_OPEN_TEMPORARY_FILE_H
2222
#define PHP_OPEN_TEMPORARY_FILE_H
2323

24+
BEGIN_EXTERN_C()
2425
PHPAPI FILE *php_open_temporary_file(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC);
2526
PHPAPI int php_open_temporary_fd(const char *dir, const char *pfx, char **opened_path_p TSRMLS_DC);
27+
END_EXTERN_C()
2628

2729
#endif /* PHP_OPEN_TEMPORARY_FILE_H */

main/php_output.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
typedef void (*php_output_handler_func_t)(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC);
2525

26+
BEGIN_EXTERN_C()
2627
PHPAPI void php_output_startup(void);
2728
PHPAPI void php_output_activate(TSRMLS_D);
2829
PHPAPI void php_output_set_status(zend_bool status TSRMLS_DC);
@@ -44,6 +45,7 @@ PHPAPI int php_ob_handler_used(char *handler_name TSRMLS_DC);
4445
PHPAPI int php_ob_init_conflict(char *handler_new, char *handler_set TSRMLS_DC);
4546
PHPAPI int php_ob_get_buffer(zval *p TSRMLS_DC);
4647
PHPAPI int php_ob_get_length(zval *p TSRMLS_DC);
48+
END_EXTERN_C()
4749

4850
PHP_FUNCTION(ob_start);
4951
PHP_FUNCTION(ob_flush);

main/php_reentrancy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#undef HAVE_GMTIME_R
5050
#endif
5151

52+
BEGIN_EXTERN_C()
53+
5254
#if defined(HAVE_POSIX_READDIR_R)
5355
#define php_readdir_r readdir_r
5456
#else
@@ -114,6 +116,8 @@ PHPAPI int php_rand_r(unsigned int *seed);
114116
#define php_rand_r rand_r
115117
#endif
116118

119+
END_EXTERN_C()
120+
117121
#if !defined(ZTS)
118122
#undef PHP_NEED_REENTRANCY
119123
#endif

main/php_streams.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
#include <sys/types.h>
2828
#include <sys/stat.h>
2929

30+
BEGIN_EXTERN_C()
3031
PHPAPI int php_file_le_stream(void);
3132
PHPAPI int php_file_le_pstream(void);
33+
END_EXTERN_C()
3234

3335
/* {{{ Streams memory debugging stuff */
3436

@@ -226,8 +228,10 @@ struct _php_stream {
226228
#define PHP_STREAM_FCLOSE_FOPENCOOKIE 2
227229

228230
/* allocate a new stream for a particular ops */
231+
BEGIN_EXTERN_C()
229232
PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract,
230233
const char *persistent_id, const char *mode STREAMS_DC TSRMLS_DC);
234+
END_EXTERN_C()
231235
#define php_stream_alloc(ops, thisptr, persistent_id, mode) _php_stream_alloc((ops), (thisptr), (persistent_id), (mode) STREAMS_CC TSRMLS_CC)
232236

233237

@@ -247,6 +251,7 @@ PHPAPI php_stream *_php_stream_alloc(php_stream_ops *ops, void *abstract,
247251
#define php_stream_from_zval(xstr, ppzval) ZEND_FETCH_RESOURCE2((xstr), php_stream *, (ppzval), -1, "stream", php_file_le_stream(), php_file_le_pstream())
248252
#define php_stream_from_zval_no_verify(xstr, ppzval) (xstr) = (php_stream*)zend_fetch_resource((ppzval) TSRMLS_CC, -1, "stream", NULL, 2, php_file_le_stream(), php_file_le_pstream())
249253

254+
BEGIN_EXTERN_C()
250255
PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream **stream TSRMLS_DC);
251256
#define PHP_STREAM_PERSISTENT_SUCCESS 0 /* id exists */
252257
#define PHP_STREAM_PERSISTENT_FAILURE 1 /* id exists but is not a stream! */
@@ -260,6 +265,7 @@ PHPAPI int php_stream_from_persistent_id(const char *persistent_id, php_stream *
260265
#define PHP_STREAM_FREE_CLOSE (PHP_STREAM_FREE_CALL_DTOR | PHP_STREAM_FREE_RELEASE_STREAM)
261266
#define PHP_STREAM_FREE_CLOSE_CASTED (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PRESERVE_HANDLE)
262267
#define PHP_STREAM_FREE_CLOSE_PERSISTENT (PHP_STREAM_FREE_CLOSE | PHP_STREAM_FREE_PERSISTENT)
268+
263269
PHPAPI int _php_stream_free(php_stream *stream, int close_options TSRMLS_DC);
264270
#define php_stream_free(stream, close_options) _php_stream_free((stream), (close_options) TSRMLS_CC)
265271
#define php_stream_close(stream) _php_stream_free((stream), PHP_STREAM_FREE_CLOSE TSRMLS_CC)
@@ -337,6 +343,9 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi
337343

338344
#define php_stream_set_chunk_size(stream, size) _php_stream_set_option((stream), PHP_STREAM_OPTION_SET_CHUNK_SIZE, (size), NULL TSRMLS_CC)
339345

346+
END_EXTERN_C()
347+
348+
340349
/* Flags for mkdir method in wrapper ops */
341350
#define PHP_STREAM_MKDIR_RECURSIVE 1
342351
/* define REPORT ERRORS 8 (below) */
@@ -384,8 +393,10 @@ PHPAPI int _php_stream_set_option(php_stream *stream, int option, int value, voi
384393

385394
#define php_stream_truncate_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_TRUNCATE_API, PHP_STREAM_TRUNCATE_SUPPORTED, NULL TSRMLS_CC) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
386395

396+
BEGIN_EXTERN_C()
387397
PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize TSRMLS_DC);
388398
#define php_stream_truncate_set_size(stream, size) _php_stream_truncate_set_size((stream), (size) TSRMLS_CC)
399+
END_EXTERN_C()
389400

390401
#define PHP_STREAM_OPTION_META_DATA_API 11 /* ptrparam is a zval* to which to add meta data information */
391402
#define php_stream_populate_meta_data(stream, zv) (_php_stream_set_option((stream), PHP_STREAM_OPTION_META_DATA_API, 0, zv TSRMLS_CC) == PHP_STREAM_OPTION_RETURN_OK ? 1 : 0)
@@ -401,6 +412,7 @@ PHPAPI int _php_stream_truncate_set_size(php_stream *stream, size_t newsize TSRM
401412
/* copy up to maxlen bytes from src to dest. If maxlen is PHP_STREAM_COPY_ALL, copy until eof(src).
402413
* Uses mmap if the src is a plain file and at offset 0 */
403414
#define PHP_STREAM_COPY_ALL -1
415+
BEGIN_EXTERN_C()
404416
PHPAPI size_t _php_stream_copy_to_stream(php_stream *src, php_stream *dest, size_t maxlen STREAMS_DC TSRMLS_DC);
405417
#define php_stream_copy_to_stream(src, dest, maxlen) _php_stream_copy_to_stream((src), (dest), (maxlen) STREAMS_CC TSRMLS_CC)
406418

@@ -414,6 +426,7 @@ PHPAPI size_t _php_stream_copy_to_mem(php_stream *src, char **buf, size_t maxlen
414426
/* output all data from a stream */
415427
PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC);
416428
#define php_stream_passthru(stream) _php_stream_passthru((stream) STREAMS_CC TSRMLS_CC)
429+
END_EXTERN_C()
417430

418431
#include "streams/php_stream_transport.h"
419432
#include "streams/php_stream_plain_wrapper.h"
@@ -435,7 +448,9 @@ PHPAPI size_t _php_stream_passthru(php_stream * src STREAMS_DC TSRMLS_DC);
435448
#define PHP_STREAM_CAST_RELEASE 0x40000000 /* stream becomes invalid on success */
436449
#define PHP_STREAM_CAST_INTERNAL 0x20000000 /* stream cast for internal use */
437450
#define PHP_STREAM_CAST_MASK (PHP_STREAM_CAST_TRY_HARD | PHP_STREAM_CAST_RELEASE | PHP_STREAM_CAST_INTERNAL)
451+
BEGIN_EXTERN_C()
438452
PHPAPI int _php_stream_cast(php_stream *stream, int castas, void **ret, int show_err TSRMLS_DC);
453+
END_EXTERN_C()
439454
/* use this to check if a stream can be cast into another form */
440455
#define php_stream_can_cast(stream, as) _php_stream_cast((stream), (as), NULL, 0 TSRMLS_CC)
441456
#define php_stream_cast(stream, as, ret, show_err) _php_stream_cast((stream), (as), (ret), (show_err) TSRMLS_CC)
@@ -491,6 +506,7 @@ int php_init_stream_wrappers(int module_number TSRMLS_DC);
491506
int php_shutdown_stream_wrappers(int module_number TSRMLS_DC);
492507
PHP_RSHUTDOWN_FUNCTION(streams);
493508

509+
BEGIN_EXTERN_C()
494510
PHPAPI int php_register_url_stream_wrapper(char *protocol, php_stream_wrapper *wrapper TSRMLS_DC);
495511
PHPAPI int php_unregister_url_stream_wrapper(char *protocol TSRMLS_DC);
496512
PHPAPI php_stream *_php_stream_open_wrapper_ex(char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
@@ -524,6 +540,7 @@ PHPAPI int _php_stream_make_seekable(php_stream *origstream, php_stream **newstr
524540
/* Give other modules access to the url_stream_wrappers_hash and stream_filters_hash */
525541
PHPAPI HashTable *php_stream_get_url_stream_wrappers_hash();
526542
PHPAPI HashTable *php_get_stream_filters_hash();
543+
END_EXTERN_C()
527544
#endif
528545

529546
/*

main/php_ticks.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
int php_startup_ticks(TSRMLS_D);
2525
void php_shutdown_ticks(TSRMLS_D);
2626
void php_run_ticks(int count);
27+
28+
BEGIN_EXTERN_C()
2729
PHPAPI void php_add_tick_function(void (*func)(int));
2830
PHPAPI void php_remove_tick_function(void (*func)(int));
31+
END_EXTERN_C()
2932

3033
#endif
3134

main/safe_mode.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
/* flags for php_checkuid_ex() */
3333
#define CHECKUID_NO_ERRORS 0x01
3434

35-
extern PHPAPI int php_checkuid(const char *filename, char *fopen_mode, int mode);
36-
extern PHPAPI int php_checkuid_ex(const char *filename, char *fopen_mode, int mode, int flags);
37-
extern PHPAPI char *php_get_current_user(void);
35+
BEGIN_EXTERN_C()
36+
PHPAPI int php_checkuid(const char *filename, char *fopen_mode, int mode);
37+
PHPAPI int php_checkuid_ex(const char *filename, char *fopen_mode, int mode, int flags);
38+
PHPAPI char *php_get_current_user(void);
39+
END_EXTERN_C()
3840

3941
#endif

0 commit comments

Comments
 (0)