Permalink
Browse files

Step 13: define unwrappers.

  • Loading branch information...
Ben Laurie
Ben Laurie committed Apr 28, 2012
1 parent df12033 commit 5c5ef33fa97e678a89bb9777e9e7695574d72706
Showing with 69 additions and 6 deletions.
  1. +6 −0 contrib/bzip2/CONVERSION
  2. +60 −4 contrib/bzip2/bzip2.c
  3. +1 −1 contrib/bzip2/capsicum.c
  4. +2 −1 contrib/bzip2/capsicum.h
View
@@ -101,3 +101,9 @@
we wrapped earlier. Luckily, there's a list in bzip2_wrapped.h, so
we'll just haul those in and get back on track with errors. Note
that the unwrap functions just take a file descriptor.
13. Define the unwrappers. Note that you have to remember to add them
to caps[] and adjust the calls where it is used. Again, an IDL
would fix this.
Now we're done.
View
@@ -206,6 +206,12 @@ void wrapped_clear_outputHandleJustInCase(void) {
outputHandleJustInCase = NULL;
}
static
void unwrap_clear_outputHandleJustInCase ( int fd ) {
wrapped_clear_outputHandleJustInCase();
lc_write_void(fd);
}
#undef workFactor
#define workFactor _workFactor
Int32 workFactor;
@@ -225,9 +231,18 @@ static void unwrap_compressedStreamEOF ( int fd ) NORETURN;
static int output_fd;
#define CAP(x) { #x, unwrap_##x }
static struct lc_capability caps[] = {
{ "applySavedFileAttrToOutputFile", unwrap_applySavedFileAttrToOutputFile },
CAP(applySavedFileAttrToOutputFile),
CAP(clear_outputHandleJustInCase),
CAP(configError),
CAP(outOfMemory),
CAP(ioError),
CAP(panic),
CAP(crcError),
CAP(compressedStreamEOF),
};
#undef CAP
// This is only needed to get the function types to match for
// lc_wrap_filter().
@@ -243,7 +258,8 @@ static void compressStream(FILE *stream, FILE *zStream) {
}
output_fd = fileno(zStream);
lc_wrap_filter(call_compressStream, stream, zStream, caps, 1);
// FIXME: this only needs a subset of caps
lc_wrap_filter(call_compressStream, stream, zStream, caps, 8);
}
static int call_uncompressStream(FILE *zStream, FILE *stream) {
@@ -255,7 +271,7 @@ static Bool uncompressStream(FILE *zStream, FILE *stream) {
return wrapped_uncompressStream(zStream, stream);
output_fd = fileno(stream);
return lc_wrap_filter(call_uncompressStream, zStream, stream, caps, 1);
return lc_wrap_filter(call_uncompressStream, zStream, stream, caps, 8);
}
static int call_testStream(FILE *zStream, FILE *dummy) {
@@ -266,7 +282,8 @@ static Bool testStream(FILE *zStream) {
if (!lc_available())
return wrapped_testStream(zStream);
return lc_wrap_filter(call_testStream, zStream, NULL, NULL, 0);
// FIXME: this only needs a subset of caps
return lc_wrap_filter(call_testStream, zStream, NULL, caps, 8);
}
/*---------------------------------------------------*/
@@ -381,6 +398,17 @@ void wrapped_panic ( const Char* s )
cleanUpAndFail( 3 );
}
static
void unwrap_panic ( int fd ) {
int wrapped_errno;
char *str;
lc_read_int( fd, &wrapped_errno );
lc_read_string( fd, &str, 1024 );
wrapped_panic( str );
/* NOTREACHED */
}
/*---------------------------------------------*/
void wrapped_crcError ( void )
@@ -393,6 +421,13 @@ void wrapped_crcError ( void )
cleanUpAndFail( 2 );
}
static
void unwrap_crcError ( int fd ) {
wrapped_crcError();
/* NOTREACHED */
}
/*---------------------------------------------*/
void wrapped_compressedStreamEOF ( void )
@@ -409,6 +444,11 @@ void wrapped_compressedStreamEOF ( void )
cleanUpAndFail( 2 );
}
static
void unwrap_compressedStreamEOF ( int fd ) {
wrapped_crcError();
/* NOTREACHED */
}
/*---------------------------------------------*/
void wrapped_ioError ( void )
@@ -422,6 +462,12 @@ void wrapped_ioError ( void )
cleanUpAndFail( 1 );
}
static
void unwrap_ioError ( int fd ) {
wrapped_ioError();
/* NOTREACHED */
}
/*---------------------------------------------*/
static
@@ -500,6 +546,11 @@ void wrapped_outOfMemory ( void )
cleanUpAndFail(1);
}
static
void unwrap_outOfMemory ( int fd ) {
wrapped_outOfMemory();
/* NOTREACHED */
}
/*---------------------------------------------*/
void wrapped_configError ( void )
@@ -514,6 +565,11 @@ void wrapped_configError ( void )
exit(exitValue);
}
static
void unwrap_configError ( int fd ) {
wrapped_configError();
/* NOTREACHED */
}
/*---------------------------------------------------*/
/*--- The main driver machinery ---*/
View
@@ -114,7 +114,7 @@ static size_t lc_full_read(int fd, void *buffer, size_t count) {
return n;
}
static int lc_read_string(int fd, char **result, uint32_t max) {
int lc_read_string(int fd, char **result, uint32_t max) {
uint32_t size;
// FIXME: check for errors
View
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <sys/types.h>
int lc_available(void);
@@ -17,4 +18,4 @@ int lc_wrap_filter(int (*func)(FILE *in, FILE *out), FILE *in, FILE *out,
void lc_write_void(int fd);
int lc_read_int(int fd, int *result);
int lc_read_string(int fd, char **result, uint32_t max);

0 comments on commit 5c5ef33

Please sign in to comment.