Merge lp:~cjwatson/storm/fix-py3-cextensions into lp:storm

Proposed by Colin Watson
Status: Merged
Merged at revision: 534
Proposed branch: lp:~cjwatson/storm/fix-py3-cextensions
Merge into: lp:storm
Diff against target: 53 lines (+11/-2)
3 files modified
NEWS (+2/-0)
storm/cextensions.c (+8/-1)
tox.ini (+1/-1)
To merge this branch: bzr merge lp:~cjwatson/storm/fix-py3-cextensions
Reviewer Review Type Date Requested Status
Kristian Glass (community) Approve
Storm Developers Pending
Review via email: mp+373435@code.launchpad.net

Commit message

Fix C version of Compile.__call__(join=) on Python 3.

Description of the change

On Python 3, an "S" argument only takes bytes, but this parameter should only accept text. (It still accepts either bytes or text on Python 2.)

The reason this wasn't caught in tests was a little subtle. tox installs the C extension in a virtualenv, as you might expect; but, when running the test program, the storm package is imported from the same directory as the test program, and so it never actually finds any C extensions. The simplest workaround is to move the test program to a subdirectory, where no storm package exists and so it will be properly imported from the virtualenv.

To post a comment you must log in.
532. By Colin Watson

Fix C version of Compile.__call__(join=) on Python 3.

On Python 3, an "S" argument only takes bytes, but this parameter should
only accept text. (It still accepts either bytes or text on Python 2.)

The reason this wasn't caught in tests was a little subtle. tox installs
the C extension in a virtualenv, as you might expect; but, when running the
test program, the storm package is imported from the same directory as the
test program, and so it never actually finds any C extensions. The simplest
workaround is to move the test program to a subdirectory, where no storm
package exists and so it will be properly imported from the virtualenv.

Revision history for this message
Kristian Glass (doismellburning) wrote :

I'm not familiar with Python C extensions, but your change certainly makes sense in the context of having just read https://docs.python.org/3/c-api/arg.html#parsing-arguments

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2019-09-27 19:22:54 +0000
3+++ NEWS 2019-09-30 22:58:57 +0000
4@@ -5,6 +5,8 @@
5 ---------
6
7 - Fix incorrect caching of wrapped DB-API exceptions (bug 1845702).
8+- Fix incorrect expected type for the 'join' parameter to the C version of
9+ Compile.__call__ on Python 3.
10
11 0.21 (2019-09-20)
12 =================
13
14=== renamed file 'test' => 'dev/test'
15=== modified file 'storm/cextensions.c'
16--- storm/cextensions.c 2019-09-17 09:35:10 +0000
17+++ storm/cextensions.c 2019-09-30 22:58:57 +0000
18@@ -27,6 +27,7 @@
19 #if PY_VERSION_HEX >= 0x03000000
20 #define PyInt_FromLong PyLong_FromLong
21 #define PyText_AsString _PyUnicode_AsString
22+#define PyString_Check(o) 0
23 #define PyString_CheckExact(o) 0
24 #else
25 /* 2.x */
26@@ -1699,10 +1700,16 @@
27
28 join = default_compile_join;
29
30- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OSbb", kwlist,
31+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OObb", kwlist,
32 &expr, &state, &join, &raw, &token)) {
33 return NULL;
34 }
35+ if (join && (!PyString_Check(join) && !PyUnicode_Check(join))) {
36+ PyErr_Format(PyExc_TypeError,
37+ "'join' argument must be a string, not %.80s",
38+ Py_TYPE(join)->tp_name);
39+ return NULL;
40+ }
41
42 if (state == Py_None) {
43 state = PyObject_CallFunctionObjArgs(State, NULL);
44
45=== modified file 'tox.ini'
46--- tox.ini 2019-09-17 09:45:08 +0000
47+++ tox.ini 2019-09-30 22:58:57 +0000
48@@ -13,4 +13,4 @@
49 cextensions: STORM_CEXTENSIONS = 1
50 nocextensions: STORM_CEXTENSIONS = 0
51 commands =
52- python test {posargs}
53+ python dev/test {posargs}

Subscribers

People subscribed via source and target branches

to status/vote changes: