diff options
author | Christopher Davis <loafier@gmail.com> | 2006-08-12 21:58:42 +0000 |
---|---|---|
committer | Christopher Davis <loafier@gmail.com> | 2006-08-12 21:58:42 +0000 |
commit | f13ea25509e932d426ebd69d90368fe9b1d4c1ab (patch) | |
tree | 98883c3fd1c4e7912320ba0013a851bfde9133cc | |
parent | b1b54c58af7cd9419631d7b82b860a7b19097836 (diff) | |
download | irssi-python-f13ea25509e932d426ebd69d90368fe9b1d4c1ab.tar.gz irssi-python-f13ea25509e932d426ebd69d90368fe9b1d4c1ab.tar.xz irssi-python-f13ea25509e932d426ebd69d90368fe9b1d4c1ab.zip |
added support for constants
git-svn-id: http://svn.irssi.org/repos/irssi-python@4311 dbcabf3a-b0e7-0310-adc4-f8d773084564
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | constants.awk | 12 | ||||
-rw-r--r-- | constants.txt | 8 | ||||
-rw-r--r-- | irssi.py | 30 | ||||
-rw-r--r-- | objects/base-objects.c | 152 | ||||
-rw-r--r-- | objects/irc-server-object.c | 4 | ||||
-rw-r--r-- | objects/main-window-object.c | 2 | ||||
-rw-r--r-- | pyconstants.h | 55 | ||||
-rw-r--r-- | pycore.c | 2 | ||||
-rw-r--r-- | pyirssi.h | 1 | ||||
-rw-r--r-- | pyirssi_irc.h | 1 | ||||
-rw-r--r-- | pymodule.c | 6 |
12 files changed, 101 insertions, 176 deletions
@@ -12,7 +12,7 @@ CFLAGS = -fpic -ggdb -Wall -I$(PYTHON) -I$(IRSSI) -I$(IRSSI)/src \ LDFLAGS = -fpic /usr/lib/libpython2.4.so OBJ = pycore.o pyutils.o pymodule.o pyloader.o pysignals.o pysource.o \ -pythemes.o pystatusbar.o +pythemes.o pystatusbar.o pyconstants.o pyirssi: pyobjects.a $(OBJ) $(CC) -shared -o libirssi_python.so $(OBJ) objects/pyobjects.a $(LDFLAGS) @@ -27,7 +27,7 @@ signalmap: awk -f sig2code.awk ~/irssi-0.8.10/docs/signals.txt > pysigmap.h constants: - awk -f constants.awk constants.txt > pyconstants.h + awk -f constants.awk constants.txt > pyconstants.c clean: rm -f *.o *.so diff --git a/constants.awk b/constants.awk index 18f8002..3aa5034 100644 --- a/constants.awk +++ b/constants.awk @@ -1,5 +1,9 @@ BEGIN { - print "static PY_CONSTANT_REC py_constants[] = {"; + print "#include \"pymodule.h\""; + print "#include \"pyirssi_irc.h\""; + print + print "void pyconstants_init(void)" + print "{" } { @@ -8,11 +12,9 @@ BEGIN { else constant = $1; - printf(" {\"%s\", %25s},\n", $1, constant); + printf(" PyModule_AddIntConstant(py_module, \"%s\", %s);\n", $1, constant); } END { - print " {NULL}"; - print "};" + print "}" } - diff --git a/constants.txt b/constants.txt index c65b779..a3b8917 100644 --- a/constants.txt +++ b/constants.txt @@ -9,10 +9,10 @@ IRSSI_GUI_KDE IRSSI_GUI_NONE IRSSI_GUI_QT IRSSI_GUI_TEXT -MASK_DOMAIN -MASK_HOST -MASK_NICK -MASK_USER +IRC_MASK_DOMAIN +IRC_MASK_HOST +IRC_MASK_NICK +IRC_MASK_USER MSGLEVEL_ACTIONS MSGLEVEL_ALL MSGLEVEL_CLIENTCRAP @@ -5,36 +5,6 @@ import sys import _irssi from _irssi import * -#XXX: what if the values change? (better to compile in constants?) -#Level constants (coppied from levels.h valid Irssi 0.8.10) -MSGLEVEL_CRAP = 0x0000001 -MSGLEVEL_MSGS = 0x0000002 -MSGLEVEL_PUBLIC = 0x0000004 -MSGLEVEL_NOTICES = 0x0000008 -MSGLEVEL_SNOTES = 0x0000010 -MSGLEVEL_CTCPS = 0x0000020 -MSGLEVEL_ACTIONS = 0x0000040 -MSGLEVEL_JOINS = 0x0000080 -MSGLEVEL_PARTS = 0x0000100 -MSGLEVEL_QUITS = 0x0000200 -MSGLEVEL_KICKS = 0x0000400 -MSGLEVEL_MODES = 0x0000800 -MSGLEVEL_TOPICS = 0x0001000 -MSGLEVEL_WALLOPS = 0x0002000 -MSGLEVEL_INVITES = 0x0004000 -MSGLEVEL_NICKS = 0x0008000 -MSGLEVEL_DCC = 0x0010000 -MSGLEVEL_DCCMSGS = 0x0020000 -MSGLEVEL_CLIENTNOTICE = 0x0040000 -MSGLEVEL_CLIENTCRAP = 0x0080000 -MSGLEVEL_CLIENTERROR = 0x0100000 -MSGLEVEL_HILIGHT = 0x0200000 -MSGLEVEL_ALL = 0x03fffff -MSGLEVEL_NOHILIGHT = 0x1000000 -MSGLEVEL_NO_ACT = 0x2000000 -MSGLEVEL_NEVER = 0x4000000 -MSGLEVEL_LASTLOG = 0x8000000 - def command_bind(*args, **kwargs): """ see Script.command_bind """ get_script().command_bind(*args, **kwargs) diff --git a/objects/base-objects.c b/objects/base-objects.c index 3601593..42f5cac 100644 --- a/objects/base-objects.c +++ b/objects/base-objects.c @@ -4,25 +4,17 @@ #include "base-objects.h" #include "pyirssi.h" -/* This is the base type for most, if not all, Irssi objects with a type - id. The user can find the type name, type id, and check if the object is - wrapping a valid Irssi record. */ - -/* member IDs */ -enum -{ - M_BASE_TYPE, - M_BASE_NAME, - M_BASE_VALID, -}; +/* This is the base type for Irssi objects with a type id. The user can find + * the type name, type id, and check if the object is wrapping a valid Irssi + * record. + */ static void PyIrssiBase_dealloc(PyIrssiBase *self) { self->ob_type->tp_free((PyObject*)self); } -static PyObject * -PyIrssiBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static PyObject *PyIrssiBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyIrssiBase *self; @@ -33,50 +25,50 @@ PyIrssiBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return (PyObject *)self; } -static PyObject *PyIrssiBase_get(PyIrssiBase *self, void *closure) +/* Getters */ +PyDoc_STRVAR(PyIrssiBase_type_id_doc, + "Irssi's type id for object" +); +static PyObject *PyIrssiBase_type_id_get(PyIrssiBase *self, void *closure) { - int member = GPOINTER_TO_INT(closure); - - /* If the user passed the valid member, don't trigger an exception */ - if (member != M_BASE_VALID) - RET_NULL_IF_INVALID(self->data); - - switch (member) - { - case M_BASE_TYPE: - return PyInt_FromLong(self->data->type); - case M_BASE_NAME: - RET_AS_STRING_OR_NONE(self->base_name); - case M_BASE_VALID: - if (self->data != NULL) - Py_RETURN_TRUE; - else - Py_RETURN_FALSE; - } - - INVALID_MEMBER(member); + RET_NULL_IF_INVALID(self->data); + return PyInt_FromLong(self->data->type); } -/* specialized getters/setters */ -static PyGetSetDef PyIrssiBase_getseters[] = { - {"type_id", (getter)PyIrssiBase_get, NULL, - "Irssi's type id for object", - GINT_TO_POINTER(M_BASE_TYPE)}, +PyDoc_STRVAR(PyIrssiBase_type_doc, + "Irssi's name for object" +); +static PyObject *PyIrssiBase_type_get(PyIrssiBase *self, void *closure) +{ + RET_NULL_IF_INVALID(self->data); + RET_AS_STRING_OR_NONE(self->base_name); +} - {"type", (getter)PyIrssiBase_get, NULL, - "Irssi's name for object", - GINT_TO_POINTER(M_BASE_NAME)}, +PyDoc_STRVAR(PyIrssiBase_valid_doc, + "True if the object is valid" +); +static PyObject *PyIrssiBase_valid_get(PyIrssiBase *self, void *closure) +{ + if (self->data != NULL) + Py_RETURN_TRUE; + + Py_RETURN_FALSE; +} - {"valid", (getter)PyIrssiBase_get, NULL, - "True if the object is valid", - GINT_TO_POINTER(M_BASE_VALID)}, +/* specialized getters/setters */ +static PyGetSetDef PyIrssiBase_getseters[] = { + {"type_id", (getter)PyIrssiBase_type_id_get, NULL, + PyIrssiBase_type_id_doc, NULL}, + {"type", (getter)PyIrssiBase_type_get, NULL, + PyIrssiBase_type_doc, NULL}, + {"valid", (getter)PyIrssiBase_valid_get, NULL, + PyIrssiBase_valid_doc, NULL}, {NULL} }; /* Methods for object */ static PyMethodDef PyIrssiBase_methods[] = { - /* {"somemeth", (PyCFunction)PyIrssiBase_name, METH_NOARGS, "docstr"}, */ - {NULL} /* Sentinel */ + {NULL} }; PyTypeObject PyIrssiBaseType = { @@ -127,21 +119,12 @@ PyTypeObject PyIrssiBaseType = { the type id with the chat_type_id member. It inherits from IrssiBase so the type, valid, and type_id members are visible to the user, too */ -/* member IDs */ -enum -{ - M_CHAT_CHAT_TYPE, - M_CHAT_CHAT_NAME, -}; - -static void -PyIrssiChatBase_dealloc(PyIrssiChatBase *self) +static void PyIrssiChatBase_dealloc(PyIrssiChatBase *self) { self->ob_type->tp_free((PyObject*)self); } -static PyObject * -PyIrssiChatBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static PyObject *PyIrssiChatBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyIrssiChatBase *self; @@ -152,43 +135,44 @@ PyIrssiChatBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds) return (PyObject *)self; } -static PyObject *PyIrssiChatBase_get(PyIrssiChatBase *self, void *closure) +/* Getters */ +PyDoc_STRVAR(PyIrssiChatBase_chat_type_id_doc, + "Chat Type id (int)" +); +static PyObject *PyIrssiChatBase_chat_type_id_get(PyIrssiChatBase *self, void *closure) { - int member = GPOINTER_TO_INT(closure); + RET_NULL_IF_INVALID(self->data); + return PyInt_FromLong(self->data->chat_type); +} + +PyDoc_STRVAR(PyIrssiChatBase_chat_type_doc, + "Chat name (str)" +); +static PyObject *PyIrssiChatBase_chat_type_get(PyIrssiChatBase *self, void *closure) +{ + CHAT_PROTOCOL_REC *rec; RET_NULL_IF_INVALID(self->data); - switch (member) - { - case M_CHAT_CHAT_TYPE: - return PyInt_FromLong(self->data->chat_type); - case M_CHAT_CHAT_NAME: - { - CHAT_PROTOCOL_REC *rec = chat_protocol_find_id(self->data->chat_type); - if (rec) - RET_AS_STRING_OR_NONE(rec->name); - else - Py_RETURN_NONE; - } - } - - INVALID_MEMBER(member); + rec = chat_protocol_find_id(self->data->chat_type); + if (rec) + RET_AS_STRING_OR_NONE(rec->name); + else + Py_RETURN_NONE; } -//specialized getters/setters +/* specialized getters/setters */ static PyGetSetDef PyIrssiChatBase_getseters[] = { - {"chat_type_id", (getter)PyIrssiChatBase_get, NULL, - "Chat Type id", - GINT_TO_POINTER(M_CHAT_CHAT_TYPE)}, - - {"chat_type", (getter)PyIrssiChatBase_get, NULL, - "Chat Name", - GINT_TO_POINTER(M_CHAT_CHAT_NAME)}, + {"chat_type_id", (getter)PyIrssiChatBase_chat_type_id_get, NULL, + PyIrssiChatBase_chat_type_id_doc, NULL}, + {"chat_type", (getter)PyIrssiChatBase_chat_type_get, NULL, + PyIrssiChatBase_chat_type_doc, NULL}, {NULL} }; +/* Methods */ static PyMethodDef PyIrssiChatBase_methods[] = { - {NULL} /* Sentinel */ + {NULL} }; PyTypeObject PyIrssiChatBaseType = { diff --git a/objects/irc-server-object.c b/objects/irc-server-object.c index a8d9845..4e9a28e 100644 --- a/objects/irc-server-object.c +++ b/objects/irc-server-object.c @@ -282,7 +282,9 @@ static GSList *py_event_conv(PyObject *list) for (node = ret; node; node = node->next) g_free(node->data); - + + g_slist_free(ret); + if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_TypeError)) { PyErr_Clear(); diff --git a/objects/main-window-object.c b/objects/main-window-object.c index 331cef6..6541f2b 100644 --- a/objects/main-window-object.c +++ b/objects/main-window-object.c @@ -173,7 +173,7 @@ PyObject *pymain_window_new(MAIN_WINDOW_REC *mw) pymw = py_inst(PyMainWindow, PyMainWindowType); if (!pymw) { - Py_XDECREF(pyactive); + Py_DECREF(pyactive); return NULL; } diff --git a/pyconstants.h b/pyconstants.h index e196236..f898ded 100644 --- a/pyconstants.h +++ b/pyconstants.h @@ -1,48 +1,7 @@ -static PY_CONSTANT_REC py_constants[] = { - {"IO_IN", G_IO_IN}, - {"IO_OUT", G_IO_OUT}, - {"IO_PRI", G_IO_PRI}, - {"IO_ERR", G_IO_ERR}, - {"IO_HUP", G_IO_HUP}, - {"IRSSI_GUI_GNOME", IRSSI_GUI_GNOME}, - {"IRSSI_GUI_GTK", IRSSI_GUI_GTK}, - {"IRSSI_GUI_KDE", IRSSI_GUI_KDE}, - {"IRSSI_GUI_NONE", IRSSI_GUI_NONE}, - {"IRSSI_GUI_QT", IRSSI_GUI_QT}, - {"IRSSI_GUI_TEXT", IRSSI_GUI_TEXT}, - {"MASK_DOMAIN", MASK_DOMAIN}, - {"MASK_HOST", MASK_HOST}, - {"MASK_NICK", MASK_NICK}, - {"MASK_USER", MASK_USER}, - {"MSGLEVEL_ACTIONS", MSGLEVEL_ACTIONS}, - {"MSGLEVEL_ALL", MSGLEVEL_ALL}, - {"MSGLEVEL_CLIENTCRAP", MSGLEVEL_CLIENTCRAP}, - {"MSGLEVEL_CLIENTERROR", MSGLEVEL_CLIENTERROR}, - {"MSGLEVEL_CLIENTNOTICE", MSGLEVEL_CLIENTNOTICE}, - {"MSGLEVEL_CRAP", MSGLEVEL_CRAP}, - {"MSGLEVEL_CTCPS", MSGLEVEL_CTCPS}, - {"MSGLEVEL_DCC", MSGLEVEL_DCC}, - {"MSGLEVEL_DCCMSGS", MSGLEVEL_DCCMSGS}, - {"MSGLEVEL_HILIGHT", MSGLEVEL_HILIGHT}, - {"MSGLEVEL_INVITES", MSGLEVEL_INVITES}, - {"MSGLEVEL_JOINS", MSGLEVEL_JOINS}, - {"MSGLEVEL_KICKS", MSGLEVEL_KICKS}, - {"MSGLEVEL_LASTLOG", MSGLEVEL_LASTLOG}, - {"MSGLEVEL_MODES", MSGLEVEL_MODES}, - {"MSGLEVEL_MSGS", MSGLEVEL_MSGS}, - {"MSGLEVEL_NEVER", MSGLEVEL_NEVER}, - {"MSGLEVEL_NICKS", MSGLEVEL_NICKS}, - {"MSGLEVEL_NO_ACT", MSGLEVEL_NO_ACT}, - {"MSGLEVEL_NOHILIGHT", MSGLEVEL_NOHILIGHT}, - {"MSGLEVEL_NOTICES", MSGLEVEL_NOTICES}, - {"MSGLEVEL_PARTS", MSGLEVEL_PARTS}, - {"MSGLEVEL_PUBLIC", MSGLEVEL_PUBLIC}, - {"MSGLEVEL_QUITS", MSGLEVEL_QUITS}, - {"MSGLEVEL_SNOTES", MSGLEVEL_SNOTES}, - {"MSGLEVEL_TOPICS", MSGLEVEL_TOPICS}, - {"MSGLEVEL_WALLOPS", MSGLEVEL_WALLOPS}, - {"SIGNAL_PRIORITY_DEFAULT", SIGNAL_PRIORITY_DEFAULT}, - {"SIGNAL_PRIORITY_HIGH", SIGNAL_PRIORITY_HIGH}, - {"SIGNAL_PRIORITY_LOW", SIGNAL_PRIORITY_LOW}, - {NULL} -}; +#ifndef _PYCONSTANTS_H_ +#define _PYCONSTANTS_H_ + +void pyconstants_init(void); + +#endif + @@ -9,6 +9,7 @@ #include "pysignals.h" #include "pythemes.h" #include "pystatusbar.h" +#include "pyconstants.h" #include "factory.h" /*XXX: copy parse into utils */ @@ -126,6 +127,7 @@ void irssi_python_init(void) printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Failed to load Python"); return; } + pyconstants_init(); /*PyImport_ImportModule("irssi_startup");*/ /* Install the custom output handlers, import hook and reload function */ @@ -3,6 +3,7 @@ #define MODULE_NAME "irssi_python" #include "config.h" +#include "core.h" #include "common.h" #include "modules.h" #include "commands.h" diff --git a/pyirssi_irc.h b/pyirssi_irc.h index 1d654ba..0ebd617 100644 --- a/pyirssi_irc.h +++ b/pyirssi_irc.h @@ -15,5 +15,6 @@ #include "dcc-chat.h" #include "netsplit.h" #include "notifylist.h" +#include "irc-masks.h" #endif @@ -825,7 +825,7 @@ static PyObject *py_notifylist_remove(PyObject *self, PyObject *args, PyObject * } PyDoc_STRVAR(py_notifylist_ison_doc, - "notifylist_ison(nick, serverlist="") -> IrcServer object\n" + "notifylist_ison(nick, serverlist=\"\") -> IrcServer object\n" "\n" "Check if nick is in IRC. serverlist is a space separated list of server tags.\n" "If it's empty string, all servers will be checked\n" @@ -1666,6 +1666,10 @@ error: for (node = gopt; node; node = node->next->next) g_free(node->data); + g_slist_free(gstart); + g_slist_free(gstop); + g_slist_free(gopt); + return NULL; } |