diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-09-25 00:13:58 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-09-25 07:15:09 +0000 |
commit | a98d1089166cc90ebf7c82b938ae0add478b921d (patch) | |
tree | b46d476a5b550010c686d5b416681620ebcbbcbc /tools/pidl | |
parent | 141637d327c6c7529b44e43e8530b6304b5a12ee (diff) |
python3: Use "y#" instead of "s#" for binary data in PyArg_ParseTuple
Pick up change from Samba:
commit 40e409bf9e89a163c771b2a58493d2c1b496fae7
Author: Petr Viktorin <pviktori@redhat.com>
Date: Wed May 3 16:57:07 2017 +0200
python3: Use "y#" instead of "s#" for binary data in PyArg_ParseTuple
The "s#" format code for PyArg_ParseTupleAndKeywords and Py_BuildValue
converts a char* and size to/from Python str (with utf-8 encoding under
Python 3).
In some cases, we want bytes (str on Python 2, bytes on 3) instead. The
code for this is "y#" in Python 3, but that is not available in 2.
Introduce a PYARG_BYTES_LEN macro that expands to "s#" or "y#", and use
that in:
- credentials.get_ntlm_response (for input and output)
- ndr_unpack argument in PIDL generated code
Signed-off-by: Petr Viktorin <pviktori@redhat.com>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Change-Id: If4d9cdabc5016127f60682caf300f6801a360083
Reviewed-on: https://code.wireshark.org/review/23722
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'tools/pidl')
-rw-r--r-- | tools/pidl/lib/Parse/Pidl/Samba4/Python.pm | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm index e40f4f17a5..79beb2e75e 100644 --- a/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm +++ b/tools/pidl/lib/Parse/Pidl/Samba4/Python.pm @@ -320,7 +320,7 @@ sub PythonStruct($$$$$$) $self->pidl("PyObject *allow_remaining_obj = NULL;"); $self->pidl("bool allow_remaining = false;"); $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|O:__ndr_unpack__\","); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, PYARG_BYTES_LEN \"|O:__ndr_unpack__\","); $self->indent; $self->pidl("discard_const_p(char *, kwnames),"); $self->pidl("&blob.data, &blob_length,"); @@ -705,7 +705,7 @@ sub PythonFunctionStruct($$$$) $self->pidl("PyObject *allow_remaining_obj = NULL;"); $self->pidl("bool allow_remaining = false;"); $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|OOO:__ndr_unpack_in__\","); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, PYARG_BYTES_LEN \"|OOO:__ndr_unpack_in__\","); $self->indent; $self->pidl("discard_const_p(char *, kwnames),"); $self->pidl("&blob.data, &blob_length,"); @@ -753,7 +753,7 @@ sub PythonFunctionStruct($$$$) $self->pidl("PyObject *allow_remaining_obj = NULL;"); $self->pidl("bool allow_remaining = false;"); $self->pidl(""); - $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, \"s#|OOO:__ndr_unpack_out__\","); + $self->pidl("if (!PyArg_ParseTupleAndKeywords(args, kwargs, PYARG_BYTES_LEN \"|OOO:__ndr_unpack_out__\","); $self->indent; $self->pidl("discard_const_p(char *, kwnames),"); $self->pidl("&blob.data, &blob_length,"); |