stas 02/03/05 21:30:27
Modified: xs/APR/PerlIO apr_perlio.c apr_perlio.h
Log:
- convert the int APR_PERLIO_HOOK hooks into enums: benefit from
compile-time checks
- now can get rid of default: cases using these hooks
- rewrite the eof() switch to deploy the default case, which was empty and
causing warnings under gcc3.
<<thanks to doug and gozer!>>
Revision Changes Path
1.11 +12 -26 modperl-2.0/xs/APR/PerlIO/apr_perlio.c
Index: apr_perlio.c
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- apr_perlio.c 8 Jan 2002 01:09:19 -0000 1.10
+++ apr_perlio.c 6 Mar 2002 05:30:27 -0000 1.11
@@ -304,11 +304,10 @@
rc = apr_file_eof(st->file);
switch (rc) {
- case APR_SUCCESS:
- return 0;
case APR_EOF:
return 1;
default:
+ return 0;
}
return -1;
@@ -357,8 +356,8 @@
/* ***** PerlIO <=> apr_file_t helper functions ***** */
-PerlIO *apr_perlio_apr_file_to_PerlIO(pTHX_ apr_file_t *file,
- apr_pool_t *pool, int type)
+PerlIO *apr_perlio_apr_file_to_PerlIO(pTHX_ apr_file_t *file, apr_pool_t *pool,
+ apr_perlio_hook_e type)
{
char *mode;
const char *layers = ":APR";
@@ -374,8 +373,6 @@
case APR_PERLIO_HOOK_READ:
mode = "r";
break;
- default:
- /* */
};
PerlIO_apply_layers(aTHX_ f, mode, layers);
@@ -394,10 +391,7 @@
return NULL;
}
-/*
- * type: APR_PERLIO_HOOK_READ | APR_PERLIO_HOOK_WRITE
- */
-static SV *apr_perlio_PerlIO_to_glob(pTHX_ PerlIO *pio, int type)
+static SV *apr_perlio_PerlIO_to_glob(pTHX_ PerlIO *pio, apr_perlio_hook_e type)
{
/* XXX: modperl_perl_gensym() cannot be used outside of httpd */
SV *retval = modperl_perl_gensym(aTHX_ "APR::PerlIO");
@@ -413,24 +407,24 @@
case APR_PERLIO_HOOK_READ:
IoIFP(GvIOp(gv)) = pio;
break;
- default:
- /* */
};
return sv_2mortal(retval);
}
-SV *apr_perlio_apr_file_to_glob(pTHX_ apr_file_t *file,
- apr_pool_t *pool, int type)
+SV *apr_perlio_apr_file_to_glob(pTHX_ apr_file_t *file, apr_pool_t *pool,
+ apr_perlio_hook_e type)
{
return apr_perlio_PerlIO_to_glob(aTHX_
- apr_perlio_apr_file_to_PerlIO(aTHX_ file,
pool, type),
+ apr_perlio_apr_file_to_PerlIO(aTHX_ file,
+ pool, type),
type);
}
#elif !defined(PERLIO_LAYERS) && !defined(WIN32) /* NOT PERLIO_LAYERS (5.6.1) */
-static FILE *apr_perlio_apr_file_to_FILE(pTHX_ apr_file_t *file, int type)
+static FILE *apr_perlio_apr_file_to_FILE(pTHX_ apr_file_t *file,
+ apr_perlio_hook_e type)
{
FILE *retval;
char *mode;
@@ -445,8 +439,6 @@
case APR_PERLIO_HOOK_READ:
mode = "r";
break;
- default:
- /* */
};
/* convert to the OS representation of file */
@@ -466,12 +458,8 @@
return retval;
}
-/*
- *
- * type: APR_PERLIO_HOOK_READ | APR_PERLIO_HOOK_WRITE
- */
-SV *apr_perlio_apr_file_to_glob(pTHX_ apr_file_t *file,
- apr_pool_t *pool, int type)
+SV *apr_perlio_apr_file_to_glob(pTHX_ apr_file_t *file, apr_pool_t *pool,
+ apr_perlio_hook_e type)
{
/* XXX: modperl_perl_gensym() cannot be used outside of httpd */
SV *retval = modperl_perl_gensym(aTHX_ "APR::PerlIO");
@@ -487,8 +475,6 @@
case APR_PERLIO_HOOK_READ:
IoIFP(GvIOp(gv)) = apr_perlio_apr_file_to_FILE(aTHX_ file, type);
break;
- default:
- /* */
};
return sv_2mortal(retval);
1.2 +12 -8 modperl-2.0/xs/APR/PerlIO/apr_perlio.h
Index: apr_perlio.h
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/APR/PerlIO/apr_perlio.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- apr_perlio.h 17 Dec 2001 16:20:27 -0000 1.1
+++ apr_perlio.h 6 Mar 2002 05:30:27 -0000 1.2
@@ -14,8 +14,10 @@
#include "apr_optional.h"
#endif
-#define APR_PERLIO_HOOK_READ 0
-#define APR_PERLIO_HOOK_WRITE 1
+typedef enum {
+ APR_PERLIO_HOOK_READ,
+ APR_PERLIO_HOOK_WRITE
+} apr_perlio_hook_e;
void apr_perlio_init(pTHX);
@@ -25,19 +27,21 @@
#ifndef MP_SOURCE_SCAN
#ifdef PERLIO_LAYERS
-PerlIO *apr_perlio_apr_file_to_PerlIO(pTHX_ apr_file_t *file,
- apr_pool_t *pool, int type);
+PerlIO *apr_perlio_apr_file_to_PerlIO(pTHX_ apr_file_t *file, apr_pool_t *pool,
+ apr_perlio_hook_e type);
APR_DECLARE_OPTIONAL_FN(PerlIO *,
apr_perlio_apr_file_to_PerlIO,
- (pTHX_ apr_file_t *file, apr_pool_t *pool, int type));
+ (pTHX_ apr_file_t *file, apr_pool_t *pool,
+ apr_perlio_hook_e type));
#endif /* PERLIO_LAYERS */
-SV *apr_perlio_apr_file_to_glob(pTHX_ apr_file_t *file,
- apr_pool_t *pool, int type);
+SV *apr_perlio_apr_file_to_glob(pTHX_ apr_file_t *file, apr_pool_t *pool,
+ apr_perlio_hook_e type);
APR_DECLARE_OPTIONAL_FN(SV *,
apr_perlio_apr_file_to_glob,
- (pTHX_ apr_file_t *file, apr_pool_t *pool, int type));
+ (pTHX_ apr_file_t *file, apr_pool_t *pool,
+ apr_perlio_hook_e type));
#endif /* MP_SOURCE_SCAN */
#endif /* APR_PERLIO_H */