summaryrefslogtreecommitdiff
path: root/python/ovs/_json.c
Commit message (Collapse)AuthorAgeFilesLines
* python-c-ext: Use designated initializers for type and module.Ilya Maximets2022-08-301-45/+11
| | | | | | | | | | Python documentation suggests to do so "to avoid listing all the PyTypeObject fields that you don't care about and also to avoid caring about the fields' declaration order". And that does make sense. Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Handle initialization failures.Ilya Maximets2022-07-291-1/+9
| | | | | | | | | | | | | PyModule_AddObject() may fail and it doesn't steal references in this case. The error condition should be handled to avoid possible memory leaks. And while it's not strictly specified if PyModule_Create may fail, most of the examples in python documentation include handling of a NULL case. Acked-by: Mike Pattrick <mkp@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Fix a couple of build warnings.Timothy Redaelli2022-07-221-2/+2
| | | | | | | | | | | ovs/_json.c:67:20: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] ovs/_json.c:132:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Wsign-compare] Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Remove Python 2 support.Timothy Redaelli2022-07-221-33/+1
| | | | | | | | | Since Python 2 is not supported anymore, remove Python 2 support from C extension too Fixes: 1ca0323e7c29 ("Require Python 3 and remove support for Python 2.") Signed-off-by: Timothy Redaelli <tredaelli@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* python-c-ext: Fix memory leak in Parser_finishEric Lapointe2018-10-311-0/+1
| | | | | | | The memory returned by json_parser_finish needs to be freed by the caller. Signed-off-by: Eric Lapointe <elapointe@corsa.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* json: Use unnamed embedded union.Flavio Leitner2018-08-061-9/+9
| | | | | | | | Otherwise the code does not build. Fixes: fa37affad362 ("Embrace anonymous unions.") Signed-off-by: Flavio Leitner <fbl@sysclose.org> Signed-off-by: Ben Pfaff <blp@ovn.org>
* json: Move from lib to include/openvswitch.Terry Wilson2016-07-221-1/+1
| | | | | | | | | | | | | | | To easily allow both in- and out-of-tree building of the Python wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to include/openvswitch. This also requires moving lib/{hmap,shash}.h. Both hmap.h and shash.h were #include-ing "util.h" even though the headers themselves did not use anything from there, but rather from include/openvswitch/util.h. Fixing that required including util.h in several C files mostly due to OVS_NOT_REACHED and things like xmalloc. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Add optional C extension wrapper for Python JSON parsingTerry Wilson2016-06-081-0/+268
The pure Python in-tree JSON parser is *much* slower than the in-tree C JSON parser. A local test parsing a 100Mb JSON file showed the Python version taking 270 seconds. With the C wrapper, it took under 4 seconds. The C extension will be used automatically if it can be built. If the extension fails to build, a warning is displayed and the build is restarted without the extension. The Serializer class is replaced with Python's built-in JSON library since the ability to process chunked data is not needed in that case. The extension should work with both Python 2.7 and Python 3.3+. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>