Commit | Line | Data |
---|---|---|
7f339edd C |
1 | diff -ru /tmp/chemoelectric-pycaml-8614105/pycaml.ml ./chemoelectric-pycaml-8614105/pycaml.ml |
2 | --- /tmp/chemoelectric-pycaml-8614105/pycaml.ml 2011-10-01 02:05:57.000000000 +0200 | |
3 | +++ ./chemoelectric-pycaml-8614105/pycaml.ml 2012-06-24 14:00:29.004094271 +0200 | |
4 | @@ -178,9 +178,11 @@ | |
5 | external pymethod_class : pyobject -> pyobject = "PyMethod_Class_wrapper" | |
6 | END | |
7 | external pymodule_getdict : pyobject -> pyobject = "PyModule_GetDict_wrapper" | |
8 | +IFDEF PYMAJOR3 THEN | |
9 | external pyunicode_asutf8string : pyobject -> pyobject = "PyUnicode_AsUTF8String_wrapper" | |
10 | external pyunicode_asutf16string : pyobject -> pyobject = "PyUnicode_AsUTF16String_wrapper" | |
11 | external pyunicode_asutf32string : pyobject -> pyobject = "PyUnicode_AsUTF32String_wrapper" | |
12 | +END | |
13 | external pyobject_repr : pyobject -> pyobject = "PyObject_Repr_wrapper" | |
14 | external pyimport_reloadmodule : pyobject -> pyobject = "PyImport_ReloadModule_wrapper" | |
15 | external pyimport_import : pyobject -> pyobject = "PyImport_Import_wrapper" | |
16 | @@ -273,7 +275,9 @@ | |
17 | external pymapping_size : pyobject -> int = "PyMapping_Size_wrapper" | |
18 | external pymapping_length : pyobject -> int = "PyMapping_Length_wrapper" | |
19 | external pyiter_check : pyobject -> int = "PyIter_Check_wrapper" | |
20 | +IFDEF PYMAJOR3 THEN | |
21 | external pyunicode_getsize : pyobject -> int = "PyUnicode_GetSize_wrapper" | |
22 | +END | |
23 | ||
24 | (* Type19 *) | |
25 | external pyobject_hasattr : (pyobject * pyobject) -> int = "PyObject_HasAttr_wrapper" | |
26 | @@ -326,7 +330,11 @@ | |
27 | (* Type28 *) | |
28 | external pyimport_addmodule : string -> pyobject = "PyImport_AddModule_wrapper" | |
29 | external pybytes_fromstring : string -> pyobject = "PyBytes_FromString_wrapper" | |
30 | +IFDEF PYMAJOR2 THEN | |
31 | external pystring_fromstring : string -> pyobject = "PyBytes_FromString_wrapper" (* Legacy support *) | |
32 | +ELSE | |
33 | +external pystring_fromstring : string -> pyobject = "PyUnicode_FromString_wrapper" (* Legacy support *) | |
34 | +ENDIF | |
35 | external pymodule_new : string -> pyobject = "PyModule_New_wrapper" | |
36 | external pyimport_importmodule : string -> pyobject = "PyImport_ImportModule_wrapper" | |
37 | ||
38 | @@ -380,15 +388,11 @@ | |
39 | ||
40 | (* Type42 *) | |
41 | external pyslice_new : (pyobject * pyobject * pyobject) -> pyobject = "PySlice_New_wrapper" | |
42 | -IFDEF PYMAJOR2 THEN | |
43 | external pyclass_new : (pyobject * pyobject * pyobject) -> pyobject = "PyClass_New_wrapper" | |
44 | +IFDEF PYMAJOR2 THEN | |
45 | external pyinstance_new : (pyobject * pyobject * pyobject) -> pyobject = "PyInstance_New_wrapper" | |
46 | END | |
47 | -IFDEF PYMAJOR2 THEN | |
48 | external pymethod_new : (pyobject * pyobject * pyobject) -> pyobject = "PyMethod_New_wrapper" | |
49 | -ELSE | |
50 | -external pymethod_new : (pyobject * pyobject) -> pyobject = "PyMethod_New_wrapper" | |
51 | -END | |
52 | external pyeval_callobjectwithkeywords : (pyobject * pyobject * pyobject) -> pyobject = "PyEval_CallObjectWithKeywords_wrapper" | |
53 | external pynumber_power : (pyobject * pyobject * pyobject) -> pyobject = "PyNumber_Power_wrapper" | |
54 | external pynumber_inplacepower : (pyobject * pyobject * pyobject) -> pyobject = "PyNumber_InPlacePower_wrapper" | |
55 | @@ -432,16 +436,9 @@ | |
56 | external pysequence_delslice : (pyobject * int * int) -> int = "PySequence_DelSlice_wrapper" | |
57 | ||
58 | (* TypeUTF8Decoder *) | |
59 | +IFDEF PYMAJOR3 THEN | |
60 | external pyunicode_decodeutf8 : (string * string option) -> pyobject = "PyUnicode_DecodeUTF8_wrapper" | |
61 | - | |
62 | -(* TypeUTF16Decoder *) | |
63 | -external pyunicode_decodeutf16 : (string * string option * int option) -> pyobject = "PyUnicode_DecodeUTF16_wrapper" | |
64 | -external pyunicode_decodeutf32 : (string * string option * int option) -> pyobject = "PyUnicode_DecodeUTF32_wrapper" | |
65 | - | |
66 | -(*-----------------------------------------------------------------------*) | |
67 | - | |
68 | -external pyunicode_fromunicode : (int -> int) -> int -> pyobject = "PyUnicode_FromUnicode_wrapper" | |
69 | -external pyunicode_asunicode : pyobject -> int array = "PyUnicode_AsUnicode_wrapper" | |
70 | +END | |
71 | ||
72 | (*-----------------------------------------------------------------------*) | |
73 | ||
74 | @@ -959,6 +956,7 @@ | |
75 | in | |
76 | work_fun | |
77 | ||
78 | +IFDEF PYMAJOR3 THEN | |
79 | (* OCaml string encoded in UTF-8 --> Python 3 string type (= Python 2 unicode type) *) | |
80 | let pythonize_string s = | |
81 | pyunicode_decodeutf8(s, None) | |
82 | @@ -976,6 +974,7 @@ | |
83 | | BytesType -> pybytes_asstringandsize s | |
84 | | _ -> assert false | |
85 | end | |
86 | +END | |
87 | ||
88 | (* FIX: Maybe rewrite this as an unpythonizing_function. *) | |
89 | let python_interfaced_function | |
90 | diff -ru /tmp/chemoelectric-pycaml-8614105/pycaml_stubs.c ./chemoelectric-pycaml-8614105/pycaml_stubs.c | |
91 | --- /tmp/chemoelectric-pycaml-8614105/pycaml_stubs.c 2011-10-01 02:05:57.000000000 +0200 | |
92 | +++ ./chemoelectric-pycaml-8614105/pycaml_stubs.c 2012-06-24 13:36:40.714560368 +0200 | |
93 | @@ -789,9 +789,11 @@ | |
94 | Type14(PyMethod_Class, pywrap) | |
95 | #endif | |
96 | ||
97 | +#if PY_MAJOR_VERSION >= 3 | |
98 | Type14(PyUnicode_AsUTF8String, pywrap_steal) | |
99 | Type14(PyUnicode_AsUTF16String, pywrap_steal) | |
100 | Type14(PyUnicode_AsUTF32String, pywrap_steal) | |
101 | +#endif | |
102 | Type14(PyObject_Repr, pywrap_steal) | |
103 | Type14(PyImport_ReloadModule, pywrap_steal) | |
104 | Type14(PyImport_Import, pywrap_steal) | |
105 | @@ -938,7 +940,9 @@ | |
106 | Type18(PyMapping_Size) | |
107 | Type18(PyMapping_Length) | |
108 | Type18(PyIter_Check) | |
109 | +#if PY_MAJOR_VERSION >= 3 | |
110 | Type18(PyUnicode_GetSize) | |
111 | +#endif | |
112 | ||
113 | /*-----------------------------------------------------------------------*/ | |
114 | ||
115 | @@ -1096,6 +1100,9 @@ | |
116 | Type28(PyImport_AddModule, pywrap) | |
117 | ||
118 | Type28(PyBytes_FromString, pywrap_steal) | |
119 | +#if PY_MAJOR_VERSION >= 3 | |
120 | +Type28(PyUnicode_FromString, pywrap_steal) | |
121 | +#endif | |
122 | Type28(PyModule_New, pywrap_steal) | |
123 | Type28(PyImport_ImportModule, pywrap_steal) | |
124 | ||
125 | @@ -1300,7 +1307,7 @@ | |
126 | CAMLparam1(py_args); \ | |
127 | \ | |
128 | PyObject *new_obj = func(pyunwrap(Field(py_args, 0)), \ | |
129 | - pyunwrap(Field(py_args, 1))); \ | |
130 | + pyunwrap(Field(py_args, 2))); \ | |
131 | CAMLreturn(wrap_obj(new_obj)); \ | |
132 | } | |
133 | #endif | |
134 | @@ -1313,6 +1320,22 @@ | |
135 | #if PY_MAJOR_VERSION <= 2 | |
136 | Type42(PyClass_New, pywrap_steal) | |
137 | Type42(PyInstance_New, pywrap_steal) | |
138 | +#else | |
139 | +/* Calls the builtin-function: type(name,bases,dict), with the | |
140 | + * name of the class, tuples of parent names, and dictionary | |
141 | + * with initializations of fields. | |
142 | + */ | |
143 | +CAMLprim value PyClass_New_wrapper(value py_args) | |
144 | +{ | |
145 | + CAMLparam1(py_args); | |
146 | + PyObject *bases = pyunwrap(Field(py_args, 0)); | |
147 | + PyObject *dict = pyunwrap(Field(py_args, 1)); | |
148 | + PyObject *name = pyunwrap(Field(py_args, 2)); | |
149 | + PyObject *new_obj = | |
150 | + PyObject_CallFunctionObjArgs | |
151 | + ( (PyObject *) &PyType_Type, name, bases, dict, NULL); | |
152 | + CAMLreturn(pywrap_steal(new_obj)); | |
153 | +} | |
154 | #endif | |
155 | ||
156 | Type42a(PyMethod_New, pywrap_steal) | |
157 | @@ -1493,7 +1516,7 @@ | |
158 | Type54(PySequence_DelSlice) | |
159 | ||
160 | /*-----------------------------------------------------------------------*/ | |
161 | - | |
162 | +#if PY_MAJOR_VERSION >= 3 | |
163 | #define TypeUTF8Decoder(func, wrap_obj) \ | |
164 | CAMLprim value func##_wrapper(value py_args) \ | |
165 | { \ | |
166 | @@ -1513,9 +1536,9 @@ | |
167 | } | |
168 | ||
169 | TypeUTF8Decoder(PyUnicode_DecodeUTF8, pywrap_steal) | |
170 | - | |
171 | +#endif | |
172 | /*-----------------------------------------------------------------------*/ | |
173 | - | |
174 | +#if 0 | |
175 | #define TypeUTF16Decoder(func, wrap_obj) \ | |
176 | CAMLprim value func##_wrapper(value py_args) \ | |
177 | { \ | |
178 | @@ -1589,7 +1612,7 @@ | |
179 | ||
180 | CAMLreturn(result); | |
181 | } | |
182 | - | |
183 | +#endif | |
184 | /*-----------------------------------------------------------------------*/ | |
185 | ||
186 | /* Value -> Pyobject */ |