INN commit: trunk (4 files)
INN Commit
rra at isc.org
Mon Nov 1 15:56:35 UTC 2010
Date: Monday, November 1, 2010 @ 08:56:35
Author: iulius
Revision: 9147
Fixed an issue in the Python access hook for nnrpd: it has not been working
since Python 2.5 on 64-bit platforms, owing to a change to Python's C API,
using a new Py_ssize_t type definition instead of int.
Thanks to Raphael Barrois for the patch.
Define Py_ssize_t as an int for Python versions < 2.5.0.
Also include Python.h before any standard headers are included, because
"Python may define some pre-processor definitions which affect the standard
headers on some systems".
Modified:
trunk/CONTRIBUTORS
trunk/doc/pod/news.pod
trunk/innd/python.c
trunk/nnrpd/python.c
------------------+
CONTRIBUTORS | 2 +-
doc/pod/news.pod | 7 +++++++
innd/python.c | 48 +++++++++++++++++++++++++++++++-----------------
nnrpd/python.c | 34 ++++++++++++++++++++++++----------
4 files changed, 63 insertions(+), 28 deletions(-)
Modified: CONTRIBUTORS
===================================================================
--- CONTRIBUTORS 2010-10-30 09:55:04 UTC (rev 9146)
+++ CONTRIBUTORS 2010-11-01 15:56:35 UTC (rev 9147)
@@ -273,4 +273,4 @@
Steve Crook, John F. Morse, Tim Woodall, Jonathan Kamens, Kamil Jonca,
S.P. Zeidler, Nix, Florian Schlichting, Torsten Jerzembeck, Harald Dunkel,
Lars Magne Ingebrigtsen, Sam Varshavchik, Matthew Vernon, Ian Jackson,
-Edmund H. Ramm
+Edmund H. Ramm, Raphael Barrois
Modified: doc/pod/news.pod
===================================================================
--- doc/pod/news.pod 2010-10-30 09:55:04 UTC (rev 9146)
+++ doc/pod/news.pod 2010-11-01 15:56:35 UTC (rev 9147)
@@ -176,6 +176,13 @@
=item *
+Fixed an issue in the Python access hook for B<nnrpd>: it has not been
+working since S<Python 2.5> on 64-bit platforms, owing to a change to
+Python's C API, using a new Py_ssize_t type definition instead of int.
+Thanks to Raphael Barrois for the patch.
+
+=item *
+
The Injection-Date: header, when present, is now used by B<innd> and
B<makehistory> to determine the posting date of an article. Otherwise,
the Date: header is used.
Modified: innd/python.c
===================================================================
--- innd/python.c 2010-10-30 09:55:04 UTC (rev 9146)
+++ innd/python.c 2010-11-01 15:56:35 UTC (rev 9147)
@@ -19,19 +19,32 @@
*/
#include "config.h"
-#include "clibrary.h"
-#include "inn/innconf.h"
-#include "inn/wire.h"
-#include "innd.h"
-
-
#ifdef DO_PYTHON
/* Python redefines _POSIX_C_SOURCE, so undef it to suppress warnings. */
#undef _POSIX_C_SOURCE
+
+/* Make "s#" use Py_ssize_t rather than int. */
+#define PY_SSIZE_T_CLEAN
+
+/* Python.h must be included after having defined PY_SSIZE_T_CLEAN,
+ * and before any standard headers are included (because Python may
+ * define some pre-processor definitions which affect the standard
+ * headers on some systems). */
#include "Python.h"
+/* Define Py_ssize_t when it does not exist (Python < 2.5.0). */
+#if PY_VERSION_HEX < 0x02050000
+ typedef int Py_ssize_t;
+#endif
+
+#include "clibrary.h"
+
+#include "inn/innconf.h"
+#include "inn/wire.h"
+#include "innd.h"
+
bool PythonFilterActive;
char *filterPath; /* This gets set in art.c. */
PyObject *PYFilterObject = NULL;
@@ -249,7 +262,7 @@
PY_havehist(PyObject *self UNUSED, PyObject *args)
{
char *msgid;
- int msgidlen;
+ Py_ssize_t msgidlen;
if (!PyArg_ParseTuple(args, (char *) "s#", &msgid, &msgidlen))
return NULL;
@@ -268,7 +281,7 @@
PY_cancel(PyObject *self UNUSED, PyObject *args)
{
char *msgid;
- int msgidlen;
+ Py_ssize_t msgidlen;
char *parambuf[2];
if (!PyArg_ParseTuple(args, (char *) "s#", &msgid, &msgidlen))
@@ -291,7 +304,7 @@
PY_addhist(PyObject *self UNUSED, PyObject *args)
{
char *msgid;
- int msgidlen;
+ Py_ssize_t msgidlen;
char *articlepaths = (char *) "";
char tbuff[12];
char *parambuf[6];
@@ -320,7 +333,7 @@
PY_newsgroup(PyObject *self UNUSED, PyObject *args)
{
char *newsgroup;
- int nglen;
+ Py_ssize_t nglen;
NEWSGROUP *ngp;
char *end;
int size;
@@ -359,7 +372,7 @@
PY_head(PyObject *self UNUSED, PyObject *args)
{
char *msgid;
- int msgidlen;
+ Py_ssize_t msgidlen;
char *p;
TOKEN token;
ARTHANDLE *art;
@@ -390,7 +403,7 @@
PY_article(PyObject *self UNUSED, PyObject *args)
{
char *msgid;
- int msgidlen;
+ Py_ssize_t msgidlen;
char *p;
TOKEN token;
ARTHANDLE *arth;
@@ -423,9 +436,9 @@
PY_syslog(PyObject *self UNUSED, PyObject *args)
{
char *loglevel;
- int levellen;
+ Py_ssize_t levellen;
char *logmsg;
- int msglen;
+ Py_ssize_t msglen;
int priority;
/* Get loglevel and message. */
@@ -463,7 +476,8 @@
{
char *instring, *wpos, *p, *q;
char *workstring = NULL;
- int insize, worksize, newsize, i, wasspace;
+ Py_ssize_t insize;
+ int worksize, newsize, i, wasspace;
int lines = 0;
HASH myhash;
@@ -472,7 +486,7 @@
/* If a linecount is provided, munge before hashing. */
if (lines > 0) {
- worksize = insize;
+ worksize = (int) insize;
/* Chop leading whitespace. */
for (p=instring ; worksize>0 && isspace((unsigned char) *p) ; p++) {
@@ -522,7 +536,7 @@
free(workstring);
}
else
- myhash = Hash(instring, insize);
+ myhash = Hash(instring, (int) insize);
return PyString_FromStringAndSize((const char *)&myhash, sizeof(myhash));
}
Modified: nnrpd/python.c
===================================================================
--- nnrpd/python.c 2010-10-30 09:55:04 UTC (rev 9146)
+++ nnrpd/python.c 2010-11-01 15:56:35 UTC (rev 9147)
@@ -20,19 +20,32 @@
*/
#include "config.h"
-#include "clibrary.h"
-#include "inn/innconf.h"
-#include "nnrpd.h"
-#include "inn/hashtab.h"
-
-
#ifdef DO_PYTHON
/* Python redefines _POSIX_C_SOURCE, so undef it to suppress warnings. */
#undef _POSIX_C_SOURCE
+
+/* Make "s#" use Py_ssize_t rather than int. */
+#define PY_SSIZE_T_CLEAN
+
+/* Python.h must be included after having defined PY_SSIZE_T_CLEAN,
+ * and before any standard headers are included (because Python may
+ * define some pre-processor definitions which affect the standard
+ * headers on some systems). */
#include "Python.h"
+/* Define Py_ssize_t when it does not exist (Python < 2.5.0). */
+#if PY_VERSION_HEX < 0x02050000
+ typedef int Py_ssize_t;
+#endif
+
+#include "clibrary.h"
+
+#include "inn/innconf.h"
+#include "nnrpd.h"
+#include "inn/hashtab.h"
+
/* Values relate name of hook to array index. */
#define PYTHONauthen 1
#define PYTHONaccess 2
@@ -250,6 +263,7 @@
char *buffer;
int authnum;
int i;
+ Py_ssize_t pos;
PY_load_python();
proc = PY_setup(PYTHONaccess, PYTHONmain, file);
@@ -312,17 +326,17 @@
vector_resize(access_vec, PyDict_Size(result) - 1);
/* Store dict values in proper format in access vector. */
- i = 0;
+ pos = 0;
buffer = xmalloc(BIG_BUFFER);
- while(PyDict_Next(result, &i, &key, &value)) {
+ while(PyDict_Next(result, &pos, &key, &value)) {
if (!PyString_Check(key)) {
- syslog(L_ERROR, "python access method return dictionary key %i not a string", i);
+ syslog(L_ERROR, "python access method return dictionary key %d not a string", pos);
Reply("%d Internal error (2). Goodbye!\r\n", NNTP_FAIL_TERMINATING);
ExitWithStats(1, false);
}
if (!PyString_Check(value)) {
- syslog(L_ERROR, "python access method return dictionary value %i not a string", i);
+ syslog(L_ERROR, "python access method return dictionary value %d not a string", pos);
Reply("%d Internal error (2). Goodbye!\r\n", NNTP_FAIL_TERMINATING);
ExitWithStats(1, false);
}
More information about the inn-committers
mailing list