Issue 19046: SystemError: ..\Objects\weakrefobject.c:903: bad argument to internal function (original) (raw)

I'm on 32 bit Python 2.7.3 and 64 bit Windows 7. I am working on a complex, multithreaded application which uses COM to communicate with other processes.

My application uses regular expressions in a few (but not very many) places. An example re I am trying to match is 'quit(\(.*\))?', an example input would be 'quit()'. Nothing exciting.

Very frustratingly, even though the regular expressions and inputs are the same, I spuriously get errors of the following form:

Traceback (most recent call last): ... File "re.pyc", line 137, in match SystemError: ..\Objects\weakrefobject.c:903: bad argument to internal function

I have seen the bug many times on 2.7.3. I briefly tried to reproduce it on 2.7.5 and it did not occur. This may be because the bug only occurs spuriously and I was unlucky, or because the bug no longer exists in 2.7.5. My (unverified) hunch is that the bug is not in 2.7.5 anymore.

I have a C unhandled exception handler installed in my application. What's interesting is that the bug frequently seems to occur together with an unhandled memory access violation (exception code C0000005). When this is the case, the Python interpreter hangs or crashes.

I have not seen similar crashes in my application at other points; only when working with regular expressions and seeing the above stack trace.