Skip to content

Commit 712c85e

Browse files
author
foobar
committed
One big mess is a bit less mess now.
1 parent 1259f0c commit 712c85e

File tree

3 files changed

+84
-136
lines changed

3 files changed

+84
-136
lines changed

ext/recode/config.m4

+39-56
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,42 @@ dnl
55
PHP_ARG_WITH(recode,for recode support,
66
[ --with-recode[=DIR] Include recode support.])
77

8-
if test "$PHP_RECODE" != "no"; then
9-
RECODE_LIST="$PHP_RECODE /usr /usr/local /opt"
10-
11-
for i in $RECODE_LIST; do
12-
if test -f $i/include/recode.h; then
13-
RECODE_DIR=$i
14-
RECODE_INC=include
15-
RECODE_LIB=lib
16-
fi
17-
if test -f $i/include/recode/recode.h; then
18-
RECODE_DIR=$i
19-
RECODE_INC=include/recode
20-
RECODE_LIB=lib/recode
21-
fi
22-
if test -f $i/recode/include/recode.h; then
23-
RECODE_DIR=$i/recode
24-
RECODE_INC=include
25-
RECODE_LIB=lib
26-
fi
27-
done
28-
if test "$RECODE_DIR" = ""; then
29-
AC_MSG_ERROR(I cannot find recode.h anywhere below $RECODE_LIST. Is it installed?)
30-
fi
31-
32-
old_LDFLAGS=$LDFLAGS
33-
old_LIBS=$LIBS
34-
LDFLAGS="$LDFLAGS -L$RECODE_DIR/$RECODE_LIB"
35-
LIBS="$LIBS -lrecode"
36-
AC_TRY_LINK([
37-
char *program_name;
38-
],[
39-
recode_format_table();
40-
],[],[
41-
AC_MSG_ERROR(I cannot link librecode (-L$RECODE_DIR/$RECODE_LIB -lrecode). Is it installed?)
42-
])
43-
LIBS=$old_LIBS
44-
LDFLAGS=$old_LDFLAGS
45-
46-
if test "$RECODE_LIB" = ""; then
47-
AC_MSG_ERROR(Please reinstall recode - I cannot find librecode.a)
48-
fi
49-
50-
PHP_ADD_INCLUDE($RECODE_DIR/$RECODE_INC)
51-
if test "$ext_shared" = "yes"; then
52-
PHP_ADD_LIBRARY_WITH_PATH(recode, $RECODE_DIR/$RECODE_LIB, RECODE_SHARED_LIBADD)
53-
PHP_SUBST(RECODE_SHARED_LIBADD)
54-
else
55-
PHP_ADD_LIBRARY_DEFER_WITH_PATH(recode, $RECODE_DIR/$RECODE_LIB)
56-
fi
57-
58-
AC_DEFINE(HAVE_LIBRECODE, 1, [Whether we have librecode 3.5 or higher])
59-
60-
AC_CHECK_HEADERS(stdbool.h)
61-
62-
PHP_NEW_EXTENSION(recode, recode.c, $ext_shared)
63-
fi
8+
if test "$PHP_RECODE" != "no"; then
9+
RECODE_LIST="$PHP_RECODE /usr /usr/local /opt"
10+
11+
for i in $RECODE_LIST; do
12+
if test -f $i/include/recode.h; then
13+
RECODE_DIR=$i
14+
RECODE_INC=include
15+
RECODE_LIB=lib
16+
fi
17+
if test -f $i/include/recode/recode.h; then
18+
RECODE_DIR=$i
19+
RECODE_INC=include/recode
20+
RECODE_LIB=lib/recode
21+
fi
22+
if test -f $i/recode/include/recode.h; then
23+
RECODE_DIR=$i/recode
24+
RECODE_INC=include
25+
RECODE_LIB=lib
26+
fi
27+
done
28+
29+
if test -z "$RECODE_DIR"; then
30+
AC_MSG_ERROR([Can not find recode.h anywhere under $RECODE_LIST.])
31+
fi
32+
33+
PHP_CHECK_LIBRARY(recode, recode_format_table, [
34+
AC_DEFINE(HAVE_LIBRECODE, 1, [Whether we have librecode 3.5 or higher])
35+
], [
36+
AC_MSG_ERROR(I cannot link librecode (-L$RECODE_DIR/$RECODE_LIB -lrecode). Is it installed?)
37+
], [
38+
-L$RECODE_DIR/$RECODE_LIB
39+
])
40+
41+
PHP_ADD_INCLUDE($RECODE_DIR/$RECODE_INC)
42+
PHP_ADD_LIBRARY_WITH_PATH(recode, $RECODE_DIR/$RECODE_LIB, RECODE_SHARED_LIBADD)
43+
PHP_SUBST(RECODE_SHARED_LIBADD)
44+
AC_CHECK_HEADERS(stdbool.h)
45+
PHP_NEW_EXTENSION(recode, recode.c, $ext_shared)
46+
fi

