Browse files

Step 7: wrap a global.

  • Loading branch information...
Ben Laurie
Ben Laurie committed Apr 28, 2012
1 parent 493fbb4 commit 95166e7e820fa96b7c7bc322487db534bbe62731
Showing with 23 additions and 0 deletions.
  1. +16 −0 contrib/bzip2/CONVERSION
  2. +4 −0 contrib/bzip2/bzip2.c
  3. +3 −0 contrib/bzip2/bzip2_wrapped.h
@@ -50,3 +50,19 @@
6. Fix the build to include the other files. Fix stupid mistakes. Move
definitions that need to be shared (and can be safely!).
7. Now we hit an interesting case:
"bzip2_wrapped.c:123: error: 'blockSize100k' undeclared (first use
in this function)"
blockSize100k is a global. Globals are, of course, potential
communication channels between the wrapped code and its parent. If
we're lucky, the communication is one way, from parent to child, as
it is in this case, and so we can simply make them const in the
wrapped functions. They will have the right values in the wrapped
function, because we have changed the call to a fork(). We use a
trick to make the compiler enforce this property. Note that we can
just assume this is so, and compiler errors will inform us if we
are incorrect.
@@ -174,12 +174,16 @@ typedef int IntNative;
/*--- Misc (file handling) data decls ---*/
#undef blockSize100k
#define blockSize100k _blockSize100k
Int32 verbosity;
Bool keepInputFiles, smallMode, deleteOutputOnInterrupt;
Bool forceOverwrite, testFailsExist, unzFailsExist, noisy;
Int32 numFileNames, numFilesProcessed, blockSize100k;
Int32 exitValue;
/*-- source modes; F==file, I==stdin, O==stdout --*/
#define SM_I2O 1
#define SM_F2O 2
@@ -12,3 +12,6 @@ void wrapped_compressStream ( FILE *stream, FILE *zStream );
Bool wrapped_uncompressStream ( FILE *zStream, FILE *stream );
Bool wrapped_testStream ( FILE *zStream );
extern Int32 _blockSize100k;
#define blockSize100k (*(const Int32 *)&_blockSize100k)

0 comments on commit 95166e7

Please sign in to comment.