ObjFW  Check-in [66f6ca045c]

Overview
Comment:Indent defines and imports where it is useful.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 66f6ca045c09c62debf486c3b470ee7c10c1c8df4c6e658acbfd45811053572d
User & Date: js on 2009-12-09 18:43:52
Other Links: manifest | tags
Context
2009-12-09
19:09
Check whether getaddrinfo is thread-safe and use locks if not. check-in: c8398d985d user: js tags: trunk
18:43
Indent defines and imports where it is useful. check-in: 66f6ca045c user: js tags: trunk
2009-12-07
20:12
Fix typo. check-in: ed366ad8f8 user: js tags: trunk
Changes

Modified src/OFExceptions.m from [0ba93b17bb] to [dd4a5ac59f].

13
14
15
16
17
18
19
20

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#import <objc/objc-api.h>
#ifdef __objc_INCLUDE_GNU

#define SEL_NAME(x) sel_get_name(x)
#else
#import <objc/runtime.h>
#define SEL_NAME(x) sel_getName(x)
#endif

#import "OFExceptions.h"
#import "OFTCPSocket.h"

#ifndef _WIN32
#include <errno.h>
#define GET_ERR	     errno
#ifndef HAVE_GETADDRINFO
#define GET_AT_ERR   h_errno
#else
#define GET_AT_ERR   errno
#endif
#define GET_SOCK_ERR errno
#define ERRFMT	     "Error string was: %s"
#define ERRPARAM     strerror(err)
#ifndef HAVE_GETADDRINFO
#define AT_ERRPARAM  hstrerror(err)
#else
#define AT_ERRPARAM  strerror(err)
#endif
#else
#include <windows.h>
#define GET_ERR	     GetLastError()
#define GET_AT_ERR   WSAGetLastError()
#define GET_SOCK_ERR WSAGetLastError()
#define ERRFMT	     "Error code was: %d"
#define ERRPARAM     err
#define AT_ERRPARAM  err
#endif

#import "asprintf.h"

