Message49124
Logged In: YES
user_id=4771
The patch looks good, but I wonder if it is safe. The SRE_STATE structure that SRE_SEARCH_INNER uses is potentially visible to the application-level Python code, via the (undocumented) scanner objects:
>>> r = re.compile(r"hello")
>>> s = r.scanner("big string in which to search")
>>> s.search()
<_sre.SRE_Match object at 0x12345678>
Each call to s.search() continues the previous search with the same SRE_STATE. The problem with releasing the GIL as you do is that several threads could call s.search() concurrently, which would most probably crash CPython.
This probably means that you need to add a lock in SRE_STATE and acquire it while searching, to serialize its usage. Of course, we should then be careful about what overhead this gives to applications that use regexps on a lot of small strings...
Another note: for consistency, match() should also release the GIL if search() does. |
|
Date |
User |
Action |
Args |
2007-08-23 15:44:46 | admin | link | issue1366311 messages |
2007-08-23 15:44:46 | admin | create | |
|