On Sun, 2009-04-19 at 22:16 -0500, Dick Hollenbeck wrote:
[snip]
> -int ft2232_read(u8* buf, int size, u32* bytes_read)
> +int ft2232_read(u8* buf, u32 size, u32* bytes_read)
> 
> 
> I would simply make that
> 
> int ft2232_read(u8* buf, unsigned size, u32* bytes_read)
> 
> or even
> 
> int ft2232_read(u8* buf, unsigned size, unsigned* bytes_read)
> 
> 
> If we don't need the "32 bitness", it is best to let the compiler, and
> the programmer, use the machine's natural size.  int and unsigned are
> simple.  
> 
> On a 64 bit machine, the "unsigned" and the "int" goes to 64 bits, but
> that is its natural size, and is generally the most efficient, easier
> than accessing 32 bits.
> 
> Microsoft was insidious about injecting needless types into C and C++
> code.  When Java was designed, they made a point of slapping that idea
> in the face.
> 
> u8* is cool, we need unsigned bytes.
> 
> u32 is cool, but only when you have to have the variable be 32 bits
> wide, otherwise int or unsigned are better IMO when you don't care if
> it is 32 bits or 64 bits.  The 64 bit days are here.

I have attached what I hope can be the final version of this patch,
addressing your immediate point in the least invasive manner possible.

While I too would like to move toward proper 32/64-bit portability,
changing the third argument for ft2232_read would require also touching
all of its callers for an unnecessary change (from the perspective of
the intended goal).  I have left it alone for now, but I agree it (and
all of its cousins in other drivers) needs to be revisited.

Cheers,

Zach

Index: src/jtag/bitq.c
===================================================================
--- src/jtag/bitq.c	(revision 1475)
+++ src/jtag/bitq.c	(working copy)
@@ -39,7 +39,7 @@
 bitq_state_t      bitq_in_state;        /* state of input queue */
 
 u8* bitq_in_buffer;                     /* buffer dynamically reallocated as needed */
-unsigned long     bitq_in_bufsize = 32; /* min. buffer size */
+int     bitq_in_bufsize = 32; /* min. buffer size */
 
 /*
  * input queue processing does not use jtag_read_buffer() to avoid unnecessary overhead
Index: src/jtag/presto.c
===================================================================
--- src/jtag/presto.c	(revision 1475)
+++ src/jtag/presto.c	(working copy)
@@ -138,7 +138,7 @@
 	0x80, 0xA0, 0xA8, 0xB0, 0xC0, 0xE0
 };
 
-int presto_write(u8 *buf, int size)
+int presto_write(u8 *buf, unsigned size)
 {
 #if BUILD_PRESTO_FTD2XX == 1
 	DWORD ftbytes;
@@ -160,14 +160,14 @@
 
 	if (ftbytes != size)
 	{
-		LOG_ERROR("couldn't write the requested number of bytes to PRESTO (%i < %i)", ftbytes, size);
+		LOG_ERROR("couldn't write the requested number of bytes to PRESTO (%u < %u)", (unsigned)ftbytes, size);
 		return ERROR_JTAG_DEVICE_ERROR;
 	}
 
 	return ERROR_OK;
 }
 
-int presto_read(u8* buf, int size)
+int presto_read(u8* buf, unsigned size)
 {
 #if BUILD_PRESTO_FTD2XX == 1
 	DWORD ftbytes;
@@ -202,7 +202,7 @@
 	if (ftbytes != size)
 	{
 		/* this is just a warning, there might have been timeout when detecting PRESTO, which is not fatal */
-		LOG_WARNING("couldn't read the requested number of bytes from PRESTO (%i < %i)", ftbytes, size);
+		LOG_WARNING("couldn't read the requested number of bytes from PRESTO (%u < %u)", (unsigned)ftbytes, size);
 		return ERROR_JTAG_DEVICE_ERROR;
 	}
 
@@ -212,7 +212,7 @@
 #if BUILD_PRESTO_FTD2XX == 1
 int presto_open_ftd2xx(char *req_serial)
 {
-	int i;
+	unsigned i;
 	DWORD numdevs;
 	DWORD vidpid;
 	char devname[FT_DEVICE_NAME_LEN];
@@ -238,7 +238,7 @@
 		return ERROR_JTAG_DEVICE_ERROR;
 	}
 
-	LOG_DEBUG("FTDI devices available: %i", numdevs);
+	LOG_DEBUG("FTDI devices available: %lu", numdevs);
 	for (i = 0; i < numdevs; i++)
 	{
 		if ((presto->status = FT_Open(i, &(presto->handle))) != FT_OK)
@@ -257,7 +257,7 @@
 				break;
 		}
 		else
-			LOG_DEBUG("FT_GetDeviceInfo failed: %i", presto->status);
+			LOG_DEBUG("FT_GetDeviceInfo failed: %lu", presto->status);
 
 		LOG_DEBUG("FTDI device %i does not match, closing", i);
 		FT_Close(presto->handle);
Index: src/jtag/ft2232.c
===================================================================
--- src/jtag/ft2232.c	(revision 1475)
+++ src/jtag/ft2232.c	(working copy)
@@ -158,7 +158,7 @@
 	{ "stm32stick",           stm32stick_init,           stm32stick_reset,   NULL                    },
 	{ "axm0432_jtag",         axm0432_jtag_init,         axm0432_jtag_reset, NULL                    },
 	{"sheevaplug",            sheevaplug_init,           sheevaplug_reset,   NULL                    },
-	{ NULL,                   NULL,                      NULL },
+	{ NULL,                   NULL,                      NULL,               NULL                    },
 };
 
 static u8                  nTRST, nTRSTnOE, nSRST, nSRSTnOE;
@@ -233,7 +233,7 @@
 }
 
 
-int ft2232_read(u8* buf, int size, u32* bytes_read)
+int ft2232_read(u8* buf, unsigned size, u32* bytes_read)
 {
 #if BUILD_FT2232_FTD2XX == 1
 	DWORD     dw_bytes_read;
@@ -1607,7 +1607,7 @@
 		if (status == FT_OK)
 		{
 			char** desc_array = malloc( sizeof(char*) * (num_devices + 1) );
-			int    i;
+			unsigned i;
 
 			for (i = 0; i < num_devices; i++)
 				desc_array[i] = malloc(64);
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to