Phil Pennock | 20 Oct 2010 03:48

Re: ${index}

On 2010-10-20 at 00:52 +0100, Mike Cardwell wrote:
> http://github.com/mikecardwell/Exim/commit/b4ef92d69ac58a46cbb0babb93d688267fbed443
> 
> Provides a ${index{string}{substring}} function to return the location
> of a string within a string. Examples:

Generally like it.  My main commentary is at the bikeshed-painting
level, so I'll throw it out there, but am not going to protest if you
ignore me.

Note that Exim doesn't really do much sequential work with variables
holding results, although it can of course be so abused, so I'm curious
about the desire to use an expansion operator instead of an expansion
condition for the basic check.  What's the use-case?

At a code-review level: multiple case statements inside a switch which
fall through should usually have a comment stating that this is explicit
and intentional.  Looking for prior art in expand.c, I see both /* Fall
through */ and, as counter-example, ECOND_ISIP/ECOND_ISIP4/ECOND_ISIP6.
I'd argue that it's clear that the ECOND_ISIP* cases are being handled
in common, whereas in this case, I had to go check the documentation for
read_subs() to see the return values, to confirm that the 2 and 3 values
could reasonably be treated the same and this was not accidental code
omission.

Is %d cross-platform safe formatting for a ptrdiff_t type?  I'd be
"impressed" if an Exim string ever holds enough data to have to worry
about wrap-around or overflow of 32-bit here, but it might be safest to
use %ld and a (long int) cast.  FreeBSD uses 64-bit signed ptrdiff_t and
that's a 'long'.  My vague recollection is that this is normal for
(Continue reading)

Mike Cardwell | 20 Oct 2010 11:48

Re: ${index}

On 20/10/2010 02:48, Phil Pennock wrote:

>> http://github.com/mikecardwell/Exim/commit/b4ef92d69ac58a46cbb0babb93d688267fbed443
>>
>> Provides a ${index{string}{substring}} function to return the location
>> of a string within a string. Examples:
> 
> Generally like it.  My main commentary is at the bikeshed-painting
> level, so I'll throw it out there, but am not going to protest if you
> ignore me.

I don't know C. It's the (IT related) skill I regret not having, most. I
figured if I start hacking at the Exim code, I'll start to pick it up.
So with that in mind, any criticism, no matter how small, is useful at
this point.

> Note that Exim doesn't really do much sequential work with variables
> holding results, although it can of course be so abused, so I'm curious
> about the desire to use an expansion operator instead of an expansion
> condition for the basic check.  What's the use-case?

Can you clarify the above please. How would it work as an expansion
condition? Can you show me an example of what the Exim config would look
like? I did initially think of writing a "contains" condition, ie:

condition = ${if contains{string}{substring}{true}{false}}

But I figured a general "index" operator would have more use cases. I'm
still unsure though... "contains" might be enough.

(Continue reading)

Phil Pennock | 20 Oct 2010 21:06

Re: ${index}

On 2010-10-20 at 10:48 +0100, Mike Cardwell wrote:
> On 20/10/2010 02:48, Phil Pennock wrote:
> > Note that Exim doesn't really do much sequential work with variables
> > holding results, although it can of course be so abused, so I'm curious
> > about the desire to use an expansion operator instead of an expansion
> > condition for the basic check.  What's the use-case?
> 
> Can you clarify the above please. How would it work as an expansion
> condition? Can you show me an example of what the Exim config would look
> like? I did initially think of writing a "contains" condition, ie:
> 
> condition = ${if contains{string}{substring}{true}{false}}

That's exactly what an expansion condition is: something which can be an
argument to ${if...}; as opposed to an expansion operator, which
converts a string to a string.

My concern is the use-cases, but it seems fairly harmless to just do
what you did (which is actually an expansion item, not an expansion
operator, and is an example of Exim being confusing).

> > Is %d cross-platform safe formatting for a ptrdiff_t type?
> 
> I don't know. I'm used to programming in languages that don't have this
> sort of issue. How would I find out if that's cross-platform safe? Or is
> the only way testing and experience? Is there a better way of doing that
> part that doesn't involve string_sprintf?

Research.  And pain.
> 
(Continue reading)


Gmane