From bbcf40ee4799b56aa7e8ee190d60e0e32d2aae35 Mon Sep 17 00:00:00 2001 From: Stu Black Date: Fri, 3 Oct 2025 01:16:32 -0400 Subject: [PATCH] Eliminate the WINGs function WMCreateDataWithBytesNoCopy. This constructor was only needed in one particular place. We can duplidate the data instead of borrowing it. This ensures that WMData always owns its data segment, which simplifies porting to Rust significantly. --- WINGs/WINGs/WUtil.h | 5 ----- WINGs/data.c | 16 ---------------- WINGs/selection.c | 3 ++- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/WINGs/WINGs/WUtil.h b/WINGs/WINGs/WUtil.h index 35bcedbf..1277f985 100644 --- a/WINGs/WINGs/WUtil.h +++ b/WINGs/WINGs/WUtil.h @@ -592,11 +592,6 @@ WMData* WMCreateDataWithLength(unsigned length); WMData* WMCreateDataWithBytes(const void *bytes, unsigned length); -/* destructor is a function called to free the data when releasing the data - * object, or NULL if no freeing of data is necesary. */ -WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length, - WMFreeDataProc *destructor); - WMData* WMCreateDataWithData(WMData *aData); WMData* WMRetainData(WMData *aData); diff --git a/WINGs/data.c b/WINGs/data.c index f42a5c37..9fdcd10e 100644 --- a/WINGs/data.c +++ b/WINGs/data.c @@ -78,22 +78,6 @@ WMData *WMCreateDataWithBytes(const void *bytes, unsigned length) return aData; } -WMData *WMCreateDataWithBytesNoCopy(void *bytes, unsigned length, WMFreeDataProc * destructor) -{ - WMData *aData; - - aData = (WMData *) wmalloc(sizeof(WMData)); - aData->length = length; - aData->capacity = length; - aData->growth = length / 2 > 0 ? length / 2 : 1; - aData->bytes = bytes; - aData->retainCount = 1; - aData->format = 0; - aData->destructor = destructor; - - return aData; -} - WMData *WMCreateDataWithData(WMData * aData) { WMData *newData; diff --git a/WINGs/selection.c b/WINGs/selection.c index 0d1bc59c..63d364b0 100644 --- a/WINGs/selection.c +++ b/WINGs/selection.c @@ -261,8 +261,9 @@ static WMData *getSelectionData(Display * dpy, Window win, Atom where) bpi = bits / 8; - wdata = WMCreateDataWithBytesNoCopy(data, len * bpi, (void *) XFree); + wdata = WMCreateDataWithBytes(data, len * bpi); WMSetDataFormat(wdata, bits); + XFree(data); return wdata; }