Changeset bc56f30 in mainline for uspace/lib/c/include/adt/list.h


Ignore:
Timestamp:
2019-05-27T12:38:26Z (5 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0d14c25
Parents:
4d51c60
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-13 16:06:49)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-05-27 12:38:26)
Message:

Make some libc and libposix headers usable in C++

These headers either get included from standard C++ headers,
or are standard themselves, which means any unnamespaced nonstandard
identifiers are a problem. This commit attempts to fix those
issues, and removes hacks previously used in libcpp to work around it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/include/adt/list.h

    r4d51c60 rbc56f30  
    4242#include <stdint.h>
    4343#include <trace.h>
    44 
    45 /** Doubly linked list link. */
    46 typedef struct link {
    47         struct link *prev;  /**< Pointer to the previous item in the list. */
    48         struct link *next;  /**< Pointer to the next item in the list. */
    49 } link_t;
    50 
    51 /** Doubly linked list. */
    52 typedef struct list {
    53         link_t head;  /**< List head. Does not have any data. */
    54 } list_t;
    55 
    56 extern bool list_member(const link_t *, const list_t *);
    57 extern void list_splice(list_t *, link_t *);
    58 extern unsigned long list_count(const list_t *);
     44#include <_bits/decls.h>
     45
     46#ifndef __cplusplus
     47
     48/**
     49 * We don't define the macros in C++ to avoid polluting headers with
     50 * namespaceless names. We don't actually need them, so this is fine.
     51 * We still allow including the rest of the file (in `helenos` namespace)
     52 * so that we can expose publicly visible types that have list_t members.
     53 */
    5954
    6055/** Declare and initialize statically allocated list.
     
    138133        assert(!link_used(link))
    139134
     135#define list_pop(list, type, member) \
     136        ((type *) list_pop_internal(list, \
     137            (list_link_to_void(&(((type *) NULL)->member)) - NULL)))
     138
     139#endif  /* !__cplusplus */
     140
     141__HELENOS_DECLS_BEGIN;
     142
     143/** Doubly linked list link. */
     144typedef struct __adt_list_link {
     145        struct __adt_list_link *prev;  /**< Pointer to the previous item in the list. */
     146        struct __adt_list_link *next;  /**< Pointer to the next item in the list. */
     147} link_t;
     148
     149/** Doubly linked list. */
     150typedef struct {
     151        link_t head;  /**< List head. Does not have any data. */
     152} list_t;
     153
     154extern bool list_member(const link_t *, const list_t *);
     155extern void list_splice(list_t *, link_t *);
     156extern unsigned long list_count(const list_t *);
     157
    140158/** Returns true if the link is definitely part of a list. False if not sure. */
    141159static inline bool link_in_use(const link_t *link)
     
    425443}
    426444
    427 #define list_pop(list, type, member) \
    428         ((type *) list_pop_internal(list, \
    429             (list_link_to_void(&(((type *) NULL)->member)) - NULL)))
     445__HELENOS_DECLS_END;
    430446
    431447#endif
Note: See TracChangeset for help on using the changeset viewer.