On Sun, 2009-05-24 at 21:12 -0400, Duane Ellis wrote:
> Why not deprecate/change, all "u32" to "uint32_t" - wholesale?

In looking into this deeper, I just found that we lack i32 (or similar),
which would be required for a case in replacements.h.  That said, the
attached patch replaces my earlier offering.  

Task complete.  I will apply it, if this looks okay to you.

Cheers,

Zach

======
Normalize use of types to use uN instead of uintN_t:
- include <inttypes.h> in "types.h":
  - this includes <stdint.h>, and both are part of C99
  - also provides intmax_t type, which has been used in-tree
- define shorthand uN types using uintN_t definitions provided by C99
- add iN equivalents to intN_t types; i32 is used by replacements.h
- use these project-defined shorthand types everywhere in the tree
- remove occurrences of these standard headers from other source files
- update Developer Style Guide to document this topic fully
---
 doc/manual/style.txt      |    7 +++++++
 src/flash/flash.c         |    2 --
 src/flash/nand.c          |    2 --
 src/flash/nand_ecc_kw.c   |    4 ++--
 src/helper/replacements.h |   12 ++++++------
 src/helper/types.h        |   28 ++++++++++++++++++----------
 src/jtag/rlink/rlink.c    |   24 ++++++++++++------------
 src/server/httpd.c        |    2 +-
 src/target/target.c       |    2 --
 src/target/trace.c        |    2 --
 10 files changed, 46 insertions(+), 39 deletions(-)
Index: src/helper/types.h
===================================================================
--- src/helper/types.h	(revision 1906)
+++ src/helper/types.h	(working copy)
@@ -23,29 +23,37 @@
 #ifndef TYPES_H
 #define TYPES_H
 
+#include <inttypes.h>
 #ifdef HAVE_SYS_TYPES_H
 #include <sys/types.h>
 #endif
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
 
 #ifndef u8
-typedef unsigned char u8;
+typedef uint8_t u8;
 #endif
-
 #ifndef u16
-typedef unsigned short u16;
+typedef uint16_t u16;
 #endif
-
 #ifndef u32
-typedef unsigned int u32;
+typedef uint32_t u32;
 #endif
-
 #ifndef u64
-typedef unsigned long long u64;
+typedef uint64_t u64;
 #endif
 
+#ifndef i8
+typedef int8_t i8;
+#endif
+#ifndef i16
+typedef int16_t i16;
+#endif
+#ifndef i32
+typedef int32_t i32;
+#endif
+#ifndef i64
+typedef int64_t i64;
+#endif
+
 typedef struct jtag_tap_s jtag_tap_t;
 
 #ifdef HAVE_STDBOOL_H
Index: src/helper/replacements.h
===================================================================
--- src/helper/replacements.h	(revision 1906)
+++ src/helper/replacements.h	(working copy)
@@ -210,12 +210,12 @@
 
 #ifndef HAVE_ELF_H
 
-typedef uint32_t	Elf32_Addr;
-typedef uint16_t	Elf32_Half;
-typedef uint32_t	Elf32_Off;
-typedef int32_t		Elf32_Sword;
-typedef uint32_t	Elf32_Word;
-typedef uint32_t	Elf32_Size;
+typedef u32	Elf32_Addr;
+typedef u16	Elf32_Half;
+typedef u32	Elf32_Off;
+typedef i32		Elf32_Sword;
+typedef u32	Elf32_Word;
+typedef u32	Elf32_Size;
 typedef Elf32_Off	Elf32_Hashelt;
 
 typedef struct
