[Ur] callbacks from C FFI (again)

Sergey grrwlf at gmail.com
Tue Jan 7 10:46:09 EST 2014


On 05.01.2014 22:10, Adam Chlipala wrote:
>> I think it is better to direct efforts into improvement of the FFI
>> interface and urweb API because we will need them anyway. If I only
>> had methods for
>>
>> 1) clone the context to use it with a new thread inside an FFI
>> 2) call the url handler (I already know that `uw_begin' or
>> `uw_get_app(ctx)->handle(ctx, uri)' may help me here)
>
> I think I'm basically on board with this proposal, but there is it 
> least one potential complication that seems worth bringing up.
>
> Any Ur/Web code may encounter a benign exception requiring transaction 
> restart.  The canonical example is a serialization failure from 
> optimistic SQL concurrency.  Your suggestions above don't make it 
> clear how transactions should be handled in general, including where 
> to jump back to when a transaction needs restarting.

I assumed the strategy to be an FFI-specific. As soon as FFI API 
provides the basic combinators (uw_begin, uw_commit, uw_rollback, ...), 
the programmer is able to implement any algorithm they want. The 
`periodic_loop()' from request.c demonstrates one possible algorithm, 
probably, the most popular one.
>
> For simplicity's sake, what do you think of implementing the following 
> two functions instead?
> 1) clone context but don't start a transaction for it (note that this 
> also opens a database connection, checks the schema, and creates 
> prepared statements!)
> 2) given a context and a URI, run the associated Ur/Web code in that 
> context in a new transaction associated only with this operation
Fine! I'll draft a patch and publish it.
> My main recommendation, though, is to do like this for a record that 
> needs to cross the Ur-C boundary.  This would be code in an FFI .urs 
> file:
>     type myrecord
>     val myrecord : int -> string -> myrecord
>     val getInt : myrecord -> int
>     val getString : myrecord -> string
>
OK. I already use this method, the only thing that bothers me is the 
amount of boilerplate code. But It is not that important at the moment.

Regards,
Sergey




More information about the Ur mailing list