ext/recode/php_recode.h

+2-43
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,26 @@
1414
+----------------------------------------------------------------------+
1515
| Author: Kristian Koehntopp <kris@koehntopp.de> |
1616
+----------------------------------------------------------------------+
17-
*/
18-
17+
*/
1918

2019
/* $Id$ */
2120

2221
#ifndef PHP_RECODE_H
2322
#define PHP_RECODE_H
2423

25-
#ifdef PHP_WIN32
26-
#define PHP_MYSQL_API __declspec(dllexport)
27-
#else
28-
#define PHP_MYSQL_API
29-
#endif
30-
3124
#if HAVE_LIBRECODE
3225

33-
/* Checking for thread safety and issue warning if necessary. */
34-
#ifdef ZTS
35-
#warning Recode module has not been tested for thread-safety.
36-
#endif
37-
38-
/* Recode 3.5 is broken in the sense that it requires the definition
39-
* of a symbol "program_name" in order to link.
40-
*/
41-
#define HAVE_BROKEN_RECODE
42-
43-
#ifdef HAVE_STDBOOL_H
44-
# include <stdbool.h>
45-
#else
46-
typedef enum {false = 0, true = 1} bool;
47-
#endif
48-
49-
#include <sys/types.h>
50-
#include <stdio.h>
51-
#include <recode.h>
52-
#include <unistd.h>
53-
5426
extern zend_module_entry recode_module_entry;
5527
#define phpext_recode_ptr &recode_module_entry
5628

5729
PHP_MINIT_FUNCTION(recode);
5830
PHP_MSHUTDOWN_FUNCTION(recode);
5931
PHP_MINFO_FUNCTION(recode);
60-
6132
PHP_FUNCTION(recode_string);
6233
PHP_FUNCTION(recode_file);
6334

64-
#ifdef ZTS
65-
#include "TSRM.h"
66-
#endif
67-
68-
ZEND_BEGIN_MODULE_GLOBALS(recode)
69-
RECODE_OUTER outer;
70-
ZEND_END_MODULE_GLOBALS(recode)
71-
72-
#ifdef ZTS
73-
#define ReSG(v) TSRMG(recode_globals_id, zend_recode_globals *, v)
7435
#else
75-
#define ReSG(v) (recode_globals.v)
76-
#endif
77-
36+
#define phpext_recode_ptr NULL
7837
#endif
7938

8039
#endif /* PHP_RECODE_H */

ext/recode/recode.c

+43-37
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,43 @@
2525
#endif
2626

2727
#include "php.h"
28-
#include "php_recode.h"
2928
#include "php_streams.h"
3029

3130
#if HAVE_LIBRECODE
32-
#include "ext/standard/info.h"
33-
#include "ext/standard/file.h"
34-
#include "ext/standard/php_string.h"
35-
#include "zend_list.h"
3631

37-
38-
#ifdef HAVE_BROKEN_RECODE
32+
/* For recode 3.5 */
3933
extern char *program_name;
4034
char *program_name = "php";
35+
36+
#ifdef HAVE_STDBOOL_H
37+
# include <stdbool.h>
38+
#else
39+
typedef enum {false = 0, true = 1} bool;
4140
#endif
41+
42+
#include <stdio.h>
43+
#include <sys/types.h>
44+
#include <unistd.h>
45+
#include <recode.h>
46+
47+
#include "php_recode.h"
48+
#include "ext/standard/info.h"
49+
#include "ext/standard/file.h"
50+
#include "ext/standard/php_string.h"
51+
4252
/* }}} */
4353

44-
#define SAFE_STRING(s) ((s)?(s):"")
54+
ZEND_BEGIN_MODULE_GLOBALS(recode)
55+
RECODE_OUTER outer;
56+
ZEND_END_MODULE_GLOBALS(recode)
4557

58+
#ifdef ZTS
59+
# define ReSG(v) TSRMG(recode_globals_id, zend_recode_globals *, v)
60+
#else
61+
# define ReSG(v) (recode_globals.v)
62+
#endif
63+
4664
ZEND_DECLARE_MODULE_GLOBALS(recode);
47-
extern int le_fp,le_pp;
4865

