mirror of
https://github.com/termux/termux-packages.git
synced 2024-12-04 18:45:52 +00:00
e8b90f4597
* pypy: bump to 7.3.12 * pypy3: bump to 7.3.12 * @TERMUX_PKG_API_LEVEL@, fix patch filenames --------- Co-authored-by: Lucy Phipps <landfillbaby69@gmail.com>
96 lines
3.1 KiB
Diff
96 lines
3.1 KiB
Diff
--- a/lib_pypy/_posixshmem_build.py
|
|
+++ b/lib_pypy/_posixshmem_build.py
|
|
@@ -12,15 +12,88 @@
|
|
""")
|
|
|
|
SOURCE = """
|
|
-#include <sys/mman.h>
|
|
-#include <sys/stat.h> /* For mode constants */
|
|
-#include <fcntl.h> /* For O_* constants */
|
|
+/* This file is a port of posix shared memory for Python3 on Termux Android,
|
|
+ based on musl-libc which is licensed under the following standard MIT
|
|
+ license. The ported files are listed as following.
|
|
+
|
|
+ File(s): src/mman/shm_open.c
|
|
+
|
|
+ Copyright © 2005-2020 Rich Felker, et al.
|
|
+
|
|
+ Permission is hereby granted, free of charge, to any person obtaining
|
|
+ a copy of this software and associated documentation files (the
|
|
+ "Software"), to deal in the Software without restriction, including
|
|
+ without limitation the rights to use, copy, modify, merge, publish,
|
|
+ distribute, sublicense, and/or sell copies of the Software, and to
|
|
+ permit persons to whom the Software is furnished to do so, subject to
|
|
+ the following conditions:
|
|
+
|
|
+ The above copyright notice and this permission notice shall be
|
|
+ included in all copies or substantial portions of the Software.
|
|
+
|
|
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
+ */
|
|
+
|
|
+#include <fcntl.h> // open()
|
|
+#include <string.h> // strlen(), memcpy()
|
|
+#include <errno.h> // errno
|
|
+#include <limits.h> // NAME_MAX
|
|
+#include <unistd.h> // unlink()
|
|
+
|
|
+#define SHM_PREFIX "@TERMUX_PREFIX@/tmp/shm."
|
|
+
|
|
+static __inline__ char *__strchrnul(const char *s, int c)
|
|
+{
|
|
+ c = (unsigned char)c;
|
|
+ if (!c) return (char *)s + strlen(s);
|
|
+ for (; *s && *(unsigned char *)s != c; s++);
|
|
+ return (char *)s;
|
|
+}
|
|
+
|
|
+static char *__shm_mapname(const char *name, char *buf)
|
|
+{
|
|
+ char *p;
|
|
+ while (*name == '/') name++;
|
|
+ if (*(p = __strchrnul(name, '/')) || p==name ||
|
|
+ (p-name <= 2 && name[0]=='.' && p[-1]=='.')) {
|
|
+ errno = EINVAL;
|
|
+ return 0;
|
|
+ }
|
|
+ if (p-name > NAME_MAX-4) {
|
|
+ errno = ENAMETOOLONG;
|
|
+ return 0;
|
|
+ }
|
|
+ memcpy(buf, SHM_PREFIX, strlen(SHM_PREFIX));
|
|
+ memcpy(buf+strlen(SHM_PREFIX), name, p-name+1);
|
|
+ return buf;
|
|
+}
|
|
+
|
|
+int shm_open(const char *name, int flag, mode_t mode)
|
|
+{
|
|
+ char buf[NAME_MAX+strlen(SHM_PREFIX)+1];
|
|
+ if (!(name = __shm_mapname(name, buf))) return -1;
|
|
+ int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode);
|
|
+ return fd;
|
|
+}
|
|
+
|
|
+int shm_unlink(const char *name)
|
|
+{
|
|
+ char buf[NAME_MAX+strlen(SHM_PREFIX)+1];
|
|
+ if (!(name = __shm_mapname(name, buf))) return -1;
|
|
+ return unlink(name);
|
|
+}
|
|
"""
|
|
|
|
if sys.platform == 'darwin':
|
|
libraries = []
|
|
else:
|
|
- libraries=['rt']
|
|
+ libraries=['c']
|
|
_ffi.set_source("_posixshmem_cffi", SOURCE, libraries=libraries)
|
|
|
|
|