[Ur] interfacing with C or other languages - example system

Adam Chlipala adamc at impredicative.com
Sun Nov 28 15:58:18 EST 2010


Marc Weber wrote:
>> Just to repeat what I said the last time someone brought this up: it is
>> impossible to support this in Ur/Web in the most general way, without
>> allowing for the possibility of some crazy behavior.  The runtime system
>> feels free to restart program execution at any time, which wouldn't work
>> well with effectful commands that can't be undone.
>>      
> Error triggers unlimited retry: Couldn't allocate new heap chunk contiguously
>
> So it seems urweb tries with small heap and if everything fails it
> retries with more?
>    

That's right.  The runtime system will also restart if an optimistic SQL 
concurrency violation is detected, when certain errors are signaled, etc..

>> Currently, Ur/Web doesn't allow C FFI functions to return values in
>> algebraic datatypes besides those that can be represented with C enums.
>> However, you can easily provide the same set of operations (as
>> additional C FFI functions) on a new abstract type.
>>      
> I think it would be cool if you could hardcode record types such as
>    result.blob
>    result.code
>    

It would certainly be more convenient, but also less abstract, in some 
sense.  Because I don't think it would really make much difference, I 
haven't implemented it.

> http://gitorious.org/some-urweb-utility-libraries/uw-process
>    

I'm surprised that the code you have leads compiled Ur/Web programs to 
pass the GCC type checker.  Your .urs file says that [Uw_process.exec] 
returns a [Uw_process.result], which translates into the C type 
'uw_Process_result'.  However, your prototype for [Uw_process_exec] 
gives the return type as 'uw_Process_result*', with an extra pointer 
level.  You should really define the type 'uw_Process_result' to be a 
pointer type in the first place.

> Right now I want to use it to outsource some jobs urweb can't do
> natively yet.
>    

I would instead recommend exposing application-specific C FFI functions 
that exhibit appropriate transactional behavior.  Exposing system() 
directly is just a bad idea.  It's obviously fine to use it internally 
within transactional functions.

> I'd love to add additional information such as "time out while waiting
> for cmd sleep 2h" which will be very helpful. But you don't expose ctx using
> the urweb.h file, do you? and the check function does not accept
> additional strings as parameters.
>    

I don't understand what you're trying to do.



More information about the Ur mailing list