@implementation OFAllocFailedException
+ (Class)class
{







|
>
|

<
|






|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|







13
14
15
16
17
18
19
20
21
22
23

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#import <objc/objc-api.h>
#ifdef OF_APPLE_RUNTIME
# import <objc/runtime.h>
# define SEL_NAME(x) sel_getName(x)
#else

# define SEL_NAME(x) sel_get_name(x)
#endif

#import "OFExceptions.h"
#import "OFTCPSocket.h"

#ifndef _WIN32
# include <errno.h>
# define GET_ERR	errno
# ifndef HAVE_GETADDRINFO
#  define GET_AT_ERR	h_errno
# else
#  define GET_AT_ERR	errno
# endif
# define GET_SOCK_ERR	errno
# define ERRFMT		"Error string was: %s"
# define ERRPARAM	strerror(err)
# ifndef HAVE_GETADDRINFO
#  define AT_ERRPARAM	hstrerror(err)
# else
#  define AT_ERRPARAM	strerror(err)
# endif
#else
# include <windows.h>
# define GET_ERR	GetLastError()
# define GET_AT_ERR	WSAGetLastError()
# define GET_SOCK_ERR	WSAGetLastError()
# define ERRFMT		"Error code was: %d"
# define ERRPARAM	err
# define AT_ERRPARAM	err
#endif

#import "asprintf.h"

@implementation OFAllocFailedException
+ (Class)class
{

Modified src/OFMacros.h from [c7622317c1] to [423a04e77c].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#import "objfw-defs.h"

#include <stddef.h>
#include <stdint.h>

#ifdef __GNUC__
#define OF_INLINE inline __attribute__((always_inline))
#define OF_LIKELY(cond) __builtin_expect(!!(cond), 1)
#define OF_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else
#define OF_INLINE inline
#define OF_LIKELY(cond) cond
#define OF_UNLIKELY(cond) cond
#endif

/* Required to build universal binaries on OS X */
#if __BIG_ENDIAN__ || __LITTLE_ENDIAN__
#if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
#error __BIG_ENDIAN__ and __LITTLE_ENDIAN__ defined!
#endif
#undef OF_BIG_ENDIAN
#if __BIG_ENDIAN__
#define OF_BIG_ENDIAN
#endif
#endif

#ifdef __GNUC__
#if defined(__amd64__) || defined(__x86_64__)
#define OF_AMD64_ASM
#elif defined(__i386__)
#define OF_X86_ASM
#elif defined(__ppc__) || defined(__PPC__)
#define OF_PPC_ASM
#elif defined(__arm__) || defined(__ARM__)
#define OF_ARM_ASM
#endif
#endif

#define OF_BSWAP16_CONST(i)					\
	(((uint16_t)i & UINT16_C(0xFF00)) >> 8 |		\
	 ((uint16_t)i & UINT16_C(0x00FF)) << 8)
#define OF_BSWAP32_CONST(i)					\
	(((uint32_t)i & UINT32_C(0xFF000000)) >> 24 |		\







|
|
|

|
|
|




|
|
|
|
|
|
|



|
|
|
|
|
|
|
|
|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

#import "objfw-defs.h"

#include <stddef.h>
#include <stdint.h>

#ifdef __GNUC__
# define OF_INLINE inline __attribute__((always_inline))
# define OF_LIKELY(cond) __builtin_expect(!!(cond), 1)
# define OF_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#else
# define OF_INLINE inline
# define OF_LIKELY(cond) cond
# define OF_UNLIKELY(cond) cond
#endif

/* Required to build universal binaries on OS X */
#if __BIG_ENDIAN__ || __LITTLE_ENDIAN__
# if __BIG_ENDIAN__ && __LITTLE_ENDIAN__
#  error __BIG_ENDIAN__ and __LITTLE_ENDIAN__ defined!
# endif
# undef OF_BIG_ENDIAN
# if __BIG_ENDIAN__
#  define OF_BIG_ENDIAN
# endif
#endif

#ifdef __GNUC__
# if defined(__amd64__) || defined(__x86_64__)
#  define OF_AMD64_ASM
# elif defined(__i386__)
#  define OF_X86_ASM
# elif defined(__ppc__) || defined(__PPC__)
#  define OF_PPC_ASM
# elif defined(__arm__) || defined(__ARM__)
#  define OF_ARM_ASM
# endif
#endif

#define OF_BSWAP16_CONST(i)					\
	(((uint16_t)i & UINT16_C(0xFF00)) >> 8 |		\
	 ((uint16_t)i & UINT16_C(0x00FF)) << 8)
#define OF_BSWAP32_CONST(i)					\
	(((uint32_t)i & UINT32_C(0xFF000000)) >> 24 |		\
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	i = (uint64_t)OF_BSWAP32_NONCONST(i & 0xFFFFFFFF) << 32 |
	    OF_BSWAP32_NONCONST(i >> 32);
#endif
	return i;
}

#ifdef __GNUC__
#define OF_BSWAP16(i) \
	(__builtin_constant_p(i) ? OF_BSWAP16_CONST(i) : OF_BSWAP16_NONCONST(i))
#define OF_BSWAP32(i) \
	(__builtin_constant_p(i) ? OF_BSWAP32_CONST(i) : OF_BSWAP32_NONCONST(i))
#define OF_BSWAP64(i) \
	(__builtin_constant_p(i) ? OF_BSWAP64_CONST(i) : OF_BSWAP64_NONCONST(i))
#else
#define OF_BSWAP16(i) OF_BSWAP16_CONST(i)
#define OF_BSWAP32(i) OF_BSWAP32_CONST(i)
#define OF_BSWAP64(i) OF_BSWAP64_CONST(i)
#endif

static OF_INLINE void
OF_BSWAP32_V(uint32_t *buf, size_t len)
{
	while (len--) {
		*buf = OF_BSWAP32(*buf);
		buf++;
	}
}

#ifdef OF_BIG_ENDIAN
#define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i)
#define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i)
#define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i)
#define OF_BSWAP16_IF_LE(i) i
#define OF_BSWAP32_IF_LE(i) i
#define OF_BSWAP64_IF_LE(i) i
#define OF_BSWAP32_V_IF_BE(buf, len) OF_BSWAP32_V(buf, len)
#else
#define OF_BSWAP16_IF_BE(i) i
#define OF_BSWAP32_IF_BE(i) i
#define OF_BSWAP64_IF_BE(i) i
#define OF_BSWAP16_IF_LE(i) OF_BSWAP16(i)
#define OF_BSWAP32_IF_LE(i) OF_BSWAP32(i)
#define OF_BSWAP64_IF_LE(i) OF_BSWAP64(i)
#define OF_BSWAP32_V_IF_BE(buf, len)
#endif

#define OF_ROL(val, bits) \
	(((val) << (bits)) | ((val) >> (32 - (bits))))

#define OF_HASH_INIT(hash) hash = 0
#define OF_HASH_ADD(hash, byte)		\







|

|

|


|
|
|












|
|
|
|
|
|
|

|
|
|
|
|
|
|







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
	i = (uint64_t)OF_BSWAP32_NONCONST(i & 0xFFFFFFFF) << 32 |
	    OF_BSWAP32_NONCONST(i >> 32);
#endif
	return i;
}

#ifdef __GNUC__
# define OF_BSWAP16(i) \
	(__builtin_constant_p(i) ? OF_BSWAP16_CONST(i) : OF_BSWAP16_NONCONST(i))
# define OF_BSWAP32(i) \
	(__builtin_constant_p(i) ? OF_BSWAP32_CONST(i) : OF_BSWAP32_NONCONST(i))
# define OF_BSWAP64(i) \
	(__builtin_constant_p(i) ? OF_BSWAP64_CONST(i) : OF_BSWAP64_NONCONST(i))
#else
# define OF_BSWAP16(i) OF_BSWAP16_CONST(i)
# define OF_BSWAP32(i) OF_BSWAP32_CONST(i)
# define OF_BSWAP64(i) OF_BSWAP64_CONST(i)
#endif

static OF_INLINE void
OF_BSWAP32_V(uint32_t *buf, size_t len)
{
	while (len--) {
		*buf = OF_BSWAP32(*buf);
		buf++;
	}
}

#ifdef OF_BIG_ENDIAN
# define OF_BSWAP16_IF_BE(i) OF_BSWAP16(i)
# define OF_BSWAP32_IF_BE(i) OF_BSWAP32(i)
# define OF_BSWAP64_IF_BE(i) OF_BSWAP64(i)
# define OF_BSWAP16_IF_LE(i) i
# define OF_BSWAP32_IF_LE(i) i
# define OF_BSWAP64_IF_LE(i) i
# define OF_BSWAP32_V_IF_BE(buf, len) OF_BSWAP32_V(buf, len)
#else
# define OF_BSWAP16_IF_BE(i) i
# define OF_BSWAP32_IF_BE(i) i
# define OF_BSWAP64_IF_BE(i) i
# define OF_BSWAP16_IF_LE(i) OF_BSWAP16(i)
# define OF_BSWAP32_IF_LE(i) OF_BSWAP32(i)
# define OF_BSWAP64_IF_LE(i) OF_BSWAP64(i)
# define OF_BSWAP32_V_IF_BE(buf, len)
#endif

#define OF_ROL(val, bits) \
	(((val) << (bits)) | ((val) >> (32 - (bits))))

#define OF_HASH_INIT(hash) hash = 0
#define OF_HASH_ADD(hash, byte)		\

Modified src/OFObject.m from [6eaebd22dd] to [ff3d52f1b1].

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "OFObject.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#import <objc/objc-api.h>
#ifdef OF_APPLE_RUNTIME
#import <objc/runtime.h>
#endif
#ifdef OF_GNU_RUNTIME
#import <objc/sarray.h>
#endif

struct pre_ivar {
	void   **memchunks;
	size_t memchunks_size;
	size_t retain_count;
};







|


|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#import "OFObject.h"
#import "OFAutoreleasePool.h"
#import "OFExceptions.h"
#import "OFMacros.h"

#import <objc/objc-api.h>
#ifdef OF_APPLE_RUNTIME
# import <objc/runtime.h>
#endif
#ifdef OF_GNU_RUNTIME
# import <objc/sarray.h>
#endif

struct pre_ivar {
	void   **memchunks;
	size_t memchunks_size;
	size_t retain_count;
};

Modified src/OFTCPSocket.m from [f19d63597b] to [4bb7848f0c].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "config.h"

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#ifndef HAVE_GETADDRINFO
#include <stdlib.h>
#ifndef _WIN32
#include <arpa/inet.h>
#endif
#endif

#import "OFTCPSocket.h"
#import "OFExceptions.h"

#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1







|
|
|
|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "config.h"

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#ifndef HAVE_GETADDRINFO
# include <stdlib.h>
# ifndef _WIN32
#  include <arpa/inet.h>
# endif
#endif

#import "OFTCPSocket.h"
#import "OFExceptions.h"

#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1

Modified src/threading.h from [04a0546353] to [0ccf73f4cd].

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <windows.h>
typedef HANDLE of_thread_t;
typedef CRITICAL_SECTION of_mutex_t;
typedef DWORD of_tlskey_t;
#endif

#ifndef _WIN32
#define of_thread_is_current(t) pthread_equal(t, pthread_self())
#define of_thread_current() pthread_self()
#else
#define of_thread_is_current(t) (t == GetCurrentThread())
#define of_thread_current() GetCurrentThread()
#endif

static OF_INLINE BOOL
of_thread_new(of_thread_t *thread, id (*main)(id), id data)
{
#ifndef _WIN32
	return (pthread_create(thread, NULL, (void*(*)(void*))main,







|
|

|
|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <windows.h>
typedef HANDLE of_thread_t;
typedef CRITICAL_SECTION of_mutex_t;
typedef DWORD of_tlskey_t;
#endif

#ifndef _WIN32
# define of_thread_is_current(t) pthread_equal(t, pthread_self())
# define of_thread_current() pthread_self()
#else
# define of_thread_is_current(t) (t == GetCurrentThread())
# define of_thread_current() GetCurrentThread()
#endif

static OF_INLINE BOOL
of_thread_new(of_thread_t *thread, id (*main)(id), id data)
{
#ifndef _WIN32
	return (pthread_create(thread, NULL, (void*(*)(void*))main,