[mercury-users] unsafe_set_char

jc at cs.york.ac.uk jc at cs.york.ac.uk
Mon May 31 05:17:24 AEST 2010


Dear Julien and Paul,

Thanks for the info. I had already tried my own dirty method which is the
same as Julien's except it had fewer properties declared in the square
brackets. Weirdly, I also called it very_unsafe_set_char (I guess it's the
obvious choice of name!). Unfortunately both it and Julien's code have the
same problem. Compilation is fine, but we get a runtime error

cscipd001 ~/godot/research/srl/prism/abc abc

*** Mercury runtime: caught segmentation violation ***
PC at signal: -1222211540 (b726882c)
address involved: 0x80516a8
This may have been caused by a stack overflow, due to unbounded recursion.
exiting from signal handler

James

>
>> As for 'dirty' ways to acheive this, you could write your own foreign
>> code that uses distructive update.
>
> The following is equivalent to the commented out code in the library:
> (Although, it omits the check for the nul character.)
>
> :- pred very_unsafe_set_char(char::in, int::in, string::in, string::out)
>      is det.
>
> :- pragma foreign_proc("C",
>      very_unsafe_set_char(Ch::in, Index::in, Str0::in, Str::out),
>      [will_not_call_mercury, promise_pure, thread_safe,
>       will_not_modify_trail, does_not_affect_liveness],
> "
>      Str = Str0;
>      MR_set_char(Str, Index, Ch);
> ").
>
> Julien.
> --------------------------------------------------------------------------
> mercury-users mailing list
> Post messages to:       mercury-users at csse.unimelb.edu.au
> Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
> Subscriptions:          mercury-users-request at csse.unimelb.edu.au
> --------------------------------------------------------------------------
>


--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list