https://github.com/python/cpython/commit/bbdf31d5d69fd5191cf38b81d4a08776731f9ea8
commit: bbdf31d5d69fd5191cf38b81d4a08776731f9ea8
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-13T15:02:31Z
summary:
gh-155907: Move PyMarshal C API tests to test_capi (#157417)
Add Modules/_testcapi/marshal.c and
Lib/test/test_capi/test_marshal.py.
files:
A Lib/test/test_capi/test_marshal.py
A Modules/_testcapi/marshal.c
M Lib/test/test_marshal.py
M Modules/Setup.stdlib.in
M Modules/_testcapi/parts.h
M Modules/_testcapimodule.c
M PCbuild/_testcapi.vcxproj
M PCbuild/_testcapi.vcxproj.filters
diff --git a/Lib/test/test_capi/test_marshal.py
b/Lib/test/test_capi/test_marshal.py
new file mode 100644
index 000000000000000..82a20c44fac4243
--- /dev/null
+++ b/Lib/test/test_capi/test_marshal.py
@@ -0,0 +1,127 @@
+import marshal
+import os.path
+import unittest
+
+from test import support
+from test.support import import_helper
+from test.support import os_helper
+from test.test_marshal import HelperMixin, omit_last_byte
+
+
+# Skip this test if _testcapi is are not available.
+_testcapi = import_helper.import_module('_testcapi')
+
+
[email protected]_only
+class CAPI_TestCase(unittest.TestCase, HelperMixin):
+
+ def test_read_from_file_error(self):
+ # A read error is reported as OSError, not EOFError.
+ # A directory cannot be read (on some platforms it cannot even
+ # be opened, which is reported as OSError as well).
+ os.mkdir(os_helper.TESTFN)
+ self.addCleanup(os_helper.rmdir, os_helper.TESTFN)
+ for func in (_testcapi.pymarshal_read_short_from_file,
+ _testcapi.pymarshal_read_long_from_file,
+ _testcapi.pymarshal_read_object_from_file,
+ _testcapi.pymarshal_read_last_object_from_file):
+ with self.subTest(func=func.__name__):
+ self.assertRaises(OSError, func, os_helper.TESTFN)
+
+ @unittest.skipUnless(os.path.exists('/dev/full'), 'requires /dev/full')
+ def test_write_to_file_error(self):
+ # A write error is reported as OSError.
+ # The data is large enough to not fit in the stdio buffer, so that
+ # the error is detected before the file is closed.
+ obj = b'x' * 100000
+ with self.assertRaises(OSError):
+ _testcapi.pymarshal_write_object_to_file(obj, '/dev/full',
+ marshal.version)
+
+ def test_write_unmarshallable_to_file(self):
+ self.addCleanup(os_helper.unlink, os_helper.TESTFN)
+ with self.assertRaisesRegex(ValueError, 'unmarshallable object'):
+ _testcapi.pymarshal_write_object_to_file(object(),
os_helper.TESTFN,
+ marshal.version)
+
+ def test_write_long_to_file(self):
+ for v in range(marshal.version + 1):
+ _testcapi.pymarshal_write_long_to_file(0x12345678,
os_helper.TESTFN, v)
+ with open(os_helper.TESTFN, 'rb') as f:
+ data = f.read()
+ os_helper.unlink(os_helper.TESTFN)
+ self.assertEqual(data, b'\x78\x56\x34\x12')
+
+ def test_write_object_to_file(self):
+ obj = ('\u20ac', b'abc', 123, 45.6, 7+8j, 'long line '*1000)
+ for v in range(marshal.version + 1):
+ _testcapi.pymarshal_write_object_to_file(obj, os_helper.TESTFN, v)
+ with open(os_helper.TESTFN, 'rb') as f:
+ data = f.read()
+ os_helper.unlink(os_helper.TESTFN)
+ self.assertEqual(marshal.loads(data), obj)
+
+ def test_read_short_from_file(self):
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(b'\x34\x12xxxx')
+ r, p = _testcapi.pymarshal_read_short_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+ self.assertEqual(r, 0x1234)
+ self.assertEqual(p, 2)
+
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(b'\x12')
+ with self.assertRaises(EOFError):
+ _testcapi.pymarshal_read_short_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+
+ def test_read_long_from_file(self):
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(b'\x78\x56\x34\x12xxxx')
+ r, p = _testcapi.pymarshal_read_long_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+ self.assertEqual(r, 0x12345678)
+ self.assertEqual(p, 4)
+
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(b'\x56\x34\x12')
+ with self.assertRaises(EOFError):
+ _testcapi.pymarshal_read_long_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+
+ def test_read_last_object_from_file(self):
+ obj = ('\u20ac', b'abc', 123, 45.6, 7+8j)
+ for v in range(marshal.version + 1):
+ data = marshal.dumps(obj, v)
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(data + b'xxxx')
+ r, p =
_testcapi.pymarshal_read_last_object_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+ self.assertEqual(r, obj)
+
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(omit_last_byte(data))
+ with self.assertRaises(EOFError):
+
_testcapi.pymarshal_read_last_object_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+
+ def test_read_object_from_file(self):
+ obj = ('\u20ac', b'abc', 123, 45.6, 7+8j)
+ for v in range(marshal.version + 1):
+ data = marshal.dumps(obj, v)
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(data + b'xxxx')
+ r, p = _testcapi.pymarshal_read_object_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+ self.assertEqual(r, obj)
+ self.assertEqual(p, len(data))
+
+ with open(os_helper.TESTFN, 'wb') as f:
+ f.write(omit_last_byte(data))
+ with self.assertRaises(EOFError):
+ _testcapi.pymarshal_read_object_from_file(os_helper.TESTFN)
+ os_helper.unlink(os_helper.TESTFN)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py
index 042cad03ce80e79..d7db3d480ff1e2e 100644
--- a/Lib/test/test_marshal.py
+++ b/Lib/test/test_marshal.py
@@ -797,117 +797,6 @@ def test_slice(self):
with self.assertRaises(ValueError):
marshal.dumps(obj, version)
[email protected]_only
[email protected](_testcapi, 'requires _testcapi')
-class CAPI_TestCase(unittest.TestCase, HelperMixin):
-
- def test_read_from_file_error(self):
- # A read error is reported as OSError, not EOFError.
- # A directory cannot be read (on some platforms it cannot even
- # be opened, which is reported as OSError as well).
- os.mkdir(os_helper.TESTFN)
- self.addCleanup(os_helper.rmdir, os_helper.TESTFN)
- for func in (_testcapi.pymarshal_read_short_from_file,
- _testcapi.pymarshal_read_long_from_file,
- _testcapi.pymarshal_read_object_from_file,
- _testcapi.pymarshal_read_last_object_from_file):
- with self.subTest(func=func.__name__):
- self.assertRaises(OSError, func, os_helper.TESTFN)
-
- @unittest.skipUnless(os.path.exists('/dev/full'), 'requires /dev/full')
- def test_write_to_file_error(self):
- # A write error is reported as OSError.
- # The data is large enough to not fit in the stdio buffer, so that
- # the error is detected before the file is closed.
- obj = b'x' * 100000
- with self.assertRaises(OSError):
- _testcapi.pymarshal_write_object_to_file(obj, '/dev/full',
- marshal.version)
-
- def test_write_unmarshallable_to_file(self):
- self.addCleanup(os_helper.unlink, os_helper.TESTFN)
- with self.assertRaisesRegex(ValueError, 'unmarshallable object'):
- _testcapi.pymarshal_write_object_to_file(object(),
os_helper.TESTFN,
- marshal.version)
-
- def test_write_long_to_file(self):
- for v in range(marshal.version + 1):
- _testcapi.pymarshal_write_long_to_file(0x12345678,
os_helper.TESTFN, v)
- with open(os_helper.TESTFN, 'rb') as f:
- data = f.read()
- os_helper.unlink(os_helper.TESTFN)
- self.assertEqual(data, b'\x78\x56\x34\x12')
-
- def test_write_object_to_file(self):
- obj = ('\u20ac', b'abc', 123, 45.6, 7+8j, 'long line '*1000)
- for v in range(marshal.version + 1):
- _testcapi.pymarshal_write_object_to_file(obj, os_helper.TESTFN, v)
- with open(os_helper.TESTFN, 'rb') as f:
- data = f.read()
- os_helper.unlink(os_helper.TESTFN)
- self.assertEqual(marshal.loads(data), obj)
-
- def test_read_short_from_file(self):
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(b'\x34\x12xxxx')
- r, p = _testcapi.pymarshal_read_short_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
- self.assertEqual(r, 0x1234)
- self.assertEqual(p, 2)
-
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(b'\x12')
- with self.assertRaises(EOFError):
- _testcapi.pymarshal_read_short_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
-
- def test_read_long_from_file(self):
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(b'\x78\x56\x34\x12xxxx')
- r, p = _testcapi.pymarshal_read_long_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
- self.assertEqual(r, 0x12345678)
- self.assertEqual(p, 4)
-
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(b'\x56\x34\x12')
- with self.assertRaises(EOFError):
- _testcapi.pymarshal_read_long_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
-
- def test_read_last_object_from_file(self):
- obj = ('\u20ac', b'abc', 123, 45.6, 7+8j)
- for v in range(marshal.version + 1):
- data = marshal.dumps(obj, v)
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(data + b'xxxx')
- r, p =
_testcapi.pymarshal_read_last_object_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
- self.assertEqual(r, obj)
-
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(omit_last_byte(data))
- with self.assertRaises(EOFError):
-
_testcapi.pymarshal_read_last_object_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
-
- def test_read_object_from_file(self):
- obj = ('\u20ac', b'abc', 123, 45.6, 7+8j)
- for v in range(marshal.version + 1):
- data = marshal.dumps(obj, v)
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(data + b'xxxx')
- r, p = _testcapi.pymarshal_read_object_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
- self.assertEqual(r, obj)
- self.assertEqual(p, len(data))
-
- with open(os_helper.TESTFN, 'wb') as f:
- f.write(omit_last_byte(data))
- with self.assertRaises(EOFError):
- _testcapi.pymarshal_read_object_from_file(os_helper.TESTFN)
- os_helper.unlink(os_helper.TESTFN)
-
if __name__ == "__main__":
unittest.main()
diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in
index 9fc0be043bac9bb..d10ed146db92b6b 100644
--- a/Modules/Setup.stdlib.in
+++ b/Modules/Setup.stdlib.in
@@ -173,7 +173,7 @@
@MODULE__XXTESTFUZZ_TRUE@_xxtestfuzz _xxtestfuzz/_xxtestfuzz.c
_xxtestfuzz/fuzzer.c
@MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c
@MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c
_testinternalcapi/test_lock.c _testinternalcapi/pytime.c
_testinternalcapi/set.c _testinternalcapi/test_critical_sections.c
_testinternalcapi/complex.c _testinternalcapi/interpreter.c
_testinternalcapi/tokenizer.c _testinternalcapi/tuple.c
_testinternalcapi/typecache.c
-@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c
_testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c
_testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c
_testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c
_testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c
_testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c
_testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c
_testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c
_testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/modsupport.c
_testcapi/monitoring.c _testcapi/config.c _testcapi/import.c _testcapi/frame.c
_testcapi/type.c _testcapi/function.c _testcapi/module.c _testcapi/weakref.c
+@MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c
_testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c
_testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c
_testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c
_testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c
_testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c
_testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c
_testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c
_testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/modsupport.c
_testcapi/monitoring.c _testcapi/config.c _testcapi/import.c _testcapi/frame.c
_testcapi/type.c _testcapi/function.c _testcapi/module.c _testcapi/weakref.c
_testcapi/marshal.c
@MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c
_testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c
_testlimitedcapi/bytes.c _testlimitedcapi/capsule.c _testlimitedcapi/codec.c
_testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c
_testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c
_testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c
_testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c
_testlimitedcapi/slots.c _testlimitedcapi/sys.c _testlimitedcapi/threadstate.c
_testlimitedcapi/tuple.c _testlimitedcapi/unicode.c
_testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c
_testlimitedcapi/file.c _testlimitedcapi/weakref.c _testlimitedcapi/run.c
_testlimitedcapi/type.c
@MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c
@MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c
diff --git a/Modules/_testcapi/marshal.c b/Modules/_testcapi/marshal.c
new file mode 100644
index 000000000000000..fe5b8259b885788
--- /dev/null
+++ b/Modules/_testcapi/marshal.c
@@ -0,0 +1,172 @@
+// Test PyMarshal C API
+
+#include "parts.h"
+#include "marshal.h" // PyMarshal_WriteLongToFile()
+
+static PyObject*
+pymarshal_write_long_to_file(PyObject* self, PyObject *args)
+{
+ long value;
+ PyObject *filename;
+ int version;
+ FILE *fp;
+
+ if (!PyArg_ParseTuple(args, "lOi:pymarshal_write_long_to_file",
+ &value, &filename, &version))
+ return NULL;
+
+ fp = Py_fopen(filename, "wb");
+ if (fp == NULL) {
+ return NULL;
+ }
+
+ PyMarshal_WriteLongToFile(value, fp, version);
+
+ fclose(fp);
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+pymarshal_write_object_to_file(PyObject* self, PyObject *args)
+{
+ PyObject *obj;
+ PyObject *filename;
+ int version;
+ FILE *fp;
+
+ if (!PyArg_ParseTuple(args, "OOi:pymarshal_write_object_to_file",
+ &obj, &filename, &version))
+ return NULL;
+
+ fp = Py_fopen(filename, "wb");
+ if (fp == NULL) {
+ return NULL;
+ }
+
+ PyMarshal_WriteObjectToFile(obj, fp, version);
+
+ fclose(fp);
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+pymarshal_read_short_from_file(PyObject* self, PyObject *args)
+{
+ int value;
+ long pos;
+ PyObject *filename;
+ FILE *fp;
+
+ if (!PyArg_ParseTuple(args, "O:pymarshal_read_short_from_file", &filename))
+ return NULL;
+
+ fp = Py_fopen(filename, "rb");
+ if (fp == NULL) {
+ return NULL;
+ }
+
+ value = PyMarshal_ReadShortFromFile(fp);
+ pos = ftell(fp);
+
+ fclose(fp);
+ if (PyErr_Occurred())
+ return NULL;
+ return Py_BuildValue("il", value, pos);
+}
+
+static PyObject*
+pymarshal_read_long_from_file(PyObject* self, PyObject *args)
+{
+ long value, pos;
+ PyObject *filename;
+ FILE *fp;
+
+ if (!PyArg_ParseTuple(args, "O:pymarshal_read_long_from_file", &filename))
+ return NULL;
+
+ fp = Py_fopen(filename, "rb");
+ if (fp == NULL) {
+ return NULL;
+ }
+
+ value = PyMarshal_ReadLongFromFile(fp);
+ pos = ftell(fp);
+
+ fclose(fp);
+ if (PyErr_Occurred())
+ return NULL;
+ return Py_BuildValue("ll", value, pos);
+}
+
+static PyObject*
+pymarshal_read_last_object_from_file(PyObject* self, PyObject *args)
+{
+ PyObject *filename;
+ if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file",
&filename))
+ return NULL;
+
+ FILE *fp = Py_fopen(filename, "rb");
+ if (fp == NULL) {
+ return NULL;
+ }
+
+ PyObject *obj = PyMarshal_ReadLastObjectFromFile(fp);
+ long pos = ftell(fp);
+
+ fclose(fp);
+ if (obj == NULL) {
+ return NULL;
+ }
+ return Py_BuildValue("Nl", obj, pos);
+}
+
+static PyObject*
+pymarshal_read_object_from_file(PyObject* self, PyObject *args)
+{
+ PyObject *filename;
+ if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file",
&filename))
+ return NULL;
+
+ FILE *fp = Py_fopen(filename, "rb");
+ if (fp == NULL) {
+ return NULL;
+ }
+
+ PyObject *obj = PyMarshal_ReadObjectFromFile(fp);
+ long pos = ftell(fp);
+
+ fclose(fp);
+ if (obj == NULL) {
+ return NULL;
+ }
+ return Py_BuildValue("Nl", obj, pos);
+}
+
+
+static PyMethodDef test_methods[] = {
+ {"pymarshal_write_long_to_file",
+ pymarshal_write_long_to_file, METH_VARARGS},
+ {"pymarshal_write_object_to_file",
+ pymarshal_write_object_to_file, METH_VARARGS},
+ {"pymarshal_read_short_from_file",
+ pymarshal_read_short_from_file, METH_VARARGS},
+ {"pymarshal_read_long_from_file",
+ pymarshal_read_long_from_file, METH_VARARGS},
+ {"pymarshal_read_last_object_from_file",
+ pymarshal_read_last_object_from_file, METH_VARARGS},
+ {"pymarshal_read_object_from_file",
+ pymarshal_read_object_from_file, METH_VARARGS},
+ {NULL},
+};
+
+int
+_PyTestCapi_Init_Marshal(PyObject *mod)
+{
+ return PyModule_AddFunctions(mod, test_methods);
+}
diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h
index 98b5dd47accde35..1ae3f0773e42f80 100644
--- a/Modules/_testcapi/parts.h
+++ b/Modules/_testcapi/parts.h
@@ -68,5 +68,6 @@ int _PyTestCapi_Init_Type(PyObject *mod);
int _PyTestCapi_Init_Function(PyObject *mod);
int _PyTestCapi_Init_Module(PyObject *mod);
int _PyTestCapi_Init_Weakref(PyObject *mod);
+int _PyTestCapi_Init_Marshal(PyObject *mod);
#endif // Py_TESTCAPI_PARTS_H
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c
index 0312ee9066231c4..eb769294fd21db8 100644
--- a/Modules/_testcapimodule.c
+++ b/Modules/_testcapimodule.c
@@ -13,7 +13,6 @@
#include "_testcapi/parts.h"
#include "frameobject.h" // PyFrame_New()
-#include "marshal.h" // PyMarshal_WriteLongToFile()
#ifdef bool
# error "The public headers should not include <stdbool.h>, see gh-90904"
@@ -1416,153 +1415,6 @@ join_temporary_c_thread(PyObject *self, PyObject
*Py_UNUSED(ignored))
Py_RETURN_NONE;
}
-/* marshal */
-
-static PyObject*
-pymarshal_write_long_to_file(PyObject* self, PyObject *args)
-{
- long value;
- PyObject *filename;
- int version;
- FILE *fp;
-
- if (!PyArg_ParseTuple(args, "lOi:pymarshal_write_long_to_file",
- &value, &filename, &version))
- return NULL;
-
- fp = Py_fopen(filename, "wb");
- if (fp == NULL) {
- return NULL;
- }
-
- PyMarshal_WriteLongToFile(value, fp, version);
-
- fclose(fp);
- if (PyErr_Occurred()) {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject*
-pymarshal_write_object_to_file(PyObject* self, PyObject *args)
-{
- PyObject *obj;
- PyObject *filename;
- int version;
- FILE *fp;
-
- if (!PyArg_ParseTuple(args, "OOi:pymarshal_write_object_to_file",
- &obj, &filename, &version))
- return NULL;
-
- fp = Py_fopen(filename, "wb");
- if (fp == NULL) {
- return NULL;
- }
-
- PyMarshal_WriteObjectToFile(obj, fp, version);
-
- fclose(fp);
- if (PyErr_Occurred()) {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject*
-pymarshal_read_short_from_file(PyObject* self, PyObject *args)
-{
- int value;
- long pos;
- PyObject *filename;
- FILE *fp;
-
- if (!PyArg_ParseTuple(args, "O:pymarshal_read_short_from_file", &filename))
- return NULL;
-
- fp = Py_fopen(filename, "rb");
- if (fp == NULL) {
- return NULL;
- }
-
- value = PyMarshal_ReadShortFromFile(fp);
- pos = ftell(fp);
-
- fclose(fp);
- if (PyErr_Occurred())
- return NULL;
- return Py_BuildValue("il", value, pos);
-}
-
-static PyObject*
-pymarshal_read_long_from_file(PyObject* self, PyObject *args)
-{
- long value, pos;
- PyObject *filename;
- FILE *fp;
-
- if (!PyArg_ParseTuple(args, "O:pymarshal_read_long_from_file", &filename))
- return NULL;
-
- fp = Py_fopen(filename, "rb");
- if (fp == NULL) {
- return NULL;
- }
-
- value = PyMarshal_ReadLongFromFile(fp);
- pos = ftell(fp);
-
- fclose(fp);
- if (PyErr_Occurred())
- return NULL;
- return Py_BuildValue("ll", value, pos);
-}
-
-static PyObject*
-pymarshal_read_last_object_from_file(PyObject* self, PyObject *args)
-{
- PyObject *filename;
- if (!PyArg_ParseTuple(args, "O:pymarshal_read_last_object_from_file",
&filename))
- return NULL;
-
- FILE *fp = Py_fopen(filename, "rb");
- if (fp == NULL) {
- return NULL;
- }
-
- PyObject *obj = PyMarshal_ReadLastObjectFromFile(fp);
- long pos = ftell(fp);
-
- fclose(fp);
- if (obj == NULL) {
- return NULL;
- }
- return Py_BuildValue("Nl", obj, pos);
-}
-
-static PyObject*
-pymarshal_read_object_from_file(PyObject* self, PyObject *args)
-{
- PyObject *filename;
- if (!PyArg_ParseTuple(args, "O:pymarshal_read_object_from_file",
&filename))
- return NULL;
-
- FILE *fp = Py_fopen(filename, "rb");
- if (fp == NULL) {
- return NULL;
- }
-
- PyObject *obj = PyMarshal_ReadObjectFromFile(fp);
- long pos = ftell(fp);
-
- fclose(fp);
- if (obj == NULL) {
- return NULL;
- }
- return Py_BuildValue("Nl", obj, pos);
-}
-
static PyObject*
return_null_without_error(PyObject *self, PyObject *args)
{
@@ -3077,18 +2929,6 @@ static PyMethodDef TestMethods[] = {
{"call_in_temporary_c_thread", call_in_temporary_c_thread, METH_VARARGS,
PyDoc_STR("set_error_class(error_class) -> None")},
{"join_temporary_c_thread", join_temporary_c_thread, METH_NOARGS},
- {"pymarshal_write_long_to_file",
- pymarshal_write_long_to_file, METH_VARARGS},
- {"pymarshal_write_object_to_file",
- pymarshal_write_object_to_file, METH_VARARGS},
- {"pymarshal_read_short_from_file",
- pymarshal_read_short_from_file, METH_VARARGS},
- {"pymarshal_read_long_from_file",
- pymarshal_read_long_from_file, METH_VARARGS},
- {"pymarshal_read_last_object_from_file",
- pymarshal_read_last_object_from_file, METH_VARARGS},
- {"pymarshal_read_object_from_file",
- pymarshal_read_object_from_file, METH_VARARGS},
{"return_null_without_error", return_null_without_error, METH_NOARGS},
{"return_result_with_error", return_result_with_error, METH_NOARGS},
{"getitem_with_error", getitem_with_error, METH_VARARGS},
@@ -3974,7 +3814,9 @@ _testcapi_exec(PyObject *m)
if (_PyTestCapi_Init_Weakref(m) < 0) {
return -1;
}
-
+ if (_PyTestCapi_Init_Marshal(m) < 0) {
+ return -1;
+ }
return 0;
}
diff --git a/PCbuild/_testcapi.vcxproj b/PCbuild/_testcapi.vcxproj
index 64e50b67be46561..d856b70bbdd5792 100644
--- a/PCbuild/_testcapi.vcxproj
+++ b/PCbuild/_testcapi.vcxproj
@@ -134,6 +134,7 @@
<ClCompile Include="..\Modules\_testcapi\type.c" />
<ClCompile Include="..\Modules\_testcapi\function.c" />
<ClCompile Include="..\Modules\_testcapi\weakref.c" />
+ <ClCompile Include="..\Modules\_testcapi\marshal.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\PC\python_nt.rc" />
diff --git a/PCbuild/_testcapi.vcxproj.filters
b/PCbuild/_testcapi.vcxproj.filters
index a3b62e1df663e00..554e5f3075f7ebf 100644
--- a/PCbuild/_testcapi.vcxproj.filters
+++ b/PCbuild/_testcapi.vcxproj.filters
@@ -135,6 +135,9 @@
<ClCompile Include="..\Modules\_testcapi\weakref.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\Modules\_testcapi\marshal.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\PC\python_nt.rc">
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]