You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2005/08/18 23:17:50 UTC
svn commit: r233381 - in /apr/apr/trunk: CHANGES include/apr_lib.h
strings/apr_snprintf.c test/testfmt.c
Author: jorton
Date: Thu Aug 18 14:17:45 2005
New Revision: 233381
URL: http://svn.apache.org/viewcvs?rev=233381&view=rev
Log:
* strings/apr_snprintf.c (apr_vformatter): Add support for %pm to
print the error string corresponding to an apr_status_t.
* test/testfmt.c (error_fmt): New test.
* include/apr_lib.h: Document %pm and note the versioning constraint.
Modified:
apr/apr/trunk/CHANGES
apr/apr/trunk/include/apr_lib.h
apr/apr/trunk/strings/apr_snprintf.c
apr/apr/trunk/test/testfmt.c
Modified: apr/apr/trunk/CHANGES
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/CHANGES?rev=233381&r1=233380&r2=233381&view=diff
==============================================================================
--- apr/apr/trunk/CHANGES (original)
+++ apr/apr/trunk/CHANGES Thu Aug 18 14:17:45 2005
@@ -1,3 +1,11 @@
+Changes for APR 1.3.0
+
+ *) Add %pm support to apr_snprintf() for printing the error string
+ corresponding to an apr_status_t value. [Joe Orton]
+
+ *) Add APR_ARRAY_IDX() and APR_ARRAY_PUSH() convenience macros to
+ apr_tables.h. [Garrett Rooney]
+
Changes for APR 1.2.1
*) Refactor Win32 condition variables code to address bugs 27654, 34336.
Modified: apr/apr/trunk/include/apr_lib.h
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/include/apr_lib.h?rev=233381&r1=233380&r2=233381&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_lib.h (original)
+++ apr/apr/trunk/include/apr_lib.h Thu Aug 18 14:17:45 2005
@@ -118,8 +118,13 @@
* ('0' is printed if !APR_HAS_THREADS)
* %%pt takes an apr_os_thread_t * and prints it in hexadecimal
* ('0' is printed if !APR_HAS_THREADS)
+ * %%pm takes an apr_status_t * and prints the appropriate error
+ * string (from apr_strerror) corresponding to that error code.
* %%pp takes a void * and outputs it in hex
*
+ * %%pt is only available from APR 1.2.0 onwards.
+ * %%pm is only available from APR 1.3.0 onwards.
+ *
* The %%p hacks are to force gcc's printf warning code to skip
* over a pointer argument without complaining. This does
* mean that the ANSI-style %%p (output a void * in hex format) won't
Modified: apr/apr/trunk/strings/apr_snprintf.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/strings/apr_snprintf.c?rev=233381&r1=233380&r2=233381&view=diff
==============================================================================
--- apr/apr/trunk/strings/apr_snprintf.c (original)
+++ apr/apr/trunk/strings/apr_snprintf.c Thu Aug 18 14:17:45 2005
@@ -21,6 +21,7 @@
#include "apr_strings.h"
#include "apr_network_io.h"
#include "apr_portable.h"
+#include "apr_errno.h"
#include <math.h>
#if APR_HAVE_CTYPE_H
#include <ctype.h>
@@ -1157,6 +1158,24 @@
s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len);
if (adjust_precision && precision < s_len)
s_len = precision;
+ }
+ else {
+ s = S_NULL;
+ s_len = S_NULL_LEN;
+ }
+ pad_char = ' ';
+ }
+ break;
+
+ /* print the error for an apr_status_t */
+ case 'm':
+ {
+ apr_status_t *mrv;
+
+ mrv = va_arg(ap, apr_status_t *);
+ if (mrv != NULL) {
+ s = apr_strerror(*mrv, num_buf, NUM_BUF_SIZE-1);
+ s_len = strlen(s);
}
else {
s = S_NULL;
Modified: apr/apr/trunk/test/testfmt.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/test/testfmt.c?rev=233381&r1=233380&r2=233381&view=diff
==============================================================================
--- apr/apr/trunk/test/testfmt.c (original)
+++ apr/apr/trunk/test/testfmt.c Thu Aug 18 14:17:45 2005
@@ -117,6 +117,24 @@
ABTS_STR_EQUAL(tc, buf, "-314159265358979323");
}
+static void error_fmt(abts_case *tc, void *data)
+{
+ char ebuf[150], sbuf[150], *s;
+ apr_status_t rv;
+
+ rv = APR_SUCCESS;
+ apr_strerror(rv, ebuf, sizeof ebuf);
+ apr_snprintf(sbuf, sizeof sbuf, "%pm", &rv);
+ ABTS_STR_EQUAL(tc, sbuf, ebuf);
+
+ rv = APR_ENOTIMPL;
+ s = apr_pstrcat(p, "foo-",
+ apr_strerror(rv, ebuf, sizeof ebuf),
+ "-bar", NULL);
+ apr_snprintf(sbuf, sizeof sbuf, "foo-%pm-bar", &rv);
+ ABTS_STR_EQUAL(tc, sbuf, s);
+}
+
abts_suite *testfmt(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -129,6 +147,7 @@
abts_run_test(suite, uint64_t_fmt, NULL);
abts_run_test(suite, uint64_t_hex_fmt, NULL);
abts_run_test(suite, more_int64_fmts, NULL);
+ abts_run_test(suite, error_fmt, NULL);
return suite;
}
Re: svn commit: r233381 - in /apr/apr/trunk: CHANGES
include/apr_lib.h strings/apr_snprintf.c test/testfmt.c
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 07:59 PM 8/18/2005, William A. Rowe, Jr. wrote:
>My prime concern, that
>
>int foo
>
>foo = *APR_ARRAY_IDX(x,int) would be unsafe, proved to work
>just fine.
whoops, make that declaration long foo;.... and as it turns
out both mismatched type assignment and retrieval do work
sufficiently. Not ideal ;-) But sufficient :)
Bill
Re: svn commit: r233381 - in /apr/apr/trunk: CHANGES
include/apr_lib.h strings/apr_snprintf.c test/testfmt.c
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
At 01:25 AM 8/19/2005, Joe Orton wrote:
>One change, with two changes being documented in CHANGES since Garrett
>forgot earlier when he committed the other change.
Ack, I didn't dig deeply enough.
Thanks for keeping CHANGES in sync.
Bill
Re: svn commit: r233381 - in /apr/apr/trunk: CHANGES include/apr_lib.h strings/apr_snprintf.c test/testfmt.c
Posted by Joe Orton <jo...@redhat.com>.
On Thu, Aug 18, 2005 at 07:59:34PM -0500, William Rowe wrote:
> Joe - haven't you been the prime voice that you can only
> follow one change per commit? WTF is this?
One change, with two changes being documented in CHANGES since Garrett
forgot earlier when he committed the other change.
Re: svn commit: r233381 - in /apr/apr/trunk: CHANGES
include/apr_lib.h strings/apr_snprintf.c test/testfmt.c
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Joe - haven't you been the prime voice that you can only
follow one change per commit? WTF is this?
In any case, +1 to both. After consideration, this is as
typesafe as these will ever get. [not quite, but I'm too
exhausted from RL to provide examples of the obverse, and
only one function is affected.]
My prime concern, that
int foo
foo = *APR_ARRAY_IDX(x,int) would be unsafe, proved to work
just fine.
At 04:17 PM 8/18/2005, jorton@apache.org wrote:
>Author: jorton
>Date: Thu Aug 18 14:17:45 2005
>New Revision: 233381
>
>URL: http://svn.apache.org/viewcvs?rev=233381&view=rev
>Log:
>* strings/apr_snprintf.c (apr_vformatter): Add support for %pm to
>print the error string corresponding to an apr_status_t.
>
>* test/testfmt.c (error_fmt): New test.
>
>* include/apr_lib.h: Document %pm and note the versioning constraint.
>
>Modified:
> apr/apr/trunk/CHANGES
> apr/apr/trunk/include/apr_lib.h
> apr/apr/trunk/strings/apr_snprintf.c
> apr/apr/trunk/test/testfmt.c
>
>Modified: apr/apr/trunk/CHANGES
>URL: http://svn.apache.org/viewcvs/apr/apr/trunk/CHANGES?rev=233381&r1=233380&r2=233381&view=diff
>==============================================================================
>--- apr/apr/trunk/CHANGES (original)
>+++ apr/apr/trunk/CHANGES Thu Aug 18 14:17:45 2005
>@@ -1,3 +1,11 @@
>+Changes for APR 1.3.0
>+
>+ *) Add %pm support to apr_snprintf() for printing the error string
>+ corresponding to an apr_status_t value. [Joe Orton]
>+
>+ *) Add APR_ARRAY_IDX() and APR_ARRAY_PUSH() convenience macros to
>+ apr_tables.h. [Garrett Rooney]
>+
> Changes for APR 1.2.1
>
> *) Refactor Win32 condition variables code to address bugs 27654, 34336.
>
>Modified: apr/apr/trunk/include/apr_lib.h
>URL: http://svn.apache.org/viewcvs/apr/apr/trunk/include/apr_lib.h?rev=233381&r1=233380&r2=233381&view=diff
>==============================================================================
>--- apr/apr/trunk/include/apr_lib.h (original)
>+++ apr/apr/trunk/include/apr_lib.h Thu Aug 18 14:17:45 2005
>@@ -118,8 +118,13 @@
> * ('0' is printed if !APR_HAS_THREADS)
> * %%pt takes an apr_os_thread_t * and prints it in hexadecimal
> * ('0' is printed if !APR_HAS_THREADS)
>+ * %%pm takes an apr_status_t * and prints the appropriate error
>+ * string (from apr_strerror) corresponding to that error code.
> * %%pp takes a void * and outputs it in hex
> *
>+ * %%pt is only available from APR 1.2.0 onwards.
>+ * %%pm is only available from APR 1.3.0 onwards.
>+ *
> * The %%p hacks are to force gcc's printf warning code to skip
> * over a pointer argument without complaining. This does
> * mean that the ANSI-style %%p (output a void * in hex format) won't
>
>Modified: apr/apr/trunk/strings/apr_snprintf.c
>URL: http://svn.apache.org/viewcvs/apr/apr/trunk/strings/apr_snprintf.c?rev=233381&r1=233380&r2=233381&view=diff
>==============================================================================
>--- apr/apr/trunk/strings/apr_snprintf.c (original)
>+++ apr/apr/trunk/strings/apr_snprintf.c Thu Aug 18 14:17:45 2005
>@@ -21,6 +21,7 @@
> #include "apr_strings.h"
> #include "apr_network_io.h"
> #include "apr_portable.h"
>+#include "apr_errno.h"
> #include <math.h>
> #if APR_HAVE_CTYPE_H
> #include <ctype.h>
>@@ -1157,6 +1158,24 @@
> s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len);
> if (adjust_precision && precision < s_len)
> s_len = precision;
>+ }
>+ else {
>+ s = S_NULL;
>+ s_len = S_NULL_LEN;
>+ }
>+ pad_char = ' ';
>+ }
>+ break;
>+
>+ /* print the error for an apr_status_t */
>+ case 'm':
>+ {
>+ apr_status_t *mrv;
>+
>+ mrv = va_arg(ap, apr_status_t *);
>+ if (mrv != NULL) {
>+ s = apr_strerror(*mrv, num_buf, NUM_BUF_SIZE-1);
>+ s_len = strlen(s);
> }
> else {
> s = S_NULL;
>
>Modified: apr/apr/trunk/test/testfmt.c
>URL: http://svn.apache.org/viewcvs/apr/apr/trunk/test/testfmt.c?rev=233381&r1=233380&r2=233381&view=diff
>==============================================================================
>--- apr/apr/trunk/test/testfmt.c (original)
>+++ apr/apr/trunk/test/testfmt.c Thu Aug 18 14:17:45 2005
>@@ -117,6 +117,24 @@
> ABTS_STR_EQUAL(tc, buf, "-314159265358979323");
> }
>
>+static void error_fmt(abts_case *tc, void *data)
>+{
>+ char ebuf[150], sbuf[150], *s;
>+ apr_status_t rv;
>+
>+ rv = APR_SUCCESS;
>+ apr_strerror(rv, ebuf, sizeof ebuf);
>+ apr_snprintf(sbuf, sizeof sbuf, "%pm", &rv);
>+ ABTS_STR_EQUAL(tc, sbuf, ebuf);
>+
>+ rv = APR_ENOTIMPL;
>+ s = apr_pstrcat(p, "foo-",
>+ apr_strerror(rv, ebuf, sizeof ebuf),
>+ "-bar", NULL);
>+ apr_snprintf(sbuf, sizeof sbuf, "foo-%pm-bar", &rv);
>+ ABTS_STR_EQUAL(tc, sbuf, s);
>+}
>+
> abts_suite *testfmt(abts_suite *suite)
> {
> suite = ADD_SUITE(suite)
>@@ -129,6 +147,7 @@
> abts_run_test(suite, uint64_t_fmt, NULL);
> abts_run_test(suite, uint64_t_hex_fmt, NULL);
> abts_run_test(suite, more_int64_fmts, NULL);
>+ abts_run_test(suite, error_fmt, NULL);
>
> return suite;
> }