Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Apr 2006 01:32:41 GMT
From:      John Birrell <jb@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 95466 for review
Message-ID:  <200604180132.k3I1WfQw022660@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=95466

Change 95466 by jb@jb_freebsd2 on 2006/04/18 01:31:42

	I don't quite understand how this code can work in OpenSolaris!
	
	The copy function pointer passed to strtab_write is cast as returning a
	value when neither function actually does.
	
	I guess that gcc must be behaving differently to Sun's compiler which must
	just happen to be leaving the number of bytes copied on the stack or in a
	register where the calling function can pick it up from the place where the
	value would be returned if the function was actually coded to return a value.
	
	For this change, type define a function prototype and don't cast the 
	value passed so that the compiler can check that the prototype is correct.
	Because of the style of the code, the last argument passed to the function has
	to be cast. There is no way around that.
	
	This makes ctfmerge work in FreeBSD. Yippee.
	
	To the Sun engineers reading these messages: OK, you might not like my
	submit messages here, but this one really is about a bug. Please don't allow
	your distaste for my general code standards compliance comments to get in the
	way of you fixing this bug. Casting function pointers so that the compiler
	can't check them is a really BAD idea.

Affected files ...

.. //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/ctf.c#3 edit
.. //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/strtab.c#3 edit
.. //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/strtab.h#2 edit

Differences ...

==== //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/ctf.c#3 (text) ====

@@ -458,10 +458,11 @@
 		parseterminate("zlib start failed: %s", zError(rc));
 }
 
-static void
-compress_buffer(caddr_t buf, size_t n, resbuf_t *rb)
+static ssize_t
+compress_buffer(void *buf, size_t n, void *arg)
 {
 	int rc;
+	resbuf_t *rb = (resbuf_t *) arg;
 
 	rb->rb_zstr.next_out = (Bytef *)rb->rb_ptr;
 	rb->rb_zstr.avail_out = rb->rb_size - (rb->rb_ptr - rb->rb_base);
@@ -476,6 +477,7 @@
 			parseterminate("zlib deflate failed: %s", zError(rc));
 	}
 	rb->rb_ptr = (caddr_t)rb->rb_zstr.next_out;
+	return n;
 }
 
 static void
@@ -524,11 +526,13 @@
 	}
 }
 
-static void
-bcopy_data(void *buf, size_t n, caddr_t *posp)
+static ssize_t
+bcopy_data(void *buf, size_t n, void *arg)
 {
+	caddr_t *posp = (caddr_t *) arg;
 	bcopy(buf, *posp, n);
 	*posp += n;
+	return n;
 }
 
 static caddr_t
@@ -544,8 +548,8 @@
 	bcopy_data(h, sizeof (ctf_header_t), &bufpos);
 	bcopy_data(buf->ctb_base, buf->ctb_ptr - buf->ctb_base,
 	    &bufpos);
-	if (strtab_write(&buf->ctb_strtab, (ssize_t (*)())bcopy_data,
-	    &bufpos) < 0)
+	if (strtab_write(&buf->ctb_strtab, bcopy_data,
+	    (void *) &bufpos) < 0)
 		terminate("strtab_write failed\n");
 	*resszp = bufpos - outbuf;
 	return (outbuf);
@@ -569,8 +573,8 @@
 	compress_start(&resbuf);
 	compress_buffer(buf->ctb_base, buf->ctb_ptr - buf->ctb_base, &resbuf);
 	compress_flush(&resbuf, Z_FULL_FLUSH);
-	if (strtab_write(&buf->ctb_strtab, (ssize_t (*)())compress_buffer,
-	    &resbuf) < 0)
+	if (strtab_write(&buf->ctb_strtab, compress_buffer,
+	    (void *) &resbuf) < 0)
 		terminate("strtab_write failed\n");
 	compress_end(&resbuf);
 

==== //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/strtab.c#3 (text) ====

@@ -210,7 +210,7 @@
 
 ssize_t
 strtab_write(const strtab_t *sp,
-    ssize_t (*func)(const void *, size_t, void *), void *priv)
+    STRTAB_COPY_FUNC func, void *priv)
 {
 	ssize_t res, total = 0;
 	ulong_t i;

==== //depot/projects/dtrace/src/contrib/opensolaris/tools/ctf/cvt/strtab.h#2 (text) ====

@@ -54,12 +54,14 @@
 	size_t str_size;		/* total size of strings in bytes */
 } strtab_t;
 
+typedef ssize_t STRTAB_COPY_FUNC(void *, size_t, void *);
+
 extern void strtab_create(strtab_t *);
 extern void strtab_destroy(strtab_t *);
 extern size_t strtab_insert(strtab_t *, const char *);
 extern size_t strtab_size(const strtab_t *);
 extern ssize_t strtab_write(const strtab_t *,
-    ssize_t (*)(const void *, size_t, void *), void *);
+    STRTAB_COPY_FUNC, void *);
 extern void strtab_print(const strtab_t *);
 
 #ifdef	__cplusplus



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604180132.k3I1WfQw022660>