Repository navigation
bpo-20185: Convert the marshal module to Argument Clinic. #541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
serhiy-storchaka
merged 3 commits into
python:master
from
serhiy-storchaka:bpo-20185-clinic-marshal
Mar 12, 2017
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
522587a
bpo-20185: Convert the marshal module to Argument Clinic.
serhiy-storchaka 5c76db0
Merge remote-tracking branch 'upstream/master' into bpo-20185-clinic-…
serhiy-storchaka 55a826f
Merge remote-tracking branch 'upstream/master' into bpo-20185-clinic-…
serhiy-storchaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
bpo-20185: Convert the marshal module to Argument Clinic.
Based on patch by Vajrasky Kok.
- Loading branch information
commit 522587a122e9a5df07b79b9a00388690a1623ca0
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| /*[clinic input] | ||
| preserve | ||
| [clinic start generated code]*/ | ||
|
|
||
| PyDoc_STRVAR(marshal_dump__doc__, | ||
| "dump($module, value, file, version=version, /)\n" | ||
| "--\n" | ||
| "\n" | ||
| "Write the value on the open file.\n" | ||
| "\n" | ||
| " value\n" | ||
| " Must be a supported type.\n" | ||
| " file\n" | ||
| " Must be an open file object such as sys.stdout or returned by open()\n" | ||
| " or os.popen(). It must be opened in binary mode (\'wb\' or \'w+b\').\n" | ||
| " version\n" | ||
| " Indicates the data format that dump should use.\n" | ||
| "\n" | ||
| "If the value has (or contains an object that has) an unsupported type, a\n" | ||
| "ValueError exception is raised - but garbage data will also be written\n" | ||
| "to the file. The object will not be properly read back by load()."); | ||
|
|
||
| #define MARSHAL_DUMP_METHODDEF \ | ||
| {"dump", (PyCFunction)marshal_dump, METH_FASTCALL, marshal_dump__doc__}, | ||
|
|
||
| static PyObject * | ||
| marshal_dump_impl(PyObject *module, PyObject *value, PyObject *file, | ||
| int version); | ||
|
|
||
| static PyObject * | ||
| marshal_dump(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | ||
| { | ||
| PyObject *return_value = NULL; | ||
| PyObject *value; | ||
| PyObject *file; | ||
| int version = Py_MARSHAL_VERSION; | ||
|
|
||
| if (!_PyArg_ParseStack(args, nargs, "OO|i:dump", | ||
| &value, &file, &version)) { | ||
| goto exit; | ||
| } | ||
|
|
||
| if (!_PyArg_NoStackKeywords("dump", kwnames)) { | ||
| goto exit; | ||
| } | ||
| return_value = marshal_dump_impl(module, value, file, version); | ||
|
|
||
| exit: | ||
| return return_value; | ||
| } | ||
|
|
||
| PyDoc_STRVAR(marshal_load__doc__, | ||
| "load($module, file, /)\n" | ||
| "--\n" | ||
| "\n" | ||
| "Read one value from the open file and return it.\n" | ||
| "\n" | ||
| " file\n" | ||
| " Must be an open file object opened in binary mode (\'rb\' or \'r+b\')\n" | ||
| "\n" | ||
| "If no valid value is read (e.g. because the data has a different Python\n" | ||
| "version\'s incompatible marshal format), raise EOFError, ValueError or\n" | ||
| "TypeError.\n" | ||
| "\n" | ||
| "Note: If an object containing an unsupported type was marshalled with\n" | ||
| "dump(), load() will substitute None for the unmarshallable type."); | ||
|
|
||
| #define MARSHAL_LOAD_METHODDEF \ | ||
| {"load", (PyCFunction)marshal_load, METH_O, marshal_load__doc__}, | ||
|
|
||
| PyDoc_STRVAR(marshal_dumps__doc__, | ||
| "dumps($module, value, version=version, /)\n" | ||
| "--\n" | ||
| "\n" | ||
| "Return the string that would be written to a file by dump(value, file).\n" | ||
| "\n" | ||
| " value\n" | ||
| " Must be a supported type.\n" | ||
| " version\n" | ||
| " Indicates the data format that dumps should use.\n" | ||
| "\n" | ||
| "Raise a ValueError exception if value has (or contains an object that has) an\n" | ||
| "unsupported type."); | ||
|
|
||
| #define MARSHAL_DUMPS_METHODDEF \ | ||
| {"dumps", (PyCFunction)marshal_dumps, METH_FASTCALL, marshal_dumps__doc__}, | ||
|
|
||
| static PyObject * | ||
| marshal_dumps_impl(PyObject *module, PyObject *value, int version); | ||
|
|
||
| static PyObject * | ||
| marshal_dumps(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject *kwnames) | ||
| { | ||
| PyObject *return_value = NULL; | ||
| PyObject *value; | ||
| int version = Py_MARSHAL_VERSION; | ||
|
|
||
| if (!_PyArg_ParseStack(args, nargs, "O|i:dumps", | ||
| &value, &version)) { | ||
| goto exit; | ||
| } | ||
|
|
||
| if (!_PyArg_NoStackKeywords("dumps", kwnames)) { | ||
| goto exit; | ||
| } | ||
| return_value = marshal_dumps_impl(module, value, version); | ||
|
|
||
| exit: | ||
| return return_value; | ||
| } | ||
|
|
||
| PyDoc_STRVAR(marshal_loads__doc__, | ||
| "loads($module, bytes, /)\n" | ||
| "--\n" | ||
| "\n" | ||
| "Convert the bytes object to a value.\n" | ||
| "\n" | ||
| "If no valid value is found, raise EOFError, ValueError or TypeError. Extra\n" | ||
| "characters in the input are ignored."); | ||
|
|
||
| #define MARSHAL_LOADS_METHODDEF \ | ||
| {"loads", (PyCFunction)marshal_loads, METH_O, marshal_loads__doc__}, | ||
|
|
||
| static PyObject * | ||
| marshal_loads_impl(PyObject *module, Py_buffer *bytes); | ||
|
|
||
| static PyObject * | ||
| marshal_loads(PyObject *module, PyObject *arg) | ||
| { | ||
| PyObject *return_value = NULL; | ||
| Py_buffer bytes = {NULL, NULL}; | ||
|
|
||
| if (!PyArg_Parse(arg, "y*:loads", &bytes)) { | ||
| goto exit; | ||
| } | ||
| return_value = marshal_loads_impl(module, &bytes); | ||
|
|
||
| exit: | ||
| /* Cleanup for bytes */ | ||
| if (bytes.obj) { | ||
| PyBuffer_Release(&bytes); | ||
| } | ||
|
|
||
| return return_value; | ||
| } | ||
| /*[clinic end generated code: output=c9a4fdb39afcd0c1 input=a9049054013a1b77]*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, 'string' should be 'bytes' in Python 3.
But it's unrelated to this pull request, because old docstring says it 'string' too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that is why I still have not pushed this patch! I noticed this when wrote the patch but forgot to open separate issue. Now it is opened: bpo-29746.