libtool/libltdl/slist.c

370 lines
9.3 KiB
C
Raw Normal View History

Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
/* slist.h -- generalised singly linked lists
Copyright (C) 2000, 2004 Free Software Foundation, Inc.
Written by Gary V. Vaughan <gary@gnu.org>
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
NOTE: The canonical source of this file is maintained with the
GNU Libtool package. Report bugs to bug-libtool@gnu.org.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
As a special exception to the GNU Lesser General Public License,
if you distribute this file as part of a program or library that
is built using GNU libtool, you may include it under the same
distribution terms that you use for the rest of that program.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
*/
#include <assert.h>
#include "slist.h"
static SList * slist_sort_merge (SList *left, SList *right,
SListCompare *compare, void *userdata);
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
/* Call DELETE repeatedly on each element of HEAD.
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
CAVEAT: If you call this when HEAD is the start of a list of boxed
items, you must remember that each item passed back to your
DELETE function will be a boxed item must be slist_unbox()ed
before operating on its contents.
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
e.g. void boxed_delete (void *item) { item_free (slist_unbox (item)); }
...
slist = slist_delete (slist, boxed_delete);
...
*/
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
SList *
slist_delete (SList *head, void (*delete) (void *item))
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
assert (delete);
while (head)
{
SList *next = head->next;
(*delete) (head);
head = next;
}
return 0;
}
/* Call FIND repeatedly with MATCHDATA and each item of *PHEAD, until
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
FIND returns non-NULL, or the list is exhausted. If a match is found
the matching item is destructively removed from *PHEAD, and the value
returned by the matching call to FIND is returned.
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
CAVEAT: To avoid memory leaks, unless you already have the address of
the stale item, you should probably return that from FIND if
it makes a successful match. Don't forget to slist_unbox()
every item in a boxed list before operating on its contents. */
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
void *
slist_remove (SList **phead, SListCallback *find, void *matchdata)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
SList *stale = 0;
void *result = 0;
assert (find);
if (!phead || !*phead)
return 0;
/* Does the head of the passed list match? */
result = (*find) (*phead, matchdata);
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
if (result)
{
stale = *phead;
*phead = stale->next;
}
/* what about the rest of the elements? */
else
{
SList *head;
for (head = *phead; head->next; head = head->next)
{
result = (*find) (head->next, matchdata);
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
if (result)
{
stale = head->next;
head->next = stale->next;
}
}
}
return result;
}
/* Call FIND repeatedly with each element of SLIST and MATCHDATA, until
FIND returns non-NULL, or the list is exhausted. If a match is found
the value returned by the matching call to FIND is returned. */
void *
slist_find (SList *slist, SListCallback *find, void *matchdata)
{
void *result = 0;
assert (find);
for (; slist; slist = slist->next)
{
result = (*find) (slist, matchdata);
if (result)
break;
}
return result;
}
/* Return a single list, composed by destructively concatenating the
items in HEAD and TAIL. The values of HEAD and TAIL are undefined
after calling this function.
CAVEAT: Don't mix boxed and unboxed items in a single list.
e.g. slist1 = slist_concat (slist1, slist2); */
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
SList *
slist_concat (SList *head, SList *tail)
{
if (!head)
{
return tail;
}
while (head->next)
head = head->next;
head->next = tail;
return head;
}
/* Return a single list, composed by destructively appending all of
the items in SLIST to ITEM. The values of ITEM and SLIST are undefined
after calling this function.
CAVEAT: Don't mix boxed and unboxed items in a single list.
e.g. slist1 = slist_cons (slist_box (data), slist1); */
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
SList *
slist_cons (SList *item, SList *slist)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
if (!item)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
return slist;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
assert (!item->next);
item->next = slist;
return item;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
/* Return a list starting at the second item of SLIST. */
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
SList *
slist_tail (SList *slist)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
return slist ? slist->next : 0;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
/* Return a list starting at the Nth item of SLIST. If SLIST is less
than N items long, NULL is returned. Just to be confusing, list items
are counted from 1, to get the 2nd element of slist:
e.g. shared_list = slist_nth (slist, 2); */
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
SList *
slist_nth (SList *slist, size_t n)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
for (;n > 1 && slist; n--)
slist = slist->next;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
return slist;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
/* Return the number of items in SLIST. We start counting from 1, so
the length of a list with no items is 0, and so on. */
size_t
slist_length (SList *slist)
{
size_t n;
for (n = 0; slist; ++n)
slist = slist->next;
return n;
}
/* Destructively reverse the order of items in SLIST. The value of SLIST
is undefined after calling this function.
CAVEAT: You must store the result of this function, or you might not
be able to get all the items except the first one back again.
e.g. slist = slist_reverse (slist); */
SList *
slist_reverse (SList *slist)
{
SList *result = 0;
SList *next;
while (slist)
{
next = slist->next;
slist->next = result;
result = slist;
slist = next;
}
return result;
}
/* Call FOREACH once for each item in SLIST, passing both the item and
USERDATA on each call. */
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
void *
slist_foreach (SList *slist, SListCallback *foreach, void *userdata)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
void *result = 0;
assert (foreach);
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
while (slist)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
SList *next = slist->next;
void *result = (*foreach) (slist, userdata);
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
if (result)
break;
slist = next;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
return result;
}
/* Destructively merge the items of two ordered lists LEFT and RIGHT,
returning a single sorted list containing the items of both -- Part of
the quicksort algorithm. The values of LEFT and RIGHT are undefined
after calling this function.
At each iteration, add another item to the merged list by taking the
lowest valued item from the head of either LEFT or RIGHT, determined
by passing those items and USERDATA to COMPARE. COMPARE should return
less than 0 if the head of LEFT has the lower value, greater than 0 if
the head of RIGHT has the lower value, otherwise 0. */
static SList *
slist_sort_merge (SList *left, SList *right, SListCompare *compare,
void *userdata)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
SList merged, *insert;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
insert = &merged;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
while (left && right)
{
if ((*compare) (left, right, userdata) <= 0)
{
insert = insert->next = left;
left = left->next;
}
else
{
insert = insert->next = right;
right = right->next;
}
}
insert->next = left ? left : right;
return merged.next;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
/* Perform a destructive quicksort on the items in SLIST, by repeatedly
calling COMPARE with a pair of items from SLIST along with USERDATA
at every iteration. COMPARE is a function as defined above for
slist_sort_merge(). The value of SLIST is undefined after calling
this function.
e.g. slist = slist_sort (slist, compare, 0); */
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
SList *
slist_sort (SList *slist, SListCompare *compare, void *userdata)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
SList *left, *right;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
if (!slist)
return slist;
/* Be sure that LEFT and RIGHT never contain the same item. */
left = slist;
right = slist->next;
/* Skip two items with RIGHT and one with SLIST, until RIGHT falls off
the end. SLIST must be about half way along. */
while (right && (right = right->next))
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
if (!right || !(right = right->next))
break;
slist = slist->next;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
right = slist->next;
slist->next = 0;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
/* Sort LEFT and RIGHT, then merge the two. */
return slist_sort_merge (slist_sort (left, compare, userdata),
slist_sort (right, compare, userdata),
compare, userdata);
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}
/* Aside from using the functions above to manage chained structures of
any type that has a NEXT pointer as its first field, SLISTs can
be comprised of boxed items. The boxes are chained together in
that case, so there is no need for a NEXT field in the item proper.
Some care must be taken to slist_box and slist_unbox each item in
a boxed list at the appropriate points to avoid leaking the memory
used for the boxes. It us usually a very bad idea to mix boxed and
non-boxed items in a single list. */
/* Return a `boxed' freshly mallocated 1 element list containing
USERDATA. */
SList *
slist_box (const void *userdata)
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
{
SList *item = malloc (sizeof *item);
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
if (item)
{
item->next = 0;
item->userdata = userdata;
}
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
return item;
}
/* Return the contents of a `boxed' ITEM, recycling the box itself. */
void *
slist_unbox (SList *item)
{
void *userdata = 0;
if (item)
{
/* Strip the const, because responsibility for this memory
passes to the caller on return. */
userdata = (void *) item->userdata;
free (item);
}
return userdata;
Split lt_dlloader management into a separate file, and factor `loaders' list management into a new SList ADT. In the process, the API for writing loaders is a little cleaner, so all the existing loaders were tweaked to take advantage of that: * libltdl/slist.h, libltdl/slist.c: New files implementing a generic singly linked list container ADT. The ADT is purely internal, and none of its API's are visible from an installed libltdl. * libltdl/lt_dlloader.h (lt_dlloader): Removed next field again :-) Renamed to lt_dlvtable for API. Changed all callers. (lt_dlloader_get): New function to turn an lt_dlloader into its associated lt_dlvtable. (lt_dlloader_add): Removed unused data parameter. The caller data belongs to (and is set by) the loader itself, not the loader's client. Changed all callers. (lt_dlloader_name, lt_dlloader_data): Removed. Use lt_dlloader_get instead! * libltdl/lt__private.h: Include slist.h. (lt__alloc_die_callback): Add missing LT_SCOPE to declaration. (lt_dlhandle_struct): Use lt_dlvtable instead of opaque lt_dlloader. * libltdl/ltdl.c (lt_dlexit): Rewritten for the new loader API. (loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): Moved from here... * libltdl/lt_dlloader.c ((loaders, lt_dlloader_add, lt_dlloader_remove, lt_dlloader_next, lt_dlloader_find): ...to here. And rewritten in terms of new SList interface. * libltdl/ltdl.c (lt_dlexit, tryall_dlopen): Rewritten in terms of new lt_dlloader interface. * libltdl/Makefile.am (libdlloader_la_SOURCES): Add slist.h and slist.c. Move lt_dlloader.h from here... (pkginclude_HEADERS): ...to here. (libltdl_la_SOURCES): Add lt_dlloader.c and lt_dlloader.h.
2004-07-15 20:33:20 +08:00
}