From 2c3c52bcf087c25a5ce58a68968b53f985b77d73 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@k1024.org>
Date: Sun, 3 Mar 2019 13:45:45 +0100
Subject: [PATCH] ACL creation: change how mode arguments are used

Currently, initialising from a mode is done by looking at the keywords
arguments that were passed and seeing if mode was part of them. For
some reason, this causes a segfault under PyPy (my fault, probably),
so let's switch to check based on whether the mode argument was
initialised. To do so, switch the type of mode to int and the Python
format char, since the 'H' is defined as "without overflow checking"
anyway, so we don't get any real checks. Document that invalid values
will cause errors.
---
 acl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/acl.c b/acl.c
index a8aefa2..2c62b9a 100644
--- a/acl.c
+++ b/acl.c
@@ -151,7 +151,7 @@ static int ACL_init(PyObject* obj, PyObject* args, PyObject *keywds) {
     static char *kwlist[] = { "file", "fd", "text", "acl", "filedef",
                               "mode", NULL };
     char *format = "|etisO!sH";
-    mode_t mode = 0;
+    int mode = -1;
 #else
     static char *kwlist[] = { "file", "fd", "text", "acl", "filedef", NULL };
     char *format = "|etisO!s";
@@ -193,7 +193,7 @@ static int ACL_init(PyObject* obj, PyObject* args, PyObject *keywds) {
     else if(filedef != NULL)
         self->acl = acl_get_file(filedef, ACL_TYPE_DEFAULT);
 #ifdef HAVE_LINUX
-    else if(PyMapping_HasKeyString(keywds, kwlist[5]))
+    else if(mode != -1)
         self->acl = acl_from_mode(mode);
 #endif
     else
-- 
2.39.5