1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-04-02 04:53:34 +02:00

Fixed behaviour of WMData objects regarding the destructor.

Merged WMCreateDataWithBytesNoCopy with WMCreateDataWithBytesAndDestructor.
This commit is contained in:
dan
2000-04-09 02:32:17 +00:00
parent 0b87b7fab9
commit b8ca9e2b64
3 changed files with 21 additions and 40 deletions

View File

@@ -440,10 +440,9 @@ WMData* WMCreateDataWithLength(unsigned length);
WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length);
WMData* WMCreateDataWithBytesAndDestructor(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);

View File

@@ -1,7 +1,7 @@
/*
* WINGs WMData function library
*
* Copyright (c) 1999 Dan Pascu
* Copyright (c) 1999-2000 Dan Pascu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -51,12 +51,13 @@ WMCreateDataWithCapacity(unsigned capacity) /*FOLD00*/
aData->bytes = wmalloc(capacity);
else
aData->bytes = NULL;
aData->capacity = capacity;
aData->growth = capacity/2 > 0 ? capacity/2 : 1;
aData->length = 0;
aData->retainCount = 1;
aData->freeData = 1;
aData->format = 0;
aData->freeData = 1;
aData->destructor = NULL;
return aData;
@@ -92,26 +93,7 @@ WMCreateDataWithBytes(void *bytes, unsigned length) /*FOLD00*/
WMData*
WMCreateDataWithBytesNoCopy(void *bytes, unsigned length) /*FOLD00*/
{
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->freeData = 0;
aData->format = 0;
aData->destructor = NULL;
return aData;
}
WMData*
WMCreateDataWithBytesAndDestructor(void *bytes, unsigned length,
WMCreateDataWithBytesNoCopy(void *bytes, unsigned length, /*FOLD00*/
WMFreeDataProc *destructor)
{
WMData *aData;
@@ -134,12 +116,12 @@ WMData*
WMCreateDataWithData(WMData *aData) /*FOLD00*/
{
WMData *newData;
if (aData->length > 0) {
newData = WMCreateDataWithBytes(aData->bytes, aData->length);
} else {
newData = WMCreateDataWithCapacity(0);
}
newData->destructor = aData->destructor;
newData->format = aData->format;
return newData;
@@ -160,12 +142,13 @@ WMReleaseData(WMData *aData) /*FOLD00*/
aData->retainCount--;
if (aData->retainCount > 0)
return;
if (aData->bytes && aData->freeData) {
if (aData->destructor != NULL)
if (aData->bytes != NULL) {
if (aData->destructor != NULL) {
aData->destructor(aData->bytes);
else
} else if (aData->freeData) {
wfree(aData->bytes);
}
}
wfree(aData);
}
@@ -274,8 +257,8 @@ WMGetSubdataWithRange(WMData *aData, WMRange aRange) /*FOLD00*/
buffer = wmalloc(aRange.count);
WMGetDataBytesWithRange(aData, buffer, aRange);
newData = WMCreateDataWithBytesNoCopy(buffer, aRange.count);
newData->destructor = aData->destructor;
newData = WMCreateDataWithBytesNoCopy(buffer, aRange.count, wfree);
//newData->freeData = 1;
newData->format = aData->format;
return newData;

View File

@@ -330,8 +330,7 @@ getSelectionData(Display *dpy, Window win, Atom where)
return NULL;
}
wdata = WMCreateDataWithBytesAndDestructor(data, len,
(WMFreeDataProc*)XFree);
wdata = WMCreateDataWithBytesNoCopy(data, len, (WMFreeDataProc*)XFree);
if (wdata == NULL) {
return NULL;
}