This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Oren Milman
Recipients Oren Milman
Date 2017-09-18.08:57:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1505725063.77.0.402266911274.issue31505@psf.upfronthosting.co.za>
In-reply-to
Content
The following code causes an assertion failure:

import _json
def _bad_encoder(*args):
    return None

enc = _json.make_encoder(None, None, _bad_encoder, None,
                         'foo', 'bar', None, None, None)

enc(obj='spam', _current_indent_level=4)


This is because encoder_new() (in Modules/_json.c) assumes that the received
encoder() argument is a function that returns a string, and stores it in the
new PyEncoderObject.
When encoder_encode_string() is called (by encoder_listencode_obj()), it
returns whatever the stored encoder() returned, assuming it returned a string.
Then, encoder_listencode_obj() passes this value to _steal_accumulate(), which
passes it to _PyAccu_Accumulate(), which asserts it is a string.


Similarly, the following code also causes an assertion failure (only the obj
argument is different):

import _json
def _bad_encoder(*args):
    return None

enc = _json.make_encoder(None, None, _bad_encoder, None,
                         'foo', 'bar', None, None, None)

enc(obj={'spam': 42}, _current_indent_level=4)


In this case, encoder_listencode_dict() passes whatever encoder_encode_string()
returned, to _PyAccu_Accumulate(), which asserts it is a string.
History
Date User Action Args
2017-09-18 08:57:43Oren Milmansetrecipients: + Oren Milman
2017-09-18 08:57:43Oren Milmansetmessageid: <1505725063.77.0.402266911274.issue31505@psf.upfronthosting.co.za>
2017-09-18 08:57:43Oren Milmanlinkissue31505 messages
2017-09-18 08:57:43Oren Milmancreate