mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-15 21:45:54 +01:00
Fixed behaviour of WMData objects regarding the destructor.
Merged WMCreateDataWithBytesNoCopy with WMCreateDataWithBytesAndDestructor.
This commit is contained in:
@@ -440,10 +440,9 @@ WMData* WMCreateDataWithLength(unsigned length);
|
|||||||
|
|
||||||
WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
|
WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
|
||||||
|
|
||||||
WMData* WMCreateDataWithBytesNoCopy(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,
|
||||||
WMData* WMCreateDataWithBytesAndDestructor(void *bytes, unsigned length,
|
|
||||||
WMFreeDataProc *destructor);
|
WMFreeDataProc *destructor);
|
||||||
|
|
||||||
WMData* WMCreateDataWithData(WMData *aData);
|
WMData* WMCreateDataWithData(WMData *aData);
|
||||||
|
|||||||
39
WINGs/data.c
39
WINGs/data.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* WINGs WMData function library
|
* 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
|
* 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
|
* 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);
|
aData->bytes = wmalloc(capacity);
|
||||||
else
|
else
|
||||||
aData->bytes = NULL;
|
aData->bytes = NULL;
|
||||||
|
|
||||||
aData->capacity = capacity;
|
aData->capacity = capacity;
|
||||||
aData->growth = capacity/2 > 0 ? capacity/2 : 1;
|
aData->growth = capacity/2 > 0 ? capacity/2 : 1;
|
||||||
aData->length = 0;
|
aData->length = 0;
|
||||||
aData->retainCount = 1;
|
aData->retainCount = 1;
|
||||||
aData->freeData = 1;
|
|
||||||
aData->format = 0;
|
aData->format = 0;
|
||||||
|
aData->freeData = 1;
|
||||||
aData->destructor = NULL;
|
aData->destructor = NULL;
|
||||||
|
|
||||||
return aData;
|
return aData;
|
||||||
@@ -92,26 +93,7 @@ WMCreateDataWithBytes(void *bytes, unsigned length) /*FOLD00*/
|
|||||||
|
|
||||||
|
|
||||||
WMData*
|
WMData*
|
||||||
WMCreateDataWithBytesNoCopy(void *bytes, unsigned length) /*FOLD00*/
|
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,
|
|
||||||
WMFreeDataProc *destructor)
|
WMFreeDataProc *destructor)
|
||||||
{
|
{
|
||||||
WMData *aData;
|
WMData *aData;
|
||||||
@@ -134,12 +116,12 @@ WMData*
|
|||||||
WMCreateDataWithData(WMData *aData) /*FOLD00*/
|
WMCreateDataWithData(WMData *aData) /*FOLD00*/
|
||||||
{
|
{
|
||||||
WMData *newData;
|
WMData *newData;
|
||||||
|
|
||||||
if (aData->length > 0) {
|
if (aData->length > 0) {
|
||||||
newData = WMCreateDataWithBytes(aData->bytes, aData->length);
|
newData = WMCreateDataWithBytes(aData->bytes, aData->length);
|
||||||
} else {
|
} else {
|
||||||
newData = WMCreateDataWithCapacity(0);
|
newData = WMCreateDataWithCapacity(0);
|
||||||
}
|
}
|
||||||
newData->destructor = aData->destructor;
|
|
||||||
newData->format = aData->format;
|
newData->format = aData->format;
|
||||||
|
|
||||||
return newData;
|
return newData;
|
||||||
@@ -160,12 +142,13 @@ WMReleaseData(WMData *aData) /*FOLD00*/
|
|||||||
aData->retainCount--;
|
aData->retainCount--;
|
||||||
if (aData->retainCount > 0)
|
if (aData->retainCount > 0)
|
||||||
return;
|
return;
|
||||||
if (aData->bytes && aData->freeData) {
|
if (aData->bytes != NULL) {
|
||||||
if (aData->destructor != NULL)
|
if (aData->destructor != NULL) {
|
||||||
aData->destructor(aData->bytes);
|
aData->destructor(aData->bytes);
|
||||||
else
|
} else if (aData->freeData) {
|
||||||
wfree(aData->bytes);
|
wfree(aData->bytes);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
wfree(aData);
|
wfree(aData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,8 +257,8 @@ WMGetSubdataWithRange(WMData *aData, WMRange aRange) /*FOLD00*/
|
|||||||
|
|
||||||
buffer = wmalloc(aRange.count);
|
buffer = wmalloc(aRange.count);
|
||||||
WMGetDataBytesWithRange(aData, buffer, aRange);
|
WMGetDataBytesWithRange(aData, buffer, aRange);
|
||||||
newData = WMCreateDataWithBytesNoCopy(buffer, aRange.count);
|
newData = WMCreateDataWithBytesNoCopy(buffer, aRange.count, wfree);
|
||||||
newData->destructor = aData->destructor;
|
//newData->freeData = 1;
|
||||||
newData->format = aData->format;
|
newData->format = aData->format;
|
||||||
|
|
||||||
return newData;
|
return newData;
|
||||||
|
|||||||
@@ -330,8 +330,7 @@ getSelectionData(Display *dpy, Window win, Atom where)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wdata = WMCreateDataWithBytesAndDestructor(data, len,
|
wdata = WMCreateDataWithBytesNoCopy(data, len, (WMFreeDataProc*)XFree);
|
||||||
(WMFreeDataProc*)XFree);
|
|
||||||
if (wdata == NULL) {
|
if (wdata == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user