Skip to content

Commit

Permalink
sync (#1)
Browse files Browse the repository at this point in the history
* Minor utstring docs cleanup.

Thanks to @tbeu for the patch!
This is adapted from part of troydhanson#95.

* Remove cast to "unsigned" from utstring_len macro.

It causes truncation on 64-bit platforms, and neither @troydhanson
nor myself know why it should have been there in the first place.

Thanks to @mse11 for the patch (troydhanson#97)!

* Silence an instance of -Wsign-compare in the tests.

* Fix a segfault in HASH_ADD_KEYPTR_INORDER.

Thanks to @IronBug for the bug report (troydhanson#99) and test90.c!

test87.c would have caught this bug at the time the macros were added,
except that by chance `offsetof(hstruct_t, hh)` was `0`. I've adjusted
the test so that it fails before this patch and succeeds after.

* Document test90.c in tests/README.

I should have done this in 13723b1, but forgot.
No functional change.

* Make `make pedantic` and `make cplusplus` build cleanly again.

Basically just adding malloc-casts and explicit casts from
string literals to `(char *)` (since that gives a deprecation
warning in clang++ these days).

No intended functional change.

* Add "Android" to the list of supported platforms.

Requested by @silvioprog! He writes:

> It worked like a charm for my ARMv7 and finally I can use an efficient
> C hash table in my Android (tested on version 5 and 6) application.

Sure, technically "Android" is covered by "Linux" anyway. :)

Fixes troydhanson#103.

* Bump version to 2.0.2.

* utlist: Add an assert to silence a scan-build diagnostic.

Thanks to @aaronmdjones for the report!

Unfortunately scan-build is unhappy with uthash and utarray
as well, and the fixes seem harder in those cases. Especially
since there's no tradition of adding redundant asserts in those
files, and I wouldn't really want to start. This case is easy
because we've already committed to liberal use of asserts in
utlist (for whatever reason).

* utlist: Add INORDER macros for inserting into sorted lists.

Thanks to @jeffreylovitz for the initial patch!

The `{LL,DL,CDL}_LOWER_BOUND` macros have semantics similar to C++'s
`std::lower_bound` algorithm: in essence they return an iterator to
the first existing list element which is *not less than* the given
one. However, in this context an "iterator to element X" is actually
a "pointer to element X-1", because our lists support only
insertion-after, not insertion-before. Therefore, in situations
where `std::lower_bound` would return `lst.begin()` we return `NULL`,
and in cases where `std::lower_bound` would return `lst.end()` we
return a pointer to the last element of the list.

* uthash, utlist: Make the NO_DECLTYPE codepaths match more closely.

utlist had made `NO_DECLTYPE` the default on `__ICCARM__` since 368010b,
but uthash had never done so. Do so.

utlist gave double-definition errors if `-DNO_DECLTYPE` was passed
on the command line (for a compiler that otherwise supported decltype
and/or __typeof). Fix that.

Passing `-DLDECLTYPE(x)=decltype(x)` on the command line ought to do
the right thing. Make it at least not double-define `DECLTYPE`. But
we still have the problem that we do things like `LDECLTYPE(*p)`,
which in C++ yields an lvalue reference type, not an object type.
I don't know how to fix that.

uthash's test87.c and test90.c gave errors in C++ with `-DNO_DECLTYPE`
because the code now known as `HASH_AKBI_INNER_LOOP` would attempt to
call the provided `cmpfcn` with an argument of type `(void *)` instead
of the expected `decltype(head)`. This works in C with an implicit
conversion, but doesn't work at all in C++ because it would try to
call a different overload of the comparison function. So, if we have
`NO_DECLTYPE`, let's use `head` as a scratch variable.

* C89 compatibility: add a missing "return 0" to test89.c

No functional change.

* Convince Clang that `pid` is never used uninitialized in hashscan.c.

No functional change.

* Use non-reserved identifiers for some helper macros.

Identifiers beginning with an underscore and an uppercase letter
are reserved to the implementation, and Clang apparently warns on
such things these days (via -Wreserved-id-macro). Solution: rename
those macros to avoid leading underscores.

Fixes troydhanson#112.

* remove libut
  • Loading branch information
val314159 authored Apr 14, 2017
1 parent e7f4693 commit 8c7f3eb
Show file tree
Hide file tree
Showing 92 changed files with 538 additions and 1,787 deletions.
7 changes: 7 additions & 0 deletions doc/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Click to return to the link:index.html[uthash home page].

NOTE: This ChangeLog may be incomplete and/or incorrect. See the git commit log.

Version 2.0.2 (2017-03-02)
--------------------------
* fix segfault in HASH_ADD_INORDER etc (thanks, Yana Kireyonok!)
* remove spurious cast to unsigned in utstring_len (thanks, Michal Sestrienka!)
* add uthash_memcmp and uthash_strlen for platforms without <stdlib.h> (thanks, Pawel Veselov!)
* fix a C++ incompatibility in utringbuffer
Version 2.0.1 (2016-07-05)
--------------------------
* in-order insertion macros HASH_ADD_INORDER etc (thanks, Thilo Schulz!)
Expand Down
2 changes: 1 addition & 1 deletion doc/license.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div id="mid">
<div id="main">
<pre>
Copyright (c) 2005-2016, Troy D. Hanson http://troydhanson.github.com/uthash/
Copyright (c) 2005-2017, Troy D. Hanson http://troydhanson.github.com/uthash/
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
3 changes: 2 additions & 1 deletion doc/userguide.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
uthash User Guide
=================
Troy D. Hanson, Arthur O'Dwyer
v2.0.1, July 2016
v2.0.2, March 2017

To download uthash, follow this link back to the
https://github.com/troydhanson/uthash[GitHub project page].
Expand Down Expand Up @@ -55,6 +55,7 @@ This software can be used in C and C++ programs. It has been tested on:
* Solaris
* OpenBSD
* FreeBSD
* Android

Test suite
^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion doc/utarray.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
utarray: dynamic array macros for C
===================================
Troy D. Hanson <tdh@tkhanson.net>
v2.0.1, July 2016
v2.0.2, March 2017

Here's a link back to the https://github.com/troydhanson/uthash[GitHub project page].

Expand Down
26 changes: 20 additions & 6 deletions doc/utlist.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
utlist: linked list macros for C structures
===========================================
Troy D. Hanson <tdh@tkhanson.net>
v2.0.1, July 2016
v2.0.2, March 2017

Here's a link back to the https://github.com/troydhanson/uthash[GitHub project page].

Expand Down Expand Up @@ -59,6 +59,8 @@ Deleting elements::
'O(n)' on singly-linked lists; constant-time on doubly-linked list.
Sorting::
'O(n log(n))' for all list types.
Insertion in order (for sorted lists)::
'O(n)' for all list types.
Iteration, counting and searching::
'O(n)' for all list types.
Expand Down Expand Up @@ -103,13 +105,15 @@ iterating over them.
|LL_APPEND_ELEM(head,ref,add); | DL_APPEND_ELEM(head,ref,add); | CDL_APPEND_ELEM(head,ref,add);
|LL_REPLACE_ELEM(head,del,add); | DL_REPLACE_ELEM(head,del,add); | CDL_REPLACE_ELEM(head,del,add);
|LL_APPEND(head,add); | DL_APPEND(head,add); | CDL_APPEND(head,add);
|LL_INSERT_INORDER(head,add,cmp); | DL_INSERT_INORDER(head,add,cmp); | CDL_INSERT_INORDER(head,add,cmp);
|LL_CONCAT(head1,head2); | DL_CONCAT(head1,head2); |
|LL_DELETE(head,del); | DL_DELETE(head,del); | CDL_DELETE(head,del);
|LL_SORT(head,cmp); | DL_SORT(head,cmp); | CDL_SORT(head,cmp);
|LL_FOREACH(head,elt) {...}| DL_FOREACH(head,elt) {...} | CDL_FOREACH(head,elt) {...}
|LL_FOREACH_SAFE(head,elt,tmp) {...}| DL_FOREACH_SAFE(head,elt,tmp) {...} | CDL_FOREACH_SAFE(head,elt,tmp1,tmp2) {...}
|LL_SEARCH_SCALAR(head,elt,mbr,val);| DL_SEARCH_SCALAR(head,elt,mbr,val); | CDL_SEARCH_SCALAR(head,elt,mbr,val);
|LL_SEARCH(head,elt,like,cmp);| DL_SEARCH(head,elt,like,cmp); | CDL_SEARCH(head,elt,like,cmp);
|LL_LOWER_BOUND(head,elt,like,cmp); | DL_LOWER_BOUND(head,elt,like,cmp); | CDL_LOWER_BOUND(head,elt,like,cmp);
|LL_COUNT(head,elt,count); | DL_COUNT(head,elt,count); | CDL_COUNT(head,elt,count);
|===============================================================================
Expand Down Expand Up @@ -141,6 +145,12 @@ There are two forms: the "scalar" version searches for an element using a
simple equality test on a given structure member, while the general version takes an
element to which all others in the list will be compared using a `cmp` function.
The 'lower_bound' operation finds the first element of the list which is no greater
than the provided `like` element, according to the provided `cmp` function.
The 'lower_bound' operation sets `elt` to a suitable value for passing to
`LL_APPEND_ELEM`; i.e., `elt=NULL` if the proper insertion point is at the front of
the list, and `elt=p` if the proper insertion point is between `p` and `p->next`.
The 'count' operation iterates over the list and increments a supplied counter.
The parameters shown in the table above are explained here:
Expand Down Expand Up @@ -273,8 +283,9 @@ the `prev` and `next` fields (as applicable) as trailing arguments.
LL_DELETE2(head, del, next);
LL_FOREACH2(head, elt, next) {...}
LL_FOREACH_SAFE2(head, elt, tmp, next) {...}
LL_SEARCH_SCALAR2(head, out, field, val, next);
LL_SEARCH2(head, out, elt, cmp, next);
LL_SEARCH_SCALAR2(head, elt, mbr, val, next);
LL_SEARCH2(head, elt, like, cmp, next);
LL_LOWER_BOUND2(head, elt, like, cmp, next);
LL_COUNT2(head, elt, count, next);
DL_PREPEND2(head, add, prev, next);
DL_PREPEND_ELEM2(head, ref, add, prev, next);
Expand All @@ -285,7 +296,9 @@ the `prev` and `next` fields (as applicable) as trailing arguments.
DL_DELETE2(head, del, prev, next);
DL_FOREACH2(head, elt, next) {...}
DL_FOREACH_SAFE2(head, elt, tmp, next) {...}
DL_SEARCH_SCALAR2(head, out, field, val, next);
DL_SEARCH_SCALAR2(head, elt, mbr, val, next);
DL_SEARCH2(head, elt, like, cmp, next);
DL_LOWER_BOUND2(head, elt, like, cmp, next);
DL_COUNT2(head, elt, count, next);
CDL_PREPEND2(head, add, prev, next);
CDL_PREPEND_ELEM2(head, ref, add, prev, next);
Expand All @@ -295,8 +308,9 @@ the `prev` and `next` fields (as applicable) as trailing arguments.
CDL_DELETE2(head, del, prev, next);
CDL_FOREACH2(head, elt, next) {...}
CDL_FOREACH_SAFE2(head, elt, tmp1, tmp2, prev, next) {...}
CDL_SEARCH_SCALAR2(head, out, field, val, next);
CDL_SEARCH2(head, out, elt, cmp, next);
CDL_SEARCH_SCALAR2(head, elt, mbr, val, next);
CDL_SEARCH2(head, elt, like, cmp, next);
CDL_LOWER_BOUND2(head, elt, like, cmp, next);
CDL_COUNT2(head, elt, count, next);
// vim: set tw=80 wm=2 syntax=asciidoc:
Expand Down
2 changes: 1 addition & 1 deletion doc/utringbuffer.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
utringbuffer: dynamic ring-buffer macros for C
==============================================
Arthur O'Dwyer <arthur[email protected]>
v2.0.1, July 2016
v2.0.2, March 2017

Here's a link back to the https://github.com/troydhanson/uthash[GitHub project page].

Expand Down
10 changes: 5 additions & 5 deletions doc/utstring.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
utstring: dynamic string macros for C
=====================================
Troy D. Hanson <tdh@tkhanson.net>
v2.0.1, July 2016
v2.0.2, March 2017

Here's a link back to the https://github.com/troydhanson/uthash[GitHub project page].

Expand Down Expand Up @@ -154,16 +154,16 @@ Operations
| utstring_new(s) | allocate a new utstring
| utstring_renew(s) | allocate a new utstring (if s is `NULL`) otherwise clears it
| utstring_free(s) | free an allocated utstring
| utstring_init(s) | init a utstring (non-alloc)
| utstring_done(s) | dispose of a utstring (non-allocd)
| utstring_init(s) | init a utstring (non-alloc)
| utstring_done(s) | dispose of a utstring (non-alloc)
| utstring_printf(s,fmt,...) | printf into a utstring (appends)
| utstring_bincpy(s,bin,len) | insert binary data of length len (appends)
| utstring_concat(dst,src) | concatenate src utstring to end of dst utstring
| utstring_clear(s) | clear the content of s (setting its length to 0)
| utstring_len(s) | obtain the length of s as an unsigned integer
| utstring_body(s) | get `char*` to body of s (buffer is always null-terminated)
| utstring_find(s,pos,str,len) | forward search from pos for a substring
| utstring_findR(s,pos,str,len) | reverse search from pos a substring
| utstring_findR(s,pos,str,len) | reverse search from pos for a substring
|===============================================================================

New/free vs. init/done
Expand All @@ -179,7 +179,7 @@ It comes in forward and reverse varieties. The reverse search scans from the end
the string backward. These take a position to start searching from, measured from 0
(the start of the utstring). A negative position is counted from the end of
the string, so, -1 is the last position. Note that in the reverse search, the
initial position anchors to the 'end' of the substring being searched for-
initial position anchors to the 'end' of the substring being searched for;
e.g., the 't' in 'cat'. The return value always refers to the offset where the
substring 'starts' in the utstring. When no substring match is found, -1 is
returned.
Expand Down
33 changes: 0 additions & 33 deletions libut/Makefile

This file was deleted.

30 changes: 0 additions & 30 deletions libut/README.md

This file was deleted.

1 change: 0 additions & 1 deletion libut/include

This file was deleted.

55 changes: 0 additions & 55 deletions libut/src/libut.c

This file was deleted.

81 changes: 0 additions & 81 deletions libut/src/ringbuf.c

This file was deleted.

Loading

0 comments on commit 8c7f3eb

Please sign in to comment.