File 2771-erts-Remove-memmove-3-fallback.patch of Package erlang
From cbf08d99faca783538b0e0d332cb673069a4eddb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?John=20H=C3=B6gberg?= <john@erlang.org>
Date: Fri, 13 Nov 2020 10:58:44 +0100
Subject: [PATCH] erts: Remove memmove(3) fallback
memmove(3) has been part of the C standard library since C89 and
we require C99 now, so this removal feels long overdue.
---
erts/emulator/Makefile.in | 1 -
erts/emulator/beam/elib_memmove.c | 114 --------------------------
erts/emulator/sys/win32/erl_win_sys.h | 1 -
erts/etc/unix/safe_string.c | 14 ----
erts/etc/unix/safe_string.h | 5 --
5 files changed, 135 deletions(-)
delete mode 100644 erts/emulator/beam/elib_memmove.c
diff --git a/erts/emulator/Makefile.in b/erts/emulator/Makefile.in
index 76415f3641..8b293d3bb3 100644
--- a/erts/emulator/Makefile.in
+++ b/erts/emulator/Makefile.in
@@ -936,7 +936,6 @@ OS_OBJS = \
$(OBJDIR)/sys_env.o \
$(OBJDIR)/sys_uds.o \
$(OBJDIR)/driver_tab.o \
- $(OBJDIR)/elib_memmove.o \
$(OBJDIR)/gzio.o \
$(OBJDIR)/unix_prim_file.o
diff --git a/erts/emulator/beam/elib_memmove.c b/erts/emulator/beam/elib_memmove.c
deleted file mode 100644
index 2f45f69026..0000000000
--- a/erts/emulator/beam/elib_memmove.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * %CopyrightBegin%
- *
- * Copyright Ericsson AB 1997-2016. All Rights Reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * %CopyrightEnd%
- */
-
-/*
- * This memmove assumes that both src and dst are aligned on an address
- * divisible by 4 and that n is a multiple of four.
- */
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifndef HAVE_MEMMOVE
-
-#define MEMCPY_LIMIT 12
-typedef unsigned long u_long;
-typedef unsigned short u_short;
-
-static void copy_high(dst, src, n)
-char* dst; char* src; int n;
-{
- dst += n;
- src += n;
-
- if (n >= MEMCPY_LIMIT) {
- while(((u_long) dst) & 3) {
- *--dst = *--src;
- n--;
- }
- if ((((u_long) src) & 3) == 0) {
- while(n >= sizeof(u_long)) {
- src -= sizeof(u_long);
- dst -= sizeof(u_long);
- *((u_long*)dst) = *((u_long*)src);
- n -= sizeof(u_long);
- }
- }
- else if ((((u_short) src) & 3) == 2) {
- while(n >= sizeof(u_short)) {
- src -= sizeof(u_short);
- dst -= sizeof(u_short);
- *((u_short*)dst) = *((u_short*)src);
- n -= sizeof(u_short);
- }
- }
- }
- while(n > 0) {
- *--dst = *--src;
- n--;
- }
-}
-
-static void copy_low(dst, src, n)
-char* dst; char* src; int n;
-{
- if (n >= MEMCPY_LIMIT) {
- while(((u_long) dst) & 3) {
- *dst++ = *src++;
- n--;
- }
- if ((((u_long) src) & 3) == 0) {
- while(n >= sizeof(u_long)) {
- *((u_long*)dst) = *((u_long*)src);
- src += sizeof(u_long);
- dst += sizeof(u_long);
- n -= sizeof(u_long);
- }
- }
- else if ((((u_long) src) & 3) == 2) {
- while(n >= sizeof(u_short)) {
- *((u_short*)dst) = *((u_short*)src);
- src += sizeof(u_short);
- dst += sizeof(u_short);
- n -= sizeof(u_short);
- }
- }
- }
- while(n > 0) {
- *dst++ = *src++;
- n--;
- }
-}
-
-/*
-** Move memory (with overlap)
-*/
-void* memmove(dst, src, n)
-char* dst; char* src; int n;
-{
- if (dst < src)
- copy_low(dst, src, n);
- else if (dst > src)
- copy_high(dst, src, n);
- return dst;
-}
-
-#endif /* HAVE_MEMMOVE */
diff --git a/erts/emulator/sys/win32/erl_win_sys.h b/erts/emulator/sys/win32/erl_win_sys.h
index b00ba287e2..51a6ea5f82 100644
--- a/erts/emulator/sys/win32/erl_win_sys.h
+++ b/erts/emulator/sys/win32/erl_win_sys.h
@@ -88,7 +88,6 @@
#define NO_SYSCONF
#define NO_DAEMON
#define NO_PWD
-/*#define HAVE_MEMMOVE*/
#define strncasecmp _strnicmp
diff --git a/erts/etc/unix/safe_string.c b/erts/etc/unix/safe_string.c
index 666022dc61..535e7d8757 100644
--- a/erts/etc/unix/safe_string.c
+++ b/erts/etc/unix/safe_string.c
@@ -108,17 +108,3 @@ char* find_str(const char* haystack, int hsize, const char* needle)
return NULL;
}
-#ifndef HAVE_MEMMOVE
-void* memmove(void *dest, const void *src, size_t n)
-{
- int i;
- if (src > dest) {
- for (i=0; i<n; i++) ((char*)dest)[i] = ((char*)src)[i];
- }
- else {
- for (i=(int)(n-1); i>=0; i--) ((char*)dest)[i] = ((char*)src)[i];
- }
- return dest;
-}
-#endif /* HAVE_MEMMOVE */
-
diff --git a/erts/etc/unix/safe_string.h b/erts/etc/unix/safe_string.h
index cafd3fc71a..155b7c1ae5 100644
--- a/erts/etc/unix/safe_string.h
+++ b/erts/etc/unix/safe_string.h
@@ -59,8 +59,3 @@ int strn_catf(char* dst, size_t size, const char* format, ...);
* without regard to '\0' characters.
*/
char* find_str(const char* haystack, int size, const char* needle);
-
-#ifndef HAVE_MEMMOVE
-void* memmove(void *dest, const void *src, size_t n);
-#endif
-
--
2.26.2