{"thread":{"id":"6888","subject":"[PATCH] Obey NO_C99_FORMAT in fast-import.c.","startedAt":"2007-02-20T00:27:09Z","lastAt":"2007-02-20T12:57:16Z","messageCount":2,"participants":["Jason Riedy","Simon 'corecode' Schubert"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35054","messageId":"17825.1171931229@lotus.CS.Berkeley.EDU","threadId":"6888","inReplyTo":null,"subject":"[PATCH] Obey NO_C99_FORMAT in fast-import.c.","fromName":"Jason Riedy","fromEmail":"ejr@eecs.berkeley.edu","sentAt":"2007-02-20T00:27:09Z","receivedAt":"2007-02-20T00:27:09Z","isPatch":true,"sender":{"key":"ejr@eecs.berkeley.edu","avatar":"https://gravatar.com/avatar/547fa56f887cab01599edab4e9f813c949c1269e02714f20e0496c56185d9837?d=mp&s=160"},"body":"Define UM_FMT and UM10_FMT and use in place of %ju and %10ju,\nrespectively.  Both format as unsigned long long, so this\nassumes the compiler supports long long.\n\nSigned-off-by: Jason Riedy <jason@acm.org>\n---\n   If there's need, I could add a NO_LONGLONG.\n\n fast-import.c |   37 +++++++++++++++++++++++--------------\n 1 files changed, 23 insertions(+), 14 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 404d911..ad32300 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -133,6 +133,15 @@ Format of STDIN stream:\n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\n \n+#if !defined(NO_C99_FORMAT)\n+#define UM_FMT \"%ju\"\n+#define UM10_FMT \"%10ju\"\n+#else\n+/* Assumes unsigned long long exists. */\n+#define UM_FMT \"%llu\"\n+#define UM10_FMT \"%10llu\"\n+#endif\n+\n struct object_entry\n {\n \tstruct object_entry *next;\n@@ -475,7 +484,7 @@ static struct object_entry *find_mark(uintmax_t idnum)\n \t\t\toe = s->data.marked[idnum];\n \t}\n \tif (!oe)\n-\t\tdie(\"mark :%ju not declared\", orig_idnum);\n+\t\tdie(\"mark :\" UM_FMT \" not declared\", orig_idnum);\n \treturn oe;\n }\n \n@@ -1361,7 +1370,7 @@ static void dump_marks_helper(FILE *f,\n \t} else {\n \t\tfor (k = 0; k < 1024; k++) {\n \t\t\tif (m->data.marked[k])\n-\t\t\t\tfprintf(f, \":%ju %s\\n\", base + k,\n+\t\t\t\tfprintf(f, \":\" UM_FMT \" %s\\n\", base + k,\n \t\t\t\t\tsha1_to_hex(m->data.marked[k]->sha1));\n \t\t}\n \t}\n@@ -1687,7 +1696,7 @@ static void cmd_from(struct branch *b)\n \t\tunsigned long size;\n \t\tchar *buf;\n \t\tif (oe->type != OBJ_COMMIT)\n-\t\t\tdie(\"Mark :%ju not a commit\", idnum);\n+\t\t\tdie(\"Mark :\" UM_FMT \" not a commit\", idnum);\n \t\thashcpy(b->sha1, oe->sha1);\n \t\tbuf = gfi_unpack_entry(oe, &size);\n \t\tif (!buf || size < 46)\n@@ -1740,7 +1749,7 @@ static struct hash_list *cmd_merge(unsigned int *count)\n \t\t\tuintmax_t idnum = strtoumax(from + 1, NULL, 10);\n \t\t\tstruct object_entry *oe = find_mark(idnum);\n \t\t\tif (oe->type != OBJ_COMMIT)\n-\t\t\t\tdie(\"Mark :%ju not a commit\", idnum);\n+\t\t\t\tdie(\"Mark :\" UM_FMT \" not a commit\", idnum);\n \t\t\thashcpy(n->sha1, oe->sha1);\n \t\t} else if (get_sha1(from, n->sha1))\n \t\t\tdie(\"Invalid ref name or SHA1 expression: %s\", from);\n@@ -1884,7 +1893,7 @@ static void cmd_new_tag(void)\n \t\tfrom_mark = strtoumax(from + 1, NULL, 10);\n \t\toe = find_mark(from_mark);\n \t\tif (oe->type != OBJ_COMMIT)\n-\t\t\tdie(\"Mark :%ju not a commit\", from_mark);\n+\t\t\tdie(\"Mark :\" UM_FMT \" not a commit\", from_mark);\n \t\thashcpy(sha1, oe->sha1);\n \t} else if (!get_sha1(from, sha1)) {\n \t\tunsigned long size;\n@@ -2059,18 +2068,18 @@ int main(int argc, const char **argv)\n \n \t\tfprintf(stderr, \"%s statistics:\\n\", argv[0]);\n \t\tfprintf(stderr, \"---------------------------------------------------------------------\\n\");\n-\t\tfprintf(stderr, \"Alloc'd objects: %10ju\\n\", alloc_count);\n-\t\tfprintf(stderr, \"Total objects:   %10ju (%10ju duplicates                  )\\n\", total_count, duplicate_count);\n-\t\tfprintf(stderr, \"      blobs  :   %10ju (%10ju duplicates %10ju deltas)\\n\", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]);\n-\t\tfprintf(stderr, \"      trees  :   %10ju (%10ju duplicates %10ju deltas)\\n\", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]);\n-\t\tfprintf(stderr, \"      commits:   %10ju (%10ju duplicates %10ju deltas)\\n\", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]);\n-\t\tfprintf(stderr, \"      tags   :   %10ju (%10ju duplicates %10ju deltas)\\n\", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]);\n+\t\tfprintf(stderr, \"Alloc'd objects: \" UM10_FMT \"\\n\", alloc_count);\n+\t\tfprintf(stderr, \"Total objects:   \" UM10_FMT \" (\" UM10_FMT \" duplicates                  )\\n\", total_count, duplicate_count);\n+\t\tfprintf(stderr, \"      blobs  :   \" UM10_FMT \" (\" UM10_FMT \" duplicates \" UM10_FMT \" deltas)\\n\", object_count_by_type[OBJ_BLOB], duplicate_count_by_type[OBJ_BLOB], delta_count_by_type[OBJ_BLOB]);\n+\t\tfprintf(stderr, \"      trees  :   \" UM10_FMT \" (\" UM10_FMT \" duplicates \" UM10_FMT \" deltas)\\n\", object_count_by_type[OBJ_TREE], duplicate_count_by_type[OBJ_TREE], delta_count_by_type[OBJ_TREE]);\n+\t\tfprintf(stderr, \"      commits:   \" UM10_FMT \" (\" UM10_FMT \" duplicates \" UM10_FMT \" deltas)\\n\", object_count_by_type[OBJ_COMMIT], duplicate_count_by_type[OBJ_COMMIT], delta_count_by_type[OBJ_COMMIT]);\n+\t\tfprintf(stderr, \"      tags   :   \" UM10_FMT \" (\" UM10_FMT \" duplicates \" UM10_FMT \" deltas)\\n\", object_count_by_type[OBJ_TAG], duplicate_count_by_type[OBJ_TAG], delta_count_by_type[OBJ_TAG]);\n \t\tfprintf(stderr, \"Total branches:  %10lu (%10lu loads     )\\n\", branch_count, branch_load_count);\n-\t\tfprintf(stderr, \"      marks:     %10ju (%10ju unique    )\\n\", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);\n+\t\tfprintf(stderr, \"      marks:     \" UM10_FMT \" (\" UM10_FMT \" unique    )\\n\", (((uintmax_t)1) << marks->shift) * 1024, marks_set_count);\n \t\tfprintf(stderr, \"      atoms:     %10u\\n\", atom_cnt);\n-\t\tfprintf(stderr, \"Memory total:    %10ju KiB\\n\", (total_allocd + alloc_count*sizeof(struct object_entry))/1024);\n+\t\tfprintf(stderr, \"Memory total:    \" UM10_FMT \" KiB\\n\", (total_allocd + alloc_count*sizeof(struct object_entry))/1024);\n \t\tfprintf(stderr, \"       pools:    %10lu KiB\\n\", (unsigned long)(total_allocd/1024));\n-\t\tfprintf(stderr, \"     objects:    %10ju KiB\\n\", (alloc_count*sizeof(struct object_entry))/1024);\n+\t\tfprintf(stderr, \"     objects:    \" UM10_FMT \" KiB\\n\", (alloc_count*sizeof(struct object_entry))/1024);\n \t\tfprintf(stderr, \"---------------------------------------------------------------------\\n\");\n \t\tpack_report();\n \t\tfprintf(stderr, \"---------------------------------------------------------------------\\n\");\n-- \n1.5.0.rc1.g6f729\n"},{"id":"35115","messageId":"45DAF02C.4020003@fs.ei.tum.de","threadId":"6888","inReplyTo":"17825.1171931229@lotus.CS.Berkeley.EDU","subject":"Re: [PATCH] Obey NO_C99_FORMAT in fast-import.c.","fromName":"Simon 'corecode' Schubert","fromEmail":"corecode@fs.ei.tum.de","sentAt":"2007-02-20T12:57:16Z","receivedAt":"2007-02-20T12:57:16Z","isPatch":true,"sender":{"key":"corecode@fs.ei.tum.de","avatar":"https://gravatar.com/avatar/eff9dbf0cdac0d1e6a6cd7ed0e50763edcb376b493b5253a35ff167918ad79e1?d=mp&s=160"},"body":"Jason Riedy wrote:\n> Define UM_FMT and UM10_FMT and use in place of %ju and %10ju,\n> respectively.  Both format as unsigned long long, so this\n> assumes the compiler supports long long.\n\nSo there are really systems which do not support the \"j\" (standardized) size modifier, but support \"long long\" (unstandardized) integers?  Oh my.\n\n> +#if !defined(NO_C99_FORMAT)\n> +#define UM_FMT \"%ju\"\n> +#define UM10_FMT \"%10ju\"\n> +#else\n> +/* Assumes unsigned long long exists. */\n> +#define UM_FMT \"%llu\"\n> +#define UM10_FMT \"%10llu\"\n> +#endif\n\nI think this should read something like\n\n#ifndef PRIuMAX\n#define PRIuMAX\t\t\"llu\"\t/* Assumes unsigned long long exists */\n#endif\n\nAfter all, these macros are standardized (<inttypes.h>)\n\nHunks like this should of course read differently then:\n\n> -\t\tdie(\"mark :%ju not declared\", orig_idnum);\n> +\t\tdie(\"mark :\" UM_FMT \" not declared\", orig_idnum);\n\ndie(\"mark :%\"PRIuMAX\" not declared\", orig_idnum);\n\n> +\t\tfprintf(stderr, \"Alloc'd objects: \" UM10_FMT \"\\n\", alloc_count);\n\nAnd then this UM10_FMT stunt isn't needed either:\n\nfprintf(stderr, \"Alloc'd objects: %10\"PRIuMAX\"\\n\", alloc_count);\n\ncheers\n  simon\n\n-- \nServe - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /\"\\\nWork - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \\ /\nParty Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \\\nDude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \\\n\n"}]}