@@ -120,37 +120,23 @@ static int le_link, le_plink, le_result, le_lofp;
120
120
#define pg_encoding_to_char (x ) "SQL_ASCII"
121
121
#endif
122
122
123
- /* {{{ _php_pgsql_trim_message */
124
- static char * _php_pgsql_trim_message (const char * message , size_t * len )
123
+ static zend_string * _php_pgsql_trim_message (const char * message )
125
124
{
126
- register size_t i = strlen (message );
125
+ size_t i = strlen (message );
127
126
128
127
if (i > 2 && (message [i - 2 ] == '\r' || message [i - 2 ] == '\n' ) && message [i - 1 ] == '.' ) {
129
128
-- i ;
130
129
}
131
130
while (i > 1 && (message [i - 1 ] == '\r' || message [i - 1 ] == '\n' )) {
132
131
-- i ;
133
132
}
134
- if (len ) {
135
- * len = i ;
136
- }
137
- return estrndup (message , i );
138
- }
139
- /* }}} */
140
-
141
- /* {{{ _php_pgsql_trim_result */
142
- static inline char * _php_pgsql_trim_result (PGconn * pgsql , char * * buf )
143
- {
144
- return * buf = _php_pgsql_trim_message (PQerrorMessage (pgsql ), NULL );
133
+ return zend_string_init (message , i , 0 );
145
134
}
146
- /* }}} */
147
135
148
- #define PQErrorMessageTrim (pgsql , buf ) _php_pgsql_trim_result(pgsql, buf)
149
-
150
- #define PHP_PQ_ERROR (text , pgsql ) { \
151
- char *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql), NULL); \
152
- php_error_docref(NULL, E_WARNING, text, msgbuf); \
153
- efree(msgbuf); \
136
+ #define PHP_PQ_ERROR (text , pgsql ) { \
137
+ zend_string *msgbuf = _php_pgsql_trim_message(PQerrorMessage(pgsql)); \
138
+ php_error_docref(NULL, E_WARNING, text, ZSTR_VAL(msgbuf)); \
139
+ zend_string_release(msgbuf); \
154
140
} \
155
141
156
142
/* {{{ php_pgsql_set_default_link */
@@ -206,25 +192,23 @@ static void _close_pgsql_plink(zend_resource *rsrc)
206
192
/* {{{ _php_pgsql_notice_handler */
207
193
static void _php_pgsql_notice_handler (void * resource_id , const char * message )
208
194
{
209
- zval * notices ;
195
+ if (PGG (ignore_notices )) {
196
+ return ;
197
+ }
198
+
210
199
zval tmp ;
211
- char * trimed_message ;
212
- size_t trimed_message_len ;
213
-
214
- if (! PGG (ignore_notices )) {
215
- notices = zend_hash_index_find (& PGG (notices ), (zend_ulong )resource_id );
216
- if (!notices ) {
217
- array_init (& tmp );
218
- notices = & tmp ;
219
- zend_hash_index_update (& PGG (notices ), (zend_ulong )resource_id , notices );
220
- }
221
- trimed_message = _php_pgsql_trim_message (message , & trimed_message_len );
222
- if (PGG (log_notices )) {
223
- php_error_docref (NULL , E_NOTICE , "%s" , trimed_message );
224
- }
225
- add_next_index_stringl (notices , trimed_message , trimed_message_len );
226
- efree (trimed_message );
200
+ zval * notices = zend_hash_index_find (& PGG (notices ), (zend_ulong )resource_id );
201
+ if (!notices ) {
202
+ array_init (& tmp );
203
+ notices = & tmp ;
204
+ zend_hash_index_update (& PGG (notices ), (zend_ulong )resource_id , notices );
227
205
}
206
+
207
+ zend_string * trimmed_message = _php_pgsql_trim_message (message );
208
+ if (PGG (log_notices )) {
209
+ php_error_docref (NULL , E_NOTICE , "%s" , ZSTR_VAL (trimmed_message ));
210
+ }
211
+ add_next_index_str (notices , trimmed_message );
228
212
}
229
213
/* }}} */
230
214
@@ -776,7 +760,6 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
776
760
zend_resource * link ;
777
761
zval * pgsql_link = NULL ;
778
762
PGconn * pgsql ;
779
- char * msgbuf ;
780
763
char * result ;
781
764
782
765
if (zend_parse_parameters (ZEND_NUM_ARGS (), "|r!" , & pgsql_link ) == FAILURE ) {
@@ -799,10 +782,7 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
799
782
result = PQdb (pgsql );
800
783
break ;
801
784
case PHP_PG_ERROR_MESSAGE :
802
- result = PQErrorMessageTrim (pgsql , & msgbuf );
803
- RETVAL_STRING (result );
804
- efree (result );
805
- return ;
785
+ RETURN_STR (_php_pgsql_trim_message (PQerrorMessage (pgsql )));
806
786
case PHP_PG_OPTIONS :
807
787
result = PQoptions (pgsql );
808
788
break ;
0 commit comments