[mercury-users] unsafe_set_char

jc at cs.york.ac.uk jc at cs.york.ac.uk
Mon May 31 17:47:04 AEST 2010


Dear Julien,

Yup, that fixed it. Many thanks.

James

>
> Hi,
>
> On Sun, 30 May 2010 jc at cs.york.ac.uk wrote:
>
>> 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
>
> I suspect you are attempting to modify a string stored as static data,
> i.e. you are encountering the issue that caused the unique mode to be
> disabled in the first place.
>
> The following definition does a check for whether something a string
> is stored on the heap.  If the above is indeed the problem, then it
> should fix it.
>
> :- pragma foreign_proc("C",
>     very_unsafe_set_char(Ch::in, Index::in, Str0::di, Str::uo),
>     [will_not_call_mercury, promise_pure, thread_safe,
> does_not_affect_liveness],
> "
>     if (MR_in_heap_range(Str0)) {
>         Str = Str0;
>         MR_set_char(Str, Index, Ch);
>     } else {
>         size_t len = strlen(Str0);
>         MR_allocate_aligned_string_msg(Str, len, MR_PROC_LABEL);
>         strcpy(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