The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
diff --git a/bzlib.c b/bzlib.c
index bd358a7..68cab7e 100644
--- a/bzlib.c
+++ b/bzlib.c
@@ -98,19 +98,29 @@ int bz_config_ok ( void )
 
 
 /*---------------------------------------------------*/
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
 static
 void* default_bzalloc ( void* opaque, Int32 items, Int32 size )
 {
    void* v = malloc ( items * size );
+   (void)opaque;
    return v;
 }
 
 static
 void default_bzfree ( void* opaque, void* addr )
 {
+   (void)opaque;
    if (addr != NULL) free ( addr );
 }
 
+#ifdef __cplusplus
+}
+#endif
 
 /*---------------------------------------------------*/
 static
@@ -165,7 +175,7 @@ int BZ_API(BZ2_bzCompressInit)
    if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
    if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
 
-   s = BZALLOC( sizeof(EState) );
+   s = (EState*) BZALLOC( sizeof(EState) );
    if (s == NULL) return BZ_MEM_ERROR;
    s->strm = strm;
 
@@ -174,9 +184,9 @@ int BZ_API(BZ2_bzCompressInit)
    s->ftab = NULL;
 
    n       = 100000 * blockSize100k;
-   s->arr1 = BZALLOC( n                  * sizeof(UInt32) );
-   s->arr2 = BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
-   s->ftab = BZALLOC( 65537              * sizeof(UInt32) );
+   s->arr1 = (UInt32*) BZALLOC( n                  * sizeof(UInt32) );
+   s->arr2 = (UInt32*) BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
+   s->ftab = (UInt32*) BZALLOC( 65537              * sizeof(UInt32) );
 
    if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) {
       if (s->arr1 != NULL) BZFREE(s->arr1);
@@ -362,7 +372,7 @@ Bool handle_compress ( bz_stream* strm )
 {
    Bool progress_in  = False;
    Bool progress_out = False;
-   EState* s = strm->state;
+   EState* s = (EState*) strm->state;
    
    while (True) {
 
@@ -409,7 +419,7 @@ int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action )
    Bool progress;
    EState* s;
    if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
+   s = (EState*) strm->state;
    if (s == NULL) return BZ_PARAM_ERROR;
    if (s->strm != strm) return BZ_PARAM_ERROR;
 
@@ -469,7 +479,7 @@ int BZ_API(BZ2_bzCompressEnd)  ( bz_stream *strm )
 {
    EState* s;
    if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
+   s = (EState*) strm->state;
    if (s == NULL) return BZ_PARAM_ERROR;
    if (s->strm != strm) return BZ_PARAM_ERROR;
 
@@ -505,7 +515,7 @@ int BZ_API(BZ2_bzDecompressInit)
    if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
    if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
 
-   s = BZALLOC( sizeof(DState) );
+   s = (DState*) BZALLOC( sizeof(DState) );
    if (s == NULL) return BZ_MEM_ERROR;
    s->strm                  = strm;
    strm->state              = s;
@@ -684,7 +694,10 @@ Bool unRLE_obuf_to_output_FAST ( DState* s )
 
 
 /*---------------------------------------------------*/
-__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
+#ifndef __cplusplus
+__inline__
+#endif
+Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab )
 {
    Int32 nb, na, mid;
    nb = 0;
@@ -810,7 +823,7 @@ int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
    Bool    corrupt;
    DState* s;
    if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
+   s = (DState*) strm->state;
    if (s == NULL) return BZ_PARAM_ERROR;
    if (s->strm != strm) return BZ_PARAM_ERROR;
 
@@ -863,7 +876,7 @@ int BZ_API(BZ2_bzDecompressEnd)  ( bz_stream *strm )
 {
    DState* s;
    if (strm == NULL) return BZ_PARAM_ERROR;
-   s = strm->state;
+   s = (DState*) strm->state;
    if (s == NULL) return BZ_PARAM_ERROR;
    if (s->strm != strm) return BZ_PARAM_ERROR;
 
@@ -934,7 +947,7 @@ BZFILE* BZ_API(BZ2_bzWriteOpen)
    if (ferror(f))
       { BZ_SETERR(BZ_IO_ERROR); return NULL; };
 
-   bzf = malloc ( sizeof(bzFile) );
+   bzf = (bzFile*) malloc ( sizeof(bzFile) );
    if (bzf == NULL)
       { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
 
@@ -982,7 +995,7 @@ void BZ_API(BZ2_bzWrite)
       { BZ_SETERR(BZ_OK); return; };
 
    bzf->strm.avail_in = len;
-   bzf->strm.next_in  = buf;
+   bzf->strm.next_in  = (char*)buf;
 
    while (True) {
       bzf->strm.avail_out = BZ_MAX_UNUSED;
@@ -1107,7 +1120,7 @@ BZFILE* BZ_API(BZ2_bzReadOpen)
    if (ferror(f))
       { BZ_SETERR(BZ_IO_ERROR); return NULL; };
 
-   bzf = malloc ( sizeof(bzFile) );
+   bzf = (bzFile*) malloc ( sizeof(bzFile) );
    if (bzf == NULL) 
       { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
 
@@ -1179,7 +1192,7 @@ int BZ_API(BZ2_bzRead)
       { BZ_SETERR(BZ_OK); return 0; };
 
    bzf->strm.avail_out = len;
-   bzf->strm.next_out = buf;
+   bzf->strm.next_out = (char*) buf;
 
    while (True) {
 
diff --git a/compress.c b/compress.c
index caf7696..522e06a 100644
--- a/compress.c
+++ b/compress.c
@@ -593,6 +593,8 @@ void sendMTFValues ( EState* s )
    }
    AssertH( selCtr == nSelectors, 3007 );
 
+   (void)nBytes; /* only set, not used */
+
    if (s->verbosity >= 3)
       VPrintf1( "codes %d\n", s->numZ-nBytes );
 }
diff --git a/decompress.c b/decompress.c
index 311f566..5441735 100644
--- a/decompress.c
+++ b/decompress.c
@@ -209,13 +209,13 @@ Int32 BZ2_decompress ( DState* s )
       s->blockSize100k -= BZ_HDR_0;
 
       if (s->smallDecompress) {
-         s->ll16 = BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
-         s->ll4  = BZALLOC( 
+         s->ll16 = (UInt16*) BZALLOC( s->blockSize100k * 100000 * sizeof(UInt16) );
+         s->ll4  = (UChar*) BZALLOC( 
                       ((1 + s->blockSize100k * 100000) >> 1) * sizeof(UChar) 
                    );
          if (s->ll16 == NULL || s->ll4 == NULL) RETURN(BZ_MEM_ERROR);
       } else {
-         s->tt  = BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
+         s->tt  = (UInt32*) BZALLOC( s->blockSize100k * 100000 * sizeof(Int32) );
          if (s->tt == NULL) RETURN(BZ_MEM_ERROR);
       }