annotate uwsginl-plugin-lang-py36/Makefile @ 85:56fc86d83f6f

python: use consistent key type for opt dict manipulations - fixes #1374. PyString_FromString is defined as PyBytes_FromString in uwsgi_python.h. What happens in Python 3 during the population of the opt_dict is that we first check if a byte object, representing the key is in the dict. If there is none, we use PyDict_SetItemString to set it. However, as the docs say, PyDict_SetItemString will convert the key using PyUnicode_FromString and we actually put a unicode key in the dict[1]. Therefore, when we check the "same" key again, we check again for the "same" key as bytes object we don't find it and end up overwriting it instead of doing the list promotion dance. Attached patch fixes this by using PyDict_SetItem and PyDict_GetItem with a consistent key type. For Python 3, a unicode object is used as key as this is the backwards compatible thing to do. Mini tester: import uwsgi def application(env, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) for k, v in uwsgi.opt.items(): yield "{} {!r} ({})\n".format(k, v, type(v)).encode("utf-8") yield "{} {}\n".format(uwsgi.version, type(uwsgi.version)).encode("utf-8") yield "{} {}\n".format(uwsgi.hostname, type(uwsgi.hostname)).encode("utf-8") yield b"END" What is a bit rough is that in Python 3 the actual values for uwsgi.opt entries end-up being all bytes, but that has always been like this... [1] https://docs.python.org/3.5/c-api/dict.html#c.PyDict_SetItemString commit 34cc53d0899f874ea1dc1d13d49c054ca1f1757c
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 14 Jun 2020 23:20:32 +0200
parents 3b6e789833d4
children 4ddf40c2765a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
1 # Created by: Franz Glasner <freebsd-dev@dom66.de>
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
2 # $FreeBSD$
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
3
53
3b6e789833d4 The Python3.6 language (interpreter) plugin for www/uwsginl
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
4 PORTNAME= ${UWSGI_NAME}-plugin-lang-py36
32
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
5
53
3b6e789833d4 The Python3.6 language (interpreter) plugin for www/uwsginl
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
6 COMMENT= Language plugin for Python 3.6
32
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
7
53
3b6e789833d4 The Python3.6 language (interpreter) plugin for www/uwsginl
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
8 USES= python:3.6 gettext-runtime
32
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
9
53
3b6e789833d4 The Python3.6 language (interpreter) plugin for www/uwsginl
Franz Glasner <fzglas.hg@dom66.de>
parents: 34
diff changeset
10 PLUGIN_NAME= python36
33
765f8e6d1d80 Adjust to the master port changes: re-define PLUGIN_NAME and PLUGIN_SOURCE
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
11 PLUGIN_SOURCE= plugins/python
32
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
12
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
13 MASTERDIR= ${.CURDIR}/../uwsginl-plugin-lang-py3
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
14
921b2db456d8 The Python3.4 language (interpreter) plugin for www/uwsginl
Franz Glasner <hg@dom66.de>
parents:
diff changeset
15 .include "${MASTERDIR}/Makefile"