Mailing List Archive

dlfunc yield value protocol
It is unclear to me how I can yield any "interesting" string from a
${dlfunc ..} expansion, because apparently the main exim program doesn't
try to free the store to which the _yield_ variable points. The only
example I have seen of actual dlfunc use is [1], and it only yields
constant strings. So 2 questions:

1. Where can I find other examples of dlfunc use?

2. How can I yield a general, variable string (which implies it needs to
be freed) ?

[1]
https://raw.githubusercontent.com/wiki/Exim/exim/attachments/exim-ext-grey.c.txt

--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet and on broken lists
which rewrite From, fetch the TXT record for no-use.mooo.com.

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: dlfunc yield value protocol [ In reply to ]
On 24/01/2019 18:13, Ian Zimmerman via Exim-users wrote:
> 2. How can I yield a general, variable string (which implies it needs to
> be freed) ?

The facilities are the same as for local_scan. See the chapter on
that, and use one of the functions documented in local_scan.h


For your purpose, that probably means one of

string_sprintf()
string_copy()
string_copyn()

Those three return a string in freshly-allocated memory. Freeing
is handled for you; it's assumed you're not going overboard
within a single processing phase (I'd not recommend attempting
to prove that ACLs are Turing-complete, nor write a Game-of-Life
program in string expansions).



A brief search found me
https://github.com/snabb/exim-geoipv6-dlfunc/blob/master/exim-geoipv6-dlfunc.c

--
Cheers,
Jeremy

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: dlfunc yield value protocol [ In reply to ]
On 2019-01-24 20:44, Jeremy Harris wrote:

> string_sprintf()
> string_copy()
> string_copyn()

Exactly what I was hoping for! Thanks.

--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet and on broken lists
which rewrite From, fetch the TXT record for no-use.mooo.com.

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: dlfunc yield value protocol [ In reply to ]
On 2019-01-24 14:10, Ian Zimmerman wrote:

> On 2019-01-24 20:44, Jeremy Harris wrote:
>
> > string_sprintf()
> > string_copy()
> > string_copyn()
>
> Exactly what I was hoping for! Thanks.

A follow-up question. Can I do the analogue of realloc()?

I am trying to construct a list (in the Exim sense) and return it from
the dlfunc module. I don't know a priori how long the list will be or
how many elements.

I could just allocate a new string as I add each new element but that
has quadratic behavior.

I guess I could store the elements in a linked list and then concatenate
them all at once, but that seems like too much work :-P

--
Please don't Cc: me privately on mailing lists and Usenet,
if you also post the followup to the list or newsgroup.
To reply privately _only_ on Usenet and on broken lists
which rewrite From, fetch the TXT record for no-use.mooo.com.

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/
Re: dlfunc yield value protocol [ In reply to ]
On 28/01/2019 19:00, Ian Zimmerman via Exim-users wrote:
> On 2019-01-24 14:10, Ian Zimmerman wrote:
>
>> On 2019-01-24 20:44, Jeremy Harris wrote:
>>
>>> string_sprintf()
>>> string_copy()
>>> string_copyn()
>>
>> Exactly what I was hoping for! Thanks.
>
> A follow-up question. Can I do the analogue of realloc()?
>
> I am trying to construct a list (in the Exim sense) and return it from
> the dlfunc module. I don't know a priori how long the list will be or
> how many elements.

Not with the documented API.

The internal way to do it would be one of

string_append_listele()
string_append_listele_n()

string_cat()
string_catn()

... all of which deal in objects called "growable string".
You don't need to alloc or realloc at all.
--
Cheers,
Jeremy

--
## List details at https://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/