Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Str.string_match raising Invalid_argument "String.sub" in gc
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-08-23 (18:23)
From: Neale Pickett <neale-caml@w...>
Subject: Re: [Caml-list] Str.string_match raising Invalid_argument "String.sub" in gc
Alain Frisch writes:
> On 23 Aug 2001, Neale Pickett wrote:

>> If this is the case, why does Str.matched_group even bother requiring
>> the original string?

> Indeed, you shouldn't.

> The manual says:

> <<
> val matched_string: string -> string

> matched_string s returns the substring of s that was matched by the latest
> string_match, search_forward or search_backward. The user must make sure
> that the parameter s is the same string that was passed to the matching or
> searching function.
> >> 

> Note the "latest".

Yes, there it is; now I feel a little silly.

> The approach you suggest (that the library keeps a reference to the
> last matched string) is acceptable. I guess it was not implemented
> like that because this would prevent garbage collection of the last
> matched string.  (maybe a "release_internal_buffer" function would
> have been better)

Hmm.  I'm beginning to see the delimna.  I don't suppose there's an
exposed function that will return the memory address of the string,
either, but if there were, that could be used to keep track of what
string was last passed in.

Maybe the proper solution is to use Markus Mottl's PCRE-OCaml library

Thanks for your patience.  I understand a lot more about OCaml than I
did yesterday!

Bug reports:  FAQ:
To unsubscribe, mail  Archives: