Mercurial > hgrepos > FreeBSD > ports > www > uwsginl
view uwsginl-plugin-lang-py3/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 | badbe8b61265 |
| children | 40e8d1ee1651 |
line wrap: on
line source
# Created by: Franz Glasner <freebsd-dev@dom66.de> # $FreeBSD$ PORTNAME?= ${UWSGI_NAME}-plugin-lang-py3 DISTVERSION= 2.0.18 PORTREVISION?= 0 CATEGORIES?= www python MASTER_SITES= https://projects.unbit.it/downloads/ DISTNAME= uwsgi-${DISTVERSION} MAINTAINER?= freebsd-dev@dom66.de COMMENT?= Language plugin for Python 3 (OS default) LICENSE= GPLv2-WITH-LINKING-EXCEPTION LICENSE_GROUPS= FSF GPL OSI LICENSE_NAME= GPLv2 with linking exception LICENSE_FILE= ${WRKSRC}/LICENSE LICENSE_PERMS= dist-mirror dist-sell pkg-mirror pkg-sell auto-accept BUILD_DEPENDS+= ${UWSGI_NAME}==${PORTVERSION}:www/uwsginl RUN_DEPENDS+= ${UWSGI_NAME}==${PORTVERSION}:www/uwsginl # This specific python version is built USES?= python:3.5+ gettext-runtime # Some python version is needed when building USES+= python:build pkgconfig PLIST_FILES= ${PLUGIN_DIR}/${PLUGIN_FILENAME} MAKE_ENV+= UWSGI_PROFILE_OVERRIDE="plugin_build_dir=${STAGEDIR}${PREFIX}/${PLUGIN_DIR};plugin_dir=${PREFIX}/${PLUGIN_DIR}" PYTHON=${PYTHON_CMD} # by default it uses the MASTERDIR's description DESCR?= ${.CURDIR}/pkg-descr UWSGI_NAME= uwsginl UWSGI_PATH= ${LOCALBASE}/bin/${UWSGI_NAME} PLUGIN_DIR= lib/${UWSGI_NAME}/plugins # The name of the plugin to be created (to eventually distingush py2 and py3) PLUGIN_NAME?= python3 # Where to find the sources for the plugin (defaults to plugins/${PLUGIN_NAME}) .if defined(MASTERDIR) .if !defined(PLUGIN_SOURCE) || empty(PLUGIN_SOURCE) PLUGIN_SOURCE= plugins/${PLUGIN_NAME} .endif .else PLUGIN_SOURCE= plugins/python .endif # The complete basename of the plugin PLUGIN_FILENAME= ${PLUGIN_NAME}_plugin.so # Use the PATCHDIR of the binary executable by default PATCHDIR?= ${.CURDIR}/../uwsginl/files do-configure: @${DO_NADA} do-build: @${MKDIR} ${STAGEDIR}${PREFIX}/${PLUGIN_DIR} @(cd ${BUILD_WRKSRC}; ${SETENV} ${MAKE_ENV} ${UWSGI_PATH} --build-plugin "${PLUGIN_SOURCE} ${PLUGIN_NAME}") do-install: ${INSTALL_LIB} ${BUILD_WRKSRC}/${PLUGIN_FILENAME} ${STAGEDIR}${PREFIX}/${PLUGIN_DIR} .include <bsd.port.mk>