Index: src/jtag/rlink/rlink.c
===================================================================
--- src/jtag/rlink/rlink.c	(revision 1906)
+++ src/jtag/rlink/rlink.c	(working copy)
@@ -115,8 +115,8 @@
 	size_t		length,
 	...
 ) {
-	uint8_t		usb_buffer[USB_EP1OUT_SIZE];
-	uint8_t		*usb_buffer_p;
+	u8		usb_buffer[USB_EP1OUT_SIZE];
+	u8		*usb_buffer_p;
 	va_list		ap;
 	int		usb_ret;
 
@@ -155,11 +155,11 @@
 ssize_t
 ep1_memory_read(
 	usb_dev_handle	*pHDev,
-	uint16_t	addr,
+	u16	addr,
 	size_t		length,
-	uint8_t		*buffer
+	u8		*buffer
 ) {
-	uint8_t		usb_buffer[USB_EP1OUT_SIZE];
+	u8		usb_buffer[USB_EP1OUT_SIZE];
 	int		usb_ret;
 	size_t		remain;
 	ssize_t		count;
@@ -221,11 +221,11 @@
 ssize_t
 ep1_memory_write(
 	usb_dev_handle	*pHDev,
-	uint16_t	addr,
+	u16	addr,
 	size_t		length,
-	uint8_t	const	*buffer
+	u8	const	*buffer
 ) {
-	uint8_t		usb_buffer[USB_EP1OUT_SIZE];
+	u8		usb_buffer[USB_EP1OUT_SIZE];
 	int		usb_ret;
 	size_t		remain;
 	ssize_t		count;
@@ -281,12 +281,12 @@
 ssize_t
 ep1_memory_writel(
 	usb_dev_handle	*pHDev,
-	uint16_t	addr,
+	u16	addr,
 	size_t		length,
 	...
 ) {
-	uint8_t		buffer[USB_EP1OUT_SIZE - 4];
-	uint8_t		*buffer_p;
+	u8		buffer[USB_EP1OUT_SIZE - 4];
+	u8		*buffer_p;
 	va_list		ap;
 	size_t		remain;
 
@@ -318,7 +318,7 @@
 #define DTC_LOAD_BUFFER		ST7_USB_BUF_EP2UIDO
 
 /* This gets set by the DTC loader */
-static uint8_t dtc_entry_download;
+static u8 dtc_entry_download;
 
 
 /* The buffer is specially formatted to represent a valid image to load into the DTC. */
Index: src/server/httpd.c
===================================================================
--- src/server/httpd.c	(revision 1906)
+++ src/server/httpd.c	(working copy)
@@ -223,7 +223,7 @@
 /* append data to each key */
 static int iterate_post(void *con_cls, enum MHD_ValueKind kind,
 		const char *key, const char *filename, const char *content_type,
-		const char *transfer_encoding, const char *data, uint64_t off,
+		const char *transfer_encoding, const char *data, u64 off,
 		size_t size)
 {
 	struct httpd_request *r = (struct httpd_request*) con_cls;
Index: src/target/trace.c
===================================================================
--- src/target/trace.c	(revision 1906)
+++ src/target/trace.c	(working copy)
@@ -25,8 +25,6 @@
 #include "trace.h"
 #include "target.h"
 
-#include <inttypes.h>
-
 int trace_point(target_t *target, u32 number)
 {
 	trace_t *trace = target->trace_info;
Index: src/target/target.c
===================================================================
--- src/target/target.c	(revision 1906)
+++ src/target/target.c	(working copy)
@@ -41,9 +41,7 @@
 #include "image.h"
 #include "jtag.h"
 
-#include <inttypes.h>
 
-
 static int handle_targets_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 
 static int handle_reg_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
Index: src/flash/nand.c
===================================================================
--- src/flash/nand.c	(revision 1906)
+++ src/flash/nand.c	(working copy)
@@ -28,9 +28,7 @@
 #include "time_support.h"
 #include "fileio.h"
 
-#include <inttypes.h>
 
-
 static int handle_nand_list_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 static int handle_nand_probe_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 static int handle_nand_check_bad_blocks_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
Index: src/flash/nand_ecc_kw.c
===================================================================
--- src/flash/nand_ecc_kw.c	(revision 1906)
+++ src/flash/nand_ecc_kw.c	(working copy)
@@ -38,13 +38,13 @@
  * identical copies of this array back-to-back so that we can save
  * the mod 1023 operation when doing a GF multiplication.
  */
-static uint16_t gf_exp[1023 + 1023];
+static u16 gf_exp[1023 + 1023];
 
 /*
  * Maps a polynomial b in GF(2^10) mod x^10 + x^3 + 1 to an index
  * a = gf_log[b] in [0..1022] such that b = x ^ a.
  */
-static uint16_t gf_log[1024];
+static u16 gf_log[1024];
 
 static void gf_build_log_exp_table(void)
 {
Index: src/flash/flash.c
===================================================================
--- src/flash/flash.c	(revision 1906)
+++ src/flash/flash.c	(working copy)
@@ -31,8 +31,6 @@
 #include "image.h"
 #include "time_support.h"
 
-#include <inttypes.h>
-
 /* command handlers */
 static int handle_flash_bank_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
 static int handle_flash_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
Index: doc/manual/style.txt
===================================================================
--- doc/manual/style.txt	(revision 1906)
+++ doc/manual/style.txt	(working copy)
@@ -53,6 +53,13 @@
 - variables declarations may be mixed with code
 - new block scopes for selection and iteration statements
 
+...@section stylec99 Type Rules
+- use native types (@c int or @c unsigned) if the type is not important
+  - if size matters, use the types from "types.h":
+    - @c i8, @c i16, @c i32, or @c i64: signed types of specified size
+    - @c u8, @c u16, @c u32, or @c u64: unsigned types of specified size
+  - do @b NOT use @c (u)intN_t types from <stdint.h> or <inttypes.h>
+
 @section stylefunc Functions
 
 - static inline functions should be prefered over macros:
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to