Permalink
Browse files

Step 10: wrap a 2-way global.

  • Loading branch information...
Ben Laurie
Ben Laurie committed Apr 28, 2012
1 parent 33c12a2 commit 81b0c3c00d0a7111dd282428b314aaa8de5cefa2
Showing with 19 additions and 2 deletions.
  1. +7 −0 contrib/bzip2/CONVERSION
  2. +11 −2 contrib/bzip2/bzip2_wrapped.c
  3. +1 −0 contrib/bzip2/bzip2_wrapped.h
View
@@ -79,3 +79,10 @@
applySavedFileAttrToOutputFile(), which would have automatically
dealt with the rest of bzip2_wrapped.c, since it is static and so
would not be available in bzip2.c.
10. The next problem is interesting - a global that is changed in the
child, outputHandleJustInCase. This could have been awkward, since
it is a FILE *, and we can't directly pass a FILE * over a pipe,
but luckily the child never does anything but set it to NULL. So
invent a new wrapped function that does this. Note that once more
we leave dangling ends to be dealt with later.
@@ -13,6 +13,15 @@ static void invoke_applySavedFileAttrToOutputFile(int fd) {
lc_send_to_parent("void", "applySavedFileAttrToOutputFile", "int", fd);
}
static void invoke_clear_outputHandleJustInCase(void) {
if (!lc_is_wrapped()) {
wrapped_clear_outputHandleJustInCase();
return;
}
lc_send_to_parent("void", "clear_outputHandleJustInCase", "void");
}
/*---------------------------------------------------*/
/*--- An implementation of 64-bit ints. Sigh. ---*/
/*--- Roll on widespread deployment of ANSI C9X ! ---*/
@@ -159,10 +168,10 @@ void wrapped_compressStream ( FILE *stream, FILE *zStream )
if (fd < 0) goto errhandler_io;
invoke_applySavedFileAttrToOutputFile ( fd );
ret = fclose ( zStream );
outputHandleJustInCase = NULL;
invoke_clear_outputHandleJustInCase();
if (ret == EOF) goto errhandler_io;
}
outputHandleJustInCase = NULL;
invoke_clear_outputHandleJustInCase();
if (ferror(stream)) goto errhandler_io;
ret = fclose ( stream );
if (ret == EOF) goto errhandler_io;
@@ -21,6 +21,7 @@ Bool wrapped_testStream ( FILE *zStream );
/* in the parent */
void wrapped_applySavedFileAttrToOutputFile ( IntNative fd );
void wrapped_clear_outputHandleJustInCase( void );
/* in both */
extern Int32 _blockSize100k;

0 comments on commit 81b0c3c

Please sign in to comment.