4966
/* {{{ module stuff */
5067
static zend_function_entry php_recode_functions[] = {
@@ -55,22 +72,18 @@ static zend_function_entry php_recode_functions[] = {
5572
};
5673

5774
zend_module_entry recode_module_entry = {
58-
STANDARD_MODULE_HEADER,
75+
STANDARD_MODULE_HEADER,
5976
"recode",
60-
php_recode_functions,
77+
php_recode_functions,
6178
PHP_MINIT(recode),
6279
PHP_MSHUTDOWN(recode),
6380
NULL,
6481
NULL,
6582
PHP_MINFO(recode),
66-
NO_VERSION_YET,
83+
NO_VERSION_YET,
6784
STANDARD_MODULE_PROPERTIES
6885
};
6986

70-
#if APACHE
71-
extern void timeout(int sig);
72-
#endif
73-
7487
#ifdef COMPILE_DL_RECODE
7588
ZEND_GET_MODULE(recode)
7689
#endif
@@ -84,14 +97,14 @@ PHP_MINIT_FUNCTION(recode)
8497
{
8598
ZEND_INIT_MODULE_GLOBALS(recode, php_recode_init_globals, NULL);
8699

87-
ReSG(outer) = recode_new_outer(true);
88-
if (ReSG(outer) == NULL)
100+
ReSG(outer) = recode_new_outer(false);
101+
if (ReSG(outer) == NULL) {
89102
return FAILURE;
90-
103+
}
104+
91105
return SUCCESS;
92106
}
93107

94-
95108
PHP_MSHUTDOWN_FUNCTION(recode)
96109
{
97110
if (ReSG(outer)) {
@@ -100,36 +113,33 @@ PHP_MSHUTDOWN_FUNCTION(recode)
100113
return SUCCESS;
101114
}
102115

103-
104116
PHP_MINFO_FUNCTION(recode)
105117
{
106118
php_info_print_table_start();
107119
php_info_print_table_row(2, "Recode Support", "enabled");
108120
php_info_print_table_row(2, "Revision", "$Revision$");
109121
php_info_print_table_end();
110-
111122
}
112123

113124
/* {{{ proto string recode_string(string request, string str)
114125
Recode string str according to request string */
115-
116126
PHP_FUNCTION(recode_string)
117127
{
118128
RECODE_REQUEST request = NULL;
119129
char *r = NULL;
120-
pval **str;
121-
pval **req;
130+
zval **str;
131+
zval **req;
122132
bool success;
123133
int r_len=0, r_alen =0;
124134

125-
if (ZEND_NUM_ARGS() != 2
126-
|| zend_get_parameters_ex(2, &req, &str) == FAILURE) {
127-
WRONG_PARAM_COUNT;
135+
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &req, &str) == FAILURE) {
136+
WRONG_PARAM_COUNT;
128137
}
129138
convert_to_string_ex(str);
130139
convert_to_string_ex(req);
131140

132141
request = recode_new_request(ReSG(outer));
142+
133143
if (request == NULL) {
134144
php_error(E_WARNING, "Cannot allocate request structure");
135145
RETURN_FALSE;
@@ -168,20 +178,17 @@ PHP_FUNCTION(recode_file)
168178
{
169179
RECODE_REQUEST request = NULL;
170180
int success;
171-
pval **req;
172-
pval **input, **output;
181+
zval **req;
182+
zval **input, **output;
173183
php_stream *instream, *outstream;
174184
FILE *in_fp, *out_fp;
175185
int in_type, out_type;
176186

177-
178-
if (ZEND_NUM_ARGS() != 3
179-
|| zend_get_parameters_ex(3, &req, &input, &output) == FAILURE) {
187+
if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &req, &input, &output) == FAILURE) {
180188
WRONG_PARAM_COUNT;
181189
}
182190

183-
instream = zend_fetch_resource(input TSRMLS_CC,-1, "File-Handle", &in_type,
184-
1, php_file_le_stream());
191+
instream = zend_fetch_resource(input TSRMLS_CC,-1, "File-Handle", &in_type, 1, php_file_le_stream());
185192

186193
if (!instream) {
187194
php_error(E_WARNING,"Unable to find input file identifier");
@@ -192,8 +199,7 @@ PHP_FUNCTION(recode_file)
192199
RETURN_FALSE;
193200
}
194201

195-
outstream = zend_fetch_resource(output TSRMLS_CC,-1, "File-Handle", &out_type,
196-
1, php_file_le_stream());
202+
outstream = zend_fetch_resource(output TSRMLS_CC,-1, "File-Handle", &out_type, 1, php_file_le_stream());
197203
if (!outstream) {
198204
php_error(E_WARNING,"Unable to find output file identifier");
199205
RETURN_FALSE;

0 commit comments

Comments
 (0)