Change in osmo-trx[master]: Vector: Copy arrays in a sane wayfor non-trivially copyable types

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Fri Aug 31 09:51:49 UTC 2018


Pau Espin Pedrol has uploaded this change for review. ( https://gerrit.osmocom.org/10721


Change subject: Vector: Copy arrays in a sane wayfor non-trivially copyable types
......................................................................

Vector: Copy arrays in a sane wayfor non-trivially copyable types

Avoids this type of compilation warnings:
‘void* memcpy(void*, const void*, size_t)’ writing to an object of non-trivially copyable type ‘class Complex<float>’; use copy-assignment or copy-initialization instead [-Werror=class-memaccess]

Change-Id: I9724454dfb7b87f74f39074e4004580ac3b5fe5c
---
M CommonLibs/Vector.h
M Transceiver52M/signalVector.cpp
2 files changed, 23 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/21/10721/1

diff --git a/CommonLibs/Vector.h b/CommonLibs/Vector.h
index 51a9fb1..a53d8d9 100644
--- a/CommonLibs/Vector.h
+++ b/CommonLibs/Vector.h
@@ -204,10 +204,15 @@
 	*/
 	void copyToSegment(Vector<T>& other, size_t start, size_t span) const
 	{
-		T* base = other.mStart + start;
-		assert(base+span<=other.mEnd);
+		unsigned int i;
+		T* dst = other.mStart + start;
+		T* src = mStart;
+		assert(dst+span<=other.mEnd);
 		assert(mStart+span<=mEnd);
-		memcpy(base,mStart,span*sizeof(T));
+		for(i = 0; i < span; i++, src++, dst++)
+			*dst = *src;
+		/*TODO if not non-trivially copyable type class, optimize:
+		memcpy(dst,mStart,span*sizeof(T)); */
 	}
 
 	/** Copy all of this Vector to a segment of another Vector. */
diff --git a/Transceiver52M/signalVector.cpp b/Transceiver52M/signalVector.cpp
index 55dad92..c6dd0f2 100644
--- a/Transceiver52M/signalVector.cpp
+++ b/Transceiver52M/signalVector.cpp
@@ -41,7 +41,14 @@
 void signalVector::operator=(const signalVector& vector)
 {
 	resize(vector.size() + vector.getStart());
-	memcpy(mData, vector.mData, bytes());
+
+	unsigned int i;
+	complex *dst = mData;
+	complex *src = vector.mData;
+	for(i = 0; i < size(); i++, src++, dst++)
+		*dst = *src;
+	/* TODO: optimize for non non-trivially copyable types: */
+	/*memcpy(mData, vector.mData, bytes()); */
 	mStart = mData + vector.getStart();
 }
 
@@ -58,8 +65,13 @@
 size_t signalVector::updateHistory()
 {
 	size_t num = getStart();
-
-	memmove(mData, mStart + this->size() - num, num * sizeof(complex));
+	unsigned int i;
+	complex *dst = mData;
+	complex *src = mStart + this->size() - num;
+	for(i = 0; i < num; i++, src++, dst++)
+		*dst = *src;
+	/* TODO: optimize for non non-trivially copyable types: */
+	/*memmove(mData, mStart + this->size() - num, num * sizeof(complex)); */
 
 	return num;
 }

-- 
To view, visit https://gerrit.osmocom.org/10721
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I9724454dfb7b87f74f39074e4004580ac3b5fe5c
Gerrit-Change-Number: 10721
Gerrit-PatchSet: 1
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20180831/ae2df272/attachment.htm>


More information about the gerrit-log mailing list