Skip to content
Browse files

Step 9: wrap a function in the parent.

  • Loading branch information...
1 parent 098d103 commit 33c12a242c84f68dfd54fd25234ebe2fd67d7ee1 Ben Laurie committed Apr 28, 2012
Showing with 35 additions and 9 deletions.
  1. +12 −0 contrib/bzip2/CONVERSION
  2. +0 −8 contrib/bzip2/bzip2.c
  3. +12 −1 contrib/bzip2/bzip2_wrapped.c
  4. +11 −0 contrib/bzip2/bzip2_wrapped.h
View
12 contrib/bzip2/CONVERSION
@@ -67,3 +67,15 @@
are incorrect.
8. Continue in this vein until we hit a new problem.
+
+9. Now we need to invoke the function we wrapped in step 3. Note that
+ there are some dangling ends left - for example,
+ applySavedFileAttrToOutputFile() needs to be renamed in bzip2.c but
+ hasn't been yet. No matter: compile errors will point that out to
+ us later.
+
+ Note that we could have instead named
+ invoke_applySavedFileAttrToOutputFile() as
+ 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.
View
8 contrib/bzip2/bzip2.c
@@ -163,13 +163,6 @@ typedef char Char;
typedef short Int16;
typedef unsigned short UInt16;
-/*--
- IntNative is your platform's `native' int size.
- Only here to avoid probs with 64-bit platforms.
---*/
-typedef int IntNative;
-
-
/*---------------------------------------------------*/
/*--- Misc (file handling) data decls ---*/
/*---------------------------------------------------*/
@@ -221,7 +214,6 @@ static void compressedStreamEOF ( void ) NORETURN;
static void copyFileName ( Char*, Char* );
static void* myMalloc ( Int32 );
-static void applySavedFileAttrToOutputFile ( IntNative fd );
static void unwrap_applySavedFileAttrToOutputFile(int fd);
static int output_fd;
View
13 contrib/bzip2/bzip2_wrapped.c
@@ -1,6 +1,17 @@
#include <stdio.h>
#include "bzlib.h"
#include "bzip2_wrapped.h"
+#include "capsicum.h"
+
+/* Invocations in the parent */
+
+static void invoke_applySavedFileAttrToOutputFile(int fd) {
+ if (!lc_is_wrapped()) {
+ wrapped_applySavedFileAttrToOutputFile(fd);
+ return;
+ }
+ lc_send_to_parent("void", "applySavedFileAttrToOutputFile", "int", fd);
+}
/*---------------------------------------------------*/
/*--- An implementation of 64-bit ints. Sigh. ---*/
@@ -146,7 +157,7 @@ void wrapped_compressStream ( FILE *stream, FILE *zStream )
if (zStream != stdout) {
Int32 fd = fileno ( zStream );
if (fd < 0) goto errhandler_io;
- applySavedFileAttrToOutputFile ( fd );
+ invoke_applySavedFileAttrToOutputFile ( fd );
ret = fclose ( zStream );
outputHandleJustInCase = NULL;
if (ret == EOF) goto errhandler_io;
View
11 contrib/bzip2/bzip2_wrapped.h
@@ -3,15 +3,26 @@ typedef unsigned char UChar;
typedef int Int32;
typedef unsigned int UInt32;
+/*--
+ IntNative is your platform's `native' int size.
+ Only here to avoid probs with 64-bit platforms.
+--*/
+typedef int IntNative;
+
#define True ((Bool)1)
#define False ((Bool)0)
#define SET_BINARY_MODE(fd) /**/
+/* in the child */
void wrapped_compressStream ( FILE *stream, FILE *zStream );
Bool wrapped_uncompressStream ( FILE *zStream, FILE *stream );
Bool wrapped_testStream ( FILE *zStream );
+/* in the parent */
+void wrapped_applySavedFileAttrToOutputFile ( IntNative fd );
+
+/* in both */
extern Int32 _blockSize100k;
#define blockSize100k (*(const Int32 *)&_blockSize100k)
extern Int32 _verbosity;

0 comments on commit 33c12a2

Please sign in to comment.
Something went wrong with that request. Please try again.