changeset 195:db6e288be0e9 HEAD

Replaced INT_TO_POINTER and POINTER_TO_INT macros with POINTER_CAST and POINTER_CAST_TO macros, the CAST_TO takes a parameter to which type we're casting to. Also POINTER_CAST should be valid ANSI-C now.
author Timo Sirainen <tss@iki.fi>
date Sun, 08 Sep 2002 18:34:27 +0300
parents d82e7d23a28d
children 95d21ab87eeb
files src/lib-index/mail-index-util.c src/lib-storage/index/index-msgcache.c src/lib/hash.c src/lib/macros.h src/login/auth-connection.c src/login/ssl-proxy.c src/master/common.h src/master/login-process.c
diffstat 8 files changed, 21 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-util.c	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/lib-index/mail-index-util.c	Sun Sep 08 18:34:27 2002 +0300
@@ -67,7 +67,7 @@
 	MessageSize hdr_size, body_size;
 	IOBuffer *inbuf;
 	const void *part_data;
-	unsigned int size;
+	size_t size;
 
 	if ((rec->index_flags & INDEX_MAIL_FLAG_BINARY_HEADER) &&
 	    (rec->index_flags & INDEX_MAIL_FLAG_BINARY_BODY)) {
--- a/src/lib-storage/index/index-msgcache.c	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/lib-storage/index/index-msgcache.c	Sun Sep 08 18:34:27 2002 +0300
@@ -73,7 +73,7 @@
 	IndexMsgcacheContext *ctx = context;
 	MessagePart *part;
 	const void *part_data;
-	unsigned int part_size;
+	size_t part_size;
 
 	part_data = ctx->index->lookup_field_raw(ctx->index, ctx->rec,
 						 FIELD_TYPE_MESSAGEPART,
--- a/src/lib/hash.c	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/lib/hash.c	Sun Sep 08 18:34:27 2002 +0300
@@ -63,7 +63,7 @@
 static unsigned int direct_hash(const void *p)
 {
 	/* NOTE: may truncate the value, but that doesn't matter. */
-	return POINTER_TO_UINT(p);
+	return POINTER_CAST_TO(p, unsigned int);
 }
 
 static HashNode *hash_node_create(Pool pool, const void *key,
--- a/src/lib/macros.h	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/lib/macros.h	Sun Sep 08 18:34:27 2002 +0300
@@ -32,11 +32,13 @@
 #undef NVL
 #define NVL(str, nullstr) ((str) != NULL ? (str) : (nullstr))
 
-#define POINTER_TO_INT(p)	((int) (p))
-#define POINTER_TO_UINT(p)	((unsigned int) ((char *) p - (char *) NULL))
-
-#define INT_TO_POINTER(i)	((void *) (size_t) (i))
-#define UINT_TO_POINTER(u)	((void *) (size_t) (u))
+/* make it easier to cast from/to pointers. assumes that
+   sizeof(size_t) == sizeof(void *) and they're both the largest datatypes
+   that are allowed to be used. so, long long isn't safe with these. */
+#define POINTER_CAST(i) \
+	((void *) ((char *) NULL + (i)))
+#define POINTER_CAST_TO(p, type) \
+	((type) ((char *) (p) - (char *) NULL))
 
 /* Define VA_COPY() to do the right thing for copying va_list variables. */
 #ifndef VA_COPY
--- a/src/login/auth-connection.c	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/login/auth-connection.c	Sun Sep 08 18:34:27 2002 +0300
@@ -83,7 +83,7 @@
 
 static void request_destroy(AuthRequest *request)
 {
-	hash_remove(request->conn->requests, INT_TO_POINTER(request->id));
+	hash_remove(request->conn->requests, POINTER_CAST(request->id));
 	i_free(request);
 }
 
@@ -177,7 +177,7 @@
 {
 	AuthRequest *request;
 
-	request = hash_lookup(conn->requests, INT_TO_POINTER(reply_data->id));
+	request = hash_lookup(conn->requests, POINTER_CAST(reply_data->id));
 	if (request == NULL) {
 		i_error("BUG: imap-auth sent us reply with unknown ID %u",
 			reply_data->id);
@@ -230,8 +230,8 @@
 			auth_handle_init(conn, &init_data);
 		} else if (size > sizeof(AuthInitData)) {
 			i_error("BUG: imap-auth sent us too much "
-				"initialization data (%u vs %u)",
-				size, sizeof(AuthInitData));
+				"initialization data (%"PRIuSIZE_T " vs %"
+				PRIuSIZE_T")", size, sizeof(AuthInitData));
 			auth_connection_destroy(conn);
 		}
 
@@ -281,7 +281,7 @@
 	request->callback = callback;
 	request->context = context;
 
-	hash_insert(conn->requests, INT_TO_POINTER(request->id), request);
+	hash_insert(conn->requests, POINTER_CAST(request->id), request);
 
 	/* send request to auth */
 	request_data.type = AUTH_REQUEST_INIT;
--- a/src/login/ssl-proxy.c	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/login/ssl-proxy.c	Sun Sep 08 18:34:27 2002 +0300
@@ -380,7 +380,7 @@
 
 /* no SSL support */
 
-int ssl_proxy_new(int fd) { return -1; }
+int ssl_proxy_new(int fd __attr_unused__) { return -1; }
 void ssl_proxy_init(void) {}
 void ssl_proxy_deinit(void) {}
 
--- a/src/master/common.h	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/master/common.h	Sun Sep 08 18:34:27 2002 +0300
@@ -24,13 +24,13 @@
 
 /* processes */
 #define PID_GET_PROCESS_TYPE(pid) \
-	POINTER_TO_INT(hash_lookup(pids, INT_TO_POINTER(pid)))
+	POINTER_CAST_TO(hash_lookup(pids, POINTER_CAST(pid)), pid_t)
 
 #define PID_ADD_PROCESS_TYPE(pid, type) \
-	hash_insert(pids, INT_TO_POINTER(pid), INT_TO_POINTER(type))
+	hash_insert(pids, POINTER_CAST(pid), POINTER_CAST(type))
 
 #define PID_REMOVE_PROCESS_TYPE(pid) \
-	hash_remove(pids, INT_TO_POINTER(pid))
+	hash_remove(pids, POINTER_CAST(pid))
 
 void clean_child_process(void);
 
--- a/src/master/login-process.c	Sun Sep 08 18:22:45 2002 +0300
+++ b/src/master/login-process.c	Sun Sep 08 18:34:27 2002 +0300
@@ -142,7 +142,7 @@
 	p->outbuf = io_buffer_create(fd, default_pool, IO_PRIORITY_DEFAULT,
 				     sizeof(MasterReply)*10);
 
-	hash_insert(processes, INT_TO_POINTER(pid), p);
+	hash_insert(processes, POINTER_CAST(pid), p);
 	return p;
 }
 
@@ -156,7 +156,7 @@
 	io_remove(p->io);
 	(void)close(p->fd);
 
-	hash_remove(processes, INT_TO_POINTER(p->pid));
+	hash_remove(processes, POINTER_CAST(p->pid));
 	login_process_unref(p);
 }