ObjFW  Check-in [b46492384a]

Overview
Comment:of_bitset_*: Use CHAR_BIT instead of 8
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b46492384acd42133377a5dcf8638cadcf005dcae157a5b2d7d6fc65b8f99350
User & Date: js on 2020-11-29 00:59:23
Other Links: manifest | tags
Context
2020-11-29
02:21
Fix a few places using msec instead of usec check-in: 208285040f user: js tags: trunk
00:59
of_bitset_*: Use CHAR_BIT instead of 8 check-in: b46492384a user: js tags: trunk
2020-11-28
19:28
Fix building for Windows check-in: 4a7b3657d0 user: js tags: trunk
Changes

Modified src/OFBitSetCharacterSet.m from [a0186359ac] to [b1c313bb58].

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
		void *pool = objc_autoreleasePoolPush();
		const of_unichar_t *characters = string.characters;
		size_t length = string.length;

		for (size_t i = 0; i < length; i++) {
			of_unichar_t c = characters[i];

			if (c / 8 >= _size) {
				size_t newSize;

				if (UINT32_MAX - c < 1)
					@throw [OFOutOfRangeException
					    exception];

				newSize = OF_ROUND_UP_POW2(8, c + 1) / 8;


				_bitset = of_realloc(_bitset, newSize, 1);
				memset(_bitset + _size, '\0', newSize - _size);

				_size = newSize;
			}








|






|
>







36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
		void *pool = objc_autoreleasePoolPush();
		const of_unichar_t *characters = string.characters;
		size_t length = string.length;

		for (size_t i = 0; i < length; i++) {
			of_unichar_t c = characters[i];

			if (c / CHAR_BIT >= _size) {
				size_t newSize;

				if (UINT32_MAX - c < 1)
					@throw [OFOutOfRangeException
					    exception];

				newSize = OF_ROUND_UP_POW2(CHAR_BIT, c + 1) /
				    CHAR_BIT;

				_bitset = of_realloc(_bitset, newSize, 1);
				memset(_bitset + _size, '\0', newSize - _size);

				_size = newSize;
			}

72
73
74
75
76
77
78
79
80
81
82
83
84
	free(_bitset);

	[super dealloc];
}

- (bool)characterIsMember: (of_unichar_t)character
{
	if (character / 8 >= _size)
		return false;

	return of_bitset_isset(_bitset, character);
}
@end







|





73
74
75
76
77
78
79
80
81
82
83
84
85
	free(_bitset);

	[super dealloc];
}

- (bool)characterIsMember: (of_unichar_t)character
{
	if (character / CHAR_BIT >= _size)
		return false;

	return of_bitset_isset(_bitset, character);
}
@end

Modified src/OFSecureData.m from [960649af1d] to [7de8ab3a25].

97
98
99
100
101
102
103
104

105
106
107
108
109
110
111
	munmap(pointer, numPages * pageSize);
}

static struct page *
addPage(bool allowPreallocated)
{
	size_t pageSize = [OFSystemInfo pageSize];
	size_t mapSize = OF_ROUND_UP_POW2(8, pageSize / CHUNK_SIZE) / 8;

	struct page *page;
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	struct page *lastPage;
# endif

	if (allowPreallocated) {
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)







|
>







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
	munmap(pointer, numPages * pageSize);
}

static struct page *
addPage(bool allowPreallocated)
{
	size_t pageSize = [OFSystemInfo pageSize];
	size_t mapSize = OF_ROUND_UP_POW2(CHAR_BIT, pageSize / CHUNK_SIZE) /
	    CHAR_BIT;
	struct page *page;
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	struct page *lastPage;
# endif

	if (allowPreallocated) {
# if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
182
183
184
185
186
187
188
189

190
191
192
193
194
195
196
}

static void
removePageIfEmpty(struct page *page)
{
	unsigned char *map = page->map;
	size_t pageSize = [OFSystemInfo pageSize];
	size_t mapSize = OF_ROUND_UP_POW2(8, pageSize / CHUNK_SIZE) / 8;


	for (size_t i = 0; i < mapSize; i++)
		if (map[i] != 0)
			return;

	unmapPages(page->page, 1);
	free(page->map);







|
>







183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
}

static void
removePageIfEmpty(struct page *page)
{
	unsigned char *map = page->map;
	size_t pageSize = [OFSystemInfo pageSize];
	size_t mapSize = OF_ROUND_UP_POW2(CHAR_BIT, pageSize / CHUNK_SIZE) /
	    CHAR_BIT;

	for (size_t i = 0; i < mapSize; i++)
		if (map[i] != 0)
			return;

	unmapPages(page->page, 1);
	free(page->map);

Modified src/macros.h from [43e7dc4d8f] to [7383bf6570].

23
24
25
26
27
28
29

30
31
32
33
34
35
36
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
#endif
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif


#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>








>







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef __STDC_LIMIT_MACROS
# define __STDC_LIMIT_MACROS
#endif
#ifndef __STDC_CONSTANT_MACROS
# define __STDC_CONSTANT_MACROS
#endif

#include <limits.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
		OF_HASH_ADD(hash, (otherCopy >>  8) & 0xFF);	\
		OF_HASH_ADD(hash, otherCopy & 0xFF);		\
	}

static OF_INLINE bool
of_bitset_isset(unsigned char *_Nonnull storage, size_t idx)
{
	return storage[idx / 8] & (1u << (idx % 8));
}

static OF_INLINE void
of_bitset_set(unsigned char *_Nonnull storage, size_t idx)
{
	storage[idx / 8] |= (1u << (idx % 8));
}

static OF_INLINE void
of_bitset_clear(unsigned char *_Nonnull storage, size_t idx)
{
	storage[idx / 8] &= ~(1u << (idx % 8));
}

static OF_INLINE char *_Nullable
of_strdup(const char *_Nonnull string)
{
	char *copy;
	size_t length = strlen(string);







|





|





|







821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
		OF_HASH_ADD(hash, (otherCopy >>  8) & 0xFF);	\
		OF_HASH_ADD(hash, otherCopy & 0xFF);		\
	}

static OF_INLINE bool
of_bitset_isset(unsigned char *_Nonnull storage, size_t idx)
{
	return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT));
}

static OF_INLINE void
of_bitset_set(unsigned char *_Nonnull storage, size_t idx)
{
	storage[idx / CHAR_BIT] |= (1u << (idx % CHAR_BIT));
}

static OF_INLINE void
of_bitset_clear(unsigned char *_Nonnull storage, size_t idx)
{
	storage[idx / CHAR_BIT] &= ~(1u << (idx % CHAR_BIT));
}

static OF_INLINE char *_Nullable
of_strdup(const char *_Nonnull string)
{
	char *copy;
	size_t length = strlen(string);