devPrivates rework: redo field offset registration, drop RC_PRIVATES class.

This commit is contained in:
Eamon Walsh 2007-03-08 12:13:36 -05:00 committed by Eamon Walsh
parent 947f8d249b
commit 2fcb45eb5d
3 changed files with 14 additions and 14 deletions

View File

@ -195,12 +195,14 @@ dixRegisterPrivateOffset(RESTYPE type, unsigned offset)
/* resize offsets table if necessary */ /* resize offsets table if necessary */
while (type >= offsetsSize) { while (type >= offsetsSize) {
offsets = (unsigned *)xrealloc(offsets, unsigned i = offsetsSize * 2 * sizeof(int);
offsetsSize * 2 * sizeof(unsigned)); offsets = (unsigned *)xrealloc(offsets, i);
if (!offsets) { if (!offsets) {
offsetsSize = 0; offsetsSize = 0;
return FALSE; return FALSE;
} }
for (i=offsetsSize; i < 2*offsetsSize; i++)
offsets[i] = -1;
offsetsSize *= 2; offsetsSize *= 2;
} }
@ -208,10 +210,9 @@ dixRegisterPrivateOffset(RESTYPE type, unsigned offset)
return TRUE; return TRUE;
} }
_X_EXPORT unsigned _X_EXPORT int
dixLookupPrivateOffset(RESTYPE type) dixLookupPrivateOffset(RESTYPE type)
{ {
assert(type & RC_PRIVATES);
type = type & TypeMask; type = type & TypeMask;
assert(type < offsetsSize); assert(type < offsetsSize);
return offsets[type]; return offsets[type];
@ -233,19 +234,22 @@ int
dixResetPrivates(void) dixResetPrivates(void)
{ {
PrivateDescRec *next; PrivateDescRec *next;
unsigned i;
/* reset internal structures */
while (items) { while (items) {
next = items->next; next = items->next;
xfree(items); xfree(items);
items = next; items = next;
} }
if (offsets) if (offsets)
xfree(offsets); xfree(offsets);
offsetsSize = 16; offsetsSize = 16;
offsets = (unsigned *)xalloc(offsetsSize * sizeof(unsigned)); offsets = (unsigned *)xalloc(offsetsSize * sizeof(unsigned));
if (!offsets) if (!offsets)
return FALSE; return FALSE;
for (i=0; i < offsetsSize; i++)
offsets[i] = -1;
/* reset legacy devPrivates support */ /* reset legacy devPrivates support */
if (!ResetExtensionPrivates() || !ResetClientPrivates()) if (!ResetExtensionPrivates() || !ResetClientPrivates())

View File

@ -142,9 +142,10 @@ dixResetPrivates(void);
*/ */
/* /*
* Looks up the offset where the devPrivates field is located by type. * Looks up the offset where the devPrivates field is located.
* Returns -1 if no offset has been registered for the resource type.
*/ */
extern unsigned extern int
dixLookupPrivateOffset(RESTYPE type); dixLookupPrivateOffset(RESTYPE type);
/* /*

View File

@ -66,12 +66,7 @@ typedef unsigned long RESTYPE;
* Extensions can use this too! * Extensions can use this too!
*/ */
#define RC_NEVERRETAIN ((RESTYPE)1<<29) #define RC_NEVERRETAIN ((RESTYPE)1<<29)
/* Use class RC_PRIVATES for resources that support extra private data. #define RC_LASTPREDEF RC_NEVERRETAIN
* Resources having this class must provide a field of type PrivateRec *.
* Refer to the X server documentation on devPrivates for the details.
*/
#define RC_PRIVATES ((RESTYPE)1<<28)
#define RC_LASTPREDEF RC_PRIVATES
#define RC_ANY (~(RESTYPE)0) #define RC_ANY (~(RESTYPE)0)
/* types for Resource routines */ /* types for Resource routines */