hexchat / hexchat

GTK+ IRC client
https://hexchat.github.io
GNU General Public License v2.0
3.08k stars 538 forks source link

Python 2 interface: crash with sqllite3 module loaded #396

Open Ennea opened 11 years ago

Ennea commented 11 years ago

Hooking the "Your Message" and/or "Your Action" text events with xchat.hook_print(), then using xchat.command() to use the "SAY" and/or "ME" command (depending on which event you hooked, if not both) will crash HexChat. Using the command normally through the client works just fine, using it in any Python plugin after it has been hooked before will lead to a crash.

OS: Windows 7 x64 Professional HexChat 2.9.4 Python 2.7.3

Arnavion commented 11 years ago

Additional info from talking on IRC:

The crash only happens when calling xchat.command("SAY ...") from anywhere in any Python plugin, after one hook handler has been registered for "Your Message" (and similar for ME and Your Action). Specifically, the following do NOT crash:

  1. Hooking the event but not calling the command from Python.
  2. Hooking the event and calling the command from the textbox with /SAY or /ME. Hook does get called.
  3. Calling the command from Python but not hooking the event.
Ennea commented 11 years ago

Yup, I can confirm that what Arnavion says is correct. Test code I created to make sure my code was not the culprit:

import xchat
import sqlite3

__module_name__        = "Test"
__module_version__     = "1.0"
__module_description__ = "Let's try things!"

def TestFunc(word, wordEOL, userData):
      xchat.prnt("ACTION!")
      return xchat.EAT_NONE

def TestCmd(word, wordEOL, userData):
      xchat.command("ME test")
      return xchat.EAT_NONE

xchat.hook_print("Your Action", TestFunc)
xchat.hook_command("testpy", TestCmd)

If, in fact, this code is also faulty.. well, that'd be embarrassing.

TingPing commented 11 years ago

You made an infinite loop...

Er well looking at your example it isn't, but the description above sounds like it.

Trying your test script it works fine.

Arnavion commented 11 years ago

"Anywhere in any python plugin" == "not necessarily from within the hook itself"

TingPing commented 11 years ago

@Arnavion his example calls it from within another hook and it works if that's what you mean.

Arnavion commented 11 years ago

When I said "from anywhere in any python plugin" in my first comment, it was because the first thing I'd ruled out was that he was creating an infinite recursion.

He himself said "using it in any Python plugin" and I reinforced it, but you ignored it anyway.

Silly TingPing!

Ennea commented 11 years ago

Trying your test script it works fine.

Does it? It does not for me, I wonder why that is.. Also, not an infinite loop, obviously.

Edit: Sorry, apparently, that wasn't the issue. I should've tried running the test code with all other Python plugins disabled. The client will only crash with the test code when the plugin (or any other loaded one, for that matter) will also import the sqlite3 module. I added an import statement to the test code above, give it a spin.

TingPing commented 11 years ago

Still works for me.

Ennea commented 11 years ago

Doesn't for me. Any ideas what might be the issue, then? Because this is awkward..

Edit: Just for the record, client crashes when xchat.command() is called, so when using the created/hooked "testpy" command in this case.

Edit²: Another clarification: I'm using x86 Python and HexChat, running x64 Windows. A friend of mine tried my test code using x64 Python and HexChat and it worked. I'll give that a spin later.

94m3k1n9 commented 11 years ago

Obvious question: did you try it with the most recent version from git? Does your friend with x64 use 2.9.4 aswell?

Ennea commented 11 years ago

He was using the latest version from git. I'll give it a try later and keep you updated.

Ennea commented 11 years ago

Sorry for the long wait on the update. I gave it a try using the x64 version of both Python and HexChat. No problems there. So the issue only occurs when:

To conclude: my sample code above does crash HexChat, but only the x86 version of it. Using it together with Python x64 and HexChat x64 works perfectly fine.

Arnavion commented 11 years ago

Confirmed crash W7 x64 with x86 Hexchat 2.9.4.

Does not crash Linux x64 with x64 Hexchat ToT.

0xbad1d3a5 commented 11 years ago

I'm getting this problem too, except with Python 2.7.4 and HexChat 2.9.5, both x64 and on Windows 8.