1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
diff --git a/Makefile b/Makefile
index c59461b..eef2c2a 100644
--- a/bundles/pyml/pyml-current/Makefile
+++ b/bundles/pyml/pyml-current/Makefile
@@ -207,13 +207,13 @@ test : test.bytecode $(TESTOPT)
.PHONY : test.bytecode
test.bytecode : pyml_tests.bytecode numpy_tests.bytecode
- ./pyml_tests.bytecode
- ./numpy_tests.bytecode
+ ./pyml_tests.bytecode $(TEST_OPTIONS)
+ ./numpy_tests.bytecode $(TEST_OPTIONS)
.PHONY : test.native
test.native : pyml_tests.native numpy_tests.native
- ./pyml_tests.native
- ./numpy_tests.native
+ ./pyml_tests.native $(TEST_OPTIONS)
+ ./numpy_tests.native $(TEST_OPTIONS)
.PHONY : install
install : $(INSTALL_FILES)
diff --git a/pyml_stubs.c b/pyml_stubs.c
index 149695c..40e3481 100644
--- a/bundles/pyml/pyml-current/pyml_stubs.c
+++ b/bundles/pyml/pyml-current/pyml_stubs.c
@@ -136,8 +136,6 @@ file_of_file_descr(value file_descr, const char *mode)
}
#endif
-static void *Python27__PyObject_NextNotImplemented;
-
/* Global variables for the library */
/* version_major != 0 iff the library is initialized */
@@ -743,15 +741,18 @@ guess_debug_build()
PyObject *debug_build_py;
char *py_debug_str = "Py_DEBUG";
if (version_major >= 3) {
- py_debug = Python3_PyUnicode_FromStringAndSize(py_debug_str, 8);
+ py_debug = Python3_PyUnicode_FromStringAndSize(py_debug_str, strlen(py_debug_str));
}
else {
- py_debug = Python2_PyString_FromStringAndSize(py_debug_str, 8);
+ py_debug = Python2_PyString_FromStringAndSize(py_debug_str, strlen(py_debug_str));
}
assert(py_debug);
args = singleton(py_debug);
debug_build_py = Python_PyObject_Call(get_config_var, args, NULL);
- assert(debug_build_py);
+ if (!debug_build_py) {
+ Python_PyErr_Print();
+ caml_failwith("Cannot check for debug build");
+ }
if (debug_build_py == Python__Py_NoneStruct) {
debug_build = 0;
}
@@ -797,8 +798,6 @@ py_load_library(value filename_ocaml, value debug_build_ocaml)
Python27_PyCapsule_New = resolve("PyCapsule_New");
Python27_PyCapsule_GetPointer = resolve("PyCapsule_GetPointer");
Python27_PyCapsule_IsValid = resolve("PyCapsule_IsValid");
- Python27__PyObject_NextNotImplemented =
- resolve("_PyObject_NextNotImplemented");
}
Python_PyObject_CallFunctionObjArgs =
resolve("PyObject_CallFunctionObjArgs");
@@ -970,6 +969,17 @@ enum pytype_labels {
Set
};
+static bool is_iterable(PyObject *obj) {
+ PyObject *iter = Python_PyObject_GetIter(obj);
+ if (iter) {
+ Py_DECREF(iter);
+ return true;
+ } else {
+ Python_PyErr_Clear();
+ return false;
+ }
+}
+
CAMLprim value
pytype(value object_ocaml)
{
@@ -1035,8 +1045,7 @@ pytype(value object_ocaml)
else if (ob_type == Python_PySet_Type) {
result = Set;
}
- else if (typeobj->tp_iternext != NULL &&
- typeobj->tp_iternext != &Python27__PyObject_NextNotImplemented) {
+ else if (is_iterable(object)) {
result = Iter;
}
else {
|