Decode NIS data to fs encoding, using the surrogate error handler.
This commit is contained in:
parent
f241afaead
commit
5ea823cf55
|
@ -69,7 +69,8 @@ Extensions
|
||||||
- Issue #5737: Add Solaris-specific mnemonics in the errno module. Patch by
|
- Issue #5737: Add Solaris-specific mnemonics in the errno module. Patch by
|
||||||
Matthew Ahrens.
|
Matthew Ahrens.
|
||||||
|
|
||||||
- Restore GIL in nis_cat in case of error.
|
- Restore GIL in nis_cat in case of error. Decode NIS data to fs encoding,
|
||||||
|
using the surrogate error handler.
|
||||||
|
|
||||||
- Issue #665761: ``functools.reduce()`` will no longer mask exceptions
|
- Issue #665761: ``functools.reduce()`` will no longer mask exceptions
|
||||||
other than ``TypeError`` raised by the iterator argument.
|
other than ``TypeError`` raised by the iterator argument.
|
||||||
|
|
|
@ -117,8 +117,8 @@ nis_foreach (int instatus, char *inkey, int inkeylen, char *inval,
|
||||||
if (invallen > 0 && inval[invallen-1] == '\0')
|
if (invallen > 0 && inval[invallen-1] == '\0')
|
||||||
invallen--;
|
invallen--;
|
||||||
}
|
}
|
||||||
key = PyUnicode_FromStringAndSize(inkey, inkeylen);
|
key = PyUnicode_DecodeFSDefaultAndSize(inkey, inkeylen);
|
||||||
val = PyUnicode_FromStringAndSize(inval, invallen);
|
val = PyUnicode_DecodeFSDefaultAndSize(inval, invallen);
|
||||||
if (key == NULL || val == NULL) {
|
if (key == NULL || val == NULL) {
|
||||||
/* XXX error -- don't know how to handle */
|
/* XXX error -- don't know how to handle */
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -159,30 +159,40 @@ nis_match (PyObject *self, PyObject *args, PyObject *kwdict)
|
||||||
{
|
{
|
||||||
char *match;
|
char *match;
|
||||||
char *domain = NULL;
|
char *domain = NULL;
|
||||||
int keylen, len;
|
Py_ssize_t keylen;
|
||||||
|
int len;
|
||||||
char *key, *map;
|
char *key, *map;
|
||||||
int err;
|
int err;
|
||||||
PyObject *res;
|
PyObject *ukey, *bkey, *res;
|
||||||
int fix;
|
int fix;
|
||||||
static char *kwlist[] = {"key", "map", "domain", NULL};
|
static char *kwlist[] = {"key", "map", "domain", NULL};
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwdict,
|
if (!PyArg_ParseTupleAndKeywords(args, kwdict,
|
||||||
"s#s|s:match", kwlist,
|
"Us|s:match", kwlist,
|
||||||
&key, &keylen, &map, &domain))
|
&ukey, &map, &domain))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!domain && ((err = yp_get_default_domain(&domain)) != 0))
|
if ((bkey = PyUnicode_EncodeFSDefault(ukey)) == NULL)
|
||||||
|
return NULL;
|
||||||
|
if (PyBytes_AsStringAndSize(bkey, &key, &keylen) == -1) {
|
||||||
|
Py_DECREF(bkey);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!domain && ((err = yp_get_default_domain(&domain)) != 0)) {
|
||||||
|
Py_DECREF(bkey);
|
||||||
return nis_error(err);
|
return nis_error(err);
|
||||||
|
}
|
||||||
map = nis_mapname (map, &fix);
|
map = nis_mapname (map, &fix);
|
||||||
if (fix)
|
if (fix)
|
||||||
keylen++;
|
keylen++;
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
err = yp_match (domain, map, key, keylen, &match, &len);
|
err = yp_match (domain, map, key, keylen, &match, &len);
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
Py_DECREF(bkey);
|
||||||
if (fix)
|
if (fix)
|
||||||
len--;
|
len--;
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
return nis_error(err);
|
return nis_error(err);
|
||||||
res = PyUnicode_FromStringAndSize (match, len);
|
res = PyUnicode_DecodeFSDefaultAndSize(match, len);
|
||||||
free (match);
|
free (match);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue