Re: [PATCH 2/3] convert "enum date_mode" into a struct

2015-07-07 Thread Junio C Hamano
Jeff King writes: > OK. Do you want to leave it be, then, or would you prefer me to do the > NULL fallback? Or we could bump the enum to start with 1, and then > explicitly treat "0" as a synonym for DATE_NORMAL (in case it comes in > through a memset or similar). I didn't think about the memset

Re: [PATCH 2/3] convert "enum date_mode" into a struct

2015-07-07 Thread Jeff King
On Tue, Jul 07, 2015 at 02:05:52PM -0700, Junio C Hamano wrote: > And that is because DATE_NORMAL is defined to be 0; we can claim > that the compiler is being stupid to take one of the enum > date_mode_type values that happens to be 0 and misinterpret it as > the program wanted to pass a NULL poi

Re: [PATCH 2/3] convert "enum date_mode" into a struct

2015-07-07 Thread Junio C Hamano
Jeff King writes: > My assumption was that using the raw "0" is something we would frowned > upon in new code. There was a single historical instance that I fixed in > the series, but I wouldn't expect new ones (and actually, that instance > was "1", which would be caught by the compiler). That

Re: [PATCH 2/3] convert "enum date_mode" into a struct

2015-07-07 Thread Jeff King
On Tue, Jul 07, 2015 at 01:37:08PM -0700, Junio C Hamano wrote: > > 3. Provide a wrapper that generates the correct struct on > > the fly. The big downside is that we end up pointing to > > a single global, which makes our wrapper non-reentrant. > > But show_date is already not re

Re: [PATCH 2/3] convert "enum date_mode" into a struct

2015-07-07 Thread Junio C Hamano
Jeff King writes: > ... However, the tricky case is where we use the > enum labels as constants, like: > > show_date(t, tz, DATE_NORMAL); > > Ideally we could say: > > show_date(t, tz, &{ DATE_NORMAL }); > > but of course C does not allow that. > ... > 3. Provide a wrapper that generates t

Re: [PATCH 2/3] convert "enum date_mode" into a struct

2015-06-25 Thread Jeff King
On Thu, Jun 25, 2015 at 06:03:28PM +0100, John Keeping wrote: > > Ideally we could say: > > > > show_date(t, tz, &{ DATE_NORMAL }); > > > > but of course C does not allow that. > > Yes it does, e.g. in 6.5.2.5 of C11, example 3 shows: Well, yes. But we generally restrict ourselves to C89 her

Re: [PATCH 2/3] convert "enum date_mode" into a struct

2015-06-25 Thread John Keeping
On Thu, Jun 25, 2015 at 12:55:02PM -0400, Jeff King wrote: > In preparation for adding date modes that may carry extra > information beyond the mode itself, this patch converts the > date_mode enum into a struct. > > Most of the conversion is fairly straightforward; we pass > the struct as a point

[PATCH 2/3] convert "enum date_mode" into a struct

2015-06-25 Thread Jeff King
In preparation for adding date modes that may carry extra information beyond the mode itself, this patch converts the date_mode enum into a struct. Most of the conversion is fairly straightforward; we pass the struct as a pointer and dereference the type field where necessary. Locations that decla