Link Here
|
1 |
--- miltermodule.c.orig 2016-12-13 19:17:34 UTC |
|
|
2 |
+++ miltermodule.c |
3 |
@@ -343,7 +343,7 @@ static struct MilterCallback { |
4 |
{ NULL , NULL } |
5 |
}; |
6 |
|
7 |
-staticforward struct smfiDesc description; /* forward declaration */ |
8 |
+static struct smfiDesc description; /* forward declaration */ |
9 |
|
10 |
static PyObject *MilterError; |
11 |
/* The interpreter instance that called milter.main */ |
12 |
@@ -355,7 +355,7 @@ typedef struct { |
13 |
|
14 |
static milter_Diag diag; |
15 |
|
16 |
-staticforward PyTypeObject milter_ContextType; |
17 |
+static PyTypeObject milter_ContextType; |
18 |
|
19 |
typedef struct { |
20 |
PyObject_HEAD |
21 |
@@ -700,7 +700,7 @@ _generic_wrapper(milter_ContextObject *s |
22 |
result = PyEval_CallObject(cb, arglist); |
23 |
Py_DECREF(arglist); |
24 |
if (result == NULL) return _report_exception(self); |
25 |
- if (!PyInt_Check(result)) { |
26 |
+ if (!PyLong_Check(result)) { |
27 |
const struct MilterCallback *p; |
28 |
const char *cbname = "milter"; |
29 |
char buf[40]; |
30 |
@@ -715,7 +715,7 @@ _generic_wrapper(milter_ContextObject *s |
31 |
PyErr_SetString(MilterError,buf); |
32 |
return _report_exception(self); |
33 |
} |
34 |
- retval = PyInt_AS_LONG(result); |
35 |
+ retval = PyLong_AS_LONG(result); |
36 |
Py_DECREF(result); |
37 |
_release_thread(self->t); |
38 |
return retval; |
39 |
@@ -732,7 +732,7 @@ makeipaddr(struct sockaddr_in *addr) { |
40 |
sprintf(buf, "%d.%d.%d.%d", |
41 |
(int) (x>>24) & 0xff, (int) (x>>16) & 0xff, |
42 |
(int) (x>> 8) & 0xff, (int) (x>> 0) & 0xff); |
43 |
- return PyString_FromString(buf); |
44 |
+ return PyUnicode_FromString(buf); |
45 |
} |
46 |
|
47 |
#ifdef HAVE_IPV6_SUPPORT |
48 |
@@ -740,8 +740,8 @@ static PyObject * |
49 |
makeip6addr(struct sockaddr_in6 *addr) { |
50 |
char buf[100]; /* must be at least INET6_ADDRSTRLEN + 1 */ |
51 |
const char *s = inet_ntop(AF_INET6, &addr->sin6_addr, buf, sizeof buf); |
52 |
- if (s) return PyString_FromString(s); |
53 |
- return PyString_FromString("inet6:unknown"); |
54 |
+ if (s) return PyUnicode_FromString(s); |
55 |
+ return PyUnicode_FromString("inet6:unknown"); |
56 |
} |
57 |
#endif |
58 |
|
59 |
@@ -832,7 +832,7 @@ generic_env_wrapper(SMFICTX *ctx, PyObje |
60 |
for (i=0;i<count;i++) { |
61 |
/* There's some error checking performed in do_mkvalue() for a string */ |
62 |
/* that's not currently done here - it probably should be */ |
63 |
- PyObject *o = PyString_FromStringAndSize(argv[i], strlen(argv[i])); |
64 |
+ PyObject *o = PyUnicode_FromStringAndSize(argv[i], strlen(argv[i])); |
65 |
if (o == NULL) { /* out of memory */ |
66 |
Py_DECREF(arglist); |
67 |
return _report_exception(self); |
68 |
@@ -889,7 +889,7 @@ milter_wrap_body(SMFICTX *ctx, u_char *b |
69 |
c = _get_context(ctx); |
70 |
if (!c) return SMFIS_TEMPFAIL; |
71 |
/* Unclear whether this should be s#, z#, or t# */ |
72 |
- arglist = Py_BuildValue("(Os#)", c, bodyp, bodylen); |
73 |
+ arglist = Py_BuildValue("(Oy#)", c, bodyp, bodylen); |
74 |
return _generic_wrapper(c, body_callback, arglist); |
75 |
} |
76 |
|
77 |
@@ -963,7 +963,7 @@ milter_wrap_negotiate(SMFICTX *ctx, |
78 |
int i; |
79 |
for (i = 0; i < 4; ++i) { |
80 |
*pa[i] = (i <= len) |
81 |
- ? PyInt_AsUnsignedLongMask(PyList_GET_ITEM(optlist,i)) |
82 |
+ ? PyLong_AsUnsignedLongMask(PyList_GET_ITEM(optlist,i)) |
83 |
: fa[i]; |
84 |
} |
85 |
if (PyErr_Occurred()) { |
86 |
@@ -1551,11 +1551,6 @@ static PyMethodDef context_methods[] = { |
87 |
{ NULL, NULL } |
88 |
}; |
89 |
|
90 |
-static PyObject * |
91 |
-milter_Context_getattr(PyObject *self, char *name) { |
92 |
- return Py_FindMethod(context_methods, self, name); |
93 |
-} |
94 |
- |
95 |
static struct smfiDesc description = { /* Set some reasonable defaults */ |
96 |
"pythonfilter", |
97 |
SMFI_VERSION, |
98 |
@@ -1604,14 +1599,13 @@ static PyMethodDef milter_methods[] = { |
99 |
}; |
100 |
|
101 |
static PyTypeObject milter_ContextType = { |
102 |
- PyObject_HEAD_INIT(&PyType_Type) |
103 |
- 0, |
104 |
- "milterContext", |
105 |
+ PyVarObject_HEAD_INIT(&PyType_Type,0) |
106 |
+ "milter.Context", |
107 |
sizeof(milter_ContextObject), |
108 |
0, |
109 |
milter_Context_dealloc, /* tp_dealloc */ |
110 |
0, /* tp_print */ |
111 |
- milter_Context_getattr, /* tp_getattr */ |
112 |
+ 0, /* tp_getattr */ |
113 |
0, /* tp_setattr */ |
114 |
0, /* tp_compare */ |
115 |
0, /* tp_repr */ |
116 |
@@ -1625,6 +1619,13 @@ static PyTypeObject milter_ContextType = |
117 |
0, /* tp_setattro */ |
118 |
0, /* tp_as_buffer */ |
119 |
Py_TPFLAGS_DEFAULT, /* tp_flags */ |
120 |
+ NULL, /* Documentation string */ |
121 |
+ 0, /* call function for all accessible objects */ |
122 |
+ 0, /* delete references to contained objects */ |
123 |
+ 0, /* rich comparisons */ |
124 |
+ 0, /* weak reference enabler */ |
125 |
+ 0, 0, /* Iterators */ |
126 |
+ context_methods, /* Attribute descriptor and subclassing stuff */ |
127 |
}; |
128 |
|
129 |
static const char milter_documentation[] = |
130 |
@@ -1634,17 +1635,31 @@ Libmilter is currently marked FFR, and n |
131 |
See <sendmailsource>/libmilter/README for details on setting it up.\n"; |
132 |
|
133 |
static void setitem(PyObject *d,const char *name,long val) { |
134 |
- PyObject *v = PyInt_FromLong(val); |
135 |
+ PyObject *v = PyLong_FromLong(val); |
136 |
PyDict_SetItemString(d,name,v); |
137 |
Py_DECREF(v); |
138 |
} |
139 |
|
140 |
-void |
141 |
-initmilter(void) { |
142 |
+static struct PyModuleDef moduledef = { |
143 |
+ PyModuleDef_HEAD_INIT, |
144 |
+ "milter", /* m_name */ |
145 |
+ milter_documentation,/* m_doc */ |
146 |
+ -1, /* m_size */ |
147 |
+ milter_methods, /* m_methods */ |
148 |
+ NULL, /* m_reload */ |
149 |
+ NULL, /* m_traverse */ |
150 |
+ NULL, /* m_clear */ |
151 |
+ NULL, /* m_free */ |
152 |
+}; |
153 |
+ |
154 |
+PyMODINIT_FUNC PyInit_milter(void) { |
155 |
PyObject *m, *d; |
156 |
|
157 |
- m = Py_InitModule4("milter", milter_methods, milter_documentation, |
158 |
- (PyObject*)NULL, PYTHON_API_VERSION); |
159 |
+ if (PyType_Ready(&milter_ContextType) < 0) |
160 |
+ return NULL; |
161 |
+ |
162 |
+ m = PyModule_Create(&moduledef); |
163 |
+ if (m == NULL) return NULL; |
164 |
d = PyModule_GetDict(m); |
165 |
MilterError = PyErr_NewException("milter.error", NULL, NULL); |
166 |
PyDict_SetItemString(d,"error", MilterError); |
167 |
@@ -1710,4 +1725,5 @@ initmilter(void) { |
168 |
setitem(d,"DISCARD", SMFIS_DISCARD); |
169 |
setitem(d,"ACCEPT", SMFIS_ACCEPT); |
170 |
setitem(d,"TEMPFAIL", SMFIS_TEMPFAIL); |
171 |
+ return m; |
172 |
} |