Comment: | Merge trunk into branch "amiga-library"
All necessary changes to adjust for the changes made in trunk are |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | amiga-library |
Files: | files | file ages | folders |
SHA3-256: |
3c88df0ce49598d38d14db135dbc9f47 |
User & Date: | js on 2021-05-09 14:45:19 |
Other Links: | branch diff | manifest | tags |
2021-05-09
| ||
18:02 | Rename library.xml to amiga-library.xml check-in: a03b820df8 user: js tags: amiga-library | |
14:45 | Merge trunk into branch "amiga-library" check-in: 3c88df0ce4 user: js tags: amiga-library | |
10:17 | tests: Fix shadowed variable check-in: c80b60fcc9 user: js tags: trunk | |
2021-01-02
| ||
22:08 | Merge trunk into branch "amiga-library" check-in: 5ffdf1aebc user: js tags: amiga-library | |
Modified .fossil-settings/clean-glob from [21f56a0dfc] to [436c792c19].
︙ | ︙ | |||
44 45 46 47 48 49 50 | tests/tests.arm9 tests/tests.nds utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp | < | 44 45 46 47 48 49 50 | tests/tests.arm9 tests/tests.nds utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Modified .fossil-settings/ignore-glob from [7ba37c3560] to [5da8718334].
︙ | ︙ | |||
49 50 51 52 53 54 55 | tests/tests.arm9 tests/tests.nds utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp | < | 49 50 51 52 53 54 55 | tests/tests.arm9 tests/tests.nds utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Modified .github/ISSUE_TEMPLATE/config.yml from [ca7ebb224c] to [ee9213e864].
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 | - name: ObjFW Discord Channel url: https://objfw.nil.im/discord about: Please use this for interactive questions and support - it is bridged to the Matrix room above. - name: ObjFW Telegram Room url: https://t.me/objfw about: Please use this for interactive questions and support - it is bridged to the Matrix room above. | > > > > > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | - name: ObjFW Discord Channel url: https://objfw.nil.im/discord about: Please use this for interactive questions and support - it is bridged to the Matrix room above. - name: ObjFW Telegram Room url: https://t.me/objfw about: Please use this for interactive questions and support - it is bridged to the Matrix room above. - name: ObjFW Gitter Room url: https://gitter.im/ObjFW/ObjFW about: Please use this for interactive questions and support - it is bridged to the Matrix room above. |
Modified .gitignore from [5a4054131c] to [0c715f3134].
︙ | ︙ | |||
49 50 51 52 53 54 55 | tests/tests.arm9 tests/tests.nds utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp | < | 49 50 51 52 53 54 55 | tests/tests.arm9 tests/tests.nds utils/objfw-config utils/ofarc/ofarc utils/ofdns/ofdns utils/ofhash/ofhash utils/ofhttp/ofhttp |
Deleted .travis.yml version [0619e15749].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted .travis/before_install.sh version [bab3d81641].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted .travis/build.sh version [02fcddbdad].
|
| < < < < < < < < < < < < < < < < < < < < |
Deleted .travis/script.sh version [d2b60e0160].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified Doxyfile from [51b1f8245c] to [c1793ad29f].
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | PROJECT_NAME = "ObjFW" OUTPUT_DIRECTORY = docs/ INPUT = src src/exceptions src/runtime FILE_PATTERNS = *.h *.m HTML_OUTPUT = . GENERATE_LATEX = NO HIDE_UNDOC_CLASSES = YES HIDE_UNDOC_MEMBERS = YES PREDEFINED = __OBJC__ \ DOXYGEN \ OF_BOXABLE \ OF_CONSUMED \ OF_DESIGNATED_INITIALIZER \ OF_GENERIC(...)= \ OF_HAVE_BLOCKS \ | > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | PROJECT_NAME = "ObjFW" OUTPUT_DIRECTORY = docs/ INPUT = src src/exceptions src/runtime FILE_PATTERNS = *.h *.m HTML_OUTPUT = . GENERATE_LATEX = NO HIDE_UNDOC_CLASSES = YES HIDE_UNDOC_MEMBERS = YES TYPEDEF_HIDES_STRUCT = YES PREDEFINED = __OBJC__ \ DOXYGEN \ OF_BOXABLE \ OF_CONSUMED \ OF_DESIGNATED_INITIALIZER \ OF_GENERIC(...)= \ OF_HAVE_BLOCKS \ |
︙ | ︙ |
Modified Makefile from [d58557a5a6] to [b5f8b9bb2c].
︙ | ︙ | |||
21 22 23 24 25 26 27 | doxygen >/dev/null release: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." rm -fr objfw-${PACKAGE_VERSION} objfw-${PACKAGE_VERSION}.tar \ objfw-${PACKAGE_VERSION}.tar.gz fossil tarball --name objfw-${PACKAGE_VERSION} current - \ | | < | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | doxygen >/dev/null release: docs echo "Generating tarball for version ${PACKAGE_VERSION}..." rm -fr objfw-${PACKAGE_VERSION} objfw-${PACKAGE_VERSION}.tar \ objfw-${PACKAGE_VERSION}.tar.gz fossil tarball --name objfw-${PACKAGE_VERSION} current - \ --exclude '.cirrus*,.fossil*,.git*' | ofarc -ttgz -xq - cp configure config.h.in objfw-${PACKAGE_VERSION}/ ofarc -cq objfw-${PACKAGE_VERSION}.tar \ $$(find objfw-${PACKAGE_VERSION} | sort) rm -fr objfw-${PACKAGE_VERSION} gzip -9 objfw-${PACKAGE_VERSION}.tar rm -f objfw-${PACKAGE_VERSION}.tar gpg -b objfw-${PACKAGE_VERSION}.tar.gz || true |
︙ | ︙ |
Modified PLATFORMS.md from [13723754e6] to [f07389da3a].
︙ | ︙ | |||
63 64 65 66 67 68 69 70 71 72 73 74 75 76 | ----- * OS version: r1-alpha4 * Architectures: x86 * Compilers: Clang 3.2, GCC 4.6.3 * Runtimes: ObjFW iOS --- * Architectures: ARMv7, ARM64 * Compilers: Clang * Runtimes: Apple | > > > > > > > > > > > | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | ----- * OS version: r1-alpha4 * Architectures: x86 * Compilers: Clang 3.2, GCC 4.6.3 * Runtimes: ObjFW HP-UX ----- * OS versions: 11i v1 (PA-RISC 2.0), 11i v3 (Itanium) * Architectures: Itanium, PA-RISC 2.0 * Compilers: GCC 4.7.2, GCC 7.5.0 * Runtimes: ObjFW * Notes: Exception handling on Itanium in 32 bit mode is broken, you need to use 64 bit mode by passing `OBJC="gcc -mlp64"` to `configure`. iOS --- * Architectures: ARMv7, ARM64 * Compilers: Clang * Runtimes: Apple |
︙ | ︙ |
Modified README.md from [9d8e18dd0e] to [014bf7d4f3].
︙ | ︙ | |||
157 158 159 160 161 162 163 | To build for iOS, use something like this: $ clang="clang -isysroot $(xcrun --sdk iphoneos --show-sdk-path)" $ export OBJC="$clang -arch armv7 -arch arm64" $ export OBJCPP="$clang -arch armv7 -E" $ export IPHONEOS_DEPLOYMENT_TARGET="9.0" | | | | 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | To build for iOS, use something like this: $ clang="clang -isysroot $(xcrun --sdk iphoneos --show-sdk-path)" $ export OBJC="$clang -arch armv7 -arch arm64" $ export OBJCPP="$clang -arch armv7 -E" $ export IPHONEOS_DEPLOYMENT_TARGET="9.0" $ ./configure --prefix=/usr/local/ios --host=arm64-apple-darwin To build for the iOS simulator, use something like this: $ clang="clang -isysroot $(xcrun --sdk iphonesimulator --show-sdk-path)" $ export OBJC="$clang -arch i386 -arch x86_64" $ export OBJCPP="$clang -arch i386 -E" $ export IPHONEOS_DEPLOYMENT_TARGET="9.0" $ ./configure --prefix=/usr/local/iossim --host=x86_64-apple-darwin <h3 id="framework-in-xcode">Using the macOS or iOS framework in Xcode</h3> To use the macOS framework in Xcode, you need to add the `.framework`s to your project and add the following flags to `Other C Flags`: -fconstant-string-class=OFConstantString -fno-constant-cfstrings |
︙ | ︙ | |||
313 314 315 316 317 318 319 | $ objfw-new app MyFirstApp This creates a file `MyFirstApp.m`. The `-[applicationDidFinishLaunching]` method is called as soon as ObjFW finished all initialization. Use this as the entry point to your own code. For example, you could add the following line there to create a "Hello World": | | | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | $ objfw-new app MyFirstApp This creates a file `MyFirstApp.m`. The `-[applicationDidFinishLaunching]` method is called as soon as ObjFW finished all initialization. Use this as the entry point to your own code. For example, you could add the following line there to create a "Hello World": [OFStdOut writeLine: @"Hello World!"]; You can compile your new app using `objfw-compile`: $ objfw-compile -o MyFirstApp MyFirstApp.m `objfw-compile` is a tool that allows building applications and libraries using ObjFW without needing a full-blown build system. If you want to use |
︙ | ︙ | |||
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | ([Web chat](https://webchat.oftc.net/?channels=%23objfw)), bridged to the Matrix room above * A [Slack channel](https://objfw.nil.im/slack), bridged to the Matrix room above * A [Discord channel](https://objfw.nil.im/discord), bridged to the Matrix room above * A [Telegram room](https://t.me/objfw), bridged to the Matrix room above Please don't hesitate to join any or all of those! <h1 id="commercial-use">Commercial use</h1> If for whatever reason neither the terms of the QPL nor those of the GPL work for you, a proprietary license for ObjFW including support is available upon request. Just write a mail to js@nil.im and we can find a reasonable solution for both parties. | > > | 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | ([Web chat](https://webchat.oftc.net/?channels=%23objfw)), bridged to the Matrix room above * A [Slack channel](https://objfw.nil.im/slack), bridged to the Matrix room above * A [Discord channel](https://objfw.nil.im/discord), bridged to the Matrix room above * A [Telegram room](https://t.me/objfw), bridged to the Matrix room above * A [Gitter room](https://gitter.im/ObjFW/ObjFW), bridged to the Matrix room above Please don't hesitate to join any or all of those! <h1 id="commercial-use">Commercial use</h1> If for whatever reason neither the terms of the QPL nor those of the GPL work for you, a proprietary license for ObjFW including support is available upon request. Just write a mail to js@nil.im and we can find a reasonable solution for both parties. |
build-aux/install-sh became executable with contents [0170726bd8].
︙ | ︙ |
Modified build-aux/m4/buildsys.m4 from [b34d61e29f] to [9126f3bfa6].
︙ | ︙ | |||
31 32 33 34 35 36 37 38 39 40 41 42 43 44 | case "$host_os" in darwin*) AC_SUBST(BUILD_AND_HOST_ARE_DARWIN, yes) ;; esac ;; esac AC_CONFIG_COMMANDS_PRE([ AS_IF([test x"$GCC" = x"yes"], [AC_SUBST(DEP_CFLAGS, '-MD -MF $${out%.o}.dep')]) AS_IF([test x"$GXX" = x"yes"], [AC_SUBST(DEP_CXXFLAGS, '-MD -MF $${out%.o}.dep')]) AS_IF([test x"$GOBJC" = x"yes"], | > > > > > > > | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | case "$host_os" in darwin*) AC_SUBST(BUILD_AND_HOST_ARE_DARWIN, yes) ;; esac ;; esac AC_PROG_INSTALL case "$INSTALL" in ./build-aux/install-sh*) INSTALL="$PWD/$INSTALL" ;; esac AC_CONFIG_COMMANDS_PRE([ AS_IF([test x"$GCC" = x"yes"], [AC_SUBST(DEP_CFLAGS, '-MD -MF $${out%.o}.dep')]) AS_IF([test x"$GXX" = x"yes"], [AC_SUBST(DEP_CXXFLAGS, '-MD -MF $${out%.o}.dep')]) AS_IF([test x"$GOBJC" = x"yes"], |
︙ | ︙ | |||
189 190 191 192 193 194 195 | INSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i && cp -R $$i ${DESTDIR}${plugindir}/' UNINSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i' CLEAN_LIB='' ;; *-*-mingw* | *-*-cygwin*) AC_MSG_RESULT(MinGW / Cygwin) LIB_CFLAGS='' | | | | | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | INSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i && cp -R $$i ${DESTDIR}${plugindir}/' UNINSTALL_PLUGIN='&& rm -fr ${DESTDIR}${plugindir}/$$i' CLEAN_LIB='' ;; *-*-mingw* | *-*-cygwin*) AC_MSG_RESULT(MinGW / Cygwin) LIB_CFLAGS='' LIB_LDFLAGS='-shared -Wl,--export-all-symbols,--out-implib,lib$${out%${LIB_SUFFIX}}.a' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='' LIB_SUFFIX='${LIB_MAJOR}.dll' LDFLAGS_RPATH='-Wl,-rpath,${libdir}' PLUGIN_CFLAGS='' PLUGIN_LDFLAGS='-shared' PLUGIN_SUFFIX='.dll' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_LIB='&& ${MKDIR_P} ${DESTDIR}${bindir} && ${INSTALL} -m 755 $$i ${DESTDIR}${bindir}/$$i && ${INSTALL} -m 755 lib$${i%${LIB_SUFFIX}}.a ${DESTDIR}${libdir}/lib$${i%${LIB_SUFFIX}}.a' UNINSTALL_LIB='&& rm -f ${DESTDIR}${bindir}/$$i ${DESTDIR}${libdir}/lib$$i.a' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' CLEAN_LIB='${SHARED_LIB}.a ${SHARED_LIB_NOINST}.a' ;; *-*-openbsd* | *-*-mirbsd*) AC_MSG_RESULT(OpenBSD) |
︙ | ︙ | |||
276 277 278 279 280 281 282 283 284 285 286 287 288 289 | PLUGIN_SUFFIX='.sl' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i && ${LN_S} -f $$i ${DESTDIR}${libdir}/$${i%%.*}.sl' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%%.*}.sl' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' CLEAN_LIB='' ;; *) AC_MSG_RESULT(ELF) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' | > > > > > > > > > > > > > > > > > > > | 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | PLUGIN_SUFFIX='.sl' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i && ${LN_S} -f $$i ${DESTDIR}${libdir}/$${i%%.*}.sl' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%%.*}.sl' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' CLEAN_LIB='' ;; ia64*-*-hpux*) AC_MSG_RESULT([HP-UX (Itanium)]) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,+h,$$out' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' LIB_SUFFIX='.${LIB_MAJOR}' LINK_LIB='&& rm -f $${out%%.*}.so && ${LN_S} $$out $${out%%.*}.so' LDFLAGS_RPATH='-Wl,+b,${libdir}' PLUGIN_CFLAGS='-fPIC -DPIC' PLUGIN_LDFLAGS='-shared' PLUGIN_SUFFIX='.so' LINK_PLUGIN='${LD} -o $$out ${PLUGIN_OBJS} ${PLUGIN_OBJS_EXTRA} ${PLUGIN_LDFLAGS} ${LDFLAGS} ${LIBS}' INSTALL_LIB='&& ${INSTALL} -m 755 $$i ${DESTDIR}${libdir}/$$i && ${LN_S} -f $$i ${DESTDIR}${libdir}/$${i%%.*}.so' UNINSTALL_LIB='&& rm -f ${DESTDIR}${libdir}/$$i ${DESTDIR}${libdir}/$${i%%.*}.so' INSTALL_PLUGIN='&& ${INSTALL} -m 755 $$i ${DESTDIR}${plugindir}/$$i' UNINSTALL_PLUGIN='&& rm -f ${DESTDIR}${plugindir}/$$i' CLEAN_LIB='' ;; *) AC_MSG_RESULT(ELF) LIB_CFLAGS='-fPIC -DPIC' LIB_LDFLAGS='-shared -Wl,-soname=$$out.${LIB_MAJOR}' LIB_LDFLAGS_INSTALL_NAME='' LIB_PREFIX='lib' |
︙ | ︙ |
Modified buildsys.mk.in from [b068b3ae0b] to [a085f99653].
︙ | ︙ | |||
208 209 210 211 212 213 214 | ${MAKE} -s copy-headers-into-framework || exit $$?; \ cd .. || exit 1; \ done if test x"${includesubdir}" = x"${COPY_HEADERS_IF_SUBDIR}"; then \ for i in "" ${INCLUDES}; do \ test x"$$i" = x"" && continue; \ | | | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | ${MAKE} -s copy-headers-into-framework || exit $$?; \ cd .. || exit 1; \ done if test x"${includesubdir}" = x"${COPY_HEADERS_IF_SUBDIR}"; then \ for i in "" ${INCLUDES}; do \ test x"$$i" = x"" && continue; \ ${MKDIR_P} $$(dirname ${COPY_HEADERS_DESTINATION}/$$i) || exit $$?; \ ${INSTALL} -m 644 $$i ${COPY_HEADERS_DESTINATION}/$$i || exit $$?; \ done \ fi ${AMIGA_LIB} ${AMIGA_LIB_NOINST}: ${EXT_DEPS} ${AMIGA_LIB_OBJS_START} ${AMIGA_LIB_OBJS} ${AMIGA_LIB_OBJS_EXTRA} ${LINK_STATUS} if ${LD} -o $@ ${AMIGA_LIB_OBJS_START} ${AMIGA_LIB_OBJS} ${AMIGA_LIB_OBJS_EXTRA} ${AMIGA_LIB_LDFLAGS} ${AMIGA_LIB_LIBS}; then \ |
︙ | ︙ | |||
729 730 731 732 733 734 735 | fi \ done if test x"${INSTALL_INCLUDES}" = x"yes"; then \ for i in "" ${INCLUDES}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ | | | 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | fi \ done if test x"${INSTALL_INCLUDES}" = x"yes"; then \ for i in "" ${INCLUDES}; do \ test x"$$i" = x"" && continue; \ ${INSTALL_STATUS}; \ if ${MKDIR_P} $$(dirname ${DESTDIR}${includedir}/${includesubdir}/$$i) && ${INSTALL} -m 644 $$i ${DESTDIR}${includedir}/${includesubdir}/$$i; then \ ${INSTALL_OK}; \ else \ ${INSTALL_FAILED}; \ fi \ done \ fi |
︙ | ︙ |
Modified configure.ac from [6318576d5e] to [80769d4ef2].
︙ | ︙ | |||
45 46 47 48 49 50 51 | LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" supports_amiga_lib="yes" AS_IF([test x"$enable_amiga_lib" != x"no"], [ | | | > | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" supports_amiga_lib="yes" AS_IF([test x"$enable_amiga_lib" != x"no"], [ AC_SUBST(OBJFW_AMIGA_LIB, 'objfw${OBJFW_LIB_MAJOR}.library') AC_SUBST(OBJFWRT_AMIGA_LIB, ['objfwrt${OBJFWRT_LIB_MAJOR}.library']) dnl For 68000, GCC emits calls to helper functions that dnl do not work properly in a library. t="-mcpu=68020 -fbaserel32 -noixemul -ffreestanding" AC_SUBST(AMIGA_LIB_CFLAGS, $t) t="$t -resident32 -nostartfiles -nodefaultlibs -ldebug -lc" AC_SUBST(AMIGA_LIB_LDFLAGS, $t) ]) |
︙ | ︙ | |||
77 78 79 80 81 82 83 | LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" supports_amiga_lib="yes" AS_IF([test x"$enable_amiga_lib" != x"no"], [ | | > | > | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | LIBS="$LIBS -ldebug" enable_files="yes" # Required for reading ENV: enable_shared="no" supports_amiga_lib="yes" AS_IF([test x"$enable_amiga_lib" != x"no"], [ AC_SUBST(OBJFW_AMIGA_LIB, ['objfw${OBJFW_LIB_MAJOR}ppc.library']) AC_SUBST(OBJFWRT_AMIGA_LIB, ['objfwrt${OBJFWRT_LIB_MAJOR}ppc.library']) t="-mresident32 -ffreestanding -noixemul" AC_SUBST(AMIGA_LIB_CFLAGS, $t) t="-mresident32 -nostartfiles -nodefaultlibs -noixemul" t="$t -laboxstubs -labox -lmath -ldebug -lc" AC_SUBST(AMIGA_LIB_LDFLAGS, $t) ]) |
︙ | ︙ | |||
157 158 159 160 161 162 163 | *) potential_compilers="clang egcc gcc" ;; esac AC_PROG_OBJC($potential_compilers) AC_PROG_OBJCPP AC_PROG_LN_S | < | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | *) potential_compilers="clang egcc gcc" ;; esac AC_PROG_OBJC($potential_compilers) AC_PROG_OBJCPP AC_PROG_LN_S AC_PROG_EGREP BUILDSYS_CHECK_IOS AC_ARG_WITH(wii, AS_HELP_STRING([--with-wii], [build for Wii])) AS_IF([test x"$with_wii" = x"yes"], [ |
︙ | ︙ | |||
363 364 365 366 367 368 369 | AC_ARG_ENABLE(shared, AS_HELP_STRING([--disable-shared], [do not build shared library])) AS_IF([test x"$enable_shared" != x"no"], [ BUILDSYS_SHARED_LIB AC_SUBST(OBJFW_SHARED_LIB, "${LIB_PREFIX}objfw${LIB_SUFFIX}") AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a") AC_SUBST(FORWARDING_LIB_A, "forwarding.lib.a") | < | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | AC_ARG_ENABLE(shared, AS_HELP_STRING([--disable-shared], [do not build shared library])) AS_IF([test x"$enable_shared" != x"no"], [ BUILDSYS_SHARED_LIB AC_SUBST(OBJFW_SHARED_LIB, "${LIB_PREFIX}objfw${LIB_SUFFIX}") AC_SUBST(EXCEPTIONS_LIB_A, "exceptions.lib.a") AC_SUBST(FORWARDING_LIB_A, "forwarding.lib.a") AC_SUBST(LOOKUP_ASM_LIB_A, "lookup-asm.lib.a") BUILDSYS_FRAMEWORK([ AC_SUBST(OBJFW_FRAMEWORK, "ObjFW.framework") build_framework="yes" ]) |
︙ | ︙ | |||
396 397 398 399 400 401 402 | TESTS_LIBS="-F../src -F../src/runtime $TESTS_LIBS" ], [ TESTS_LIBS="\${OBJFW_LIBS} \${RUNTIME_LIBS} $TESTS_LIBS" TESTS_LIBS="-L../src/runtime -L../src/runtime/linklib $TESTS_LIBS" TESTS_LIBS="-L../src -L../src/linklib $TESTS_LIBS" ]) | < < < < < < < < < < < < < < < < < < < < | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | TESTS_LIBS="-F../src -F../src/runtime $TESTS_LIBS" ], [ TESTS_LIBS="\${OBJFW_LIBS} \${RUNTIME_LIBS} $TESTS_LIBS" TESTS_LIBS="-L../src/runtime -L../src/runtime/linklib $TESTS_LIBS" TESTS_LIBS="-L../src -L../src/linklib $TESTS_LIBS" ]) AC_ARG_ENABLE(static, AS_HELP_STRING([--enable-static], [build static library])) AS_IF([test x"$enable_shared" = x"no" -a x"$enable_amiga_lib" = x"no"], [ enable_static="yes" ]) AS_IF([test x"$enable_static" = x"yes"], [ AC_SUBST(OBJFW_STATIC_LIB, "libobjfw.a") AC_SUBST(EXCEPTIONS_A, "exceptions.a") AC_SUBST(FORWARDING_A, "forwarding.a") AC_SUBST(LOOKUP_ASM_A, "lookup-asm.a") ]) AS_IF([test x"$enable_amiga_lib" != x"no"], [ AC_SUBST(EXCEPTIONS_AMIGALIB_A, "exceptions.amigalib.a") AC_SUBST(FORWARDING_AMIGALIB_A, "forwarding.amigalib.a") AC_SUBST(LOOKUP_ASM_AMIGALIB_A, "lookup-asm.amigalib.a") ]) AC_DEFINE_UNQUOTED(PLUGIN_SUFFIX, "$PLUGIN_SUFFIX", [Suffix for plugins]) AS_IF([test x"$enable_files" != x"no" -a x"$PLUGIN_SUFFIX" != x""], [ AC_SUBST(USE_SRCS_PLUGINS, '${SRCS_PLUGINS}') AC_SUBST(TESTPLUGIN, "plugin") AC_DEFINE(OF_HAVE_PLUGINS, 1, [Whether we have plugin support]) |
︙ | ︙ | |||
640 641 642 643 644 645 646 | AC_MSG_RESULT($exception_type) ], [ AC_MSG_RESULT(exceptions unavailable!) AC_MSG_ERROR([Exceptions not accepted by compiler!]) ]) | | | 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | AC_MSG_RESULT($exception_type) ], [ AC_MSG_RESULT(exceptions unavailable!) AC_MSG_ERROR([Exceptions not accepted by compiler!]) ]) AC_SEARCH_LIBS($raise_exception, [c++abi gcc_s gcc unwind], [ dnl c++abi requires pthread on OpenBSD AS_IF([test x"$ac_lib" = x"c++abi"], [LIBS="$LIBS -lpthread"]) ], [ AC_MSG_ERROR([$raise_exception missing!]) ], [-lpthread]) AC_CHECK_FUNCS(_Unwind_GetDataRelBase _Unwind_GetTextRelBase) |
︙ | ︙ | |||
673 674 675 676 677 678 679 | AC_SUBST(RUNTIME_INSTANCE_M, "runtime/instance.m") ]) OBJCFLAGS="$old_OBJCFLAGS" ;; esac | > > > > > | > > | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | AC_SUBST(RUNTIME_INSTANCE_M, "runtime/instance.m") ]) OBJCFLAGS="$old_OBJCFLAGS" ;; esac case "$host_os" in hpux*) dnl _Unwind_Backtrace() returns complete garbage on HP-UX. ;; *) AC_CHECK_FUNCS(_Unwind_Backtrace) ;; esac case "$host_os" in darwin*) AC_SUBST(LDFLAGS_REEXPORT, ["-Wl,-reexport-lobjfw"]) AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_SUBST(REEXPORT_RUNTIME, ["-Wl,-reexport-lobjc"]) AC_SUBST(REEXPORT_RUNTIME_FRAMEWORK, ["-Wl,-reexport-lobjc"]) |
︙ | ︙ | |||
965 966 967 968 969 970 971 | dnl Use -Wp, as we only use it for the preprocessor. AX_CHECK_COMPILER_FLAGS([-Wp,-pthread], [ CPPFLAGS="$CPPFLAGS -Wp,-pthread" ], [ CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE" ]) | | | 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 | dnl Use -Wp, as we only use it for the preprocessor. AX_CHECK_COMPILER_FLAGS([-Wp,-pthread], [ CPPFLAGS="$CPPFLAGS -Wp,-pthread" ], [ CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_THREAD_SAFE" ]) AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread") AC_LINK_IFELSE([ AC_LANG_PROGRAM([ #include <pthread.h> ], [ pthread_create(NULL, NULL, NULL, NULL); ]) |
︙ | ︙ | |||
1368 1369 1370 1371 1372 1373 1374 | AC_DEFINE(OF_HAVE_NETINET_IN_H, 1, [Whether we have netinet/in.h]) ]) AC_CHECK_HEADER(netinet/tcp.h, [ AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1, [Whether we have netinet/tcp.h]) ]) | < < < < < < | 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 | AC_DEFINE(OF_HAVE_NETINET_IN_H, 1, [Whether we have netinet/in.h]) ]) AC_CHECK_HEADER(netinet/tcp.h, [ AC_DEFINE(OF_HAVE_NETINET_TCP_H, 1, [Whether we have netinet/tcp.h]) ]) AC_CHECK_HEADERS([arpa/inet.h netdb.h]) AC_CHECK_HEADER(netipx/ipx.h, [ AC_DEFINE(OF_HAVE_NETIPX_IPX_H, 1, [Whether we have netipx/ipx.h]) ]) AC_CHECK_MEMBER([struct sockaddr_in6.sin6_addr], [ |
︙ | ︙ | |||
1554 1555 1556 1557 1558 1559 1560 | AC_SUBST(OF_HTTP_CLIENT_TESTS_M, "OFHTTPClientTests.m") ]) AC_SUBST(OFDNS, "ofdns") AS_IF([test x"$enable_files" != x"no"], [ AC_SUBST(OFHTTP, "ofhttp") ]) | < | 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 | AC_SUBST(OF_HTTP_CLIENT_TESTS_M, "OFHTTPClientTests.m") ]) AC_SUBST(OFDNS, "ofdns") AS_IF([test x"$enable_files" != x"no"], [ AC_SUBST(OFHTTP, "ofhttp") ]) ]) AC_DEFUN([CHECK_BUILTIN_BSWAP], [ AC_MSG_CHECKING(for __builtin_bswap$1) AC_LINK_IFELSE([ AC_LANG_PROGRAM([ #include <stdint.h> |
︙ | ︙ | |||
1592 1593 1594 1595 1596 1597 1598 | #if (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \ (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR) egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) | | | | | | | | | | | 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 | #if (!defined(TARGET_OS_IPHONE) || !TARGET_OS_IPHONE) && \ (!defined(TARGET_OS_SIMULATOR) || !TARGET_OS_SIMULATOR) egrep_cpp_yes #endif ], [ AC_MSG_RESULT(yes) have_subprocesses="yes" ], [ AC_MSG_RESULT(no) have_subprocesses="no" ]) ;; mingw*) have_subprocesses="yes" ;; msdosdjgpp*) have_subprocesses="no" ;; *) AC_HEADER_SYS_WAIT AC_CHECK_FUNCS(kill) AC_CHECK_FUNCS(posix_spawnp, [ AS_IF([test x"$ac_cv_func_kill" = x"yes"], [ have_subprocesses="yes" AC_CHECK_HEADERS(spawn.h) ]) ], [ AC_CHECK_FUNCS([vfork dup2 execvp _exit], [ AS_IF([test x"$ac_cv_func_vfork" = x"yes" \ -a x"$ac_cv_func_pipe" = x"yes" \ -a x"$ac_cv_func_dup2" = x"yes" \ -a x"$ac_cv_func_execvp" = x"yes" \ -a x"$ac_cv_func_kill" = x"yes" \ -a x"$ac_cv_func__exit" = x"yes"], [ have_subprocesses="yes" ]) ], [ break ]) ]) ;; esac AS_IF([test x"$have_subprocesses" = x"yes"], [ AC_SUBST(OF_SUBPROCESS_M, "OFSubprocess.m") AC_DEFINE(OF_HAVE_SUBPROCESSES, 1, [Whether we have subprocesses]) ]) AC_CHECK_HEADERS_ONCE([complex.h sys/ioctl.h sys/ttycom.h]) AC_CHECK_FUNCS(isatty) AC_CHECK_FUNC(pledge, [ AC_DEFINE(OF_HAVE_PLEDGE, 1, [Whether we have pledge()]) |
︙ | ︙ |
Modified extra.mk.in from [11499a214c] to [58325ddf01].
1 2 3 4 | OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_FRAMEWORK = @OBJFW_FRAMEWORK@ OBJFW_AMIGA_LIB = @OBJFW_AMIGA_LIB@ | | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 | OBJFW_SHARED_LIB = @OBJFW_SHARED_LIB@ OBJFW_STATIC_LIB = @OBJFW_STATIC_LIB@ OBJFW_FRAMEWORK = @OBJFW_FRAMEWORK@ OBJFW_AMIGA_LIB = @OBJFW_AMIGA_LIB@ OBJFW_LIB_MAJOR = 1 OBJFW_LIB_MINOR = 0 OBJFW_LIB_MAJOR_MINOR = ${OBJFW_LIB_MAJOR}.${OBJFW_LIB_MINOR} OBJFWRT_SHARED_LIB = @OBJFWRT_SHARED_LIB@ OBJFWRT_STATIC_LIB = @OBJFWRT_STATIC_LIB@ OBJFWRT_FRAMEWORK = @OBJFWRT_FRAMEWORK@ OBJFWRT_AMIGA_LIB = @OBJFWRT_AMIGA_LIB@ OBJFWRT_LIB_MAJOR = 1 |
︙ | ︙ | |||
28 29 30 31 32 33 34 | EXCEPTIONS_A = @EXCEPTIONS_A@ EXCEPTIONS_AMIGALIB_A = @EXCEPTIONS_AMIGALIB_A@ EXCEPTIONS_LIB_A = @EXCEPTIONS_LIB_A@ FISH_COMPLETIONS = @FISH_COMPLETIONS@ FORWARDING_A = @FORWARDING_A@ FORWARDING_AMIGALIB_A = @FORWARDING_AMIGALIB_A@ FORWARDING_LIB_A = @FORWARDING_LIB_A@ | < < < < < < > | 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 61 62 63 | EXCEPTIONS_A = @EXCEPTIONS_A@ EXCEPTIONS_AMIGALIB_A = @EXCEPTIONS_AMIGALIB_A@ EXCEPTIONS_LIB_A = @EXCEPTIONS_LIB_A@ FISH_COMPLETIONS = @FISH_COMPLETIONS@ FORWARDING_A = @FORWARDING_A@ FORWARDING_AMIGALIB_A = @FORWARDING_AMIGALIB_A@ FORWARDING_LIB_A = @FORWARDING_LIB_A@ LIBBASES_M = @LIBBASES_M@ LIBOBJFWRT_DEP = @LIBOBJFWRT_DEP@ LIBOBJFWRT_DEP_LVL2 = @LIBOBJFWRT_DEP_LVL2@ LIBOBJFW_DEP = @LIBOBJFW_DEP@ LIBOBJFW_DEP_LVL2 = @LIBOBJFW_DEP_LVL2@ LINKLIB = @LINKLIB@ LOOKUP_ASM_A = @LOOKUP_ASM_A@ LOOKUP_ASM_AMIGALIB_A = @LOOKUP_ASM_AMIGALIB_A@ LOOKUP_ASM_LIB_A = @LOOKUP_ASM_LIB_A@ MAP_LDFLAGS = @MAP_LDFLAGS@ OBJFW_LIBS = @OBJFW_LIBS@ OFARC = @OFARC@ OFDNS = @OFDNS@ OFHASH = @OFHASH@ OFHTTP = @OFHTTP@ OF_BLOCK_TESTS_M = @OF_BLOCK_TESTS_M@ OF_EPOLL_KERNEL_EVENT_OBSERVER_M = @OF_EPOLL_KERNEL_EVENT_OBSERVER_M@ OF_HTTP_CLIENT_TESTS_M = @OF_HTTP_CLIENT_TESTS_M@ OF_KQUEUE_KERNEL_EVENT_OBSERVER_M = @OF_KQUEUE_KERNEL_EVENT_OBSERVER_M@ OF_POLL_KERNEL_EVENT_OBSERVER_M = @OF_POLL_KERNEL_EVENT_OBSERVER_M@ OF_SELECT_KERNEL_EVENT_OBSERVER_M = @OF_SELECT_KERNEL_EVENT_OBSERVER_M@ OF_SUBPROCESS_M = @OF_SUBPROCESS_M@ REEXPORT_RUNTIME = @REEXPORT_RUNTIME@ REEXPORT_RUNTIME_FRAMEWORK = @REEXPORT_RUNTIME_FRAMEWORK@ RUNTIME = @RUNTIME@ RUNTIME_ARC_TESTS_M = @RUNTIME_ARC_TESTS_M@ RUNTIME_AUTORELEASE_M = @RUNTIME_AUTORELEASE_M@ RUNTIME_FRAMEWORK_LIBS = @RUNTIME_FRAMEWORK_LIBS@ RUNTIME_INSTANCE_M = @RUNTIME_INSTANCE_M@ |
︙ | ︙ | |||
76 77 78 79 80 81 82 | TESTS_LIBS = @TESTS_LIBS@ TESTS_STATIC_LIB = @TESTS_STATIC_LIB@ UNICODE_M = @UNICODE_M@ USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@ USE_SRCS_FILES = @USE_SRCS_FILES@ USE_SRCS_IPX = @USE_SRCS_IPX@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ | < | 71 72 73 74 75 76 77 78 79 80 81 | TESTS_LIBS = @TESTS_LIBS@ TESTS_STATIC_LIB = @TESTS_STATIC_LIB@ UNICODE_M = @UNICODE_M@ USE_INCLUDES_ATOMIC = @USE_INCLUDES_ATOMIC@ USE_SRCS_FILES = @USE_SRCS_FILES@ USE_SRCS_IPX = @USE_SRCS_IPX@ USE_SRCS_PLUGINS = @USE_SRCS_PLUGINS@ USE_SRCS_SOCKETS = @USE_SRCS_SOCKETS@ USE_SRCS_THREADS = @USE_SRCS_THREADS@ USE_SRCS_WINDOWS = @USE_SRCS_WINDOWS@ WRAPPER = @WRAPPER@ |
Modified generators/library/LibraryGenerator.m from [4e7b018ec4] to [c412c8dbe7].
︙ | ︙ | |||
42 43 44 45 46 47 48 | OFURL *glueHeaderURL = [sourcesURL URLByAppendingPathComponent: @"amiga-glue.h"]; OFURL *glueURL = [sourcesURL URLByAppendingPathComponent: @"amiga-glue.m"]; OFURL *funcArrayURL = [sourcesURL URLByAppendingPathComponent: @"amiga-funcarray.inc"]; OFXMLElement *library = [OFXMLElement elementWithStream: | | < | < | < | < | < | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | OFURL *glueHeaderURL = [sourcesURL URLByAppendingPathComponent: @"amiga-glue.h"]; OFURL *glueURL = [sourcesURL URLByAppendingPathComponent: @"amiga-glue.m"]; OFURL *funcArrayURL = [sourcesURL URLByAppendingPathComponent: @"amiga-funcarray.inc"]; OFXMLElement *library = [OFXMLElement elementWithStream: [OFFile fileWithURL: libraryURL mode: @"r"]]; OFFile *linkLib = [OFFile fileWithURL: linkLibURL mode: @"w"]; OFFile *glueHeader = [OFFile fileWithURL: glueHeaderURL mode: @"w"]; OFFile *glue = [OFFile fileWithURL: glueURL mode: @"w"]; OFFile *funcArray = [OFFile fileWithURL: funcArrayURL mode: @"w"]; LinkLibGenerator *linkLibGenerator = [[[LinkLibGenerator alloc] initWithLibrary: library implementation: linkLib] autorelease]; GlueGenerator *glueGenerator = [[[GlueGenerator alloc] initWithLibrary: library header: glueHeader implementation: glue] autorelease]; |
︙ | ︙ |
Modified generators/library/Makefile from [7064d263a2] to [e4cd0b67be].
1 2 3 4 5 6 7 8 9 10 11 12 | include ../../extra.mk PROG_NOINST = gen_libraries${PROG_SUFFIX} SRCS = FuncArrayGenerator.m \ GlueGenerator.m \ LibraryGenerator.m \ LinkLibGenerator.m .PHONY: run run: all rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} | | > | | | > | | > | > | > | 1 2 3 4 5 6 7 8 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | include ../../extra.mk PROG_NOINST = gen_libraries${PROG_SUFFIX} SRCS = FuncArrayGenerator.m \ GlueGenerator.m \ LibraryGenerator.m \ LinkLibGenerator.m .PHONY: run run: all rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib rm -f ${OBJFWRT_AMIGA_LIB} if test -f ../../src/libobjfw.so; then \ ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../../src/libobjfw.dylib; then \ ${LN_S} ../../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/libobjfwrt.so; then \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/${OBJFWRT_AMIGA_LIB}; then \ ${LN_S} ../../src/runtime/${OBJFWRT_AMIGA_LIB} \ ${OBJFWRT_AMIGA_LIB}; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_FRAMEWORK_PATH=../../src:../../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ASAN_OPTIONS=allocator_may_return_null=1 \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT include ../../buildsys.mk CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} |
Modified generators/unicode/Makefile from [c6ebd60fbb] to [c50589aa66].
1 2 3 4 5 6 7 8 9 | include ../../extra.mk PROG_NOINST = gen_tables${PROG_SUFFIX} SRCS = TableGenerator.m .PHONY: run run: all rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} | | > | | | > | | > | > | > | 1 2 3 4 5 6 7 8 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | include ../../extra.mk PROG_NOINST = gen_tables${PROG_SUFFIX} SRCS = TableGenerator.m .PHONY: run run: all rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib rm -f ${OBJFWRT_AMIGA_LIB} if test -f ../../src/libobjfw.so; then \ ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../../src/libobjfw.dylib; then \ ${LN_S} ../../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/libobjfwrt.so; then \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/${OBJFWRT_AMIGA_LIB}; then \ ${LN_S} ../../src/runtime/${OBJFWRT_AMIGA_LIB} \ ${OBJFWRT_AMIGA_LIB}; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_FRAMEWORK_PATH=../../src:../../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ASAN_OPTIONS=allocator_may_return_null=1 \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT include ../../buildsys.mk CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} |
Modified generators/unicode/TableGenerator.h from [75d0d664b0] to [7eb32f5774].
︙ | ︙ | |||
18 19 20 21 22 23 24 | @class OFString; @interface TableGenerator: OFObject <OFApplicationDelegate, OFHTTPClientDelegate> { OFHTTPClient *_HTTPClient; | | | | | | | | | | 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 | @class OFString; @interface TableGenerator: OFObject <OFApplicationDelegate, OFHTTPClientDelegate> { OFHTTPClient *_HTTPClient; OFUnichar _uppercaseTable[0x110000]; OFUnichar _lowercaseTable[0x110000]; OFUnichar _titlecaseTable[0x110000]; OFUnichar _caseFoldingTable[0x110000]; OFString *_decompositionTable[0x110000]; OFString *_decompositionCompatTable[0x110000]; char _uppercaseTableUsed[0x1100]; char _lowercaseTableUsed[0x1100]; char _titlecaseTableUsed[0x1100]; char _caseFoldingTableUsed[0x1100]; char _decompositionTableUsed[0x1100]; char _decompositionCompatTableUsed[0x1100]; size_t _uppercaseTableSize; size_t _lowercaseTableSize; size_t _titlecaseTableSize; size_t _caseFoldingTableSize; size_t _decompositionTableSize; size_t _decompositionCompatTableSize; enum { stateUnicodeData, stateCaseFolding } _state; } - (void)parseUnicodeData: (OFHTTPResponse *)response; - (void)parseCaseFolding: (OFHTTPResponse *)response; - (void)applyDecompositionRecursivelyForTable: (OFString *[0x110000])table; - (void)writeFiles; |
︙ | ︙ |
Modified generators/unicode/TableGenerator.m from [4d33b76d8d] to [6b626ad955].
︙ | ︙ | |||
28 29 30 31 32 33 34 | #import "OFStdIOStream.h" #import "OFOutOfRangeException.h" #import "TableGenerator.h" #import "copyright.h" | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | #import "OFStdIOStream.h" #import "OFOutOfRangeException.h" #import "TableGenerator.h" #import "copyright.h" static OFString *const unicodeDataURL = @"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt"; static OFString *const caseFoldingURL = @"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt"; OF_APPLICATION_DELEGATE(TableGenerator) @implementation TableGenerator - (instancetype)init { self = [super init]; @try { _HTTPClient = [[OFHTTPClient alloc] init]; _HTTPClient.delegate = self; _uppercaseTableSize = SIZE_MAX; _lowercaseTableSize = SIZE_MAX; _titlecaseTableSize = SIZE_MAX; _caseFoldingTableSize = SIZE_MAX; _decompositionTableSize = SIZE_MAX; _decompositionCompatTableSize = SIZE_MAX; } @catch (id e) { @throw e; [self release]; } return self; } - (void)applicationDidFinishLaunching { OFHTTPRequest *request; [OFStdOut writeString: @"Downloading UnicodeData.txt…"]; _state = stateUnicodeData; request = [OFHTTPRequest requestWithURL: [OFURL URLWithString: unicodeDataURL]]; [_HTTPClient asyncPerformRequest: request]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception { if (exception != nil) @throw exception; [OFStdOut writeLine: @" done"]; switch (_state) { case stateUnicodeData: [self parseUnicodeData: response]; break; case stateCaseFolding: [self parseCaseFolding: response]; break; } } - (void)parseUnicodeData: (OFHTTPResponse *)response { OFString *line; OFHTTPRequest *request; [OFStdOut writeString: @"Parsing UnicodeData.txt…"]; while ((line = [response readLine]) != nil) { void *pool2; OFArray OF_GENERIC(OFString *) *components; OFUnichar codePoint; if (line.length == 0) continue; pool2 = objc_autoreleasePoolPush(); components = [line componentsSeparatedByString: @";"]; if (components.count != 15) { OFLog(@"Invalid line: %@\n", line); [OFApplication terminateWithStatus: 1]; } codePoint = (OFUnichar)[[components objectAtIndex: 0] unsignedLongLongValueWithBase: 16]; if (codePoint > 0x10FFFF) @throw [OFOutOfRangeException exception]; _uppercaseTable[codePoint] = (OFUnichar)[[components objectAtIndex: 12] unsignedLongLongValueWithBase: 16]; _lowercaseTable[codePoint] = (OFUnichar)[[components objectAtIndex: 13] unsignedLongLongValueWithBase: 16]; _titlecaseTable[codePoint] = (OFUnichar)[[components objectAtIndex: 14] unsignedLongLongValueWithBase: 16]; if ([[components objectAtIndex: 5] length] > 0) { OFArray *decomposed = [[components objectAtIndex: 5] componentsSeparatedByString: @" "]; bool compat = false; OFMutableString *string; if ([decomposed.firstObject hasPrefix: @"<"]) { decomposed = [decomposed objectsInRange: OFRangeMake(1, decomposed.count - 1)]; compat = true; } string = [OFMutableString string]; for (OFString *character in decomposed) { OFUnichar unichar = (OFUnichar)[character unsignedLongLongValueWithBase: 16]; [string appendCharacters: &unichar length: 1]; } [string makeImmutable]; if (!compat) _decompositionTable[codePoint] = [string copy]; _decompositionCompatTable[codePoint] = [string copy]; } objc_autoreleasePoolPop(pool2); } [self applyDecompositionRecursivelyForTable: _decompositionTable]; [self applyDecompositionRecursivelyForTable: _decompositionCompatTable]; [OFStdOut writeLine: @" done"]; [OFStdOut writeString: @"Downloading CaseFolding.txt…"]; _state = stateCaseFolding; request = [OFHTTPRequest requestWithURL: [OFURL URLWithString: caseFoldingURL]]; [_HTTPClient asyncPerformRequest: request]; } - (void)parseCaseFolding: (OFHTTPResponse *)response { OFString *line; [OFStdOut writeString: @"Parsing CaseFolding.txt…"]; while ((line = [response readLine]) != nil) { void *pool2; OFArray OF_GENERIC(OFString *) *components; OFUnichar codePoint; if (line.length == 0 || [line hasPrefix: @"#"]) continue; pool2 = objc_autoreleasePoolPush(); components = [line componentsSeparatedByString: @"; "]; if (components.count != 4) { OFLog(@"Invalid line: %s\n", line); [OFApplication terminateWithStatus: 1]; } if (![[components objectAtIndex: 1] isEqual: @"S"] && ![[components objectAtIndex: 1] isEqual: @"C"]) continue; codePoint = (OFUnichar)[[components objectAtIndex: 0] unsignedLongLongValueWithBase: 16]; if (codePoint > 0x10FFFF) @throw [OFOutOfRangeException exception]; _caseFoldingTable[codePoint] = (OFUnichar)[[components objectAtIndex: 2] unsignedLongLongValueWithBase: 16]; objc_autoreleasePoolPop(pool2); } [OFStdOut writeLine: @" done"]; [self writeFiles]; } - (void)applyDecompositionRecursivelyForTable: (OFString *[0x110000])table { bool done; do { done = true; for (OFUnichar i = 0; i < 0x110000; i++) { void *pool; const OFUnichar *characters; size_t length; OFMutableString *replacement; bool changed = false; if (table[i] == nil) continue; |
︙ | ︙ | |||
268 269 270 271 272 273 274 | } while (!done); } - (void)writeFiles { OFURL *URL; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 | } while (!done); } - (void)writeFiles { OFURL *URL; [OFStdOut writeString: @"Writing files…"]; URL = [OFURL fileURLWithPath: @"../../src/unicode.m"]; [self writeTablesToFile: URL.fileSystemRepresentation]; URL = [OFURL fileURLWithPath: @"../../src/unicode.h"]; [self writeHeaderToFile: URL.fileSystemRepresentation]; [OFStdOut writeLine: @" done"]; [OFApplication terminate]; } - (void)writeTablesToFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: COPYRIGHT @"#include \"config.h\"\n" @"\n" @"#import \"OFString.h\"\n\n" @"static const OFUnichar emptyPage[0x100] = { 0 };\n" @"static const char *emptyDecompositionPage[0x100] = { NULL };\n" @"\n"]; /* Write uppercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_uppercaseTable[j] != 0) { isEmpty = false; _uppercaseTableSize = i >> 8; _uppercaseTableUsed[_uppercaseTableSize] = 1; break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"uppercasePage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _uppercaseTable[j], _uppercaseTable[j + 1], _uppercaseTable[j + 2], _uppercaseTable[j + 3], _uppercaseTable[j + 4], _uppercaseTable[j + 5], _uppercaseTable[j + 6], _uppercaseTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write lowercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_lowercaseTable[j] != 0) { isEmpty = false; _lowercaseTableSize = i >> 8; _lowercaseTableUsed[_lowercaseTableSize] = 1; break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"lowercasePage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _lowercaseTable[j], _lowercaseTable[j + 1], _lowercaseTable[j + 2], _lowercaseTable[j + 3], _lowercaseTable[j + 4], _lowercaseTable[j + 5], _lowercaseTable[j + 6], _lowercaseTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write titlecasePage%u if it does NOT match uppercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_titlecaseTable[j] != 0) { isEmpty = !memcmp(_uppercaseTable + i, _titlecaseTable + i, 256 * sizeof(OFUnichar)); _titlecaseTableSize = i >> 8; _titlecaseTableUsed[_titlecaseTableSize] = (isEmpty ? 2 : 1); break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"titlecasePage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _titlecaseTable[j], _titlecaseTable[j + 1], _titlecaseTable[j + 2], _titlecaseTable[j + 3], _titlecaseTable[j + 4], _titlecaseTable[j + 5], _titlecaseTable[j + 6], _titlecaseTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write caseFoldingPage%u if it does NOT match lowercasePage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_caseFoldingTable[j] != 0) { isEmpty = !memcmp(_lowercaseTable + i, _caseFoldingTable + i, 256 * sizeof(OFUnichar)); _caseFoldingTableSize = i >> 8; _caseFoldingTableUsed[_caseFoldingTableSize] = (isEmpty ? 2 : 1); break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const OFUnichar " @"caseFoldingPage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j += 8) [file writeFormat: @"\t%u, %u, %u, %u, %u, %u, %u, %u,\n", _caseFoldingTable[j], _caseFoldingTable[j + 1], _caseFoldingTable[j + 2], _caseFoldingTable[j + 3], _caseFoldingTable[j + 4], _caseFoldingTable[j + 5], _caseFoldingTable[j + 6], _caseFoldingTable[j + 7]]; [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write decompositionPage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_decompositionTable[j] != nil) { isEmpty = false; _decompositionTableSize = i >> 8; _decompositionTableUsed[ _decompositionTableSize] = 1; break; } } if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const char *const " @"decompositionPage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j++) { if ((j - i) % 2 == 0) [file writeString: @"\t"]; else [file writeString: @" "]; if (_decompositionTable[j] != nil) { const char *UTF8String = |
︙ | ︙ | |||
508 509 510 511 512 513 514 | [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write decompCompatPage%u if it does NOT match decompositionPage%u */ | | | | 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | [file writeString: @"};\n\n"]; objc_autoreleasePoolPop(pool2); } } /* Write decompCompatPage%u if it does NOT match decompositionPage%u */ for (OFUnichar i = 0; i < 0x110000; i += 0x100) { bool isEmpty = true; for (OFUnichar j = i; j < i + 0x100; j++) { if (_decompositionCompatTable[j] != 0) { /* * We bulk-compare pointers via memcmp here. * This is safe, as we always set the same * pointer in both tables if both are the same. */ isEmpty = !memcmp(_decompositionTable + i, |
︙ | ︙ | |||
537 538 539 540 541 542 543 | if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const char *const " @"decompCompatPage%u[0x100] = {\n", i >> 8]; | | | 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | if (!isEmpty) { void *pool2 = objc_autoreleasePoolPush(); [file writeFormat: @"static const char *const " @"decompCompatPage%u[0x100] = {\n", i >> 8]; for (OFUnichar j = i; j < i + 0x100; j++) { if ((j - i) % 2 == 0) [file writeString: @"\t"]; else [file writeString: @" "]; if (_decompositionCompatTable[j] != nil) { const char *UTF8String = |
︙ | ︙ | |||
579 580 581 582 583 584 585 | /* * Those are currently set to the last index. * But from now on, we need the size. */ _uppercaseTableSize++; _lowercaseTableSize++; _titlecaseTableSize++; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | /* * Those are currently set to the last index. * But from now on, we need the size. */ _uppercaseTableSize++; _lowercaseTableSize++; _titlecaseTableSize++; _caseFoldingTableSize++; _decompositionTableSize++; _decompositionCompatTableSize++; /* Write OFUnicodeUppercaseTable */ [file writeFormat: @"const OFUnichar *const " @"OFUnicodeUppercaseTable[0x%X] = {\n\t", _uppercaseTableSize]; for (OFUnichar i = 0; i < _uppercaseTableSize; i++) { if (_uppercaseTableUsed[i]) [file writeFormat: @"uppercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _uppercaseTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write OFUnicodeLowercaseTable */ [file writeFormat: @"const OFUnichar *const " @"OFUnicodeLowercaseTable[0x%X] = {\n\t", _lowercaseTableSize]; for (OFUnichar i = 0; i < _lowercaseTableSize; i++) { if (_lowercaseTableUsed[i]) [file writeFormat: @"lowercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _lowercaseTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write OFUnicodeTitlecaseTable */ [file writeFormat: @"const OFUnichar *const " @"OFUnicodeTitlecaseTable[0x%X] = {\n\t", _titlecaseTableSize]; for (OFUnichar i = 0; i < _titlecaseTableSize; i++) { if (_titlecaseTableUsed[i] == 1) [file writeFormat: @"titlecasePage%u", i]; else if (_titlecaseTableUsed[i] == 2) [file writeFormat: @"uppercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _titlecaseTableSize) { if ((i + 1) % 4 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write OFUnicodeCaseFoldingTable */ [file writeFormat: @"const OFUnichar *const " @"OFUnicodeCaseFoldingTable[0x%X] = {\n\t", _caseFoldingTableSize]; for (OFUnichar i = 0; i < _caseFoldingTableSize; i++) { if (_caseFoldingTableUsed[i] == 1) [file writeFormat: @"caseFoldingPage%u", i]; else if (_caseFoldingTableUsed[i] == 2) [file writeFormat: @"lowercasePage%u", i]; else [file writeString: @"emptyPage"]; if (i + 1 < _caseFoldingTableSize) { if ((i + 1) % 3 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write OFUnicodeDecompositionTable */ [file writeFormat: @"const char *const " @"*OFUnicodeDecompositionTable[0x%X] = {\n\t", _decompositionTableSize]; for (OFUnichar i = 0; i < _decompositionTableSize; i++) { if (_decompositionTableUsed[i]) [file writeFormat: @"decompositionPage%u", i]; else [file writeString: @"emptyDecompositionPage"]; if (i + 1 < _decompositionTableSize) { if ((i + 1) % 3 == 0) [file writeString: @",\n\t"]; else [file writeString: @", "]; } } [file writeString: @"\n};\n\n"]; /* Write OFUnicodeDecompositionCompatTable */ [file writeFormat: @"const char *const " @"*OFUnicodeDecompositionCompatTable[0x%X] = {" @"\n\t", _decompositionCompatTableSize]; for (OFUnichar i = 0; i < _decompositionCompatTableSize; i++) { if (_decompositionCompatTableUsed[i] == 1) [file writeFormat: @"decompCompatPage%u", i]; else if (_decompositionCompatTableUsed[i] == 2) [file writeFormat: @"decompositionPage%u", i]; else [file writeString: @"emptyDecompositionPage"]; |
︙ | ︙ | |||
729 730 731 732 733 734 735 | OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: COPYRIGHT @"#import \"OFString.h\"\n\n"]; [file writeFormat: | | | | | | | | | | < | | < | | < | | < | | | < > | 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 | OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: COPYRIGHT @"#import \"OFString.h\"\n\n"]; [file writeFormat: @"#define OFUnicodeUppercaseTableSize 0x%X\n" @"#define OFUnicodeLowercaseTableSize 0x%X\n" @"#define OFUnicodeTitlecaseTableSize 0x%X\n" @"#define OFUnicodeCaseFoldingTableSize 0x%X\n" @"#define OFUnicodeDecompositionTableSize 0x%X\n" @"#define OFUnicodeDecompositionCompatTableSize 0x%X\n\n", _uppercaseTableSize, _lowercaseTableSize, _titlecaseTableSize, _caseFoldingTableSize, _decompositionTableSize, _decompositionCompatTableSize]; [file writeString: @"#ifdef __cplusplus\n" @"extern \"C\" {\n" @"#endif\n" @"extern const OFUnichar *const _Nonnull\n" @" OFUnicodeUppercaseTable[OFUnicodeUppercaseTableSize];\n" @"extern const OFUnichar *const _Nonnull\n" @" OFUnicodeLowercaseTable[OFUnicodeLowercaseTableSize];\n" @"extern const OFUnichar *const _Nonnull\n" @" OFUnicodeTitlecaseTable[OFUnicodeTitlecaseTableSize];\n" @"extern const OFUnichar *const _Nonnull\n" @" OFUnicodeCaseFoldingTable[OFUnicodeCaseFoldingTableSize];\n" @"extern const char *const _Nullable *const _Nonnull\n" @" OFUnicodeDecompositionTable[" @"OFUnicodeDecompositionTableSize];\n" @"extern const char *const _Nullable *const _Nonnull\n" @" OFUnicodeDecompositionCompatTable[" @"OFUnicodeDecompositionCompatTableSize];\n" @"#ifdef __cplusplus\n" @"}\n" @"#endif\n"]; objc_autoreleasePoolPop(pool); } @end |
Modified src/Makefile from [adbca9f8d2] to [364ab65b22].
1 2 | include ../extra.mk | | | < < < < < < < < < < > > > < | > < > > > < < < < < > > > > > > | > | < < < < < < < < < < < > < | < < < | | | > | > | | < | | | | < | < < < > > | | > | < | < < | 1 2 3 4 5 6 7 8 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | include ../extra.mk SUBDIRS = ${RUNTIME} exceptions encodings forwarding SUBDIRS_AFTER = ${LINKLIB} ${BRIDGE} CLEAN = amiga-end.amigalib.dep \ amiga-end.amigalib.o \ amiga-glue.amigalib.dep \ amiga-glue.amigalib.o \ amiga-library-functable.inc \ amiga-library.amigalib.dep \ amiga-library.amigalib.o \ inline.h DISTCLEAN = Info.plist objfw-defs.h SHARED_LIB = ${OBJFW_SHARED_LIB} STATIC_LIB = ${OBJFW_STATIC_LIB} FRAMEWORK = ${OBJFW_FRAMEWORK} AMIGA_LIB = ${OBJFW_AMIGA_LIB} LIB_MAJOR = ${OBJFW_LIB_MAJOR} LIB_MINOR = ${OBJFW_LIB_MINOR} SRCS = OFASPrintF.m \ OFApplication.m \ OFArray.m \ OFBase64.m \ OFBlock.m \ OFCRC16.m \ OFCRC32.m \ OFCharacterSet.m \ OFColor.m \ OFConstantString.m \ OFCountedSet.m \ OFData.m \ OFData+CryptographicHashing.m \ OFData+MessagePackParsing.m \ OFDate.m \ OFDictionary.m \ OFEnumerator.m \ OFFileManager.m \ OFGZIPStream.m \ OFHMAC.m \ OFHuffmanTree.m \ OFInflate64Stream.m \ OFInflateStream.m \ OFInvocation.m \ OFLHAArchive.m \ OFLHAArchiveEntry.m \ OFList.m \ OFLocale.m \ OFMD5Hash.m \ OFMapTable.m \ OFMessagePackExtension.m \ OFMethodSignature.m \ OFMutableArray.m \ OFMutableData.m \ OFMutableDictionary.m \ OFMutableLHAArchiveEntry.m \ OFMutablePair.m \ OFMutableSet.m \ OFMutableString.m \ OFMutableTarArchiveEntry.m \ OFMutableTriple.m \ OFMutableURL.m \ OFMutableZIPArchiveEntry.m \ OFNull.m \ OFNumber.m \ OFObject.m \ OFObject+KeyValueCoding.m \ OFObject+Serialization.m \ OFOnce.m \ OFOptionsParser.m \ OFPBKDF2.m \ OFPair.m \ OFRIPEMD160Hash.m \ OFRunLoop.m \ OFSHA1Hash.m \ OFSHA224Hash.m \ OFSHA224Or256Hash.m \ OFSHA256Hash.m \ OFSHA384Hash.m \ OFSHA384Or512Hash.m \ OFSHA512Hash.m \ OFScrypt.m \ OFSecureData.m \ OFSeekableStream.m \ OFSerialization.m \ OFSet.m \ OFSortedList.m \ OFStdIOStream.m \ OFStrPTime.m \ OFStream.m \ OFString.m \ OFString+CryptographicHashing.m \ OFString+JSONParsing.m \ OFString+PropertyListParsing.m \ OFString+Serialization.m \ OFString+URLEncoding.m \ OFString+XMLEscaping.m \ OFString+XMLUnescaping.m \ ${OF_SUBUPROCESS_M} \ OFSystemInfo.m \ OFTarArchive.m \ OFTarArchiveEntry.m \ OFThread.m \ OFTimer.m \ OFTriple.m \ OFURL.m \ OFURLHandler.m \ OFValue.m \ OFXMLAttribute.m \ OFXMLCDATA.m \ OFXMLCharacters.m \ OFXMLComment.m \ OFXMLElement.m \ OFXMLElement+Serialization.m \ OFXMLElementBuilder.m \ OFXMLNode.m \ OFXMLParser.m \ OFXMLProcessingInstruction.m \ OFZIPArchive.m \ OFZIPArchiveEntry.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFFile.m \ OFINICategory.m \ OFINIFile.m \ OFSettings.m \ OFString+PathAdditions.m SRCS_IPX = OFIPXSocket.m \ OFSPXSocket.m \ OFSPXStreamSocket.m SRCS_PLUGINS = OFPlugin.m SRCS_SOCKETS = OFDNSQuery.m \ OFDNSResolver.m \ OFDNSResourceRecord.m \ OFDNSResponse.m \ OFDatagramSocket.m \ OFHTTPClient.m \ OFHTTPCookie.m \ OFHTTPCookieManager.m \ OFHTTPRequest.m \ OFHTTPResponse.m \ OFHTTPServer.m \ OFSequencedPacketSocket.m \ OFSocket.m \ OFStreamSocket.m \ OFTCPSocket.m \ OFUDPSocket.m \ ${USE_SRCS_IPX} SRCS_THREADS = OFCondition.m \ OFMutex.m \ OFPlainCondition.m \ OFPlainMutex.m \ OFPlainThread.m \ OFRecursiveMutex.m \ OFTLSKey.m \ OFThreadPool.m SRCS_WINDOWS = OFWin32ConsoleStdIOStream.m \ OFWindowsRegistryKey.m INCLUDES_ATOMIC = OFAtomic.h \ platform/GCC4/OFAtomic.h \ platform/GCC4.7/OFAtomic.h \ platform/PowerPC/OFAtomic.h \ platform/macOS/OFAtomic.h \ platform/x86/OFAtomic.h INCLUDES := ${SRCS:.m=.h} \ OFCollection.h \ OFCryptographicHash.h \ OFJSONRepresentation.h \ OFKernelEventObserver.h \ OFKeyValueCoding.h \ OFLocking.h \ OFMessagePackRepresentation.h \ OFTLSSocket.h \ ObjFW.h \ macros.h \ objfw-defs.h \ platform.h \ ${USE_INCLUDES_ATOMIC} SRCS += OFAdjacentArray.m \ OFAdjacentSubarray.m \ OFBitSetCharacterSet.m \ OFBytesValue.m \ OFCountedMapTableSet.m \ OFInvertedCharacterSet.m \ OFLHADecompressingStream.m \ OFMapTableDictionary.m \ OFMapTableSet.m \ OFMutableAdjacentArray.m \ OFMutableMapTableDictionary.m \ OFMutableMapTableSet.m \ OFMutableUTF8String.m \ OFNonretainedObjectValue.m \ OFPointValue.m \ OFPointerValue.m \ OFRangeCharacterSet.m \ OFRangeValue.m \ OFRectValue.m \ OFSandbox.m \ OFSizeValue.m \ OFSubarray.m \ OFUTF8String.m \ ${LIBBASES_M} \ ${RUNTIME_AUTORELEASE_M} \ ${RUNTIME_INSTANCE_M} \ ${UNICODE_M} SRCS_FILES += OFFileURLHandler.m \ OFINIFileSettings.m SRCS_SOCKETS += OFDNSResolverSettings.m \ OFHTTPURLHandler.m \ OFHostAddressResolver.m \ OFIPSocketAsyncConnector.m \ OFKernelEventObserver.m \ ${OF_EPOLL_KERNEL_EVENT_OBSERVER_M} \ ${OF_KQUEUE_KERNEL_EVENT_OBSERVER_M} \ ${OF_POLL_KERNEL_EVENT_OBSERVER_M} \ ${OF_SELECT_KERNEL_EVENT_OBSERVER_M} \ OFTCPSocketSOCKS5Connector.m OBJS_EXTRA = exceptions/exceptions.a \ encodings/encodings.a \ forwarding/forwarding.a LIB_OBJS_EXTRA = exceptions/exceptions.lib.a \ encodings/encodings.lib.a \ forwarding/forwarding.lib.a AMIGA_LIB_OBJS_START = amiga-library.amigalib.o AMIGA_LIB_OBJS_EXTRA = amiga-glue.amigalib.o \ exceptions/exceptions.amigalib.a \ encodings/encodings.amigalib.a \ forwarding/forwarding.amigalib.a \ amiga-end.amigalib.o include ../buildsys.mk CPPFLAGS += -I. -I.. -Iexceptions -Iruntime \ -DOBJFW_AMIGA_LIB=\"${OBJFW_AMIGA_LIB}\" \ -DOBJFW_LIB_MAJOR=${OBJFW_LIB_MAJOR} \ |
︙ | ︙ |
Deleted src/OFASN1BitString.h version [c2be33e12e].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1BitString.m version [323c648f9c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Boolean.h version [4ac9986bdd].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Boolean.m version [1a29ed76f3].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1DERRepresentation.h version [fea4984136].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Enumerated.h version [5d2a579693].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Enumerated.m version [eb1e77637a].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1IA5String.h version [c74a3606bd].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1IA5String.m version [494960fd54].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Integer.h version [06cbc99c2c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Integer.m version [5a16302993].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1NumericString.h version [e0198cfd1a].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1NumericString.m version [50fd063fbe].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1ObjectIdentifier.h version [e688ca72a5].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1ObjectIdentifier.m version [4d9e8570e7].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1OctetString.h version [547dec0827].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1OctetString.m version [42b0c8635d].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1PrintableString.h version [0506eb78c3].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1PrintableString.m version [d6f8fd877c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1UTF8String.h version [338855ca89].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1UTF8String.m version [92cd83c978].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Value.h version [6ceb7a1c4f].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFASN1Value.m version [200bca2819].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Renamed and modified src/of_asprintf.h [2f5af44b9a] to src/OFASPrintF.h [ca2e45c02b].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif | | < < | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int OFVASPrintF( char *_Nullable *_Nonnull, const char *_Nonnull, va_list); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Renamed and modified src/of_asprintf.m [f0147f7049] to src/OFASPrintF.m [55b5185ec7].
︙ | ︙ | |||
37 38 39 40 41 42 43 | #endif #import "OFString.h" #import "OFLocale.h" #import "OFInitializationFailedException.h" | | | | | | | | | | | | | | | | | | > | | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | #endif #import "OFString.h" #import "OFLocale.h" #import "OFInitializationFailedException.h" #define maxSubformatLen 64 #ifndef HAVE_ASPRINTF /* * (v)asprintf might be declared, but HAVE_ASPRINTF not defined because * configure determined it is broken. In this case, we must make sure there is * no name clash. */ # define asprintf asprintf_ # define vasprintf vasprintf_ #endif struct Context { const char *format; size_t formatLen; char subformat[maxSubformatLen + 1]; size_t subformatLen; va_list arguments; char *buffer; size_t bufferLen; size_t i, last; enum { stateString, stateFormatFlags, stateFormatFieldWidth, stateFormatLengthModifier, stateFormatConversionSpecifier } state; enum { lengthModifierNone, lengthModifierHH, lengthModifierH, lengthModifierL, lengthModifierLL, lengthModifierJ, lengthModifierZ, lengthModifierT, lengthModifierCapitalL } lengthModifier; bool useLocale; }; #ifdef HAVE_ASPRINTF_L static locale_t cLocale; OF_CONSTRUCTOR() { if ((cLocale = newlocale(LC_ALL_MASK, "C", NULL)) == NULL) @throw [OFInitializationFailedException exception]; } #endif #ifndef HAVE_ASPRINTF static int vasprintf(char **string, const char *format, va_list arguments) { int length; size_t bufferLength = 128; *string = NULL; for (;;) { free(*string); if ((*string = malloc(bufferLength)) == NULL) return -1; length = vsnprintf(*string, bufferLength - 1, format, arguments); if (length >= 0 && (size_t)length < bufferLength - 1) break; if (bufferLength > INT_MAX / 2) { free(*string); return -1; } bufferLength <<= 1; } if (length > 0 && (size_t)length != bufferLength - 1) { char *resized = realloc(*string, length + 1); /* Ignore if making it smaller failed. */ if (resized != NULL) *string = resized; } |
︙ | ︙ | |||
143 144 145 146 147 148 149 | va_end(arguments); return ret; } #endif static bool | | | | | | | | | | | | | | | | | | | | | | | | | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | va_end(arguments); return ret; } #endif static bool appendString(struct Context *ctx, const char *append, size_t appendLen) { char *newBuf; if (appendLen == 0) return true; if ((newBuf = realloc(ctx->buffer, ctx->bufferLen + appendLen + 1)) == NULL) return false; memcpy(newBuf + ctx->bufferLen, append, appendLen); ctx->buffer = newBuf; ctx->bufferLen += appendLen; return true; } static bool appendSubformat(struct Context *ctx, const char *subformat, size_t subformatLen) { if (ctx->subformatLen + subformatLen > maxSubformatLen) return false; memcpy(ctx->subformat + ctx->subformatLen, subformat, subformatLen); ctx->subformatLen += subformatLen; ctx->subformat[ctx->subformatLen] = 0; return true; } static bool stringState(struct Context *ctx) { if (ctx->format[ctx->i] == '%') { if (ctx->i > 0) if (!appendString(ctx, ctx->format + ctx->last, ctx->i - ctx->last)) return false; if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->last = ctx->i + 1; ctx->state = stateFormatFlags; } return true; } static bool formatFlagsState(struct Context *ctx) { switch (ctx->format[ctx->i]) { case '-': case '+': case ' ': case '#': case '0': if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; break; case ',': /* ObjFW extension: Use decimal point from locale */ ctx->useLocale = true; break; default: ctx->state = stateFormatFieldWidth; ctx->i--; break; } return true; } static bool formatFieldWidthState(struct Context *ctx) { if ((ctx->format[ctx->i] >= '0' && ctx->format[ctx->i] <= '9') || ctx->format[ctx->i] == '*' || ctx->format[ctx->i] == '.') { if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; } else { ctx->state = stateFormatLengthModifier; ctx->i--; } return true; } static bool formatLengthModifierState(struct Context *ctx) { /* Only one allowed */ switch (ctx->format[ctx->i]) { case 'h': /* and also hh */ if (ctx->formatLen > ctx->i + 1 && ctx->format[ctx->i + 1] == 'h') { if (!appendSubformat(ctx, ctx->format + ctx->i, 2)) return false; ctx->i++; ctx->lengthModifier = lengthModifierHH; } else { if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierH; } break; case 'l': /* and also ll */ if (ctx->formatLen > ctx->i + 1 && ctx->format[ctx->i + 1] == 'l') { #ifndef OF_WINDOWS if (!appendSubformat(ctx, ctx->format + ctx->i, 2)) return false; #else if (!appendSubformat(ctx, "I64", 3)) return false; #endif ctx->i++; ctx->lengthModifier = lengthModifierLL; } else { if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierL; } break; case 'j': #if defined(OF_WINDOWS) if (!appendSubformat(ctx, "I64", 3)) return false; #elif defined(_NEWLIB_VERSION) || defined(OF_HPUX) if (!appendSubformat(ctx, "ll", 2)) return false; #else if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; #endif ctx->lengthModifier = lengthModifierJ; break; case 'z': #if defined(OF_WINDOWS) if (sizeof(size_t) == 8) if (!appendSubformat(ctx, "I64", 3)) return false; #elif defined(_NEWLIB_VERSION) || defined(OF_HPUX) if (!appendSubformat(ctx, "l", 1)) return false; #else if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; #endif ctx->lengthModifier = lengthModifierZ; break; case 't': #if defined(OF_WINDOWS) if (sizeof(ptrdiff_t) == 8) if (!appendSubformat(ctx, "I64", 3)) return false; #elif defined(_NEWLIB_VERSION) || defined(OF_HPUX) if (!appendSubformat(ctx, "l", 1)) return false; #else if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; #endif ctx->lengthModifier = lengthModifierT; break; case 'L': if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierCapitalL; break; #ifdef OF_WINDOWS case 'I': /* win32 strangeness (I64 instead of ll or j) */ if (ctx->formatLen > ctx->i + 2 && ctx->format[ctx->i + 1] == '6' && ctx->format[ctx->i + 2] == '4') { if (!appendSubformat(ctx, ctx->format + ctx->i, 3)) return false; ctx->i += 2; ctx->lengthModifier = lengthModifierLL; } else ctx->i--; break; #endif #ifdef OF_IOS case 'q': /* iOS uses this for PRI?64 */ if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; ctx->lengthModifier = lengthModifierLL; break; #endif default: ctx->i--; break; } ctx->state = stateFormatConversionSpecifier; return true; } static bool formatConversionSpecifierState(struct Context *ctx) { char *tmp = NULL; int tmpLen = 0; #ifndef HAVE_ASPRINTF_L OFString *point; #endif if (!appendSubformat(ctx, ctx->format + ctx->i, 1)) return false; switch (ctx->format[ctx->i]) { case '@': if (ctx->lengthModifier != lengthModifierNone) return false; ctx->subformat[ctx->subformatLen - 1] = 's'; @try { id object; |
︙ | ︙ | |||
406 407 408 409 410 411 412 | } @catch (id e) { free(ctx->buffer); @throw e; } break; case 'C': | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | } @catch (id e) { free(ctx->buffer); @throw e; } break; case 'C': if (ctx->lengthModifier != lengthModifierNone) return false; ctx->subformat[ctx->subformatLen - 1] = 's'; { char buffer[5]; size_t len = OFUTF8StringEncode( va_arg(ctx->arguments, OFUnichar), buffer); if (len == 0) return false; buffer[len] = 0; tmpLen = asprintf(&tmp, ctx->subformat, buffer); } break; case 'S': if (ctx->lengthModifier != lengthModifierNone) return false; ctx->subformat[ctx->subformatLen - 1] = 's'; { const OFUnichar *arg = va_arg(ctx->arguments, const OFUnichar *); size_t j, len = OFUTF32StringLength(arg); char *buffer; if (SIZE_MAX / 4 < len || (SIZE_MAX / 4) - len < 1) return false; if ((buffer = malloc((len * 4) + 1)) == NULL) return false; j = 0; for (size_t i = 0; i < len; i++) { size_t clen = OFUTF8StringEncode(arg[i], buffer + j); if (clen == 0) { free(buffer); return false; } j += clen; } buffer[j] = 0; tmpLen = asprintf(&tmp, ctx->subformat, buffer); free(buffer); } break; case 'd': case 'i': switch (ctx->lengthModifier) { case lengthModifierNone: case lengthModifierHH: case lengthModifierH: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); break; case lengthModifierL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long)); break; case lengthModifierLL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, long long)); break; case lengthModifierJ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, intmax_t)); break; case lengthModifierZ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ssize_t)); break; case lengthModifierT: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } break; case 'o': case 'u': case 'x': case 'X': switch (ctx->lengthModifier) { case lengthModifierNone: case lengthModifierHH: case lengthModifierH: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned int)); break; case lengthModifierL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned long)); break; case lengthModifierLL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, unsigned long long)); break; case lengthModifierJ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, uintmax_t)); break; case lengthModifierZ: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, size_t)); break; case lengthModifierT: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, ptrdiff_t)); break; default: return false; } break; case 'f': case 'F': case 'e': case 'E': case 'g': case 'G': case 'a': case 'A': switch (ctx->lengthModifier) { case lengthModifierNone: case lengthModifierL: #ifdef HAVE_ASPRINTF_L if (!ctx->useLocale) tmpLen = asprintf_l(&tmp, cLocale, ctx->subformat, va_arg(ctx->arguments, double)); else #endif tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, double)); break; case lengthModifierCapitalL: #ifdef HAVE_ASPRINTF_L if (!ctx->useLocale) tmpLen = asprintf_l(&tmp, cLocale, ctx->subformat, va_arg(ctx->arguments, long double)); else #endif |
︙ | ︙ | |||
608 609 610 611 612 613 614 | tmp = tmp2; } #endif break; case 'c': switch (ctx->lengthModifier) { | | | | | | | | | | | | | | | | 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | tmp = tmp2; } #endif break; case 'c': switch (ctx->lengthModifier) { case lengthModifierNone: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); break; case lengthModifierL: #ifdef HAVE_WCHAR_H # if WINT_MAX >= INT_MAX tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, wint_t)); # else tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, int)); # endif break; #endif default: return false; } break; case 's': switch (ctx->lengthModifier) { case lengthModifierNone: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, const char *)); break; #ifdef HAVE_WCHAR_T case lengthModifierL: tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, const wchar_t *)); break; #endif default: return false; } break; case 'p': if (ctx->lengthModifier != lengthModifierNone) return false; tmpLen = asprintf(&tmp, ctx->subformat, va_arg(ctx->arguments, void *)); break; case 'n': switch (ctx->lengthModifier) { case lengthModifierNone: *va_arg(ctx->arguments, int *) = (int)ctx->bufferLen; break; case lengthModifierHH: *va_arg(ctx->arguments, signed char *) = (signed char)ctx->bufferLen; break; case lengthModifierH: *va_arg(ctx->arguments, short *) = (short)ctx->bufferLen; break; case lengthModifierL: *va_arg(ctx->arguments, long *) = (long)ctx->bufferLen; break; case lengthModifierLL: *va_arg(ctx->arguments, long long *) = (long long)ctx->bufferLen; break; case lengthModifierJ: *va_arg(ctx->arguments, intmax_t *) = (intmax_t)ctx->bufferLen; break; case lengthModifierZ: *va_arg(ctx->arguments, size_t *) = (size_t)ctx->bufferLen; break; case lengthModifierT: *va_arg(ctx->arguments, ptrdiff_t *) = (ptrdiff_t)ctx->bufferLen; break; default: return false; } break; case '%': if (ctx->lengthModifier != lengthModifierNone) return false; if (!appendString(ctx, "%", 1)) return false; break; default: |
︙ | ︙ | |||
715 716 717 718 719 720 721 | free(tmp); return false; } free(tmp); } | | | | | | | | | | | < < < < < < < < < < < < < | 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | free(tmp); return false; } free(tmp); } memset(ctx->subformat, 0, maxSubformatLen); ctx->subformatLen = 0; ctx->lengthModifier = lengthModifierNone; ctx->useLocale = false; ctx->last = ctx->i + 1; ctx->state = stateString; return true; } static bool (*states[])(struct Context *) = { stringState, formatFlagsState, formatFieldWidthState, formatLengthModifierState, formatConversionSpecifierState }; int OFVASPrintF(char **string, const char *format, va_list arguments) { struct Context ctx; ctx.format = format; ctx.formatLen = strlen(format); memset(ctx.subformat, 0, maxSubformatLen + 1); ctx.subformatLen = 0; va_copy(ctx.arguments, arguments); ctx.bufferLen = 0; ctx.last = 0; ctx.state = stateString; ctx.lengthModifier = lengthModifierNone; ctx.useLocale = false; if ((ctx.buffer = malloc(1)) == NULL) return -1; for (ctx.i = 0; ctx.i < ctx.formatLen; ctx.i++) { if (!states[ctx.state](&ctx)) { free(ctx.buffer); return -1; } } if (ctx.state != stateString) { free(ctx.buffer); return -1; } if (!appendString(&ctx, ctx.format + ctx.last, ctx.formatLen - ctx.last)) { free(ctx.buffer); return -1; } ctx.buffer[ctx.bufferLen] = 0; *string = ctx.buffer; return (ctx.bufferLen <= INT_MAX ? (int)ctx.bufferLen : -1); } |
Modified src/OFAdjacentArray.m from [a432edffec] to [82d92d7ef3].
︙ | ︙ | |||
57 58 59 60 61 62 63 | [self release]; @throw e; } return self; } | | < | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { self = [self init]; @try { id object; [_array addItem: &firstObject]; |
︙ | ︙ | |||
105 106 107 108 109 110 111 | @throw e; } @try { for (size_t i = 0; i < count; i++) [objects[i] retain]; | | < | < | < | | | 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | @throw e; } @try { for (size_t i = 0; i < count; i++) [objects[i] retain]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; /* Prevent double-release of objects */ [_array release]; _array = nil; [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [self init]; @try { bool ok = true; for (size_t i = 0; i < count; i++) { if (objects[i] == nil) ok = false; [objects[i] retain]; } if (!ok) @throw [OFInvalidArgumentException exception]; [_array addItems: objects count: count]; } @catch (id e) { for (size_t i = 0; i < count; i++) [objects[i] release]; [self release]; @throw e; } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if ((![element.name isEqual: @"OFArray"] && ![element.name isEqual: @"OFMutableArray"]) || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *child in [element elementsForNamespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); id object; object = child.objectByDeserializing; [_array addItem: &object]; [object retain]; |
︙ | ︙ | |||
206 207 208 209 210 211 212 | } - (id)objectAtIndexedSubscript: (size_t)idx { return *((id *)[_array itemAtIndex: idx]); } | | < | | | | | | < | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | } - (id)objectAtIndexedSubscript: (size_t)idx { return *((id *)[_array itemAtIndex: idx]); } - (void)getObjects: (id *)buffer inRange: (OFRange)range { id const *objects = _array.items; size_t count = _array.count; if (range.length > SIZE_MAX - range.location || range.location + range.length > count) @throw [OFOutOfRangeException exception]; for (size_t i = 0; i < range.length; i++) buffer[i] = objects[range.location + i]; } - (size_t)indexOfObject: (id)object { id const *objects; size_t count; if (object == nil) return OFNotFound; objects = _array.items; count = _array.count; for (size_t i = 0; i < count; i++) if ([objects[i] isEqual: object]) return i; return OFNotFound; } - (size_t)indexOfObjectIdenticalTo: (id)object { id const *objects; size_t count; if (object == nil) return OFNotFound; objects = _array.items; count = _array.count; for (size_t i = 0; i < count; i++) if (objects[i] == object) return i; return OFNotFound; } - (OFArray *)objectsInRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _array.count) @throw [OFOutOfRangeException exception]; if ([self isKindOfClass: [OFMutableArray class]]) return [OFArray arrayWithObjects: (id *)_array.items + range.location count: range.length]; return [OFAdjacentSubarray arrayWithArray: self range: range]; } - (bool)isEqual: (id)object { OFArray *otherArray; id const *objects, *otherObjects; size_t count; |
︙ | ︙ | |||
306 307 308 309 310 311 312 | return true; } - (unsigned long)hash { id const *objects = _array.items; size_t count = _array.count; | | | | | | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | return true; } - (unsigned long)hash { id const *objects = _array.items; size_t count = _array.count; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < count; i++) OFHashAddHash(&hash, [objects[i] hash]); OFHashFinalize(&hash); return hash; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count_ { size_t count = _array.count; if (count > INT_MAX) /* |
︙ | ︙ | |||
344 345 346 347 348 349 350 | state->itemsPtr = (id *)_array.items; state->mutationsPtr = (unsigned long *)self; return (int)count; } #ifdef OF_HAVE_BLOCKS | | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | state->itemsPtr = (id *)_array.items; state->mutationsPtr = (unsigned long *)self; return (int)count; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = _array.items; size_t count = _array.count; bool stop = false; for (size_t i = 0; i < count && !stop; i++) block(objects[i], i, &stop); |
︙ | ︙ |
Modified src/OFAdjacentSubarray.m from [738b4fad30] to [188174c31a].
︙ | ︙ | |||
49 50 51 52 53 54 55 | if (![objects[i] isEqual: otherObjects[i]]) return false; return true; } #ifdef OF_HAVE_BLOCKS | | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | if (![objects[i] isEqual: otherObjects[i]]) return false; return true; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = self.objects; bool stop = false; for (size_t i = 0; i < _range.length && !stop; i++) block(objects[i], i, &stop); } |
︙ | ︙ |
Modified src/OFApplication.h from [05d5c2e935] to [5f5127d646].
︙ | ︙ | |||
48 49 50 51 52 53 54 | * - (void)applicationDidFinishLaunching * { * [OFApplication terminate]; * } * @end * @endcode */ | | | | | | | | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | * - (void)applicationDidFinishLaunching * { * [OFApplication terminate]; * } * @end * @endcode */ #define OF_APPLICATION_DELEGATE(class_) \ int \ main(int argc, char *argv[]) \ { \ return OFApplicationMain(&argc, &argv, \ (class_ *)[[class_ alloc] init]); \ } #ifdef OF_HAVE_PLEDGE # define OF_HAVE_SANDBOX #endif /** |
︙ | ︙ | |||
196 197 198 199 200 201 202 | /** * @brief The delegate of the application. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFApplicationDelegate> delegate; #ifdef OF_HAVE_SANDBOX | < < < < < < < | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | /** * @brief The delegate of the application. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) id <OFApplicationDelegate> delegate; #ifdef OF_HAVE_SANDBOX @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFSandbox *activeSandbox; @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFSandbox *activeSandboxForChildProcesses; #endif /** * @brief Returns the only OFApplication instance in the application. * |
︙ | ︙ | |||
249 250 251 252 253 254 255 | * @brief Terminates the application with the specified status. * * @param status The status with which the application will terminate */ + (void)terminateWithStatus: (int)status OF_NO_RETURN; #ifdef OF_HAVE_SANDBOX | < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | * @brief Terminates the application with the specified status. * * @param status The status with which the application will terminate */ + (void)terminateWithStatus: (int)status OF_NO_RETURN; #ifdef OF_HAVE_SANDBOX + (void)of_activateSandbox: (OFSandbox *)sandbox; + (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Gets argc and argv. * |
︙ | ︙ | |||
306 307 308 309 310 311 312 | * @brief Terminates the application with the specified status. * * @param status The status with which the application will terminate */ - (void)terminateWithStatus: (int)status OF_NO_RETURN; #ifdef OF_HAVE_SANDBOX | < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < | | | | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | * @brief Terminates the application with the specified status. * * @param status The status with which the application will terminate */ - (void)terminateWithStatus: (int)status OF_NO_RETURN; #ifdef OF_HAVE_SANDBOX - (void)of_activateSandbox: (OFSandbox *)sandbox; - (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox; #endif @end #ifdef __cplusplus extern "C" { #endif extern int OFApplicationMain(int *_Nonnull, char *_Nullable *_Nonnull[_Nonnull], id <OFApplicationDelegate>); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFApplication.m from [8bb94e9bd1] to [9af79ccbcf].
︙ | ︙ | |||
69 70 71 72 73 74 75 | # include <nds.h> # undef asm #endif OF_DIRECT_MEMBERS @interface OFApplication () - (instancetype)of_init OF_METHOD_FAMILY(init); | | < | < | < | | < | < | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | # include <nds.h> # undef asm #endif OF_DIRECT_MEMBERS @interface OFApplication () - (instancetype)of_init OF_METHOD_FAMILY(init); - (void)of_setArgumentCount: (int *)argc andArgumentValues: (char **[])argv; #ifdef OF_WINDOWS - (void)of_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t *[])argv; #endif - (void)of_run; @end static OFApplication *app = nil; static void atexitHandler(void) { id <OFApplicationDelegate> delegate = app.delegate; if ([delegate respondsToSelector: @selector(applicationWillTerminate)]) [delegate applicationWillTerminate]; [delegate release]; #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_SOCKETS) && \ defined(OF_AMIGAOS) && !defined(OF_MORPHOS) OFSocketDeinit(); #endif } int OFApplicationMain(int *argc, char **argv[], id <OFApplicationDelegate> delegate) { #ifdef OF_WINDOWS wchar_t **wargv, **wenvp; int wargc, si = 0; #endif [[OFLocale alloc] init]; app = [[OFApplication alloc] of_init]; #ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) { __wgetmainargs(&wargc, &wargv, &wenvp, _CRT_glob, &si); [app of_setArgumentCount: wargc andWideArgumentValues: wargv]; } else #endif [app of_setArgumentCount: argc andArgumentValues: argv]; app.delegate = delegate; [app of_run]; [delegate release]; |
︙ | ︙ | |||
196 197 198 199 200 201 202 | sceKernelExitGame(); OF_UNREACHABLE #endif } #ifdef OF_HAVE_SANDBOX | | | | | | | | < | < | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | sceKernelExitGame(); OF_UNREACHABLE #endif } #ifdef OF_HAVE_SANDBOX + (void)of_activateSandbox: (OFSandbox *)sandbox { [app of_activateSandbox: sandbox]; } + (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox { [app of_activateSandboxForChildProcesses: sandbox]; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_init { self = [super init]; @try { _environment = [[OFMutableDictionary alloc] init]; atexit(atexitHandler); #if defined(OF_WINDOWS) if ([OFSystemInfo isWindowsNT]) { OFChar16 *env, *env0; env = env0 = GetEnvironmentStringsW(); while (*env != 0) { void *pool = objc_autoreleasePoolPush(); OFString *tmp, *key, *value; size_t length, pos; length = OFUTF16StringLength(env); tmp = [OFString stringWithUTF16String: env length: length]; env += length + 1; /* * cmd.exe seems to add some special variables * which start with a "=", even though variable * names are not allowed to contain a "=". */ if ([tmp hasPrefix: @"="]) { objc_autoreleasePoolPop(pool); continue; } pos = [tmp rangeOfString: @"="].location; if (pos == OFNotFound) { fprintf(stderr, "Warning: Invalid environment " "variable: %s\n", tmp.UTF8String); continue; } key = [tmp substringToIndex: pos]; value = [tmp substringFromIndex: pos + 1]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } FreeEnvironmentStringsW(env0); } else { char *env, *env0; |
︙ | ︙ | |||
291 292 293 294 295 296 297 | */ if ([tmp hasPrefix: @"="]) { objc_autoreleasePoolPop(pool); continue; } pos = [tmp rangeOfString: @"="].location; | | < | < | | < | < | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | */ if ([tmp hasPrefix: @"="]) { objc_autoreleasePoolPop(pool); continue; } pos = [tmp rangeOfString: @"="].location; if (pos == OFNotFound) { fprintf(stderr, "Warning: Invalid environment " "variable: %s\n", tmp.UTF8String); continue; } key = [tmp substringToIndex: pos]; value = [tmp substringFromIndex: pos + 1]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } FreeEnvironmentStringsA(env0); } #elif defined(OF_AMIGAOS) void *pool = objc_autoreleasePoolPush(); OFFileManager *fileManager = [OFFileManager defaultManager]; OFArray *envContents = [fileManager contentsOfDirectoryAtPath: @"ENV:"]; OFStringEncoding encoding = [OFLocale encoding]; struct Process *proc; struct LocalVar *firstLocalVar; for (OFString *name in envContents) { void *pool2 = objc_autoreleasePoolPush(); OFString *path, *value; OFFile *file; if ([name containsString: @"."]) continue; path = [@"ENV:" stringByAppendingString: name]; if ([fileManager directoryExistsAtPath: path]) continue; file = [OFFile fileWithPath: path mode: @"r"]; value = [file readLineWithEncoding: encoding]; if (value != nil) [_environment setObject: value forKey: name]; objc_autoreleasePoolPop(pool2); } /* Local variables override global variables */ proc = (struct Process *)FindTask(NULL); firstLocalVar = (struct LocalVar *)proc->pr_LocalVars.mlh_Head; |
︙ | ︙ | |||
370 371 372 373 374 375 376 | key = [OFString stringWithCString: iter->lv_Node.ln_Name encoding: encoding]; value = [OFString stringWithCString: (const char *)iter->lv_Value encoding: encoding length: length]; | < | < < | < | < | < | < | < | < | < | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | key = [OFString stringWithCString: iter->lv_Node.ln_Name encoding: encoding]; value = [OFString stringWithCString: (const char *)iter->lv_Value encoding: encoding length: length]; [_environment setObject: value forKey: key]; } objc_autoreleasePoolPop(pool); #elif !defined(OF_IOS) # ifndef OF_MACOS char **env = environ; # else char **env = *_NSGetEnviron(); # endif if (env != NULL) { OFStringEncoding encoding = [OFLocale encoding]; for (; *env != NULL; env++) { void *pool = objc_autoreleasePoolPush(); OFString *key, *value; char *sep; if ((sep = strchr(*env, '=')) == NULL) { fprintf(stderr, "Warning: Invalid " "environment variable: %s\n", *env); continue; } key = [OFString stringWithCString: *env encoding: encoding length: sep - *env]; value = [OFString stringWithCString: sep + 1 encoding: encoding]; [_environment setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } } #else /* * iOS does not provide environ and Apple does not allow using * _NSGetEnviron on iOS. Therefore, we just get a few common * variables from the environment which applications might * expect. */ void *pool = objc_autoreleasePoolPush(); char *env; if ((env = getenv("HOME")) != NULL) { OFString *home = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: home forKey: @"HOME"]; } if ((env = getenv("PATH")) != NULL) { OFString *path = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: path forKey: @"PATH"]; } if ((env = getenv("SHELL")) != NULL) { OFString *shell = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: shell forKey: @"SHELL"]; } if ((env = getenv("TMPDIR")) != NULL) { OFString *tmpdir = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: tmpdir forKey: @"TMPDIR"]; } if ((env = getenv("USER")) != NULL) { OFString *user = [[[OFString alloc] initWithUTF8StringNoCopy: env freeWhenDone: false] autorelease]; [_environment setObject: user forKey: @"USER"]; } objc_autoreleasePoolPop(pool); #endif [_environment makeImmutable]; } @catch (id e) { |
︙ | ︙ | |||
479 480 481 482 483 484 485 | { [_arguments release]; [_environment release]; [super dealloc]; } | | < | | 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | { [_arguments release]; [_environment release]; [super dealloc]; } - (void)of_setArgumentCount: (int *)argc andArgumentValues: (char ***)argv { void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; OFStringEncoding encoding; _argc = argc; _argv = argv; encoding = [OFLocale encoding]; #ifndef OF_NINTENDO_DS |
︙ | ︙ | |||
513 514 515 516 517 518 519 | [arguments makeImmutable]; } objc_autoreleasePoolPop(pool); } #ifdef OF_WINDOWS | | < | < | 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | [arguments makeImmutable]; } objc_autoreleasePoolPop(pool); } #ifdef OF_WINDOWS - (void)of_setArgumentCount: (int)argc andWideArgumentValues: (wchar_t **)argv { void *pool = objc_autoreleasePoolPush(); OFMutableArray *arguments; if (argc > 0) { _programName = [[OFString alloc] initWithUTF16String: argv[0]]; arguments = [[OFMutableArray alloc] init]; for (int i = 1; i < argc; i++) [arguments addObject: [OFString stringWithUTF16String: argv[i]]]; [arguments makeImmutable]; _arguments = arguments; } objc_autoreleasePoolPop(pool); } #endif - (void)getArgumentCount: (int **)argc andArgumentValues: (char ****)argv { *argc = _argc; *argv = _argv; } - (id <OFApplicationDelegate>)delegate { |
︙ | ︙ | |||
621 622 623 624 625 626 627 | { [self.class terminateWithStatus: status]; OF_UNREACHABLE } #ifdef OF_HAVE_SANDBOX | | | | | | 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 | { [self.class terminateWithStatus: status]; OF_UNREACHABLE } #ifdef OF_HAVE_SANDBOX - (void)of_activateSandbox: (OFSandbox *)sandbox { # ifdef OF_HAVE_PLEDGE void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding = [OFLocale encoding]; OFArray OF_GENERIC(OFSandboxUnveilPath) *unveiledPaths; size_t unveiledPathsCount; const char *promises; if (_activeSandbox != nil && sandbox != _activeSandbox) @throw [OFInvalidArgumentException exception]; unveiledPaths = sandbox.unveiledPaths; unveiledPathsCount = unveiledPaths.count; for (size_t i = sandbox->_unveiledPathsIndex; i < unveiledPathsCount; i++) { OFSandboxUnveilPath unveiledPath = [unveiledPaths objectAtIndex: i]; OFString *path = unveiledPath.firstObject; OFString *permissions = unveiledPath.secondObject; if (path == nil || permissions == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
666 667 668 669 670 671 672 | objc_autoreleasePoolPop(pool); if (_activeSandbox == nil) _activeSandbox = [sandbox retain]; # endif } | | | 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | objc_autoreleasePoolPop(pool); if (_activeSandbox == nil) _activeSandbox = [sandbox retain]; # endif } - (void)of_activateSandboxForChildProcesses: (OFSandbox *)sandbox { # ifdef OF_HAVE_PLEDGE void *pool = objc_autoreleasePoolPush(); const char *promises; if (_activeSandboxForChildProcesses != nil && sandbox != _activeSandboxForChildProcesses) |
︙ | ︙ |
Modified src/OFArray.h from [a47af03a06] to [0789a761b0].
︙ | ︙ | |||
31 32 33 34 35 36 37 | OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFString; | > > > > > | > | > | < > > > > > > > > > | < | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFString; /** * @brief Options for joining the objects of an array. * * This is a bit mask. */ typedef enum { /** Skip empty components */ OFArraySkipEmptyComponents = 1 } OFArrayJoinOptions; /** * @brief Options for sorting an array. * * This is a bit mask. */ typedef enum { /** Sort the array descending */ OFArraySortDescending = 1 } OFArraySortOptions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFArray. * * @param object The current object * @param index The index of the current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFArrayEnumerationBlock)(id object, size_t index, bool *stop); /** * @brief A block for filtering an OFArray. * * @param object The object to inspect * @param index The index of the object to inspect * @return Whether the object should be in the filtered array */ typedef bool (^OFArrayFilterBlock)(id object, size_t index); /** * @brief A block for mapping objects to objects in an OFArray. * * @param object The object to map * @param index The index of the object to map * @return The object to map to */ typedef id _Nonnull (^OFArrayMapBlock)(id object, size_t index); /** * @brief A block for folding an OFArray. * * @param left The object to which the object has been folded so far * @param right The object that should be added to the left object * @return The left and right side folded into one object */ typedef id _Nullable (^OFArrayFoldBlock)(id _Nullable left, id right); #endif /** * @class OFArray OFArray.h ObjFW/OFArray.h * * @brief An abstract class for storing objects in an array. * |
︙ | ︙ | |||
213 214 215 216 217 218 219 220 221 222 223 224 225 226 | * @param objects A C array of objects * @param count The length of the C array * @return An initialized OFArray */ - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects count: (size_t)count; /** * @brief Returns the object at the specified index in the array. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @param index The index of the object to return | > > > > > > > | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | * @param objects A C array of objects * @param count The length of the C array * @return An initialized OFArray */ - (instancetype)initWithObjects: (ObjectType const _Nonnull *_Nonnull)objects count: (size_t)count; /** * @brief Returns an OFEnumerator to enumerate through all objects of the array. * * @return An OFEnumerator to enumerate through all objects of the array */ - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator; /** * @brief Returns the object at the specified index in the array. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! * * @param index The index of the object to return |
︙ | ︙ | |||
250 251 252 253 254 255 256 | * @ref setValue:forKey: is called for each object in the array. * * @note A @ref OFNull value is translated to nil! * * @param value The value for the specified key * @param key The key of the value to set */ | | < | | | | | | 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | * @ref setValue:forKey: is called for each object in the array. * * @note A @ref OFNull value is translated to nil! * * @param value The value for the specified key * @param key The key of the value to set */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Copies the objects at the specified range to the specified buffer. * * @param buffer The buffer to copy the objects to * @param range The range to copy */ - (void)getObjects: (ObjectType __unsafe_unretained _Nonnull *_Nonnull)buffer inRange: (OFRange)range; /** * @brief Returns the index of the first object that is equivalent to the * specified object or `OFNotFound` if it was not found. * * @param object The object whose index is returned * @return The index of the first object equivalent to the specified object * or `OFNotFound` if it was not found */ - (size_t)indexOfObject: (ObjectType)object; /** * @brief Returns the index of the first object that has the same address as the * specified object or `OFNotFound` if it was not found. * * @param object The object whose index is returned * @return The index of the first object that has the same address as * the specified object or `OFNotFound` if it was not found */ - (size_t)indexOfObjectIdenticalTo: (ObjectType)object; /** * @brief Checks whether the array contains an object equal to the specified * object. * |
︙ | ︙ | |||
307 308 309 310 311 312 313 | /** * @brief Returns the objects in the specified range as a new OFArray. * * @param range The range for the subarray * @return The subarray as a new autoreleased OFArray */ | | | < < < < | | < < < < | | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | /** * @brief Returns the objects in the specified range as a new OFArray. * * @param range The range for the subarray * @return The subarray as a new autoreleased OFArray */ - (OFArray OF_GENERIC(ObjectType) *)objectsInRange: (OFRange)range; /** * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator; /** * @brief Creates a string by joining all objects of the array. * * @param separator The string with which the objects should be joined * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator options: (OFArrayJoinOptions)options; /** * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * * @param separator The string with which the objects should be joined * @param selector The selector to perform on the objects * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector; /** * @brief Creates a string by calling the selector on all objects of the array * and joining the strings returned by calling the selector. * * @param separator The string with which the objects should be joined * @param selector The selector to perform on the objects * @param options Options according to which the objects should be joined * @return A string containing all objects joined by the separator */ - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector options: (OFArrayJoinOptions)options; /** * @brief Performs the specified selector on all objects in the array. * * @param selector The selector to perform on all objects in the array */ - (void)makeObjectsPerformSelector: (SEL)selector; |
︙ | ︙ | |||
383 384 385 386 387 388 389 | /** * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. | | < < < < | > | | < < < < | | | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | /** * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. * @param options The options to use when sorting the array * @return A sorted copy of the array */ - (OFArray OF_GENERIC(ObjectType) *) sortedArrayUsingSelector: (SEL)selector options: (OFArraySortOptions)options; #ifdef OF_HAVE_BLOCKS /** * @brief Returns a copy of the array sorted using the specified selector and * options. * * @param comparator The comparator to use to sort the array * @param options The options to use when sorting the array * @return A sorted copy of the array */ - (OFArray OF_GENERIC(ObjectType) *) sortedArrayUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options; #endif /** * @brief Creates a new array with the specified object added. * * @param object The object to add * @return A new array with the specified object added |
︙ | ︙ | |||
442 443 444 445 446 447 448 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object. * * @param block The block to execute for each object */ | | | | | | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object. * * @param block The block to execute for each object */ - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block; /** * @brief Creates a new array, mapping each object using the specified block. * * @param block A block which maps an object for each object * @return A new, autoreleased OFArray */ - (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block; /** * @brief Creates a new array, only containing the objects for which the block * returns true. * * @param block A block which determines if the object should be in the new * array * @return A new, autoreleased OFArray */ - (OFArray OF_GENERIC(ObjectType) *)filteredArrayUsingBlock: (OFArrayFilterBlock)block; /** * @brief Folds the array to a single object using the specified block. * * If the array is empty, it will return `nil`. * * If there is only one object in the array, that object will be returned and * the block will not be invoked. * * If there are at least two objects, the block is invoked for each object * except the first, where left is always to what the array has already been * folded and right what should be added to left. * * @param block A block which folds two objects into one, which is called for * all objects except the first * @return The array folded to a single object */ - (nullable id)foldUsingBlock: (OFArrayFoldBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END |
︙ | ︙ |
Modified src/OFArray.m from [1f1150d009] to [37c945555f].
︙ | ︙ | |||
34 35 36 37 38 39 40 | #import "OFOutOfRangeException.h" static struct { Class isa; } placeholder; @interface OFArray () | | > | | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #import "OFOutOfRangeException.h" static struct { Class isa; } placeholder; @interface OFArray () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFPlaceholderArray: OFArray @end @implementation OFPlaceholderArray - (instancetype)init |
︙ | ︙ | |||
191 192 193 194 195 196 197 | - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); | | < | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [self initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments |
︙ | ︙ | |||
225 226 227 228 229 230 231 | } - (size_t)count { OF_UNRECOGNIZED_SELECTOR } | | < | | < | | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | } - (size_t)count { OF_UNRECOGNIZED_SELECTOR } - (void)getObjects: (id *)buffer inRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) buffer[i] = [self objectAtIndex: range.location + i]; } - (id const *)objects { size_t count = self.count; id *buffer = OFAllocMemory(count, sizeof(id)); @try { [self getObjects: buffer inRange: OFRangeMake(0, count)]; return [[OFData dataWithItemsNoCopy: buffer count: count itemSize: sizeof(id) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } } - (id)copy { return [self retain]; |
︙ | ︙ | |||
294 295 296 297 298 299 300 | } [ret makeImmutable]; return ret; } | | < | < | | | | | | | | < | | < | < | | | | | | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | } [ret makeImmutable]; return ret; } - (void)setValue: (id)value forKey: (OFString *)key { for (id object in self) [object setValue: value forKey: key]; } - (size_t)indexOfObject: (id)object { size_t i = 0; if (object == nil) return OFNotFound; for (id objectIter in self) { if ([objectIter isEqual: object]) return i; i++; } return OFNotFound; } - (size_t)indexOfObjectIdenticalTo: (id)object { size_t i = 0; if (object == nil) return OFNotFound; for (id objectIter in self) { if (objectIter == object) return i; i++; } return OFNotFound; } - (bool)containsObject: (id)object { return ([self indexOfObject: object] != OFNotFound); } - (bool)containsObjectIdenticalTo: (id)object { return ([self indexOfObjectIdenticalTo: object] != OFNotFound); } - (id)firstObject { if (self.count > 0) return [self objectAtIndex: 0]; return nil; } - (id)lastObject { size_t count = self.count; if (count > 0) return [self objectAtIndex: count - 1]; return nil; } - (OFArray *)objectsInRange: (OFRange)range { OFArray *ret; id *buffer; if (range.length > SIZE_MAX - range.location || range.location + range.length < self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) return [OFSubarray arrayWithArray: self range: range]; buffer = OFAllocMemory(range.length, sizeof(*buffer)); @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer count: range.length]; } @finally { OFFreeMemory(buffer); } return ret; } - (OFString *)componentsJoinedByString: (OFString *)separator { return [self componentsJoinedByString: separator usingSelector: @selector(description) options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator options: (OFArrayJoinOptions)options { return [self componentsJoinedByString: separator usingSelector: @selector(description) options: options]; } - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector { return [self componentsJoinedByString: separator usingSelector: selector options: 0]; } - (OFString *)componentsJoinedByString: (OFString *)separator usingSelector: (SEL)selector options: (OFArrayJoinOptions)options { OFMutableString *ret; if (separator == nil) @throw [OFInvalidArgumentException exception]; if (self.count == 0) return @""; if (self.count == 1) { OFString *component = [[self objectAtIndex: 0] performSelector: selector]; if (component == nil) @throw [OFInvalidArgumentException exception]; return component; } ret = [OFMutableString string]; if (options & OFArraySkipEmptyComponents) { for (id object in self) { void *pool = objc_autoreleasePoolPush(); OFString *component = [object performSelector: selector]; if (component == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
511 512 513 514 515 516 517 | return false; return true; } - (unsigned long)hash { | | | | | | < | | | < | > | < | > | | | 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (id object in self) OFHashAddHash(&hash, [object hash]); OFHashFinalize(&hash); return hash; } - (OFString *)description { void *pool; OFMutableString *ret; if (self.count == 0) return @"()"; pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { [ret prependString: @"(\n"]; [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)"]; } @catch (id e) { [ret release]; @throw e; } objc_autoreleasePoolPop(pool); [ret makeImmutable]; return [ret autorelease]; } - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; if ([self isKindOfClass: [OFMutableArray class]]) element = [OFXMLElement elementWithName: @"OFMutableArray" namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFArray" namespace: OFSerializationNS]; for (id <OFSerialization> object in self) { void *pool2 = objc_autoreleasePoolPush(); [element addChild: object.XMLElementBySerializing]; objc_autoreleasePoolPop(pool2); } [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"["]; void *pool = objc_autoreleasePoolPush(); size_t i, count = self.count; if (options & OFJSONRepresentationOptionPretty) { OFMutableString *indentation = [OFMutableString string]; for (i = 0; i < depth; i++) [indentation appendString: @"\t"]; [JSON appendString: @"\n"]; |
︙ | ︙ | |||
662 663 664 665 666 667 668 | count = self.count; if (count <= 15) { uint8_t tmp = 0x90 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDC; | | | < | | < | < | 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 | count = self.count; if (count <= 15) { uint8_t tmp = 0x90 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDC; uint16_t tmp = OFToBigEndian16((uint16_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDD; uint32_t tmp = OFToBigEndian32((uint32_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); i = 0; for (id object in self) { void *pool2 = objc_autoreleasePoolPush(); OFData *child; i++; child = [object messagePackRepresentation]; [data addItems: child.items count: child.count]; objc_autoreleasePoolPop(pool2); } assert(i == count); [data makeImmutable]; |
︙ | ︙ | |||
712 713 714 715 716 717 718 | [object performSelector: selector]; } - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object { for (id objectIter in self) | | < < < < | < | < < < | | < | < < < < < < | | | < | | 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | [object performSelector: selector]; } - (void)makeObjectsPerformSelector: (SEL)selector withObject: (id)object { for (id objectIter in self) [objectIter performSelector: selector withObject: object]; } - (OFArray *)sortedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sort]; [new makeImmutable]; return new; } - (OFArray *)sortedArrayUsingSelector: (SEL)selector options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingSelector: selector options: options]; [new makeImmutable]; return new; } #ifdef OF_HAVE_BLOCKS - (OFArray *)sortedArrayUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options { OFMutableArray *new = [[self mutableCopy] autorelease]; [new sortUsingComparator: comparator options: options]; [new makeImmutable]; return new; } #endif - (OFArray *)reversedArray { OFMutableArray *new = [[self mutableCopy] autorelease]; [new reverse]; [new makeImmutable]; return new; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFRange range = OFRangeMake(state->state, count); if (range.length > SIZE_MAX - range.location) @throw [OFOutOfRangeException exception]; if (range.location + range.length > self.count) range.length = self.count - range.location; [self getObjects: objects inRange: range]; if (range.location + range.length > ULONG_MAX) @throw [OFOutOfRangeException exception]; state->state = (unsigned long)(range.location + range.length); state->itemsPtr = objects; state->mutationsPtr = (unsigned long *)self; return (int)range.length; } - (OFEnumerator *)objectEnumerator { return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: NULL] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { size_t i = 0; bool stop = false; for (id object in self) { block(object, i++, &stop); |
︙ | ︙ | |||
820 821 822 823 824 825 826 | { OFMutableArray *ret; if (object == nil) @throw [OFInvalidArgumentException exception]; ret = [[self mutableCopy] autorelease]; | < < < < | | | < | | | | < | | | | 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 | { OFMutableArray *ret; if (object == nil) @throw [OFInvalidArgumentException exception]; ret = [[self mutableCopy] autorelease]; [ret addObject: object]; [ret makeImmutable]; return ret; } - (OFArray *)arrayByAddingObjectsFromArray: (OFArray *)array { OFMutableArray *ret = [[self mutableCopy] autorelease]; [ret addObjectsFromArray: array]; [ret makeImmutable]; return ret; } - (OFArray *)arrayByRemovingObject: (id)object { OFMutableArray *ret = [[self mutableCopy] autorelease]; [ret removeObject: object]; [ret makeImmutable]; return ret; } #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (OFArrayMapBlock)block { OFArray *ret; size_t count = self.count; id *tmp = OFAllocMemory(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); }]; ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { OFFreeMemory(tmp); } return ret; } - (OFArray *)filteredArrayUsingBlock: (OFArrayFilterBlock)block { OFArray *ret; size_t count = self.count; id *tmp = OFAllocMemory(count, sizeof(id)); @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { if (block(object, idx)) tmp[i++] = object; }]; ret = [OFArray arrayWithObjects: tmp count: i]; } @finally { OFFreeMemory(tmp); } return ret; } - (id)foldUsingBlock: (OFArrayFoldBlock)block { size_t count = self.count; __block id current; if (count == 0) return nil; if (count == 1) return [[[self objectAtIndex: 0] retain] autorelease]; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { id new; if (idx == 0) { current = [object retain]; |
︙ | ︙ |
Renamed and modified src/atomic.h [7f44045855] to src/OFAtomic.h [cd35260cdb].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "macros.h" #ifndef OF_HAVE_ATOMIC_OPS # error No atomic operations available! #endif #if !defined(OF_HAVE_THREADS) | > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | #import "macros.h" #ifndef OF_HAVE_ATOMIC_OPS # error No atomic operations available! #endif #if !defined(OF_HAVE_THREADS) static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return (*p += i); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return (*p += i); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { return (*(char *volatile *)p += i); } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return (*p -= i); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return (*p -= i); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { return (*(char *volatile *)p -= i); } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return ++*p; } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return ++*p; } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return --*p; } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return --*p; } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return (*p |= i); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return (*p |= i); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return (*p &= i); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return (*p &= i); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return (*p ^= i); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return (*p ^= i); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { if (*p == o) { *p = n; return true; } return false; } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { if (*p == o) { *p = n; return true; } return false; } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { if (*p == o) { *p = n; return true; } return false; } static OF_INLINE void OFMemoryBarrier(void) { /* nop */ } static OF_INLINE void OFAcquireMemoryBarrier(void) { /* nop */ } static OF_INLINE void OFReleaseMemoryBarrier(void) { /* nop */ } #elif (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__) # import "platform/x86/OFAtomic.h" #elif defined(OF_POWERPC) && defined(__GNUC__) && !defined(__APPLE_CC__) && \ !defined(OF_AIX) # import "platform/PowerPC/OFAtomic.h" #elif defined(OF_HAVE_ATOMIC_BUILTINS) # import "platform/GCC4.7/OFAtomic.h" #elif defined(OF_HAVE_SYNC_BUILTINS) # import "platform/GCC4/OFAtomic.h" #elif defined(OF_HAVE_OSATOMIC) # import "platform/macOS/OFAtomic.h" #else # error No atomic operations available! #endif |
Renamed and modified src/base64.h [43a1dbe183] to src/OFBase64.h [459c01211d].
︙ | ︙ | |||
26 27 28 29 30 31 32 | @class OFString; @class OFMutableData; #ifdef __cplusplus extern "C" { #endif | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | @class OFString; @class OFMutableData; #ifdef __cplusplus extern "C" { #endif extern OFString *OFBase64Encode(const void *, size_t); extern bool OFBase64Decode(OFMutableData *, const char *, size_t); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Renamed and modified src/base64.m [042f7c96a2] to src/OFBase64.m [8e11dbdc78].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | | | | | | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFBase64.h" #import "OFString.h" #import "OFData.h" static const unsigned char encodeTable[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; static const signed char decodeTable[128] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 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, -1, -1, -1, -1, -1 }; OFString * OFBase64Encode(const void *data, size_t length) { OFMutableString *ret = [OFMutableString string]; uint8_t *buffer = (uint8_t *)data; size_t i; uint8_t rest; char tb[4]; uint32_t sb; rest = length % 3; for (i = 0; i < length - rest; i += 3) { sb = (buffer[i] << 16) | (buffer[i + 1] << 8) | buffer[i + 2]; tb[0] = encodeTable[(sb & 0xFC0000) >> 18]; tb[1] = encodeTable[(sb & 0x03F000) >> 12]; tb[2] = encodeTable[(sb & 0x000FC0) >> 6]; tb[3] = encodeTable[sb & 0x00003F]; [ret appendCString: tb encoding: OFStringEncodingASCII length: 4]; } switch (rest) { case 1: tb[0] = encodeTable[buffer[i] >> 2]; tb[1] = encodeTable[(buffer[i] & 3) << 4]; tb[2] = tb[3] = '='; [ret appendCString: tb encoding: OFStringEncodingASCII length: 4]; break; case 2: sb = (buffer[i] << 16) | (buffer[i + 1] << 8); tb[0] = encodeTable[(sb & 0xFC0000) >> 18]; tb[1] = encodeTable[(sb & 0x03F000) >> 12]; tb[2] = encodeTable[(sb & 0x000FC0) >> 6]; tb[3] = '='; [ret appendCString: tb encoding: OFStringEncodingASCII length: 4]; break; } [ret makeImmutable]; return ret; } bool OFBase64Decode(OFMutableData *data, const char *string, size_t length) { const uint8_t *buffer = (const uint8_t *)string; size_t i; if ((length & 3) != 0) return false; |
︙ | ︙ | |||
121 122 123 124 125 126 127 | return false; if (buffer[i + 2] == '=') count--; if (buffer[i + 3] == '=') count--; | | | | | | < | 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 | return false; if (buffer[i + 2] == '=') count--; if (buffer[i + 3] == '=') count--; if ((tmp = decodeTable[buffer[i]]) == -1) return false; sb |= tmp << 18; if ((tmp = decodeTable[buffer[i + 1]]) == -1) return false; sb |= tmp << 12; if ((tmp = decodeTable[buffer[i + 2]]) == -1) return false; sb |= tmp << 6; if ((tmp = decodeTable[buffer[i + 3]]) == -1) return false; sb |= tmp; db[0] = (sb & 0xFF0000) >> 16; db[1] = (sb & 0x00FF00) >> 8; db[2] = sb & 0x0000FF; [data addItems: db count: count]; } return true; } |
Modified src/OFBitSetCharacterSet.m from [54df15f988] to [269813e483].
︙ | ︙ | |||
28 29 30 31 32 33 34 | - (instancetype)initWithCharactersInString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | - (instancetype)initWithCharactersInString: (OFString *)string { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = string.characters; size_t length = string.length; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; if (c / CHAR_BIT >= _size) { size_t newSize; if (UINT32_MAX - c < 1) @throw [OFOutOfRangeException exception]; newSize = OFRoundUpToPowerOf2(CHAR_BIT, c + 1) / CHAR_BIT; _bitset = OFResizeMemory(_bitset, newSize, 1); memset(_bitset + _size, '\0', newSize - _size); _size = newSize; } OFBitsetSet(_bitset, c); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { OFFreeMemory(_bitset); [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { if (character / CHAR_BIT >= _size) return false; return OFBitsetIsSet(_bitset, character); } @end |
Modified src/OFBlock.h from [f6b4954bd3] to [d0a30cd463].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" | < < | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFBlock OFBlock.h ObjFW/OFBlock.h * * @brief The class for all blocks, since all blocks are also objects. */ |
︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 | OF_SUBCLASSING_RESTRICTED @interface OFGlobalBlock: OFBlock @end OF_SUBCLASSING_RESTRICTED @interface OFMallocBlock: OFBlock @end OF_ASSUME_NONNULL_END | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | OF_SUBCLASSING_RESTRICTED @interface OFGlobalBlock: OFBlock @end OF_SUBCLASSING_RESTRICTED @interface OFMallocBlock: OFBlock @end #ifdef __cplusplus extern "C" { #endif extern void *_Nullable _Block_copy(const void *_Nullable); extern void _Block_release(const void *_Nullable); # if defined(OF_WINDOWS) && \ (defined(OF_NO_SHARED) || defined(OF_COMPILING_OBJFW)) /* * Clang has implicit declarations for these, but they are dllimport. When * compiling ObjFW itself or using it as a static library, these need to be * dllexport. Interestingly, this still works when using it as a shared library. */ extern __declspec(dllexport) struct objc_class _NSConcreteStackBlock; extern __declspec(dllexport) struct objc_class _NSConcreteGlobalBlock; extern __declspec(dllexport) void _Block_object_assign(void *, const void *, const int); extern __declspec(dllexport) void _Block_object_dispose(const void *, const int); # endif #ifdef __cplusplus } #endif #ifndef Block_copy # define Block_copy(...) \ ((__typeof__(__VA_ARGS__))_Block_copy((const void *)(__VA_ARGS__))) #endif #ifndef Block_release # define Block_release(...) _Block_release((const void *)(__VA_ARGS__)) #endif OF_ASSUME_NONNULL_END |
Modified src/OFBlock.m from [678cbad32a] to [032a1ec707].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include "config.h" #include <stdint.h> #include <stdlib.h> #include <string.h> #import "OFBlock.h" #import "OFAllocFailedException.h" #import "OFInitializationFailedException.h" #if defined(OF_OBJFW_RUNTIME) # import "runtime/private.h" #endif | > > > > > > | | | | > | > > > > > | > < | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | #include "config.h" #include <stdint.h> #include <stdlib.h> #include <string.h> #import "OFBlock.h" #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif #import "OFAllocFailedException.h" #import "OFInitializationFailedException.h" #if defined(OF_OBJFW_RUNTIME) # import "runtime/private.h" #endif struct Block { Class isa; int flags; int reserved; void (*invoke)(void *block, ...); struct { unsigned long reserved; unsigned long size; void (*_Nullable copyHelper)(void *dest, void *src); void (*_Nullable disposeHelper)(void *src); const char *signature; } *descriptor; }; struct Byref { Class isa; struct Byref *forwarding; int flags; int size; void (*keepByref)(void *dest, void *src); void (*disposeByref)(void *); }; enum { OFBlockHasCopyDispose = (1 << 25), OFBlockHasCtor = (1 << 26), OFBlockIsGlobal = (1 << 28), OFBlockHasStret = (1 << 29), OFBlockHasSignature = (1 << 30) }; #define OFBlockRefCountMask 0xFFFF enum { OFBlockFieldIsObject = 3, OFBlockFieldIsBlock = 7, OFBlockFieldIsByref = 8, OFBlockFieldIsWeak = 16, OFBlockByrefCaller = 128 }; @protocol RetainRelease - (instancetype)retain; - (void)release; @end #ifdef OF_OBJFW_RUNTIME /* Begin of ObjC module */ static struct objc_class _NSConcreteStackBlock_metaclass = { Nil, Nil, "OFStackBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(_NSConcreteStackBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteStackBlock = { &_NSConcreteStackBlock_metaclass, (Class)(void *)"OFBlock", "OFStackBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct Block), NULL, NULL }; static struct objc_class _NSConcreteGlobalBlock_metaclass = { Nil, Nil, "OFGlobalBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(_NSConcreteGlobalBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteGlobalBlock = { &_NSConcreteGlobalBlock_metaclass, (Class)(void *)"OFBlock", "OFGlobalBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct Block), NULL, NULL }; static struct objc_class _NSConcreteMallocBlock_metaclass = { Nil, Nil, "OFMallocBlock", 8, OBJC_CLASS_INFO_METACLASS, sizeof(_NSConcreteMallocBlock_metaclass), NULL, NULL }; struct objc_class _NSConcreteMallocBlock = { &_NSConcreteMallocBlock_metaclass, (Class)(void *)"OFBlock", "OFMallocBlock", 8, OBJC_CLASS_INFO_CLASS, sizeof(struct Block), NULL, NULL }; static struct { unsigned long unknown; struct objc_selector *selectorRefs; uint16_t classDefsCount, categoryDefsCount; |
︙ | ︙ | |||
150 151 152 153 154 155 156 | #endif static struct { Class isa; } alloc_failed_exception; #ifndef OF_HAVE_ATOMIC_OPS | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | < | | | | | | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | #endif static struct { Class isa; } alloc_failed_exception; #ifndef OF_HAVE_ATOMIC_OPS # define numSpinlocks 8 /* needs to be a power of 2 */ # define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (numSpinlocks - 1) static OFSpinlock blockSpinlocks[numSpinlocks]; static OFSpinlock byrefSpinlocks[numSpinlocks]; #endif void * _Block_copy(const void *block_) { struct Block *block = (struct Block *)block_; if ([(id)block isMemberOfClass: (Class)&_NSConcreteStackBlock]) { struct Block *copy; if ((copy = malloc(block->descriptor->size)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException *) &alloc_failed_exception; } memcpy(copy, block, block->descriptor->size); object_setClass((id)copy, (Class)&_NSConcreteMallocBlock); copy->flags++; if (block->flags & OFBlockHasCopyDispose) block->descriptor->copyHelper(copy, block); return copy; } if ([(id)block isMemberOfClass: (Class)&_NSConcreteMallocBlock]) { #ifdef OF_HAVE_ATOMIC_OPS OFAtomicIntIncrease(&block->flags); #else unsigned hash = SPINLOCK_HASH(block); OFEnsure(OFSpinlockLock(&blockSpinlocks[hash]) == 0); block->flags++; OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0); #endif } return block; } void _Block_release(const void *block_) { struct Block *block = (struct Block *)block_; if (object_getClass((id)block) != (Class)&_NSConcreteMallocBlock) return; #ifdef OF_HAVE_ATOMIC_OPS if ((OFAtomicIntDecrease(&block->flags) & OFBlockRefCountMask) == 0) { if (block->flags & OFBlockHasCopyDispose) block->descriptor->disposeHelper(block); free(block); } #else unsigned hash = SPINLOCK_HASH(block); OFEnsure(OFSpinlockLock(&blockSpinlocks[hash]) == 0); if ((--block->flags & OFBlockRefCountMask) == 0) { OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0); if (block->flags & OFBlockHasCopyDispose) block->descriptor->disposeHelper(block); free(block); return; } OFEnsure(OFSpinlockUnlock(&blockSpinlocks[hash]) == 0); #endif } void _Block_object_assign(void *dst_, const void *src_, const int flags_) { int flags = flags_ & (OFBlockFieldIsBlock | OFBlockFieldIsObject | OFBlockFieldIsByref); if (src_ == NULL) return; switch (flags) { case OFBlockFieldIsBlock: *(struct Block **)dst_ = _Block_copy(src_); break; case OFBlockFieldIsObject: if (!(flags_ & OFBlockByrefCaller)) *(id *)dst_ = [(id)src_ retain]; break; case OFBlockFieldIsByref:; struct Byref *src = (struct Byref *)src_; struct Byref **dst = (struct Byref **)dst_; src = src->forwarding; if ((src->flags & OFBlockRefCountMask) == 0) { if ((*dst = malloc(src->size)) == NULL) { alloc_failed_exception.isa = [OFAllocFailedException class]; @throw (OFAllocFailedException *) &alloc_failed_exception; } memcpy(*dst, src, src->size); (*dst)->flags = ((*dst)->flags & ~OFBlockRefCountMask) | 1; (*dst)->forwarding = *dst; if (src->flags & OFBlockHasCopyDispose) src->keepByref(*dst, src); #ifdef OF_HAVE_ATOMIC_OPS if (!OFAtomicPointerCompareAndSwap( (void **)&src->forwarding, src, *dst)) { src->disposeByref(*dst); free(*dst); *dst = src->forwarding; } #else unsigned hash = SPINLOCK_HASH(src); OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0); if (src->forwarding == src) src->forwarding = *dst; else { src->disposeByref(*dst); free(*dst); *dst = src->forwarding; } OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); #endif } else *dst = src; #ifdef OF_HAVE_ATOMIC_OPS OFAtomicIntIncrease(&(*dst)->flags); #else unsigned hash = SPINLOCK_HASH(*dst); OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0); (*dst)->flags++; OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); #endif break; } } void _Block_object_dispose(const void *object_, const int flags_) { const int flags = flags_ & (OFBlockFieldIsBlock | OFBlockFieldIsObject | OFBlockFieldIsByref); if (object_ == NULL) return; switch (flags) { case OFBlockFieldIsBlock: _Block_release(object_); break; case OFBlockFieldIsObject: if (!(flags_ & OFBlockByrefCaller)) [(id)object_ release]; break; case OFBlockFieldIsByref:; struct Byref *object = (struct Byref *)object_; object = object->forwarding; #ifdef OF_HAVE_ATOMIC_OPS if ((OFAtomicIntDecrease(&object->flags) & OFBlockRefCountMask) == 0) { if (object->flags & OFBlockHasCopyDispose) object->disposeByref(object); free(object); } #else unsigned hash = SPINLOCK_HASH(object); OFEnsure(OFSpinlockLock(&byrefSpinlocks[hash]) == 0); if ((--object->flags & OFBlockRefCountMask) == 0) { OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); if (object->flags & OFBlockHasCopyDispose) object->disposeByref(object); free(object); } OFEnsure(OFSpinlockUnlock(&byrefSpinlocks[hash]) == 0); #endif break; } } @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS for (size_t i = 0; i < numSpinlocks; i++) if (OFSpinlockNew(&blockSpinlocks[i]) != 0 || OFSpinlockNew(&byrefSpinlocks[i]) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif #ifdef OF_APPLE_RUNTIME Class tmp; |
︙ | ︙ | |||
459 460 461 462 463 464 465 | return self; } - (unsigned int)retainCount { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) | | < | | 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | return self; } - (unsigned int)retainCount { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) return ((struct Block *)self)->flags & OFBlockRefCountMask; return OFMaxRetainCount; } - (void)release { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) Block_release(self); } - (void)dealloc { OF_DEALLOC_UNSUPPORTED } @end |
Modified src/OFBytesValue.m from [a0f881f925] to [cd6955a0ec].
︙ | ︙ | |||
23 24 25 26 27 28 29 | - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { self = [super init]; @try { | | | | | < | 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 | - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { self = [super init]; @try { _size = OFSizeOfTypeEncoding(objCType); _objCType = objCType; _bytes = OFAllocMemory(1, _size); memcpy(_bytes, bytes, _size); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { OFFreeMemory(_bytes); [super dealloc]; } - (void)getValue: (void *)value size: (size_t)size { if (size != _size) @throw [OFOutOfRangeException exception]; memcpy(value, _bytes, _size); } @end |
Renamed and modified src/crc16.h [a52b4d6f65] to src/OFCRC16.h [bfd06c1f20].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #endif #import "macros.h" #ifdef __cplusplus extern "C" { #endif | | | 21 22 23 24 25 26 27 28 29 30 31 32 | #endif #import "macros.h" #ifdef __cplusplus extern "C" { #endif extern uint16_t OFCRC16(uint16_t crc, const void *_Nonnull bytes, size_t length); #ifdef __cplusplus } #endif |
Renamed and modified src/crc16.m [db8332a387] to src/OFCRC16.m [d2261f5782].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFCRC16.h" static const uint16_t CRC16Magic = 0xA001; uint16_t OFCRC16(uint16_t CRC, const void *bytes_, size_t length) { const unsigned char *bytes = bytes_; for (size_t i = 0; i < length; i++) { CRC ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) CRC = (CRC >> 1) ^ (CRC16Magic & (~(CRC & 1) + 1)); } return CRC; } |
Renamed and modified src/crc32.h [c9bf40923b] to src/OFCRC32.h [4930b09098].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #endif #import "macros.h" #ifdef __cplusplus extern "C" { #endif | | | 21 22 23 24 25 26 27 28 29 30 31 32 | #endif #import "macros.h" #ifdef __cplusplus extern "C" { #endif extern uint32_t OFCRC32(uint32_t crc, const void *_Nonnull bytes, size_t length); #ifdef __cplusplus } #endif |
Renamed and modified src/crc32.m [40c6d66d15] to src/OFCRC32.m [0968fe2540].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFCRC32.h" static const uint32_t CRC32Magic = 0xEDB88320; uint32_t OFCRC32(uint32_t CRC, const void *bytes_, size_t length) { const unsigned char *bytes = bytes_; for (size_t i = 0; i < length; i++) { CRC ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) CRC = (CRC >> 1) ^ (CRC32Magic & (~(CRC & 1) + 1)); } return CRC; } |
Modified src/OFCharacterSet.h from [213677c26a] to [718ebc3831].
︙ | ︙ | |||
52 53 54 55 56 57 58 | /** * @brief Creates a new character set containing the characters in the specified * range. * * @param range The range of characters for the character set * @return A new OFCharacterSet */ | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | /** * @brief Creates a new character set containing the characters in the specified * range. * * @param range The range of characters for the character set * @return A new OFCharacterSet */ + (instancetype)characterSetWithRange: (OFRange)range; /** * @brief A character set containing all Unicode characters in the category * `Zs` plus CHARACTER TABULATION (U+0009). */ + (OFCharacterSet *)whitespaceCharacterSet; |
︙ | ︙ | |||
76 77 78 79 80 81 82 | /** * @brief Initializes an already allocated character set with the characters in * the specified range. * * @param range The range of characters for the character set * @return An initialized OFCharacterSet */ | | | | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | /** * @brief Initializes an already allocated character set with the characters in * the specified range. * * @param range The range of characters for the character set * @return An initialized OFCharacterSet */ - (instancetype)initWithRange: (OFRange)range; /** * @brief Returns whether the specified character is a member of the character * set. * * @param character The character that is checked for being a member of the * character set * @return Whether the specified character is a member of the character set. */ - (bool)characterIsMember: (OFUnichar)character; @end OF_ASSUME_NONNULL_END |
Modified src/OFCharacterSet.m from [e06618edef] to [c98072a03a].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "OFCharacterSet.h" #import "OFBitSetCharacterSet.h" #import "OFInvertedCharacterSet.h" | | < | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | */ #include "config.h" #import "OFCharacterSet.h" #import "OFBitSetCharacterSet.h" #import "OFInvertedCharacterSet.h" #import "OFOnce.h" #import "OFRangeCharacterSet.h" @interface OFPlaceholderCharacterSet: OFCharacterSet @end @interface OFWhitespaceCharacterSet: OFCharacterSet @end static struct { |
︙ | ︙ | |||
48 49 50 51 52 53 54 | - (instancetype)initWithCharactersInString: (OFString *)characters { return (id)[[OFBitSetCharacterSet alloc] initWithCharactersInString: characters]; } | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | - (instancetype)initWithCharactersInString: (OFString *)characters { return (id)[[OFBitSetCharacterSet alloc] initWithCharactersInString: characters]; } - (instancetype)initWithRange: (OFRange)range { return (id)[[OFRangeCharacterSet alloc] initWithRange: range]; } - (instancetype)retain { return self; |
︙ | ︙ | |||
96 97 98 99 100 101 102 | + (instancetype)characterSetWithCharactersInString: (OFString *)characters { return [[[self alloc] initWithCharactersInString: characters] autorelease]; } | | | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | + (instancetype)characterSetWithCharactersInString: (OFString *)characters { return [[[self alloc] initWithCharactersInString: characters] autorelease]; } + (instancetype)characterSetWithRange: (OFRange)range { return [[[self alloc] initWithRange: range] autorelease]; } + (OFCharacterSet *)whitespaceCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initWhitespaceCharacterSet); return whitespaceCharacterSet; } - (instancetype)init { if ([self isMemberOfClass: [OFCharacterSet class]]) { |
︙ | ︙ | |||
130 131 132 133 134 135 136 | } - (instancetype)initWithCharactersInString: (OFString *)characters { OF_INVALID_INIT_METHOD } | | | | 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | } - (instancetype)initWithCharactersInString: (OFString *)characters { OF_INVALID_INIT_METHOD } - (instancetype)initWithRange: (OFRange)range { OF_INVALID_INIT_METHOD } - (bool)characterIsMember: (OFUnichar)character { OF_UNRECOGNIZED_SELECTOR } - (OFCharacterSet *)invertedSet { return [[[OFInvertedCharacterSet alloc] |
︙ | ︙ | |||
164 165 166 167 168 169 170 | - (void)release { } - (unsigned int)retainCount { | | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } - (bool)characterIsMember: (OFUnichar)character { switch (character) { case 0x0009: case 0x0020: case 0x00A0: case 0x1680: case 0x2000: |
︙ | ︙ |
Modified src/OFCollection.h from [9e18f6ef6d] to [af0d421edb].
︙ | ︙ | |||
18 19 20 21 22 23 24 | OF_ASSUME_NONNULL_BEGIN /** * @protocol OFCollection OFCollection.h ObjFW/OFCollection.h * * @brief A protocol with methods common for all collections. */ | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | OF_ASSUME_NONNULL_BEGIN /** * @protocol OFCollection OFCollection.h ObjFW/OFCollection.h * * @brief A protocol with methods common for all collections. */ @protocol OFCollection <OFEnumeration, OFFastEnumeration> /** * @brief The number of objects in the collection */ @property (readonly, nonatomic) size_t count; /** * @brief Checks whether the collection contains an object equal to the |
︙ | ︙ |
Modified src/OFColor.m from [8af2ad50d8] to [7162349776].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFColor.h" | < | | | | | | | | | | | | | | | | | | | | 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 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFColor.h" #import "OFOnce.h" #import "OFInvalidArgumentException.h" @implementation OFColor #define PREDEFINED_COLOR(name, redValue, greenValue, blueValue) \ static OFColor *name##Color = nil; \ \ static void \ initPredefinedColor_##name(void) \ { \ name##Color = [[OFColor alloc] initWithRed: redValue \ green: greenValue \ blue: blueValue \ alpha: 1]; \ } \ \ + (OFColor *)name \ { \ static OFOnceControl onceControl = OFOnceControlInitValue; \ OFOnce(&onceControl, initPredefinedColor_##name); \ \ return name##Color; \ } PREDEFINED_COLOR(black, 0.00f, 0.00f, 0.00f) PREDEFINED_COLOR(silver, 0.75f, 0.75f, 0.75f) PREDEFINED_COLOR(grey, 0.50f, 0.50f, 0.50f) PREDEFINED_COLOR(white, 1.00f, 1.00f, 1.00f) PREDEFINED_COLOR(maroon, 0.50f, 0.00f, 0.00f) |
︙ | ︙ | |||
118 119 120 121 122 123 124 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | 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 | return false; return true; } - (unsigned long)hash { unsigned long hash; float tmp; OFHashInit(&hash); tmp = OFToLittleEndianFloat(_red); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAdd(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(_green); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAdd(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(_blue); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAdd(&hash, ((char *)&tmp)[i]); tmp = OFToLittleEndianFloat(_alpha); for (uint_fast8_t i = 0; i < sizeof(float); i++) OFHashAdd(&hash, ((char *)&tmp)[i]); OFHashFinalize(&hash); return hash; } - (void)getRed: (float *)red green: (float *)green blue: (float *)blue |
︙ | ︙ |
Modified src/OFCondition.h from [43068e28cc] to [8519816f5f].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFMutex.h" | < | | | 10 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 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFMutex.h" #import "OFPlainCondition.h" OF_ASSUME_NONNULL_BEGIN @class OFDate; /** * @class OFCondition OFCondition.h ObjFW/OFCondition.h * * @brief A class implementing a condition variable for thread synchronization. */ OF_SUBCLASSING_RESTRICTED @interface OFCondition: OFMutex { OFPlainCondition _condition; bool _conditionInitialized; } /** * @brief Creates a new condition. * * @return A new, autoreleased OFCondition |
︙ | ︙ | |||
68 69 70 71 72 73 74 | * * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref waitForTimeInterval: returned! * * @param timeInterval The time interval until the timeout is reached * @return Whether the condition has been signaled */ | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | * * @note Waiting might have been interrupted by a signal. It is thus recommended * to check the condition again after @ref waitForTimeInterval: returned! * * @param timeInterval The time interval until the timeout is reached * @return Whether the condition has been signaled */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval; #ifdef OF_AMIGAOS /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast, the timeout is reached or an Exec Signal is received. * * @note This is only available on AmigaOS! * * @param timeInterval The time interval until the timeout is reached * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @return Whether the condition has been signaled or a signal received */ - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval orExecSignal: (ULONG *)signalMask; #endif /** * @brief Blocks the current thread until another thread calls @ref signal, * @ref broadcast or the timeout is reached. * |
︙ | ︙ | |||
110 111 112 113 114 115 116 | * @note This is only available on AmigaOS! * * @param date The date at which the timeout is reached * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @return Whether the condition has been signaled or a signal received */ | | < | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | * @note This is only available on AmigaOS! * * @param date The date at which the timeout is reached * @param signalMask A pointer to a signal mask of Exec Signals to receive. * This is modified and set to the mask of signals received. * @return Whether the condition has been signaled or a signal received */ - (bool)waitUntilDate: (OFDate *)date orExecSignal: (ULONG *)signalMask; #endif /** * @brief Signals the next waiting thread to continue. */ - (void)signal; |
︙ | ︙ |
Modified src/OFCondition.m from [00d905a1c0] to [17f7291bd2].
︙ | ︙ | |||
32 33 34 35 36 37 38 | return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; | | | | | | | | > | | | < | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; if (OFPlainConditionNew(&_condition) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } _conditionInitialized = true; return self; } - (void)dealloc { if (_conditionInitialized) { int error = OFPlainConditionFree(&_condition); if (error != 0) { OFEnsure(error == EBUSY); @throw [OFConditionStillWaitingException exceptionWithCondition: self]; } } [super dealloc]; } - (void)wait { int error = OFPlainConditionWait(&_condition, &_mutex); if (error != 0) @throw [OFConditionWaitFailedException exceptionWithCondition: self errNo: error]; } #ifdef OF_AMIGAOS - (void)waitForConditionOrExecSignal: (ULONG *)signalMask { int error = OFPlainConditionWaitOrExecSignal(&_condition, &_mutex, signalMask); if (error != 0) @throw [OFConditionWaitFailedException exceptionWithCondition: self errNo: error]; } #endif - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval { int error = OFPlainConditionTimedWait(&_condition, &_mutex, timeInterval); if (error == ETIMEDOUT) return false; if (error != 0) @throw [OFConditionWaitFailedException exceptionWithCondition: self errNo: error]; return true; } #ifdef OF_AMIGAOS - (bool)waitForTimeInterval: (OFTimeInterval)timeInterval orExecSignal: (ULONG *)signalMask { int error = OFPlainConditionTimedWaitOrExecSignal(&_condition, &_mutex, timeInterval, signalMask); if (error == ETIMEDOUT) return false; if (error != 0) @throw [OFConditionWaitFailedException exceptionWithCondition: self errNo: error]; return true; } #endif - (bool)waitUntilDate: (OFDate *)date { return [self waitForTimeInterval: date.timeIntervalSinceNow]; } #ifdef OF_AMIGAOS - (bool)waitUntilDate: (OFDate *)date orExecSignal: (ULONG *)signalMask { return [self waitForTimeInterval: date.timeIntervalSinceNow orExecSignal: signalMask]; } #endif - (void)signal { int error = OFPlainConditionSignal(&_condition); if (error != 0) @throw [OFConditionSignalFailedException exceptionWithCondition: self errNo: error]; } - (void)broadcast { int error = OFPlainConditionBroadcast(&_condition); if (error != 0) @throw [OFConditionBroadcastFailedException exceptionWithCondition: self errNo: error]; } @end |
Modified src/OFConstantString.m from [41b6262c76] to [a046d60efd].
︙ | ︙ | |||
60 61 62 63 64 65 66 | - (instancetype)autorelease { return self; } - (unsigned int)retainCount { | | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | - (instancetype)autorelease { return self; } - (unsigned int)retainCount { return OFMaxRetainCount; } - (void)release { } - (void)dealloc |
︙ | ︙ | |||
102 103 104 105 106 107 108 | objc_registerClassPair((Class)&_OFConstantStringClassReference); #endif } - (void)finishInitialization { @synchronized (self) { | | | | | | | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | objc_registerClassPair((Class)&_OFConstantStringClassReference); #endif } - (void)finishInitialization { @synchronized (self) { struct OFUTF8StringIvars *ivars; if ([self isMemberOfClass: [OFConstantUTF8String class]]) return; ivars = OFAllocZeroedMemory(1, sizeof(*ivars)); ivars->cString = _cString; ivars->cStringLength = _cStringLength; switch (OFUTF8StringCheck(ivars->cString, ivars->cStringLength, &ivars->length)) { case 1: ivars->isUTF8 = true; break; case -1: OFFreeMemory(ivars); @throw [OFInvalidEncodingException exception]; } _cString = (char *)ivars; object_setClass(self, [OFConstantUTF8String class]); } } |
︙ | ︙ | |||
143 144 145 146 147 148 149 | - (instancetype)autorelease { return self; } - (unsigned int)retainCount { | | < < | | < | < < < < | < | < < < | < | < | | < | < < | < | < | | < | < | | | < | < < < | < | < | | < < < < | < < < | < < < < | < < < < < < < < < < | < | < < | < < < < < < < < < < | < | < | < < | < | < | < < < < < | < < | < < | < < | < | < | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | - (instancetype)autorelease { return self; } - (unsigned int)retainCount { return OFMaxRetainCount; } - (void)release { } - (void)dealloc { OF_DEALLOC_UNSUPPORTED } /* * In all following methods, the constant string is converted to an * OFConstantUTF8String and the message sent again. */ /* From protocol OFCopying */ - (id)copy { [self finishInitialization]; return [self copy]; } /* From protocol OFMutableCopying */ - (id)mutableCopy { [self finishInitialization]; return [self mutableCopy]; } /* From protocol OFComparing, but overridden in OFString */ - (OFComparisonResult)compare: (OFString *)string { [self finishInitialization]; return [self compare: string]; } /* From OFObject, but reimplemented in OFString */ - (bool)isEqual: (id)object { [self finishInitialization]; return [self isEqual: object]; } - (unsigned long)hash { [self finishInitialization]; return self.hash; } - (OFString *)description { [self finishInitialization]; return self.description; } /* From OFString */ - (const char *)UTF8String { [self finishInitialization]; return self.UTF8String; } - (size_t)getCString: (char *)cString_ maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self getCString: cString_ maxLength: maxLength encoding: encoding]; } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self cStringWithEncoding: encoding]; } - (size_t)length { [self finishInitialization]; return self.length; } - (size_t)UTF8StringLength { [self finishInitialization]; return self.UTF8StringLength; } - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self cStringLengthWithEncoding: encoding]; } - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string { [self finishInitialization]; return [self caseInsensitiveCompare: string]; } - (OFUnichar)characterAtIndex: (size_t)idx { [self finishInitialization]; return [self characterAtIndex: idx]; } - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range { [self finishInitialization]; [self getCharacters: buffer inRange: range]; } - (OFRange)rangeOfString: (OFString *)string { [self finishInitialization]; return [self rangeOfString: string]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options { [self finishInitialization]; return [self rangeOfString: string options: options]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { [self finishInitialization]; return [self rangeOfString: string options: options range: range]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet options: options]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options range: (OFRange)range { [self finishInitialization]; return [self indexOfCharacterFromSet: characterSet options: options range: range]; } - (bool)containsString: (OFString *)string { [self finishInitialization]; return [self containsString: string]; } - (OFString *)substringFromIndex: (size_t)idx { [self finishInitialization]; return [self substringFromIndex: idx]; } - (OFString *)substringToIndex: (size_t)idx { [self finishInitialization]; return [self substringToIndex: idx]; } - (OFString *)substringWithRange: (OFRange)range { [self finishInitialization]; return [self substringWithRange: range]; } - (OFString *)stringByAppendingString: (OFString *)string { [self finishInitialization]; return [self stringByAppendingString: string]; } - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments { [self finishInitialization]; return [self stringByAppendingFormat: format arguments: arguments]; } - (OFString *)stringByAppendingPathComponent: (OFString *)component { [self finishInitialization]; return [self stringByAppendingPathComponent: component]; } - (OFString *)stringByPrependingString: (OFString *)string { [self finishInitialization]; return [self stringByPrependingString: string]; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { [self finishInitialization]; return [self stringByReplacingOccurrencesOfString: string withString: replacement]; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { [self finishInitialization]; return [self stringByReplacingOccurrencesOfString: string withString: replacement options: options range: range]; } - (OFString *)uppercaseString { [self finishInitialization]; return self.uppercaseString; } - (OFString *)lowercaseString { [self finishInitialization]; return self.lowercaseString; } - (OFString *)capitalizedString { [self finishInitialization]; return self.capitalizedString; } - (OFString *)stringByDeletingLeadingWhitespaces { [self finishInitialization]; return self.stringByDeletingLeadingWhitespaces; } - (OFString *)stringByDeletingTrailingWhitespaces { [self finishInitialization]; return self.stringByDeletingTrailingWhitespaces; } - (OFString *)stringByDeletingEnclosingWhitespaces { [self finishInitialization]; return self.stringByDeletingEnclosingWhitespaces; } - (bool)hasPrefix: (OFString *)prefix { [self finishInitialization]; return [self hasPrefix: prefix]; } - (bool)hasSuffix: (OFString *)suffix { [self finishInitialization]; return [self hasSuffix: suffix]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter { [self finishInitialization]; return [self componentsSeparatedByString: delimiter]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options { [self finishInitialization]; return [self componentsSeparatedByString: delimiter options: options]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet { [self finishInitialization]; return [self componentsSeparatedByCharactersInSet: characterSet]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet options: (OFStringSeparationOptions)options { [self finishInitialization]; return [self componentsSeparatedByCharactersInSet: characterSet options: options]; } - (OFArray *)pathComponents { [self finishInitialization]; return self.pathComponents; } - (OFString *)lastPathComponent { [self finishInitialization]; return self.lastPathComponent; } - (OFString *)stringByDeletingLastPathComponent { [self finishInitialization]; return self.stringByDeletingLastPathComponent; } - (long long)longLongValue { [self finishInitialization]; return self.longLongValue; } - (long long)longLongValueWithBase: (int)base { [self finishInitialization]; return [self longLongValueWithBase: base]; } - (unsigned long long)unsignedLongLongValue { [self finishInitialization]; return self.unsignedLongLongValue; } - (unsigned long long)unsignedLongLongValueWithBase: (int)base { [self finishInitialization]; return [self unsignedLongLongValueWithBase: base]; } - (float)floatValue { [self finishInitialization]; return self.floatValue; } - (double)doubleValue { [self finishInitialization]; return self.doubleValue; } - (const OFUnichar *)characters { [self finishInitialization]; return self.characters; } - (const OFChar16 *)UTF16String { [self finishInitialization]; return self.UTF16String; } - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder { [self finishInitialization]; return [self UTF16StringWithByteOrder: byteOrder]; } - (size_t)UTF16StringLength { [self finishInitialization]; return self.UTF16StringLength; } - (const OFChar32 *)UTF32String { [self finishInitialization]; return self.UTF32String; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { [self finishInitialization]; return [self UTF32StringWithByteOrder: byteOrder]; } - (OFData *)dataWithEncoding: (OFStringEncoding)encoding { [self finishInitialization]; return [self dataWithEncoding: encoding]; } #ifdef OF_HAVE_UNICODE_TABLES - (OFString *)decomposedStringWithCanonicalMapping { [self finishInitialization]; return self.decomposedStringWithCanonicalMapping; } - (OFString *)decomposedStringWithCompatibilityMapping { [self finishInitialization]; return self.decomposedStringWithCompatibilityMapping; } #endif #ifdef OF_WINDOWS - (OFString *)stringByExpandingWindowsEnvironmentStrings { [self finishInitialization]; return self.stringByExpandingWindowsEnvironmentStrings; } #endif #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { [self finishInitialization]; [self writeToFile: path]; } - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { [self finishInitialization]; [self writeToFile: path encoding: encoding]; } #endif - (void)writeToURL: (OFURL *)URL { [self finishInitialization]; [self writeToURL: URL]; } - (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding { [self finishInitialization]; [self writeToURL: URL encoding: encoding]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block { [self finishInitialization]; [self enumerateLinesUsingBlock: block]; } #endif @end |
Modified src/OFCountedMapTableSet.m from [5101deac28] to [fb2a261b38].
︙ | ︙ | |||
79 80 81 82 83 84 85 | [self release]; @throw e; } return self; } | | < | < | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [self init]; @try { for (size_t i = 0; i < count; i++) [self addObject: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { self = [self init]; @try { id object; [self addObject: firstObject]; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: @"OFCountedSet"] || | | | | | 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 | { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: @"OFCountedSet"] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *objectElement in [element elementsForName: @"object" namespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *object; OFXMLAttribute *countAttribute; unsigned long long count; object = [objectElement elementsForNamespace: OFSerializationNS].firstObject; countAttribute = [objectElement attributeForName: @"count"]; if (object == nil || countAttribute == nil) @throw [OFInvalidFormatException exception]; count = countAttribute.unsignedLongLongValue; |
︙ | ︙ | |||
167 168 169 170 171 172 173 | - (size_t)countForObject: (id)object { return (size_t)(uintptr_t)[_mapTable objectForKey: object]; } #ifdef OF_HAVE_BLOCKS | | < | < | < | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | - (size_t)countForObject: (id)object { return (size_t)(uintptr_t)[_mapTable objectForKey: object]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (OFCountedSetEnumerationBlock)block { @try { [_mapTable enumerateKeysAndObjectsUsingBlock: ^ (void *key, void *object, bool *stop) { block(key, (size_t)(uintptr_t)object, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: self]; } } #endif - (void)addObject: (id)object { size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object]; if (SIZE_MAX - count < 1 || UINTPTR_MAX - count < 1) @throw [OFOutOfRangeException exception]; [_mapTable setObject: (void *)(uintptr_t)(count + 1) forKey: object]; } - (void)removeObject: (id)object { size_t count = (size_t)(uintptr_t)[_mapTable objectForKey: object]; if (count == 0) return; count--; if (count > 0) [_mapTable setObject: (void *)(uintptr_t)count forKey: object]; else [_mapTable removeObjectForKey: object]; } - (void)removeAllObjects { [_mapTable removeAllObjects]; } - (void)makeImmutable { } @end |
Modified src/OFCountedSet.h from [d5fbc7df8a] to [aa07eb172d].
︙ | ︙ | |||
24 25 26 27 28 29 30 | * @brief A block for enumerating an OFCountedSet. * * @param object The current object * @param count The count of the object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | * @brief A block for enumerating an OFCountedSet. * * @param object The current object * @param count The count of the object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFCountedSetEnumerationBlock)(id object, size_t count, bool *stop); #endif /** * @class OFCountedSet OFCountedSet.h ObjFW/OFCountedSet.h * * @brief An abstract class for a mutable unordered set of objects, counting how |
︙ | ︙ | |||
55 56 57 58 59 60 61 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object in the set. * * @param block The block to execute for each object in the set */ | | < | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object in the set. * * @param block The block to execute for each object in the set */ - (void)enumerateObjectsAndCountUsingBlock: (OFCountedSetEnumerationBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END |
Modified src/OFCountedSet.m from [2a2cd32bfd] to [f1dc200ff4].
︙ | ︙ | |||
55 56 57 58 59 60 61 | ret = [[OFCountedMapTableSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } | | < | < | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | ret = [[OFCountedMapTableSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFCountedMapTableSet alloc] initWithObjects: objects count: count]; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFCountedMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { |
︙ | ︙ | |||
156 157 158 159 160 161 162 | [ret appendFormat: @": %zu", [self countForObject: object]]; if (++i < count) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool2); } | | < < | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | [ret appendFormat: @": %zu", [self countForObject: object]]; if (++i < count) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } |
︙ | ︙ | |||
183 184 185 186 187 188 189 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFCountedSet" | | | | < | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFCountedSet" namespace: OFSerializationNS]; for (id <OFSerialization> object in self) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *objectElement; OFString *count; count = [OFString stringWithFormat: @"%zu", [self countForObject: object]]; objectElement = [OFXMLElement elementWithName: @"object" namespace: OFSerializationNS]; [objectElement addAttributeWithName: @"count" stringValue: count]; [objectElement addChild: object.XMLElementBySerializing]; [element addChild: objectElement]; objc_autoreleasePoolPop(pool2); } [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (OFCountedSetEnumerationBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, bool *stop) { block(object, [self countForObject: object], stop); }]; } #endif |
︙ | ︙ |
Renamed and modified src/OFCryptoHash.h [09ebd5cbd7] to src/OFCryptographicHash.h [3e39e62dc1].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** | | > | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** * @protocol OFCryptographicHash \ * OFCryptographicHash.h ObjFW/OFCryptographicHash.h * * @brief A protocol for classes providing cryptographic hash functions. * * A cryptographic hash implementing this protocol can be copied. The entire * state is copied, allowing to calculate a new hash from there. This is * especially useful for generating many hashes with a common prefix. */ @protocol OFCryptographicHash <OFObject, OFCopying> #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) size_t digestSize; @property (class, readonly, nonatomic) size_t blockSize; #endif /** * @brief The digest size of the cryptographic hash, in bytes. |
︙ | ︙ | |||
62 63 64 65 66 67 68 | OF_RETURNS_INNER_POINTER; /** * @brief Creates a new cryptographic hash. * * @return A new autoreleased cryptographic hash */ | < | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | OF_RETURNS_INNER_POINTER; /** * @brief Creates a new cryptographic hash. * * @return A new autoreleased cryptographic hash */ + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory; /** * @brief Returns the digest size of the cryptographic hash, in bytes. * * @return The digest size of the cryptographic hash, in bytes */ + (size_t)digestSize; |
︙ | ︙ | |||
94 95 96 97 98 99 100 | /** * @brief Adds a buffer to the cryptographic hash to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ | | < | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | /** * @brief Adds a buffer to the cryptographic hash to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Resets all state so that a new hash can be calculated. * * @warning This invalidates any pointer previously returned by @ref digest. If * you are still interested in the previous digest, you need to memcpy * it yourself before calling @ref reset! */ - (void)reset; @end OF_ASSUME_NONNULL_END |
Modified src/OFDNSQuery.h from [ebec8fd547] to [3c40a6d229].
︙ | ︙ | |||
24 25 26 27 28 29 30 | * @class OFDNSQuery OFDNSQuery.h ObjFW/OFDNSQuery.h * * @brief A class representing a DNS query. */ @interface OFDNSQuery: OFObject <OFCopying> { OFString *_domainName; | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | * @class OFDNSQuery OFDNSQuery.h ObjFW/OFDNSQuery.h * * @brief A class representing a DNS query. */ @interface OFDNSQuery: OFObject <OFCopying> { OFString *_domainName; OFDNSClass _DNSClass; OFDNSRecordType _recordType; OF_RESERVE_IVARS(OFDNSQuery, 4) } /** * @brief The domain name of the query. */ @property (readonly, nonatomic) OFString *domainName; /** * @brief The DNS class of the query. */ @property (readonly, nonatomic) OFDNSClass DNSClass; /** * @brief The record type of the query. */ @property (readonly, nonatomic) OFDNSRecordType recordType; /** * @brief Creates a new, autoreleased OFDNSQuery. * * @param domainName The domain name to query * @param DNSClass The DNS class of the query * @param recordType The record type of the query * @return A new, autoreleased OFDNSQuery */ + (instancetype)queryWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType; /** * @brief Initializes an already allocated OFDNSQuery. * * @param domainName The domain name to query * @param DNSClass The DNS class of the query * @param recordType The record type of the query * @return An initialized OFDNSQuery */ - (instancetype)initWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/OFDNSQuery.m from [a81f7a9a95] to [cc70b330d8].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFString.h" @implementation OFDNSQuery @synthesize domainName = _domainName, DNSClass = _DNSClass; @synthesize recordType = _recordType; + (instancetype)queryWithDomainName: (OFString *)domainName | | | | | | 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 | #import "OFString.h" @implementation OFDNSQuery @synthesize domainName = _domainName, DNSClass = _DNSClass; @synthesize recordType = _recordType; + (instancetype)queryWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType { return [[[self alloc] initWithDomainName: domainName DNSClass: DNSClass recordType: recordType] autorelease]; } - (instancetype)initWithDomainName: (OFString *)domainName DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); if (![domainName hasSuffix: @"."]) |
︙ | ︙ | |||
89 90 91 92 93 94 95 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _domainName.hash); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (OFString *)description { return [OFString stringWithFormat: @"<%@ %@ %@ %@>", self.className, _domainName, OFDNSClassName(_DNSClass), OFDNSRecordTypeName(_recordType)]; } @end |
Modified src/OFDNSResolver.h from [c467730d8f] to [d50442556a].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "OFDNSResourceRecord.h" #import "OFDNSResponse.h" #import "OFRunLoop.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #import "OFDNSResourceRecord.h" #import "OFDNSResponse.h" #import "OFRunLoop.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #define OFDNSResolverBufferLength 512 @class OFArray OF_GENERIC(ObjectType); @class OFDNSResolver; @class OFDNSResolverContext; @class OFDNSResolverSettings; @class OFDate; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFNumber; @class OFTCPSocket; @class OFUDPSocket; /** * @enum OFDNSResolverErrorCode OFDNSResolver.h ObjFW/OFDNSResolver.h * * @brief An enum describing why resolving a host failed. */ typedef enum { /** An unknown error */ OFDNSResolverErrorCodeUnknown, /** The query timed out */ OFDNSResolverErrorCodeTimeout, /** The query was canceled */ OFDNSResolverErrorCodeCanceled, /** * No result for the specified host with the specified type and class. * * This is only used in situations where this is an error, e.g. when * trying to connect to a host. */ OFDNSResolverErrorCodeNoResult, /** The server considered the query to be malformed */ OFDNSResolverErrorCodeServerInvalidFormat, /** The server was unable to process due to an internal error */ OFDNSResolverErrorCodeServerFailure, /** The server returned an error that the domain does not exist */ OFDNSResolverErrorCodeServerNameError, /** The server does not have support for the requested query */ OFDNSResolverErrorCodeServerNotImplemented, /** The server refused the query */ OFDNSResolverErrorCodeServerRefused, /** There was no name server to query */ OFDNSResolverErrorCodeNoNameServer } OFDNSResolverErrorCode; /** * @protocol OFDNSResolverQueryDelegate OFDNSResolver.h ObjFW/OFDNSResolver.h * * @brief A delegate for performed DNS queries. */ @protocol OFDNSResolverQueryDelegate <OFObject> |
︙ | ︙ | |||
97 98 99 100 101 102 103 | @protocol OFDNSResolverHostDelegate <OFObject> /** * @brief This method is called when a DNS resolver resolved a host to * addresses. * * @param resolver The acting resolver * @param host The host the resolver resolved | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | @protocol OFDNSResolverHostDelegate <OFObject> /** * @brief This method is called when a DNS resolver resolved a host to * addresses. * * @param resolver The acting resolver * @param host The host the resolver resolved * @param addresses OFData containing several OFSocketAddress * @param exception The exception that occurred during resolving, or nil on * success */ - (void)resolver: (OFDNSResolver *)resolver didResolveHost: (OFString *)host addresses: (nullable OFData *)addresses exception: (nullable id)exception; |
︙ | ︙ | |||
125 126 127 128 129 130 131 | @interface OFDNSResolver: OFObject { OFDNSResolverSettings *_settings; OFUDPSocket *_IPv4Socket; #ifdef OF_HAVE_IPV6 OFUDPSocket *_IPv6Socket; #endif | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | @interface OFDNSResolver: OFObject { OFDNSResolverSettings *_settings; OFUDPSocket *_IPv4Socket; #ifdef OF_HAVE_IPV6 OFUDPSocket *_IPv6Socket; #endif char _buffer[OFDNSResolverBufferLength]; OFMutableDictionary OF_GENERIC(OFNumber *, OFDNSResolverContext *) *_queries; OFMutableDictionary OF_GENERIC(OFTCPSocket *, OFDNSResolverContext *) *_TCPQueries; } /** |
︙ | ︙ | |||
161 162 163 164 165 166 167 | */ @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains; /** * @brief The timeout, in seconds, after which the next name server should be * tried. */ | | | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | */ @property (copy, nonatomic) OFArray OF_GENERIC(OFString *) *searchDomains; /** * @brief The timeout, in seconds, after which the next name server should be * tried. */ @property (nonatomic) OFTimeInterval timeout; /** * @brief The number of attempts before giving up to resolve a host. * * Trying all name servers once is considered a single attempt. */ @property (nonatomic) unsigned int maxAttempts; |
︙ | ︙ | |||
185 186 187 188 189 190 191 | @property (nonatomic) bool usesTCP; /** * @brief The interval in seconds in which the config should be reloaded. * * Setting this to 0 disables config reloading. */ | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | @property (nonatomic) bool usesTCP; /** * @brief The interval in seconds in which the config should be reloaded. * * Setting this to 0 disables config reloading. */ @property (nonatomic) OFTimeInterval configReloadInterval; /** * @brief Creates a new, autoreleased OFDNSResolver. */ + (instancetype)resolver; /** |
︙ | ︙ | |||
214 215 216 217 218 219 220 | * @brief Asynchronously performs the specified query. * * @param query The query to perform * @param runLoopMode The run loop mode in which to resolve * @param delegate The delegate to use for callbacks */ - (void)asyncPerformQuery: (OFDNSQuery *)query | | | | | | | | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | * @brief Asynchronously performs the specified query. * * @param query The query to perform * @param runLoopMode The run loop mode in which to resolve * @param delegate The delegate to use for callbacks */ - (void)asyncPerformQuery: (OFDNSQuery *)query runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id <OFDNSResolverQueryDelegate>)delegate; /** * @brief Asynchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param delegate The delegate to use for callbacks */ - (void)asyncResolveAddressesForHost: (OFString *)host delegate: (id <OFDNSResolverHostDelegate>)delegate; /** * @brief Asynchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @param delegate The delegate to use for callbacks */ - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily delegate: (id <OFDNSResolverHostDelegate>)delegate; /** * @brief Asynchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @param runLoopMode The run loop mode in which to resolve * @param delegate The delegate to use for callbacks */ - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id <OFDNSResolverHostDelegate>)delegate; /** * @brief Synchronously resolves the specified host to socket addresses. * * @param host The host to resolve * @param addressFamily The desired socket address family * @return OFData containing several OFSocketAddress */ - (OFData *)resolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily; /** * @brief Closes all sockets and cancels all ongoing queries. */ - (void)close; @end OF_ASSUME_NONNULL_END |
Modified src/OFDNSResolver.m from [9c1e2cde9e] to [9a8423f14c].
︙ | ︙ | |||
42 43 44 45 46 47 48 | #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #ifndef SOCK_DNS # define SOCK_DNS 0 #endif | | | < | < | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #ifndef SOCK_DNS # define SOCK_DNS 0 #endif static const size_t bufferLength = OFDNSResolverBufferLength; static const size_t maxDNSResponseLength = 65536; /* * RFC 1035 doesn't specify if pointers to pointers are allowed, and if so how * many. Since it's unspecified, we have to assume that it might happen, but we * also want to limit it to avoid DoS. Limiting it to 16 levels of pointers and * immediately rejecting pointers to itself seems like a fair balance. */ static const uint_fast8_t maxAllowedPointers = 16; @interface OFDNSResolver () <OFUDPSocketDelegate, OFTCPSocketDelegate> - (void)of_contextTimedOut: (OFDNSResolverContext *)context; @end OF_DIRECT_MEMBERS @interface OFDNSResolverContext: OFObject { @public OFDNSQuery *_query; OFNumber *_ID; OFDNSResolverSettings *_settings; size_t _nameServersIndex; unsigned int _attempt; id <OFDNSResolverQueryDelegate> _delegate; OFData *_queryData; OFSocketAddress _usedNameServer; OFTCPSocket *_TCPSocket; OFMutableData *_TCPQueryData; void *_TCPBuffer; size_t _responseLength; OFTimer *_cancelTimer; } |
︙ | ︙ | |||
164 165 166 167 168 169 170 | [components addObject: component]; } while (componentLength > 0); return [components componentsJoinedByString: @"."]; } static OF_KINDOF(OFDNSResourceRecord *) | | | | | | | | | | | | | | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | [components addObject: component]; } while (componentLength > 0); return [components componentsJoinedByString: @"."]; } static OF_KINDOF(OFDNSResourceRecord *) parseResourceRecord(OFString *name, OFDNSClass DNSClass, OFDNSRecordType recordType, uint32_t TTL, const unsigned char *buffer, size_t length, size_t i, uint16_t dataLength) { if (recordType == OFDNSRecordTypeA && DNSClass == OFDNSClassIN) { OFSocketAddress address; if (dataLength != 4) @throw [OFInvalidServerReplyException exception]; memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPv4; address.length = sizeof(address.sockaddr.in); address.sockaddr.in.sin_family = AF_INET; memcpy(&address.sockaddr.in.sin_addr.s_addr, buffer + i, 4); return [[[OFADNSResourceRecord alloc] initWithName: name address: &address TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeNS) { size_t j = i; OFString *authoritativeHost = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFNSDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass authoritativeHost: authoritativeHost TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeCNAME) { size_t j = i; OFString *alias = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFCNAMEDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass alias: alias TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeSOA) { size_t j = i; OFString *primaryNameServer = parseName(buffer, length, &j, maxAllowedPointers); OFString *responsiblePerson; uint32_t serialNumber, refreshInterval, retryInterval; uint32_t expirationInterval, minTTL; if (j > i + dataLength) @throw [OFInvalidServerReplyException exception]; responsiblePerson = parseName(buffer, length, &j, maxAllowedPointers); if (dataLength - (j - i) != 20) @throw [OFInvalidServerReplyException exception]; serialNumber = (buffer[j] << 24) | (buffer[j + 1] << 16) | (buffer[j + 2] << 8) | buffer[j + 3]; refreshInterval = (buffer[j + 4] << 24) | |
︙ | ︙ | |||
252 253 254 255 256 257 258 | responsiblePerson: responsiblePerson serialNumber: serialNumber refreshInterval: refreshInterval retryInterval: retryInterval expirationInterval: expirationInterval minTTL: minTTL TTL: TTL] autorelease]; | | | | | | | | 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | responsiblePerson: responsiblePerson serialNumber: serialNumber refreshInterval: refreshInterval retryInterval: retryInterval expirationInterval: expirationInterval minTTL: minTTL TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypePTR) { size_t j = i; OFString *domainName = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFPTRDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass domainName: domainName TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeHINFO) { size_t j = i; OFString *CPU = parseString(buffer, length, &j); OFString *OS; if (j > i + dataLength) @throw [OFInvalidServerReplyException exception]; OS = parseString(buffer, length, &j); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFHINFODNSResourceRecord alloc] initWithName: name DNSClass: DNSClass CPU: CPU OS: OS TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeMX) { uint16_t preference; size_t j; OFString *mailExchange; if (dataLength < 2) @throw [OFInvalidServerReplyException exception]; preference = (buffer[i] << 8) | buffer[i + 1]; j = i + 2; mailExchange = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFMXDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass preference: preference mailExchange: mailExchange TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeTXT) { OFMutableArray *textStrings = [OFMutableArray array]; while (dataLength > 0) { uint_fast8_t stringLength = buffer[i++]; dataLength--; if (stringLength > dataLength) |
︙ | ︙ | |||
333 334 335 336 337 338 339 | [textStrings makeImmutable]; return [[[OFTXTDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass textStrings: textStrings TTL: TTL] autorelease]; | | | | | | | | | | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | [textStrings makeImmutable]; return [[[OFTXTDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass textStrings: textStrings TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeRP) { size_t j = i; OFString *mailbox = parseName(buffer, length, &j, maxAllowedPointers); OFString *TXTDomainName; if (j > i + dataLength) @throw [OFInvalidServerReplyException exception]; TXTDomainName = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFRPDNSResourceRecord alloc] initWithName: name DNSClass: DNSClass mailbox: mailbox TXTDomainName: TXTDomainName TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeAAAA && DNSClass == OFDNSClassIN) { OFSocketAddress address; if (dataLength != 16) @throw [OFInvalidServerReplyException exception]; memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPv6; address.length = sizeof(address.sockaddr.in6); #ifdef AF_INET6 address.sockaddr.in6.sin6_family = AF_INET6; #else address.sockaddr.in6.sin6_family = AF_UNSPEC; #endif memcpy(address.sockaddr.in6.sin6_addr.s6_addr, buffer + i, 16); return [[[OFAAAADNSResourceRecord alloc] initWithName: name address: &address TTL: TTL] autorelease]; } else if (recordType == OFDNSRecordTypeSRV && DNSClass == OFDNSClassIN) { uint16_t priority, weight, port; size_t j; OFString *target; if (dataLength < 6) @throw [OFInvalidServerReplyException exception]; priority = (buffer[i] << 8) | buffer[i + 1]; weight = (buffer[i + 2] << 8) | buffer[i + 3]; port = (buffer[i + 4] << 8) | buffer[i + 5]; j = i + 6; target = parseName(buffer, length, &j, maxAllowedPointers); if (j != i + dataLength) @throw [OFInvalidServerReplyException exception]; return [[[OFSRVDNSResourceRecord alloc] initWithName: name priority: priority |
︙ | ︙ | |||
420 421 422 423 424 425 426 | { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; OFEnumerator OF_GENERIC(OFMutableArray *) *objectEnumerator; OFMutableArray *array; for (uint_fast16_t j = 0; j < count; j++) { OFString *name = parseName(buffer, length, i, | | | | | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | { OFMutableDictionary *ret = [OFMutableDictionary dictionary]; OFEnumerator OF_GENERIC(OFMutableArray *) *objectEnumerator; OFMutableArray *array; for (uint_fast16_t j = 0; j < count; j++) { OFString *name = parseName(buffer, length, i, maxAllowedPointers); OFDNSClass DNSClass; OFDNSRecordType recordType; uint32_t TTL; uint16_t dataLength; OFDNSResourceRecord *record; if (*i + 10 > length) @throw [OFTruncatedDataException exception]; |
︙ | ︙ | |||
449 450 451 452 453 454 455 | buffer, length, *i, dataLength); *i += dataLength; array = [ret objectForKey: name]; if (array == nil) { array = [OFMutableArray array]; | | < | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | buffer, length, *i, dataLength); *i += dataLength; array = [ret objectForKey: name]; if (array == nil) { array = [OFMutableArray array]; [ret setObject: array forKey: name]; } [array addObject: record]; } objectEnumerator = [ret objectEnumerator]; while ((array = [objectEnumerator nextObject]) != nil) |
︙ | ︙ | |||
487 488 489 490 491 492 493 | _settings = [settings copy]; _delegate = [delegate retain]; queryData = [OFMutableData dataWithCapacity: 512]; /* Header */ | | | < < | | < < | | < < | 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | _settings = [settings copy]; _delegate = [delegate retain]; queryData = [OFMutableData dataWithCapacity: 512]; /* Header */ tmp = OFToBigEndian16(_ID.unsignedShortValue); [queryData addItems: &tmp count: 2]; /* RD */ tmp = OFToBigEndian16(1u << 8); [queryData addItems: &tmp count: 2]; /* QDCOUNT */ tmp = OFToBigEndian16(1); [queryData addItems: &tmp count: 2]; /* ANCOUNT, NSCOUNT and ARCOUNT */ [queryData increaseCountBy: 6]; /* Question */ /* QNAME */ for (OFString *component in |
︙ | ︙ | |||
522 523 524 525 526 527 528 | length8 = (uint8_t)length; [queryData addItem: &length8]; [queryData addItems: component.UTF8String count: length]; } /* QTYPE */ | | | < < | | < < | 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | length8 = (uint8_t)length; [queryData addItem: &length8]; [queryData addItems: component.UTF8String count: length]; } /* QTYPE */ tmp = OFToBigEndian16(_query.recordType); [queryData addItems: &tmp count: 2]; /* QCLASS */ tmp = OFToBigEndian16(_query.DNSClass); [queryData addItems: &tmp count: 2]; [queryData makeImmutable]; _queryData = [queryData copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; |
︙ | ︙ | |||
553 554 555 556 557 558 559 | [_query release]; [_ID release]; [_settings release]; [_delegate release]; [_queryData release]; [_TCPSocket release]; [_TCPQueryData release]; | | | | 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | [_query release]; [_ID release]; [_settings release]; [_delegate release]; [_queryData release]; [_TCPSocket release]; [_TCPQueryData release]; OFFreeMemory(_TCPBuffer); [_cancelTimer release]; [super dealloc]; } @end @implementation OFDNSResolver #ifdef OF_AMIGAOS + (void)initialize { if (self != [OFDNSResolver class]) return; if (!OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } #endif + (instancetype)resolver { |
︙ | ︙ | |||
654 655 656 657 658 659 660 | - (void)setSearchDomains: (OFArray *)searchDomains { OFArray *old = _settings->_searchDomains; _settings->_searchDomains = [searchDomains copy]; [old release]; } | | | | 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | - (void)setSearchDomains: (OFArray *)searchDomains { OFArray *old = _settings->_searchDomains; _settings->_searchDomains = [searchDomains copy]; [old release]; } - (OFTimeInterval)timeout { return _settings->_timeout; } - (void)setTimeout: (OFTimeInterval)timeout { _settings->_timeout = timeout; } - (unsigned int)maxAttempts { return _settings->_maxAttempts; |
︙ | ︙ | |||
696 697 698 699 700 701 702 | } - (void)setUsesTCP: (bool)usesTCP { _settings->_usesTCP = usesTCP; } | | | | | < | | < | | | | | | | | | | | | | < | | < | < | < | < | | | 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | } - (void)setUsesTCP: (bool)usesTCP { _settings->_usesTCP = usesTCP; } - (OFTimeInterval)configReloadInterval { return _settings->_configReloadInterval; } - (void)setConfigReloadInterval: (OFTimeInterval)configReloadInterval { _settings->_configReloadInterval = configReloadInterval; } - (void)of_sendQueryForContext: (OFDNSResolverContext *)context runLoopMode: (OFRunLoopMode)runLoopMode { OFUDPSocket *sock; OFString *nameServer; [_queries setObject: context forKey: context->_ID]; [context->_cancelTimer invalidate]; [context->_cancelTimer release]; context->_cancelTimer = nil; context->_cancelTimer = [[OFTimer alloc] initWithFireDate: [OFDate dateWithTimeIntervalSinceNow: context->_settings->_timeout] interval: context->_settings->_timeout target: self selector: @selector(of_contextTimedOut:) object: context repeats: false]; [[OFRunLoop currentRunLoop] addTimer: context->_cancelTimer forMode: runLoopMode]; nameServer = [context->_settings->_nameServers objectAtIndex: context->_nameServersIndex]; if (context->_settings->_usesTCP) { OFEnsure(context->_TCPSocket == nil); context->_TCPSocket = [[OFTCPSocket alloc] init]; [_TCPQueries setObject: context forKey: context->_TCPSocket]; context->_TCPSocket.delegate = self; [context->_TCPSocket asyncConnectToHost: nameServer port: 53 runLoopMode: runLoopMode]; return; } context->_usedNameServer = OFSocketAddressParseIP(nameServer, 53); switch (context->_usedNameServer.family) { #ifdef OF_HAVE_IPV6 case OFSocketAddressFamilyIPv6: if (_IPv6Socket == nil) { OFSocketAddress address = OFSocketAddressParseIPv6(@"::", 0); _IPv6Socket = [[OFUDPSocket alloc] init]; [_IPv6Socket of_bindToAddress: &address extraType: SOCK_DNS]; _IPv6Socket.canBlock = false; _IPv6Socket.delegate = self; } sock = _IPv6Socket; break; #endif case OFSocketAddressFamilyIPv4: if (_IPv4Socket == nil) { OFSocketAddress address = OFSocketAddressParseIPv4(@"0.0.0.0", 0); _IPv4Socket = [[OFUDPSocket alloc] init]; [_IPv4Socket of_bindToAddress: &address extraType: SOCK_DNS]; _IPv4Socket.canBlock = false; _IPv4Socket.delegate = self; } sock = _IPv4Socket; break; default: @throw [OFInvalidArgumentException exception]; } [sock asyncSendData: context->_queryData receiver: &context->_usedNameServer runLoopMode: runLoopMode]; [sock asyncReceiveIntoBuffer: _buffer length: bufferLength runLoopMode: runLoopMode]; } - (void)asyncPerformQuery: (OFDNSQuery *)query delegate: (id <OFDNSResolverQueryDelegate>)delegate { [self asyncPerformQuery: query runLoopMode: OFDefaultRunLoopMode delegate: delegate]; } - (void)asyncPerformQuery: (OFDNSQuery *)query runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id <OFDNSResolverQueryDelegate>)delegate { void *pool = objc_autoreleasePoolPush(); OFNumber *ID; OFDNSResolverContext *context; /* Random, unused ID */ do { ID = [OFNumber numberWithUnsignedShort: OFRandom16()]; } while ([_queries objectForKey: ID] != nil); if (query.domainName.UTF8StringLength > 253) @throw [OFOutOfRangeException exception]; if (_settings->_nameServers.count == 0) { id exception = [OFDNSQueryFailedException exceptionWithQuery: query errorCode: OFDNSResolverErrorCodeNoNameServer]; [delegate resolver: self didPerformQuery: query response: nil exception: exception]; return; } context = [[[OFDNSResolverContext alloc] initWithQuery: query ID: ID settings: _settings delegate: delegate] autorelease]; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } - (void)of_contextTimedOut: (OFDNSResolverContext *)context { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; OFDNSQueryFailedException *exception; if (context->_TCPSocket != nil) { context->_TCPSocket.delegate = nil; [context->_TCPSocket cancelAsyncRequests]; [_TCPQueries removeObjectForKey: context->_TCPSocket]; [context->_TCPSocket release]; context->_TCPSocket = nil; context->_responseLength = 0; } if (context->_nameServersIndex + 1 < context->_settings->_nameServers.count) { context->_nameServersIndex++; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return; } if (++context->_attempt < context->_settings->_maxAttempts) { context->_nameServersIndex = 0; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return; } context = [[context retain] autorelease]; [_queries removeObjectForKey: context->_ID]; /* * Cancel any pending queries, to avoid a send being still pending and * trying to access the query once it no longer exists. */ [_IPv4Socket cancelAsyncRequests]; [_IPv4Socket asyncReceiveIntoBuffer: _buffer length: bufferLength]; #ifdef OF_HAVE_IPV6 [_IPv6Socket cancelAsyncRequests]; [_IPv6Socket asyncReceiveIntoBuffer: _buffer length: bufferLength]; #endif exception = [OFDNSQueryFailedException exceptionWithQuery: context->_query errorCode: OFDNSResolverErrorCodeTimeout]; [context->_delegate resolver: self didPerformQuery: context->_query response: nil exception: exception]; } - (bool)of_handleResponseBuffer: (unsigned char *)buffer length: (size_t)length sender: (const OFSocketAddress *)sender { OFDictionary *answerRecords = nil, *authorityRecords = nil; OFDictionary *additionalRecords = nil; OFDNSResponse *response = nil; id exception = nil; OFNumber *ID; OFDNSResolverContext *context; |
︙ | ︙ | |||
917 918 919 920 921 922 923 | if (context == nil) return true; if (context->_TCPSocket != nil) { if ([_TCPQueries objectForKey: context->_TCPSocket] != context) return true; | | | | 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 | if (context == nil) return true; if (context->_TCPSocket != nil) { if ([_TCPQueries objectForKey: context->_TCPSocket] != context) return true; } else if (!OFSocketAddressEqual(sender, &context->_usedNameServer)) return true; [context->_cancelTimer invalidate]; [context->_cancelTimer release]; context->_cancelTimer = nil; [_queries removeObjectForKey: ID]; @try { OFDNSResolverErrorCode errorCode = 0; bool tryNextNameServer = false; const unsigned char *queryDataBuffer; size_t i; uint16_t numQuestions, numAnswers, numAuthorityRecords; uint16_t numAdditionalRecords; if (length < 12) |
︙ | ︙ | |||
952 953 954 955 956 957 958 | /* Opcode */ if ((buffer[2] & 0x78) != (queryDataBuffer[2] & 0x78)) @throw [OFInvalidServerReplyException exception]; /* TC */ if (buffer[2] & 0x02) { | | | | | | | | | | | | 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | /* Opcode */ if ((buffer[2] & 0x78) != (queryDataBuffer[2] & 0x78)) @throw [OFInvalidServerReplyException exception]; /* TC */ if (buffer[2] & 0x02) { OFRunLoopMode runLoopMode; if (context->_settings->_usesTCP) @throw [OFTruncatedDataException exception]; context->_settings->_usesTCP = true; runLoopMode = [OFRunLoop currentRunLoop].currentMode; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return false; } /* RCODE */ switch (buffer[3] & 0x0F) { case 0: break; case 1: errorCode = OFDNSResolverErrorCodeServerInvalidFormat; break; case 2: errorCode = OFDNSResolverErrorCodeServerFailure; tryNextNameServer = true; break; case 3: errorCode = OFDNSResolverErrorCodeServerNameError; break; case 4: errorCode = OFDNSResolverErrorCodeServerNotImplemented; tryNextNameServer = true; break; case 5: errorCode = OFDNSResolverErrorCodeServerRefused; tryNextNameServer = true; break; default: errorCode = OFDNSResolverErrorCodeUnknown; tryNextNameServer = true; break; } if (tryNextNameServer) { if (context->_nameServersIndex + 1 < context->_settings->_nameServers.count) { OFRunLoopMode runLoopMode = [OFRunLoop currentRunLoop].currentMode; context->_nameServersIndex++; [self of_sendQueryForContext: context runLoopMode: runLoopMode]; return false; } } if (buffer[3] & 0x0F) @throw [OFDNSQueryFailedException exceptionWithQuery: context->_query errorCode: errorCode]; numQuestions = (buffer[4] << 8) | buffer[5]; numAnswers = (buffer[6] << 8) | buffer[7]; numAuthorityRecords = (buffer[8] << 8) | buffer[9]; numAdditionalRecords = (buffer[10] << 8) | buffer[11]; i = 12; /* * Skip over the questions - we use the ID to identify the * query. * * TODO: Compare to our query, just in case? */ for (uint_fast16_t j = 0; j < numQuestions; j++) { parseName(buffer, length, &i, maxAllowedPointers); i += 4; } answerRecords = parseSection(buffer, length, &i, numAnswers); authorityRecords = parseSection(buffer, length, &i, numAuthorityRecords); additionalRecords = parseSection(buffer, length, &i, |
︙ | ︙ | |||
1057 1058 1059 1060 1061 1062 1063 | return false; } - (bool)socket: (OFDatagramSocket *)sock didReceiveIntoBuffer: (void *)buffer length: (size_t)length | | | | 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 | return false; } - (bool)socket: (OFDatagramSocket *)sock didReceiveIntoBuffer: (void *)buffer length: (size_t)length sender: (const OFSocketAddress *)sender exception: (id)exception { if (exception != nil) return true; return [self of_handleResponseBuffer: buffer length: length sender: sender]; } - (void)socket: (OFTCPSocket *)sock didConnectToHost: (OFString *)host port: (uint16_t)port exception: (id)exception { OFDNSResolverContext *context = [_TCPQueries objectForKey: sock]; OFEnsure(context != nil); if (exception != nil) { /* * TODO: Handle error immediately instead of waiting for the * timer to try the next nameserver or to retry. */ [_TCPQueries removeObjectForKey: context->_TCPSocket]; |
︙ | ︙ | |||
1099 1100 1101 1102 1103 1104 1105 | if (queryDataCount > UINT16_MAX) @throw [OFOutOfRangeException exception]; context->_TCPQueryData = [[OFMutableData alloc] initWithCapacity: queryDataCount + 2]; | | | < | | | < | | | | < < | | | | | | | | 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 | if (queryDataCount > UINT16_MAX) @throw [OFOutOfRangeException exception]; context->_TCPQueryData = [[OFMutableData alloc] initWithCapacity: queryDataCount + 2]; tmp = OFToBigEndian16(queryDataCount); [context->_TCPQueryData addItems: &tmp count: sizeof(tmp)]; [context->_TCPQueryData addItems: context->_queryData.items count: queryDataCount]; } [sock asyncWriteData: context->_TCPQueryData]; } - (OFData *)stream: (OFStream *)stream didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { OFTCPSocket *sock = (OFTCPSocket *)stream; OFDNSResolverContext *context = [_TCPQueries objectForKey: sock]; OFEnsure(context != nil); if (exception != nil) { /* * TODO: Handle error immediately instead of waiting for the * timer to try the next nameserver or to retry. */ [_TCPQueries removeObjectForKey: context->_TCPSocket]; [context->_TCPSocket release]; context->_TCPSocket = nil; context->_responseLength = 0; return nil; } if (context->_TCPBuffer == nil) context->_TCPBuffer = OFAllocMemory(maxDNSResponseLength, 1); [sock asyncReadIntoBuffer: context->_TCPBuffer exactLength: 2]; return nil; } - (bool)stream: (OFStream *)stream didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { OFTCPSocket *sock = (OFTCPSocket *)stream; OFDNSResolverContext *context = [_TCPQueries objectForKey: sock]; OFEnsure(context != nil); if (exception != nil) { /* * TODO: Handle error immediately instead of waiting for the * timer to try the next nameserver or to retry. */ goto done; } if (context->_responseLength == 0) { unsigned char *ucBuffer = buffer; OFEnsure(length == 2); context->_responseLength = (ucBuffer[0] << 8) | ucBuffer[1]; if (context->_responseLength > maxDNSResponseLength) @throw [OFOutOfRangeException exception]; if (context->_responseLength == 0) goto done; [sock asyncReadIntoBuffer: context->_TCPBuffer exactLength: context->_responseLength]; return false; } if (length != context->_responseLength) /* * The connection was closed before we received the entire * response. */ goto done; [self of_handleResponseBuffer: buffer length: length sender: NULL]; done: [_TCPQueries removeObjectForKey: context->_TCPSocket]; [context->_TCPSocket release]; context->_TCPSocket = nil; context->_responseLength = 0; return false; } - (void)asyncResolveAddressesForHost: (OFString *)host delegate: (id <OFDNSResolverHostDelegate>)delegate { [self asyncResolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny runLoopMode: OFDefaultRunLoopMode delegate: delegate]; } - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily delegate: (id <OFDNSResolverHostDelegate>)delegate { [self asyncResolveAddressesForHost: host addressFamily: addressFamily runLoopMode: OFDefaultRunLoopMode delegate: delegate]; } - (void)asyncResolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id <OFDNSResolverHostDelegate>)delegate { void *pool = objc_autoreleasePoolPush(); OFHostAddressResolver *resolver = [[[OFHostAddressResolver alloc] initWithHost: host addressFamily: addressFamily resolver: self settings: _settings runLoopMode: runLoopMode delegate: delegate] autorelease]; [resolver asyncResolve]; objc_autoreleasePoolPop(pool); } - (OFData *)resolveAddressesForHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily { void *pool = objc_autoreleasePoolPush(); OFHostAddressResolver *resolver = [[[OFHostAddressResolver alloc] initWithHost: host addressFamily: addressFamily resolver: self settings: _settings |
︙ | ︙ | |||
1275 1276 1277 1278 1279 1280 1281 | enumerator = [_queries objectEnumerator]; while ((context = [enumerator nextObject]) != nil) { OFDNSQueryFailedException *exception; exception = [OFDNSQueryFailedException exceptionWithQuery: context->_query | | | 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 | enumerator = [_queries objectEnumerator]; while ((context = [enumerator nextObject]) != nil) { OFDNSQueryFailedException *exception; exception = [OFDNSQueryFailedException exceptionWithQuery: context->_query errorCode: OFDNSResolverErrorCodeCanceled]; [context->_delegate resolver: self didPerformQuery: context->_query response: nil exception: exception]; } [_queries removeAllObjects]; objc_autoreleasePoolPop(pool); } @end |
Modified src/OFDNSResolverSettings.h from [f96b5d98db] to [e160ff7316].
︙ | ︙ | |||
25 26 27 28 29 30 31 | { @public OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *) *_staticHosts; OFArray OF_GENERIC(OFString *) *_nameServers; OFString *_Nullable _localDomain; OFArray OF_GENERIC(OFString *) *_searchDomains; | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | { @public OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC(OFString *) *) *_staticHosts; OFArray OF_GENERIC(OFString *) *_nameServers; OFString *_Nullable _localDomain; OFArray OF_GENERIC(OFString *) *_searchDomains; OFTimeInterval _timeout; unsigned int _maxAttempts, _minNumberOfDotsInAbsoluteName; bool _usesTCP; OFTimeInterval _configReloadInterval; @protected OFDate *_lastConfigReload; } - (void)reload; @end |
︙ | ︙ |
Modified src/OFDNSResolverSettings.m from [7a11cbe993] to [eb1fcb5845].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFDNSResolverSettings.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFFile.h" #import "OFLocale.h" #import "OFString.h" #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #import "OFDNSResolverSettings.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFFile.h" #import "OFLocale.h" #import "OFSocket+Private.h" #import "OFString.h" #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" |
︙ | ︙ | |||
49 50 51 52 53 54 55 | #ifdef OF_MORPHOS # include <proto/rexxsyslib.h> # include <rexx/errors.h> # include <rexx/storage.h> #endif | < < | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #ifdef OF_MORPHOS # include <proto/rexxsyslib.h> # include <rexx/errors.h> # include <rexx/storage.h> #endif #if defined(OF_HAIKU) # define HOSTS_PATH @"/system/settings/network/hosts" # define RESOLV_CONF_PATH @"/system/settings/network/resolv.conf" #elif defined(OF_AMIGAOS4) # define HOSTS_PATH @"DEVS:Internet/hosts" #elif defined(OF_AMIGAOS) # define HOSTS_PATH @"AmiTCP:db/hosts" |
︙ | ︙ | |||
72 73 74 75 76 77 78 | static OFString * domainFromHostname(OFString *hostname) { if (hostname == nil) return nil; @try { | | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | static OFString * domainFromHostname(OFString *hostname) { if (hostname == nil) return nil; @try { OFSocketAddressParseIP(hostname, 0); /* * If we are still here, the host name is a valid IP address. * We can't use that as local domain. */ return nil; } @catch (OFInvalidFormatException *e) { /* Not an IP address -> we can use it if it contains a dot. */ size_t pos = [hostname rangeOfString: @"."].location; if (pos == OFNotFound) return nil; return [hostname substringFromIndex: pos + 1]; } } #endif |
︙ | ︙ | |||
171 172 173 174 175 176 177 | static OFArray OF_GENERIC(OFString *) * parseNetStackArray(OFString *string) { if (![string hasPrefix: @"["] || ![string hasSuffix: @"]"]) return nil; | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | static OFArray OF_GENERIC(OFString *) * parseNetStackArray(OFString *string) { if (![string hasPrefix: @"["] || ![string hasSuffix: @"]"]) return nil; string = [string substringWithRange: OFRangeMake(1, string.length - 2)]; return [string componentsSeparatedByString: @"|"]; } #endif @implementation OFDNSResolverSettings - (void)dealloc |
︙ | ︙ | |||
249 250 251 252 253 254 255 | OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; OFMutableDictionary *staticHosts; OFFile *file; OFString *line; @try { | | < | | | | < | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; OFMutableDictionary *staticHosts; OFFile *file; OFString *line; @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } staticHosts = [OFMutableDictionary dictionary]; while ((line = [file readLine]) != nil) { OFArray *components, *hosts; size_t pos; OFString *address; pos = [line rangeOfString: @"#"].location; if (pos != OFNotFound) line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet options: OFStringSkipEmptyComponents]; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: OFRangeMake(1, components.count - 1)]; for (OFString *host in hosts) { OFMutableArray *addresses = [staticHosts objectForKey: host]; if (addresses == nil) { addresses = [OFMutableArray array]; [staticHosts setObject: addresses forKey: host]; } [addresses addObject: address]; } } for (OFMutableArray *addresses in [staticHosts objectEnumerator]) [addresses makeImmutable]; |
︙ | ︙ | |||
350 351 352 353 354 355 356 | OFCharacterSet *commentCharacters = [OFCharacterSet characterSetWithCharactersInString: @"#;"]; OFMutableArray *nameServers = [[_nameServers mutableCopy] autorelease]; OFFile *file; OFString *line; @try { | | < | | | | | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | OFCharacterSet *commentCharacters = [OFCharacterSet characterSetWithCharactersInString: @"#;"]; OFMutableArray *nameServers = [[_nameServers mutableCopy] autorelease]; OFFile *file; OFString *line; @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { objc_autoreleasePoolPop(pool); return; } if (nameServers == nil) nameServers = [OFMutableArray array]; while ((line = [file readLine]) != nil) { void *pool2 = objc_autoreleasePoolPush(); size_t pos; OFArray *components, *arguments; OFString *option; pos = [line indexOfCharacterFromSet: commentCharacters]; if (pos != OFNotFound) line = [line substringToIndex: pos]; components = [line componentsSeparatedByCharactersInSet: whitespaceCharacterSet options: OFStringSkipEmptyComponents]; if (components.count < 2) { objc_autoreleasePoolPop(pool2); continue; } option = components.firstObject; arguments = [components objectsInRange: OFRangeMake(1, components.count - 1)]; if ([option isEqual: @"nameserver"]) { if (arguments.count != 1) { objc_autoreleasePoolPop(pool2); continue; } [nameServers addObject: arguments.firstObject]; } else if ([option isEqual: @"domain"]) { if (arguments.count != 1) { objc_autoreleasePoolPop(pool2); continue; } [_localDomain release]; |
︙ | ︙ | |||
421 422 423 424 425 426 427 | } # endif #endif #ifdef OF_WINDOWS - (void)obtainWindowsSystemConfig { | | | 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | } # endif #endif #ifdef OF_WINDOWS - (void)obtainWindowsSystemConfig { OFStringEncoding encoding = [OFLocale encoding]; OFMutableArray *nameServers; /* * We need more space than FIXED_INFO in case we have more than one * name server, but we also want it to be properly aligned, meaning we * can't just get a buffer of bytes. Thus, we just get space for 8. */ FIXED_INFO fixedInfo[8]; |
︙ | ︙ | |||
480 481 482 483 484 485 486 | OFArray *hosts; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: | | | < | | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | OFArray *hosts; if (components.count < 2) continue; address = components.firstObject; hosts = [components objectsInRange: OFRangeMake(1, components.count - 1)]; for (OFString *host in hosts) { OFMutableArray *addresses = [staticHosts objectForKey: host]; if (addresses == nil) { addresses = [OFMutableArray array]; [staticHosts setObject: addresses forKey: host]; } [addresses addObject: address]; } } for (OFMutableArray *addresses in [staticHosts objectEnumerator]) [addresses makeImmutable]; [staticHosts makeImmutable]; _staticHosts = [staticHosts copy]; objc_autoreleasePoolPop(pool); } #endif #ifdef OF_AMIGAOS4 - (void)obtainAmigaOS4SystemConfig { OFMutableArray *nameServers = [OFMutableArray array]; OFStringEncoding encoding = [OFLocale encoding]; struct List *nameServerList = ObtainDomainNameServerList(); char buffer[MAXHOSTNAMELEN]; if (nameServerList == NULL) @throw [OFOutOfMemoryException exception]; @try { |
︙ | ︙ | |||
574 575 576 577 578 579 580 | * We're fine if this gets smaller in a future release (unlikely), as * long as two entries still fit. */ if (optLen < sizeof(buffer.entries)) return; for (uint_fast8_t i = 0; i < 2; i++) { | | | 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | * We're fine if this gets smaller in a future release (unlikely), as * long as two entries still fit. */ if (optLen < sizeof(buffer.entries)) return; for (uint_fast8_t i = 0; i < 2; i++) { uint32_t ip = OFFromBigEndian32(buffer.entries[i].ip.s_addr); if (ip == 0) continue; [nameServers addObject: [OFString stringWithFormat: @"%u.%u.%u.%u", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF]]; |
︙ | ︙ | |||
617 618 619 620 621 622 623 | #if defined(OF_WINDOWS) # ifdef OF_HAVE_FILES OFWindowsRegistryKey *key = [[OFWindowsRegistryKey localMachineKey] openSubkeyAtPath: @"SYSTEM\\CurrentControlSet\\Services\\" @"Tcpip\\Parameters" securityAndAccessRights: KEY_QUERY_VALUE]; | | | 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | #if defined(OF_WINDOWS) # ifdef OF_HAVE_FILES OFWindowsRegistryKey *key = [[OFWindowsRegistryKey localMachineKey] openSubkeyAtPath: @"SYSTEM\\CurrentControlSet\\Services\\" @"Tcpip\\Parameters" securityAndAccessRights: KEY_QUERY_VALUE]; path = [[[key stringForValueNamed: @"DataBasePath"] stringByAppendingPathComponent: @"hosts"] stringByExpandingWindowsEnvironmentStrings]; if (path != nil) [self parseHosts: path]; # endif |
︙ | ︙ |
Modified src/OFDNSResourceRecord.h from [cfe4c4fb24] to [684c620d59].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSocket.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFArray OF_GENERIC(ObjectType); @class OFData; /** * @brief The DNS class. */ typedef enum { /** IN */ OFDNSClassIN = 1, /** Any class. Only for queries. */ OFDNSClassAny = 255, } OFDNSClass; /** * @brief The type of a DNS resource record. */ typedef enum { /** A */ OFDNSRecordTypeA = 1, /** NS */ OFDNSRecordTypeNS = 2, /** CNAME */ OFDNSRecordTypeCNAME = 5, /** SOA */ OFDNSRecordTypeSOA = 6, /** PTR */ OFDNSRecordTypePTR = 12, /** HINFO */ OFDNSRecordTypeHINFO = 13, /** MX */ OFDNSRecordTypeMX = 15, /** TXT */ OFDNSRecordTypeTXT = 16, /** RP */ OFDNSRecordTypeRP = 17, /** AAAA */ OFDNSRecordTypeAAAA = 28, /** SRV */ OFDNSRecordTypeSRV = 33, /** All types. Only for queries. */ OFDNSRecordTypeAll = 255, } OFDNSRecordType; /** * @class OFDNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing a DNS resource record. */ @interface OFDNSResourceRecord: OFObject <OFCopying> { OFString *_name; OFDNSClass _DNSClass; OFDNSRecordType _recordType; uint32_t _TTL; OF_RESERVE_IVARS(OFDNSResourceRecord, 4) } /** * @brief The domain name to which the resource record belongs. */ @property (readonly, nonatomic) OFString *name; /** * @brief The DNS class. */ @property (readonly, nonatomic) OFDNSClass DNSClass; /** * @brief The resource record type code. */ @property (readonly, nonatomic) OFDNSRecordType recordType; /** * @brief The number of seconds after which the resource record should be * discarded from the cache. */ @property (readonly, nonatomic) uint32_t TTL; /** * @brief Initializes an already allocated OFDNSResourceRecord with the * specified name, class, type, data and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param recordType The type code for the resource record * @param TTL The time to live for the resource record * @return An initialized OFDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFADNSResourceRecord OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class representing an A DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFADNSResourceRecord: OFDNSResourceRecord { OFSocketAddress _address; } /** * @brief The IPv4 address of the resource record. */ @property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFADNSResourceRecord with the * specified name, class, address and time to live. * * @param name The name for the resource record * @param address The address for the resource record * @param TTL The time to live for the resource record * @return An initialized OFADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFAAAADNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * * @brief A class represenging a DNS resource record. */ OF_SUBCLASSING_RESTRICTED @interface OFAAAADNSResourceRecord: OFDNSResourceRecord { OFSocketAddress _address; } /** * @brief The IPv6 address of the resource record. */ @property (readonly, nonatomic) const OFSocketAddress *address; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFAAAADNSResourceRecord with the * specified name, class, address and time to live. * * @param name The name for the resource record * @param address The address for the resource record * @param TTL The time to live for the resource record * @return An initialized OFAAAADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFCNAMEDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h * |
︙ | ︙ | |||
201 202 203 204 205 206 207 | /** * @brief The alias of the resource record. */ @property (readonly, nonatomic) OFString *alias; - (instancetype)initWithName: (OFString *)name | | | | | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | /** * @brief The alias of the resource record. */ @property (readonly, nonatomic) OFString *alias; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFCNAMEDNSResourceRecord with the * specified name, class, alias and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param alias The alias for the resource record * @param TTL The time to live for the resource record * @return An initialized OFCNAMEDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass alias: (OFString *)alias TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFHINFODNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h |
︙ | ︙ | |||
244 245 246 247 248 249 250 | /** * @brief The OS of the host info of the resource record. */ @property (readonly, nonatomic) OFString *OS; - (instancetype)initWithName: (OFString *)name | | | | | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | /** * @brief The OS of the host info of the resource record. */ @property (readonly, nonatomic) OFString *OS; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFHINFODNSResourceRecord with the * specified name, class, domain name and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param CPU The CPU of the host info for the resource record * @param OS The OS of the host info for the resource record * @param TTL The time to live for the resource record * @return An initialized OFHINFODNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass CPU: (OFString *)CPU OS: (OFString *)OS TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFMXDNSResourceRecord \ |
︙ | ︙ | |||
290 291 292 293 294 295 296 | /** * @brief The mail exchange of the resource record. */ @property (readonly, nonatomic) OFString *mailExchange; - (instancetype)initWithName: (OFString *)name | | | | | 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | /** * @brief The mail exchange of the resource record. */ @property (readonly, nonatomic) OFString *mailExchange; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMXDNSResourceRecord with the * specified name, class, preference, mail exchange and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param preference The preference for the resource record * @param mailExchange The mail exchange for the resource record * @param TTL The time to live for the resource record * @return An initialized OFMXDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass preference: (uint16_t)preference mailExchange: (OFString *)mailExchange TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFNSDNSResourceRecord \ |
︙ | ︙ | |||
330 331 332 333 334 335 336 | /** * @brief The authoritative host of the resource record. */ @property (readonly, nonatomic) OFString *authoritativeHost; - (instancetype)initWithName: (OFString *)name | | | | | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | /** * @brief The authoritative host of the resource record. */ @property (readonly, nonatomic) OFString *authoritativeHost; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFNSDNSResourceRecord with the * specified name, class, authoritative host and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param authoritativeHost The authoritative host for the resource record * @param TTL The time to live for the resource record * @return An initialized OFNSDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass authoritativeHost: (OFString *)authoritativeHost TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFPTRDNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h |
︙ | ︙ | |||
368 369 370 371 372 373 374 | /** * @brief The domain name of the resource record. */ @property (readonly, nonatomic) OFString *domainName; - (instancetype)initWithName: (OFString *)name | | | | | 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | /** * @brief The domain name of the resource record. */ @property (readonly, nonatomic) OFString *domainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFPTRDNSResourceRecord with the * specified name, class, domain name and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param domainName The domain name for the resource record * @param TTL The time to live for the resource record * @return An initialized OFPTRDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass domainName: (OFString *)domainName TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFRPNSResourceRecord \ * OFDNSResourceRecord.h ObjFW/OFDNSResourceRecord.h |
︙ | ︙ | |||
412 413 414 415 416 417 418 | /** * @brief A domain name that contains a TXT resource record for the responsible * person of the resource record. */ @property (readonly, nonatomic) OFString *TXTDomainName; - (instancetype)initWithName: (OFString *)name | | | | | 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | /** * @brief A domain name that contains a TXT resource record for the responsible * person of the resource record. */ @property (readonly, nonatomic) OFString *TXTDomainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFRPDNSResourceRecord with the * specified name, class, alias and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param mailbox The mailbox of the responsible person of the resource record * @param TXTDomainName A domain name that contains a TXT resource record for * the responsible person of the resource record * @param TTL The time to live for the resource record * @return An initialized OFRPDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass mailbox: (OFString *)mailbox TXTDomainName: (OFString *)TXTDomainName TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end /** * @class OFSOADNSResourceRecord \ |
︙ | ︙ | |||
485 486 487 488 489 490 491 | /** * @brief The minimum TTL of the zone. */ @property (readonly, nonatomic) uint32_t minTTL; - (instancetype)initWithName: (OFString *)name | | | | | 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | /** * @brief The minimum TTL of the zone. */ @property (readonly, nonatomic) uint32_t minTTL; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSOADNSResourceRecord with the * specified name, class, text data and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param primaryNameServer The the primary name server for the zone * @param responsiblePerson The mailbox of the person responsible for the zone * @param serialNumber The serial number of the original copy of the zone * @param refreshInterval The refresh interval of the zone * @param retryInterval The retry interval of the zone * @param expirationInterval The expiration interval of the zone * @param minTTL The minimum TTL of the zone * @param TTL The time to live for the resource record * @return An initialized OFSOADNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass primaryNameServer: (OFString *)primaryNameServer responsiblePerson: (OFString *)responsiblePerson serialNumber: (uint32_t)serialNumber refreshInterval: (uint32_t)refreshInterval retryInterval: (uint32_t)retryInterval expirationInterval: (uint32_t)expirationInterval minTTL: (uint32_t)minTTL |
︙ | ︙ | |||
552 553 554 555 556 557 558 | /** * @brief The port on the target of the resource record. */ @property (readonly, nonatomic) uint16_t port; - (instancetype)initWithName: (OFString *)name | | | | 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | /** * @brief The port on the target of the resource record. */ @property (readonly, nonatomic) uint16_t port; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSRVDNSResourceRecord with the * specified name, class, preference, mail exchange and time to live. * * @param name The name for the resource record |
︙ | ︙ | |||
594 595 596 597 598 599 600 | /** * @brief The text of the resource record. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFData *) *textStrings; - (instancetype)initWithName: (OFString *)name | | | | > > > > > > | > > > > > > > | | > > > > > > | > > > > > > > | | 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | /** * @brief The text of the resource record. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFData *) *textStrings; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFTXTDNSResourceRecord with the * specified name, class, text data and time to live. * * @param name The name for the resource record * @param DNSClass The class code for the resource record * @param textStrings An array of text strings for the resource record * @param TTL The time to live for the resource record * @return An initialized OFTXTDNSResourceRecord */ - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings TTL: (uint32_t)TTL OF_DESIGNATED_INITIALIZER; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Returns the name for the specified OFDNSClass. * * @param DNSClass The OFDNSClass to return the name for * @return The name for the specified OFDNSClass */ extern OFString *_Nonnull OFDNSClassName(OFDNSClass DNSClass); /** * @brief Returns the name for the specified OFDNSRecordType. * * @param recordType The OFDNSRecordType to return the name for * @return The name for the specified OFDNSRecordType */ extern OFString *_Nonnull OFDNSRecordTypeName(OFDNSRecordType recordType); /** * @brief Parses the specified string as an @ref OFDNSClass. * * @param string The string to parse as an @ref OFDNSClass * @return The parsed OFDNSClass */ extern OFDNSClass OFDNSClassParseName(OFString *_Nonnull string); /** * @brief Parses the specified string as an @ref OFDNSRecordType. * * @param string The string to parse as an @ref OFDNSRecordType * @return The parsed OFDNSRecordType */ extern OFDNSRecordType OFDNSRecordTypeParseName(OFString *_Nonnull string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFDNSResourceRecord.m from [50a5f9e1de] to [4cd40cf93d].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFArray.h" #import "OFData.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" OFString * | | | | | | | | | | | | | | | | | > | | | | > | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #import "OFArray.h" #import "OFData.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" OFString * OFDNSClassName(OFDNSClass DNSClass) { switch (DNSClass) { case OFDNSClassIN: return @"IN"; case OFDNSClassAny: return @"any"; default: return [OFString stringWithFormat: @"%u", DNSClass]; } } OFString * OFDNSRecordTypeName(OFDNSRecordType recordType) { switch (recordType) { case OFDNSRecordTypeA: return @"A"; case OFDNSRecordTypeNS: return @"NS"; case OFDNSRecordTypeCNAME: return @"CNAME"; case OFDNSRecordTypeSOA: return @"SOA"; case OFDNSRecordTypePTR: return @"PTR"; case OFDNSRecordTypeHINFO: return @"HINFO"; case OFDNSRecordTypeMX: return @"MX"; case OFDNSRecordTypeTXT: return @"TXT"; case OFDNSRecordTypeRP: return @"RP"; case OFDNSRecordTypeAAAA: return @"AAAA"; case OFDNSRecordTypeSRV: return @"SRV"; case OFDNSRecordTypeAll: return @"all"; default: return [OFString stringWithFormat: @"%u", recordType]; } } OFDNSClass OFDNSClassParseName(OFString *string) { void *pool = objc_autoreleasePoolPush(); OFDNSClass DNSClass; string = string.uppercaseString; if ([string isEqual: @"IN"]) DNSClass = OFDNSClassIN; else { @try { DNSClass = (OFDNSClass) [string unsignedLongLongValueWithBase: 0]; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidArgumentException exception]; } } objc_autoreleasePoolPop(pool); return DNSClass; } OFDNSRecordType OFDNSRecordTypeParseName(OFString *string) { void *pool = objc_autoreleasePoolPush(); OFDNSRecordType recordType; string = string.uppercaseString; if ([string isEqual: @"A"]) recordType = OFDNSRecordTypeA; else if ([string isEqual: @"NS"]) recordType = OFDNSRecordTypeNS; else if ([string isEqual: @"CNAME"]) recordType = OFDNSRecordTypeCNAME; else if ([string isEqual: @"SOA"]) recordType = OFDNSRecordTypeSOA; else if ([string isEqual: @"PTR"]) recordType = OFDNSRecordTypePTR; else if ([string isEqual: @"HINFO"]) recordType = OFDNSRecordTypeHINFO; else if ([string isEqual: @"MX"]) recordType = OFDNSRecordTypeMX; else if ([string isEqual: @"TXT"]) recordType = OFDNSRecordTypeTXT; else if ([string isEqual: @"RP"]) recordType = OFDNSRecordTypeRP; else if ([string isEqual: @"AAAA"]) recordType = OFDNSRecordTypeAAAA; else if ([string isEqual: @"SRV"]) recordType = OFDNSRecordTypeSRV; else if ([string isEqual: @"ALL"]) recordType = OFDNSRecordTypeAll; else { @try { recordType = (OFDNSRecordType) [string unsignedLongLongValueWithBase: 0]; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidArgumentException exception]; } } objc_autoreleasePoolPop(pool); return recordType; } @implementation OFDNSResourceRecord @synthesize name = _name, DNSClass = _DNSClass, recordType = _recordType; @synthesize TTL = _TTL; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { self = [super init]; @try { _name = [name copy]; _DNSClass = DNSClass; |
︙ | ︙ | |||
177 178 179 180 181 182 183 | return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tType = %@\n" @"\tTTL = %" PRIu32 "\n" @">", | | | | | | | | | | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tType = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), OFDNSRecordTypeName(_recordType), _TTL]; } @end @implementation OFADNSResourceRecord - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeA TTL: TTL]; _address = *address; return self; } - (const OFSocketAddress *)address { return &_address; } - (bool)isEqual: (id)object { OFADNSResourceRecord *record; |
︙ | ︙ | |||
231 232 233 234 235 236 237 | if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; | | | | | | | | | | | | < | | | | | | | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (!OFSocketAddressEqual(&record->_address, &_address)) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, OFSocketAddressHash(&_address)); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tAddress = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFSocketAddressString(&_address), _TTL]; } @end @implementation OFAAAADNSResourceRecord - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name address: (const OFSocketAddress *)address TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeAAAA TTL: TTL]; _address = *address; return self; } - (const OFSocketAddress *)address { return &_address; } - (bool)isEqual: (id)object { OFAAAADNSResourceRecord *record; |
︙ | ︙ | |||
317 318 319 320 321 322 323 | if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; | | | | | | | | | | | | < | | | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | if (record->_DNSClass != _DNSClass) return false; if (record->_recordType != _recordType) return false; if (!OFSocketAddressEqual(&record->_address, &_address)) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, OFSocketAddressHash(&_address)); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tAddress = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFSocketAddressString(&_address), _TTL]; } @end @implementation OFCNAMEDNSResourceRecord @synthesize alias = _alias; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass alias: (OFString *)alias TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeCNAME TTL: TTL]; @try { _alias = [alias copy]; } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
421 422 423 424 425 426 427 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | < | | | | | 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, _alias.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tAlias = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _alias, _TTL]; } @end @implementation OFHINFODNSResourceRecord @synthesize CPU = _CPU, OS = _OS; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass CPU: (OFString *)CPU OS: (OFString *)OS TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeHINFO TTL: TTL]; @try { _CPU = [CPU copy]; _OS = [OS copy]; } @catch (id e) { [self release]; |
︙ | ︙ | |||
524 525 526 527 528 529 530 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | < | | | | | 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, _CPU.hash); OFHashAddHash(&hash, _OS.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tCPU = %@\n" @"\tOS = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _CPU, _OS, _TTL]; } @end @implementation OFMXDNSResourceRecord @synthesize preference = _preference, mailExchange = _mailExchange; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass preference: (uint16_t)preference mailExchange: (OFString *)mailExchange TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeMX TTL: TTL]; @try { _preference = preference; _mailExchange = [mailExchange copy]; } @catch (id e) { [self release]; |
︙ | ︙ | |||
629 630 631 632 633 634 635 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | | | | | 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAdd(&hash, _preference >> 8); OFHashAdd(&hash, _preference); OFHashAddHash(&hash, _mailExchange.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tPreference = %" PRIu16 "\n" @"\tMail Exchange = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _preference, _mailExchange, _TTL]; } @end @implementation OFNSDNSResourceRecord @synthesize authoritativeHost = _authoritativeHost; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass authoritativeHost: (OFString *)authoritativeHost TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeNS TTL: TTL]; @try { _authoritativeHost = [authoritativeHost copy]; } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
730 731 732 733 734 735 736 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | | 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, _authoritativeHost.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tAuthoritative Host = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _authoritativeHost, _TTL]; } @end @implementation OFPTRDNSResourceRecord @synthesize domainName = _domainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass domainName: (OFString *)domainName TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypePTR TTL: TTL]; @try { _domainName = [domainName copy]; } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
828 829 830 831 832 833 834 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | | | 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, _domainName.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tDomain Name = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _domainName, _TTL]; } @end @implementation OFRPDNSResourceRecord @synthesize mailbox = _mailbox, TXTDomainName = _TXTDomainName; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass mailbox: (OFString *)mailbox TXTDomainName: (OFString *)TXTDomainName TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeRP TTL: TTL]; @try { _mailbox = [mailbox copy]; _TXTDomainName = [TXTDomainName copy]; } @catch (id e) { [self release]; |
︙ | ︙ | |||
933 934 935 936 937 938 939 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | | | 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, _mailbox.hash); OFHashAddHash(&hash, _TXTDomainName.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tMailbox = %@\n" @"\tTXT Domain Name = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _mailbox, _TXTDomainName, _TTL]; } @end @implementation OFSOADNSResourceRecord @synthesize primaryNameServer = _primaryNameServer; @synthesize responsiblePerson = _responsiblePerson; @synthesize serialNumber = _serialNumber, refreshInterval = _refreshInterval; @synthesize retryInterval = _retryInterval; @synthesize expirationInterval = _expirationInterval, minTTL = _minTTL; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass primaryNameServer: (OFString *)primaryNameServer responsiblePerson: (OFString *)responsiblePerson serialNumber: (uint32_t)serialNumber refreshInterval: (uint32_t)refreshInterval retryInterval: (uint32_t)retryInterval expirationInterval: (uint32_t)expirationInterval minTTL: (uint32_t)minTTL TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeSOA TTL: TTL]; @try { _primaryNameServer = [primaryNameServer copy]; _responsiblePerson = [responsiblePerson copy]; _serialNumber = serialNumber; _refreshInterval = refreshInterval; |
︙ | ︙ | |||
1069 1070 1071 1072 1073 1074 1075 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, _primaryNameServer.hash); OFHashAddHash(&hash, _responsiblePerson.hash); OFHashAdd(&hash, _serialNumber >> 24); OFHashAdd(&hash, _serialNumber >> 16); OFHashAdd(&hash, _serialNumber >> 8); OFHashAdd(&hash, _serialNumber); OFHashAdd(&hash, _refreshInterval >> 24); OFHashAdd(&hash, _refreshInterval >> 16); OFHashAdd(&hash, _refreshInterval >> 8); OFHashAdd(&hash, _refreshInterval); OFHashAdd(&hash, _retryInterval >> 24); OFHashAdd(&hash, _retryInterval >> 16); OFHashAdd(&hash, _retryInterval >> 8); OFHashAdd(&hash, _retryInterval); OFHashAdd(&hash, _expirationInterval >> 24); OFHashAdd(&hash, _expirationInterval >> 16); OFHashAdd(&hash, _expirationInterval >> 8); OFHashAdd(&hash, _expirationInterval); OFHashAdd(&hash, _minTTL >> 24); OFHashAdd(&hash, _minTTL >> 16); OFHashAdd(&hash, _minTTL >> 8); OFHashAdd(&hash, _minTTL); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tPrimary Name Server = %@\n" @"\tResponsible Person = %@\n" @"\tSerial Number = %" PRIu32 "\n" @"\tRefresh Interval = %" PRIu32 "\n" @"\tRetry Interval = %" PRIu32 "\n" @"\tExpiration Interval = %" PRIu32 "\n" @"\tMinimum TTL = %" PRIu32 "\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), _primaryNameServer, _responsiblePerson, _serialNumber, _refreshInterval, _retryInterval, _expirationInterval, _minTTL, _TTL]; } @end @implementation OFSRVDNSResourceRecord @synthesize priority = _priority, weight = _weight, target = _target; @synthesize port = _port; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name priority: (uint16_t)priority weight: (uint16_t)weight target: (OFString *)target port: (uint16_t)port TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeSRV TTL: TTL]; @try { _priority = priority; _weight = weight; _target = [target copy]; _port = port; |
︙ | ︙ | |||
1210 1211 1212 1213 1214 1215 1216 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | | | 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAdd(&hash, _priority >> 8); OFHashAdd(&hash, _priority); OFHashAdd(&hash, _weight >> 8); OFHashAdd(&hash, _weight); OFHashAddHash(&hash, _target.hash); OFHashAdd(&hash, _port >> 8); OFHashAdd(&hash, _port); OFHashFinalize(&hash); return hash; } - (OFString *)description { return [OFString stringWithFormat: |
︙ | ︙ | |||
1251 1252 1253 1254 1255 1256 1257 | } @end @implementation OFTXTDNSResourceRecord @synthesize textStrings = _textStrings; - (instancetype)initWithName: (OFString *)name | | | | | | 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 | } @end @implementation OFTXTDNSResourceRecord @synthesize textStrings = _textStrings; - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass recordType: (OFDNSRecordType)recordType TTL: (uint32_t)TTL { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name DNSClass: (OFDNSClass)DNSClass textStrings: (OFArray OF_GENERIC(OFData *) *)textStrings TTL: (uint32_t)TTL { self = [super initWithName: name DNSClass: DNSClass recordType: OFDNSRecordTypeTXT TTL: TTL]; @try { _textStrings = [textStrings copy]; } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
1315 1316 1317 1318 1319 1320 1321 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAdd(&hash, _DNSClass >> 8); OFHashAdd(&hash, _DNSClass); OFHashAdd(&hash, _recordType >> 8); OFHashAdd(&hash, _recordType); OFHashAddHash(&hash, _textStrings.hash); OFHashFinalize(&hash); return hash; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
1371 1372 1373 1374 1375 1376 1377 | ret = [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tText strings = %@\n" @"\tTTL = %" PRIu32 "\n" @">", | | < | 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 | ret = [OFString stringWithFormat: @"<%@:\n" @"\tName = %@\n" @"\tClass = %@\n" @"\tText strings = %@\n" @"\tTTL = %" PRIu32 "\n" @">", self.className, _name, OFDNSClassName(_DNSClass), text, _TTL]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end |
Modified src/OFDNSResponse.h from [c3b7658d6e] to [52b6089a44].
︙ | ︙ | |||
18 19 20 21 22 23 24 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); typedef OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC( | | < | | | | | < | | | | < | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); typedef OFDictionary OF_GENERIC(OFString *, OFArray OF_GENERIC( OF_KINDOF(OFDNSResourceRecord *)) *) *OFDNSResponseRecords; /** * @class OFDNSResponse OFDNSResponse.h ObjFW/OFDNSResponse.h * * @brief A class storing a response from @ref OFDNSResolver. */ @interface OFDNSResponse: OFObject { OFString *_domainName; OFDNSResponseRecords _answerRecords, _authorityRecords; OFDNSResponseRecords _additionalRecords; OF_RESERVE_IVARS(OFDNSResponse, 4) } /** * @brief The domain name of the response. */ @property (readonly, nonatomic) OFString *domainName; /** * @brief The answer records of the response. * * This is a dictionary with the key being the domain name and the value being * an array of @ref OFDNSResourceRecord. */ @property (readonly, nonatomic) OFDNSResponseRecords answerRecords; /** * @brief The authority records of the response. * * This is a dictionary with the key being the domain name and the value being * an array of @ref OFDNSResourceRecord. */ @property (readonly, nonatomic) OFDNSResponseRecords authorityRecords; /** * @brief The additional records of the response. * * This is a dictionary with the key being the domain name and the value being * an array of @ref OFDNSResourceRecord. */ @property (readonly, nonatomic) OFDNSResponseRecords additionalRecords; /** * @brief Creates a new, autoreleased OFDNSResponse. * * @param domainName The domain name the response is for * @param answerRecords The answer records of the response * @param authorityRecords The authority records of the response * @param additionalRecords The additional records of the response * @return A new, autoreleased OFDNSResponse */ + (instancetype)responseWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords; /** * @brief Initializes an already allocated OFDNSResponse. * * @param domainName The domain name the response is for * @param answerRecords The answer records of the response * @param authorityRecords The authority records of the response * @param additionalRecords The additional records of the response * @return An initialized OFDNSResponse */ - (instancetype)initWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords OF_DESIGNATED_INITIALIZER; - (instancetype)init OF_UNAVAILABLE; @end OF_ASSUME_NONNULL_END |
Modified src/OFDNSResponse.m from [0cb62c07fd] to [e2ab2da42d].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFString.h" @implementation OFDNSResponse @synthesize domainName = _domainName, answerRecords = _answerRecords; @synthesize authorityRecords = _authorityRecords; @synthesize additionalRecords = _additionalRecords; | < | | | | | | | | 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 | #import "OFString.h" @implementation OFDNSResponse @synthesize domainName = _domainName, answerRecords = _answerRecords; @synthesize authorityRecords = _authorityRecords; @synthesize additionalRecords = _additionalRecords; + (instancetype)responseWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords { return [[[self alloc] initWithDomainName: domainName answerRecords: answerRecords authorityRecords: authorityRecords additionalRecords: additionalRecords] autorelease]; } - (instancetype)initWithDomainName: (OFString *)domainName answerRecords: (OFDNSResponseRecords)answerRecords authorityRecords: (OFDNSResponseRecords)authorityRecords additionalRecords: (OFDNSResponseRecords)additionalRecords { self = [super init]; @try { _domainName = [domainName copy]; _answerRecords = [answerRecords copy]; _authorityRecords = [authorityRecords copy]; |
︙ | ︙ | |||
98 99 100 101 102 103 104 | return false; return true; } - (unsigned long)hash { | | | | | | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _domainName.hash); OFHashAddHash(&hash, [_answerRecords hash]); OFHashAddHash(&hash, [_authorityRecords hash]); OFHashAddHash(&hash, [_additionalRecords hash]); OFHashFinalize(&hash); return hash; } - (OFString *)description { OFString *answerRecords = [_answerRecords.description |
︙ | ︙ |
Deleted src/OFData+ASN1DERParsing.h version [98f51ac0d9].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFData+ASN1DERParsing.m version [5e5d1157d6].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Renamed and modified src/OFData+CryptoHashing.h [a5a229d49d] to src/OFData+CryptographicHashing.h [c987e02085].
︙ | ︙ | |||
18 19 20 21 22 23 24 | OF_ASSUME_NONNULL_BEGIN @class OFString; #ifdef __cplusplus extern "C" { #endif | | | | | | | | | | | 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 61 62 63 64 65 66 67 | OF_ASSUME_NONNULL_BEGIN @class OFString; #ifdef __cplusplus extern "C" { #endif extern int _OFData_CryptographicHashing_reference; #ifdef __cplusplus } #endif @interface OFData (CryptographicHashing) /** * @brief The MD5 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringByMD5Hashing; /** * @brief The RIPEMD-160 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringByRIPEMD160Hashing; /** * @brief The SHA-1 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA1Hashing; /** * @brief The SHA-224 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA224Hashing; /** * @brief The SHA-256 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA256Hashing; /** * @brief The SHA-384 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA384Hashing; /** * @brief The SHA-512 hash of the data as a string. */ @property (readonly, nonatomic) OFString *stringBySHA512Hashing; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFData+CryptoHashing.m [42a49bdd70] to src/OFData+CryptographicHashing.m [404b89feab].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | > | | | | | | | | | | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFData+CryptographicHashing.h" #import "OFString.h" #import "OFCryptographicHash.h" #import "OFMD5Hash.h" #import "OFRIPEMD160Hash.h" #import "OFSHA1Hash.h" #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" int _OFData_CryptographicHashing_reference; @implementation OFData (CryptographicHashing) static OFString * stringByHashing(Class <OFCryptographicHash> class, OFData *self) { void *pool = objc_autoreleasePoolPush(); id <OFCryptographicHash> hash = [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self->_items length: self->_count * self->_itemSize]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } objc_autoreleasePoolPop(pool); return [OFString stringWithCString: cString encoding: OFStringEncodingASCII length: digestSize * 2]; } - (OFString *)stringByMD5Hashing { return stringByHashing([OFMD5Hash class], self); } - (OFString *)stringByRIPEMD160Hashing { return stringByHashing([OFRIPEMD160Hash class], self); } - (OFString *)stringBySHA1Hashing { return stringByHashing([OFSHA1Hash class], self); } - (OFString *)stringBySHA224Hashing { return stringByHashing([OFSHA224Hash class], self); } - (OFString *)stringBySHA256Hashing { return stringByHashing([OFSHA256Hash class], self); } - (OFString *)stringBySHA384Hashing { return stringByHashing([OFSHA384Hash class], self); } - (OFString *)stringBySHA512Hashing { return stringByHashing([OFSHA512Hash class], self); } @end |
Modified src/OFData+MessagePackParsing.m from [0f8a367f42] to [9723a31520].
︙ | ︙ | |||
114 115 116 117 118 119 120 | pool = objc_autoreleasePoolPush(); pos += parseObject(buffer + pos, length - pos, &key, depthLimit); pos += parseObject(buffer + pos, length - pos, &value, depthLimit); | | < | | | | | 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 163 164 165 166 | pool = objc_autoreleasePoolPush(); pos += parseObject(buffer + pos, length - pos, &key, depthLimit); pos += parseObject(buffer + pos, length - pos, &value, depthLimit); [*object setObject: value forKey: key]; objc_autoreleasePoolPop(pool); } return pos; } static OFDate * createDate(OFData *data) { switch (data.count) { case 4: { uint32_t timestamp; memcpy(×tamp, data.items, 4); timestamp = OFFromBigEndian32(timestamp); return [OFDate dateWithTimeIntervalSince1970: timestamp]; } case 8: { uint64_t combined; memcpy(&combined, data.items, 8); combined = OFFromBigEndian64(combined); return [OFDate dateWithTimeIntervalSince1970: (double)(combined & 0x3FFFFFFFF) + (double)(combined >> 34) / 1000000000]; } case 12: { uint32_t nanoseconds; int64_t seconds; memcpy(&nanoseconds, data.items, 4); memcpy(&seconds, (char *)data.items + 4, 8); nanoseconds = OFFromBigEndian32(nanoseconds); seconds = OFFromBigEndian64(seconds); return [OFDate dateWithTimeIntervalSince1970: (double)seconds + (double)nanoseconds / 1000000000]; } default: @throw [OFInvalidFormatException exception]; } |
︙ | ︙ | |||
284 285 286 287 288 289 290 | float f; if (length < 5) @throw [OFTruncatedDataException exception]; memcpy(&f, buffer + 1, 4); | | | | 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | float f; if (length < 5) @throw [OFTruncatedDataException exception]; memcpy(&f, buffer + 1, 4); *object = [OFNumber numberWithFloat: OFFromBigEndianFloat(f)]; return 5; case 0xCB:; /* float 64 */ double d; if (length < 9) @throw [OFTruncatedDataException exception]; memcpy(&d, buffer + 1, 8); *object = [OFNumber numberWithDouble: OFFromBigEndianDouble(d)]; return 9; /* nil */ case 0xC0: *object = [OFNull null]; return 1; /* false */ case 0xC2: |
︙ | ︙ | |||
318 319 320 321 322 323 324 | @throw [OFTruncatedDataException exception]; count = buffer[1]; if (length < count + 2) @throw [OFTruncatedDataException exception]; | | < | < | < | < | < | < | < | < | < | < | < | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | @throw [OFTruncatedDataException exception]; count = buffer[1]; if (length < count + 2) @throw [OFTruncatedDataException exception]; *object = [OFData dataWithItems: buffer + 2 count: count]; return count + 2; case 0xC5: /* bin 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; count = readUInt16(buffer + 1); if (length < count + 3) @throw [OFTruncatedDataException exception]; *object = [OFData dataWithItems: buffer + 3 count: count]; return count + 3; case 0xC6: /* bin 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; count = readUInt32(buffer + 1); if (length < count + 5) @throw [OFTruncatedDataException exception]; *object = [OFData dataWithItems: buffer + 5 count: count]; return count + 5; /* Extensions */ case 0xC7: /* ext 8 */ if (length < 3) @throw [OFTruncatedDataException exception]; count = buffer[1]; if (length < count + 3) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 3 count: count]; @try { *object = createExtension(buffer[2], data); } @finally { [data release]; } return count + 3; case 0xC8: /* ext 16 */ if (length < 4) @throw [OFTruncatedDataException exception]; count = readUInt16(buffer + 1); if (length < count + 4) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 4 count: count]; @try { *object = createExtension(buffer[3], data); } @finally { [data release]; } return count + 4; case 0xC9: /* ext 32 */ if (length < 6) @throw [OFTruncatedDataException exception]; count = readUInt32(buffer + 1); if (length < count + 6) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 6 count: count]; @try { *object = createExtension(buffer[5], data); } @finally { [data release]; } return count + 6; case 0xD4: /* fixext 1 */ if (length < 3) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 1]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 3; case 0xD5: /* fixext 2 */ if (length < 4) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 2]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 4; case 0xD6: /* fixext 4 */ if (length < 6) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 4]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 6; case 0xD7: /* fixext 8 */ if (length < 10) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 8]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 10; case 0xD8: /* fixext 16 */ if (length < 18) @throw [OFTruncatedDataException exception]; data = [[OFData alloc] initWithItems: buffer + 2 count: 16]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 18; |
︙ | ︙ |
Modified src/OFData.h from [bbb3c7d446] to [adb3c41f53].
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSerialization.h" #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFURL; | > > > > > > > | > | < > | 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 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSerialization.h" #import "OFMessagePackRepresentation.h" /*! @file */ OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFURL; /** * @brief Options for searching in data. * * This is a bit mask. */ typedef enum { /** Search backwards in the data */ OFDataSearchBackwards = 1 } OFDataSearchOptions; /** * @class OFData OFData.h ObjFW/OFData.h * * @brief A class for storing arbitrary data in an array. * * For security reasons, serialization and deserialization is only implemented |
︙ | ︙ | |||
90 91 92 93 94 95 96 | /** * @brief Creates a new OFData with the specified `count` items of size 1. * * @param items The items to store in the OFData * @param count The number of items * @return A new autoreleased OFData */ | | < | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | /** * @brief Creates a new OFData with the specified `count` items of size 1. * * @param items The items to store in the OFData * @param count The number of items * @return A new autoreleased OFData */ + (instancetype)dataWithItems: (const void *)items count: (size_t)count; /** * @brief Creates a new OFData with the specified `count` items of the * specified size. * * @param items The items to store in the OFData * @param count The number of items |
︙ | ︙ | |||
182 183 184 185 186 187 188 | * @brief Initialized an already allocated OFData with the specified `count` * items of size 1. * * @param items The items to store in the OFData * @param count The number of items * @return An initialized OFData */ | | < | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | * @brief Initialized an already allocated OFData with the specified `count` * items of size 1. * * @param items The items to store in the OFData * @param count The number of items * @return An initialized OFData */ - (instancetype)initWithItems: (const void *)items count: (size_t)count; /** * @brief Initialized an already allocated OFData with the specified `count` * items of the specified size. * * @param items The items to store in the OFData * @param count The number of items |
︙ | ︙ | |||
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | * containing the data of the Base64-encoded string. * * @param string The string with the Base64-encoded data * @return An initialized OFData */ - (instancetype)initWithBase64EncodedString: (OFString *)string; /** * @brief Returns a specific item of the OFData. * * @param index The number of the item to return * @return The specified item of the OFData */ - (const void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; /** * @brief Returns the data in the specified range as a new OFData. * * @param range The range of the data for the new OFData * @return The data in the specified range as a new OFData */ | > > > > > > > > | | < < < < | | | | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | * containing the data of the Base64-encoded string. * * @param string The string with the Base64-encoded data * @return An initialized OFData */ - (instancetype)initWithBase64EncodedString: (OFString *)string; /** * @brief Compares the data to other data. * * @param data Data to compare the data to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFData *)data; /** * @brief Returns a specific item of the OFData. * * @param index The number of the item to return * @return The specified item of the OFData */ - (const void *)itemAtIndex: (size_t)index OF_RETURNS_INNER_POINTER; /** * @brief Returns the data in the specified range as a new OFData. * * @param range The range of the data for the new OFData * @return The data in the specified range as a new OFData */ - (OFData *)subdataWithRange: (OFRange)range; /** * @brief Returns the range of the data. * * @param data The data to search for * @param options Options modifying search behavior * @param range The range in which to search * @return The range of the first occurrence of the data or a range with * `OFNotFound` as start position if it was not found. */ - (OFRange)rangeOfData: (OFData *)data options: (OFDataSearchOptions)options range: (OFRange)range; #ifdef OF_HAVE_FILES /** * @brief Writes the OFData into the specified file. * * @param path The path of the file to write to */ |
︙ | ︙ | |||
321 322 323 324 325 326 327 | */ - (void)writeToURL: (OFURL *)URL; @end OF_ASSUME_NONNULL_END #import "OFMutableData.h" | < | | 331 332 333 334 335 336 337 338 339 | */ - (void)writeToURL: (OFURL *)URL; @end OF_ASSUME_NONNULL_END #import "OFMutableData.h" #import "OFData+CryptographicHashing.h" #import "OFData+MessagePackParsing.h" |
Modified src/OFData.m from [e36b8d42d3] to [1a9ee2a47d].
︙ | ︙ | |||
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 | #include "config.h" #include <stdlib.h> #include <string.h> #include <limits.h> #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFURL.h" #import "OFURLHandler.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" | > < < < | | < | < | 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 61 62 63 64 | #include "config.h" #include <stdlib.h> #include <string.h> #include <limits.h> #import "OFData.h" #import "OFBase64.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" #endif #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFURL.h" #import "OFURLHandler.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" /* References for static linking */ void _references_to_categories_of_OFData(void) { _OFData_CryptographicHashing_reference = 1; _OFData_MessagePackParsing_reference = 1; } @implementation OFData @synthesize itemSize = _itemSize; + (instancetype)dataWithItems: (const void *)items count: (size_t)count { return [[[self alloc] initWithItems: items count: count] autorelease]; } + (instancetype)dataWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { return [[[self alloc] initWithItems: items |
︙ | ︙ | |||
109 110 111 112 113 114 115 | } + (instancetype)dataWithBase64EncodedString: (OFString *)string { return [[[self alloc] initWithBase64EncodedString: string] autorelease]; } | | < | < < | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | } + (instancetype)dataWithBase64EncodedString: (OFString *)string { return [[[self alloc] initWithBase64EncodedString: string] autorelease]; } - (instancetype)initWithItems: (const void *)items count: (size_t)count { return [self initWithItems: items count: count itemSize: 1]; } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _items = OFAllocMemory(count, itemSize); _count = count; _itemSize = itemSize; _freeWhenDone = true; memcpy(_items, items, count * itemSize); } @catch (id e) { [self release]; |
︙ | ︙ | |||
191 192 193 194 195 196 197 | attributesOfItemAtPath: path].fileSize; # if ULLONG_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif | | | < | < | | | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | attributesOfItemAtPath: path].fileSize; # if ULLONG_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif buffer = OFAllocMemory((size_t)size, 1); file = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { [file readIntoBuffer: buffer exactLength: (size_t)size]; } @finally { [file release]; } } @catch (id e) { OFFreeMemory(buffer); [self release]; @throw e; } @try { self = [self initWithItemsNoCopy: buffer count: (size_t)size freeWhenDone: true]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return self; } #endif |
︙ | ︙ | |||
235 236 237 238 239 240 241 | size_t pageSize; unsigned char *buffer; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; | | < | > | | | | | < | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | size_t pageSize; unsigned char *buffer; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; stream = [URLHandler openItemAtURL: URL mode: @"r"]; _count = 0; _itemSize = 1; _freeWhenDone = true; pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; if (SIZE_MAX - _count < length) @throw [OFOutOfRangeException exception]; _items = OFResizeMemory(_items, _count + length, 1); memcpy(_items + _count, buffer, length); _count += length; } } @finally { OFFreeMemory(buffer); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithStringRepresentation: (OFString *)string { self = [super init]; @try { size_t count = [string cStringLengthWithEncoding: OFStringEncodingASCII]; const char *cString; if (count % 2 != 0) @throw [OFInvalidFormatException exception]; count /= 2; _items = OFAllocMemory(count, 1); _count = count; _itemSize = 1; _freeWhenDone = true; cString = [string cStringWithEncoding: OFStringEncodingASCII]; for (size_t i = 0; i < count; i++) { uint8_t c1 = cString[2 * i]; uint8_t c2 = cString[2 * i + 1]; uint8_t byte; if (c1 >= '0' && c1 <= '9') |
︙ | ︙ | |||
339 340 341 342 343 344 345 | [self release]; self = [OFMutableData alloc]; } self = [(OFMutableData *)self initWithCapacity: string.length / 3]; @try { | | | | < | | | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | [self release]; self = [OFMutableData alloc]; } self = [(OFMutableData *)self initWithCapacity: string.length / 3]; @try { if (!OFBase64Decode((OFMutableData *)self, [string cStringWithEncoding: OFStringEncodingASCII], [string cStringLengthWithEncoding: OFStringEncodingASCII])) @throw [OFInvalidFormatException exception]; } @catch (id e) { [self release]; @throw e; } if (!mutable) [(OFMutableData *)self makeImmutable]; return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; stringValue = element.stringValue; } @catch (id e) { [self release]; @throw e; } self = [self initWithBase64EncodedString: stringValue]; objc_autoreleasePoolPop(pool); return self; } - (void)dealloc { if (_freeWhenDone) OFFreeMemory(_items); [_parentData release]; [super dealloc]; } - (size_t)count |
︙ | ︙ | |||
454 455 456 457 458 459 460 | return false; if (memcmp(data.items, _items, _count * _itemSize) != 0) return false; return true; } | | < | < < | | | | | | | | | | | 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 | return false; if (memcmp(data.items, _items, _count * _itemSize) != 0) return false; return true; } - (OFComparisonResult)compare: (OFData *)data { int comparison; size_t count, minCount; if (![data isKindOfClass: [OFData class]]) @throw [OFInvalidArgumentException exception]; if (data.itemSize != _itemSize) @throw [OFInvalidArgumentException exception]; count = data.count; minCount = (_count > count ? count : _count); if ((comparison = memcmp(_items, data.items, minCount * _itemSize)) == 0) { if (_count > count) return OFOrderedDescending; if (_count < count) return OFOrderedAscending; return OFOrderedSame; } if (comparison > 0) return OFOrderedDescending; else return OFOrderedAscending; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < _count * _itemSize; i++) OFHashAdd(&hash, ((uint8_t *)_items)[i]); OFHashFinalize(&hash); return hash; } - (OFData *)subdataWithRange: (OFRange)range { OFData *ret; if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
550 551 552 553 554 555 556 | [ret makeImmutable]; return ret; } - (OFString *)stringByBase64Encoding { | | | | | | | | | | | | < < | < < | < < | | | < < | | < < | < | | < < | < | < < | 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | [ret makeImmutable]; return ret; } - (OFString *)stringByBase64Encoding { return OFBase64Encode(_items, _count * _itemSize); } - (OFRange)rangeOfData: (OFData *)data options: (OFDataSearchOptions)options range: (OFRange)range { const char *search; size_t searchLength; if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) @throw [OFOutOfRangeException exception]; if (data == nil || data.itemSize != _itemSize) @throw [OFInvalidArgumentException exception]; if ((searchLength = data.count) == 0) return OFRangeMake(0, 0); if (searchLength > range.length) return OFRangeMake(OFNotFound, 0); search = data.items; if (options & OFDataSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(_items + i * _itemSize, search, searchLength * _itemSize) == 0) return OFRangeMake(i, searchLength); /* No match and we're at the last item */ if (i == 0) break; } } else { for (size_t i = range.location; i <= range.length - searchLength; i++) if (memcmp(_items + i * _itemSize, search, searchLength * _itemSize) == 0) return OFRangeMake(i, searchLength); } return OFRangeMake(OFNotFound, 0); } #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"w"]; @try { [file writeBuffer: _items length: _count * _itemSize]; } @finally { [file release]; } } #endif - (void)writeToURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); OFURLHandler *URLHandler; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; [[URLHandler openItemAtURL: URL mode: @"w"] writeData: self]; objc_autoreleasePoolPop(pool); } - (OFXMLElement *)XMLElementBySerializing { void *pool; OFXMLElement *element; if (_itemSize != 1) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: OFBase64Encode(_items, _count * _itemSize)]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFData *)messagePackRepresentation { OFMutableData *data; if (_itemSize != 1) @throw [OFInvalidArgumentException exception]; if (_count <= UINT8_MAX) { uint8_t type = 0xC4; uint8_t tmp = (uint8_t)_count; data = [OFMutableData dataWithCapacity: _count + 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (_count <= UINT16_MAX) { uint8_t type = 0xC5; uint16_t tmp = OFToBigEndian16((uint16_t)_count); data = [OFMutableData dataWithCapacity: _count + 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (_count <= UINT32_MAX) { uint8_t type = 0xC6; uint32_t tmp = OFToBigEndian32((uint32_t)_count); data = [OFMutableData dataWithCapacity: _count + 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; [data addItems: _items count: _count]; [data makeImmutable]; return data; } @end |
Modified src/OFDatagramSocket.h from [588f1627d3] to [cca2997072].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFKernelEventObserver.h" #import "OFRunLoop.h" | < | | < | | | | 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 55 56 57 58 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFKernelEventObserver.h" #import "OFRunLoop.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFData; @class OFDatagramSocket; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when a packet has been received. * * @param length The length of the packet * @param sender The address of the sender of the packet * @param exception An exception which occurred while receiving or `nil` on * success * @return A bool whether the same block should be used for the next receive */ typedef bool (^OFDatagramSocketAsyncReceiveBlock)(size_t length, const OFSocketAddress *_Nonnull sender, id _Nullable exception); /** * @brief A block which is called when a packet has been sent. * * @param data The data which was sent * @param receiver The receiver for the packet * @param exception An exception which occurred while reading or `nil` on * success * @return The data to repeat the send with or nil if it should not repeat */ typedef OFData *_Nullable (^OFDatagramSocketAsyncSendDataBlock)( OFData *_Nonnull data, const OFSocketAddress *_Nonnull receiver, id _Nullable exception); #endif /** * @protocol OFDatagramSocketDelegate OFDatagramSocket.h \ * ObjFW/OFDatagramSocket.h * |
︙ | ︙ | |||
72 73 74 75 76 77 78 | * @param exception An exception that occurred while receiving, or nil on * success * @return A bool whether the same block should be used for the next receive */ - (bool)socket: (OFDatagramSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length | | | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | * @param exception An exception that occurred while receiving, or nil on * success * @return A bool whether the same block should be used for the next receive */ - (bool)socket: (OFDatagramSocket *)socket didReceiveIntoBuffer: (void *)buffer length: (size_t)length sender: (const OFSocketAddress *_Nonnull)sender exception: (nullable id)exception; /** * @brief This method is called when a packet has been sent. * * @param socket The datagram socket which sent a packet * @param data The data which was sent * @param receiver The receiver for the packet * @param exception An exception that occurred while sending, or nil on success * @return The data to repeat the send with or nil if it should not repeat */ - (nullable OFData *)socket: (OFDatagramSocket *)socket didSendData: (OFData *)data receiver: (const OFSocketAddress *_Nonnull)receiver exception: (nullable id)exception; @end /** * @class OFDatagramSocket OFDatagramSocket.h ObjFW/OFDatagramSocket.h * * @brief A base class for datagram sockets. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFDatagramSocket: OFObject <OFCopying, OFReadyForReadingObserving, OFReadyForWritingObserving> { OFSocketHandle _socket; bool _canBlock; #ifdef OF_WII bool _canSendToBroadcastAddresses; #endif id <OFDatagramSocketDelegate> _Nullable _delegate; OF_RESERVE_IVARS(OFDatagramSocket, 4) } |
︙ | ︙ | |||
149 150 151 152 153 154 155 | /** * @brief Receives a datagram and stores it into the specified buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | /** * @brief Receives a datagram and stores it into the specified buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param sender A pointer to an @ref OFSocketAddress, which will be set to the * address of the sender * @return The length of the received datagram */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length sender: (OFSocketAddress *)sender; /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the async receive */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param block The block to call when the datagram has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more datagrams have been * received. If you want the next method in the queue to handle * the datagram received next, you need to return false from the * method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFDatagramSocketAsyncReceiveBlock)block; /** * @brief Asynchronously receives a datagram and stores it into the specified * buffer. * * If the buffer is too small, the datagram is truncated. * * @param buffer The buffer to write the datagram to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the async receive * @param block The block to call when the datagram has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more datagrams have been * received. If you want the next method in the queue to handle * the datagram received next, you need to return false from the * method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncReceiveBlock)block; #endif /** * @brief Sends the specified datagram to the specified address. * * @param buffer The buffer to send as a datagram * @param length The length of the buffer * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent */ - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent. The receiver is copied. */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datgram * should be sent. The receiver is copied. * @param runLoopMode The run loop mode in which to perform the async send */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent. The receiver is copied. * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver block: (OFDatagramSocketAsyncSendDataBlock)block; /** * @brief Asynchronously sends the specified datagram to the specified address. * * @param data The data to send as a datagram * @param receiver A pointer to an @ref OFSocketAddress to which the datagram * should be sent. The receiver is copied. * @param runLoopMode The run loop mode in which to perform the async send * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncSendDataBlock)block; #endif /** * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; |
︙ | ︙ |
Modified src/OFDatagramSocket.m from [1a97a9ea83] to [a53bf3d04b].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFDatagramSocket.h" #import "OFData.h" | > > > > > | | > > < < < | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFDatagramSocket.h" #import "OFData.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFGetOptionFailedException.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" @implementation OFDatagramSocket @synthesize delegate = _delegate; + (void)initialize { if (self != [OFDatagramSocket class]) return; if (!OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)socket { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { if (self.class == [OFDatagramSocket class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _socket = OFInvalidSocketHandle; _canBlock = true; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket != OFInvalidSocketHandle) [self close]; [super dealloc]; } - (id)copy { |
︙ | ︙ | |||
110 111 112 113 114 115 116 | if (fcntl(_socket, F_SETFL, flags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; _canBlock = canBlock; #elif defined(OF_WINDOWS) | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | if (fcntl(_socket, F_SETFL, flags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; _canBlock = canBlock; #elif defined(OF_WINDOWS) u_long v = !canBlock; if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; _canBlock = canBlock; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)setCanSendToBroadcastAddresses: (bool)canSendToBroadcastAddresses { int v = canSendToBroadcastAddresses; if (setsockopt(_socket, SOL_SOCKET, SO_BROADCAST, (char *)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; #ifdef OF_WII _canSendToBroadcastAddresses = canSendToBroadcastAddresses; #endif } - (bool)canSendToBroadcastAddresses { #ifndef OF_WII int v; socklen_t len = sizeof(v); if (getsockopt(_socket, SOL_SOCKET, SO_BROADCAST, (char *)&v, &len) != 0 || len != sizeof(v)) @throw [OFGetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; return v; #else return _canSendToBroadcastAddresses; #endif } - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length sender: (OFSocketAddress *)sender { ssize_t ret; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; sender->length = (socklen_t)sizeof(sender->sockaddr); #ifndef OF_WINDOWS if ((ret = recvfrom(_socket, buffer, length, 0, &sender->sockaddr.sockaddr, &sender->length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: OFSocketErrNo()]; #else if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = recvfrom(_socket, buffer, (int)length, 0, &sender->sockaddr.sockaddr, &sender->length)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: OFSocketErrNo()]; #endif switch (sender->sockaddr.sockaddr.sa_family) { case AF_INET: sender->family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: sender->family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: sender->family = OFSocketAddressFamilyIPX; break; #endif default: sender->family = OFSocketAddressFamilyUnknown; break; } return ret; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncReceiveForDatagramSocket: self buffer: buffer length: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFDatagramSocketAsyncReceiveBlock)block { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncReceiveBlock)block { [OFRunLoop of_addAsyncReceiveForDatagramSocket: self buffer: buffer length: length mode: runLoopMode block: block delegate: nil]; } #endif - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = sendto(_socket, (void *)buffer, length, 0, (struct sockaddr *)&receiver->sockaddr.sockaddr, receiver->length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: OFSocketErrNo()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = sendto(_socket, buffer, (int)length, 0, &receiver->sockaddr.sockaddr, receiver->length)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: OFSocketErrNo()]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver { [self asyncSendData: data receiver: receiver runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncSendForDatagramSocket: self data: data receiver: receiver mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver block: (OFDatagramSocketAsyncSendDataBlock)block { [self asyncSendData: data receiver: receiver runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncSendData: (OFData *)data receiver: (const OFSocketAddress *)receiver runLoopMode: (OFRunLoopMode)runLoopMode block: (OFDatagramSocketAsyncSendDataBlock)block { [OFRunLoop of_addAsyncSendForDatagramSocket: self data: data receiver: receiver mode: runLoopMode block: block delegate: nil]; } #endif - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self mode: OFDefaultRunLoopMode]; } - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (int)fileDescriptorForWriting { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (void)close { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; closesocket(_socket); _socket = OFInvalidSocketHandle; } @end |
Modified src/OFDate.h from [e9a1a4ba66] to [67980cebbc].
︙ | ︙ | |||
29 30 31 32 33 34 35 | */ #ifndef OF_DATE_M OF_SUBCLASSING_RESTRICTED #endif @interface OFDate: OFObject <OFCopying, OFComparing, OFSerialization, OFMessagePackRepresentation> { | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | */ #ifndef OF_DATE_M OF_SUBCLASSING_RESTRICTED #endif @interface OFDate: OFObject <OFCopying, OFComparing, OFSerialization, OFMessagePackRepresentation> { OFTimeInterval _seconds; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFDate *distantFuture; @property (class, readonly, nonatomic) OFDate *distantPast; #endif |
︙ | ︙ | |||
120 121 122 123 124 125 126 | * @brief The day of the year of the date in local time. */ @property (readonly, nonatomic) unsigned short localDayOfYear; /** * @brief The seconds since 1970-01-01T00:00:00Z. */ | | | | | | 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 163 | * @brief The day of the year of the date in local time. */ @property (readonly, nonatomic) unsigned short localDayOfYear; /** * @brief The seconds since 1970-01-01T00:00:00Z. */ @property (readonly, nonatomic) OFTimeInterval timeIntervalSince1970; /** * @brief The seconds the date is in the future. */ @property (readonly, nonatomic) OFTimeInterval timeIntervalSinceNow; /** * @brief Creates a new OFDate with the current date and time. * * @return A new, autoreleased OFDate with the current date and time */ + (instancetype)date; /** * @brief Creates a new OFDate with the specified date and time since * 1970-01-01T00:00:00Z. * * @param seconds The seconds since 1970-01-01T00:00:00Z * @return A new, autoreleased OFDate with the specified date and time */ + (instancetype)dateWithTimeIntervalSince1970: (OFTimeInterval)seconds; /** * @brief Creates a new OFDate with the specified date and time since now. * * @param seconds The seconds since now * @return A new, autoreleased OFDate with the specified date and time */ + (instancetype)dateWithTimeIntervalSinceNow: (OFTimeInterval)seconds; /** * @brief Creates a new OFDate with the specified string in the specified * format. * * The time zone used is UTC. See @ref dateWithLocalDateString:format: if you * want local time. |
︙ | ︙ | |||
213 214 215 216 217 218 219 | /** * @brief Initializes an already allocated OFDate with the specified date and * time since 1970-01-01T00:00:00Z. * * @param seconds The seconds since 1970-01-01T00:00:00Z * @return An initialized OFDate with the specified date and time */ | | | | 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | /** * @brief Initializes an already allocated OFDate with the specified date and * time since 1970-01-01T00:00:00Z. * * @param seconds The seconds since 1970-01-01T00:00:00Z * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds OF_DESIGNATED_INITIALIZER; /** * @brief Initializes an already allocated OFDate with the specified date and * time since now. * * @param seconds The seconds since now * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithTimeIntervalSinceNow: (OFTimeInterval)seconds; /** * @brief Initializes an already allocated OFDate with the specified string in * the specified format. * * The time zone used is UTC. If a time zone is specified anyway, an * OFInvalidFormatException is thrown. See @ref initWithLocalDateString:format: |
︙ | ︙ | |||
263 264 265 266 267 268 269 270 271 272 273 274 275 276 | * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Creates a string of the date with the specified format. * * See the man page for `strftime` for information on the format. * * @param format The format for the date string * @return A new, autoreleased OFString | > > > > > > > > | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | * @param string The string describing the date * @param format The format of the string describing the date * @return An initialized OFDate with the specified date and time */ - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format; /** * @brief Compares the date to another date. * * @param date The date to compare the date to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFDate *)date; /** * @brief Creates a string of the date with the specified format. * * See the man page for `strftime` for information on the format. * * @param format The format for the date string * @return A new, autoreleased OFString |
︙ | ︙ | |||
309 310 311 312 313 314 315 | /** * @brief Returns the seconds the receiver is after the date. * * @param otherDate Date date to generate the difference with receiver * @return The seconds the receiver is after the date. */ | | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | /** * @brief Returns the seconds the receiver is after the date. * * @param otherDate Date date to generate the difference with receiver * @return The seconds the receiver is after the date. */ - (OFTimeInterval)timeIntervalSinceDate: (OFDate *)otherDate; /** * @brief Creates a new date with the specified time interval added. * * @param seconds The seconds after the date * @return A new, autoreleased OFDate */ - (OFDate *)dateByAddingTimeInterval: (OFTimeInterval)seconds; @end OF_ASSUME_NONNULL_END |
Modified src/OFDate.m from [3377ad9619] to [aee2dab951].
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFDate.h" #import "OFData.h" #import "OFDictionary.h" #import "OFMessagePackExtension.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLElement.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" | > < < | 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 | #import "OFDate.h" #import "OFData.h" #import "OFDictionary.h" #import "OFMessagePackExtension.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFStrPTime.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLElement.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #ifdef OF_AMIGAOS_M68K /* amiga-gcc does not have trunc() */ # define trunc(x) ((int64_t)(x)) #endif @interface OFDate () + (instancetype)of_alloc; |
︙ | ︙ | |||
87 88 89 90 91 92 93 | static void initDistantPast(void) { distantPast = [[OFDateSingleton alloc] initWithTimeIntervalSince1970: -62167219200.0]; } | | | | | | | | | | | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | static void initDistantPast(void) { distantPast = [[OFDateSingleton alloc] initWithTimeIntervalSince1970: -62167219200.0]; } static OFTimeInterval now(void) { struct timeval tv; OFTimeInterval seconds; OFEnsure(gettimeofday(&tv, NULL) == 0); seconds = tv.tv_sec; seconds += (OFTimeInterval)tv.tv_usec / 1000000; return seconds; } #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_HAVE_THREADS) static OFMutex *mutex; static void releaseMutex(void) { [mutex release]; } #endif #ifdef OF_WINDOWS static __time64_t (*_mktime64FuncPtr)(struct tm *); #endif #ifdef HAVE_GMTIME_R # define GMTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if (gmtime_r(&seconds, &tm) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm.field; # define LOCALTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if (localtime_r(&seconds, &tm) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm.field; #else # ifdef OF_HAVE_THREADS # define GMTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ [mutex lock]; \ \ @try { \ if ((tm = gmtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm->field; \ } @finally { \ [mutex unlock]; \ } # define LOCALTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ [mutex lock]; \ \ @try { \ if ((tm = localtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm->field; \ } @finally { \ [mutex unlock]; \ } # else # define GMTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if ((tm = gmtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException exception]; \ \ return tm->field; # define LOCALTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ time_t seconds = (time_t)timeInterval; \ struct tm *tm; \ \ if (seconds != trunc(timeInterval)) \ @throw [OFOutOfRangeException exception]; \ \ if ((tm = localtime(&seconds)) == NULL) \ |
︙ | ︙ | |||
273 274 275 276 277 278 279 | - (void)release { } - (unsigned int)retainCount { | | | | | | | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } @end @implementation OFDatePlaceholder #ifdef __clang__ /* We intentionally don't call into super, so silence the warning. */ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunknown-pragmas" # pragma clang diagnostic ignored "-Wobjc-designated-initializers" #endif - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds { #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX uint64_t value; #endif if (seconds == 0) { static OFOnceControl once = OFOnceControlInitValue; OFOnce(&once, initZeroDate); return (id)zeroDate; } #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX value = OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( seconds))); /* Almost all dates fall into this range. */ if (value & (UINT64_C(4) << 60)) { id ret = objc_createTaggedPointer(dateTag, value & ~(UINT64_C(4) << 60)); |
︙ | ︙ | |||
319 320 321 322 323 324 325 | #ifdef __clang__ # pragma clang diagnostic pop #endif @end #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX @implementation OFTaggedPointerDate | | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | #ifdef __clang__ # pragma clang diagnostic pop #endif @end #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX @implementation OFTaggedPointerDate - (OFTimeInterval)timeIntervalSince1970 { uint64_t value = (uint64_t)object_getTaggedPointerValue(self); value |= UINT64_C(4) << 60; return OFFromBigEndianDouble(OFRawUInt64ToDouble(OFToBigEndian64( value))); } @end #endif @implementation OFDate + (void)initialize |
︙ | ︙ | |||
351 352 353 354 355 356 357 | defined(OF_HAVE_THREADS) mutex = [[OFMutex alloc] init]; atexit(releaseMutex); #endif #ifdef OF_WINDOWS if ((module = LoadLibrary("msvcrt.dll")) != NULL) | | | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 | defined(OF_HAVE_THREADS) mutex = [[OFMutex alloc] init]; atexit(releaseMutex); #endif #ifdef OF_WINDOWS if ((module = LoadLibrary("msvcrt.dll")) != NULL) _mktime64FuncPtr = (__time64_t (*)(struct tm *)) GetProcAddress(module, "_mktime64"); #endif #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX dateTag = objc_registerTaggedPointerClass([OFTaggedPointerDate class]); #endif } |
︙ | ︙ | |||
378 379 380 381 382 383 384 | } + (instancetype)date { return [[[self alloc] init] autorelease]; } | | | | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | } + (instancetype)date { return [[[self alloc] init] autorelease]; } + (instancetype)dateWithTimeIntervalSince1970: (OFTimeInterval)seconds { return [[[self alloc] initWithTimeIntervalSince1970: seconds] autorelease]; } + (instancetype)dateWithTimeIntervalSinceNow: (OFTimeInterval)seconds { return [[[self alloc] initWithTimeIntervalSinceNow: seconds] autorelease]; } + (instancetype)dateWithDateString: (OFString *)string format: (OFString *)format |
︙ | ︙ | |||
406 407 408 409 410 411 412 | { return [[[self alloc] initWithLocalDateString: string format: format] autorelease]; } + (instancetype)distantFuture { | | | | | | | | | | | | | | | | | | 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 | { return [[[self alloc] initWithLocalDateString: string format: format] autorelease]; } + (instancetype)distantFuture { static OFOnceControl once = OFOnceControlInitValue; OFOnce(&once, initDistantFuture); return distantFuture; } + (instancetype)distantPast { static OFOnceControl once = OFOnceControlInitValue; OFOnce(&once, initDistantPast); return distantPast; } - (instancetype)init { return [self initWithTimeIntervalSince1970: now()]; } - (instancetype)initWithTimeIntervalSince1970: (OFTimeInterval)seconds { self = [super init]; _seconds = seconds; return self; } - (instancetype)initWithTimeIntervalSinceNow: (OFTimeInterval)seconds { return [self initWithTimeIntervalSince1970: now() + seconds]; } - (instancetype)initWithDateString: (OFString *)string format: (OFString *)format { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; struct tm tm = { .tm_isdst = -1 }; short tz = 0; if (OFStrPTime(UTF8String, format.UTF8String, &tm, &tz) != UTF8String + string.UTF8StringLength) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return [self initWithTimeIntervalSince1970: tmAndTzToTime(&tm, tz)]; } - (instancetype)initWithLocalDateString: (OFString *)string format: (OFString *)format { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = string.UTF8String; struct tm tm = { .tm_isdst = -1 }; /* * OFStrPTime() can never set this to SHRT_MAX, no matter what is * passed to it, so this is a safe way to figure out if the date * contains a time zone. */ short tz = SHRT_MAX; OFTimeInterval seconds; if (OFStrPTime(UTF8String, format.UTF8String, &tm, &tz) != UTF8String + string.UTF8StringLength) @throw [OFInvalidFormatException exception]; if (tz == SHRT_MAX) { #ifdef OF_WINDOWS if (_mktime64FuncPtr != NULL) { if ((seconds = _mktime64FuncPtr(&tm)) == -1) @throw [OFInvalidFormatException exception]; } else { #endif if ((seconds = mktime(&tm)) == -1) @throw [OFInvalidFormatException exception]; #ifdef OF_WINDOWS } #endif } else seconds = tmAndTzToTime(&tm, tz); objc_autoreleasePoolPop(pool); return [self initWithTimeIntervalSince1970: seconds]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { OFTimeInterval seconds; @try { void *pool = objc_autoreleasePoolPush(); unsigned long long value; if (![element.name isEqual: @"OFDate"] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; value = [element unsignedLongLongValueWithBase: 16]; if (value > UINT64_MAX) @throw [OFOutOfRangeException exception]; seconds = OFFromBigEndianDouble(OFRawUInt64ToDouble( OFToBigEndian64(value))); objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
541 542 543 544 545 546 547 | return false; return true; } - (unsigned long)hash { | | | | | | < < | | | < < | | | | | | | | | | < | < | | | < | | 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | return false; return true; } - (unsigned long)hash { unsigned long hash; double tmp; OFHashInit(&hash); tmp = OFToLittleEndianDouble(self.timeIntervalSince1970); for (size_t i = 0; i < sizeof(double); i++) OFHashAdd(&hash, ((char *)&tmp)[i]); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } - (OFComparisonResult)compare: (OFDate *)date { if (![date isKindOfClass: [OFDate class]]) @throw [OFInvalidArgumentException exception]; if (self.timeIntervalSince1970 < date.timeIntervalSince1970) return OFOrderedAscending; if (self.timeIntervalSince1970 > date.timeIntervalSince1970) return OFOrderedDescending; return OFOrderedSame; } - (OFString *)description { return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"]; } - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFDate" namespace: OFSerializationNS]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( self.timeIntervalSince1970)))]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFData *)messagePackRepresentation { void *pool = objc_autoreleasePoolPush(); OFTimeInterval timeInterval = self.timeIntervalSince1970; int64_t seconds = (int64_t)timeInterval; uint32_t nanoseconds = (uint32_t)((timeInterval - trunc(timeInterval)) * 1000000000); OFData *ret; if (seconds >= 0 && seconds < 0x400000000) { if (seconds <= UINT32_MAX && nanoseconds == 0) { uint32_t seconds32 = (uint32_t)seconds; OFData *data; seconds32 = OFToBigEndian32(seconds32); data = [OFData dataWithItems: &seconds32 count: sizeof(seconds32)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } else { uint64_t combined = ((uint64_t)nanoseconds << 34) | (uint64_t)seconds; OFData *data; combined = OFToBigEndian64(combined); data = [OFData dataWithItems: &combined count: sizeof(combined)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } } else { OFMutableData *data = [OFMutableData dataWithCapacity: 12]; nanoseconds = OFToBigEndian32(nanoseconds); [data addItems: &nanoseconds count: sizeof(nanoseconds)]; seconds = OFToBigEndian64(seconds); [data addItems: &seconds count: sizeof(seconds)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (unsigned long)microsecond { OFTimeInterval timeInterval = self.timeIntervalSince1970; return (unsigned long)((timeInterval - trunc(timeInterval)) * 1000000); } - (unsigned char)second { GMTIME_RET(tm_sec) |
︙ | ︙ | |||
744 745 746 747 748 749 750 | { LOCALTIME_RET(tm_yday + 1) } - (OFString *)dateStringWithFormat: (OFConstantString *)format { OFString *ret; | | | 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | { LOCALTIME_RET(tm_yday + 1) } - (OFString *)dateStringWithFormat: (OFConstantString *)format { OFString *ret; OFTimeInterval timeInterval = self.timeIntervalSince1970; time_t seconds = (time_t)timeInterval; struct tm tm; size_t pageSize; #ifndef OF_WINDOWS char *buffer; #else wchar_t *buffer; |
︙ | ︙ | |||
780 781 782 783 784 785 786 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; | | | | | 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; #else if (wcsftime(buffer, pageSize / sizeof(wchar_t), format.UTF16String, &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF16String: buffer]; #endif } @finally { OFFreeMemory(buffer); } return ret; } - (OFString *)localDateStringWithFormat: (OFConstantString *)format { OFString *ret; OFTimeInterval timeInterval = self.timeIntervalSince1970; time_t seconds = (time_t)timeInterval; struct tm tm; size_t pageSize; #ifndef OF_WINDOWS char *buffer; #else wchar_t *buffer; |
︙ | ︙ | |||
840 841 842 843 844 845 846 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; | | | | | | | | | | | | | 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | } @finally { [mutex unlock]; } # endif #endif pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { #ifndef OF_WINDOWS if (strftime(buffer, pageSize, format.UTF8String, &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF8String: buffer]; #else if (wcsftime(buffer, pageSize / sizeof(wchar_t), format.UTF16String, &tm) == 0) @throw [OFOutOfRangeException exception]; ret = [OFString stringWithUTF16String: buffer]; #endif } @finally { OFFreeMemory(buffer); } return ret; } - (OFDate *)earlierDate: (OFDate *)otherDate { if (otherDate == nil) return self; if ([self compare: otherDate] == OFOrderedDescending) return otherDate; return self; } - (OFDate *)laterDate: (OFDate *)otherDate { if (otherDate == nil) return self; if ([self compare: otherDate] == OFOrderedAscending) return otherDate; return self; } - (OFTimeInterval)timeIntervalSince1970 { return _seconds; } - (OFTimeInterval)timeIntervalSinceDate: (OFDate *)otherDate { return self.timeIntervalSince1970 - otherDate.timeIntervalSince1970; } - (OFTimeInterval)timeIntervalSinceNow { struct timeval t; OFTimeInterval seconds; OFEnsure(gettimeofday(&t, NULL) == 0); seconds = t.tv_sec; seconds += (OFTimeInterval)t.tv_usec / 1000000; return self.timeIntervalSince1970 - seconds; } - (OFDate *)dateByAddingTimeInterval: (OFTimeInterval)seconds { return [OFDate dateWithTimeIntervalSince1970: self.timeIntervalSince1970 + seconds]; } @end |
Modified src/OFDictionary.h from [c87704d4fa] to [a266eaef28].
︙ | ︙ | |||
30 31 32 33 34 35 36 | #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); #ifdef OF_HAVE_BLOCKS | | < | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #import "OFMessagePackRepresentation.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); #ifdef OF_HAVE_BLOCKS typedef void (^OFDictionaryEnumerationBlock)(id key, id object, bool *stop); typedef bool (^OFDictionaryFilterBlock)(id key, id object); typedef id _Nonnull (^OFDictionaryMapBlock)(id key, id object); #endif /** * @class OFDictionary OFDictionary.h ObjFW/OFDictionary.h * * @brief An abstract class for storing objects in a dictionary. * |
︙ | ︙ | |||
94 95 96 97 98 99 100 | /** * @brief Creates a new OFDictionary with the specified key and object. * * @param key The key * @param object The object * @return A new autoreleased OFDictionary */ | | < | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | /** * @brief Creates a new OFDictionary with the specified key and object. * * @param key The key * @param object The object * @return A new autoreleased OFDictionary */ + (instancetype)dictionaryWithObject: (ObjectType)object forKey: (KeyType)key; /** * @brief Creates a new OFDictionary with the specified keys and objects. * * @param keys An array of keys * @param objects An array of objects * @return A new autoreleased OFDictionary |
︙ | ︙ | |||
148 149 150 151 152 153 154 | * @brief Initializes an already allocated OFDictionary with the specified key * and object. * * @param key The key * @param object The object * @return An initialized OFDictionary */ | | < | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | * @brief Initializes an already allocated OFDictionary with the specified key * and object. * * @param key The key * @param object The object * @return An initialized OFDictionary */ - (instancetype)initWithObject: (ObjectType)object forKey: (KeyType)key; /** * @brief Initializes an already allocated OFDictionary with the specified keys * and objects. * * @param keys An array of keys * @param objects An array of objects |
︙ | ︙ | |||
192 193 194 195 196 197 198 | * @brief Initializes an already allocated OFDictionary with the specified key * and va_list. * * @param firstKey The first key * @param arguments A va_list of the other arguments * @return An initialized OFDictionary */ | | < | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | * @brief Initializes an already allocated OFDictionary with the specified key * and va_list. * * @param firstKey The first key * @param arguments A va_list of the other arguments * @return An initialized OFDictionary */ - (instancetype)initWithKey: (KeyType)firstKey arguments: (va_list)arguments; /** * @brief Returns the object for the given key or `nil` if the key was not * found. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! |
︙ | ︙ | |||
230 231 232 233 234 235 236 | * * This is equivalent to OFMutableDictionary#setObject:forKey:. If the * dictionary is immutable, an @ref OFUndefinedKeyException is thrown. * * @param key The key to set * @param value The value to set the key to */ | | < | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | * * This is equivalent to OFMutableDictionary#setObject:forKey:. If the * dictionary is immutable, an @ref OFUndefinedKeyException is thrown. * * @param key The key to set * @param value The value to set the key to */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Checks whether the dictionary contains an object equal to the * specified object. * * @param object The object which is checked for being in the dictionary * @return A boolean whether the dictionary contains the specified object |
︙ | ︙ | |||
272 273 274 275 276 277 278 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each key / object pair. * * @param block The block to execute for each key / object pair. */ | | < | | | | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each key / object pair. * * @param block The block to execute for each key / object pair. */ - (void)enumerateKeysAndObjectsUsingBlock: (OFDictionaryEnumerationBlock)block; /** * @brief Creates a new dictionary, mapping each object using the specified * block. * * @param block A block which maps an object for each object * @return A new autoreleased OFDictionary */ - (OFDictionary OF_GENERIC(KeyType, id) *) mappedDictionaryUsingBlock: (OFDictionaryMapBlock)block; /** * @brief Creates a new dictionary, only containing the objects for which the * block returns true. * * @param block A block which determines if the object should be in the new * dictionary * @return A new autoreleased OFDictionary */ - (OFDictionary OF_GENERIC(KeyType, ObjectType) *) filteredDictionaryUsingBlock: (OFDictionaryFilterBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef KeyType # undef ObjectType #endif @end |
︙ | ︙ |
Modified src/OFDictionary.m from [acad8576d1] to [804d125c3d].
︙ | ︙ | |||
35 36 37 38 39 40 41 | static struct { Class isa; } placeholder; static OFCharacterSet *URLQueryPartAllowedCharacterSet = nil; @interface OFDictionary () | | > | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | static struct { Class isa; } placeholder; static OFCharacterSet *URLQueryPartAllowedCharacterSet = nil; @interface OFDictionary () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFDictionaryPlaceholder: OFDictionary @end OF_DIRECT_MEMBERS @interface OFDictionaryObjectEnumerator: OFEnumerator |
︙ | ︙ | |||
69 70 71 72 73 74 75 | - (instancetype)initWithDictionary: (OFDictionary *)dictionary { return (id)[[OFMapTableDictionary alloc] initWithDictionary: dictionary]; } | | < | < | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | - (instancetype)initWithDictionary: (OFDictionary *)dictionary { return (id)[[OFMapTableDictionary alloc] initWithDictionary: dictionary]; } - (instancetype)initWithObject: (id)object forKey: (id)key { return (id)[[OFMapTableDictionary alloc] initWithObject: object forKey: key]; } - (instancetype)initWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { return (id)[[OFMapTableDictionary alloc] initWithObjects: objects forKeys: keys]; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys |
︙ | ︙ | |||
169 170 171 172 173 174 175 | - (void)release { } - (unsigned int)retainCount { | | | | | 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': case '.': case '_': case '~': |
︙ | ︙ | |||
224 225 226 227 228 229 230 | + (instancetype)dictionaryWithDictionary: (OFDictionary *)dictionary { return [[(OFDictionary *)[self alloc] initWithDictionary: dictionary] autorelease]; } | | < | < | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | + (instancetype)dictionaryWithDictionary: (OFDictionary *)dictionary { return [[(OFDictionary *)[self alloc] initWithDictionary: dictionary] autorelease]; } + (instancetype)dictionaryWithObject: (id)object forKey: (id)key { return [[[self alloc] initWithObject: object forKey: key] autorelease]; } + (instancetype)dictionaryWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { return [[[self alloc] initWithObjects: objects forKeys: keys] autorelease]; } + (instancetype)dictionaryWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { return [[[self alloc] initWithObjects: objects forKeys: keys count: count] autorelease]; } + (instancetype)dictionaryWithKeysAndObjects: (id)firstKey, ... |
︙ | ︙ | |||
281 282 283 284 285 286 287 | } - (instancetype)initWithDictionary: (OFDictionary *)dictionary { OF_INVALID_INIT_METHOD } | | < | < | < < | < | < | 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | } - (instancetype)initWithDictionary: (OFDictionary *)dictionary { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object forKey: (id)key { if (key == nil || object == nil) @throw [OFInvalidArgumentException exception]; return [self initWithKeysAndObjects: key, object, nil]; } - (instancetype)initWithObjects: (OFArray *)objects_ forKeys: (OFArray *)keys_ { id const *objects, *keys; size_t count; @try { count = objects_.count; if (count != keys_.count) @throw [OFInvalidArgumentException exception]; objects = objects_.objects; keys = keys_.objects; } @catch (id e) { [self release]; @throw e; } return [self initWithObjects: objects forKeys: keys count: count]; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { OF_INVALID_INIT_METHOD } - (instancetype)initWithKeysAndObjects: (id)firstKey, ... { id ret; va_list arguments; va_start(arguments, firstKey); ret = [self initWithKey: firstKey arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { OF_INVALID_INIT_METHOD } - (instancetype)initWithSerialization: (OFXMLElement *)element { OF_INVALID_INIT_METHOD |
︙ | ︙ | |||
363 364 365 366 367 368 369 | { if ([key isEqual: @"@count"]) return [super valueForKey: @"count"]; return [self objectForKey: key]; } | | < | < | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | { if ([key isEqual: @"@count"]) return [super valueForKey: @"count"]; return [self objectForKey: key]; } - (void)setValue: (id)value forKey: (OFString *)key { if (![self isKindOfClass: [OFMutableDictionary class]]) @throw [OFUndefinedKeyException exceptionWithObject: self key: key value: value]; [(OFMutableDictionary *)self setObject: value forKey: key]; } - (size_t)count { OF_UNRECOGNIZED_SELECTOR } |
︙ | ︙ | |||
515 516 517 518 519 520 521 | - (OFEnumerator *)objectEnumerator { return [[[OFDictionaryObjectEnumerator alloc] initWithDictionary: self] autorelease]; } | | | 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | - (OFEnumerator *)objectEnumerator { return [[[OFDictionaryObjectEnumerator alloc] initWithDictionary: self] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFEnumerator *enumerator; int i; memcpy(&enumerator, state->extra, sizeof(enumerator)); |
︙ | ︙ | |||
545 546 547 548 549 550 551 | objects[i] = object; } return i; } #ifdef OF_HAVE_BLOCKS | | < | | < | < | < | 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 | objects[i] = object; } return i; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (OFDictionaryEnumerationBlock)block { bool stop = false; for (id key in self) { block(key, [self objectForKey: key], &stop); if (stop) break; } } - (OFDictionary *)mappedDictionaryUsingBlock: (OFDictionaryMapBlock)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { [new setObject: block(key, object) forKey: key]; }]; [new makeImmutable]; return new; } - (OFDictionary *)filteredDictionaryUsingBlock: (OFDictionaryFilterBlock)block { OFMutableDictionary *new = [OFMutableDictionary dictionary]; [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { if (block(key, object)) [new setObject: object forKey: key]; }]; [new makeImmutable]; return new; } #endif |
︙ | ︙ | |||
640 641 642 643 644 645 646 | [ret appendString: object.description]; if (++i < count) [ret appendString: @";\n"]; objc_autoreleasePoolPop(pool2); } | | < | 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | [ret appendString: object.description]; if (++i < count) [ret appendString: @";\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @";\n}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; |
︙ | ︙ | |||
692 693 694 695 696 697 698 | void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; OFEnumerator *keyEnumerator, *objectEnumerator; id <OFSerialization> key, object; if ([self isKindOfClass: [OFMutableDictionary class]]) element = [OFXMLElement elementWithName: @"OFMutableDictionary" | | | | | | < | > | < | > | | | | 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 | void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; OFEnumerator *keyEnumerator, *objectEnumerator; id <OFSerialization> key, object; if ([self isKindOfClass: [OFMutableDictionary class]]) element = [OFXMLElement elementWithName: @"OFMutableDictionary" namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFDictionary" namespace: OFSerializationNS]; keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *keyElement, *objectElement; keyElement = [OFXMLElement elementWithName: @"key" namespace: OFSerializationNS]; [keyElement addChild: key.XMLElementBySerializing]; objectElement = [OFXMLElement elementWithName: @"object" namespace: OFSerializationNS]; [objectElement addChild: object.XMLElementBySerializing]; [element addChild: keyElement]; [element addChild: objectElement]; objc_autoreleasePoolPop(pool2); } [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { OFMutableString *JSON = [OFMutableString stringWithString: @"{"]; void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [self keyEnumerator]; OFEnumerator *objectEnumerator = [self objectEnumerator]; size_t i, count = self.count; id key, object; if (options & OFJSONRepresentationOptionPretty) { OFMutableString *indentation = [OFMutableString string]; for (i = 0; i < depth; i++) [indentation appendString: @"\t"]; [JSON appendString: @"\n"]; i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); int identifierOptions = options | OFJSONRepresentationOptionIsIdentifier; if (![key isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; [JSON appendString: indentation]; [JSON appendString: @"\t"]; [JSON appendString: [key |
︙ | ︙ | |||
792 793 794 795 796 797 798 | [JSON appendString: indentation]; } else { i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); int identifierOptions = | | | 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | [JSON appendString: indentation]; } else { i = 0; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); int identifierOptions = options | OFJSONRepresentationOptionIsIdentifier; if (![key isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; [JSON appendString: [key of_JSONRepresentationWithOptions: identifierOptions depth: depth + 1]]; |
︙ | ︙ | |||
836 837 838 839 840 841 842 | count = self.count; if (count <= 15) { uint8_t tmp = 0x80 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDE; | | | < | | < | < | < | 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 | count = self.count; if (count <= 15) { uint8_t tmp = 0x80 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDE; uint16_t tmp = OFToBigEndian16((uint16_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDF; uint32_t tmp = OFToBigEndian32((uint32_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); i = 0; keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFData *child; i++; child = key.messagePackRepresentation; [data addItems: child.items count: child.count]; child = object.messagePackRepresentation; [data addItems: child.items count: child.count]; objc_autoreleasePoolPop(pool2); } assert(i == count); [data makeImmutable]; |
︙ | ︙ |
Modified src/OFEnumerator.h from [26a2240303] to [aa2de24ec1].
︙ | ︙ | |||
17 18 19 20 21 22 23 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFEnumerator OF_GENERIC(ObjectType); /** | | > > > > | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFEnumerator OF_GENERIC(ObjectType); /** * @protocol OFEnumeration OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A protocol for getting an enumerator for the object. * * If the class conforming to OFEnumeration is using lightweight generics, the * only method, @ref objectEnumerator, should be overridden to use lightweight * generics. */ @protocol OFEnumeration /** * @brief Returns an OFEnumerator to enumerate through all objects of the * collection. * * @return An OFEnumerator to enumerate through all objects of the collection */ - (OFEnumerator *)objectEnumerator; @end /* * This needs to be exactly like this because it's hard-coded in the compiler. * * We need this bad check to see if we already imported Cocoa, which defines * this as well. */ /** * @struct OFFastEnumerationState OFEnumerator.h ObjFW/OFEnumerator.h * * @brief State information for fast enumerations. */ #define OFFastEnumerationState NSFastEnumerationState #ifndef NSINTEGER_DEFINED typedef struct { /** Arbitrary state information for the enumeration */ unsigned long state; /** Pointer to a C array of objects to return */ id __unsafe_unretained _Nullable *_Nullable itemsPtr; /** Arbitrary state information to detect mutations */ unsigned long *_Nullable mutationsPtr; /** Additional arbitrary state information */ unsigned long extra[5]; } OFFastEnumerationState; #endif /** * @protocol OFFastEnumeration OFEnumerator.h ObjFW/OFEnumerator.h * * @brief A protocol for fast enumeration. * |
︙ | ︙ | |||
75 76 77 78 79 80 81 | * * @param state Context information for the enumeration * @param objects A pointer to an array where to put the objects * @param count The number of objects that can be stored at objects * @return The number of objects returned in objects or 0 when the enumeration * finished. */ | | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | * * @param state Context information for the enumeration * @param objects A pointer to an array where to put the objects * @param count The number of objects that can be stored at objects * @return The number of objects returned in objects or 0 when the enumeration * finished. */ - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id __unsafe_unretained _Nonnull *_Nonnull) objects count: (int)count; @end /** * @class OFEnumerator OFEnumerator.h ObjFW/OFEnumerator.h |
︙ | ︙ |
Modified src/OFEnumerator.m from [c36212a268] to [e234a4699e].
︙ | ︙ | |||
53 54 55 56 57 58 59 | [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } | | | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { int i; state->itemsPtr = objects; state->mutationsPtr = (unsigned long *)self; |
︙ | ︙ |
Modified src/OFEpollKernelEventObserver.m from [11ad156308] to [b83e1bbf77].
︙ | ︙ | |||
29 30 31 32 33 34 35 | #import "OFArray.h" #import "OFMapTable.h" #import "OFNull.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" | | | | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #import "OFArray.h" #import "OFMapTable.h" #import "OFNull.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #define eventListSize 64 static const OFMapTableFunctions mapFunctions = { NULL }; @implementation OFEpollKernelEventObserver - (instancetype)init { self = [super init]; @try { |
︙ | ︙ | |||
183 184 185 186 187 188 189 | [self of_removeObject: object fileDescriptor: object.fileDescriptorForWriting events: EPOLLOUT]; [super removeObjectForWriting: object]; } | | | | | | 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | [self of_removeObject: object fileDescriptor: object.fileDescriptorForWriting events: EPOLLOUT]; [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { OFNull *nullObject = [OFNull null]; struct epoll_event eventList[eventListSize]; int events; if ([self of_processReadBuffers]) return; events = epoll_wait(_epfd, eventList, eventListSize, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { if (eventList[i].events & EPOLLIN) { void *pool = objc_autoreleasePoolPush(); if (eventList[i].data.ptr == nullObject) { char buffer; OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); continue; } if ([_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: eventList[i].data.ptr]; |
︙ | ︙ |
Modified src/OFFile.h from [7be975c2e8] to [bac13481b9].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFSeekableStream.h" #import "OFKernelEventObserver.h" #ifndef OF_AMIGAOS # define OF_FILE_HANDLE_IS_FD | < | > < | > | | 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 | */ #import "OFSeekableStream.h" #import "OFKernelEventObserver.h" #ifndef OF_AMIGAOS # define OF_FILE_HANDLE_IS_FD typedef int OFFileHandle; static const OFFileHandle OFInvalidFileHandle = -1; #else typedef struct _OFFileHandle *OFFileHandle; static const OFFileHandle OFInvalidFileHandle = NULL; #endif OF_ASSUME_NONNULL_BEGIN @class OFURL; /** * @class OFFile OFFile.h ObjFW/OFFile.h * * @brief A class which provides methods to read and write files. */ OF_SUBCLASSING_RESTRICTED @interface OFFile: OFSeekableStream #ifdef OF_FILE_HANDLE_IS_FD <OFReadyForReadingObserving, OFReadyForWritingObserving> #endif { OFFileHandle _handle; bool _atEndOfStream; } /** * @brief Creates a new OFFile with the specified path and mode. * * @param path The path to the file to open as a string |
︙ | ︙ | |||
59 60 61 62 63 64 65 | * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @return A new autoreleased OFFile */ | | < | < | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @return A new autoreleased OFFile */ + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Creates a new OFFile with the specified URL and mode. * * @param URL The URL to the file to open * @param mode The mode in which the file should be opened.@n * Possible modes are: * Mode | Description * ---------------|------------------------------------- * `r` | Read-only * `r+` | Read-write * `w` | Write-only, create or truncate * `wx` | Write-only, create or fail, exclusive * `w+` | Read-write, create or truncate * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @return A new autoreleased OFFile */ + (instancetype)fileWithURL: (OFURL *)URL mode: (OFString *)mode; /** * @brief Creates a new OFFile with the specified native file handle. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this * is a file descriptor. The handle is closed when the OFFile * object is deallocated! * @return A new autoreleased OFFile */ + (instancetype)fileWithHandle: (OFFileHandle)handle; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFFile. * * @param path The path to the file to open as a string |
︙ | ︙ | |||
117 118 119 120 121 122 123 | * `wb+` or `w+b` | read-write, create, truncate, binary * `a` | write-only, create, append * `ab` | write-only, create, append, binary * `a+` | read-write, create, append * `ab+` or `a+b` | read-write, create, append, binary * @return An initialized OFFile */ | | < | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | * `wb+` or `w+b` | read-write, create, truncate, binary * `a` | write-only, create, append * `ab` | write-only, create, append, binary * `a+` | read-write, create, append * `ab+` or `a+b` | read-write, create, append, binary * @return An initialized OFFile */ - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; /** * @brief Initializes an already allocated OFFile. * * @param URL The URL to the file to open * @param mode The mode in which the file should be opened.@n * Possible modes are: |
︙ | ︙ | |||
142 143 144 145 146 147 148 | * `wb+` or `w+b` | read-write, create, truncate, binary * `a` | write-only, create, append * `ab` | write-only, create, append, binary * `a+` | read-write, create, append * `ab+` or `a+b` | read-write, create, append, binary * @return An initialized OFFile */ | | < | < | 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | * `wb+` or `w+b` | read-write, create, truncate, binary * `a` | write-only, create, append * `ab` | write-only, create, append, binary * `a+` | read-write, create, append * `ab+` or `a+b` | read-write, create, append, binary * @return An initialized OFFile */ - (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode; /** * @brief Initializes an already allocated OFFile. * * @param handle A native file handle. If OF_FILE_HANDLE_IS_FD is defined, this * is a file descriptor. The handle is closed when the OFFile * object is deallocated! * @return An initialized OFFile */ - (instancetype)initWithHandle: (OFFileHandle)handle OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/OFFile.m from [ea0a6a975e] to [87a6169ed1].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <assert.h> #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #include "unistd_wrapper.h" | > > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #define _LARGEFILE64_SOURCE #include <assert.h> #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #include "unistd_wrapper.h" |
︙ | ︙ | |||
73 74 75 76 77 78 79 | #ifndef O_EXLOCK # define O_EXLOCK 0 #endif #ifndef OF_AMIGAOS # define closeHandle(h) close(h) #else | | | | > > > > | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #ifndef O_EXLOCK # define O_EXLOCK 0 #endif #ifndef OF_AMIGAOS # define closeHandle(h) close(h) #else static struct _OFFileHandle { struct _OFFileHandle *previous, *next; BPTR handle; bool append; } *firstHandle = NULL; static void closeHandle(OFFileHandle handle) { Close(handle->handle); Forbid(); if (handle->previous != NULL) handle->previous->next = handle->next; if (handle->next != NULL) handle->next->previous = handle->previous; if (firstHandle == handle) firstHandle = handle->next; Permit(); OFFreeMemory(handle); } OF_DESTRUCTOR() { for (OFFileHandle iter = firstHandle; iter != NULL; iter = iter->next) Close(iter->handle); } #endif #ifndef OF_AMIGAOS static int |
︙ | ︙ | |||
176 177 178 179 180 181 182 | #ifdef OF_NINTENDO_DS if (!nitroFSInit(NULL)) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif } | | < | < | < | < | | < | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | #ifdef OF_NINTENDO_DS if (!nitroFSInit(NULL)) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif } + (instancetype)fileWithPath: (OFString *)path mode: (OFString *)mode { return [[[self alloc] initWithPath: path mode: mode] autorelease]; } + (instancetype)fileWithURL: (OFURL *)URL mode: (OFString *)mode { return [[[self alloc] initWithURL: URL mode: mode] autorelease]; } + (instancetype)fileWithHandle: (OFFileHandle)handle { return [[[self alloc] initWithHandle: handle] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode { OFFileHandle handle; @try { void *pool = objc_autoreleasePoolPush(); int flags; #ifndef OF_AMIGAOS if ((flags = parseMode(mode.UTF8String)) == -1) |
︙ | ︙ | |||
237 238 239 240 241 242 243 | if (handle == -1) @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errno]; #else | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | if (handle == -1) @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: errno]; #else handle = OFAllocMemory(1, sizeof(*handle)); @try { if ((flags = parseMode(mode.UTF8String, &handle->append)) == -1) @throw [OFInvalidArgumentException exception]; if ((handle->handle = Open([path cStringWithEncoding: [OFLocale encoding]], flags)) == 0) { |
︙ | ︙ | |||
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | Close(handle->handle); @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: EIO]; } } handle->previous = NULL; handle->next = firstHandle; if (firstHandle != NULL) firstHandle->previous = handle; firstHandle = handle; } @catch (id e) { | > > > > | | < | < | | | < | | 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | Close(handle->handle); @throw [OFOpenItemFailedException exceptionWithPath: path mode: mode errNo: EIO]; } } Forbid(); handle->previous = NULL; handle->next = firstHandle; if (firstHandle != NULL) firstHandle->previous = handle; firstHandle = handle; Permit(); } @catch (id e) { OFFreeMemory(handle); @throw e; } #endif objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @try { self = [self initWithHandle: handle]; } @catch (id e) { closeHandle(handle); @throw e; } return self; } - (instancetype)initWithURL: (OFURL *)URL mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFString *fileSystemRepresentation; @try { fileSystemRepresentation = URL.fileSystemRepresentation; } @catch (id e) { [self release]; @throw e; } self = [self initWithPath: fileSystemRepresentation mode: mode]; objc_autoreleasePoolPop(pool); return self; } - (instancetype)initWithHandle: (OFFileHandle)handle { self = [super init]; _handle = handle; return self; } - (bool)lowlevelIsAtEndOfStream { if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) if (length > UINT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = read(_handle, buffer, (unsigned int)length)) < 0) |
︙ | ︙ | |||
395 396 397 398 399 400 401 | if (ret == 0) _atEndOfStream = true; return ret; } | | < | | 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #if defined(OF_WINDOWS) int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
454 455 456 457 458 459 460 | bytesWritten: 0 errNo: errno]; #endif return (size_t)bytesWritten; } | < | | | | 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | bytesWritten: 0 errNo: errno]; #endif return (size_t)bytesWritten; } - (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence { OFFileOffset ret; if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_AMIGAOS # if defined(OF_WINDOWS) ret = _lseeki64(_handle, offset, whence); # elif defined(HAVE_LSEEK64) ret = lseek64(_handle, offset, whence); |
︙ | ︙ | |||
529 530 531 532 533 534 535 | { return _handle; } #endif - (void)close { | | | | | 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | { return _handle; } #endif - (void)close { if (_handle == OFInvalidFileHandle) @throw [OFNotOpenException exceptionWithObject: self]; closeHandle(_handle); _handle = OFInvalidFileHandle; [super close]; } - (void)dealloc { if (_handle != OFInvalidFileHandle) [self close]; [super dealloc]; } @end |
Modified src/OFFileManager.h from [4928c6d9ac] to [0757b002f6].
︙ | ︙ | |||
42 43 44 45 46 47 48 | @class OFURL; /** * @brief A key for a file attribute in the file attributes dictionary. * * Possible keys for file URLs are: * | | | | | | | | | | | | | | | | | | > | | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | > | > > > > > > > > | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | @class OFURL; /** * @brief A key for a file attribute in the file attributes dictionary. * * Possible keys for file URLs are: * * * @ref OFFileSize * * @ref OFFileType * * @ref OFFilePOSIXPermissions * * @ref OFFileOwnerAccountID * * @ref OFFileGroupOwnerAccountID * * @ref OFFileOwnerAccountName * * @ref OFFileGroupOwnerAccountName * * @ref OFFileLastAccessDate * * @ref OFFileModificationDate * * @ref OFFileStatusChangeDate * * @ref OFFileCreationDate * * @ref OFFileSymbolicLinkDestination * * Other URL schemes might not have all keys and might have keys not listed. */ typedef OFConstantString *OFFileAttributeKey; /** * @brief The type of a file. * * Possibles values for file URLs are: * * * @ref OFFileTypeRegular * * @ref OFFileTypeDirectory * * @ref OFFileTypeSymbolicLink * * @ref OFFileTypeFIFO * * @ref OFFileTypeCharacterSpecial * * @ref OFFileTypeBlockSpecial * * @ref OFFileTypeSocket * * @ref OFFileTypeUnknown * * Other URL schemes might not have all types and might have types not listed. */ typedef OFConstantString *OFFileAttributeType; /** * @brief A dictionary mapping keys of type @ref OFFileAttributeKey to their * attribute values. */ typedef OFDictionary OF_GENERIC(OFFileAttributeKey, id) *OFFileAttributes; /** * @brief A mutable dictionary mapping keys of type @ref OFFileAttributeKey to * their attribute values. */ typedef OFMutableDictionary OF_GENERIC(OFFileAttributeKey, id) *OFMutableFileAttributes; #ifdef __cplusplus extern "C" { #endif /** * @brief The size of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileSize. */ extern const OFFileAttributeKey OFFileSize; /** * @brief The type of the file. * * The corresponding value is of type @ref OFFileAttributeType. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileType. */ extern const OFFileAttributeKey OFFileType; /** * @brief The POSIX permissions of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#filePOSIXPermissions. */ extern const OFFileAttributeKey OFFilePOSIXPermissions; /** * @brief The account ID of the owner of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileOwnerAccountID. */ extern const OFFileAttributeKey OFFileOwnerAccountID; /** * @brief The account ID of the group owner of the file as an @ref OFNumber. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileGroupOwnerAccountID. */ extern const OFFileAttributeKey OFFileGroupOwnerAccountID; /** * @brief The account name of the owner of the file as an OFString. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileOwnerAccountName. */ extern const OFFileAttributeKey OFFileOwnerAccountName; /** * @brief The account name of the group owner of the file as an OFString. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileGroupOwnerAccountName. */ extern const OFFileAttributeKey OFFileGroupOwnerAccountName; /** * @brief The last access date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileLastAccessDate. */ extern const OFFileAttributeKey OFFileLastAccessDate; /** * @brief The last modification date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileModificationDate. */ extern const OFFileAttributeKey OFFileModificationDate; /** * @brief The last status change date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileStatusChangeDate. */ extern const OFFileAttributeKey OFFileStatusChangeDate; /** * @brief The creation date of the file as an @ref OFDate. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileCreationDate. */ extern const OFFileAttributeKey OFFileCreationDate; /** * @brief The destination of a symbolic link as an OFString. * * For convenience, a category on @ref OFDictionary is provided to access this * via @ref OFDictionary#fileSymbolicLinkDestination. */ extern const OFFileAttributeKey OFFileSymbolicLinkDestination; /** * @brief A regular file. */ extern const OFFileAttributeType OFFileTypeRegular; /** * @brief A directory. */ extern const OFFileAttributeType OFFileTypeDirectory; /** * @brief A symbolic link. */ extern const OFFileAttributeType OFFileTypeSymbolicLink; /** * @brief A FIFO. */ extern const OFFileAttributeType OFFileTypeFIFO; /** * @brief A character special file. */ extern const OFFileAttributeType OFFileTypeCharacterSpecial; /** * @brief A block special file. */ extern const OFFileAttributeType OFFileTypeBlockSpecial; /** * @brief A socket. */ extern const OFFileAttributeType OFFileTypeSocket; /** * @brief An unknown file type. * * This is different from not having an @ref OFFileType at all in that it means * that retrieving file types is supported, but the particular file type is * unknown. */ extern const OFFileAttributeType OFFileTypeUnknown; #ifdef __cplusplus } #endif /** * @class OFFileManager OFFileManager.h ObjFW/OFFileManager.h * |
︙ | ︙ | |||
267 268 269 270 271 272 273 | #ifdef OF_HAVE_FILES /** * @brief Returns the attributes for the item at the specified path. * * @param path The path to return the attributes for * @return A dictionary of attributes for the specified path, with the keys of | | | | | | < | | 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | #ifdef OF_HAVE_FILES /** * @brief Returns the attributes for the item at the specified path. * * @param path The path to return the attributes for * @return A dictionary of attributes for the specified path, with the keys of * type @ref OFFileAttributeKey */ - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path; #endif /** * @brief Returns the attributes for the item at the specified URL. * * @param URL The URL to return the attributes for * @return A dictionary of attributes for the specified URL, with the keys of * type @ref OFFileAttributeKey */ - (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL; #ifdef OF_HAVE_FILES /** * @brief Sets the attributes for the item at the specified path. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified path * @param path The path of the item to set the attributes for */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtPath: (OFString *)path; #endif /** * @brief Sets the attributes for the item at the specified URL. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified URL * @param URL The URL of the item to set the attributes for */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL; #ifdef OF_HAVE_FILES /** * @brief Checks whether a file exists at the specified path. * * @param path The path to check * @return A boolean whether there is a file at the specified path |
︙ | ︙ | |||
372 373 374 375 376 377 378 | /** * @brief Creates a directory at the specified URL. * * @param URL The URL of the directory to create * @param createParents Whether to create the parents of the directory */ | | < | > | | | 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | /** * @brief Creates a directory at the specified URL. * * @param URL The URL of the directory to create * @param createParents Whether to create the parents of the directory */ - (void)createDirectoryAtURL: (OFURL *)URL createParents: (bool)createParents; #ifdef OF_HAVE_FILES /** * @brief Returns an array with the items in the specified directory. * * @note `.` and `..` are not part of the returned array. * * @param path The path to the directory whose items should be returned * @return An array of OFString with the items in the specified directory */ - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path; #endif /** * @brief Returns an array with the URLs of the items in the specified * directory. * * @note `.` and `..` are not part of the returned array. * * @param URL The URL to the directory whose items should be returned * @return An array with the URLs of the items in the specified directory */ - (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL; #ifdef OF_HAVE_FILES /** * @brief Changes the current working directory. * * @param path The new directory to change to */ |
︙ | ︙ | |||
425 426 427 428 429 430 431 | * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination path */ | | < | < | < | < | 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination path */ - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Copies a file, directory or symbolic link (if supported by the OS). * * The destination URL must have a full path, which means it must include the * name of the item. * * If an item already exists, the copy operation fails. This is also the case * if a directory is copied and an item already exists in the destination * directory. * * @param source The file, directory or symbolic link to copy * @param destination The destination URL */ - (void)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination; #ifdef OF_HAVE_FILES /** * @brief Moves an item. * * The destination path must be a full path, which means it must include the * name of the item. * * If the destination is on a different logical device, the source will be * copied to the destination using @ref copyItemAtPath:toPath: and the source * removed using @ref removeItemAtPath:. * * @param source The item to rename * @param destination The new name for the item */ - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Moves an item. * * The destination URL must have a full path, which means it must include the * name of the item. * * If the destination is on a different logical device or uses a different * scheme, the source will be copied to the destination using * @ref copyItemAtURL:toURL: and the source removed using @ref removeItemAtURL:. * * @param source The item to rename * @param destination The new name for the item */ - (void)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination; #ifdef OF_HAVE_FILES /** * @brief Removes the item at the specified path. * * If the item at the specified path is a directory, it is removed recursively. * |
︙ | ︙ | |||
511 512 513 514 515 516 517 | * name of the item. * * This method is not available on some systems. * * @param source The path to the item for which a link should be created * @param destination The path to the item which should link to the source */ | | < | < | 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | * name of the item. * * This method is not available on some systems. * * @param source The path to the item for which a link should be created * @param destination The path to the item which should link to the source */ - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination; #endif /** * @brief Creates a hard link for the specified item. * * The destination URL must have a full path, which means it must include the * name of the item. * * This method is not available for all URLs. * * @param source The URL to the item for which a link should be created * @param destination The URL to the item which should link to the source */ - (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination; #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS /** * @brief Creates a symbolic link for an item. * * The destination path must be a full path, which means it must include the * name of the item. |
︙ | ︙ | |||
568 569 570 571 572 573 574 | */ - (void)createSymbolicLinkAtURL: (OFURL *)URL withDestinationPath: (OFString *)target; @end @interface OFDictionary (FileAttributes) /** | | | | | < | | | | | | | | < | < | < | | | < | 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | */ - (void)createSymbolicLinkAtURL: (OFURL *)URL withDestinationPath: (OFString *)target; @end @interface OFDictionary (FileAttributes) /** * @brief The @ref OFFileSize key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) unsigned long long fileSize; /** * @brief The @ref OFFileType key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFFileAttributeType fileType; /** * @brief The @ref OFFilePOSIXPermissions key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) unsigned long filePOSIXPermissions; /** * @brief The @ref OFFileOwnerAccountID key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) unsigned long fileOwnerAccountID; /** * @brief The @ref OFFileGroupOwnerAccountID key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) unsigned long fileGroupOwnerAccountID; /** * @brief The @ref OFFileOwnerAccountName key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFString *fileOwnerAccountName; /** * @brief The @ref OFFileGroupOwnerAccountName key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFString *fileGroupOwnerAccountName; /** * @brief The @ref OFFileLastAccessDate key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFDate *fileLastAccessDate; /** * @brief The @ref OFFileModificationDate key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFDate *fileModificationDate; /** * @brief The @ref OFFileStatusChangeDate key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFDate *fileStatusChangeDate; /** * @brief The @ref OFFileCreationDate key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFDate *fileCreationDate; /** * @brief The @ref OFFileSymbolicLinkDestination key from the dictionary. * * Raises an @ref OFUndefinedKeyException if the key is missing. */ @property (readonly, nonatomic) OFString *fileSymbolicLinkDestination; @end OF_ASSUME_NONNULL_END |
Modified src/OFFileManager.m from [6e650b26ed] to [4897ac9203].
︙ | ︙ | |||
87 88 89 90 91 92 93 | { if (dirChanged) UnLock(CurrentDir(originalDirLock)); } #endif static id | | < | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | { if (dirChanged) UnLock(CurrentDir(originalDirLock)); } #endif static id attributeForKeyOrException(OFFileAttributes attributes, OFFileAttributeKey key) { id object = [attributes objectForKey: key]; if (object == nil) @throw [OFUndefinedKeyException exceptionWithObject: attributes key: key]; |
︙ | ︙ | |||
195 196 197 198 199 200 201 | [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif | | | | < | | < | < < | 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL { OFURLHandler *URLHandler; if (URL == nil) @throw [OFInvalidArgumentException exception]; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; return [URLHandler attributesOfItemAtURL: URL]; } #ifdef OF_HAVE_FILES - (OFFileAttributes)attributesOfItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFFileAttributes ret; ret = [self attributesOfItemAtURL: [OFURL fileURLWithPath: path]]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL { OFURLHandler *URLHandler; if (URL == nil) @throw [OFInvalidArgumentException exception]; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; [URLHandler setAttributes: attributes ofItemAtURL: URL]; } #ifdef OF_HAVE_FILES - (void)setAttributes: (OFFileAttributes)attributes ofItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self setAttributes: attributes ofItemAtURL: [OFURL fileURLWithPath: path]]; objc_autoreleasePoolPop(pool); } #endif - (bool)fileExistsAtURL: (OFURL *)URL { OFURLHandler *URLHandler; |
︙ | ︙ | |||
423 424 425 426 427 428 429 | [self createDirectoryAtURL: [OFURL fileURLWithPath: path] createParents: createParents]; objc_autoreleasePoolPop(pool); } #endif | | | > | > > > > | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | [self createDirectoryAtURL: [OFURL fileURLWithPath: path] createParents: createParents]; objc_autoreleasePoolPop(pool); } #endif - (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL { OFURLHandler *URLHandler; if (URL == nil) @throw [OFInvalidArgumentException exception]; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; return [URLHandler contentsOfDirectoryAtURL: URL]; } #ifdef OF_HAVE_FILES - (OFArray OF_GENERIC(OFString *) *)contentsOfDirectoryAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFURL *) *URLs; OFMutableArray OF_GENERIC(OFString *) *ret; URLs = [self contentsOfDirectoryAtURL: [OFURL fileURLWithPath: path]]; ret = [OFMutableArray arrayWithCapacity: URLs.count]; for (OFURL *URL in URLs) [ret addObject: URL.lastPathComponent]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } |
︙ | ︙ | |||
516 517 518 519 520 521 522 | void *pool = objc_autoreleasePoolPush(); [self changeCurrentDirectoryPath: URL.fileSystemRepresentation]; objc_autoreleasePoolPop(pool); } | | < | < | | | < | | | < | | 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | void *pool = objc_autoreleasePoolPush(); [self changeCurrentDirectoryPath: URL.fileSystemRepresentation]; objc_autoreleasePoolPop(pool); } - (void)copyItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self copyItemAtURL: [OFURL fileURLWithPath: source] toURL: [OFURL fileURLWithPath: destination]]; objc_autoreleasePoolPop(pool); } #endif - (void)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool; OFURLHandler *URLHandler; OFFileAttributes attributes; OFFileAttributeType type; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: source]; if ([URLHandler copyItemAtURL: source toURL: destination]) return; if ([self fileExistsAtURL: destination]) @throw [OFCopyItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: EEXIST]; @try { attributes = [self attributesOfItemAtURL: source]; } @catch (OFRetrieveItemAttributesFailedException *e) { @throw [OFCopyItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: e.errNo]; } type = attributes.fileType; if ([type isEqual: OFFileTypeDirectory]) { OFArray OF_GENERIC(OFURL *) *contents; @try { [self createDirectoryAtURL: destination]; @try { OFFileAttributeKey key = OFFilePOSIXPermissions; OFNumber *permissions = [attributes objectForKey: key]; OFFileAttributes destinationAttributes; if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes |
︙ | ︙ | |||
607 608 609 610 611 612 613 | exceptionWithSourceURL: source destinationURL: destination errNo: [e errNo]]; @throw e; } | | | < < | < | | < | | | < | | 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | exceptionWithSourceURL: source destinationURL: destination errNo: [e errNo]]; @throw e; } for (OFURL *item in contents) { void *pool2 = objc_autoreleasePoolPush(); OFURL *destinationURL = [destination URLByAppendingPathComponent: item.lastPathComponent]; [self copyItemAtURL: item toURL: destinationURL]; objc_autoreleasePoolPop(pool2); } } else if ([type isEqual: OFFileTypeRegular]) { size_t pageSize = [OFSystemInfo pageSize]; OFStream *sourceStream = nil; OFStream *destinationStream = nil; char *buffer; buffer = OFAllocMemory(1, pageSize); @try { sourceStream = [[OFURLHandler handlerForURL: source] openItemAtURL: source mode: @"r"]; destinationStream = [[OFURLHandler handlerForURL: destination] openItemAtURL: destination mode: @"w"]; while (!sourceStream.atEndOfStream) { size_t length; length = [sourceStream readIntoBuffer: buffer length: pageSize]; [destinationStream writeBuffer: buffer length: length]; } @try { OFFileAttributeKey key = OFFilePOSIXPermissions; OFNumber *permissions = [attributes objectForKey: key]; OFFileAttributes destinationAttributes; if (permissions != nil) { destinationAttributes = [OFDictionary dictionaryWithObject: permissions forKey: key]; [self setAttributes: destinationAttributes |
︙ | ︙ | |||
680 681 682 683 684 685 686 | destinationURL: destination errNo: [e errNo]]; @throw e; } @finally { [sourceStream close]; [destinationStream close]; | | | | 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | destinationURL: destination errNo: [e errNo]]; @throw e; } @finally { [sourceStream close]; [destinationStream close]; OFFreeMemory(buffer); } } else if ([type isEqual: OFFileTypeSymbolicLink]) { @try { OFString *linkDestination = attributes.fileSymbolicLinkDestination; [self createSymbolicLinkAtURL: destination withDestinationPath: linkDestination]; } @catch (id e) { |
︙ | ︙ | |||
714 715 716 717 718 719 720 | destinationURL: destination errNo: EINVAL]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_FILES | | < < < | < | < | < | 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | destinationURL: destination errNo: EINVAL]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_FILES - (void)moveItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self moveItemAtURL: [OFURL fileURLWithPath: source] toURL: [OFURL fileURLWithPath: destination]]; objc_autoreleasePoolPop(pool); } #endif - (void)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool; OFURLHandler *URLHandler; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); if ((URLHandler = [OFURLHandler handlerForURL: source]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: source]; @try { if ([URLHandler moveItemAtURL: source toURL: destination]) return; } @catch (OFMoveItemFailedException *e) { if (e.errNo != EXDEV) @throw e; } if ([self fileExistsAtURL: destination]) @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: EEXIST]; @try { [self copyItemAtURL: source toURL: destination]; } @catch (OFCopyItemFailedException *e) { [self removeItemAtURL: destination]; @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: e.errNo]; |
︙ | ︙ | |||
797 798 799 800 801 802 803 | [URLHandler removeItemAtURL: URL]; } #ifdef OF_HAVE_FILES - (void)removeItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); | < < | < | < | < < < | < < < | 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 | [URLHandler removeItemAtURL: URL]; } #ifdef OF_HAVE_FILES - (void)removeItemAtPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); [self removeItemAtURL: [OFURL fileURLWithPath: path]]; objc_autoreleasePoolPop(pool); } #endif - (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool = objc_autoreleasePoolPush(); OFURLHandler *URLHandler; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; if (![destination.scheme isEqual: source.scheme]) @throw [OFInvalidArgumentException exception]; URLHandler = [OFURLHandler handlerForURL: source]; if (URLHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: source]; [URLHandler linkItemAtURL: source toURL: destination]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS - (void)linkItemAtPath: (OFString *)source toPath: (OFString *)destination { void *pool = objc_autoreleasePoolPush(); [self linkItemAtURL: [OFURL fileURLWithPath: source] toURL: [OFURL fileURLWithPath: destination]]; objc_autoreleasePoolPop(pool); } #endif - (void)createSymbolicLinkAtURL: (OFURL *)URL withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); OFURLHandler *URLHandler; if (URL == nil || target == nil) @throw [OFInvalidArgumentException exception]; URLHandler = [OFURLHandler handlerForURL: URL]; if (URLHandler == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; [URLHandler createSymbolicLinkAtURL: URL withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS - (void)createSymbolicLinkAtPath: (OFString *)path withDestinationPath: (OFString *)target { void *pool = objc_autoreleasePoolPush(); [self createSymbolicLinkAtURL: [OFURL fileURLWithPath: path] withDestinationPath: target]; objc_autoreleasePoolPop(pool); } #endif @end @implementation OFDefaultFileManager - (instancetype)autorelease |
︙ | ︙ | |||
892 893 894 895 896 897 898 | - (void)release { } - (unsigned int)retainCount { | | | | | | | | | | | | | | | < | < | < | < | < | 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } @end @implementation OFDictionary (FileAttributes) - (unsigned long long)fileSize { return [attributeForKeyOrException(self, OFFileSize) unsignedLongLongValue]; } - (OFFileAttributeType)fileType { return attributeForKeyOrException(self, OFFileType); } - (unsigned long)filePOSIXPermissions { return [attributeForKeyOrException(self, OFFilePOSIXPermissions) unsignedLongValue]; } - (unsigned long)fileOwnerAccountID { return [attributeForKeyOrException(self, OFFileOwnerAccountID) unsignedLongValue]; } - (unsigned long)fileGroupOwnerAccountID { return [attributeForKeyOrException(self, OFFileGroupOwnerAccountID) unsignedLongValue]; } - (OFString *)fileOwnerAccountName { return attributeForKeyOrException(self, OFFileOwnerAccountName); } - (OFString *)fileGroupOwnerAccountName { return attributeForKeyOrException(self, OFFileGroupOwnerAccountName); } - (OFDate *)fileLastAccessDate { return attributeForKeyOrException(self, OFFileLastAccessDate); } - (OFDate *)fileModificationDate { return attributeForKeyOrException(self, OFFileModificationDate); } - (OFDate *)fileStatusChangeDate { return attributeForKeyOrException(self, OFFileStatusChangeDate); } - (OFDate *)fileCreationDate { return attributeForKeyOrException(self, OFFileCreationDate); } - (OFString *)fileSymbolicLinkDestination { return attributeForKeyOrException(self, OFFileSymbolicLinkDestination); } @end |
Modified src/OFFileManager_constants.m from [b0c2ffa8b8] to [e875ee7ab5].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | < | < | < | < | < | < | > | | < | | | < | < | < | | < < > > | | | < > | > | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ const OFFileAttributeKey OFFileSize = @"OFFileSize"; const OFFileAttributeKey OFFileType = @"OFFileType"; const OFFileAttributeKey OFFilePOSIXPermissions = @"OFFilePOSIXPermissions"; const OFFileAttributeKey OFFileOwnerAccountID = @"OFFileOwnerAccountID"; const OFFileAttributeKey OFFileGroupOwnerAccountID = @"OFFileGroupOwnerAccountID"; const OFFileAttributeKey OFFileOwnerAccountName = @"OFFileOwnerAccountName"; const OFFileAttributeKey OFFileGroupOwnerAccountName = @"OFFileGroupOwnerAccountName"; const OFFileAttributeKey OFFileLastAccessDate = @"OFFileLastAccessDate"; const OFFileAttributeKey OFFileModificationDate = @"OFFileModificationDate"; const OFFileAttributeKey OFFileStatusChangeDate = @"OFFileStatusChangeDate"; const OFFileAttributeKey OFFileCreationDate = @"OFFileCreationDate"; const OFFileAttributeKey OFFileSymbolicLinkDestination = @"OFFileSymbolicLinkDestination"; const OFFileAttributeType OFFileTypeRegular = @"OFFileTypeRegular"; const OFFileAttributeType OFFileTypeDirectory = @"OFFileTypeDirectory"; const OFFileAttributeType OFFileTypeSymbolicLink = @"OFFileTypeSymbolicLink"; const OFFileAttributeType OFFileTypeFIFO = @"OFFileTypeFIFO"; const OFFileAttributeType OFFileTypeCharacterSpecial = @"OFFileTypeCharacterSpecial"; const OFFileAttributeType OFFileTypeBlockSpecial = @"OFFileTypeBlockSpecial"; const OFFileAttributeType OFFileTypeSocket = @"OFFileTypeSocket"; const OFFileAttributeType OFFileTypeUnknown = @"OFFileTypeUnknown"; |
Modified src/OFFileURLHandler.m from [e65a587713] to [b0e449d601].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <errno.h> #include <math.h> #ifdef HAVE_DIRENT_H # include <dirent.h> #endif #include "unistd_wrapper.h" | > > | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #define _LARGEFILE64_SOURCE #include <errno.h> #include <math.h> #ifdef HAVE_DIRENT_H # include <dirent.h> #endif #include "unistd_wrapper.h" |
︙ | ︙ | |||
81 82 83 84 85 86 87 | # ifdef OF_AMIGAOS4 # define DeleteFile(path) Delete(path) # endif #endif #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) typedef struct { | | | | | | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | # ifdef OF_AMIGAOS4 # define DeleteFile(path) Delete(path) # endif #endif #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) typedef struct { OFFileOffset st_size; unsigned int st_mode; OFTimeInterval st_atime, st_mtime, st_ctime; # ifdef OF_WINDOWS # define HAVE_STRUCT_STAT_ST_BIRTHTIME OFTimeInterval st_birthtime; DWORD fileAttributes; # endif } Stat; #elif defined(HAVE_STAT64) typedef struct stat64 Stat; #else typedef struct stat Stat; #endif #ifdef OF_WINDOWS # define S_IFLNK 0x10000 # define S_ISLNK(mode) (mode & S_IFLNK) #endif |
︙ | ︙ | |||
121 122 123 124 125 126 127 | releaseReaddirMutex(void) { [readdirMutex release]; } #endif #ifdef OF_WINDOWS | | | | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | releaseReaddirMutex(void) { [readdirMutex release]; } #endif #ifdef OF_WINDOWS static int (*_wutime64FuncPtr)(const wchar_t *, struct __utimbuf64 *); static WINAPI BOOLEAN (*createSymbolicLinkWFuncPtr)(LPCWSTR, LPCWSTR, DWORD); static WINAPI BOOLEAN (*createHardLinkWFuncPtr)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); #endif #ifdef OF_WINDOWS static OFTimeInterval filetimeToTimeInterval(const FILETIME *filetime) { return (double)((int64_t)filetime->dwHighDateTime << 32 | filetime->dwLowDateTime) / 10000000.0 - 11644473600.0; } static int |
︙ | ︙ | |||
190 191 192 193 194 195 196 | default: return EIO; } } #endif static int | | | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | default: return EIO; } } #endif static int statWrapper(OFString *path, Stat *buffer) { #if defined(OF_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA data; bool success; if ([OFSystemInfo isWindowsNT]) success = GetFileAttributesExW(path.UTF16String, |
︙ | ︙ | |||
256 257 258 259 260 261 262 | #elif defined(OF_AMIGAOS) BPTR lock; # ifdef OF_AMIGAOS4 struct ExamineData *ed; # else struct FileInfoBlock fib; # endif | | | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | #elif defined(OF_AMIGAOS) BPTR lock; # ifdef OF_AMIGAOS4 struct ExamineData *ed; # else struct FileInfoBlock fib; # endif OFTimeInterval timeInterval; struct Locale *locale; struct DateStamp *date; if ((lock = Lock([path cStringWithEncoding: [OFLocale encoding]], SHARED_LOCK)) == 0) return retrieveError(); |
︙ | ︙ | |||
309 310 311 312 313 314 315 | # ifdef OF_AMIGAOS4 date = &ed->Date; # else date = &fib.fib_Date; # endif timeInterval += date->ds_Days * 86400.0; timeInterval += date->ds_Minute * 60.0; | | | 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | # ifdef OF_AMIGAOS4 date = &ed->Date; # else date = &fib.fib_Date; # endif timeInterval += date->ds_Days * 86400.0; timeInterval += date->ds_Minute * 60.0; timeInterval += date->ds_Tick / (OFTimeInterval)TICKS_PER_SECOND; buffer->st_atime = buffer->st_mtime = buffer->st_ctime = timeInterval; # ifdef OF_AMIGAOS4 FreeDosObject(DOS_EXAMINEDATA, ed); # endif |
︙ | ︙ | |||
333 334 335 336 337 338 339 | return errno; return 0; #endif } static int | | | | | < | < | | | < | | | | | < > > | | | | | | < | | | | | | | < < | | < | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | return errno; return 0; #endif } static int lstatWrapper(OFString *path, Stat *buffer) { #if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && \ !defined(OF_NINTENDO_3DS) && !defined(OF_WII) # ifdef HAVE_LSTAT64 if (lstat64([path cStringWithEncoding: [OFLocale encoding]], buffer) != 0) return errno; # else if (lstat([path cStringWithEncoding: [OFLocale encoding]], buffer) != 0) return errno; # endif return 0; #else return statWrapper(path, buffer); #endif } static void setTypeAttribute(OFMutableFileAttributes attributes, Stat *s) { if (S_ISREG(s->st_mode)) [attributes setObject: OFFileTypeRegular forKey: OFFileType]; else if (S_ISDIR(s->st_mode)) [attributes setObject: OFFileTypeDirectory forKey: OFFileType]; #ifdef S_ISLNK else if (S_ISLNK(s->st_mode)) [attributes setObject: OFFileTypeSymbolicLink forKey: OFFileType]; #endif #ifdef S_ISFIFO else if (S_ISFIFO(s->st_mode)) [attributes setObject: OFFileTypeFIFO forKey: OFFileType]; #endif #ifdef S_ISCHR else if (S_ISCHR(s->st_mode)) [attributes setObject: OFFileTypeCharacterSpecial forKey: OFFileType]; #endif #ifdef S_ISBLK else if (S_ISBLK(s->st_mode)) [attributes setObject: OFFileTypeBlockSpecial forKey: OFFileType]; #endif #ifdef S_ISSOCK else if (S_ISSOCK(s->st_mode)) [attributes setObject: OFFileTypeSocket forKey: OFFileType]; #endif else [attributes setObject: OFFileTypeUnknown forKey: OFFileType]; } static void setDateAttributes(OFMutableFileAttributes attributes, Stat *s) { /* FIXME: We could be more precise on some OSes */ [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_atime] forKey: OFFileLastAccessDate]; [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_mtime] forKey: OFFileModificationDate]; [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_ctime] forKey: OFFileStatusChangeDate]; #ifdef HAVE_STRUCT_STAT_ST_BIRTHTIME [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_birthtime] forKey: OFFileCreationDate]; #endif } static void setOwnerAndGroupAttributes(OFMutableFileAttributes attributes, Stat *s) { #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_uid] forKey: OFFileOwnerAccountID]; [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_gid] forKey: OFFileGroupOwnerAccountID]; # ifdef OF_HAVE_THREADS [passwdMutex lock]; @try { # endif OFStringEncoding encoding = [OFLocale encoding]; struct passwd *passwd = getpwuid(s->st_uid); struct group *group_ = getgrgid(s->st_gid); if (passwd != NULL) { OFString *owner = [OFString stringWithCString: passwd->pw_name encoding: encoding]; [attributes setObject: owner forKey: OFFileOwnerAccountName]; } if (group_ != NULL) { OFString *group = [OFString stringWithCString: group_->gr_name encoding: encoding]; [attributes setObject: group forKey: OFFileGroupOwnerAccountName]; } # ifdef OF_HAVE_THREADS } @finally { [passwdMutex unlock]; } # endif #endif } #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS static void setSymbolicLinkDestinationAttribute(OFMutableFileAttributes attributes, OFURL *URL) { OFString *path = URL.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; char destinationC[PATH_MAX]; ssize_t length; OFString *destination; length = readlink([path cStringWithEncoding: encoding], destinationC, PATH_MAX); if (length < 0) @throw [OFRetrieveItemAttributesFailedException exceptionWithURL: URL errNo: errno]; destination = [OFString stringWithCString: destinationC encoding: encoding length: length]; [attributes setObject: destination forKey: OFFileSymbolicLinkDestination]; # else HANDLE handle; OFString *destination; if (createSymbolicLinkWFuncPtr == NULL) return; if ((handle = CreateFileW(path.UTF16String, 0, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL)) == INVALID_HANDLE_VALUE) @throw [OFRetrieveItemAttributesFailedException exceptionWithURL: URL errNo: retrieveError()]; @try { union { char bytes[MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; REPARSE_DATA_BUFFER data; } buffer; DWORD size; wchar_t *tmp; if (!DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0, buffer.bytes, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, &size, NULL)) @throw [OFRetrieveItemAttributesFailedException exceptionWithURL: URL errNo: retrieveError()]; |
︙ | ︙ | |||
523 524 525 526 527 528 529 | (slrb.SubstituteNameOffset / sizeof(wchar_t)); destination = [OFString stringWithUTF16String: tmp length: slrb.SubstituteNameLength / sizeof(wchar_t)]; | | | < | | 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | (slrb.SubstituteNameOffset / sizeof(wchar_t)); destination = [OFString stringWithUTF16String: tmp length: slrb.SubstituteNameLength / sizeof(wchar_t)]; [attributes setObject: OFFileTypeSymbolicLink forKey: OFFileType]; [attributes setObject: destination forKey: OFFileSymbolicLinkDestination]; # undef slrb } @finally { CloseHandle(handle); } # endif } #endif |
︙ | ︙ | |||
557 558 559 560 561 562 563 | #if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS) readdirMutex = [[OFMutex alloc] init]; atexit(releaseReaddirMutex); #endif #ifdef OF_WINDOWS if ((module = LoadLibrary("msvcrt.dll")) != NULL) | | | | | | | < | | | | | | | | | < | | | 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | #if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS) readdirMutex = [[OFMutex alloc] init]; atexit(releaseReaddirMutex); #endif #ifdef OF_WINDOWS if ((module = LoadLibrary("msvcrt.dll")) != NULL) _wutime64FuncPtr = (int (*)(const wchar_t *, struct __utimbuf64 *))GetProcAddress(module, "_wutime64"); if ((module = LoadLibrary("kernel32.dll")) != NULL) { createSymbolicLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD)) GetProcAddress(module, "CreateSymbolicLinkW"); createHardLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES)) GetProcAddress(module, "CreateHardLinkW"); } #endif /* * Make sure OFFile is initialized. * On some systems, this is needed to initialize the file system driver. */ [OFFile class]; } + (bool)of_directoryExistsAtPath: (OFString *)path { Stat s; if (statWrapper(path, &s) != 0) return false; return S_ISDIR(s.st_mode); } - (OFStream *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode { void *pool = objc_autoreleasePoolPush(); OFFile *file = [[OFFile alloc] initWithPath: URL.fileSystemRepresentation mode: mode]; objc_autoreleasePoolPop(pool); return [file autorelease]; } - (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL { OFMutableFileAttributes ret = [OFMutableDictionary dictionary]; void *pool = objc_autoreleasePoolPush(); OFString *path; int error; Stat s; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![[URL scheme] isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URL.fileSystemRepresentation; if ((error = lstatWrapper(path, &s)) != 0) @throw [OFRetrieveItemAttributesFailedException exceptionWithURL: URL errNo: error]; if (s.st_size < 0) @throw [OFOutOfRangeException exception]; [ret setObject: [NSNumber numberWithUnsignedLongLong: s.st_size] forKey: OFFileSize]; setTypeAttribute(ret, &s); [ret setObject: [NSNumber numberWithUnsignedLong: s.st_mode] forKey: OFFilePOSIXPermissions]; setOwnerAndGroupAttributes(ret, &s); setDateAttributes(ret, &s); #ifdef OF_FILE_MANAGER_SUPPORTS_SYMLINKS if (S_ISLNK(s.st_mode)) setSymbolicLinkDestinationAttribute(ret, URL); #endif objc_autoreleasePoolPop(pool); return ret; } - (void)of_setLastAccessDate: (OFDate *)lastAccessDate andModificationDate: (OFDate *)modificationDate ofItemAtURL: (OFURL *)URL attributes: (OFFileAttributes)attributes OF_DIRECT { OFString *path = URL.fileSystemRepresentation; OFFileAttributeKey attributeKey = (modificationDate != nil ? OFFileModificationDate : OFFileLastAccessDate); if (lastAccessDate == nil) lastAccessDate = modificationDate; if (modificationDate == nil) modificationDate = lastAccessDate; #if defined(OF_WINDOWS) if (_wutime64FuncPtr != NULL) { struct __utimbuf64 times = { .actime = (__time64_t)lastAccessDate.timeIntervalSince1970, .modtime = (__time64_t)modificationDate.timeIntervalSince1970 }; if (_wutime64FuncPtr([path UTF16String], ×) != 0) @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey errNo: errno]; } else { struct _utimbuf times = { |
︙ | ︙ | |||
700 701 702 703 704 705 706 | exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey errNo: errno]; } #elif defined(OF_AMIGAOS) /* AmigaOS does not support access time. */ | | | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 | exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey errNo: errno]; } #elif defined(OF_AMIGAOS) /* AmigaOS does not support access time. */ OFTimeInterval modificationTime = modificationDate.timeIntervalSince1970; struct Locale *locale; struct DateStamp date; modificationTime -= 252460800; /* 1978-01-01 */ if (modificationTime < 0) |
︙ | ︙ | |||
736 737 738 739 740 741 742 | # endif @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey errNo: retrieveError()]; #else | < | | | 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | # endif @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey errNo: retrieveError()]; #else OFTimeInterval lastAccessTime = lastAccessDate.timeIntervalSince1970; OFTimeInterval modificationTime = modificationDate.timeIntervalSince1970; struct timeval times[2] = { { .tv_sec = (time_t)lastAccessTime, .tv_usec = (int)((lastAccessTime - times[0].tv_sec) * 1000000) }, |
︙ | ︙ | |||
764 765 766 767 768 769 770 | failedAttribute: attributeKey errNo: errno]; #endif } - (void)of_setPOSIXPermissions: (OFNumber *)permissions ofItemAtURL: (OFURL *)URL | | | | | | | | | | 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | failedAttribute: attributeKey errNo: errno]; #endif } - (void)of_setPOSIXPermissions: (OFNumber *)permissions ofItemAtURL: (OFURL *)URL attributes: (OFFileAttributes)attributes OF_DIRECT { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS mode_t mode = (mode_t)permissions.unsignedLongValue; OFString *path = URL.fileSystemRepresentation; int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wchmod(path.UTF16String, mode); else # endif status = chmod( [path cStringWithEncoding: [OFLocale encoding]], mode); if (status != 0) @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes failedAttribute: OFFilePOSIXPermissions errNo: errno]; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)of_setOwnerAccountName: (OFString *)owner andGroupOwnerAccountName: (OFString *)group ofItemAtURL: (OFURL *)URL attributeKey: (OFFileAttributeKey)attributeKey attributes: (OFFileAttributes)attributes OF_DIRECT { #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER OFString *path = URL.fileSystemRepresentation; uid_t uid = -1; gid_t gid = -1; OFStringEncoding encoding; if (owner == nil && group == nil) @throw [OFInvalidArgumentException exception]; encoding = [OFLocale encoding]; # ifdef OF_HAVE_THREADS |
︙ | ︙ | |||
855 856 857 858 859 860 861 | failedAttribute: attributeKey errNo: errno]; #else OF_UNRECOGNIZED_SELECTOR #endif } | < | | | | | | | | | | | | | | | | | | | < | < | | | | | 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 | failedAttribute: attributeKey errNo: errno]; #else OF_UNRECOGNIZED_SELECTOR #endif } - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); OFEnumerator OF_GENERIC(OFFileAttributeKey) *keyEnumerator; OFEnumerator *objectEnumerator; OFFileAttributeKey key; id object; OFDate *lastAccessDate, *modificationDate; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; keyEnumerator = [attributes keyEnumerator]; objectEnumerator = [attributes objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { if ([key isEqual: OFFileModificationDate] || [key isEqual: OFFileLastAccessDate]) continue; else if ([key isEqual: OFFilePOSIXPermissions]) [self of_setPOSIXPermissions: object ofItemAtURL: URL attributes: attributes]; else if ([key isEqual: OFFileOwnerAccountName]) [self of_setOwnerAccountName: object andGroupOwnerAccountName: nil ofItemAtURL: URL attributeKey: key attributes: attributes]; else if ([key isEqual: OFFileGroupOwnerAccountName]) [self of_setOwnerAccountName: nil andGroupOwnerAccountName: object ofItemAtURL: URL attributeKey: key attributes: attributes]; else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; } lastAccessDate = [attributes objectForKey: OFFileLastAccessDate]; modificationDate = [attributes objectForKey: OFFileModificationDate]; if (lastAccessDate != nil || modificationDate != nil) [self of_setLastAccessDate: lastAccessDate andModificationDate: modificationDate ofItemAtURL: URL attributes: attributes]; objc_autoreleasePoolPop(pool); } - (bool)fileExistsAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); Stat s; bool ret; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; if (statWrapper(URL.fileSystemRepresentation, &s) != 0) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISREG(s.st_mode); objc_autoreleasePoolPop(pool); return ret; } - (bool)directoryExistsAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); Stat s; bool ret; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; if (statWrapper(URL.fileSystemRepresentation, &s) != 0) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISDIR(s.st_mode); objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
1009 1010 1011 1012 1013 1014 1015 | exceptionWithURL: URL errNo: errno]; #endif objc_autoreleasePoolPop(pool); } | | | | 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | exceptionWithURL: URL errNo: errno]; #endif objc_autoreleasePoolPop(pool); } - (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL { OFMutableArray *URLs = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); OFString *path; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) |
︙ | ︙ | |||
1049 1050 1051 1052 1053 1054 1055 | if (wcscmp(fd.cFileName, L".") == 0 || wcscmp(fd.cFileName, L"..") == 0) continue; file = [[OFString alloc] initWithUTF16String: fd.cFileName]; @try { | | > | | 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | if (wcscmp(fd.cFileName, L".") == 0 || wcscmp(fd.cFileName, L"..") == 0) continue; file = [[OFString alloc] initWithUTF16String: fd.cFileName]; @try { [URLs addObject: [URL URLByAppendingPathComponent: file]]; } @finally { [file release]; } } while (FindNextFileW(handle, &fd)); if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: retrieveError()]; } @finally { FindClose(handle); } } else { OFStringEncoding encoding = [OFLocale encoding]; WIN32_FIND_DATA fd; if ((handle = FindFirstFileA( [path cStringWithEncoding: encoding], &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenItemFailedException exceptionWithURL: URL |
︙ | ︙ | |||
1087 1088 1089 1090 1091 1092 1093 | strcmp(fd.cFileName, "..") == 0) continue; file = [[OFString alloc] initWithCString: fd.cFileName encoding: encoding]; @try { | | > | | 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | strcmp(fd.cFileName, "..") == 0) continue; file = [[OFString alloc] initWithCString: fd.cFileName encoding: encoding]; @try { [URLs addObject: [URL URLByAppendingPathComponent: file]]; } @finally { [file release]; } } while (FindNextFileA(handle, &fd)); if (GetLastError() != ERROR_NO_MORE_FILES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: retrieveError()]; } @finally { FindClose(handle); } } #elif defined(OF_AMIGAOS) OFStringEncoding encoding = [OFLocale encoding]; BPTR lock; if ((lock = Lock([path cStringWithEncoding: encoding], SHARED_LOCK)) == 0) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil |
︙ | ︙ | |||
1133 1134 1135 1136 1137 1138 1139 | @try { while ((ed = ExamineDir(context)) != NULL) { OFString *file = [[OFString alloc] initWithCString: ed->Name encoding: encoding]; @try { | | > < | > | < | 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 | @try { while ((ed = ExamineDir(context)) != NULL) { OFString *file = [[OFString alloc] initWithCString: ed->Name encoding: encoding]; @try { [URLs addObject: [URL URLByAppendingPathComponent: file]]; } @finally { [file release]; } } } @finally { ReleaseDirContext(context); } # else struct FileInfoBlock fib; if (!Examine(lock, &fib)) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil errNo: retrieveError()]; while (ExNext(lock, &fib)) { OFString *file = [[OFString alloc] initWithCString: fib.fib_FileName encoding: encoding]; @try { [URLs addObject: [URL URLByAppendingPathComponent: file]]; } @finally { [file release]; } } # endif if (IoErr() != ERROR_NO_MORE_ENTRIES) @throw [OFReadFailedException exceptionWithObject: self requestedLength: 0 errNo: retrieveError()]; } @finally { UnLock(lock); } #else OFStringEncoding encoding = [OFLocale encoding]; DIR *dir; if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL) @throw [OFOpenItemFailedException exceptionWithURL: URL mode: nil errNo: errno]; # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) @try { |
︙ | ︙ | |||
1226 1227 1228 1229 1230 1231 1232 | if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue; file = [[OFString alloc] initWithCString: dirent->d_name encoding: encoding]; @try { | | > | | | | | | | < | 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 | if (strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) continue; file = [[OFString alloc] initWithCString: dirent->d_name encoding: encoding]; @try { [URLs addObject: [URL URLByAppendingPathComponent: file]]; } @finally { [file release]; } } } @finally { closedir(dir); # if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) [readdirMutex unlock]; # endif } #endif [URLs makeImmutable]; objc_autoreleasePoolPop(pool); return URLs; } - (void)removeItemAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); OFString *path; int error; Stat s; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URL.fileSystemRepresentation; if ((error = lstatWrapper(path, &s)) != 0) @throw [OFRemoveItemFailedException exceptionWithURL: URL errNo: error]; if (S_ISDIR(s.st_mode)) { OFArray OF_GENERIC(OFURL *) *contents; @try { contents = [self contentsOfDirectoryAtURL: URL]; } @catch (id e) { /* * Only convert exceptions to * OFRemoveItemFailedException that have an errNo * property. This covers all I/O related exceptions * from the operations used to remove an item, all * others should be left as is. */ if ([e respondsToSelector: @selector(errNo)]) @throw [OFRemoveItemFailedException exceptionWithURL: URL errNo: [e errNo]]; @throw e; } for (OFURL *item in contents) { void *pool2 = objc_autoreleasePoolPush(); [self removeItemAtURL: item]; objc_autoreleasePoolPop(pool2); } #ifndef OF_AMIGAOS int status; |
︙ | ︙ | |||
1339 1340 1341 1342 1343 1344 1345 | errNo: retrieveError()]; #endif objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS | | < | | | | 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 | errNo: retrieveError()]; #endif objc_autoreleasePoolPop(pool); } #ifdef OF_FILE_MANAGER_SUPPORTS_LINKS - (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool = objc_autoreleasePoolPush(); OFString *sourcePath, *destinationPath; if (source == nil || destination == nil) @throw [OFInvalidArgumentException exception]; if (![source.scheme isEqual: _scheme] || ![destination.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; sourcePath = source.fileSystemRepresentation; destinationPath = destination.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; if (link([sourcePath cStringWithEncoding: encoding], [destinationPath cStringWithEncoding: encoding]) != 0) @throw [OFLinkFailedException exceptionWithSourceURL: source destinationURL: destination errNo: errno]; # else if (createHardLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (!createHardLinkWFuncPtr(destinationPath.UTF16String, sourcePath.UTF16String, NULL)) @throw [OFLinkFailedException exceptionWithSourceURL: source destinationURL: destination errNo: retrieveError()]; # endif |
︙ | ︙ | |||
1397 1398 1399 1400 1401 1402 1403 | if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URL.fileSystemRepresentation; # ifndef OF_WINDOWS | | | | > | < | | | 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 | if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URL.fileSystemRepresentation; # ifndef OF_WINDOWS OFStringEncoding encoding = [OFLocale encoding]; if (symlink([target cStringWithEncoding: encoding], [path cStringWithEncoding: encoding]) != 0) @throw [OFCreateSymbolicLinkFailedException exceptionWithURL: URL target: target errNo: errno]; # else if (createSymbolicLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; if (!createSymbolicLinkWFuncPtr(path.UTF16String, target.UTF16String, 0)) @throw [OFCreateSymbolicLinkFailedException exceptionWithURL: URL target: target errNo: retrieveError()]; # endif objc_autoreleasePoolPop(pool); } #endif - (bool)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination { void *pool; if (![source.scheme isEqual: _scheme] || ![destination.scheme isEqual: _scheme]) return false; if ([self fileExistsAtURL: destination]) @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: EEXIST]; pool = objc_autoreleasePoolPush(); #ifdef OF_AMIGAOS OFStringEncoding encoding = [OFLocale encoding]; if (!Rename([source.fileSystemRepresentation cStringWithEncoding: encoding], [destination.fileSystemRepresentation cStringWithEncoding: encoding])) @throw [OFMoveItemFailedException exceptionWithSourceURL: source destinationURL: destination errNo: retrieveError()]; #else int status; # ifdef OF_WINDOWS if ([OFSystemInfo isWindowsNT]) status = _wrename(source.fileSystemRepresentation.UTF16String, destination.fileSystemRepresentation.UTF16String); else { # endif OFStringEncoding encoding = [OFLocale encoding]; status = rename([source.fileSystemRepresentation cStringWithEncoding: encoding], [destination.fileSystemRepresentation cStringWithEncoding: encoding]); # ifdef OF_WINDOWS } |
︙ | ︙ |
Modified src/OFGZIPStream.h from [b7c2096cd2] to [498f0a4cf5].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFStream.h" #import "OFDate.h" @class OFInflateStream; OF_ASSUME_NONNULL_BEGIN /** * @class OFGZIPStream OFGZIPStream.h ObjFW/OFGZIPStream.h * * @brief A class that handles GZIP compression and decompression transparently * for an underlying stream. */ OF_SUBCLASSING_RESTRICTED @interface OFGZIPStream: OFStream { OFStream *_stream; OFInflateStream *_Nullable _inflateStream; | > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < < | | | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | #import "OFStream.h" #import "OFDate.h" @class OFInflateStream; OF_ASSUME_NONNULL_BEGIN /** * @brief The operating system on which compressed the data. */ typedef enum { OFGZIPStreamOperatingSystemFAT = 0, OFGZIPStreamOperatingSystemAmiga = 1, OFGZIPStreamOperatingSystemVMS = 2, OFGZIPStreamOperatingSystemUNIX = 3, OFGZIPStreamOperatingSystemVM_CMS = 4, OFGZIPStreamOperatingSystemAtariTOS = 5, OFGZIPStreamOperatingSystemHPFS = 6, OFGZIPStreamOperatingSystemMacintosh = 7, OFGZIPStreamOperatingSystemZSystem = 8, OFGZIPStreamOperatingSystemCPM = 9, OFGZIPStreamOperatingSystemTOPS20 = 10, OFGZIPStreamOperatingSystemNTFS = 11, OFGZIPStreamOperatingSystemQDO = 12, OFGZIPStreamOperatingSystemAcornRISCOS = 13, OFGZIPStreamOperatingSystemUnknown = 255 } OFGZIPStreamOperatingSystem; /** * @class OFGZIPStream OFGZIPStream.h ObjFW/OFGZIPStream.h * * @brief A class that handles GZIP compression and decompression transparently * for an underlying stream. */ OF_SUBCLASSING_RESTRICTED @interface OFGZIPStream: OFStream { OFStream *_stream; OFInflateStream *_Nullable _inflateStream; enum { OFGZIPStreamStateID1, OFGZIPStreamStateID2, OFGZIPStreamStateCompressionMethod, OFGZIPStreamStateFlags, OFGZIPStreamStateModificationDate, OFGZIPStreamStateExtraFlags, OFGZIPStreamStateOperatingSystem, OFGZIPStreamStateExtraLength, OFGZIPStreamStateExtra, OFGZIPStreamStateName, OFGZIPStreamStateComment, OFGZIPStreamStateHeaderCRC16, OFGZIPStreamStateData, OFGZIPStreamStateCRC32, OFGZIPStreamStateUncompressedSize } _state; enum { OFGZIPStreamFlagText = 0x01, OFGZIPStreamFlagHeaderCRC16 = 0x02, OFGZIPStreamFlagExtra = 0x04, OFGZIPStreamFlagName = 0x08, OFGZIPStreamFlagComment = 0x10 } _flags; uint8_t _extraFlags; OFGZIPStreamOperatingSystem _operatingSystemMadeOn; size_t _bytesRead; uint8_t _buffer[4]; OFDate *_Nullable _modificationDate; uint16_t _extraLength; uint32_t _CRC32, _uncompressedSize; } /** * @brief The operating system on which the data was compressed. * * This property is only guaranteed to be available once @ref atEndOfStream is * true. */ @property (readonly, nonatomic) OFGZIPStreamOperatingSystem operatingSystemMadeOn; /** * @brief The modification date of the original file. * * This property is only guaranteed to be available once @ref atEndOfStream is * true. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFDate *modificationDate; /** * @brief Creates a new OFGZIPStream with the specified underlying stream. * * @param stream The underlying stream for the OFGZIPStream * @param mode The mode for the OFGZIPStream. Valid modes are "r" for reading * and "w" for writing. * @return A new, autoreleased OFGZIPStream */ + (instancetype)streamWithStream: (OFStream *)stream mode: (OFString *)mode; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFGZIPStream with the specified * underlying stream. * |
︙ | ︙ |
Modified src/OFGZIPStream.m from [4ed53f9a5c] to [072d5c3fec].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFGZIPStream.h" | | < | | < | < | < | < | < | | | | | < | | | | | < | | | < | | < | | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFGZIPStream.h" #import "OFCRC32.h" #import "OFDate.h" #import "OFInflateStream.h" #import "OFChecksumMismatchException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" @implementation OFGZIPStream @synthesize operatingSystemMadeOn = _operatingSystemMadeOn; @synthesize modificationDate = _modificationDate; + (instancetype)streamWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { if (![mode isEqual: @"r"]) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; _stream = [stream retain]; _operatingSystemMadeOn = OFGZIPStreamOperatingSystemUnknown; _CRC32 = ~0; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; [_inflateStream release]; [_modificationDate release]; [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; for (;;) { uint8_t byte; uint32_t CRC32, uncompressedSize; if (_stream.atEndOfStream) { if (_state != OFGZIPStreamStateID1) @throw [OFTruncatedDataException exception]; return 0; } switch (_state) { case OFGZIPStreamStateID1: case OFGZIPStreamStateID2: case OFGZIPStreamStateCompressionMethod: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; if ((_state == OFGZIPStreamStateID1 && byte != 0x1F) || (_state == OFGZIPStreamStateID2 && byte != 0x8B) || (_state == OFGZIPStreamStateCompressionMethod && byte != 8)) @throw [OFInvalidFormatException exception]; _state++; break; case OFGZIPStreamStateFlags: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _flags = byte; _state++; break; case OFGZIPStreamStateModificationDate: _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; [_modificationDate release]; _modificationDate = nil; _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: (_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]]; _bytesRead = 0; _state++; break; case OFGZIPStreamStateExtraFlags: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _extraFlags = byte; _state++; break; case OFGZIPStreamStateOperatingSystem: if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; _operatingSystemMadeOn = byte; _state++; break; case OFGZIPStreamStateExtraLength: if (!(_flags & OFGZIPStreamFlagExtra)) { _state += 2; break; } _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 2 - _bytesRead]; if (_bytesRead < 2) return 0; _extraLength = (_buffer[1] << 8) | _buffer[0]; _bytesRead = 0; _state++; break; case OFGZIPStreamStateExtra: { char tmp[512]; size_t toRead = _extraLength - _bytesRead; if (toRead > 512) toRead = 512; _bytesRead += [_stream readIntoBuffer: tmp length: toRead]; } if (_bytesRead < _extraLength) return 0; _bytesRead = 0; _state++; break; case OFGZIPStreamStateName: if (!(_flags & OFGZIPStreamFlagName)) { _state++; break; } do { if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; } while (byte != 0); _state++; break; case OFGZIPStreamStateComment: if (!(_flags & OFGZIPStreamFlagComment)) { _state++; break; } do { if ([_stream readIntoBuffer: &byte length: 1] < 1) return 0; } while (byte != 0); _state++; break; case OFGZIPStreamStateHeaderCRC16: if (!(_flags & OFGZIPStreamFlagHeaderCRC16)) { _state++; break; } _bytesRead += [_stream readIntoBuffer: _buffer + _bytesRead length: 2 - _bytesRead]; if (_bytesRead < 2) return 0; /* * Header CRC16 is not checked, as I could not find a * single file in the wild that actually has a header * CRC16 - and thus no file to test against. */ _bytesRead = 0; _state++; break; case OFGZIPStreamStateData: if (_inflateStream == nil) _inflateStream = [[OFInflateStream alloc] initWithStream: _stream]; if (!_inflateStream.atEndOfStream) { size_t bytesRead = [_inflateStream readIntoBuffer: buffer length: length]; _CRC32 = OFCRC32(_CRC32, buffer, bytesRead); _uncompressedSize += bytesRead; return bytesRead; } [_inflateStream release]; _inflateStream = nil; _state++; break; case OFGZIPStreamStateCRC32: _bytesRead += [_stream readIntoBuffer: _buffer length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; CRC32 = ((uint32_t)_buffer[3] << 24) | |
︙ | ︙ | |||
279 280 281 282 283 284 285 | expectedChecksum: expected]; } _bytesRead = 0; _CRC32 = ~0; _state++; break; | | | | | 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | expectedChecksum: expected]; } _bytesRead = 0; _CRC32 = ~0; _state++; break; case OFGZIPStreamStateUncompressedSize: _bytesRead += [_stream readIntoBuffer: _buffer length: 4 - _bytesRead]; uncompressedSize = ((uint32_t)_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]; if (_uncompressedSize != uncompressedSize) { OFString *actual = [OFString stringWithFormat: @"%" PRIu32, _uncompressedSize]; OFString *expected = [OFString stringWithFormat: @"%" PRIu32, uncompressedSize]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actual expectedChecksum: expected]; } _bytesRead = 0; _uncompressedSize = 0; _state = OFGZIPStreamStateID1; break; } } } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _stream.atEndOfStream; } - (bool)hasDataInReadBuffer { if (_state == OFGZIPStreamStateData) return (super.hasDataInReadBuffer || _inflateStream.hasDataInReadBuffer); return (super.hasDataInReadBuffer || _stream.hasDataInReadBuffer); } - (void)close |
︙ | ︙ |
Modified src/OFHMAC.h from [42893456b1] to [bca836378e].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" | | | | | | | 10 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 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFHMAC OFHMAC.h ObjFW/OFHMAC.h * * @brief A class which provides methods to calculate an HMAC. */ OF_SUBCLASSING_RESTRICTED @interface OFHMAC: OFObject { Class <OFCryptographicHash> _hashClass; bool _allowsSwappableMemory; id <OFCryptographicHash> _Nullable _outerHash, _innerHash; id <OFCryptographicHash> _Nullable _outerHashCopy, _innerHashCopy; bool _calculated; } /** * @brief The class for the cryptographic hash used by the HMAC. */ @property (readonly, nonatomic) Class <OFCryptographicHash> hashClass; /** * @brief Whether data may be stored in swappable memory. */ @property (readonly, nonatomic) bool allowsSwappableMemory; /** |
︙ | ︙ | |||
60 61 62 63 64 65 66 | /** * @brief Returns a new OFHMAC with the specified hashing algorithm. * * @param hashClass The class of the hashing algorithm * @param allowsSwappableMemory Whether data may be stored in swappable memory * @return A new, autoreleased OFHMAC */ | | | | < | < | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | /** * @brief Returns a new OFHMAC with the specified hashing algorithm. * * @param hashClass The class of the hashing algorithm * @param allowsSwappableMemory Whether data may be stored in swappable memory * @return A new, autoreleased OFHMAC */ + (instancetype)HMACWithHashClass: (Class <OFCryptographicHash>)hashClass allowsSwappableMemory: (bool)allowsSwappableMemory; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initialized an already allocated OFHMAC with the specified hashing * algorithm. * * @param hashClass The class of the hashing algorithm * @param allowsSwappableMemory Whether data may be stored in swappable memory * @return An initialized OFHMAC */ - (instancetype)initWithHashClass: (Class <OFCryptographicHash>)hashClass allowsSwappableMemory: (bool)allowsSwappableMemory OF_DESIGNATED_INITIALIZER; /** * @brief Sets the key for the HMAC. * * @note This resets the HMAC! * * @warning This invalidates any pointer previously returned by @ref digest. If * you are still interested in the previous digest, you need to memcpy * it yourself before calling @ref setKey:length:! * * @param key The key for the HMAC * @param length The length of the key for the HMAC */ - (void)setKey: (const void *)key length: (size_t)length; /** * @brief Adds a buffer to the HMAC to be calculated. * * @param buffer The buffer which should be included into the calculation * @param length The length of the buffer */ - (void)updateWithBuffer: (const void *)buffer length: (size_t)length; /** * @brief Resets the HMAC so that it can be calculated for a new message. * * @note This does not reset the key so that a new HMAC with the same key can * be calculated efficiently. If you want to reset both, use * @ref setKey:length:. |
︙ | ︙ |
Modified src/OFHMAC.m from [0effc9def0] to [23d069a3eb].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "OFHashAlreadyCalculatedException.h" #import "OFInvalidArgumentException.h" @implementation OFHMAC @synthesize hashClass = _hashClass; @synthesize allowsSwappableMemory = _allowsSwappableMemory; | | | | < | | < | < | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | #import "OFHashAlreadyCalculatedException.h" #import "OFInvalidArgumentException.h" @implementation OFHMAC @synthesize hashClass = _hashClass; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (instancetype)HMACWithHashClass: (Class <OFCryptographicHash>)class allowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithHashClass: class allowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithHashClass: (Class <OFCryptographicHash>)class allowsSwappableMemory: (bool)allowsSwappableMemory { self = [super init]; _hashClass = class; _allowsSwappableMemory = allowsSwappableMemory; return self; } - (void)dealloc { [_outerHash release]; [_innerHash release]; [_outerHashCopy release]; [_innerHashCopy release]; [super dealloc]; } - (void)setKey: (const void *)key length: (size_t)length { void *pool = objc_autoreleasePoolPush(); size_t blockSize = [_hashClass blockSize]; OFSecureData *outerKeyPad = [OFSecureData dataWithCount: blockSize allowsSwappableMemory: _allowsSwappableMemory]; OFSecureData *innerKeyPad = [OFSecureData dataWithCount: blockSize allowsSwappableMemory: _allowsSwappableMemory]; unsigned char *outerKeyPadItems = outerKeyPad.mutableItems; unsigned char *innerKeyPadItems = innerKeyPad.mutableItems; [_outerHash release]; [_innerHash release]; [_outerHashCopy release]; [_innerHashCopy release]; _outerHash = _innerHash = _outerHashCopy = _innerHashCopy = nil; @try { if (length > blockSize) { id <OFCryptographicHash> hash = [_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory]; [hash updateWithBuffer: key length: length]; length = hash.digestSize; if OF_UNLIKELY (length > blockSize) length = blockSize; memcpy(outerKeyPadItems, hash.digest, length); memcpy(innerKeyPadItems, hash.digest, length); } else { memcpy(outerKeyPadItems, key, length); memcpy(innerKeyPadItems, key, length); } memset(outerKeyPadItems + length, 0, blockSize - length); memset(innerKeyPadItems + length, 0, blockSize - length); for (size_t i = 0; i < blockSize; i++) { outerKeyPadItems[i] ^= 0x5C; innerKeyPadItems[i] ^= 0x36; } _outerHash = [[_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory] retain]; _innerHash = [[_hashClass hashWithAllowsSwappableMemory: _allowsSwappableMemory] retain]; [_outerHash updateWithBuffer: outerKeyPadItems length: blockSize]; [_innerHash updateWithBuffer: innerKeyPadItems length: blockSize]; } @catch (id e) { |
︙ | ︙ | |||
127 128 129 130 131 132 133 | _outerHashCopy = [_outerHash copy]; _innerHashCopy = [_innerHash copy]; _calculated = false; } | | < | < | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | _outerHashCopy = [_outerHash copy]; _innerHashCopy = [_innerHash copy]; _calculated = false; } - (void)updateWithBuffer: (const void *)buffer length: (size_t)length { if (_innerHash == nil) @throw [OFInvalidArgumentException exception]; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; [_innerHash updateWithBuffer: buffer length: length]; } - (const unsigned char *)digest { if (_outerHash == nil || _innerHash == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ |
Modified src/OFHTTPClient.m from [392b01fde8] to [53c6cb3f12].
︙ | ︙ | |||
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 | #import "OFData.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFKernelEventObserver.h" #import "OFNumber.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFURL.h" #import "OFAlreadyConnectedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" | > < | < | 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 | #import "OFData.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFKernelEventObserver.h" #import "OFNumber.h" #import "OFRunLoop.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFTCPSocket.h" #import "OFURL.h" #import "OFAlreadyConnectedException.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" static const unsigned int defaultRedirects = 10; OF_DIRECT_MEMBERS @interface OFHTTPClientRequestHandler: OFObject <OFTCPSocketDelegate> { @public OFHTTPClient *_client; OFHTTPRequest *_request; |
︙ | ︙ | |||
112 113 114 115 116 117 118 | redirects: (unsigned int)redirects; @end static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); | | | | 111 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 | redirects: (unsigned int)redirects; @end static OFString * constructRequestString(OFHTTPRequest *request) { void *pool = objc_autoreleasePoolPush(); OFHTTPRequestMethod method = request.method; OFURL *URL = request.URL; OFString *path; OFString *user = URL.user, *password = URL.password; OFMutableString *requestString; OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; bool hasContentLength, chunked; OFEnumerator OF_GENERIC(OFString *) *keyEnumerator, *objectEnumerator; OFString *key, *object; if (URL.path != nil) path = URL.URLEncodedPath; else path = @"/"; requestString = [OFMutableString stringWithFormat: @"%s %@", OFHTTPRequestMethodName(method), path]; if (URL.query != nil) { [requestString appendString: @"?"]; [requestString appendString: URL.URLEncodedQuery]; } [requestString appendString: @" HTTP/"]; |
︙ | ︙ | |||
150 151 152 153 154 155 156 | if ([headers objectForKey: @"Host"] == nil) { OFNumber *port = URL.port; if (port != nil) { OFString *host = [OFString stringWithFormat: @"%@:%@", URL.URLEncodedHost, port]; | | < < | | < | < | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | if ([headers objectForKey: @"Host"] == nil) { OFNumber *port = URL.port; if (port != nil) { OFString *host = [OFString stringWithFormat: @"%@:%@", URL.URLEncodedHost, port]; [headers setObject: host forKey: @"Host"]; } else [headers setObject: URL.URLEncodedHost forKey: @"Host"]; } if ((user.length > 0 || password.length > 0) && [headers objectForKey: @"Authorization"] == nil) { OFMutableData *authorizationData = [OFMutableData data]; OFString *authorization; [authorizationData addItems: user.UTF8String count: user.UTF8StringLength]; [authorizationData addItem: ":"]; [authorizationData addItems: password.UTF8String count: password.UTF8StringLength]; authorization = [OFString stringWithFormat: @"Basic %@", authorizationData.stringByBase64Encoding]; [headers setObject: authorization forKey: @"Authorization"]; } if ([headers objectForKey: @"User-Agent"] == nil) [headers setObject: @"Something using ObjFW " @"<https://objfw.nil.im/>" forKey: @"User-Agent"]; if (request.protocolVersion.major == 1 && request.protocolVersion.minor == 0 && [headers objectForKey: @"Connection"] == nil) [headers setObject: @"keep-alive" forKey: @"Connection"]; hasContentLength = ([headers objectForKey: @"Content-Length"] != nil); chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; if ((hasContentLength || chunked) && [headers objectForKey: @"Content-Type"] == nil) |
︙ | ︙ | |||
219 220 221 222 223 224 225 | static OF_INLINE void normalizeKey(char *str_) { unsigned char *str = (unsigned char *)str_; bool firstLetter = true; while (*str != '\0') { | | < | | | | | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | static OF_INLINE void normalizeKey(char *str_) { unsigned char *str = (unsigned char *)str_; bool firstLetter = true; while (*str != '\0') { if (!OFASCIIIsAlpha(*str)) { firstLetter = true; str++; continue; } *str = (firstLetter ? OFASCIIToUpper(*str) : OFASCIIToLower(*str)); firstLetter = false; str++; } } static bool defaultShouldFollow(OFHTTPRequestMethod method, short statusCode) { bool follow; /* * 301, 302 and 307 should only redirect with user confirmation if the * request method is not GET or HEAD. Asking the delegate and getting * true returned is considered user confirmation. */ if (method == OFHTTPRequestMethodGet || method == OFHTTPRequestMethodHead) follow = true; /* 303 should always be redirected and converted to a GET request. */ else if (statusCode == 303) follow = true; else follow = false; |
︙ | ︙ | |||
321 322 323 324 325 326 327 | if (connectionHeader != nil) keepAlive = [connectionHeader isEqual: @"close"]; else keepAlive = true; } else { if (connectionHeader != nil) keepAlive = ([connectionHeader caseInsensitiveCompare: | | | | | | | | 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | if (connectionHeader != nil) keepAlive = [connectionHeader isEqual: @"close"]; else keepAlive = true; } else { if (connectionHeader != nil) keepAlive = ([connectionHeader caseInsensitiveCompare: @"keep-alive"] == OFOrderedSame); else keepAlive = false; } if (keepAlive) { response.of_keepAlive = true; _client->_socket = [sock retain]; _client->_lastURL = [URL copy]; _client->_lastWasHEAD = (_request.method == OFHTTPRequestMethodHead); _client->_lastResponse = [response retain]; } if (_redirects > 0 && (_status == 301 || _status == 302 || _status == 303 || _status == 307) && (location = [_serverHeaders objectForKey: @"Location"]) != nil) { bool follow = true; OFURL *newURL; OFString *newURLScheme; newURL = [OFURL URLWithString: location relativeToURL: URL]; newURLScheme = newURL.scheme; if ([newURLScheme caseInsensitiveCompare: @"http"] != OFOrderedSame && [newURLScheme caseInsensitiveCompare: @"https"] != OFOrderedSame) follow = false; if (!_client->_allowsInsecureRedirects && [URL.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame && [newURLScheme caseInsensitiveCompare: @"http"] == OFOrderedSame) follow = false; if (follow && [_client->_delegate respondsToSelector: @selector( client:shouldFollowRedirect:statusCode:request:response:)]) follow = [_client->_delegate client: _client shouldFollowRedirect: newURL statusCode: _status |
︙ | ︙ | |||
401 402 403 404 405 406 407 | (object = [objectEnumerator nextObject]) != nil) if ([key hasPrefix: @"Content-"] || [key hasPrefix: @"Transfer-"]) [newHeaders removeObjectForKey: key]; | | | 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | (object = [objectEnumerator nextObject]) != nil) if ([key hasPrefix: @"Content-"] || [key hasPrefix: @"Transfer-"]) [newHeaders removeObjectForKey: key]; newRequest.method = OFHTTPRequestMethodGet; } newRequest.URL = newURL; newRequest.headers = newHeaders; _client->_inProgress = false; |
︙ | ︙ | |||
460 461 462 463 464 465 466 | return false; } if (![line hasPrefix: @"HTTP/"] || line.length < 9 || [line characterAtIndex: 8] != ' ') @throw [OFInvalidServerReplyException exception]; | | | | < | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | return false; } if (![line hasPrefix: @"HTTP/"] || line.length < 9 || [line characterAtIndex: 8] != ' ') @throw [OFInvalidServerReplyException exception]; _version = [[line substringWithRange: OFRangeMake(5, 3)] copy]; if (![_version isEqual: @"1.0"] && ![_version isEqual: @"1.1"]) @throw [OFUnsupportedVersionException exceptionWithVersion: _version]; status = [line substringWithRange: OFRangeMake(9, 3)].longLongValue; if (status < 0 || status > 599) @throw [OFInvalidServerReplyException exception]; _status = (short)status; return true; } - (bool)handleServerHeader: (OFString *)line socket: (OFTCPSocket *)sock { OFString *key, *value, *old; const char *lineC, *tmp; char *keyC; if (line == nil) @throw [OFInvalidServerReplyException exception]; |
︙ | ︙ | |||
509 510 511 512 513 514 515 | } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; | | | | < | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; keyC = OFAllocMemory(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { key = [OFString stringWithUTF8StringNoCopy: keyC freeWhenDone: true]; } @catch (id e) { OFFreeMemory(keyC); @throw e; } do { tmp++; } while (*tmp == ' '); value = [OFString stringWithUTF8String: tmp]; old = [_serverHeaders objectForKey: key]; if (old != nil) value = [old stringByAppendingFormat: @",%@", value]; [_serverHeaders setObject: value forKey: key]; return true; } - (bool)stream: (OFStream *)sock didReadLine: (OFString *)line exception: (id)exception |
︙ | ︙ | |||
570 571 572 573 574 575 576 | } return ret; } - (OFString *)stream: (OFStream *)stream didWriteString: (OFString *)string | | | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 | } return ret; } - (OFString *)stream: (OFStream *)stream didWriteString: (OFString *)string encoding: (OFStringEncoding)encoding bytesWritten: (size_t)bytesWritten exception: (id)exception { OFDictionary OF_GENERIC(OFString *, OFString *) *headers; bool chunked; if (exception != nil) { |
︙ | ︙ | |||
702 703 704 705 706 707 708 | OFTCPSocket *sock; uint16_t port; OFNumber *URLPort; [_client close]; if ([URL.scheme caseInsensitiveCompare: @"https"] == | | | | | < | 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | OFTCPSocket *sock; uint16_t port; OFNumber *URLPort; [_client close]; if ([URL.scheme caseInsensitiveCompare: @"https"] == OFOrderedSame) { if (OFTLSSocketClass == Nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; sock = [[[OFTLSSocketClass alloc] init] autorelease]; port = 443; } else { sock = [OFTCPSocket socket]; port = 80; } URLPort = URL.port; if (URLPort != nil) port = URLPort.unsignedShortValue; sock.delegate = self; [sock asyncConnectToHost: URL.host port: port]; } @catch (id e) { [self raiseException: e]; } } @end @implementation OFHTTPClientRequestBodyStream |
︙ | ︙ | |||
801 802 803 804 805 806 807 | errNo: 0]; if (_chunked) [_socket writeFormat: @"%zX\r\n", length]; else if (length > _toWrite) length = (size_t)_toWrite; | | < | 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | errNo: 0]; if (_chunked) [_socket writeFormat: @"%zX\r\n", length]; else if (length > _toWrite) length = (size_t)_toWrite; ret = [_socket writeBuffer: buffer length: length]; if (_chunked) [_socket writeString: @"\r\n"]; if (ret > length) @throw [OFOutOfRangeException exception]; if (!_chunked) { |
︙ | ︙ | |||
906 907 908 909 910 911 912 | _toRead = (long long)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerReplyException exception]; } } } | | < | < | < < | < | < | < < | | | 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 | _toRead = (long long)toRead; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerReplyException exception]; } } } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if (!_hasContentLength && !_chunked) return [_socket readIntoBuffer: buffer length: length]; if (_socket.atEndOfStream) @throw [OFTruncatedDataException exception]; /* Content-Length */ if (!_chunked) { size_t ret; if (length > (unsigned long long)_toRead) length = (size_t)_toRead; ret = [_socket readIntoBuffer: buffer length: length]; if (ret > length) @throw [OFOutOfRangeException exception]; _toRead -= ret; if (_toRead == 0) _atEndOfStream = true; return ret; } /* Chunked */ if (_toRead == -2) { char tmp[2]; switch ([_socket readIntoBuffer: tmp length: 2]) { case 2: _toRead++; if (tmp[1] != '\n') @throw [OFInvalidServerReplyException exception]; case 1: _toRead++; if (tmp[0] != '\r') @throw [OFInvalidServerReplyException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead == -1) { char tmp; if ([_socket readIntoBuffer: &tmp length: 1] == 1) { _toRead++; if (tmp != '\n') @throw [OFInvalidServerReplyException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead > 0) { if (length > (unsigned long long)_toRead) length = (size_t)_toRead; length = [_socket readIntoBuffer: buffer length: length]; _toRead -= length; if (_toRead == 0) _toRead = -2; return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; size_t pos; @try { line = [_socket tryReadLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exception]; } if (line == nil) return 0; pos = [line rangeOfString: @";"].location; if (pos != OFNotFound) line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the socket is * at end of stream. */ if (_socket.atEndOfStream && pos == OFNotFound) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidServerReplyException exception]; } @try { |
︙ | ︙ | |||
1116 1117 1118 1119 1120 1121 1122 | [super dealloc]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { | | < < < | 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | [super dealloc]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { [_client asyncPerformRequest: request redirects: redirects]; [[OFRunLoop currentRunLoop] run]; return _response; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception |
︙ | ︙ | |||
1222 1223 1224 1225 1226 1227 1228 | [self close]; [super dealloc]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request { | | < | 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 | [self close]; [super dealloc]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request { return [self performRequest: request redirects: defaultRedirects]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); OFHTTPClientSyncPerformer *syncPerformer = |
︙ | ︙ | |||
1245 1246 1247 1248 1249 1250 1251 | objc_autoreleasePoolPop(pool); return [response autorelease]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request { | | < | | | 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 | objc_autoreleasePoolPop(pool); return [response autorelease]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request { [self asyncPerformRequest: request redirects: defaultRedirects]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { void *pool = objc_autoreleasePoolPush(); OFURL *URL = request.URL; OFString *scheme = URL.scheme; if ([scheme caseInsensitiveCompare: @"http"] != OFOrderedSame && [scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; if (_inProgress) /* TODO: Find a better exception */ @throw [OFAlreadyConnectedException exception]; _inProgress = true; |
︙ | ︙ |
Modified src/OFHTTPCookie.m from [f788425642] to [a0376d23d9].
︙ | ︙ | |||
64 65 66 67 68 69 70 | (OFDictionary OF_GENERIC(OFString *, OFString *) *)headerFields forURL: (OFURL *)URL { OFMutableArray OF_GENERIC(OFHTTPCookie *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); OFString *string = [headerFields objectForKey: @"Set-Cookie"]; OFString *domain = URL.host; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | (OFDictionary OF_GENERIC(OFString *, OFString *) *)headerFields forURL: (OFURL *)URL { OFMutableArray OF_GENERIC(OFHTTPCookie *) *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); OFString *string = [headerFields objectForKey: @"Set-Cookie"]; OFString *domain = URL.host; const OFUnichar *characters = string.characters; size_t length = string.length, last = 0; enum { statePreName, stateName, stateExpectValue, stateValue, stateQuotedValue, statePostQuotedValue, statePreAttrName, stateAttrName, stateAttrValue } state = statePreName; OFString *name = nil, *value = nil; for (size_t i = 0; i < length; i++) { switch (state) { case statePreName: if (characters[i] != ' ') { state = stateName; last = i; i--; } break; case stateName: if (characters[i] == '=') { name = [string substringWithRange: OFRangeMake(last, i - last)]; state = stateExpectValue; } break; case stateExpectValue: if (characters[i] == '"') { state = stateQuotedValue; last = i + 1; } else { state = stateValue; last = i; } i--; break; case stateValue: if (characters[i] == ';' || characters[i] == ',') { value = [string substringWithRange: OFRangeMake(last, i - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; case stateQuotedValue: if (characters[i] == '"') { value = [string substringWithRange: OFRangeMake(last, i - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; state = statePostQuotedValue; } break; case statePostQuotedValue: if (characters[i] == ';') state = statePreAttrName; else if (characters[i] == ',') state = statePreName; else @throw [OFInvalidFormatException exception]; break; case statePreAttrName: if (characters[i] != ' ') { state = stateAttrName; last = i; i--; } break; case stateAttrName: if (characters[i] == '=') { name = [string substringWithRange: OFRangeMake(last, i - last)]; state = stateAttrValue; last = i + 1; } else if (characters[i] == ';' || characters[i] == ',') { name = [string substringWithRange: OFRangeMake(last, i - last)]; handleAttribute(ret.lastObject, name, nil); state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; case stateAttrValue: if (characters[i] == ';' || characters[i] == ',') { value = [string substringWithRange: OFRangeMake(last, i - last)]; /* * Expires often contains a comma, even though * the comma is used as a separator for * concatenating headers as per RFC 2616, * meaning RFC 6265 contradicts RFC 2616. * Solve this by special casing this. */ if (characters[i] == ',' && [name caseInsensitiveCompare: @"expires"] == OFOrderedSame && value.length == 3 && ([value isEqual: @"Mon"] || [value isEqual: @"Tue"] || [value isEqual: @"Wed"] || [value isEqual: @"Thu"] || [value isEqual: @"Fri"] || [value isEqual: @"Sat"] || [value isEqual: @"Sun"])) break; handleAttribute(ret.lastObject, name, value); state = (characters[i] == ';' ? statePreAttrName : statePreName); } break; } } switch (state) { case statePreName: case statePostQuotedValue: case statePreAttrName: break; case stateName: case stateQuotedValue: @throw [OFInvalidFormatException exception]; break; case stateValue: value = [string substringWithRange: OFRangeMake(last, length - last)]; [ret addObject: [OFHTTPCookie cookieWithName: name value: value domain: domain]]; break; /* We end up here if the cookie is just foo= */ case stateExpectValue: [ret addObject: [OFHTTPCookie cookieWithName: name value: @"" domain: domain]]; break; case stateAttrName: if (last != length) { name = [string substringWithRange: OFRangeMake(last, length - last)]; handleAttribute(ret.lastObject, name, nil); } break; case stateAttrValue: value = [string substringWithRange: OFRangeMake(last, length - last)]; handleAttribute(ret.lastObject, name, value); break; } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
359 360 361 362 363 364 365 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _value.hash); OFHashAddHash(&hash, _domain.hash); OFHashAddHash(&hash, _path.hash); OFHashAddHash(&hash, _expires.hash); OFHashAdd(&hash, _secure); OFHashAdd(&hash, _HTTPOnly); OFHashAddHash(&hash, _extensions.hash); OFHashFinalize(&hash); return hash; } - (id)copy { OFHTTPCookie *copy = [[OFHTTPCookie alloc] initWithName: _name |
︙ | ︙ |
Modified src/OFHTTPCookieManager.h from [2f94287da3] to [83e63d79cd].
︙ | ︙ | |||
50 51 52 53 54 55 56 | * * @warning This modifies the cookie (e.g. it sets the domain if it is unset)! * If you do not want this, pass a copy! * * @param cookie The cookie to add to the manager * @param URL The URL for which the cookie should be added */ | | < | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | * * @warning This modifies the cookie (e.g. it sets the domain if it is unset)! * If you do not want this, pass a copy! * * @param cookie The cookie to add to the manager * @param URL The URL for which the cookie should be added */ - (void)addCookie: (OFHTTPCookie *)cookie forURL: (OFURL *)URL; /** * @brief Adds the specified cookies for the specified URL. * * @warning This modifies the cookies (e.g. it sets the domain if it is unset)! * If you do not want this, pass copies! * |
︙ | ︙ |
Modified src/OFHTTPCookieManager.m from [3511ad0390] to [5134a266a2].
︙ | ︙ | |||
49 50 51 52 53 54 55 | } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies { return [[_cookies copy] autorelease]; } | | < | | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies { return [[_cookies copy] autorelease]; } - (void)addCookie: (OFHTTPCookie *)cookie forURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); OFString *cookieDomain, *URLHost; size_t i; if (![cookie.path hasPrefix: @"/"]) cookie.path = @"/"; if (cookie.secure && [URL.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) { objc_autoreleasePoolPop(pool); return; } cookieDomain = cookie.domain.lowercaseString; cookie.domain = cookieDomain; |
︙ | ︙ | |||
83 84 85 86 87 88 89 | } i = 0; for (OFHTTPCookie *iter in _cookies) { if ([iter.name isEqual: cookie.name] && [iter.domain isEqual: cookie.domain] && [iter.path isEqual: cookie.path]) { | | < < | < | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | } i = 0; for (OFHTTPCookie *iter in _cookies) { if ([iter.name isEqual: cookie.name] && [iter.domain isEqual: cookie.domain] && [iter.path isEqual: cookie.path]) { [_cookies replaceObjectAtIndex: i withObject: cookie]; objc_autoreleasePoolPop(pool); return; } i++; } [_cookies addObject: cookie]; objc_autoreleasePoolPop(pool); } - (void)addCookies: (OFArray OF_GENERIC(OFHTTPCookie *) *)cookies forURL: (OFURL *)URL { for (OFHTTPCookie *cookie in cookies) [self addCookie: cookie forURL: URL]; } - (OFArray OF_GENERIC(OFHTTPCookie *) *)cookiesForURL: (OFURL *)URL { OFMutableArray *ret = [OFMutableArray array]; for (OFHTTPCookie *cookie in _cookies) { void *pool; OFDate *expires; OFString *cookieDomain, *URLHost, *cookiePath, *URLPath; bool match; expires = cookie.expires; if (expires != nil && expires.timeIntervalSinceNow <= 0) continue; if (cookie.secure && [URL.scheme caseInsensitiveCompare: @"https"] != OFOrderedSame) continue; pool = objc_autoreleasePoolPush(); cookieDomain = cookie.domain.lowercaseString; URLHost = URL.host.lowercaseString; if ([cookieDomain hasPrefix: @"."]) { |
︙ | ︙ |
Modified src/OFHTTPRequest.h from [3c89198066] to [e5c26eec6f].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" | | < | | | | | | | | | | < | | < < | | | | | | | < | 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSocket.h" #import "OFString.h" OF_ASSUME_NONNULL_BEGIN @class OFURL; @class OFDictionary OF_GENERIC(KeyType, ObjectType); @class OFData; @class OFString; /** @file */ /** * @brief The type of an HTTP request. */ typedef enum { /** OPTIONS */ OFHTTPRequestMethodOptions, /** GET */ OFHTTPRequestMethodGet, /** HEAD */ OFHTTPRequestMethodHead, /** POST */ OFHTTPRequestMethodPost, /** PUT */ OFHTTPRequestMethodPut, /** DELETE */ OFHTTPRequestMethodDelete, /** TRACE */ OFHTTPRequestMethodTrace, /** CONNECT */ OFHTTPRequestMethodConnect } OFHTTPRequestMethod; /** * @struct OFHTTPRequestProtocolVersion OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief The HTTP version of the HTTP request. */ typedef struct OF_BOXABLE { /** The major of the HTTP version */ unsigned char major; /** The minor of the HTTP version */ unsigned char minor; } OFHTTPRequestProtocolVersion; /** * @class OFHTTPRequest OFHTTPRequest.h ObjFW/OFHTTPRequest.h * * @brief A class for storing HTTP requests. */ @interface OFHTTPRequest: OFObject <OFCopying> { OFURL *_URL; OFHTTPRequestMethod _method; OFHTTPRequestProtocolVersion _protocolVersion; OFDictionary OF_GENERIC(OFString *, OFString *) *_Nullable _headers; OFSocketAddress _remoteAddress; bool _hasRemoteAddress; OF_RESERVE_IVARS(OFHTTPRequest, 4) } /** * @brief The URL of the HTTP request. */ @property (copy, nonatomic) OFURL *URL; /** * @brief The protocol version of the HTTP request. */ @property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request as a string. */ @property (copy, nonatomic) OFString *protocolVersionString; /** * @brief The request method of the HTTP request. */ @property (nonatomic) OFHTTPRequestMethod method; /** * @brief The headers for the HTTP request. */ @property OF_NULLABLE_PROPERTY (copy, nonatomic) OFDictionary OF_GENERIC(OFString *, OFString *) *headers; /** * @brief The remote address from which the request originates. * * @note The setter creates a copy of the remote address. */ @property OF_NULLABLE_PROPERTY (nonatomic) const OFSocketAddress *remoteAddress; /** * @brief Creates a new OFHTTPRequest. * * @return A new, autoreleased OFHTTPRequest */ + (instancetype)request; |
︙ | ︙ | |||
143 144 145 146 147 148 149 | #endif /** * @brief Returns a C string describing the specified request method. * * @param method The request method which should be described as a C string * @return A C string describing the specified request method */ | | | < | | 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | #endif /** * @brief Returns a C string describing the specified request method. * * @param method The request method which should be described as a C string * @return A C string describing the specified request method */ extern const char *_Nullable OFHTTPRequestMethodName( OFHTTPRequestMethod method); /** * @brief Returns the request method for the specified string. * * @param string The string for which the request method should be returned * @return The request method for the specified string */ extern OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFHTTPRequest.m from [c73164e676] to [44128a59e9].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" const char * | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" const char * OFHTTPRequestMethodName(OFHTTPRequestMethod method) { switch (method) { case OFHTTPRequestMethodOptions: return "OPTIONS"; case OFHTTPRequestMethodGet: return "GET"; case OFHTTPRequestMethodHead: return "HEAD"; case OFHTTPRequestMethodPost: return "POST"; case OFHTTPRequestMethodPut: return "PUT"; case OFHTTPRequestMethodDelete: return "DELETE"; case OFHTTPRequestMethodTrace: return "TRACE"; case OFHTTPRequestMethodConnect: return "CONNECT"; } return NULL; } OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string) { if ([string isEqual: @"OPTIONS"]) return OFHTTPRequestMethodOptions; if ([string isEqual: @"GET"]) return OFHTTPRequestMethodGet; if ([string isEqual: @"HEAD"]) return OFHTTPRequestMethodHead; if ([string isEqual: @"POST"]) return OFHTTPRequestMethodPost; if ([string isEqual: @"PUT"]) return OFHTTPRequestMethodPut; if ([string isEqual: @"DELETE"]) return OFHTTPRequestMethodDelete; if ([string isEqual: @"TRACE"]) return OFHTTPRequestMethodTrace; if ([string isEqual: @"CONNECT"]) return OFHTTPRequestMethodConnect; @throw [OFInvalidArgumentException exception]; } @implementation OFHTTPRequest @synthesize URL = _URL, method = _method, headers = _headers; |
︙ | ︙ | |||
90 91 92 93 94 95 96 | return [[[self alloc] initWithURL: URL] autorelease]; } - (instancetype)init { self = [super init]; | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | return [[[self alloc] initWithURL: URL] autorelease]; } - (instancetype)init { self = [super init]; _method = OFHTTPRequestMethodGet; _protocolVersion.major = 1; _protocolVersion.minor = 1; return self; } - (instancetype)initWithURL: (OFURL *)URL |
︙ | ︙ | |||
119 120 121 122 123 124 125 | { [_URL release]; [_headers release]; [super dealloc]; } | | | | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | { [_URL release]; [_headers release]; [super dealloc]; } - (void)setRemoteAddress: (const OFSocketAddress *)remoteAddress { _hasRemoteAddress = (remoteAddress != NULL); if (_hasRemoteAddress) _remoteAddress = *remoteAddress; } - (const OFSocketAddress *)remoteAddress { if (_hasRemoteAddress) return &_remoteAddress; return NULL; } |
︙ | ︙ | |||
173 174 175 176 177 178 179 | request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || ![request->_URL isEqual: _URL] || ![request->_headers isEqual: _headers]) return false; if (request.remoteAddress != self.remoteAddress && | | | | | | | | | | | | | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | request->_protocolVersion.major != _protocolVersion.major || request->_protocolVersion.minor != _protocolVersion.minor || ![request->_URL isEqual: _URL] || ![request->_headers isEqual: _headers]) return false; if (request.remoteAddress != self.remoteAddress && !OFSocketAddressEqual(request.remoteAddress, self.remoteAddress)) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAdd(&hash, _method); OFHashAdd(&hash, _protocolVersion.major); OFHashAdd(&hash, _protocolVersion.minor); OFHashAddHash(&hash, _URL.hash); OFHashAddHash(&hash, _headers.hash); if (_hasRemoteAddress) OFHashAddHash(&hash, OFSocketAddressHash(&_remoteAddress)); OFHashFinalize(&hash); return hash; } - (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion { if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%hhu.%hhu", protocolVersion.major, protocolVersion.minor]]; _protocolVersion = protocolVersion; } - (OFHTTPRequestProtocolVersion)protocolVersion { return _protocolVersion; } - (void)setProtocolVersionString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; unsigned long long major, minor; OFHTTPRequestProtocolVersion protocolVersion; if (components.count != 2) @throw [OFInvalidFormatException exception]; major = [components.firstObject unsignedLongLongValue]; minor = [components.lastObject unsignedLongLongValue]; |
︙ | ︙ | |||
248 249 250 251 252 253 254 | _protocolVersion.major, _protocolVersion.minor]; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); | | | < | 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | _protocolVersion.major, _protocolVersion.minor]; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); const char *method = OFHTTPRequestMethodName(_method); OFString *indentedHeaders, *remoteAddress, *ret; indentedHeaders = [_headers.description stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; if (_hasRemoteAddress) remoteAddress = OFSocketAddressString(&_remoteAddress); else remoteAddress = nil; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tURL = %@\n" @"\tMethod = %s\n" @"\tHeaders = %@\n" |
︙ | ︙ |
Modified src/OFHTTPResponse.h from [4cf17ed197] to [a9e1fde80c].
︙ | ︙ | |||
24 25 26 27 28 29 30 | /** * @class OFHTTPResponse OFHTTPResponse.h ObjFW/OFHTTPResponse.h * * @brief A class for representing an HTTP request reply as a stream. */ @interface OFHTTPResponse: OFStream { | | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | /** * @class OFHTTPResponse OFHTTPResponse.h ObjFW/OFHTTPResponse.h * * @brief A class for representing an HTTP request reply as a stream. */ @interface OFHTTPResponse: OFStream { OFHTTPRequestProtocolVersion _protocolVersion; short _statusCode; OFDictionary OF_GENERIC(OFString *, OFString *) *_headers; OF_RESERVE_IVARS(OFHTTPResponse, 4) } /** * @brief The protocol version of the HTTP request reply. */ @property (nonatomic) OFHTTPRequestProtocolVersion protocolVersion; /** * @brief The protocol version of the HTTP request reply as a string. */ @property (copy, nonatomic) OFString *protocolVersionString; /** |
︙ | ︙ | |||
62 63 64 65 66 67 68 | /** * @brief Returns the reply as a string, trying to detect the encoding and * falling back to the specified encoding if not detectable. * * @return The reply as a string */ | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | /** * @brief Returns the reply as a string, trying to detect the encoding and * falling back to the specified encoding if not detectable. * * @return The reply as a string */ - (OFString *)stringWithEncoding: (OFStringEncoding)encoding; @end #ifdef __cplusplus extern "C" { #endif /** * @brief Returns a description string for the specified HTTP status code. * * @param code The HTTP status code to return a description string for * @return A description string for the specified HTTP status code */ extern OFString *_Nonnull OFHTTPStatusCodeString(short code); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFHTTPResponse.m from [e267b58d94] to [f1cfec9f86].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" OFString * | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" OFString * OFHTTPStatusCodeString(short code) { switch (code) { case 100: return @"Continue"; case 101: return @"Switching Protocols"; case 200: |
︙ | ︙ | |||
112 113 114 115 116 117 118 | case 505: return @"HTTP Version Not Supported"; default: return @"(unknown)"; } } | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | case 505: return @"HTTP Version Not Supported"; default: return @"(unknown)"; } } static OFStringEncoding encodingForContentType(OFString *contentType) { const char *UTF8String = contentType.UTF8String; size_t last, length = contentType.UTF8StringLength; enum { stateType, stateBeforeParamName, stateParamName, stateParamValueOrQuote, stateParamValue, stateParamQuotedValue, stateAfterParamValue } state = stateType; OFString *name = nil, *value = nil, *charset = nil; OFStringEncoding ret; last = 0; for (size_t i = 0; i < length; i++) { switch (state) { case stateType: if (UTF8String[i] == ';') { state = stateBeforeParamName; last = i + 1; } break; case stateBeforeParamName: if (UTF8String[i] == ' ') last = i + 1; else { state = stateParamName; i--; } break; case stateParamName: if (UTF8String[i] == '=') { name = [OFString stringWithUTF8String: UTF8String + last length: i - last]; state = stateParamValueOrQuote; last = i + 1; } break; case stateParamValueOrQuote: if (UTF8String[i] == '"') { state = stateParamQuotedValue; last = i + 1; } else { state = stateParamValue; i--; } break; case stateParamValue: if (UTF8String[i] == ';') { value = [OFString stringWithUTF8String: UTF8String + last length: i - last]; value = value.stringByDeletingTrailingWhitespaces; if ([name isEqual: @"charset"]) charset = value; state = stateBeforeParamName; last = i + 1; } break; case stateParamQuotedValue: if (UTF8String[i] == '"') { value = [OFString stringWithUTF8String: UTF8String + last length: i - last]; if ([name isEqual: @"charset"]) charset = value; state = stateAfterParamValue; } break; case stateAfterParamValue: if (UTF8String[i] == ';') { state = stateBeforeParamName; last = i + 1; } else if (UTF8String[i] != ' ') return OFStringEncodingAutodetect; break; } } if (state == stateParamValue) { value = [OFString stringWithUTF8String: UTF8String + last length: length - last]; value = value.stringByDeletingTrailingWhitespaces; if ([name isEqual: @"charset"]) charset = value; } @try { ret = OFStringEncodingParseName(charset); } @catch (OFInvalidArgumentException *e) { ret = OFStringEncodingAutodetect; } return ret; } @implementation OFHTTPResponse @synthesize statusCode = _statusCode, headers = _headers; |
︙ | ︙ | |||
245 246 247 248 249 250 251 | - (void)dealloc { [_headers release]; [super dealloc]; } | | | | | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | - (void)dealloc { [_headers release]; [super dealloc]; } - (void)setProtocolVersion: (OFHTTPRequestProtocolVersion)protocolVersion { if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithVersion: [OFString stringWithFormat: @"%hhu.%hhu", protocolVersion.major, protocolVersion.minor]]; _protocolVersion = protocolVersion; } - (OFHTTPRequestProtocolVersion)protocolVersion { return _protocolVersion; } - (void)setProtocolVersionString: (OFString *)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; unsigned long long major, minor; OFHTTPRequestProtocolVersion protocolVersion; if (components.count != 2) @throw [OFInvalidFormatException exception]; major = [components.firstObject unsignedLongLongValue]; minor = [components.lastObject unsignedLongLongValue]; |
︙ | ︙ | |||
294 295 296 297 298 299 300 | return [OFString stringWithFormat: @"%hhu.%hhu", _protocolVersion.major, _protocolVersion.minor]; } - (OFString *)string { | | | | | | | 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | return [OFString stringWithFormat: @"%hhu.%hhu", _protocolVersion.major, _protocolVersion.minor]; } - (OFString *)string { return [self stringWithEncoding: OFStringEncodingAutodetect]; } - (OFString *)stringWithEncoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFString *contentType, *contentLengthString, *ret; OFData *data; if (encoding == OFStringEncodingAutodetect && (contentType = [_headers objectForKey: @"Content-Type"]) != nil) encoding = encodingForContentType(contentType); if (encoding == OFStringEncodingAutodetect) encoding = OFStringEncodingUTF8; data = [self readDataUntilEndOfStream]; contentLengthString = [_headers objectForKey: @"Content-Length"]; if (contentLengthString != nil) { unsigned long long contentLength = contentLengthString.unsignedLongLongValue; |
︙ | ︙ |
Modified src/OFHTTPServer.m from [93f1451d06] to [76527fc01b].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFNumber.h" #import "OFTCPSocket.h" #import "OFTLSSocket.h" #import "OFThread.h" #import "OFTimer.h" #import "OFURL.h" #import "OFAlreadyConnectedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" | > < < < < | 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 | #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFNumber.h" #import "OFSocket+Private.h" #import "OFTCPSocket.h" #import "OFTLSSocket.h" #import "OFThread.h" #import "OFTimer.h" #import "OFURL.h" #import "OFAlreadyConnectedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" /* * FIXME: Key normalization replaces headers like "DNT" with "Dnt". * FIXME: Errors are not reported to the user. */ @interface OFHTTPServer () <OFTCPSocketDelegate> @end |
︙ | ︙ | |||
73 74 75 76 77 78 79 | @interface OFHTTPServerConnection: OFObject <OFTCPSocketDelegate> { @public OFStreamSocket *_socket; OFHTTPServer *_server; OFTimer *_timer; enum { | | | | | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | @interface OFHTTPServerConnection: OFObject <OFTCPSocketDelegate> { @public OFStreamSocket *_socket; OFHTTPServer *_server; OFTimer *_timer; enum { stateAwaitingProlog, stateParsingHeaders, stateSendResponse } _state; uint8_t _HTTPMinorVersion; OFHTTPRequestMethod _method; OFString *_host, *_path; uint16_t _port; OFMutableDictionary *_headers; size_t _contentLength; OFStream *_requestBody; } |
︙ | ︙ | |||
118 119 120 121 122 123 124 | - (void)stop; @end #endif static OF_INLINE OFString * normalizedKey(OFString *key) { | | < < < < | < | | | 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 | - (void)stop; @end #endif static OF_INLINE OFString * normalizedKey(OFString *key) { char *cString = OFStrDup(key.UTF8String); unsigned char *tmp = (unsigned char *)cString; bool firstLetter = true; while (*tmp != '\0') { if (!OFASCIIIsAlpha(*tmp)) { firstLetter = true; tmp++; continue; } *tmp = (firstLetter ? OFASCIIToUpper(*tmp) : OFASCIIToLower(*tmp)); firstLetter = false; tmp++; } @try { return [OFString stringWithUTF8StringNoCopy: cString freeWhenDone: true]; } @catch (id e) { OFFreeMemory(cString); @throw e; } } @implementation OFHTTPServerResponse - (instancetype)initWithSocket: (OFStreamSocket *)sock server: (OFHTTPServer *)server |
︙ | ︙ | |||
185 186 187 188 189 190 191 | void *pool = objc_autoreleasePoolPush(); OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; OFEnumerator *keyEnumerator, *valueEnumerator; OFString *key, *value; [_socket writeFormat: @"HTTP/%@ %hd %@\r\n", self.protocolVersionString, _statusCode, | | < | < | < | < | < | < | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | void *pool = objc_autoreleasePoolPush(); OFMutableDictionary OF_GENERIC(OFString *, OFString *) *headers; OFEnumerator *keyEnumerator, *valueEnumerator; OFString *key, *value; [_socket writeFormat: @"HTTP/%@ %hd %@\r\n", self.protocolVersionString, _statusCode, OFHTTPStatusCodeString(_statusCode)]; headers = [[_headers mutableCopy] autorelease]; if ([headers objectForKey: @"Date"] == nil) { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; [headers setObject: date forKey: @"Date"]; } if ([headers objectForKey: @"Server"] == nil) { OFString *name = _server.name; if (name != nil) [headers setObject: name forKey: @"Server"]; } keyEnumerator = [headers keyEnumerator]; valueEnumerator = [headers objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (value = [valueEnumerator nextObject]) != nil) [_socket writeFormat: @"%@: %@\r\n", key, value]; [_socket writeString: @"\r\n"]; _headersSent = true; _chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; objc_autoreleasePoolPop(pool); } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { /* TODO: Use non-blocking writes */ void *pool; if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (!_headersSent) [self of_sendHeaders]; if (!_chunked) return [_socket writeBuffer: buffer length: length]; pool = objc_autoreleasePoolPush(); [_socket writeString: [OFString stringWithFormat: @"%zX\r\n", length]]; objc_autoreleasePoolPop(pool); [_socket writeBuffer: buffer length: length]; [_socket writeString: @"\r\n"]; return length; } - (void)close { |
︙ | ︙ | |||
300 301 302 303 304 305 306 | _server = [server retain]; _timer = [[OFTimer scheduledTimerWithTimeInterval: 10 target: _socket selector: @selector( cancelAsyncRequests) repeats: false] retain]; | | | 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | _server = [server retain]; _timer = [[OFTimer scheduledTimerWithTimeInterval: 10 target: _socket selector: @selector( cancelAsyncRequests) repeats: false] retain]; _state = stateAwaitingProlog; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
334 335 336 337 338 339 340 | exception: (id)exception { if (line == nil || exception != nil) return false; @try { switch (_state) { | | | | | | | | | | | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | exception: (id)exception { if (line == nil || exception != nil) return false; @try { switch (_state) { case stateAwaitingProlog: return [self parseProlog: line]; case stateParsingHeaders: return [self parseHeaders: line]; default: return false; } } @catch (OFWriteFailedException *e) { return false; } OFEnsure(0); } - (bool)parseProlog: (OFString *)line { OFString *method; OFMutableString *path; size_t pos; @try { OFString *version = [line substringWithRange: OFRangeMake(line.length - 9, 9)]; OFUnichar tmp; if (![version hasPrefix: @" HTTP/1."]) return [self sendErrorAndClose: 505]; tmp = [version characterAtIndex: 8]; if (tmp < '0' || tmp > '9') return [self sendErrorAndClose: 400]; _HTTPMinorVersion = (uint8_t)(tmp - '0'); } @catch (OFOutOfRangeException *e) { return [self sendErrorAndClose: 400]; } pos = [line rangeOfString: @" "].location; if (pos == OFNotFound) return [self sendErrorAndClose: 400]; method = [line substringToIndex: pos]; @try { _method = OFHTTPRequestMethodParseName(method); } @catch (OFInvalidArgumentException *e) { return [self sendErrorAndClose: 405]; } @try { OFRange range = OFRangeMake(pos + 1, line.length - pos - 10); path = [[[line substringWithRange: range] mutableCopy] autorelease]; } @catch (OFOutOfRangeException *e) { return [self sendErrorAndClose: 400]; } [path deleteEnclosingWhitespaces]; [path makeImmutable]; if (![path hasPrefix: @"/"]) return [self sendErrorAndClose: 400]; _headers = [[OFMutableDictionary alloc] init]; _path = [path copy]; _state = stateParsingHeaders; return true; } - (bool)parseHeaders: (OFString *)line { OFString *key, *value, *old; |
︙ | ︙ | |||
441 442 443 444 445 446 447 | contentLength: contentLength]; [_timer invalidate]; [_timer release]; _timer = nil; } | | | | < | < | | | 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | contentLength: contentLength]; [_timer invalidate]; [_timer release]; _timer = nil; } _state = stateSendResponse; [self createResponse]; return false; } pos = [line rangeOfString: @":"].location; if (pos == OFNotFound) return [self sendErrorAndClose: 400]; key = [line substringToIndex: pos]; value = [line substringFromIndex: pos + 1]; key = normalizedKey(key.stringByDeletingTrailingWhitespaces); value = value.stringByDeletingLeadingWhitespaces; old = [_headers objectForKey: key]; if (old != nil) value = [old stringByAppendingFormat: @",%@", value]; [_headers setObject: value forKey: key]; if ([key isEqual: @"Host"]) { pos = [value rangeOfString: @":" options: OFStringSearchBackwards].location; if (pos != OFNotFound) { [_host release]; _host = [[value substringToIndex: pos] retain]; @try { unsigned long long portTmp = [value substringFromIndex: pos + 1] .unsignedLongLongValue; |
︙ | ︙ | |||
499 500 501 502 503 504 505 | return true; } - (bool)sendErrorAndClose: (short)statusCode { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; | < | < < | 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | return true; } - (bool)sendErrorAndClose: (short)statusCode { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; [_socket writeFormat: @"HTTP/1.1 %hd %@\r\n" @"Date: %@\r\n" @"Server: %@\r\n" @"\r\n", statusCode, OFHTTPStatusCodeString(statusCode), date, _server.name]; return false; } - (void)createResponse { void *pool = objc_autoreleasePoolPush(); OFMutableURL *URL; |
︙ | ︙ | |||
540 541 542 543 544 545 546 | URL = [OFMutableURL URL]; URL.scheme = @"http"; URL.host = _host; if (_port != 80) URL.port = [OFNumber numberWithUnsignedShort: _port]; | | | | 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | URL = [OFMutableURL URL]; URL.scheme = @"http"; URL.host = _host; if (_port != 80) URL.port = [OFNumber numberWithUnsignedShort: _port]; if ((pos = [_path rangeOfString: @"?"].location) != OFNotFound) { OFString *path, *query; path = [_path substringToIndex: pos]; query = [_path substringFromIndex: pos + 1]; URL.URLEncodedPath = path; URL.URLEncodedQuery = query; } else URL.URLEncodedPath = _path; [URL makeImmutable]; request = [OFHTTPRequest requestWithURL: URL]; request.method = _method; request.protocolVersion = (OFHTTPRequestProtocolVersion){ 1, _HTTPMinorVersion }; request.headers = _headers; request.remoteAddress = _socket.remoteAddress; response = [[[OFHTTPServerResponse alloc] initWithSocket: _socket server: _server request: request] autorelease]; |
︙ | ︙ | |||
612 613 614 615 616 617 618 | } - (bool)lowlevelIsAtEndOfStream { return _atEndOfStream; } | | < | < | < | < | < < | | | 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | } - (bool)lowlevelIsAtEndOfStream { return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { if (_socket == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if (_socket.atEndOfStream) @throw [OFTruncatedDataException exception]; /* Content-Length */ if (!_chunked) { size_t ret; if (length > (unsigned long long)_toRead) length = (size_t)_toRead; ret = [_socket readIntoBuffer: buffer length: length]; _toRead -= ret; if (_toRead == 0) _atEndOfStream = true; return ret; } /* Chunked */ if (_toRead == -2) { char tmp[2]; switch ([_socket readIntoBuffer: tmp length: 2]) { case 2: _toRead++; if (tmp[1] != '\n') @throw [OFInvalidFormatException exception]; case 1: _toRead++; if (tmp[0] != '\r') @throw [OFInvalidFormatException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead == -1) { char tmp; if ([_socket readIntoBuffer: &tmp length: 1] == 1) { _toRead++; if (tmp != '\n') @throw [OFInvalidFormatException exception]; } if (_setAtEndOfStream && _toRead == 0) _atEndOfStream = true; return 0; } else if (_toRead > 0) { if (length > (unsigned long long)_toRead) length = (size_t)_toRead; length = [_socket readIntoBuffer: buffer length: length]; _toRead -= length; if (_toRead == 0) _toRead = -2; return length; } else { void *pool = objc_autoreleasePoolPush(); OFString *line; size_t pos; unsigned long long toRead; @try { line = [_socket tryReadLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidFormatException exception]; } if (line == nil) return 0; pos = [line rangeOfString: @";"].location; if (pos != OFNotFound) line = [line substringToIndex: pos]; if (line.length < 1) { /* * We have read the empty string because the socket is * at end of stream. */ if (_socket.atEndOfStream && pos == OFNotFound) @throw [OFTruncatedDataException exception]; else @throw [OFInvalidFormatException exception]; } toRead = [line unsignedLongLongValueWithBase: 16]; if (toRead > LLONG_MAX) |
︙ | ︙ | |||
920 921 922 923 924 925 926 | if (_listeningSocket != nil) @throw [OFAlreadyConnectedException exception]; if (_usesTLS) { OFTCPSocket <OFTLSSocket> *TLSSocket; | | | | < | 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 | if (_listeningSocket != nil) @throw [OFAlreadyConnectedException exception]; if (_usesTLS) { OFTCPSocket <OFTLSSocket> *TLSSocket; if (OFTLSSocketClass == Nil) @throw [OFUnsupportedProtocolException exception]; TLSSocket = [[OFTLSSocketClass alloc] init]; _listeningSocket = TLSSocket; TLSSocket.certificateFile = _certificateFile; TLSSocket.privateKeyFile = _privateKeyFile; TLSSocket.privateKeyPassphrase = _privateKeyPassphrase; } else _listeningSocket = [[OFTCPSocket alloc] init]; _port = [_listeningSocket bindToHost: _host port: _port]; [_listeningSocket listen]; #ifdef OF_HAVE_THREADS if (_numberOfThreads > 1) { OFMutableArray *threads = [OFMutableArray arrayWithCapacity: _numberOfThreads - 1]; |
︙ | ︙ | |||
995 996 997 998 999 1000 1001 | exception: (id)exception { if (exception != nil) { if (![_delegate respondsToSelector: @selector(server:didReceiveExceptionOnListeningSocket:)]) return false; | | | 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 | exception: (id)exception { if (exception != nil) { if (![_delegate respondsToSelector: @selector(server:didReceiveExceptionOnListeningSocket:)]) return false; return [_delegate server: self didReceiveExceptionOnListeningSocket: exception]; } #ifdef OF_HAVE_THREADS if (_numberOfThreads > 1) { OFHTTPServerThread *thread = [_threadPool objectAtIndex: _nextThreadIndex]; |
︙ | ︙ |
Modified src/OFHostAddressResolver.h from [6761889c77] to [303154eb82].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFDNSResolver.h" #import "OFRunLoop.h" | < | | | | | | 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 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFDNSResolver.h" #import "OFRunLoop.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN @class OFDNSResolverSettings; @class OFDNSResourceRecord; @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableData; @class OFString; @interface OFHostAddressResolver: OFObject <OFDNSResolverQueryDelegate> { OFString *_host; OFSocketAddressFamily _addressFamily; OFDNSResolver *_resolver; OFDNSResolverSettings *_settings; OFRunLoopMode _Nullable _runLoopMode; id <OFDNSResolverHostDelegate> _Nullable _delegate; bool _isFQDN; size_t _searchDomainIndex; unsigned int _numExpectedResponses; OFMutableData *_addresses; } - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily resolver: (OFDNSResolver *)resolver settings: (OFDNSResolverSettings *)settings runLoopMode: (nullable OFRunLoopMode)runLoopMode delegate: (nullable id <OFDNSResolverHostDelegate>)delegate; - (void)asyncResolve; - (OFData *)resolve; @end OF_ASSUME_NONNULL_END |
Modified src/OFHostAddressResolver.m from [2d5bf5c91e] to [ba379d973e].
︙ | ︙ | |||
36 37 38 39 40 41 42 | @public bool _done; OFData *_addresses; id _exception; } @end | | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | @public bool _done; OFData *_addresses; id _exception; } @end static const OFRunLoopMode resolveRunLoopMode = @"OFHostAddressResolverResolveRunLoopMode"; static bool isFQDN(OFString *host, unsigned int minNumberOfDotsInAbsoluteName) { const char *UTF8String; size_t length; unsigned int dots; |
︙ | ︙ | |||
62 63 64 65 66 67 68 | dots++; return (dots >= minNumberOfDotsInAbsoluteName); } static bool addressForRecord(OF_KINDOF(OFDNSResourceRecord *) record, | | < | | | | | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | dots++; return (dots >= minNumberOfDotsInAbsoluteName); } static bool addressForRecord(OF_KINDOF(OFDNSResourceRecord *) record, const OFSocketAddress **address, OFSocketAddressFamily addressFamily) { switch ([record recordType]) { #ifdef OF_HAVE_IPV6 case OFDNSRecordTypeAAAA: if (addressFamily != OFSocketAddressFamilyIPv6 && addressFamily != OFSocketAddressFamilyAny) return false; break; #endif case OFDNSRecordTypeA: if (addressFamily != OFSocketAddressFamilyIPv4 && addressFamily != OFSocketAddressFamilyAny) return false; break; default: return false; } *address = [record address]; return true; } static void callDelegateInMode(OFRunLoopMode runLoopMode, id <OFDNSResolverHostDelegate> delegate, OFDNSResolver *resolver, OFString *host, OFData *addresses, id exception) { SEL selector = @selector(resolver:didResolveHost:addresses:exception:); if ([delegate respondsToSelector: selector]) { OFTimer *timer = [OFTimer |
︙ | ︙ | |||
110 111 112 113 114 115 116 | [[OFRunLoop currentRunLoop] addTimer: timer forMode: runLoopMode]; } } @implementation OFHostAddressResolver: OFObject - (instancetype)initWithHost: (OFString *)host | | | | 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | [[OFRunLoop currentRunLoop] addTimer: timer forMode: runLoopMode]; } } @implementation OFHostAddressResolver: OFObject - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily resolver: (OFDNSResolver *)resolver settings: (OFDNSResolverSettings *)settings runLoopMode: (OFRunLoopMode)runLoopMode delegate: (id <OFDNSResolverHostDelegate>)delegate { self = [super init]; @try { _host = [host copy]; _addressFamily = addressFamily; |
︙ | ︙ | |||
159 160 161 162 163 164 165 | domainName = [OFString stringWithFormat: @"%@.%@", _host, searchDomain]; } else domainName = _host; #ifdef OF_HAVE_IPV6 | | | | | | | | | | | | | | | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | domainName = [OFString stringWithFormat: @"%@.%@", _host, searchDomain]; } else domainName = _host; #ifdef OF_HAVE_IPV6 if (_addressFamily == OFSocketAddressFamilyIPv6 || _addressFamily == OFSocketAddressFamilyAny) { OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeAAAA]; _numExpectedResponses++; [_resolver asyncPerformQuery: query runLoopMode: _runLoopMode delegate: self]; } #endif if (_addressFamily == OFSocketAddressFamilyIPv4 || _addressFamily == OFSocketAddressFamilyAny) { OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: OFDNSClassIN recordType: OFDNSRecordTypeA]; _numExpectedResponses++; [_resolver asyncPerformQuery: query runLoopMode: _runLoopMode delegate: self]; } } - (void)resolver: (OFDNSResolver *)resolver didPerformQuery: (OFDNSQuery *)query response: (OFDNSResponse *)response exception: (id)exception { _numExpectedResponses--; if ([exception isKindOfClass: [OFDNSQueryFailedException class]] && [exception errorCode] == OFDNSResolverErrorCodeServerNameError && !_isFQDN && _numExpectedResponses == 0 && _addresses.count == 0 && _searchDomainIndex + 1 < _settings->_searchDomains.count) { _searchDomainIndex++; [self sendQueries]; return; } for (OF_KINDOF(OFDNSResourceRecord *) record in [response.answerRecords objectForKey: query.domainName]) { const OFSocketAddress *address = NULL; OFDNSQuery *CNAMEQuery; if ([record DNSClass] != OFDNSClassIN) continue; if (addressForRecord(record, &address, _addressFamily)) { [_addresses addItem: address]; continue; } if ([record recordType] != OFDNSRecordTypeCNAME) continue; /* FIXME: Check if it's already in answers */ CNAMEQuery = [OFDNSQuery queryWithDomainName: [record alias] DNSClass: OFDNSClassIN recordType: query.recordType]; _numExpectedResponses++; [_resolver asyncPerformQuery: CNAMEQuery runLoopMode: _runLoopMode delegate: self]; } |
︙ | ︙ | |||
241 242 243 244 245 246 247 | _addresses = nil; if ([exception isKindOfClass: [OFDNSQueryFailedException class]]) exception = [OFResolveHostFailedException exceptionWithHost: _host addressFamily: _addressFamily | | | | < | | | | | | | | < | < < < | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | _addresses = nil; if ([exception isKindOfClass: [OFDNSQueryFailedException class]]) exception = [OFResolveHostFailedException exceptionWithHost: _host addressFamily: _addressFamily errorCode: [exception errorCode]]; if (exception == nil) exception = [OFResolveHostFailedException exceptionWithHost: _host addressFamily: _addressFamily errorCode: OFDNSResolverErrorCodeNoResult]; } else exception = nil; if ([_delegate respondsToSelector: @selector(resolver:didResolveHost:addresses:exception:)]) [_delegate resolver: _resolver didResolveHost: _host addresses: _addresses exception: exception]; } - (void)asyncResolve { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC(OFString *) *aliases; @try { OFSocketAddress address = OFSocketAddressParseIP(_host, 0); OFData *addresses = nil; id exception = nil; if (_addressFamily == address.family || _addressFamily == OFSocketAddressFamilyAny) addresses = [OFData dataWithItems: &address count: 1 itemSize: sizeof(address)]; else exception = [OFInvalidArgumentException exception]; callDelegateInMode(_runLoopMode, _delegate, _resolver, _host, addresses, exception); objc_autoreleasePoolPop(pool); return; } @catch (OFInvalidFormatException *e) { } if ((aliases = [_settings->_staticHosts objectForKey: _host]) != nil) { OFMutableData *addresses = [OFMutableData dataWithItemSize: sizeof(OFSocketAddress)]; id exception = nil; for (OFString *alias in aliases) { OFSocketAddress address; @try { address = OFSocketAddressParseIP(alias, 0); } @catch (OFInvalidFormatException *e) { continue; } if (_addressFamily != address.family && _addressFamily != OFSocketAddressFamilyAny) continue; [addresses addItem: &address]; } [addresses makeImmutable]; if (addresses.count == 0) { addresses = nil; exception = [OFResolveHostFailedException exceptionWithHost: _host addressFamily: _addressFamily errorCode: OFDNSResolverErrorCodeNoResult]; } callDelegateInMode(_runLoopMode, _delegate, _resolver, _host, addresses, exception); objc_autoreleasePoolPop(pool); return; } _isFQDN = isFQDN(_host, _settings->_minNumberOfDotsInAbsoluteName); _addresses = [[OFMutableData alloc] initWithItemSize: sizeof(OFSocketAddress)]; [self sendQueries]; objc_autoreleasePoolPop(pool); } - (OFData *)resolve { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; OFHostAddressResolverDelegate *delegate; OFData *ret; delegate = [[[OFHostAddressResolverDelegate alloc] init] autorelease]; _runLoopMode = [resolveRunLoopMode copy]; _delegate = [delegate retain]; [self asyncResolve]; while (!delegate->_done) [runLoop runMode: resolveRunLoopMode beforeDate: nil]; /* Cleanup */ [runLoop runMode: resolveRunLoopMode beforeDate: [OFDate date]]; if (delegate->_exception != nil) @throw delegate->_exception; ret = [delegate->_addresses copy]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end @implementation OFHostAddressResolverDelegate - (void)dealloc { |
︙ | ︙ |
Renamed and modified src/huffman_tree.h [2155b8e3b4] to src/OFHuffmanTree.h [fd05cd38a9].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "macros.h" #import "OFInvalidFormatException.h" OF_ASSUME_NONNULL_BEGIN | | | | > | | | | 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 | #import "macros.h" #import "OFInvalidFormatException.h" OF_ASSUME_NONNULL_BEGIN typedef struct _OFHuffmanTree { struct _OFHuffmanTree *_Nullable leaves[2]; uint16_t value; } *OFHuffmanTree; /* Inlined for performance. */ static OF_INLINE bool OFHuffmanTreeWalk(id _Nullable stream, bool (*bitReader)(id _Nullable, uint16_t *_Nonnull, uint8_t), OFHuffmanTree _Nonnull *_Nonnull tree, uint16_t *_Nonnull value) { OFHuffmanTree iter = *tree; uint16_t bits; while (iter->value == 0xFFFF) { if OF_UNLIKELY (!bitReader(stream, &bits, 1)) { *tree = iter; return false; } |
︙ | ︙ | |||
50 51 52 53 54 55 56 | *value = iter->value; return true; } #ifdef __cplusplus extern "C" { #endif | < | < | > | | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | *value = iter->value; return true; } #ifdef __cplusplus extern "C" { #endif extern OFHuffmanTree _Nonnull OFHuffmanTreeNew(uint8_t lengths[_Nonnull], uint16_t count); extern OFHuffmanTree _Nonnull OFHuffmanTreeNewSingle(uint16_t value); extern void OFHuffmanTreeFree(OFHuffmanTree _Nonnull tree); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Renamed and modified src/huffman_tree.m [c8d56de598] to src/OFHuffmanTree.m [f7a4f8d9de].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include <stdint.h> #include <stdlib.h> | | | | | | < | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | */ #include "config.h" #include <stdint.h> #include <stdlib.h> #import "OFHuffmanTree.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" static OFHuffmanTree newTree(void) { OFHuffmanTree tree; tree = OFAllocMemory(1, sizeof(*tree)); tree->leaves[0] = tree->leaves[1] = NULL; tree->value = 0xFFFF; return tree; } static void treeInsert(OFHuffmanTree tree, uint16_t code, uint8_t length, uint16_t value) { while (length > 0) { uint8_t bit; length--; bit = (code & (1u << length)) >> length; if (tree->leaves[bit] == NULL) tree->leaves[bit] = newTree(); tree = tree->leaves[bit]; } tree->value = value; } OFHuffmanTree OFHuffmanTreeNew(uint8_t lengths[], uint16_t count) { OFHuffmanTree tree; uint16_t *lengthCount = NULL; uint16_t code, maxCode = 0, *nextCode = NULL; uint_fast8_t maxBit = 0; @try { for (uint16_t i = 0; i < count; i++) { uint_fast8_t length = lengths[i]; if OF_UNLIKELY (length > maxBit) { lengthCount = OFResizeMemory(lengthCount, length + 1, sizeof(uint16_t)); nextCode = OFResizeMemory(nextCode, length + 1, sizeof(uint16_t)); for (uint_fast8_t j = maxBit + 1; j <= length; j++) { lengthCount[j] = 0; nextCode[j] = 0; } |
︙ | ︙ | |||
95 96 97 98 99 100 101 | tree = newTree(); for (uint16_t i = 0; i <= maxCode; i++) { uint8_t length = lengths[i]; if (length > 0) | | | | | | | | | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | tree = newTree(); for (uint16_t i = 0; i <= maxCode; i++) { uint8_t length = lengths[i]; if (length > 0) treeInsert(tree, nextCode[length]++, length, i); } } @finally { OFFreeMemory(lengthCount); OFFreeMemory(nextCode); } return tree; } OFHuffmanTree OFHuffmanTreeNewSingle(uint16_t value) { OFHuffmanTree tree = newTree(); tree->value = value; return tree; } void OFHuffmanTreeFree(OFHuffmanTree tree) { for (uint_fast8_t i = 0; i < 2; i++) if OF_LIKELY (tree->leaves[i] != NULL) OFHuffmanTreeFree(tree->leaves[i]); OFFreeMemory(tree); } |
Modified src/OFINICategory+Private.h from [c5a381e443] to [6b052bbd06].
︙ | ︙ | |||
21 22 23 24 25 26 27 | @class OFStream; OF_DIRECT_MEMBERS @interface OFINICategory () - (instancetype)of_initWithName: (OFString *)name OF_METHOD_FAMILY(init); - (void)of_parseLine: (OFString *)line; - (bool)of_writeToStream: (OFStream *)stream | | | 21 22 23 24 25 26 27 28 29 30 31 32 | @class OFStream; OF_DIRECT_MEMBERS @interface OFINICategory () - (instancetype)of_initWithName: (OFString *)name OF_METHOD_FAMILY(init); - (void)of_parseLine: (OFString *)line; - (bool)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding first: (bool)first; @end OF_ASSUME_NONNULL_END |
Modified src/OFINICategory.h from [4d30d101c6] to [f788995406].
︙ | ︙ | |||
37 38 39 40 41 42 43 | * @brief The name of the INI category */ @property (copy, nonatomic) OFString *name; - (instancetype)init OF_UNAVAILABLE; /** | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | < | | | | | | | | < | | | | | | | < | | | | < | | | | | < | | | | < | | | | < | | | | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | * @brief The name of the INI category */ @property (copy, nonatomic) OFString *name; - (instancetype)init OF_UNAVAILABLE; /** * @brief Returns the string for the specified key, or `nil` if it does not * exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the string should be returned * @return The string for the specified key, or `nil` if it does not exist */ - (nullable OFString *)stringForKey: (OFString *)key; /** * @brief Returns the string for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the string should be returned * @param defaultValue The value to return if the key does not exist * @return The string for the specified key or the specified default value if * it does not exist */ - (nullable OFString *)stringForKey: (OFString *)key defaultValue: (nullable OFString *)defaultValue; /** * @brief Returns the long long for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the long long should be returned * @param defaultValue The value to return if the key does not exist * @return The long long for the specified key or the specified default value * if it does not exist */ - (long long)longLongForKey: (OFString *)key defaultValue: (long long)defaultValue; /** * @brief Returns the bool for the specified key or the specified default value * if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the bool should be returned * @param defaultValue The value to return if the key does not exist * @return The bool for the specified key or the specified default value if it * does not exist */ - (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue; /** * @brief Returns the float for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the float should be returned * @param defaultValue The value to return if the key does not exist * @return The float for the specified key or the specified default value if it * does not exist */ - (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue; /** * @brief Returns the double for the specified key or the specified default * value if it does not exist. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is returned. * * @param key The key for which the double should be returned * @param defaultValue The value to return if the key does not exist * @return The double for the specified key or the specified default value if * it does not exist */ - (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue; /** * @brief Returns an array of strings for the specified multi-key, or an empty * array if the key does not exist. * * A multi-key is a key which exists several times in the same category. Each * occurrence of the key/value pair adds the respective value to the array. * * @param key The multi-key for which the array should be returned * @return The array for the specified key, or an empty array if it does not * exist */ - (OFArray OF_GENERIC(OFString *) *)stringArrayForKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified string. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is changed. * * @param string The string to which the key should be set * @param key The key for which the new value should be set */ - (void)setString: (OFString *)string forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified long long. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is changed. * * @param longLong The long long to which the key should be set * @param key The key for which the new value should be set */ - (void)setLongLong: (long long)longLong forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified bool. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is changed. * * @param bool_ The bool to which the key should be set * @param key The key for which the new value should be set */ - (void)setBool: (bool)bool_ forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified float. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is changed. * * @param float_ The float to which the key should be set * @param key The key for which the new value should be set */ - (void)setFloat: (float)float_ forKey: (OFString *)key; /** * @brief Sets the value of the specified key to the specified double. * * If the specified key is a multi-key (see @ref stringArrayForKey:), the value * of the first key/value pair found is changed. * * @param double_ The double to which the key should be set * @param key The key for which the new value should be set */ - (void)setDouble: (double)double_ forKey: (OFString *)key; /** * @brief Sets the specified multi-key to the specified array of strings. * * It replaces the first occurrence of the multi-key with several key/value * pairs and removes all following occurrences. If the multi-key does not exist * yet, it is appended to the section. * * See also @ref stringArrayForKey: for more information about multi-keys. * * @param array The array of strings to which the multi-key should be set * @param key The multi-key for which the new values should be set */ - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forKey: (OFString *)key; /** * @brief Removes the value for the specified key * * If the specified key is a multi-key (see @ref stringArrayForKey:), all * key/value pairs matching the specified key are removed. * * @param key The key of the value to remove */ - (void)removeValueForKey: (OFString *)key; @end OF_ASSUME_NONNULL_END |
Modified src/OFINICategory.m from [8974141c79] to [4bd3d1b960].
︙ | ︙ | |||
48 49 50 51 52 53 54 | ![string hasPrefix: @"\f"] && ![string hasSuffix: @" "] && ![string hasSuffix: @"\t"] && ![string hasSuffix: @"\f"] && ![string containsString: @"\""]) return string; mutableString = [[string mutableCopy] autorelease]; | | < | < | < | < | < | | < | < | < | < | < > > > > > > > > > > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | ![string hasPrefix: @"\f"] && ![string hasSuffix: @" "] && ![string hasSuffix: @"\t"] && ![string hasSuffix: @"\f"] && ![string containsString: @"\""]) return string; mutableString = [[string mutableCopy] autorelease]; [mutableString replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; [mutableString replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [mutableString replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [mutableString replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [mutableString replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [mutableString prependString: @"\""]; [mutableString appendString: @"\""]; [mutableString makeImmutable]; return mutableString; } static OFString * unescapeString(OFString *string) { OFMutableString *mutableString; if (![string hasPrefix: @"\""] || ![string hasSuffix: @"\""]) return string; string = [string substringWithRange: OFRangeMake(1, string.length - 2)]; mutableString = [[string mutableCopy] autorelease]; [mutableString replaceOccurrencesOfString: @"\\f" withString: @"\f"]; [mutableString replaceOccurrencesOfString: @"\\r" withString: @"\r"]; [mutableString replaceOccurrencesOfString: @"\\n" withString: @"\n"]; [mutableString replaceOccurrencesOfString: @"\\\"" withString: @"\""]; [mutableString replaceOccurrencesOfString: @"\\\\" withString: @"\\"]; [mutableString makeImmutable]; return mutableString; } @implementation OFINICategoryPair - (void)dealloc { [_key release]; [_value release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"%@ = %@", _key, _value]; } @end @implementation OFINICategoryComment - (void)dealloc { [_comment release]; [super dealloc]; } - (OFString *)description { return [[_comment copy] autorelease]; } @end @implementation OFINICategory @synthesize name = _name; - (instancetype)of_initWithName: (OFString *)name OF_DIRECT { |
︙ | ︙ | |||
152 153 154 155 156 157 158 | { if (![line hasPrefix: @";"]) { OFINICategoryPair *pair = [[[OFINICategoryPair alloc] init] autorelease]; OFString *key, *value; size_t pos; | | | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | { if (![line hasPrefix: @";"]) { OFINICategoryPair *pair = [[[OFINICategoryPair alloc] init] autorelease]; OFString *key, *value; size_t pos; if ((pos = [line rangeOfString: @"="].location) == OFNotFound) @throw [OFInvalidFormatException exception]; key = unescapeString([line substringToIndex: pos] .stringByDeletingEnclosingWhitespaces); value = unescapeString([line substringFromIndex: pos + 1] .stringByDeletingEnclosingWhitespaces); |
︙ | ︙ | |||
176 177 178 179 180 181 182 | [_lines addObject: comment]; } } - (OFString *)stringForKey: (OFString *)key { | | < | | | < | < | < | < | < | < | < | | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | [_lines addObject: comment]; } } - (OFString *)stringForKey: (OFString *)key { return [self stringForKey: key defaultValue: nil]; } - (OFString *)stringForKey: (OFString *)key defaultValue: (OFString *)defaultValue { for (id line in _lines) { OFINICategoryPair *pair; if (![line isKindOfClass: [OFINICategoryPair class]]) continue; pair = line; if ([pair->_key isEqual: key]) return [[pair->_value copy] autorelease]; } return defaultValue; } - (long long)longLongForKey: (OFString *)key defaultValue: (long long)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringForKey: key defaultValue: nil]; long long ret; if (value != nil) ret = [value longLongValueWithBase: 0]; else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (bool)boolForKey: (OFString *)key defaultValue: (bool)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringForKey: key defaultValue: nil]; bool ret; if (value != nil) { if ([value isEqual: @"true"]) ret = true; else if ([value isEqual: @"false"]) ret = false; else @throw [OFInvalidFormatException exception]; } else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (float)floatForKey: (OFString *)key defaultValue: (float)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringForKey: key defaultValue: nil]; float ret; if (value != nil) ret = value.floatValue; else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (double)doubleForKey: (OFString *)key defaultValue: (double)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *value = [self stringForKey: key defaultValue: nil]; double ret; if (value != nil) ret = value.doubleValue; else ret = defaultValue; objc_autoreleasePoolPop(pool); return ret; } - (OFArray OF_GENERIC(OFString *) *)stringArrayForKey: (OFString *)key { OFMutableArray *ret = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (id line in _lines) { OFINICategoryPair *pair; |
︙ | ︙ | |||
299 300 301 302 303 304 305 | objc_autoreleasePoolPop(pool); [ret makeImmutable]; return ret; } | | < | 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | objc_autoreleasePoolPop(pool); [ret makeImmutable]; return ret; } - (void)setString: (OFString *)string forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); OFINICategoryPair *pair; for (id line in _lines) { if (![line isKindOfClass: [OFINICategoryPair class]]) continue; |
︙ | ︙ | |||
340 341 342 343 344 345 346 | @throw e; } objc_autoreleasePoolPop(pool); } | < | | | < | < | < | < | | | | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | @throw e; } objc_autoreleasePoolPop(pool); } - (void)setLongLong: (long long)longLong forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setString: [OFString stringWithFormat: @"%lld", longLong] forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setBool: (bool)bool_ forKey: (OFString *)key { [self setString: (bool_ ? @"true" : @"false") forKey: key]; } - (void)setFloat: (float)float_ forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setString: [OFString stringWithFormat: @"%g", float_] forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setDouble: (double)double_ forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); [self setString: [OFString stringWithFormat: @"%g", double_] forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forKey: (OFString *)key { void *pool; OFMutableArray *pairs; id const *lines; size_t count; bool replaced; if (array.count == 0) { [self removeValueForKey: key]; return; } pool = objc_autoreleasePoolPush(); pairs = [OFMutableArray arrayWithCapacity: array.count]; for (OFString *string in array) { OFINICategoryPair *pair; if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; pair = [[[OFINICategoryPair alloc] init] autorelease]; pair->_key = [key copy]; pair->_value = [string copy]; [pairs addObject: pair]; } lines = _lines.objects; count = _lines.count; replaced = false; |
︙ | ︙ | |||
478 479 480 481 482 483 484 | } } objc_autoreleasePoolPop(pool); } - (bool)of_writeToStream: (OFStream *)stream | | < | < > > > > > > | 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | } } objc_autoreleasePoolPop(pool); } - (bool)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding first: (bool)first { if (_lines.count == 0) return false; if (first) [stream writeFormat: @"[%@]\r\n", _name]; else [stream writeFormat: @"\r\n[%@]\r\n", _name]; for (id line in _lines) { if ([line isKindOfClass: [OFINICategoryComment class]]) { OFINICategoryComment *comment = line; [stream writeFormat: @"%@\r\n", comment->_comment]; } else if ([line isKindOfClass: [OFINICategoryPair class]]) { OFINICategoryPair *pair = line; OFString *key = escapeString(pair->_key); OFString *value = escapeString(pair->_value); OFString *tmp = [OFString stringWithFormat: @"%@=%@\r\n", key, value]; [stream writeString: tmp encoding: encoding]; } else @throw [OFInvalidArgumentException exception]; } return true; } - (OFString *)description { return [OFString stringWithFormat: @"<%@ \"%@\": %@>", self.class, _name, _lines]; } @end |
Modified src/OFINIFile.h from [5f1fab4818] to [8b191bee9f].
︙ | ︙ | |||
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 | */ OF_SUBCLASSING_RESTRICTED @interface OFINIFile: OFObject { OFMutableArray OF_GENERIC(OFINICategory *) *_categories; } /** * @brief Creates a new OFINIFile with the contents of the specified file. * * @param path The path to the file whose contents the OFINIFile should contain * * @return A new, autoreleased OFINIFile with the contents of the specified file */ + (instancetype)fileWithPath: (OFString *)path; /** * @brief Creates a new OFINIFile with the contents of the specified file in * the specified encoding. * * @param path The path to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * * @return A new, autoreleased OFINIFile with the contents of the specified file */ + (instancetype)fileWithPath: (OFString *)path | > > > > > | | 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 61 62 63 64 65 66 | */ OF_SUBCLASSING_RESTRICTED @interface OFINIFile: OFObject { OFMutableArray OF_GENERIC(OFINICategory *) *_categories; } /** * @brief All categories in the INI file. */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFINICategory *) *categories; /** * @brief Creates a new OFINIFile with the contents of the specified file. * * @param path The path to the file whose contents the OFINIFile should contain * * @return A new, autoreleased OFINIFile with the contents of the specified file */ + (instancetype)fileWithPath: (OFString *)path; /** * @brief Creates a new OFINIFile with the contents of the specified file in * the specified encoding. * * @param path The path to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * * @return A new, autoreleased OFINIFile with the contents of the specified file */ + (instancetype)fileWithPath: (OFString *)path encoding: (OFStringEncoding)encoding; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFINIFile with the contents of the * specified file. * |
︙ | ︙ | |||
71 72 73 74 75 76 77 | * * @param path The path to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * * @return An initialized OFINIFile with the contents of the specified file */ - (instancetype)initWithPath: (OFString *)path | | | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | * * @param path The path to the file whose contents the OFINIFile should contain * @param encoding The encoding of the specified file * * @return An initialized OFINIFile with the contents of the specified file */ - (instancetype)initWithPath: (OFString *)path encoding: (OFStringEncoding)encoding OF_DESIGNATED_INITIALIZER; /** * @brief Returns an @ref OFINICategory for the category with the specified * name. * * @param name The name of the category for which an @ref OFINICategory should |
︙ | ︙ | |||
99 100 101 102 103 104 105 | /** * @brief Writes the contents of the OFINIFile to a file in the specified * encoding. * * @param path The path of the file to write to * @param encoding The encoding to use */ | | < | 104 105 106 107 108 109 110 111 112 113 114 | /** * @brief Writes the contents of the OFINIFile to a file in the specified * encoding. * * @param path The path of the file to write to * @param encoding The encoding to use */ - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END |
Modified src/OFINIFile.m from [c32d0fe539] to [512706fb2b].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #import "OFINICategory+Private.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" OF_DIRECT_MEMBERS @interface OFINIFile () | | < | > > | | < | | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #import "OFINICategory+Private.h" #import "OFInvalidFormatException.h" #import "OFOpenItemFailedException.h" OF_DIRECT_MEMBERS @interface OFINIFile () - (void)of_parseFile: (OFString *)path encoding: (OFStringEncoding)encoding; @end static bool isWhitespaceLine(OFString *line) { const char *cString = line.UTF8String; size_t length = line.UTF8StringLength; for (size_t i = 0; i < length; i++) if (!OFASCIIIsSpace(cString[i])) return false; return true; } @implementation OFINIFile @synthesize categories = _categories; + (instancetype)fileWithPath: (OFString *)path { return [[[self alloc] initWithPath: path] autorelease]; } + (instancetype)fileWithPath: (OFString *)path encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithPath: path encoding: encoding] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithPath: (OFString *)path { return [self initWithPath: path encoding: OFStringEncodingUTF8]; } - (instancetype)initWithPath: (OFString *)path encoding: (OFStringEncoding)encoding { self = [super init]; @try { _categories = [[OFMutableArray alloc] init]; [self of_parseFile: path encoding: encoding]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
108 109 110 111 112 113 114 | [_categories addObject: category]; objc_autoreleasePoolPop(pool); return category; } | | < | < | < | < | < | < > > > > > > | 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | [_categories addObject: category]; objc_autoreleasePoolPop(pool); return category; } - (void)of_parseFile: (OFString *)path encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file; OFINICategory *category = nil; OFString *line; @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { /* Handle missing file like an empty file */ if (e.errNo == ENOENT) return; @throw e; } while ((line = [file readLineWithEncoding: encoding]) != nil) { if (isWhitespaceLine(line)) continue; if ([line hasPrefix: @"["]) { OFString *categoryName; if (![line hasSuffix: @"]"]) @throw [OFInvalidFormatException exception]; categoryName = [line substringWithRange: OFRangeMake(1, line.length - 2)]; category = [[[OFINICategory alloc] of_initWithName: categoryName] autorelease]; [_categories addObject: category]; } else { if (category == nil) @throw [OFInvalidFormatException exception]; [category of_parseLine: line]; } } objc_autoreleasePoolPop(pool); } - (void)writeToFile: (OFString *)path { [self writeToFile: path encoding: OFStringEncodingUTF8]; } - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; bool first = true; for (OFINICategory *category in _categories) if ([category of_writeToStream: file encoding: encoding first: first]) first = false; objc_autoreleasePoolPop(pool); } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, _categories]; } @end |
Modified src/OFINIFileSettings.m from [d5a169cfa7] to [b35044d2f1].
︙ | ︙ | |||
53 54 55 56 57 58 59 | } - (void)of_getCategory: (OFString **)category andKey: (OFString **)key forPath: (OFString *)path OF_DIRECT { size_t pos = [path rangeOfString: @"." | | | | < | > | > > | > | > > > > | | < | | < < < | < < | | > | > > | > | > > > > | < | | | < < < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < | | | < < < | | | < | < < < | < | < < < | < | < < < | | < < < | | < < < | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | } - (void)of_getCategory: (OFString **)category andKey: (OFString **)key forPath: (OFString *)path OF_DIRECT { size_t pos = [path rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound) { *category = @""; *key = path; return; } *category = [path substringToIndex: pos]; *key = [path substringFromIndex: pos + 1]; } - (void)setString: (OFString *)string forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setString: string forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setLongLong: (long long)longLong forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setLongLong: longLong forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setBool: (bool)bool_ forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setBool: bool_ forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setFloat: (float)float_ forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setFloat: float_ forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setDouble: (double)double_ forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setDouble: double_ forKey: key]; objc_autoreleasePoolPop(pool); } - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] setStringArray: array forKey: key]; objc_autoreleasePoolPop(pool); } - (OFString *)stringForPath: (OFString *)path defaultValue: (OFString *)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key, *ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] stringForKey: key defaultValue: defaultValue]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (long long)longLongForPath: (OFString *)path defaultValue: (long long)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; long long ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] longLongForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (bool)boolForPath: (OFString *)path defaultValue: (bool)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; bool ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] boolForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (float)floatForPath: (OFString *)path defaultValue: (float)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; float ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] floatForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (double)doubleForPath: (OFString *)path defaultValue: (double)defaultValue { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; double ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] doubleForKey: key defaultValue: defaultValue]; objc_autoreleasePoolPop(pool); return ret; } - (OFArray OF_GENERIC(OFString *) *)stringArrayForPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; OFArray *ret; [self of_getCategory: &category andKey: &key forPath: path]; ret = [[_INIFile categoryForName: category] stringArrayForKey: key]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)removeValueForPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFString *category, *key; [self of_getCategory: &category andKey: &key forPath: path]; [[_INIFile categoryForName: category] removeValueForKey: key]; objc_autoreleasePoolPop(pool); } - (void)save { |
︙ | ︙ |
Modified src/OFIPSocketAsyncConnector.h from [a61a99efb6] to [185e130707].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFDNSResolver.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" OF_ASSUME_NONNULL_BEGIN @protocol OFIPSocketAsyncConnecting | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #import "OFDNSResolver.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" OF_ASSUME_NONNULL_BEGIN @protocol OFIPSocketAsyncConnecting - (bool)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end @interface OFIPSocketAsyncConnector: OFObject <OFRunLoopConnectDelegate, OFDNSResolverHostDelegate> { |
︙ | ︙ | |||
42 43 44 45 46 47 48 | - (instancetype)initWithSocket: (id)sock host: (OFString *)host port: (uint16_t)port delegate: (nullable id)delegate block: (nullable id)block; - (void)didConnect; | | | | 42 43 44 45 46 47 48 49 50 51 52 53 | - (instancetype)initWithSocket: (id)sock host: (OFString *)host port: (uint16_t)port delegate: (nullable id)delegate block: (nullable id)block; - (void)didConnect; - (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode; - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end OF_ASSUME_NONNULL_END |
Modified src/OFIPSocketAsyncConnector.m from [dac9c59275] to [f532e1ec24].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <errno.h> #import "OFIPSocketAsyncConnector.h" #import "OFData.h" | < < < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include "config.h" #include <errno.h> #import "OFIPSocketAsyncConnector.h" #import "OFData.h" #import "OFTCPSocket.h" #import "OFThread.h" #import "OFTimer.h" #import "OFConnectionFailedException.h" #import "OFInvalidFormatException.h" |
︙ | ︙ | |||
68 69 70 71 72 73 74 | { if (_exception == nil) [_socket setCanBlock: true]; #ifdef OF_HAVE_BLOCKS if (_block != NULL) { if ([_socket isKindOfClass: [OFTCPSocket class]]) | < | < < < < < | | | < | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | { if (_exception == nil) [_socket setCanBlock: true]; #ifdef OF_HAVE_BLOCKS if (_block != NULL) { if ([_socket isKindOfClass: [OFTCPSocket class]]) ((OFTCPSocketAsyncConnectBlock)_block)(_exception); else OFEnsure(0); } else { #endif if ([_delegate respondsToSelector: @selector(socket:didConnectToHost:port:exception:)]) [_delegate socket: _socket didConnectToHost: _host port: _port exception: _exception]; #ifdef OF_HAVE_BLOCKS } #endif } - (void)of_socketDidConnect: (id)sock exception: (id)exception { if (exception != nil) { /* * self might be retained only by the pending async requests, * which we're about to cancel. */ [[self retain] autorelease]; |
︙ | ︙ | |||
121 122 123 124 125 126 127 | @selector(tryNextAddressWithRunLoopMode:); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: runLoop.currentMode repeats: false]; | | < | | | | < | 111 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 | @selector(tryNextAddressWithRunLoopMode:); OFTimer *timer = [OFTimer timerWithTimeInterval: 0 target: self selector: selector object: runLoop.currentMode repeats: false]; [runLoop addTimer: timer forMode: runLoop.currentMode]; } return; } [self didConnect]; } - (id)of_connectionFailedExceptionForErrNo: (int)errNo { return [OFConnectionFailedException exceptionWithHost: _host port: _port socket: _socket errNo: errNo]; } - (void)tryNextAddressWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = *(const OFSocketAddress *) [_socketAddresses itemAtIndex: _socketAddressesIndex++]; int errNo; OFSocketAddressSetPort(&address, _port); if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { if (_socketAddressesIndex >= _socketAddresses.count) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host port: _port socket: _socket errNo: errNo]; [self didConnect]; |
︙ | ︙ | |||
179 180 181 182 183 184 185 | * FIXME: Use a different thread as a work around. */ [_socket setCanBlock: true]; #else [_socket setCanBlock: false]; #endif | | < > > > > | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | * FIXME: Use a different thread as a work around. */ [_socket setCanBlock: true]; #else [_socket setCanBlock: false]; #endif if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) { #if !defined(OF_NINTENDO_3DS) && !defined(OF_WII) # ifdef OF_WINDOWS if (errNo == EINPROGRESS || errNo == EWOULDBLOCK) { # else if (errNo == EINPROGRESS) { # endif [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } else { #endif [_socket of_closeSocket]; |
︙ | ︙ | |||
232 233 234 235 236 237 238 | _socketAddresses = [addresses copy]; [self tryNextAddressWithRunLoopMode: [OFRunLoop currentRunLoop].currentMode]; } | | < | | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | _socketAddresses = [addresses copy]; [self tryNextAddressWithRunLoopMode: [OFRunLoop currentRunLoop].currentMode]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { @try { OFSocketAddress address = OFSocketAddressParseIP(_host, _port); _socketAddresses = [[OFData alloc] initWithItems: &address count: 1 itemSize: sizeof(address)]; [self tryNextAddressWithRunLoopMode: runLoopMode]; return; } @catch (OFInvalidFormatException *e) { } [[OFThread DNSResolver] asyncResolveAddressesForHost: _host addressFamily: OFSocketAddressFamilyAny runLoopMode: runLoopMode delegate: self]; } @end |
Modified src/OFIPXSocket.h from [3a07b6e6f2] to [635704366b].
︙ | ︙ | |||
28 29 30 31 32 33 34 | @end /** * @class OFIPXSocket OFIPXSocket.h ObjFW/OFIPXSocket.h * * @brief A class which provides methods to create and use IPX sockets. * | | | | | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | @end /** * @class OFIPXSocket OFIPXSocket.h ObjFW/OFIPXSocket.h * * @brief A class which provides methods to create and use IPX sockets. * * Addresses are of type @ref OFSocketAddress. You can use * @ref OFSocketAddressMakeIPX to create an address or * @ref OFSocketAddressIPXNetwork to get the IPX network, * @ref OFSocketAddressIPXNode to get the IPX node and * @ref OFSocketAddressPort to get the port (sometimes also called * socket number). * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy |
︙ | ︙ | |||
68 69 70 71 72 73 74 | * specified packet type. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached */ | < | | 68 69 70 71 72 73 74 75 76 77 78 | * specified packet type. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @param packetType The packet type to use on the socket * @return The address on which this socket can be reached */ - (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType; @end OF_ASSUME_NONNULL_END |
Modified src/OFIPXSocket.m from [aa8a1a2ffd] to [3bd5ef99ac].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 | #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFIPXSocket.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" | > > < < < < | | | | | | | | | | | | | | | | | < < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFIPXSocket.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" @implementation OFIPXSocket @dynamic delegate; - (OFSocketAddress)bindToPort: (uint16_t)port packetType: (uint8_t)packetType { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address; int protocol = 0; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; address = OFSocketAddressMakeIPX(zeroNode, 0, port); #ifdef OF_WINDOWS protocol = NSPROTO_IPX + packetType; #else _packetType = address.sockaddr.ipx.sipx_type = packetType; #endif if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_DGRAM | SOCK_CLOEXEC, protocol)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithPort: port packetType: packetType socket: self errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: packetType socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (OFGetSockName(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: packetType socket: self errNo: errNo]; } if (address.sockaddr.sockaddr.sa_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: packetType socket: self errNo: EAFNOSUPPORT]; } return address; } #ifndef OF_WINDOWS - (void)sendBuffer: (const void *)buffer length: (size_t)length receiver: (const OFSocketAddress *)receiver { OFSocketAddress fixedReceiver; memcpy(&fixedReceiver, receiver, sizeof(fixedReceiver)); /* If it's not IPX, no fix-up needed - it will fail anyway. */ if (fixedReceiver.family == OFSocketAddressFamilyIPX) fixedReceiver.sockaddr.ipx.sipx_type = _packetType; [super sendBuffer: buffer length: length receiver: &fixedReceiver]; } #endif @end |
Modified src/OFInflate64Stream.h from [a10344d136] to [a6bacf7fa9].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN | > | | | | | | | | | | 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" #import "OFHuffmanTree.h" #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN #define OFInflate64StreamBufferSize 4096 /** * @class OFInflate64Stream OFInflate64Stream.h ObjFW/OFInflate64Stream.h * * @note This class only conforms to OFReadyForReadingObserving if the * underlying stream does so, too. * * @brief A class that handles Deflate decompression transparently for an * underlying stream. */ OF_SUBCLASSING_RESTRICTED @interface OFInflate64Stream: OFStream <OFReadyForReadingObserving> { OFStream *_stream; unsigned char _buffer[OFInflate64StreamBufferSize]; uint16_t _bufferIndex, _bufferLength; uint8_t _byte; uint8_t _bitIndex, _savedBitsLength; uint16_t _savedBits; unsigned char *_Nullable _slidingWindow; uint16_t _slidingWindowIndex, _slidingWindowMask; int _state; union { struct { uint8_t position; uint8_t length[4]; } uncompressedHeader; struct { uint16_t position, length; } uncompressed; struct { OFHuffmanTree _Nullable litLenTree; OFHuffmanTree _Nullable distTree; OFHuffmanTree _Nullable codeLenTree; OFHuffmanTree _Nullable treeIter; uint8_t *_Nullable lengths; uint16_t receivedCount; uint8_t value, litLenCodesCount, distCodesCount; uint8_t codeLenCodesCount; } huffmanTree; struct { OFHuffmanTree _Nullable litLenTree; OFHuffmanTree _Nullable distTree; OFHuffmanTree _Nullable treeIter; int state; uint16_t value, length, distance, extraBits; } huffman; } _context; bool _inLastBlock, _atEndOfStream; } |
︙ | ︙ |
Modified src/OFInflateStream.h from [975875032e] to [f8763882fa].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN | > | | | | | | | | | | 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" #import "OFHuffmanTree.h" #import "OFKernelEventObserver.h" OF_ASSUME_NONNULL_BEGIN #define OFInflateStreamBufferSize 4096 /** * @class OFInflateStream OFInflateStream.h ObjFW/OFInflateStream.h * * @note This class only conforms to OFReadyForReadingObserving if the * underlying stream does so, too. * * @brief A class that handles Deflate decompression transparently for an * underlying stream. */ OF_SUBCLASSING_RESTRICTED @interface OFInflateStream: OFStream <OFReadyForReadingObserving> { OFStream *_stream; unsigned char _buffer[OFInflateStreamBufferSize]; uint16_t _bufferIndex, _bufferLength; uint8_t _byte; uint8_t _bitIndex, _savedBitsLength; uint16_t _savedBits; unsigned char *_Nullable _slidingWindow; uint16_t _slidingWindowIndex, _slidingWindowMask; int _state; union { struct { uint8_t position; uint8_t length[4]; } uncompressedHeader; struct { uint16_t position, length; } uncompressed; struct { OFHuffmanTree _Nullable litLenTree; OFHuffmanTree _Nullable distTree; OFHuffmanTree _Nullable codeLenTree; OFHuffmanTree _Nullable treeIter; uint8_t *_Nullable lengths; uint16_t receivedCount; uint8_t value, litLenCodesCount, distCodesCount; uint8_t codeLenCodesCount; } huffmanTree; struct { OFHuffmanTree _Nullable litLenTree; OFHuffmanTree _Nullable distTree; OFHuffmanTree _Nullable treeIter; int state; uint16_t value, length, distance, extraBits; } huffman; } _context; bool _inLastBlock, _atEndOfStream; } |
︙ | ︙ |
Modified src/OFInflateStream.m from [8a296ae0d3] to [ddc6f9f77f].
︙ | ︙ | |||
22 23 24 25 26 27 28 | #ifndef OF_INFLATE64_STREAM_M # import "OFInflateStream.h" #else # import "OFInflate64Stream.h" # define OFInflateStream OFInflate64Stream #endif | < | | | | | | | | | > | < | | | | | | 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 61 62 63 | #ifndef OF_INFLATE64_STREAM_M # import "OFInflateStream.h" #else # import "OFInflate64Stream.h" # define OFInflateStream OFInflate64Stream #endif #import "OFHuffmanTree.h" #import "OFInitializationFailedException.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" #import "OFOutOfMemoryException.h" #ifndef OF_INFLATE64_STREAM_M # define bufferSize OFInflateStreamBufferSize #else # define bufferSize OFInflate64StreamBufferSize #endif enum State { stateBlockHeader, stateUncompressedBlockHeader, stateUncompressedBlock, stateHuffmanTree, stateHuffmanBlock }; enum HuffmanState { huffmanStateWriteValue, huffmanStateAwaitCode, huffmanStateAwaitLengthExtraBits, huffmanStateAwaitDistance, huffmanStateAwaitDistanceExtraBits, huffmanStateProcessPair }; #ifndef OF_INFLATE64_STREAM_M static const uint8_t numDistanceCodes = 30; static const uint8_t lengthCodes[29] = { /* indices are -257, values -3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, |
︙ | ︙ | |||
96 97 98 99 100 101 102 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14 }; #endif static const uint8_t codeLengthsOrder[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; | | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14 }; #endif static const uint8_t codeLengthsOrder[19] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; static OFHuffmanTree fixedLitLenTree, fixedDistTree; @implementation OFInflateStream static OF_INLINE bool tryReadBits(OFInflateStream *stream, uint16_t *bits, uint8_t count) { uint16_t ret = stream->_savedBits; assert(stream->_savedBitsLength < count); for (uint_fast8_t i = stream->_savedBitsLength; i < count; i++) { if OF_UNLIKELY (stream->_bitIndex == 8) { if OF_LIKELY (stream->_bufferIndex < stream->_bufferLength) stream->_byte = stream->_buffer[stream->_bufferIndex++]; else { size_t length = [stream->_stream readIntoBuffer: stream->_buffer length: bufferSize]; if OF_UNLIKELY (length < 1) { stream->_savedBits = ret; stream->_savedBitsLength = i; return false; } |
︙ | ︙ | |||
157 158 159 160 161 162 163 | for (uint16_t i = 144; i <= 255; i++) lengths[i] = 9; for (uint16_t i = 256; i <= 279; i++) lengths[i] = 7; for (uint16_t i = 280; i <= 287; i++) lengths[i] = 8; | | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | for (uint16_t i = 144; i <= 255; i++) lengths[i] = 9; for (uint16_t i = 256; i <= 279; i++) lengths[i] = 7; for (uint16_t i = 280; i <= 287; i++) lengths[i] = 8; fixedLitLenTree = OFHuffmanTreeNew(lengths, 288); for (uint16_t i = 0; i <= 31; i++) lengths[i] = 5; fixedDistTree = OFHuffmanTreeNew(lengths, 32); } + (instancetype)streamWithStream: (OFStream *)stream { return [[[self alloc] initWithStream: stream] autorelease]; } |
︙ | ︙ | |||
190 191 192 193 194 195 196 | _bitIndex = 8; #ifdef OF_INFLATE64_STREAM_M _slidingWindowMask = 0xFFFF; #else _slidingWindowMask = 0x7FFF; #endif | | | | | < | | | | | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | _bitIndex = 8; #ifdef OF_INFLATE64_STREAM_M _slidingWindowMask = 0xFFFF; #else _slidingWindowMask = 0x7FFF; #endif _slidingWindow = OFAllocZeroedMemory(_slidingWindowMask + 1, 1); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; OFFreeMemory(_slidingWindow); if (_state == stateHuffmanTree) { OFFreeMemory(_context.huffmanTree.lengths); if (_context.huffmanTree.codeLenTree != NULL) OFHuffmanTreeFree(_context.huffmanTree.codeLenTree); } if (_state == stateHuffmanTree || _state == stateHuffmanBlock) { if (_context.huffman.litLenTree != fixedLitLenTree) OFHuffmanTreeFree(_context.huffman.litLenTree); if (_context.huffman.distTree != fixedDistTree) OFHuffmanTreeFree(_context.huffman.distTree); } [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer_ length: (size_t)length |
︙ | ︙ | |||
240 241 242 243 244 245 246 | if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; start: | | | | | | | | | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; start: switch ((enum State)_state) { case stateBlockHeader: if OF_UNLIKELY (_inLastBlock) { [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bufferIndex = _bufferLength = 0; _atEndOfStream = true; return bytesWritten; } if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) return bytesWritten; _inLastBlock = (bits & 1); switch (bits >> 1) { case 0: /* No compression */ _state = stateUncompressedBlockHeader; _bitIndex = 8; _context.uncompressedHeader.position = 0; memset(_context.uncompressedHeader.length, 0, 4); break; case 1: /* Fixed Huffman */ _state = stateHuffmanBlock; _context.huffman.state = huffmanStateAwaitCode; _context.huffman.litLenTree = fixedLitLenTree; _context.huffman.distTree = fixedDistTree; _context.huffman.treeIter = fixedLitLenTree; break; case 2: /* Dynamic Huffman */ _state = stateHuffmanTree; _context.huffmanTree.lengths = NULL; _context.huffmanTree.receivedCount = 0; _context.huffmanTree.value = 0xFE; _context.huffmanTree.litLenCodesCount = 0xFF; _context.huffmanTree.distCodesCount = 0xFF; _context.huffmanTree.codeLenCodesCount = 0xFF; break; default: @throw [OFInvalidFormatException exception]; } goto start; case stateUncompressedBlockHeader: #define CTX _context.uncompressedHeader /* FIXME: This can be done more efficiently than unreading */ [_stream unreadFromBuffer: _buffer + _bufferIndex length: _bufferLength - _bufferIndex]; _bufferIndex = _bufferLength = 0; CTX.position += [_stream readIntoBuffer: CTX.length + CTX.position length: 4 - CTX.position]; if OF_UNLIKELY (CTX.position < 4) return bytesWritten; if OF_UNLIKELY ((CTX.length[0] | (CTX.length[1] << 8)) != (uint16_t)~(CTX.length[2] | (CTX.length[3] << 8))) @throw [OFInvalidFormatException exception]; _state = stateUncompressedBlock; /* * Do not reorder! _context.uncompressed.position and * _context.uncompressedHeader.length overlap! */ _context.uncompressed.length = CTX.length[0] | (CTX.length[1] << 8); _context.uncompressed.position = 0; goto start; #undef CTX case stateUncompressedBlock: #define CTX _context.uncompressed if OF_UNLIKELY (length == 0) return bytesWritten; tmp = (length < (size_t)CTX.length - CTX.position ? (uint16_t)length : CTX.length - CTX.position); |
︙ | ︙ | |||
341 342 343 344 345 346 347 | _slidingWindowIndex = slidingWindowIndex; length -= tmp; bytesWritten += tmp; CTX.position += tmp; if OF_UNLIKELY (CTX.position == CTX.length) | | | | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | _slidingWindowIndex = slidingWindowIndex; length -= tmp; bytesWritten += tmp; CTX.position += tmp; if OF_UNLIKELY (CTX.position == CTX.length) _state = stateBlockHeader; goto start; #undef CTX case stateHuffmanTree: #define CTX _context.huffmanTree if OF_LIKELY (CTX.value == 0xFE) { if OF_LIKELY (CTX.litLenCodesCount == 0xFF) { if OF_UNLIKELY (!tryReadBits(self, &bits, 5)) return bytesWritten; if OF_UNLIKELY (bits > 29) |
︙ | ︙ | |||
374 375 376 377 378 379 380 | if OF_UNLIKELY (!tryReadBits(self, &bits, 4)) return bytesWritten; CTX.codeLenCodesCount = bits; } if OF_LIKELY (CTX.lengths == NULL) | | < | | | | | 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | if OF_UNLIKELY (!tryReadBits(self, &bits, 4)) return bytesWritten; CTX.codeLenCodesCount = bits; } if OF_LIKELY (CTX.lengths == NULL) CTX.lengths = OFAllocZeroedMemory(19, 1); for (uint16_t i = CTX.receivedCount; i < CTX.codeLenCodesCount + 4; i++) { if OF_UNLIKELY (!tryReadBits(self, &bits, 3)) { CTX.receivedCount = i; return bytesWritten; } CTX.lengths[codeLengthsOrder[i]] = bits; } CTX.codeLenTree = OFHuffmanTreeNew(CTX.lengths, 19); CTX.treeIter = CTX.codeLenTree; OFFreeMemory(CTX.lengths); CTX.lengths = NULL; CTX.receivedCount = 0; CTX.value = 0xFF; } if OF_LIKELY (CTX.lengths == NULL) CTX.lengths = OFAllocMemory( CTX.litLenCodesCount + CTX.distCodesCount + 258, 1); for (uint16_t i = CTX.receivedCount; i < CTX.litLenCodesCount + CTX.distCodesCount + 258;) { uint8_t j, count; if OF_LIKELY (CTX.value == 0xFF) { if OF_UNLIKELY (!OFHuffmanTreeWalk(self, tryReadBits, &CTX.treeIter, &value)) { CTX.receivedCount = i; return bytesWritten; } CTX.treeIter = CTX.codeLenTree; |
︙ | ︙ | |||
472 473 474 475 476 477 478 | for (j = 0; j < count; j++) CTX.lengths[i++] = value; CTX.value = 0xFF; } | | | | | | | | | | | > | | | > | < > | | > | | | 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 | for (j = 0; j < count; j++) CTX.lengths[i++] = value; CTX.value = 0xFF; } OFHuffmanTreeFree(CTX.codeLenTree); CTX.codeLenTree = NULL; CTX.litLenTree = OFHuffmanTreeNew(CTX.lengths, CTX.litLenCodesCount + 257); CTX.distTree = OFHuffmanTreeNew( CTX.lengths + CTX.litLenCodesCount + 257, CTX.distCodesCount + 1); OFFreeMemory(CTX.lengths); /* * litLenTree and distTree are at the same location in * _context.huffman and _context.huffmanTree, thus no need to * set them. */ _state = stateHuffmanBlock; _context.huffman.state = huffmanStateAwaitCode; _context.huffman.treeIter = CTX.litLenTree; goto start; #undef CTX case stateHuffmanBlock: #define CTX _context.huffman for (;;) { uint8_t extraBits, lengthCodeIndex; if OF_UNLIKELY (CTX.state == huffmanStateWriteValue) { if OF_UNLIKELY (length == 0) return bytesWritten; buffer[bytesWritten++] = CTX.value; length--; _slidingWindow[_slidingWindowIndex] = CTX.value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; CTX.state = huffmanStateAwaitCode; CTX.treeIter = CTX.litLenTree; } if OF_UNLIKELY (CTX.state == huffmanStateAwaitLengthExtraBits) { if OF_UNLIKELY (!tryReadBits(self, &bits, CTX.extraBits)) return bytesWritten; CTX.length += bits; CTX.state = huffmanStateAwaitDistance; CTX.treeIter = CTX.distTree; } /* Distance of length distance pair */ if (CTX.state == huffmanStateAwaitDistance) { if OF_UNLIKELY (!OFHuffmanTreeWalk(self, tryReadBits, &CTX.treeIter, &value)) return bytesWritten; if OF_UNLIKELY (value >= numDistanceCodes) @throw [OFInvalidFormatException exception]; CTX.distance = distanceCodes[value]; extraBits = distanceExtraBits[value]; if (extraBits > 0) { if OF_UNLIKELY (!tryReadBits(self, &bits, extraBits)) { #define HSADEB huffmanStateAwaitDistanceExtraBits CTX.state = HSADEB; #undef HSADEB CTX.extraBits = extraBits; return bytesWritten; } CTX.distance += bits; } CTX.state = huffmanStateProcessPair; } else if (CTX.state == huffmanStateAwaitDistanceExtraBits) { if OF_UNLIKELY (!tryReadBits(self, &bits, CTX.extraBits)) return bytesWritten; CTX.distance += bits; CTX.state = huffmanStateProcessPair; } /* Length distance pair */ if (CTX.state == huffmanStateProcessPair) { for (uint_fast16_t j = 0; j < CTX.length; j++) { uint16_t idx; if OF_UNLIKELY (length == 0) { CTX.length -= j; return bytesWritten; } |
︙ | ︙ | |||
586 587 588 589 590 591 592 | _slidingWindow[_slidingWindowIndex] = value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; } | | | | | | | | 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 | _slidingWindow[_slidingWindowIndex] = value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; } CTX.state = huffmanStateAwaitCode; CTX.treeIter = CTX.litLenTree; } if OF_UNLIKELY (!OFHuffmanTreeWalk(self, tryReadBits, &CTX.treeIter, &value)) return bytesWritten; /* End of block */ if OF_UNLIKELY (value == 256) { if (CTX.litLenTree != fixedLitLenTree) OFHuffmanTreeFree(CTX.litLenTree); if (CTX.distTree != fixedDistTree) OFHuffmanTreeFree(CTX.distTree); _state = stateBlockHeader; goto start; } /* Literal byte */ if OF_LIKELY (value < 256) { if OF_UNLIKELY (length == 0) { CTX.state = huffmanStateWriteValue; CTX.value = value; return bytesWritten; } buffer[bytesWritten++] = value; length--; |
︙ | ︙ | |||
637 638 639 640 641 642 643 | CTX.length = lengthCodes[lengthCodeIndex] + 3; extraBits = lengthExtraBits[lengthCodeIndex]; if (extraBits > 0) { if OF_UNLIKELY (!tryReadBits(self, &bits, extraBits)) { CTX.extraBits = extraBits; | | > | | 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | CTX.length = lengthCodes[lengthCodeIndex] + 3; extraBits = lengthExtraBits[lengthCodeIndex]; if (extraBits > 0) { if OF_UNLIKELY (!tryReadBits(self, &bits, extraBits)) { CTX.extraBits = extraBits; CTX.state = huffmanStateAwaitLengthExtraBits; return bytesWritten; } CTX.length += bits; } CTX.treeIter = CTX.distTree; CTX.state = huffmanStateAwaitDistance; } break; #undef CTX } OF_UNREACHABLE |
︙ | ︙ |
Modified src/OFInvertedCharacterSet.h from [6a080d4b74] to [c74c805b51].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @interface OFInvertedCharacterSet: OFCharacterSet { OFCharacterSet *_characterSet; | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @interface OFInvertedCharacterSet: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, OFUnichar); } - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet; @end OF_ASSUME_NONNULL_END |
Modified src/OFInvertedCharacterSet.m from [ea0333ca6e] to [e08da05e4c].
︙ | ︙ | |||
28 29 30 31 32 33 34 | - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet { self = [super init]; @try { _characterSet = [characterSet retain]; | | | | 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 61 62 63 | - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet { self = [super init]; @try { _characterSet = [characterSet retain]; _characterIsMember = (bool (*)(id, SEL, OFUnichar)) [_characterSet methodForSelector: @selector(characterIsMember:)]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_characterSet release]; [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { return !_characterIsMember(_characterSet, @selector(characterIsMember:), character); } - (OFCharacterSet *)invertedSet { return [[_characterSet retain] autorelease]; } @end |
Modified src/OFInvocation.h from [0b22e6a97b] to [8c29c4a2ab].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN | < < < < < < < < < < < < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFMethodSignature; @class OFMutableArray OF_GENERIC(ObjectType); @class OFMutableData; /** * @class OFInvocation OFInvocation.h ObjFW/OFInvocation.h * |
︙ | ︙ | |||
70 71 72 73 74 75 76 | /** * @brief Sets the argument for the specified index. * * @param buffer The buffer in which the argument is stored * @param index The index of the argument to set */ | | < | < < < < < < < < | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | /** * @brief Sets the argument for the specified index. * * @param buffer The buffer in which the argument is stored * @param index The index of the argument to set */ - (void)setArgument: (const void *)buffer atIndex: (size_t)index; /** * @brief Gets the argument for the specified index. * * @param buffer The buffer in which the argument is stored * @param index The index of the argument to get */ - (void)getArgument: (void *)buffer atIndex: (size_t)index; /** * @brief Sets the return value. * * @param buffer The buffer in which the return value is stored */ - (void)setReturnValue: (const void *)buffer; /** * @brief Gets the return value. * * @param buffer The buffer in which the return value is stored */ - (void)getReturnValue: (void *)buffer; @end OF_ASSUME_NONNULL_END |
Modified src/OFInvocation.m from [85fef7c394] to [a2a3075eb5].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #include <string.h> #import "OFInvocation.h" #import "OFArray.h" #import "OFData.h" #import "OFMethodSignature.h" | < < < < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <string.h> #import "OFInvocation.h" #import "OFArray.h" #import "OFData.h" #import "OFMethodSignature.h" @implementation OFInvocation @synthesize methodSignature = _methodSignature; + (instancetype)invocationWithMethodSignature: (OFMethodSignature *)signature { return [[[self alloc] initWithMethodSignature: signature] autorelease]; } |
︙ | ︙ | |||
48 49 50 51 52 53 54 | _arguments = [[OFMutableArray alloc] init]; for (size_t i = 0; i < numberOfArguments; i++) { OFMutableData *data; typeEncoding = [_methodSignature argumentTypeAtIndex: i]; | | | | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | _arguments = [[OFMutableArray alloc] init]; for (size_t i = 0; i < numberOfArguments; i++) { OFMutableData *data; typeEncoding = [_methodSignature argumentTypeAtIndex: i]; typeSize = OFSizeOfTypeEncoding(typeEncoding); data = [OFMutableData dataWithItemSize: typeSize capacity: 1]; [data increaseCountBy: 1]; [_arguments addObject: data]; } typeEncoding = _methodSignature.methodReturnType; typeSize = OFSizeOfTypeEncoding(typeEncoding); if (typeSize > 0) { _returnValue = [[OFMutableData alloc] initWithItemSize: typeSize capacity: 1]; [_returnValue increaseCountBy: 1]; } |
︙ | ︙ | |||
84 85 86 87 88 89 90 | [_methodSignature release]; [_arguments release]; [_returnValue release]; [super dealloc]; } | | < < | < < < < < < < < < | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | [_methodSignature release]; [_arguments release]; [_returnValue release]; [super dealloc]; } - (void)setArgument: (const void *)buffer atIndex: (size_t)idx { OFMutableData *data = [_arguments objectAtIndex: idx]; memcpy(data.mutableItems, buffer, data.itemSize); } - (void)getArgument: (void *)buffer atIndex: (size_t)idx { OFData *data = [_arguments objectAtIndex: idx]; memcpy(buffer, data.items, data.itemSize); } - (void)setReturnValue: (const void *)buffer { memcpy(_returnValue.mutableItems, buffer, _returnValue.itemSize); } - (void)getReturnValue: (void *)buffer { memcpy(buffer, _returnValue.items, _returnValue.itemSize); } @end |
Modified src/OFJSONRepresentation.h from [121e6d00f3] to [02ee58f172].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFObject.h" @class OFString; OF_ASSUME_NONNULL_BEGIN | > > > | > | > | | < > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFObject.h" @class OFString; OF_ASSUME_NONNULL_BEGIN /** * @brief Options to change the behavior when creating a JSON representation. */ typedef enum { /** Optimize for readability */ OFJSONRepresentationOptionPretty = 0x01, /** Generate JSON5 */ OFJSONRepresentationOptionJSON5 = 0x02, OFJSONRepresentationOptionIsIdentifier = 0x10 } OFJSONRepresentationOptions; /** * @protocol OFJSONRepresentation * OFJSONRepresentation.h ObjFW/OFJSONRepresentation.h * * @brief A protocol implemented by classes that support encoding to a JSON * representation. |
︙ | ︙ | |||
41 42 43 44 45 46 47 | * @brief The JSON representation of the object as a string. */ @property (readonly, nonatomic) OFString *JSONRepresentation; /** * @brief Returns the JSON representation of the object as a string. * | | < < < < < < | > | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | * @brief The JSON representation of the object as a string. */ @property (readonly, nonatomic) OFString *JSONRepresentation; /** * @brief Returns the JSON representation of the object as a string. * * @param options The options to use when creating a JSON representation * @return The JSON representation of the object as a string */ - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options; @end OF_ASSUME_NONNULL_END |
Modified src/OFKernelEventObserver.h from [9a570d3d9f] to [76fb579d1c].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" | < | | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #ifdef OF_HAVE_SOCKETS # import "OFSocket.h" #endif #ifdef OF_AMIGAOS # include <exec/types.h> # include <exec/tasks.h> #endif |
︙ | ︙ | |||
124 125 126 127 128 129 130 | id <OFKernelEventObserverDelegate> _Nullable _delegate; #if defined(OF_AMIGAOS) struct Task *_waitingTask; ULONG _cancelSignal; #elif defined(OF_HAVE_PIPE) int _cancelFD[2]; #else | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | id <OFKernelEventObserverDelegate> _Nullable _delegate; #if defined(OF_AMIGAOS) struct Task *_waitingTask; ULONG _cancelSignal; #elif defined(OF_HAVE_PIPE) int _cancelFD[2]; #else OFSocketHandle _cancelFD[2]; struct sockaddr_in _cancelAddr; #endif #ifdef OF_AMIGAOS ULONG _execSignalMask; #endif OF_RESERVE_IVARS(OFKernelEventObserver, 4) } |
︙ | ︙ | |||
209 210 211 212 213 214 215 | /** * @brief Observes all objects until an event happens on an object or the * timeout is reached. * * @param timeInterval The time to wait for an event, in seconds */ | | | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | /** * @brief Observes all objects until an event happens on an object or the * timeout is reached. * * @param timeInterval The time to wait for an event, in seconds */ - (void)observeForTimeInterval: (OFTimeInterval)timeInterval; /** * @brief Observes all objects until an event happens on an object or the * specified date is reached. * * @param date The until which to observe */ |
︙ | ︙ |
Modified src/OFKernelEventObserver.m from [9d77b8881b] to [bc5e41d427].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #include <errno.h> #import "OFKernelEventObserver.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" | < < | | < < < < > > > > > > > < < < < < < < < < < < | | 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 61 62 63 64 65 66 67 68 69 70 71 72 | #include <errno.h> #import "OFKernelEventObserver.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #ifdef HAVE_EPOLL # import "OFEpollKernelEventObserver.h" #endif #ifdef HAVE_KQUEUE # import "OFKqueueKernelEventObserver.h" #endif #ifdef HAVE_POLL # import "OFPollKernelEventObserver.h" #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFStream.h" #import "OFStream+Private.h" #ifndef OF_HAVE_PIPE # import "OFStreamSocket.h" #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #ifdef OF_AMIGAOS # include <proto/exec.h> #endif @implementation OFKernelEventObserver @synthesize delegate = _delegate; #ifdef OF_AMIGAOS @synthesize execSignalMask = _execSignalMask; #endif + (void)initialize { if (self != [OFKernelEventObserver class]) return; if (!OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)observer { return [[[self alloc] init] autorelease]; |
︙ | ︙ | |||
116 117 118 119 120 121 122 | #if defined(OF_HAVE_PIPE) && !defined(OF_AMIGAOS) if (pipe(_cancelFD)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #elif !defined(OF_AMIGAOS) _cancelFD[0] = _cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); | | | | | | 106 107 108 109 110 111 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 | #if defined(OF_HAVE_PIPE) && !defined(OF_AMIGAOS) if (pipe(_cancelFD)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #elif !defined(OF_AMIGAOS) _cancelFD[0] = _cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); if (_cancelFD[0] == OFInvalidSocketHandle) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _cancelAddr.sin_family = AF_INET; _cancelAddr.sin_port = 0; _cancelAddr.sin_addr.s_addr = inet_addr((void *)"127.0.0.1"); # ifdef OF_WII _cancelAddr.sin_len = 8; # endif # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) if (bind(_cancelFD[0], (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; cancelAddrLen = sizeof(_cancelAddr); if (OFGetSockName(_cancelFD[0], (struct sockaddr *)&_cancelAddr, &cancelAddrLen) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; # else for (;;) { uint16_t rnd = 0; int ret; while (rnd < 1024) rnd = (uint16_t)rand(); _cancelAddr.sin_port = OFToBigEndian16(rnd); ret = bind(_cancelFD[0], (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)); if (ret == 0) break; if (OFSocketErrNo() != EADDRINUSE) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } # endif #endif } @catch (id e) { [self release]; |
︙ | ︙ | |||
241 242 243 244 245 246 247 | } - (void)observe { [self observeForTimeInterval: -1]; } | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | } - (void)observe { [self observeForTimeInterval: -1]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { OF_UNRECOGNIZED_SELECTOR } - (void)observeUntilDate: (OFDate *)date { [self observeForTimeInterval: date.timeIntervalSinceNow]; |
︙ | ︙ | |||
263 264 265 266 267 268 269 | if (_waitingTask != NULL) { Signal(_waitingTask, (1ul << _cancelSignal)); _waitingTask = NULL; } Permit(); #elif defined(OF_HAVE_PIPE) | | | | | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | if (_waitingTask != NULL) { Signal(_waitingTask, (1ul << _cancelSignal)); _waitingTask = NULL; } Permit(); #elif defined(OF_HAVE_PIPE) OFEnsure(write(_cancelFD[1], "", 1) > 0); #elif defined(OF_WII) OFEnsure(sendto(_cancelFD[1], "", 1, 0, (struct sockaddr *)&_cancelAddr, 8) > 0); #else OFEnsure(sendto(_cancelFD[1], (void *)"", 1, 0, (struct sockaddr *)&_cancelAddr, sizeof(_cancelAddr)) > 0); #endif } @end |
Modified src/OFKeyValueCoding.h from [f61d77bf20] to [859098584b].
︙ | ︙ | |||
57 58 59 60 61 62 63 | /** * @brief Set the value for the specified key. * * @param value The value for the specified key * @param key The key of the value to set */ | | < | < | < | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | /** * @brief Set the value for the specified key. * * @param value The value for the specified key * @param key The key of the value to set */ - (void)setValue: (nullable id)value forKey: (OFString *)key; /** * @brief Set the value for the specified key path. * * @param value The value for the specified key path * @param keyPath The key path of the value to set */ - (void)setValue: (nullable id)value forKeyPath: (OFString *)keyPath; /** * @brief This is called by @ref setValue:forKey: if the specified key does not * exist. * * By default, this throws an @ref OFUndefinedKeyException. * * @param value The value for the specified undefined key * @param key The undefined key of the value to set */ - (void)setValue: (nullable id)value forUndefinedKey: (OFString *)key; /** * @brief This is called by @ref setValue:forKey: if the specified key is a * scalar, but the value specified is `nil`. * * By default, this throws an @ref OFInvalidArgumentException. * |
︙ | ︙ |
Modified src/OFKqueueKernelEventObserver.m from [8d97fca7a9] to [070f451697].
︙ | ︙ | |||
30 31 32 33 34 35 36 | #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" | | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #import "OFKqueueKernelEventObserver.h" #import "OFArray.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #define eventListSize 64 @implementation OFKqueueKernelEventObserver - (instancetype)init { self = [super init]; @try { |
︙ | ︙ | |||
149 150 151 152 153 154 155 | if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; [super removeObjectForWriting: object]; } | | | | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | if (kevent(_kernelQueue, &event, 1, NULL, 0, NULL) != 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { struct timespec timeout; struct kevent eventList[eventListSize]; int events; if ([self of_processReadBuffers]) return; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = (long)((timeInterval - timeout.tv_sec) * 1000000000); events = kevent(_kernelQueue, NULL, 0, eventList, eventListSize, (timeInterval != -1 ? &timeout : NULL)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; for (int i = 0; i < events; i++) { void *pool; if (eventList[i].flags & EV_ERROR) @throw [OFObserveFailedException exceptionWithObserver: self errNo: (int)eventList[i].data]; if (eventList[i].ident == (uintptr_t)_cancelFD[0]) { char buffer; assert(eventList[i].filter == EVFILT_READ); OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); continue; } pool = objc_autoreleasePoolPush(); switch (eventList[i].filter) { |
︙ | ︙ |
Modified src/OFLHAArchive.h from [129ceb20e9] to [934898264e].
︙ | ︙ | |||
27 28 29 30 31 32 33 | * * @brief A class for accessing and manipulating LHA files. */ OF_SUBCLASSING_RESTRICTED @interface OFLHAArchive: OFObject { OFStream *_stream; | < < < < | | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | * * @brief A class for accessing and manipulating LHA files. */ OF_SUBCLASSING_RESTRICTED @interface OFLHAArchive: OFObject { OFStream *_stream; uint_least8_t _mode; OFStringEncoding _encoding; OFStream *_Nullable _lastReturnedStream; } /** * @brief The encoding to use for the archive. Defaults to ISO 8859-1. */ @property (nonatomic) OFStringEncoding encoding; /** * @brief A stream for reading the current entry. * * @note This is only available in read mode. * * @note The returned stream conforms to @ref OFReadyForReadingObserving if the |
︙ | ︙ | |||
61 62 63 64 65 66 67 | * @param stream A stream from which the LHA archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFLHAArchive */ | | < | < | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | * @param stream A stream from which the LHA archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFLHAArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; #ifdef OF_HAVE_FILES /** * @brief Creates a new OFLHAArchive object with the specified file. * * @param path The path to the LHA file * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFLHAArchive */ + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFLHAArchive object with the * specified stream. |
︙ | ︙ | |||
105 106 107 108 109 110 111 | * * @param path The path to the LHA file * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFLHAArchive */ | | < | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | * * @param path The path to the LHA file * @param mode The mode for the LHA file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFLHAArchive */ - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; #endif /** * @brief Returns the next entry from the LHA archive or `nil` if all entries * have been read. * * @note This is only available in read mode. |
︙ | ︙ |
Modified src/OFLHAArchive.m from [2ae2007028] to [8caabc2fe9].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "config.h" #import "OFLHAArchive.h" #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFLHADecompressingStream.h" #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" | > < < > > > > > > | | | | < | < | < | < | < | | | | < | | | < | < | < | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | */ #include "config.h" #import "OFLHAArchive.h" #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFCRC16.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFLHADecompressingStream.h" #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" enum { modeRead, modeWrite, modeAppend }; OF_DIRECT_MEMBERS @interface OFLHAArchiveFileReadStream: OFStream <OFReadyForReadingObserving> { OFStream *_stream, *_decompressedStream; OFLHAArchiveEntry *_entry; uint32_t _toRead, _bytesConsumed; uint16_t _CRC16; bool _atEndOfStream, _skipped; } - (instancetype)of_initWithStream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry; - (void)of_skip; @end OF_DIRECT_MEMBERS @interface OFLHAArchiveFileWriteStream: OFStream <OFReadyForWritingObserving> { OFMutableLHAArchiveEntry *_entry; OFStringEncoding _encoding; OFSeekableStream *_stream; OFFileOffset _headerOffset; uint32_t _bytesWritten; uint16_t _CRC16; } - (instancetype)of_initWithStream: (OFSeekableStream *)stream entry: (OFLHAArchiveEntry *)entry encoding: (OFStringEncoding)encoding; @end @implementation OFLHAArchive @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode { return [[[self alloc] initWithPath: path mode: mode] autorelease]; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { _stream = [stream retain]; if ([mode isEqual: @"r"]) _mode = modeRead; else if ([mode isEqual: @"w"]) _mode = modeWrite; else if ([mode isEqual: @"a"]) _mode = modeAppend; else @throw [OFInvalidArgumentException exception]; if ((_mode == modeWrite || _mode == modeAppend) && ![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; if (_mode == modeAppend) [(OFSeekableStream *)_stream seekToOffset: 0 whence: SEEK_END]; _encoding = OFStringEncodingISO8859_1; } @catch (id e) { [self release]; @throw e; } return self; } #ifdef OF_HAVE_FILES - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode { OFFile *file; if ([mode isEqual: @"a"]) file = [[OFFile alloc] initWithPath: path mode: @"r+"]; else file = [[OFFile alloc] initWithPath: path mode: mode]; @try { self = [self initWithStream: file mode: mode]; } @finally { [file release]; } return self; } #endif |
︙ | ︙ | |||
160 161 162 163 164 165 166 | - (OFLHAArchiveEntry *)nextEntry { OFLHAArchiveEntry *entry; char header[21]; size_t headerLen; | | | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | - (OFLHAArchiveEntry *)nextEntry { OFLHAArchiveEntry *entry; char header[21]; size_t headerLen; if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; [(OFLHAArchiveFileReadStream *)_lastReturnedStream of_skip]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ |
︙ | ︙ | |||
201 202 203 204 205 206 207 | entry: entry]; return entry; } - (OFStream *)streamForReadingCurrentEntry { | | | < | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | entry: entry]; return entry; } - (OFStream *)streamForReadingCurrentEntry { if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if (_lastReturnedStream == nil) @throw [OFInvalidArgumentException exception]; return [[(OFLHAArchiveFileReadStream *)_lastReturnedStream retain] autorelease]; } - (OFStream *)streamForWritingEntry: (OFLHAArchiveEntry *)entry { OFString *compressionMethod; if (_mode != modeWrite && _mode != modeAppend) @throw [OFInvalidArgumentException exception]; compressionMethod = entry.compressionMethod; if (![compressionMethod isEqual: @"-lh0-"] && ![compressionMethod isEqual: @"-lhd-"]) @throw [OFNotImplementedException exceptionWithSelector: _cmd |
︙ | ︙ | |||
321 322 323 324 325 326 327 | { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } | | < | < | | 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if (_stream.atEndOfStream && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; if (length > _toRead) length = _toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC16 = OFCRC16(_CRC16, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (_CRC16 != _entry.CRC16) { OFString *actualChecksum = [OFString stringWithFormat: @"%04" PRIX16, _CRC16]; |
︙ | ︙ | |||
402 403 404 405 406 407 408 | toRead = _entry.compressedSize - decompressingStream.bytesConsumed; stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && | | | | < | 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | toRead = _entry.compressedSize - decompressingStream.bytesConsumed; stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && (sizeof(OFFileOffset) > 4 || toRead < INT32_MAX)) [(OFSeekableStream *)stream seekToOffset: (OFFileOffset)toRead whence: SEEK_CUR]; else { while (toRead > 0) { char buffer[512]; size_t min = toRead; if (min > 512) min = 512; toRead -= [stream readIntoBuffer: buffer length: min]; } } _toRead = 0; _skipped = true; } |
︙ | ︙ | |||
442 443 444 445 446 447 448 | [super close]; } @end @implementation OFLHAArchiveFileWriteStream - (instancetype)of_initWithStream: (OFSeekableStream *)stream entry: (OFLHAArchiveEntry *)entry | | | < | < | 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | [super close]; } @end @implementation OFLHAArchiveFileWriteStream - (instancetype)of_initWithStream: (OFSeekableStream *)stream entry: (OFLHAArchiveEntry *)entry encoding: (OFStringEncoding)encoding { self = [super init]; @try { _entry = [entry mutableCopy]; _encoding = encoding; _headerOffset = [stream seekToOffset: 0 whence: SEEK_CUR]; [_entry of_writeToStream: stream encoding: _encoding]; /* * Retain stream last, so that -[close] called by -[dealloc] * doesn't write in case of an error. */ _stream = [stream retain]; } @catch (id e) { |
︙ | ︙ | |||
478 479 480 481 482 483 484 | [self close]; [_entry release]; [super dealloc]; } | | < | | | | < | < | < | < | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | [self close]; [_entry release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { uint32_t bytesWritten; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (UINT32_MAX - _bytesWritten < length) @throw [OFOutOfRangeException exception]; @try { bytesWritten = (uint32_t)[_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { _bytesWritten += e.bytesWritten; _CRC16 = OFCRC16(_CRC16, buffer, e.bytesWritten); @throw e; } _bytesWritten += (uint32_t)bytesWritten; _CRC16 = OFCRC16(_CRC16, buffer, bytesWritten); return bytesWritten; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _stream.atEndOfStream; } - (int)fileDescriptorForWriting { return ((id <OFReadyForWritingObserving>)_stream) .fileDescriptorForWriting; } - (void)close { OFFileOffset offset; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; _entry.uncompressedSize = _bytesWritten; _entry.compressedSize = _bytesWritten; _entry.CRC16 = _CRC16; offset = [_stream seekToOffset: 0 whence: SEEK_CUR]; [_stream seekToOffset: _headerOffset whence: SEEK_SET]; [_entry of_writeToStream: _stream encoding: _encoding]; [_stream seekToOffset: offset whence: SEEK_SET]; [_stream release]; _stream = nil; [super close]; } @end |
Modified src/OFLHAArchiveEntry+Private.h from [7ab4266d19] to [1e5b6ab947].
︙ | ︙ | |||
17 18 19 20 21 22 23 | OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFLHAArchiveEntry () - (instancetype)of_initWithHeader: (char [_Nonnull 21])header stream: (OFStream *)stream | | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFLHAArchiveEntry () - (instancetype)of_initWithHeader: (char [_Nonnull 21])header stream: (OFStream *)stream encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init); - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END |
Modified src/OFLHAArchiveEntry.m from [a71890ea74] to [54c8747335].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 | #include "config.h" #include <string.h> #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFArray.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" #import "OFStream.h" #import "OFString.h" | > < < | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include "config.h" #include <string.h> #import "OFLHAArchiveEntry.h" #import "OFLHAArchiveEntry+Private.h" #import "OFArray.h" #import "OFCRC16.h" #import "OFData.h" #import "OFDate.h" #import "OFNumber.h" #import "OFStream.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "OFUnsupportedVersionException.h" @implementation OFLHAArchiveEntry static OFDate * |
︙ | ︙ | |||
51 52 53 54 55 56 57 | return [OFDate dateWithLocalDateString: dateString format: @"%Y-%m-%d %H:%M:%S"]; } static void parseFileNameExtension(OFLHAArchiveEntry *entry, OFData *extension, | | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | return [OFDate dateWithLocalDateString: dateString format: @"%Y-%m-%d %H:%M:%S"]; } static void parseFileNameExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_fileName release]; entry->_fileName = nil; entry->_fileName = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: [extension count] - 1]; } static void parseDirectoryNameExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { void *pool = objc_autoreleasePoolPush(); OFMutableData *data = [[extension mutableCopy] autorelease]; char *items = data.mutableItems; size_t count = data.count; OFMutableString *directoryName; |
︙ | ︙ | |||
95 96 97 98 99 100 101 | entry->_directoryName = [directoryName copy]; objc_autoreleasePoolPop(pool); } static void parseCommentExtension(OFLHAArchiveEntry *entry, OFData *extension, | | | | | | | | | | | | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | entry->_directoryName = [directoryName copy]; objc_autoreleasePoolPop(pool); } static void parseCommentExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_fileComment release]; entry->_fileComment = nil; entry->_fileComment = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parsePermissionsExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint16_t mode; if (extension.count != 3) @throw [OFInvalidFormatException exception]; memcpy(&mode, (char *)extension.items + 1, 2); mode = OFFromLittleEndian16(mode); [entry->_mode release]; entry->_mode = nil; entry->_mode = [[OFNumber alloc] initWithUnsignedShort: mode]; } static void parseGIDUIDExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint16_t UID, GID; if (extension.count != 5) @throw [OFInvalidFormatException exception]; memcpy(&GID, (char *)extension.items + 1, 2); GID = OFFromLittleEndian16(GID); memcpy(&UID, (char *)extension.items + 3, 2); UID = OFFromLittleEndian16(UID); [entry->_GID release]; entry->_GID = nil; [entry->_UID release]; entry->_UID = nil; entry->_GID = [[OFNumber alloc] initWithUnsignedShort: GID]; entry->_UID = [[OFNumber alloc] initWithUnsignedShort: UID]; } static void parseGroupExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_group release]; entry->_group = nil; entry->_group = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parseOwnerExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { [entry->_owner release]; entry->_owner = nil; entry->_owner = [[OFString alloc] initWithCString: (char *)extension.items + 1 encoding: encoding length: extension.count - 1]; } static void parseModificationDateExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding) { uint32_t modificationDate; if (extension.count != 5) @throw [OFInvalidFormatException exception]; memcpy(&modificationDate, (char *)extension.items + 1, 4); modificationDate = OFFromLittleEndian32(modificationDate); [entry->_modificationDate release]; entry->_modificationDate = nil; entry->_modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: modificationDate]; } static bool parseExtension(OFLHAArchiveEntry *entry, OFData *extension, OFStringEncoding encoding, bool allowFileName) { void (*function)(OFLHAArchiveEntry *, OFData *, OFStringEncoding) = NULL; switch (*(char *)[extension itemAtIndex: 0]) { case 0x01: if (allowFileName) function = parseFileNameExtension; break; |
︙ | ︙ | |||
238 239 240 241 242 243 244 | function(entry, extension, encoding); return true; } static void readExtensions(OFLHAArchiveEntry *entry, OFStream *stream, | | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | function(entry, extension, encoding); return true; } static void readExtensions(OFLHAArchiveEntry *entry, OFStream *stream, OFStringEncoding encoding, bool allowFileName) { uint16_t size; while ((size = [stream readLittleEndianInt16]) > 0) { OFData *extension; if (size < 2) |
︙ | ︙ | |||
263 264 265 266 267 268 269 | entry->_compressedSize -= size; } } } static void | | < | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | entry->_compressedSize -= size; } } } static void getFileNameAndDirectoryName(OFLHAArchiveEntry *entry, OFStringEncoding encoding, const char **fileName, size_t *fileNameLength, const char **directoryName, size_t *directoryNameLength) { OFMutableData *data; char *cString; size_t length; size_t pos; |
︙ | ︙ | |||
329 330 331 332 333 334 335 | } return self; } - (instancetype)of_initWithHeader: (char [21])header stream: (OFStream *)stream | | | | | | | 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | } return self; } - (instancetype)of_initWithHeader: (char [21])header stream: (OFStream *)stream encoding: (OFStringEncoding)encoding { self = [super init]; @try { uint32_t date; _compressionMethod = [[OFString alloc] initWithCString: header + 2 encoding: OFStringEncodingASCII length: 5]; memcpy(&_compressedSize, header + 7, 4); _compressedSize = OFFromLittleEndian32(_compressedSize); memcpy(&_uncompressedSize, header + 11, 4); _uncompressedSize = OFFromLittleEndian32(_uncompressedSize); memcpy(&date, header + 15, 4); date = OFFromLittleEndian32(date); _headerLevel = header[20]; _extensions = [[OFMutableArray alloc] init]; switch (_headerLevel) { case 0: case 1:; |
︙ | ︙ | |||
551 552 553 554 555 556 557 | - (OFArray OF_GENERIC(OFData *) *)extensions { return _extensions; } - (void)of_writeToStream: (OFStream *)stream | | | | | | < | | < | | < | | < | | < | | < | < | | < | < | | < | | < | | < | | < | | < | | < | | < | | < | | < | | < | | < | < | | | | 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 | - (OFArray OF_GENERIC(OFData *) *)extensions { return _extensions; } - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFMutableData *data = [OFMutableData dataWithCapacity: 24]; const char *fileName, *directoryName; size_t fileNameLength, directoryNameLength; uint16_t tmp16; uint32_t tmp32; size_t headerSize; if ([_compressionMethod cStringLengthWithEncoding: OFStringEncodingASCII] != 5) @throw [OFInvalidArgumentException exception]; getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength, &directoryName, &directoryNameLength); if (fileNameLength > UINT16_MAX - 3 || directoryNameLength > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; /* Length. Filled in after we're done. */ [data increaseCountBy: 2]; [data addItems: [_compressionMethod cStringWithEncoding: OFStringEncodingASCII] count: 5]; tmp32 = OFToLittleEndian32(_compressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; tmp32 = OFToLittleEndian32(_uncompressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; tmp32 = OFToLittleEndian32((uint32_t)_date.timeIntervalSince1970); [data addItems: &tmp32 count: sizeof(tmp32)]; /* Reserved */ [data increaseCountBy: 1]; /* Header level */ [data addItem: "\x02"]; /* CRC16 */ tmp16 = OFToLittleEndian16(_CRC16); [data addItems: &tmp16 count: sizeof(tmp16)]; /* Operating system identifier */ [data addItem: "U"]; /* Common header. Contains CRC16, which is written at the end. */ tmp16 = OFToLittleEndian16(5); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x00"]; [data increaseCountBy: 2]; tmp16 = OFToLittleEndian16((uint16_t)fileNameLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x01"]; [data addItems: fileName count: fileNameLength]; if (directoryNameLength > 0) { tmp16 = OFToLittleEndian16((uint16_t)directoryNameLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x02"]; [data addItems: directoryName count: directoryNameLength]; } if (_fileComment != nil) { size_t fileCommentLength = [_fileComment cStringLengthWithEncoding: encoding]; if (fileCommentLength > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)fileCommentLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x3F"]; [data addItems: [_fileComment cStringWithEncoding: encoding] count: fileCommentLength]; } if (_mode != nil) { tmp16 = OFToLittleEndian16(5); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x50"]; tmp16 = OFToLittleEndian16(_mode.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; } if (_UID != nil || _GID != nil) { if (_UID == nil || _GID == nil) @throw [OFInvalidArgumentException exception]; tmp16 = OFToLittleEndian16(7); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x51"]; tmp16 = OFToLittleEndian16(_GID.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; tmp16 = OFToLittleEndian16(_UID.unsignedShortValue); [data addItems: &tmp16 count: sizeof(tmp16)]; } if (_group != nil) { size_t groupLength = [_group cStringLengthWithEncoding: encoding]; if (groupLength > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)groupLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x52"]; [data addItems: [_group cStringWithEncoding: encoding] count: groupLength]; } if (_owner != nil) { size_t ownerLength = [_owner cStringLengthWithEncoding: encoding]; if (ownerLength > UINT16_MAX - 3) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)ownerLength + 3); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x53"]; [data addItems: [_owner cStringWithEncoding: encoding] count: ownerLength]; } if (_modificationDate != nil) { tmp16 = OFToLittleEndian16(7); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItem: "\x54"]; tmp32 = OFToLittleEndian32( (uint32_t)_modificationDate.timeIntervalSince1970); [data addItems: &tmp32 count: sizeof(tmp32)]; } for (OFData *extension in _extensions) { size_t extensionLength = extension.count; if (extension.itemSize != 1) @throw [OFInvalidArgumentException exception]; if (extensionLength > UINT16_MAX - 2) @throw [OFOutOfRangeException exception]; tmp16 = OFToLittleEndian16((uint16_t)extensionLength + 2); [data addItems: &tmp16 count: sizeof(tmp16)]; [data addItems: extension.items count: extension.count]; } /* Zero-length extension to terminate */ [data increaseCountBy: 2]; headerSize = data.count; if (headerSize > UINT16_MAX) @throw [OFOutOfRangeException exception]; /* Now fill in the size and CRC16 for the entire header */ tmp16 = OFToLittleEndian16(headerSize); memcpy([data mutableItemAtIndex: 0], &tmp16, sizeof(tmp16)); tmp16 = OFCRC16(0, data.items, data.count); tmp16 = OFToLittleEndian16(tmp16); memcpy([data mutableItemAtIndex: 27], &tmp16, sizeof(tmp16)); [stream writeData: data]; objc_autoreleasePoolPop(pool); } |
︙ | ︙ |
Modified src/OFLHADecompressingStream.h from [8c1fbf6c83] to [50abfd9a4a].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN | > | | > | > | | 10 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 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" #import "OFHuffmanTree.h" OF_ASSUME_NONNULL_BEGIN #define OFLHADecompressingStreamBufferSize 4096 OF_DIRECT_MEMBERS @interface OFLHADecompressingStream: OFStream { OFStream *_stream; uint8_t _distanceBits, _dictionaryBits; unsigned char _buffer[OFLHADecompressingStreamBufferSize]; uint32_t _bytesConsumed; uint16_t _bufferIndex, _bufferLength; uint8_t _byte; uint8_t _bitIndex, _savedBitsLength; uint16_t _savedBits; unsigned char *_slidingWindow; uint32_t _slidingWindowIndex, _slidingWindowMask; int _state; uint16_t _symbolsLeft; OFHuffmanTree _Nullable _codeLenTree; OFHuffmanTree _Nullable _litLenTree; OFHuffmanTree _Nullable _distTree; OFHuffmanTree _Nullable _treeIter; uint16_t _codesCount, _codesReceived; bool _currentIsExtendedLength, _skip; uint8_t *_Nullable _codesLengths; uint16_t _length; uint32_t _distance; } |
︙ | ︙ |
Modified src/OFLHADecompressingStream.m from [50a6bfc7bc] to [73678fe27b].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #include <assert.h> #import "OFLHADecompressingStream.h" #import "OFKernelEventObserver.h" | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 | #include "config.h" #include <assert.h> #import "OFLHADecompressingStream.h" #import "OFKernelEventObserver.h" #import "OFHuffmanTree.h" #import "OFInvalidFormatException.h" #import "OFNotOpenException.h" enum State { stateBlockHeader, stateCodeLenCodesCount, stateCodeLenTree, stateCodeLenTreeSingle, stateLitLenCodesCount, stateLitLenTree, stateLitLenTreeSingle, stateDistCodesCount, stateDistTree, stateDistTreeSingle, stateBlockLitLen, stateBlockDistLength, stateBlockDistLengthExtra, stateBlockLenDistPair }; @implementation OFLHADecompressingStream @synthesize bytesConsumed = _bytesConsumed; static OF_INLINE bool tryReadBits(OFLHADecompressingStream *stream, uint16_t *bits, uint8_t count) { uint16_t ret = stream->_savedBits; assert(stream->_savedBitsLength < count); for (uint_fast8_t i = stream->_savedBitsLength; i < count; i++) { if OF_UNLIKELY (stream->_bitIndex == 8) { if OF_LIKELY (stream->_bufferIndex < stream->_bufferLength) stream->_byte = stream->_buffer[stream->_bufferIndex++]; else { const size_t bufferLength = OFLHADecompressingStreamBufferSize; size_t length = [stream->_stream readIntoBuffer: stream->_buffer length: bufferLength]; stream->_bytesConsumed += (uint32_t)length; if OF_UNLIKELY (length < 1) { |
︙ | ︙ | |||
104 105 106 107 108 109 110 | /* 0-7 address the bit, 8 means fetch next byte */ _bitIndex = 8; _distanceBits = distanceBits; _dictionaryBits = dictionaryBits; _slidingWindowMask = (1u << dictionaryBits) - 1; | | | | | | | | | | | | | | | | | 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | /* 0-7 address the bit, 8 means fetch next byte */ _bitIndex = 8; _distanceBits = distanceBits; _dictionaryBits = dictionaryBits; _slidingWindowMask = (1u << dictionaryBits) - 1; _slidingWindow = OFAllocMemory(_slidingWindowMask + 1, 1); memset(_slidingWindow, ' ', _slidingWindowMask + 1); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_stream != nil) [self close]; OFFreeMemory(_slidingWindow); if (_codeLenTree != NULL) OFHuffmanTreeFree(_codeLenTree); if (_litLenTree != NULL) OFHuffmanTreeFree(_litLenTree); if (_distTree != NULL) OFHuffmanTreeFree(_distTree); OFFreeMemory(_codesLengths); [super dealloc]; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer_ length: (size_t)length { unsigned char *buffer = buffer_; uint16_t bits = 0, value = 0; size_t bytesWritten = 0; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_stream.atEndOfStream && _bufferLength - _bufferIndex == 0 && _state == stateBlockHeader) return 0; start: switch ((enum State)_state) { case stateBlockHeader: if OF_UNLIKELY (!tryReadBits(self, &bits, 16)) return bytesWritten; _symbolsLeft = bits; _state = stateCodeLenCodesCount; goto start; case stateCodeLenCodesCount: if OF_UNLIKELY (!tryReadBits(self, &bits, 5)) return bytesWritten; if OF_UNLIKELY (bits > 20) @throw [OFInvalidFormatException exception]; if OF_UNLIKELY (bits == 0) { _state = stateCodeLenTreeSingle; goto start; } _codesCount = bits; _codesReceived = 0; _codesLengths = OFAllocZeroedMemory(bits, 1); _skip = true; _state = stateCodeLenTree; goto start; case stateCodeLenTree: while (_codesReceived < _codesCount) { if OF_UNLIKELY (_currentIsExtendedLength) { if OF_UNLIKELY (!tryReadBits(self, &bits, 1)) return bytesWritten; if OF_UNLIKELY (bits == 0) { _codesReceived++; |
︙ | ︙ | |||
220 221 222 223 224 225 226 | if OF_UNLIKELY (bits == 7) { _currentIsExtendedLength = true; continue; } else _codesReceived++; } | < | | | | | | | | | | | | | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | if OF_UNLIKELY (bits == 7) { _currentIsExtendedLength = true; continue; } else _codesReceived++; } _codeLenTree = OFHuffmanTreeNew(_codesLengths, _codesCount); OFFreeMemory(_codesLengths); _codesLengths = NULL; _state = stateLitLenCodesCount; goto start; case stateCodeLenTreeSingle: if OF_UNLIKELY (!tryReadBits(self, &bits, 5)) return bytesWritten; _codeLenTree = OFHuffmanTreeNewSingle(bits); _state = stateLitLenCodesCount; goto start; case stateLitLenCodesCount: if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; if OF_UNLIKELY (bits > 510) @throw [OFInvalidFormatException exception]; if OF_UNLIKELY (bits == 0) { OFHuffmanTreeFree(_codeLenTree); _codeLenTree = NULL; _state = stateLitLenTreeSingle; goto start; } _codesCount = bits; _codesReceived = 0; _codesLengths = OFAllocZeroedMemory(bits, 1); _skip = false; _treeIter = _codeLenTree; _state = stateLitLenTree; goto start; case stateLitLenTree: while (_codesReceived < _codesCount) { if OF_UNLIKELY (_skip) { uint16_t skipCount; switch (_codesLengths[_codesReceived]) { case 0: skipCount = 1; |
︙ | ︙ | |||
282 283 284 285 286 287 288 | if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; skipCount = bits + 20; break; default: | | | | < | | | | | | | | | | | | | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; skipCount = bits + 20; break; default: OFEnsure(0); } if OF_UNLIKELY (_codesReceived + skipCount > _codesCount) @throw [OFInvalidFormatException exception]; for (uint_fast16_t j = 0; j < skipCount; j++) _codesLengths[_codesReceived++] = 0; _skip = false; continue; } if (!OFHuffmanTreeWalk(self, tryReadBits, &_treeIter, &value)) return bytesWritten; _treeIter = _codeLenTree; if (value < 3) { _codesLengths[_codesReceived] = value; _skip = true; } else _codesLengths[_codesReceived++] = value - 2; } _litLenTree = OFHuffmanTreeNew(_codesLengths, _codesCount); OFFreeMemory(_codesLengths); _codesLengths = NULL; OFHuffmanTreeFree(_codeLenTree); _codeLenTree = NULL; _state = stateDistCodesCount; goto start; case stateLitLenTreeSingle: if OF_UNLIKELY (!tryReadBits(self, &bits, 9)) return bytesWritten; _litLenTree = OFHuffmanTreeNewSingle(bits); _state = stateDistCodesCount; goto start; case stateDistCodesCount: if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits)) return bytesWritten; if OF_UNLIKELY (bits > _dictionaryBits) @throw [OFInvalidFormatException exception]; if OF_UNLIKELY (bits == 0) { _state = stateDistTreeSingle; goto start; } _codesCount = bits; _codesReceived = 0; _codesLengths = OFAllocZeroedMemory(bits, 1); _treeIter = _codeLenTree; _state = stateDistTree; goto start; case stateDistTree: while (_codesReceived < _codesCount) { if OF_UNLIKELY (_currentIsExtendedLength) { if OF_UNLIKELY (!tryReadBits(self, &bits, 1)) return bytesWritten; if OF_UNLIKELY (bits == 0) { _codesReceived++; |
︙ | ︙ | |||
375 376 377 378 379 380 381 | if OF_UNLIKELY (bits == 7) { _currentIsExtendedLength = true; continue; } else _codesReceived++; } | < | | | | | | | | | | | 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | if OF_UNLIKELY (bits == 7) { _currentIsExtendedLength = true; continue; } else _codesReceived++; } _distTree = OFHuffmanTreeNew(_codesLengths, _codesCount); OFFreeMemory(_codesLengths); _codesLengths = NULL; _treeIter = _litLenTree; _state = stateBlockLitLen; goto start; case stateDistTreeSingle: if OF_UNLIKELY (!tryReadBits(self, &bits, _distanceBits)) return bytesWritten; _distTree = OFHuffmanTreeNewSingle(bits); _treeIter = _litLenTree; _state = stateBlockLitLen; goto start; case stateBlockLitLen: if OF_UNLIKELY (_symbolsLeft == 0) { OFHuffmanTreeFree(_litLenTree); OFHuffmanTreeFree(_distTree); _litLenTree = _distTree = NULL; _state = stateBlockHeader; /* * We must return here, as there is no indication * whether this was the last block. Whoever called this * method needs to check if everything has been read * already and only call read again if that is not the * case. |
︙ | ︙ | |||
423 424 425 426 427 428 429 | return bytesWritten; } if OF_UNLIKELY (length == 0) return bytesWritten; | | | | | | < | | | | 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | return bytesWritten; } if OF_UNLIKELY (length == 0) return bytesWritten; if OF_UNLIKELY (!OFHuffmanTreeWalk(self, tryReadBits, &_treeIter, &value)) return bytesWritten; if OF_LIKELY (value < 256) { buffer[bytesWritten++] = value; length--; _slidingWindow[_slidingWindowIndex] = value; _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; _symbolsLeft--; _treeIter = _litLenTree; } else { _length = value - 253; _treeIter = _distTree; _state = stateBlockDistLength; } goto start; case stateBlockDistLength: if OF_UNLIKELY (!OFHuffmanTreeWalk(self, tryReadBits, &_treeIter, &value)) return bytesWritten; _distance = value; _state = (value < 2 ? stateBlockLenDistPair : stateBlockDistLengthExtra); goto start; case stateBlockDistLengthExtra: if OF_UNLIKELY (!tryReadBits(self, &bits, _distance - 1)) return bytesWritten; _distance = bits + (1u << (_distance - 1)); _state = stateBlockLenDistPair; goto start; case stateBlockLenDistPair: for (uint_fast16_t i = 0; i < _length; i++) { uint32_t idx; if OF_UNLIKELY (length == 0) { _length -= i; return bytesWritten; } |
︙ | ︙ | |||
487 488 489 490 491 492 493 | _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; } _symbolsLeft--; _treeIter = _litLenTree; | | | | 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | _slidingWindowIndex = (_slidingWindowIndex + 1) & _slidingWindowMask; } _symbolsLeft--; _treeIter = _litLenTree; _state = stateBlockLitLen; goto start; } OF_UNREACHABLE } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return (_stream.atEndOfStream && _bufferLength - _bufferIndex == 0 && _state == stateBlockHeader); } - (int)fileDescriptorForReading { return ((id <OFReadyForReadingObserving>)_stream) .fileDescriptorForReading; } |
︙ | ︙ |
Modified src/OFList.h from [36d06c646e] to [e9b48b38c5].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN | > | > > > > > > > > | | < | > > > > | > > > > > > > | > > | > > > > > | > > | > | > > > > > | < > > > > > | | | | < | < | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN /** @file */ /* * Make clang's -Wdocumentation shut about about using @struct on someting it * thinks is not a struct. Doxygen requires it this way. */ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wdocumentation" #endif /** * @struct OFListItem OFList.h ObjFW/OFList.h * * @brief A list item. * * See @ref OFListItemNext, @ref OFListItemPrevious and @ref OFListItemObject. */ typedef struct _OFListItem *OFListItem; #ifdef __clang__ # pragma clang diagnostic pop #endif #ifdef __cplusplus extern "C" { #endif /*! * @brief Returns the next list item of the list item. * * @param listItem The list item for which the next list item should be returned * @return The next list item of the list item */ extern OFListItem _Nullable OFListItemNext(OFListItem _Nonnull listItem); /*! * @brief Returns the previous list item of the list item. * * @param listItem The list item for which the previous list item should be * returned * @return The previous list item of the list item */ extern OFListItem _Nullable OFListItemPrevious(OFListItem _Nonnull listItem); /*! * @brief Returns the object of the list item. * * @warning The returned object is not retained and autoreleased - this is the * caller's responsibility! * * @param listItem The list item for which the object should be returned * @return The object of the list item */ extern id _Nonnull OFListItemObject(OFListItem _Nonnull listItem); #ifdef __cplusplus } #endif /** * @class OFList OFList.h ObjFW/OFList.h * * @brief A class which provides easy to use double-linked lists. */ @interface OFList OF_GENERIC(ObjectType): OFObject <OFCopying, OFCollection, OFSerialization> #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif { OFListItem _Nullable _firstListItem; OFListItem _Nullable _lastListItem; size_t _count; unsigned long _mutations; OF_RESERVE_IVARS(OFList, 4) } /** * @brief The first list object of the list. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem firstListItem; /** * @brief The first object of the list or `nil`. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType firstObject; /** * @brief The last list object of the list. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFListItem lastListItem; /** * @brief The last object of the list or `nil`. * * @warning The returned object is *not* retained and autoreleased for * performance reasons! */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) ObjectType lastObject; /** * @brief Creates a new OFList. * * @return A new autoreleased OFList */ + (instancetype)list; /** * @brief Appends an object to the list. * * @param object The object to append * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)appendObject: (ObjectType)object; /** * @brief Prepends an object to the list. * * @param object The object to prepend * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)prependObject: (ObjectType)object; /** * @brief Inserts an object before another list object. * * @param object The object to insert * @param listItem The OFListItem of the object before which it should be * inserted * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)insertObject: (ObjectType)object beforeListItem: (OFListItem)listItem; /** * @brief Inserts an object after another list object. * * @param object The object to insert * @param listItem The OFListItem of the object after which it should be * inserted * @return An OFListItem, needed to identify the object inside the list. * For example, if you want to remove an object from the list, you need * its OFListItem. */ - (OFListItem)insertObject: (ObjectType)object afterListItem: (OFListItem)listItem; /** * @brief Removes the object with the specified list object from the list. * * @param listItem The list object returned by append / prepend */ - (void)removeListItem: (OFListItem)listItem; /** * @brief Checks whether the list contains an object equal to the specified * object. * * @param object The object which is checked for being in the list * @return A boolean whether the list contains the specified object |
︙ | ︙ |
Modified src/OFList.m from [9079ad9449] to [75ee6d9e19].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 | #import "OFList.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFArray.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" OF_DIRECT_MEMBERS @interface OFListEnumerator: OFEnumerator { OFList *_list; | > > > > > | > > > > > > > > > > > > > > > > > > | < | | | < | | | | < | | | | | | | | | | | < | | | | | | | | | | < | < | | | | | | | | | | < | < | | | | | | | | | | | | | | | | | | | | | | | | < | < | | < | | | < < < | | | | | | | | | | | | | < | | | | | < | | | | | | | | | | | < | > | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | #import "OFList.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFArray.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" struct _OFListItem { struct _OFListItem *previous, *next; id object; }; OF_DIRECT_MEMBERS @interface OFListEnumerator: OFEnumerator { OFList *_list; OFListItem _Nullable _current; unsigned long _mutations; unsigned long *_Nullable _mutationsPtr; } - (instancetype)initWithList: (OFList *)list mutationsPointer: (unsigned long *)mutationsPtr; @end OFListItem OFListItemNext(OFListItem listItem) { return listItem->next; } OFListItem OFListItemPrevious(OFListItem listItem) { return listItem->previous; } id OFListItemObject(OFListItem listItem) { return listItem->object; } @implementation OFList @synthesize firstListItem = _firstListItem, lastListItem = _lastListItem; + (instancetype)list { return [[[self alloc] init] autorelease]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *child in [element elementsForNamespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); [self appendObject: child.objectByDeserializing]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { OFListItem next; for (OFListItem iter = _firstListItem; iter != NULL; iter = next) { [iter->object release]; next = iter->next; OFFreeMemory(iter); } [super dealloc]; } - (OFListItem)appendObject: (id)object { OFListItem listItem = OFAllocMemory(1, sizeof(*listItem)); listItem->object = [object retain]; listItem->next = NULL; listItem->previous = _lastListItem; if (_lastListItem != NULL) _lastListItem->next = listItem; _lastListItem = listItem; if (_firstListItem == NULL) _firstListItem = listItem; _count++; _mutations++; return listItem; } - (OFListItem)prependObject: (id)object { OFListItem listItem = OFAllocMemory(1, sizeof(*listItem)); listItem->object = [object retain]; listItem->next = _firstListItem; listItem->previous = NULL; if (_firstListItem != NULL) _firstListItem->previous = listItem; _firstListItem = listItem; if (_lastListItem == NULL) _lastListItem = listItem; _count++; _mutations++; return listItem; } - (OFListItem)insertObject: (id)object beforeListItem: (OFListItem)listItem { OFListItem newListItem = OFAllocMemory(1, sizeof(*newListItem)); newListItem->object = [object retain]; newListItem->next = listItem; newListItem->previous = listItem->previous; if (listItem->previous != NULL) listItem->previous->next = newListItem; listItem->previous = newListItem; if (listItem == _firstListItem) _firstListItem = newListItem; _count++; _mutations++; return newListItem; } - (OFListItem)insertObject: (id)object afterListItem: (OFListItem)listItem { OFListItem newListItem = OFAllocMemory(1, sizeof(*newListItem)); newListItem->object = [object retain]; newListItem->next = listItem->next; newListItem->previous = listItem; if (listItem->next != NULL) listItem->next->previous = newListItem; listItem->next = newListItem; if (listItem == _lastListItem) _lastListItem = newListItem; _count++; _mutations++; return newListItem; } - (void)removeListItem: (OFListItem)listItem { if (listItem->previous != NULL) listItem->previous->next = listItem->next; if (listItem->next != NULL) listItem->next->previous = listItem->previous; if (_firstListItem == listItem) _firstListItem = listItem->next; if (_lastListItem == listItem) _lastListItem = listItem->previous; _count--; _mutations++; [listItem->object release]; OFFreeMemory(listItem); } - (id)firstObject { return (_firstListItem != NULL ? _firstListItem->object : nil); } - (id)lastObject { return (_lastListItem != NULL ? _lastListItem->object : nil); } - (size_t)count { return _count; } - (bool)isEqual: (id)object { OFList *list; OFListItem iter, iter2; if (object == self) return true; if (![object isKindOfClass: [OFList class]]) return false; list = object; if (list.count != _count) return false; for (iter = _firstListItem, iter2 = list.firstListItem; iter != NULL && iter2 != NULL; iter = iter->next, iter2 = iter2->next) if (![iter->object isEqual: iter2->object]) return false; /* One is bigger than the other even though we checked the count */ assert(iter == NULL && iter2 == NULL); return true; } - (bool)containsObject: (id)object { if (_count == 0) return false; for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) if ([iter->object isEqual: object]) return true; return false; } - (bool)containsObjectIdenticalTo: (id)object { if (_count == 0) return false; for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) if (iter->object == object) return true; return false; } - (void)removeAllObjects { OFListItem next; _mutations++; for (OFListItem iter = _firstListItem; iter != NULL; iter = next) { [iter->object release]; next = iter->next; OFFreeMemory(iter); } _firstListItem = _lastListItem = NULL; } - (id)copy { OFList *copy = [[[self class] alloc] init]; OFListItem listItem = NULL, previous = NULL; @try { for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) { listItem = OFAllocMemory(1, sizeof(*listItem)); listItem->object = [iter->object retain]; listItem->next = NULL; listItem->previous = previous; if (copy->_firstListItem == NULL) copy->_firstListItem = listItem; if (previous != NULL) previous->next = listItem; copy->_count++; previous = listItem; } } @catch (id e) { [copy release]; @throw e; } copy->_lastListItem = listItem; return copy; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) OFHashAddHash(&hash, [iter->object hash]); OFHashFinalize(&hash); return hash; } - (OFString *)description { OFMutableString *ret; if (_count == 0) return @"[]"; ret = [OFMutableString stringWithString: @"[\n"]; for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); [ret appendString: [iter->object description]]; if (iter->next != NULL) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n]"]; [ret makeImmutable]; return ret; } - (OFXMLElement *)XMLElementBySerializing { OFXMLElement *element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS]; for (OFListItem iter = _firstListItem; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); [element addChild: [iter->object XMLElementBySerializing]]; objc_autoreleasePoolPop(pool); } return element; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFListItem listItem; memcpy(&listItem, state->extra, sizeof(listItem)); state->itemsPtr = objects; state->mutationsPtr = &_mutations; if (state->state == 0) { listItem = _firstListItem; state->state = 1; } for (int i = 0; i < count; i++) { if (listItem == NULL) return i; objects[i] = listItem->object; listItem = listItem->next; } memcpy(state->extra, &listItem, sizeof(listItem)); return count; } - (OFEnumerator *)objectEnumerator { return [[[OFListEnumerator alloc] initWithList: self mutationsPointer: &_mutations] autorelease]; } @end @implementation OFListEnumerator - (instancetype)initWithList: (OFList *)list mutationsPointer: (unsigned long *)mutationsPtr { self = [super init]; _list = [list retain]; _current = _list.firstListItem; _mutations = *mutationsPtr; _mutationsPtr = mutationsPtr; return self; } - (void)dealloc |
︙ | ︙ |
Modified src/OFLocale.h from [88c5c97127] to [323b529f40].
︙ | ︙ | |||
41 42 43 44 45 46 47 | * * @brief A class for querying the locale and retrieving localized strings. */ OF_SUBCLASSING_RESTRICTED @interface OFLocale: OFObject { OFString *_Nullable _language, *_Nullable _territory; | | | | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | * * @brief A class for querying the locale and retrieving localized strings. */ OF_SUBCLASSING_RESTRICTED @interface OFLocale: OFObject { OFString *_Nullable _language, *_Nullable _territory; OFStringEncoding _encoding; OFString *_decimalPoint; OFMutableArray OF_GENERIC(OFDictionary OF_GENERIC(OFString *, id) *) *_localizedStrings; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFLocale *currentLocale; @property (class, readonly, nullable, nonatomic) OFString *language; @property (class, readonly, nullable, nonatomic) OFString *territory; @property (class, readonly, nonatomic) OFStringEncoding encoding; @property (class, readonly, nullable, nonatomic) OFString *decimalPoint; #endif /** * @brief The language of the locale for messages. * * If the language is unknown, it is `nil`. |
︙ | ︙ | |||
77 78 79 80 81 82 83 | * @brief The native 8-bit string encoding of the locale for messages. * * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. */ | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | * @brief The native 8-bit string encoding of the locale for messages. * * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. */ @property (readonly, nonatomic) OFStringEncoding encoding; /** * @brief The decimal point of the system's locale. */ @property (readonly, nonatomic) OFString *decimalPoint; /** |
︙ | ︙ | |||
123 124 125 126 127 128 129 | * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. * * @return The native 8-bit string encoding for the locale */ | | | 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | * This is useful to encode strings correctly for passing them to operating * system calls. * * If the native 8-bit encoding is unknown, UTF-8 is assumed. * * @return The native 8-bit string encoding for the locale */ + (OFStringEncoding)encoding; /** * @brief Returns the decimal point of the system's locale. * * @return The decimal point of the system's locale */ + (nullable OFString *)decimalPoint; |
︙ | ︙ |
Modified src/OFLocale.m from [640d1c188f] to [947d4e8829].
︙ | ︙ | |||
35 36 37 38 39 40 41 | #endif static OFLocale *currentLocale = nil; static OFDictionary *operatorPrecedences = nil; #ifndef OF_AMIGAOS static void | | | < | | | | > < | < | < | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #endif static OFLocale *currentLocale = nil; static OFDictionary *operatorPrecedences = nil; #ifndef OF_AMIGAOS static void parseLocale(char *locale, OFStringEncoding *encoding, OFString **language, OFString **territory) { locale = OFStrDup(locale); @try { OFStringEncoding enc = OFStringEncodingASCII; char *tmp; /* We don't care for extras behind the @ */ if ((tmp = strrchr(locale, '@')) != NULL) *tmp = '\0'; /* Encoding */ if ((tmp = strrchr(locale, '.')) != NULL) { *tmp++ = '\0'; @try { if (encoding != NULL) *encoding = OFStringEncodingParseName( [OFString stringWithCString: tmp encoding: enc]); } @catch (OFInvalidArgumentException *e) { } } /* Territory */ if ((tmp = strrchr(locale, '_')) != NULL) { *tmp++ = '\0'; if (territory != NULL) *territory = [OFString stringWithCString: tmp encoding: enc]; } if (language != NULL) *language = [OFString stringWithCString: locale encoding: enc]; } @finally { OFFreeMemory(locale); } } #endif static bool evaluateCondition(OFString *condition_, OFDictionary *variables) { OFMutableString *condition = [[condition_ mutableCopy] autorelease]; OFMutableArray *tokens, *operators, *stack; /* Empty condition is the fallback that's always true */ if (condition.length == 0) return true; /* * Dirty hack to allow not needing spaces after "!" or "(" and spaces * before ")". * TODO: Replace with a proper tokenizer. */ [condition replaceOccurrencesOfString: @"!" withString: @"! "]; [condition replaceOccurrencesOfString: @"(" withString: @"( "]; [condition replaceOccurrencesOfString: @")" withString: @" )"]; /* Substitute variables and convert to RPN first */ tokens = [OFMutableArray array]; operators = [OFMutableArray array]; for (OFString *token in [condition componentsSeparatedByString: @" " options: OFStringSkipEmptyComponents]) { unsigned precedence; OFUnichar c; if ([token isEqual: @"("]) { [operators addObject: @"("]; continue; } if ([token isEqual: @")"]) { |
︙ | ︙ | |||
195 196 197 198 199 200 201 | var = [OFNumber numberWithBool: [first isEqual: second]]; else if ([token isEqual: @"!="]) var = [OFNumber numberWithBool: ![first isEqual: second]]; else if ([token isEqual: @"<"]) var = [OFNumber numberWithBool: [first | | | | | | | | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | var = [OFNumber numberWithBool: [first isEqual: second]]; else if ([token isEqual: @"!="]) var = [OFNumber numberWithBool: ![first isEqual: second]]; else if ([token isEqual: @"<"]) var = [OFNumber numberWithBool: [first compare: second] == OFOrderedAscending]; else if ([token isEqual: @"<="]) var = [OFNumber numberWithBool: [first compare: second] != OFOrderedDescending]; else if ([token isEqual: @">"]) var = [OFNumber numberWithBool: [first compare: second] == OFOrderedDescending]; else if ([token isEqual: @">="]) var = [OFNumber numberWithBool: [first compare: second] != OFOrderedAscending]; else if ([token isEqual: @"+"]) var = [OFNumber numberWithDouble: [first doubleValue] + [second doubleValue]]; else if ([token isEqual: @"%"]) var = [OFNumber numberWithLongLong: [first longLongValue] % [second longLongValue]]; else if ([token isEqual: @"&&"]) var = [OFNumber numberWithBool: [first boolValue] && [second boolValue]]; else if ([token isEqual: @"||"]) var = [OFNumber numberWithBool: [first boolValue] || [second boolValue]]; else OFEnsure(0); [stack replaceObjectAtIndex: stackSize - 2 withObject: var]; [stack removeLastObject]; } else if (precedence == 1) { stackSize = stack.count; first = stack.lastObject; if ([token isEqual: @"!"]) var = [OFNumber numberWithBool: ![first boolValue]]; else if ([token isEqual: @"is_real"]) var = [OFNumber numberWithBool: ([first doubleValue] != [first longLongValue])]; else OFEnsure(0); [stack replaceObjectAtIndex: stackSize - 1 withObject: var]; } else [stack addObject: token]; } |
︙ | ︙ | |||
349 350 351 352 353 354 355 | } + (OFString *)territory { return currentLocale.territory; } | | | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | } + (OFString *)territory { return currentLocale.territory; } + (OFStringEncoding)encoding { return currentLocale.encoding; } + (OFString *)decimalPoint { return currentLocale.decimalPoint; |
︙ | ︙ | |||
378 379 380 381 382 383 384 | #ifndef OF_AMIGAOS char *locale, *messagesLocale = NULL; if (currentLocale != nil) @throw [OFInitializationFailedException exceptionWithClass: self.class]; | | | 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | #ifndef OF_AMIGAOS char *locale, *messagesLocale = NULL; if (currentLocale != nil) @throw [OFInitializationFailedException exceptionWithClass: self.class]; _encoding = OFStringEncodingUTF8; _decimalPoint = @"."; _localizedStrings = [[OFMutableArray alloc] init]; if ((locale = setlocale(LC_ALL, "")) != NULL) _decimalPoint = [[OFString alloc] initWithCString: localeconv()->decimal_point encoding: _encoding]; |
︙ | ︙ | |||
422 423 424 425 426 427 428 | # if defined(OF_MORPHOS) if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { # elif defined(OF_AMIGAOS4) if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { # else if (0) { # endif | | | | | | 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | # if defined(OF_MORPHOS) if (GetVar("CODEPAGE", buffer, sizeof(buffer), 0) > 0) { # elif defined(OF_AMIGAOS4) if (GetVar("Charset", buffer, sizeof(buffer), 0) > 0) { # else if (0) { # endif OFStringEncoding ASCII = OFStringEncodingASCII; @try { _encoding = OFStringEncodingParseName( [OFString stringWithCString: buffer encoding: ASCII]); } @catch (OFInvalidArgumentException *e) { _encoding = OFStringEncodingISO8859_1; } } else _encoding = OFStringEncodingISO8859_1; /* * Get it via localeconv() instead of from the Locale struct, * to make sure we and printf etc. have the same expectations. */ _decimalPoint = [[OFString alloc] initWithCString: localeconv()->decimal_point |
︙ | ︙ | |||
455 456 457 458 459 460 461 | if ((locale = OpenLocale(NULL)) != NULL) { @try { uint32_t territory; size_t length; territory = | | | 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | if ((locale = OpenLocale(NULL)) != NULL) { @try { uint32_t territory; size_t length; territory = OFToBigEndian32(locale->loc_CountryCode); for (length = 0; length < 4; length++) if (((char *)&territory)[length] == 0) break; _territory = [[OFString alloc] initWithCString: (char *)&territory |
︙ | ︙ | |||
567 568 569 570 571 572 573 | OFConstantString *name; const char *UTF8String = NULL; size_t last, UTF8StringLength; int state = 0; variables = [OFMutableDictionary dictionary]; while ((name = va_arg(arguments, OFConstantString *)) != nil) | | < | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | OFConstantString *name; const char *UTF8String = NULL; size_t last, UTF8StringLength; int state = 0; variables = [OFMutableDictionary dictionary]; while ((name = va_arg(arguments, OFConstantString *)) != nil) [variables setObject: va_arg(arguments, id) forKey: name]; for (OFDictionary *strings in _localizedStrings) { id string = [strings objectForKey: ID]; if (string == nil) continue; |
︙ | ︙ |
Modified src/OFMD5Hash.h from [2ab0f29af9] to [cdc110c606].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | | | | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFMD5Hash OFMD5Hash.h ObjFW/OFMD5Hash.h * * @brief A class which provides methods to create an MD5 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFMD5Hash: OFObject <OFCryptographicHash> { OFSecureData *_iVarsData; struct { uint32_t state[4]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[16]; } buffer; size_t bufferLength; } *_iVars; bool _allowsSwappableMemory; bool _calculated; |
︙ | ︙ |
Modified src/OFMD5Hash.m from [5fb4681c4e] to [df0ebde97e].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFMD5Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #import "OFMD5Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 16; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFMD5Hash () - (void)of_resetState; @end #define F(a, b, c) (((a) & (b)) | (~(a) & (c))) |
︙ | ︙ | |||
71 72 73 74 75 76 77 | }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length) { #ifdef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) | | | | | | | | | | > | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length) { #ifdef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[4]; uint_fast8_t i = 0; new[0] = state[0]; new[1] = state[1]; new[2] = state[2]; new[3] = state[3]; byteSwapVectorIfBE(buffer, 16); #define LOOP_BODY(f) \ { \ uint32_t tmp = new[3]; \ tmp = new[3]; \ new[0] += f(new[1], new[2], new[3]) + \ buffer[wordOrder[i]] + table[i]; \ new[3] = new[2]; \ new[2] = new[1]; \ new[1] += OFRotateLeft(new[0], \ rotateBits[(i % 4) + (i / 16) * 4]); \ new[0] = tmp; \ } for (; i < 16; i++) LOOP_BODY(F) for (; i < 32; i++) LOOP_BODY(G) for (; i < 48; i++) |
︙ | ︙ | |||
123 124 125 126 127 128 129 | @implementation OFMD5Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { | | | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | @implementation OFMD5Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { return digestSize; } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { |
︙ | ︙ | |||
176 177 178 179 180 181 182 | [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { | | | | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { return digestSize; } - (size_t)blockSize { return blockSize; } - (id)copy { OFMD5Hash *copy = [[OFMD5Hash alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; |
︙ | ︙ | |||
204 205 206 207 208 209 210 | { _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; } | | < | 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | { _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; |
︙ | ︙ | |||
244 245 246 247 248 249 250 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; | | | | | | | | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); _iVars->buffer.words[15] = OFToLittleEndian32((uint32_t)(_iVars->bits >> 32)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfBE(_iVars->state, 4); _calculated = true; return (const unsigned char *)_iVars->state; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end |
Modified src/OFMapTable.h from [aaa3a8b0bc] to [67af88b431].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #import "OFEnumerator.h" OF_ASSUME_NONNULL_BEGIN /** @file */ /** | | | < | | | | | | | | < | | < | | | | | | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 | #import "OFEnumerator.h" OF_ASSUME_NONNULL_BEGIN /** @file */ /** * @struct OFMapTableFunctions OFMapTable.h ObjFW/OFMapTable.h * * @brief A struct describing the functions to be used by the map table. */ typedef struct { /** The function to retain keys / objects */ void *_Nullable (*_Nullable retain)(void *_Nullable object); /** The function to release keys / objects */ void (*_Nullable release)(void *_Nullable object); /** The function to hash keys */ unsigned long (*_Nullable hash)(void *_Nullable object); /** The function to compare keys / objects */ bool (*_Nullable equal)(void *_Nullable object1, void *_Nullable object2); } OFMapTableFunctions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating an OFMapTable. * * @param key The current key * @param object The current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFMapTableEnumerationBlock)(void *_Nullable key, void *_Nullable object, bool *stop); /** * @brief A block for replacing objects in an OFMapTable. * * @param key The key of the object to replace * @param object The object to replace * @return The object to replace the object with */ typedef void *_Nullable (^OFMapTableReplaceBlock)(void *_Nullable key, void *_Nullable object); #endif @class OFMapTableEnumerator; /** * @class OFMapTable OFMapTable.h ObjFW/OFMapTable.h * * @brief A class similar to OFDictionary, but providing more options how keys * and objects should be retained, released, compared and hashed. */ OF_SUBCLASSING_RESTRICTED @interface OFMapTable: OFObject <OFCopying, OFFastEnumeration> { OFMapTableFunctions _keyFunctions, _objectFunctions; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; unsigned long _count, _capacity; unsigned char _rotate; unsigned long _mutations; } /** * @brief The key functions used by the map table. */ @property (readonly, nonatomic) OFMapTableFunctions keyFunctions; /** * @brief The object functions used by the map table. */ @property (readonly, nonatomic) OFMapTableFunctions objectFunctions; /** * @brief The number of objects in the map table. */ @property (readonly, nonatomic) size_t count; /** * @brief Creates a new OFMapTable with the specified key and object functions. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @return A new autoreleased OFMapTable */ + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions; /** * @brief Creates a new OFMapTable with the specified key functions, object * functions and capacity. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @param capacity A hint about the count of elements expected to be in the map * table * @return A new autoreleased OFMapTable */ + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMapTable with the specified key * and object functions. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @return An initialized OFMapTable */ - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions; /** * @brief Initializes an already allocated OFMapTable with the specified key * functions, object functions and capacity. * * @param keyFunctions A structure of functions for handling keys * @param objectFunctions A structure of functions for handling objects * @param capacity A hint about the count of elements expected to be in the map * table * @return An initialized OFMapTable */ - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity OF_DESIGNATED_INITIALIZER; /** * @brief Returns the object for the given key or NULL if the key was not found. * * @param key The key whose object should be returned * @return The object for the given key or NULL if the key was not found */ - (nullable void *)objectForKey: (void *)key; /** * @brief Sets an object for a key. * * @param key The key to set * @param object The object to set the key to */ - (void)setObject: (nullable void *)object forKey: (nullable void *)key; /** * @brief Removes the object for the specified key from the map table. * * @param key The key whose object should be removed */ - (void)removeObjectForKey: (nullable void *)key; |
︙ | ︙ | |||
214 215 216 217 218 219 220 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each key / object pair. * * @param block The block to execute for each key / object pair. */ | | < | | | 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each key / object pair. * * @param block The block to execute for each key / object pair. */ - (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block; /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ - (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block; #endif @end /** * @class OFMapTableEnumerator OFMapTable.h ObjFW/OFMapTable.h * * @brief A class which provides methods to enumerate through an OFMapTable's * keys or objects. */ @interface OFMapTableEnumerator: OFObject { OFMapTable *_mapTable; struct OFMapTableBucket *_Nonnull *_Nullable _buckets; unsigned long _capacity, _mutations, *_Nullable _mutationsPtr; unsigned long _position; } - (instancetype)init OF_UNAVAILABLE; /** |
︙ | ︙ |
Modified src/OFMapTable.m from [b3889238ba] to [37fa19bf82].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #import "OFMapTable+Private.h" #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" | > | > | | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #import "OFMapTable+Private.h" #import "OFEnumerator.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" extern unsigned long OFHashSeed; static const unsigned long minCapacity = 16; struct OFMapTableBucket { void *key, *object; unsigned long hash; }; static struct OFMapTableBucket deletedBucket = { 0 }; static void * defaultRetain(void *object) { return object; } |
︙ | ︙ | |||
55 56 57 58 59 60 61 | static bool defaultEqual(void *object1, void *object2) { return (object1 == object2); } | < < < < < < < | | < | | < | | | | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | static bool defaultEqual(void *object1, void *object2) { return (object1 == object2); } OF_DIRECT_MEMBERS @interface OFMapTableEnumerator () - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct OFMapTableBucket **)buckets capacity: (unsigned long)capacity mutationsPointer: (unsigned long *)mutationsPtr OF_METHOD_FAMILY(init); @end @interface OFMapTableKeyEnumerator: OFMapTableEnumerator @end @interface OFMapTableObjectEnumerator: OFMapTableEnumerator @end @implementation OFMapTable @synthesize keyFunctions = _keyFunctions, objectFunctions = _objectFunctions; + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions { return [[[self alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions] autorelease]; } + (instancetype)mapTableWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity { return [[[self alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: capacity] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions { return [self initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: 0]; } - (instancetype)initWithKeyFunctions: (OFMapTableFunctions)keyFunctions objectFunctions: (OFMapTableFunctions)objectFunctions capacity: (size_t)capacity { self = [super init]; @try { _keyFunctions = keyFunctions; _objectFunctions = objectFunctions; |
︙ | ︙ | |||
154 155 156 157 158 159 160 | _capacity *= 2; } if (capacity * 8 / _capacity >= 6) if (_capacity <= ULONG_MAX / 2) _capacity *= 2; | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < | | | | | | | | | | | | | | | | | | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 | _capacity *= 2; } if (capacity * 8 / _capacity >= 6) if (_capacity <= ULONG_MAX / 2) _capacity *= 2; if (_capacity < minCapacity) _capacity = minCapacity; _buckets = OFAllocZeroedMemory(_capacity, sizeof(*_buckets)); if (OFHashSeed != 0) _rotate = OFRandom16() & 31; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); } } OFFreeMemory(_buckets); [super dealloc]; } static void resizeForCount(OFMapTable *self, unsigned long count) { unsigned long fullness, capacity; struct OFMapTableBucket **buckets; if (count > ULONG_MAX / sizeof(*self->_buckets) || count > ULONG_MAX / 8) @throw [OFOutOfRangeException exception]; fullness = count * 8 / self->_capacity; if (fullness >= 6) { if (self->_capacity > ULONG_MAX / 2) return; capacity = self->_capacity * 2; } else if (fullness <= 1) capacity = self->_capacity / 2; else return; /* * Don't downsize if we have an initial capacity or if we would fall * below the minimum capacity. */ if ((capacity < self->_capacity && count > self->_count) || capacity < minCapacity) return; buckets = OFAllocZeroedMemory(capacity, sizeof(*buckets)); for (unsigned long i = 0; i < self->_capacity; i++) { if (self->_buckets[i] != NULL && self->_buckets[i] != &deletedBucket) { unsigned long j, last; last = capacity; for (j = self->_buckets[i]->hash & (capacity - 1); j < last && buckets[j] != NULL; j++); /* In case the last bucket is already used */ if (j >= last) { last = self->_buckets[i]->hash & (capacity - 1); for (j = 0; j < last && buckets[j] != NULL; j++); } if (j >= last) @throw [OFOutOfRangeException exception]; buckets[j] = self->_buckets[i]; } } OFFreeMemory(self->_buckets); self->_buckets = buckets; self->_capacity = capacity; } static void setObject(OFMapTable *restrict self, void *key, void *object, unsigned long hash) { unsigned long i, last; void *old; if (key == NULL || object == NULL) @throw [OFInvalidArgumentException exception]; hash = OFRotateLeft(hash, self->_rotate); last = self->_capacity; for (i = hash & (self->_capacity - 1); i < last && self->_buckets[i] != NULL; i++) { if (self->_buckets[i] == &deletedBucket) continue; if (self->_keyFunctions.equal(self->_buckets[i]->key, key)) break; } /* In case the last bucket is already used */ if (i >= last) { last = hash & (self->_capacity - 1); for (i = 0; i < last && self->_buckets[i] != NULL; i++) { if (self->_buckets[i] == &deletedBucket) continue; if (self->_keyFunctions.equal( self->_buckets[i]->key, key)) break; } } /* Key not in map table */ if (i >= last || self->_buckets[i] == NULL || self->_buckets[i] == &deletedBucket || !self->_keyFunctions.equal(self->_buckets[i]->key, key)) { struct OFMapTableBucket *bucket; resizeForCount(self, self->_count + 1); self->_mutations++; last = self->_capacity; for (i = hash & (self->_capacity - 1); i < last && self->_buckets[i] != NULL && self->_buckets[i] != &deletedBucket; i++); /* In case the last bucket is already used */ if (i >= last) { last = hash & (self->_capacity - 1); for (i = 0; i < last && self->_buckets[i] != NULL && self->_buckets[i] != &deletedBucket; i++); } if (i >= last) @throw [OFOutOfRangeException exception]; bucket = OFAllocMemory(1, sizeof(*bucket)); @try { bucket->key = self->_keyFunctions.retain(key); } @catch (id e) { OFFreeMemory(bucket); @throw e; } @try { bucket->object = self->_objectFunctions.retain(object); } @catch (id e) { self->_keyFunctions.release(bucket->key); OFFreeMemory(bucket); @throw e; } bucket->hash = hash; self->_buckets[i] = bucket; self->_count++; return; } old = self->_buckets[i]->object; self->_buckets[i]->object = self->_objectFunctions.retain(object); self->_objectFunctions.release(old); } - (bool)isEqual: (id)object { OFMapTable *mapTable; if (object == self) return true; if (![object isKindOfClass: [OFMapTable class]]) return false; mapTable = object; if (mapTable->_count != _count || mapTable->_keyFunctions.equal != _keyFunctions.equal || mapTable->_objectFunctions.equal != _objectFunctions.equal) return false; for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { void *objectIter = [mapTable objectForKey: _buckets[i]->key]; if (!_objectFunctions.equal(objectIter, _buckets[i]->object)) return false; } } return true; } - (unsigned long)hash { unsigned long hash = 0; for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { hash ^= OFRotateRight(_buckets[i]->hash, _rotate); hash ^= _objectFunctions.hash(_buckets[i]->object); } } return hash; } - (id)copy { OFMapTable *copy = [[OFMapTable alloc] initWithKeyFunctions: _keyFunctions objectFunctions: _objectFunctions capacity: _capacity]; @try { for (unsigned long i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) setObject(copy, _buckets[i]->key, _buckets[i]->object, OFRotateRight(_buckets[i]->hash, _rotate)); } @catch (id e) { [copy release]; @throw e; } return copy; } - (size_t)count { return _count; } - (void *)objectForKey: (void *)key { unsigned long i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OFRotateLeft(_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) return _buckets[i]->object; } if (i < last) return nil; /* In case the last bucket is already used */ last = hash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) return _buckets[i]->object; } return NULL; } - (void)setObject: (void *)object forKey: (void *)key { setObject(self, key, object,_keyFunctions.hash(key)); } - (void)removeObjectForKey: (void *)key { unsigned long i, hash, last; if (key == NULL) @throw [OFInvalidArgumentException exception]; hash = OFRotateLeft(_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) { _mutations++; _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); _buckets[i] = &deletedBucket; _count--; resizeForCount(self, _count); return; } } if (i < last) return; /* In case the last bucket is already used */ last = hash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL; i++) { if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); _buckets[i] = &deletedBucket; _count--; _mutations++; resizeForCount(self, _count); return; } } } - (void)removeAllObjects { for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL) { if (_buckets[i] == &deletedBucket) { _buckets[i] = NULL; continue; } _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); _buckets[i] = NULL; } } _count = 0; _capacity = minCapacity; _buckets = OFResizeMemory(_buckets, _capacity, sizeof(*_buckets)); /* * Get a new random value for _rotate, so that it is not less secure * than creating a new hash map. */ if (OFHashSeed != 0) _rotate = OFRandom16() & 31; } - (bool)containsObject: (void *)object { if (object == NULL || _count == 0) return false; for (unsigned long i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_objectFunctions.equal(_buckets[i]->object, object)) return true; return false; } - (bool)containsObjectIdenticalTo: (void *)object { if (object == NULL || _count == 0) return false; for (unsigned long i = 0; i < _capacity; i++) if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_buckets[i]->object == object) return true; return false; } - (OFMapTableEnumerator *)keyEnumerator |
︙ | ︙ | |||
575 576 577 578 579 580 581 | return [[[OFMapTableObjectEnumerator alloc] of_initWithMapTable: self buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } | | | | < | | | | 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 | return [[[OFMapTableObjectEnumerator alloc] of_initWithMapTable: self buckets: _buckets capacity: _capacity mutationsPointer: &_mutations] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { unsigned long j = state->state; int i; for (i = 0; i < count; i++) { for (; j < _capacity && (_buckets[j] == NULL || _buckets[j] == &deletedBucket); j++); if (j < _capacity) { objects[i] = _buckets[j]->key; j++; } else break; } state->state = j; state->itemsPtr = objects; state->mutationsPtr = &_mutations; return i; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (OFMapTableEnumerationBlock)block { bool stop = false; unsigned long mutations = _mutations; for (size_t i = 0; i < _capacity && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) block(_buckets[i]->key, _buckets[i]->object, &stop); } } - (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block { unsigned long mutations = _mutations; for (size_t i = 0; i < _capacity; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { void *new; new = block(_buckets[i]->key, _buckets[i]->object); if (new == NULL) @throw [OFInvalidArgumentException exception]; if (new != _buckets[i]->object) { |
︙ | ︙ | |||
651 652 653 654 655 656 657 | @implementation OFMapTableEnumerator - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable | | | 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | @implementation OFMapTableEnumerator - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithMapTable: (OFMapTable *)mapTable buckets: (struct OFMapTableBucket **)buckets capacity: (unsigned long)capacity mutationsPointer: (unsigned long *)mutationsPtr { self = [super init]; _mapTable = [mapTable retain]; _buckets = buckets; |
︙ | ︙ | |||
687 688 689 690 691 692 693 | - (void **)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || | | | | 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 | - (void **)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deletedBucket); _position++); if (_position < _capacity) return &_buckets[_position++]->key; else return NULL; } @end @implementation OFMapTableObjectEnumerator - (void **)nextObject { if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || _buckets[_position] == &deletedBucket); _position++); if (_position < _capacity) return &_buckets[_position++]->object; else return NULL; } @end |
︙ | ︙ |
Modified src/OFMapTableDictionary.m from [300d637d78] to [121bed2172].
︙ | ︙ | |||
55 56 57 58 59 60 61 | static bool equal(void *object1, void *object2) { return [(id)object1 isEqual: (id)object2]; } | | | | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | static bool equal(void *object1, void *object2) { return [(id)object1 isEqual: (id)object2]; } static const OFMapTableFunctions keyFunctions = { .retain = copy, .release = release, .hash = hash, .equal = equal }; static const OFMapTableFunctions objectFunctions = { .retain = retain, .release = release, .hash = hash, .equal = equal }; @implementation OFMapTableDictionary |
︙ | ︙ | |||
133 134 135 136 137 138 139 | OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; keyEnumerator = [dictionary keyEnumerator]; objectEnumerator = [dictionary objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) | | < | < | < | < | < | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; keyEnumerator = [dictionary keyEnumerator]; objectEnumerator = [dictionary objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [_mapTable setObject: object forKey: key]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)object forKey: (id)key { self = [self initWithCapacity: 1]; @try { [_mapTable setObject: object forKey: key]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys count: (size_t)count { self = [self initWithCapacity: count]; @try { size_t i; for (i = 0; i < count; i++) [_mapTable setObject: objects[i] forKey: keys[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { self = [super init]; @try { va_list argumentsCopy; id key, object; size_t i, count; |
︙ | ︙ | |||
214 215 216 217 218 219 220 | count /= 2; _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: count]; | | < | < | | | | | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | count /= 2; _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: count]; [_mapTable setObject: object forKey: key]; for (i = 1; i < count; i++) { key = va_arg(arguments, id); object = va_arg(arguments, id); if (key == nil || object == nil) @throw [OFInvalidArgumentException exception]; [_mapTable setObject: object forKey: key]; } } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFArray *keys, *objects; OFEnumerator *keyEnumerator, *objectEnumerator; OFXMLElement *keyElement, *objectElement; keys = [element elementsForName: @"key" namespace: OFSerializationNS]; objects = [element elementsForName: @"object" namespace: OFSerializationNS]; if (keys.count != objects.count) @throw [OFInvalidFormatException exception]; _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: keys.count]; keyEnumerator = [keys objectEnumerator]; objectEnumerator = [objects objectEnumerator]; while ((keyElement = [keyEnumerator nextObject]) != nil && (objectElement = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *key, *object; key = [keyElement elementsForNamespace: OFSerializationNS].firstObject; object = [objectElement elementsForNamespace: OFSerializationNS].firstObject; if (key == nil || object == nil) @throw [OFInvalidFormatException exception]; [_mapTable setObject: object.objectByDeserializing forKey: key.objectByDeserializing]; |
︙ | ︙ | |||
338 339 340 341 342 343 344 | - (OFArray *)allKeys { OFArray *ret; id *keys; size_t count; count = _mapTable.count; | | | < | | | < | | | < | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | - (OFArray *)allKeys { OFArray *ret; id *keys; size_t count; count = _mapTable.count; keys = OFAllocMemory(count, sizeof(*keys)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **keyPtr; size_t i; i = 0; enumerator = [_mapTable keyEnumerator]; while ((keyPtr = [enumerator nextObject]) != NULL) { assert(i < count); keys[i++] = (id)*keyPtr; } objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: keys count: count]; } @finally { OFFreeMemory(keys); } return ret; } - (OFArray *)allObjects { OFArray *ret; id *objects; size_t count; count = _mapTable.count; objects = OFAllocMemory(count, sizeof(*objects)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **objectPtr; size_t i; i = 0; enumerator = [_mapTable objectEnumerator]; while ((objectPtr = [enumerator nextObject]) != NULL) { assert(i < count); objects[i++] = (id)*objectPtr; } objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: objects count: count]; } @finally { OFFreeMemory(objects); } return ret; } - (OFEnumerator *)keyEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [_mapTable keyEnumerator] object: self] autorelease]; } - (OFEnumerator *)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [_mapTable objectEnumerator] object: self] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { return [_mapTable countByEnumeratingWithState: state objects: objects count: count]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (OFDictionaryEnumerationBlock)block { @try { [_mapTable enumerateKeysAndObjectsUsingBlock: ^ (void *key, void *object, bool *stop) { block(key, object, stop); }]; } @catch (OFEnumerationMutationException *e) { |
︙ | ︙ |
Modified src/OFMapTableSet.m from [d8234d4e2f] to [5b1053bcbc].
︙ | ︙ | |||
47 48 49 50 51 52 53 | static bool equal(void *object1, void *object2) { return [(id)object1 isEqual: (id)object2]; } | | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | static bool equal(void *object1, void *object2) { return [(id)object1 isEqual: (id)object2]; } static const OFMapTableFunctions keyFunctions = { .retain = retain, .release = release, .hash = hash, .equal = equal }; static const OFMapTableFunctions objectFunctions = { NULL }; @implementation OFMapTableSet - (instancetype)init { return [self initWithCapacity: 0]; } |
︙ | ︙ | |||
96 97 98 99 100 101 102 | @throw e; } self = [self initWithCapacity: count]; @try { for (id object in set) | | < | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | @throw e; } self = [self initWithCapacity: count]; @try { for (id object in set) [_mapTable setObject: (void *)1 forKey: object]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
124 125 126 127 128 129 130 | @throw e; } self = [self initWithCapacity: count]; @try { for (id object in array) | | < | < | < | < | < | < | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | @throw e; } self = [self initWithCapacity: count]; @try { for (id object in array) [_mapTable setObject: (void *)1 forKey: object]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [self initWithCapacity: count]; @try { for (size_t i = 0; i < count; i++) [_mapTable setObject: (void *)1 forKey: objects[i]]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { self = [super init]; @try { id object; va_list argumentsCopy; size_t count; va_copy(argumentsCopy, arguments); for (count = 1; va_arg(argumentsCopy, id) != nil; count++); _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions capacity: count]; [_mapTable setObject: (void *)1 forKey: firstObject]; while ((object = va_arg(arguments, id)) != nil) [_mapTable setObject: (void *)1 forKey: object]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { self = [self init]; @try { void *pool = objc_autoreleasePoolPush(); if ((![element.name isEqual: @"OFSet"] && ![element.name isEqual: @"OFMutableSet"]) || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; for (OFXMLElement *child in [element elementsForNamespace: OFSerializationNS]) { void *pool2 = objc_autoreleasePoolPush(); [_mapTable setObject: (void *)1 forKey: [child objectByDeserializing]]; objc_autoreleasePoolPop(pool2); } |
︙ | ︙ | |||
279 280 281 282 283 284 285 | - (OFEnumerator *)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [_mapTable keyEnumerator] object: self] autorelease]; } | | | | 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | - (OFEnumerator *)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] initWithEnumerator: [_mapTable keyEnumerator] object: self] autorelease]; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { return [_mapTable countByEnumeratingWithState: state objects: objects count: count]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFSetEnumerationBlock)block { @try { [_mapTable enumerateKeysAndObjectsUsingBlock: ^ (void *key, void *object, bool *stop) { block(key, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException exceptionWithObject: self]; } } #endif @end |
Modified src/OFMessagePackExtension.h from [bde5fd00c0] to [312db63f78].
︙ | ︙ | |||
48 49 50 51 52 53 54 | * @brief Creates a new OFMessagePackRepresentation with the specified type and * data. * * @param type The MessagePack extension type * @param data The data for the extension * @return A new, autoreleased OFMessagePackRepresentation */ | | < | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | * @brief Creates a new OFMessagePackRepresentation with the specified type and * data. * * @param type The MessagePack extension type * @param data The data for the extension * @return A new, autoreleased OFMessagePackRepresentation */ + (instancetype)extensionWithType: (int8_t)type data: (OFData *)data; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFMessagePackRepresentation with the * specified type and data. * |
︙ | ︙ |
Modified src/OFMessagePackExtension.m from [2e0b603741] to [28a9f74124].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFMessagePackExtension @synthesize type = _type, data = _data; | | < | < | < | 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 | #import "OFString.h" #import "OFInvalidArgumentException.h" @implementation OFMessagePackExtension @synthesize type = _type, data = _data; + (instancetype)extensionWithType: (int8_t)type data: (OFData *)data { return [[[self alloc] initWithType: type data: data] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithType: (int8_t)type data: (OFData *)data { self = [super init]; @try { if (data == nil || data.itemSize != 1) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
119 120 121 122 123 124 125 | uint16_t length; ret = [OFMutableData dataWithCapacity: count + 4]; prefix = 0xC8; [ret addItem: &prefix]; | | | < | | < | < < | 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 | uint16_t length; ret = [OFMutableData dataWithCapacity: count + 4]; prefix = 0xC8; [ret addItem: &prefix]; length = OFToBigEndian16((uint16_t)count); [ret addItems: &length count: 2]; [ret addItem: &_type]; } else { uint32_t length; ret = [OFMutableData dataWithCapacity: count + 6]; prefix = 0xC9; [ret addItem: &prefix]; length = OFToBigEndian32((uint32_t)count); [ret addItems: &length count: 4]; [ret addItem: &_type]; } [ret addItems: _data.items count: _data.count]; [ret makeImmutable]; return ret; } - (OFString *)description { |
︙ | ︙ | |||
173 174 175 176 177 178 179 | return false; return true; } - (unsigned long)hash { | | | | | | | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAdd(&hash, (uint8_t)_type); OFHashAddHash(&hash, _data.hash); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; } @end |
Modified src/OFMethodSignature.h from [02180a8d88] to [11b966e495].
︙ | ︙ | |||
90 91 92 93 94 95 96 | #endif /** * @brief Returns the size for the specified type encoding. * * @param type The type encoding to return the size for * @return The size for the specified type encoding */ | | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #endif /** * @brief Returns the size for the specified type encoding. * * @param type The type encoding to return the size for * @return The size for the specified type encoding */ extern size_t OFSizeOfTypeEncoding(const char *type); /** * @brief Returns the alignment for the specified type encoding. * * @param type The type encoding to return the alignment for * @return The alignment for the specified type encoding */ extern size_t OFAlignmentOfTypeEncoding(const char *type); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFMethodSignature.m from [350056b928] to [556b909780].
︙ | ︙ | |||
23 24 25 26 27 28 29 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "macros.h" | | > | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "macros.h" static size_t alignmentOfEncoding(const char **type, size_t *length, bool inStruct); static size_t sizeOfEncoding(const char **type, size_t *length); static size_t alignmentOfArray(const char **type, size_t *length) { size_t alignment; assert(*length > 0); (*type)++; (*length)--; while (*length > 0 && OFASCIIIsDigit(**type)) { (*type)++; (*length)--; } alignment = alignmentOfEncoding(type, length, true); if (*length == 0 || **type != ']') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return alignment; } static size_t alignmentOfStruct(const char **type, size_t *length) { size_t alignment = 0; #if defined(OF_POWERPC) && defined(OF_MACOS) bool first = true; #endif assert(*length > 0); (*type)++; |
︙ | ︙ | |||
79 80 81 82 83 84 85 | @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != '}') { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != '}') { size_t fieldAlignment = alignmentOfEncoding(type, length, true); #if defined(OF_POWERPC) && defined(OF_MACOS) if (!first && fieldAlignment > 4) fieldAlignment = 4; first = false; #endif if (fieldAlignment > alignment) alignment = fieldAlignment; } if (*length == 0 || **type != '}') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return alignment; } static size_t alignmentOfUnion(const char **type, size_t *length) { size_t alignment = 0; assert(*length > 0); (*type)++; (*length)--; /* Skip name */ while (*length > 0 && **type != '=') { (*type)++; (*length)--; } if (*length == 0) @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != ')') { size_t fieldAlignment = alignmentOfEncoding(type, length, true); if (fieldAlignment > alignment) alignment = fieldAlignment; } if (*length == 0 || **type != ')') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return alignment; } static size_t alignmentOfEncoding(const char **type, size_t *length, bool inStruct) { size_t alignment; if (*length == 0) @throw [OFInvalidFormatException exception]; if (**type == 'r') { (*type)++; (*length)--; if (*length == 0) @throw [OFInvalidFormatException exception]; } switch (**type) { case 'c': case 'C': alignment = OF_ALIGNOF(char); break; case 'i': case 'I': alignment = OF_ALIGNOF(int); break; case 's': case 'S': alignment = OF_ALIGNOF(short); break; case 'l': case 'L': alignment = OF_ALIGNOF(long); break; case 'q': case 'Q': #if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else #endif alignment = OF_ALIGNOF(long long); break; #ifdef __SIZEOF_INT128__ case 't': case 'T': alignment = __extension__ OF_ALIGNOF(__int128); break; #endif case 'f': alignment = OF_ALIGNOF(float); break; case 'd': #if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else #endif alignment = OF_ALIGNOF(double); break; case 'D': #if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else #endif alignment = OF_ALIGNOF(long double); break; case 'B': alignment = OF_ALIGNOF(_Bool); break; case 'v': alignment = 0; break; case '*': alignment = OF_ALIGNOF(char *); break; case '@': alignment = OF_ALIGNOF(id); break; case '#': alignment = OF_ALIGNOF(Class); break; case ':': alignment = OF_ALIGNOF(SEL); break; case '[': return alignmentOfArray(type, length); case '{': return alignmentOfStruct(type, length); case '(': return alignmentOfUnion(type, length); case '^': /* Just to skip over the rest */ (*type)++; (*length)--; alignmentOfEncoding(type, length, false); return OF_ALIGNOF(void *); #ifndef __STDC_NO_COMPLEX__ case 'j': (*type)++; (*length)--; if (*length == 0) @throw [OFInvalidFormatException exception]; switch (**type) { case 'f': alignment = OF_ALIGNOF(float _Complex); break; case 'd': # if defined(OF_X86) && !defined(OF_WINDOWS) if (inStruct) alignment = 4; else # endif alignment = OF_ALIGNOF(double _Complex); break; case 'D': alignment = OF_ALIGNOF(long double _Complex); break; default: @throw [OFInvalidFormatException exception]; } break; #endif default: @throw [OFInvalidFormatException exception]; } (*type)++; (*length)--; return alignment; } static size_t sizeOfArray(const char **type, size_t *length) { size_t count = 0; size_t size; assert(*length > 0); (*type)++; (*length)--; while (*length > 0 && OFASCIIIsDigit(**type)) { count = count * 10 + **type - '0'; (*type)++; (*length)--; } if (count == 0) @throw [OFInvalidFormatException exception]; size = sizeOfEncoding(type, length); if (*length == 0 || **type != ']') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; if (SIZE_MAX / count < size) @throw [OFOutOfRangeException exception]; return count * size; } static size_t sizeOfStruct(const char **type, size_t *length) { size_t size = 0; const char *typeCopy = *type; size_t lengthCopy = *length; size_t alignment = alignmentOfStruct(&typeCopy, &lengthCopy); #if defined(OF_POWERPC) && defined(OF_MACOS) bool first = true; #endif assert(*length > 0); (*type)++; |
︙ | ︙ | |||
342 343 344 345 346 347 348 | @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != '}') { | | | | > | | | | > | 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != '}') { size_t fieldSize, fieldAlignment; typeCopy = *type; lengthCopy = *length; fieldSize = sizeOfEncoding(type, length); fieldAlignment = alignmentOfEncoding(&typeCopy, &lengthCopy, true); #if defined(OF_POWERPC) && defined(OF_MACOS) if (!first && fieldAlignment > 4) fieldAlignment = 4; first = false; #endif if (size % fieldAlignment != 0) { size_t padding = fieldAlignment - (size % fieldAlignment); if (SIZE_MAX - size < padding) @throw [OFOutOfRangeException exception]; size += padding; } |
︙ | ︙ | |||
390 391 392 393 394 395 396 | size += padding; } return size; } static size_t | | | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | size += padding; } return size; } static size_t sizeOfUnion(const char **type, size_t *length) { size_t size = 0; assert(*length > 0); (*type)++; (*length)--; |
︙ | ︙ | |||
413 414 415 416 417 418 419 | @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != ')') { | | | | 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | @throw [OFInvalidFormatException exception]; /* Skip '=' */ (*type)++; (*length)--; while (*length > 0 && **type != ')') { size_t fieldSize = sizeOfEncoding(type, length); if (fieldSize > size) size = fieldSize; } if (*length == 0 || **type != ')') @throw [OFInvalidFormatException exception]; (*type)++; (*length)--; return size; } static size_t sizeOfEncoding(const char **type, size_t *length) { size_t size; if (*length == 0) @throw [OFInvalidFormatException exception]; if (**type == 'r') { |
︙ | ︙ | |||
499 500 501 502 503 504 505 | case '#': size = sizeof(Class); break; case ':': size = sizeof(SEL); break; case '[': | | | | | | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | case '#': size = sizeof(Class); break; case ':': size = sizeof(SEL); break; case '[': return sizeOfArray(type, length); case '{': return sizeOfStruct(type, length); case '(': return sizeOfUnion(type, length); case '^': /* Just to skip over the rest */ (*type)++; (*length)--; sizeOfEncoding(type, length); return sizeof(void *); #ifndef __STDC_NO_COMPLEX__ case 'j': (*type)++; (*length)--; |
︙ | ︙ | |||
546 547 548 549 550 551 552 | (*type)++; (*length)--; return size; } size_t | | | | | | 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | (*type)++; (*length)--; return size; } size_t OFSizeOfTypeEncoding(const char *type) { size_t length = strlen(type); size_t ret = sizeOfEncoding(&type, &length); if (length > 0) @throw [OFInvalidFormatException exception]; return ret; } size_t OFAlignmentOfTypeEncoding(const char *type) { size_t length = strlen(type); size_t ret = alignmentOfEncoding(&type, &length, false); if (length > 0) @throw [OFInvalidFormatException exception]; return ret; } |
︙ | ︙ | |||
591 592 593 594 595 596 597 | @throw [OFInvalidArgumentException exception]; length = strlen(types); if (length == 0) @throw [OFInvalidFormatException exception]; | | | | | 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | @throw [OFInvalidArgumentException exception]; length = strlen(types); if (length == 0) @throw [OFInvalidFormatException exception]; _types = OFAllocMemory(length + 1, 1); memcpy(_types, types, length); _typesPointers = [[OFMutableData alloc] initWithItemSize: sizeof(char *)]; _offsets = [[OFMutableData alloc] initWithItemSize: sizeof(size_t)]; last = _types; for (size_t i = 0; i < length; i++) { if (OFASCIIIsDigit(_types[i])) { size_t offset = _types[i] - '0'; if (last == _types + i) @throw [OFInvalidFormatException exception]; _types[i] = '\0'; [_typesPointers addItem: &last]; i++; for (; i < length && OFASCIIIsDigit(_types[i]); i++) offset = offset * 10 + _types[i] - '0'; [_offsets addItem: &offset]; last = _types + i; i--; } else if (_types[i] == '{') { |
︙ | ︙ | |||
665 666 667 668 669 670 671 | } return self; } - (void)dealloc { | | | 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | } return self; } - (void)dealloc { OFFreeMemory(_types); [_typesPointers release]; [_offsets release]; [super dealloc]; } - (size_t)numberOfArguments |
︙ | ︙ |
Modified src/OFMutableAdjacentArray.m from [a783390738] to [797d22d2c1].
︙ | ︙ | |||
55 56 57 58 59 60 61 | [_array addItem: &object]; [object retain]; _mutations++; } | | < | < | < | < < | < | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | [_array addItem: &object]; [object retain]; _mutations++; } - (void)insertObject: (id)object atIndex: (size_t)idx { if (object == nil) @throw [OFInvalidArgumentException exception]; @try { [_array insertItem: &object atIndex: idx]; } @catch (OFOutOfRangeException *e) { @throw [OFOutOfRangeException exception]; } [object retain]; _mutations++; } - (void)insertObjectsFromArray: (OFArray *)array atIndex: (size_t)idx { id const *objects = array.objects; size_t count = array.count; @try { [_array insertItems: objects atIndex: idx count: count]; } @catch (OFOutOfRangeException *e) { @throw [OFOutOfRangeException exception]; } for (size_t i = 0; i < count; i++) [objects[i] retain]; _mutations++; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { id *objects; size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
115 116 117 118 119 120 121 | objects[i] = newObject; return; } } } | | < | < | 109 110 111 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 | objects[i] = newObject; return; } } } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { id *objects; id oldObject; if (object == nil) @throw [OFInvalidArgumentException exception]; objects = _array.mutableItems; if (idx >= _array.count) @throw [OFOutOfRangeException exception]; oldObject = objects[idx]; objects[idx] = [object retain]; [oldObject release]; } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { id *objects; size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
227 228 229 230 231 232 233 | for (size_t i = 0; i < count; i++) [objects[i] release]; [_array removeAllItems]; } | | | | | < | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | for (size_t i = 0; i < count; i++) [objects[i] release]; [_array removeAllItems]; } - (void)removeObjectsInRange: (OFRange)range { id const *objects = _array.items; size_t count = _array.count; id *copy; if (range.length > SIZE_MAX - range.location || range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; copy = OFAllocMemory(range.length, sizeof(*copy)); memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { [_array removeItemsInRange: range]; _mutations++; for (size_t i = 0; i < range.length; i++) [copy[i] release]; } @finally { OFFreeMemory(copy); } } - (void)removeLastObject { #ifndef __clang_analyzer__ size_t count = _array.count; id object; if (count == 0) return; object = [self objectAtIndex: count - 1]; [_array removeLastItem]; [object release]; _mutations++; #endif } - (void)exchangeObjectAtIndex: (size_t)idx1 withObjectAtIndex: (size_t)idx2 { id *objects = _array.mutableItems; size_t count = _array.count; id tmp; if (idx1 >= count || idx2 >= count) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
298 299 300 301 302 303 304 | for (i = 0, j = count - 1; i < j; i++, j--) { id tmp = objects[i]; objects[i] = objects[j]; objects[j] = tmp; } } | | | 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | for (i = 0, j = count - 1; i < j; i++, j--) { id tmp = objects[i]; objects[i] = objects[j]; objects[j] = tmp; } } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count_ { size_t count = _array.count; if (count > INT_MAX) { /* |
︙ | ︙ | |||
335 336 337 338 339 340 341 | { return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: &_mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS | | | | 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | { return [[[OFArrayEnumerator alloc] initWithArray: self mutationsPtr: &_mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFArrayEnumerationBlock)block { id const *objects = _array.items; size_t count = _array.count; bool stop = false; unsigned long mutations = _mutations; for (size_t i = 0; i < count && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; block(objects[i], i, &stop); } } - (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { id *objects = _array.mutableItems; size_t count = _array.count; unsigned long mutations = _mutations; for (size_t i = 0; i < count; i++) { id new; |
︙ | ︙ |
Modified src/OFMutableArray.h from [55375a9442] to [a684ec1cde].
︙ | ︙ | |||
23 24 25 26 27 28 29 | /** * @brief A block for replacing values in an OFMutableArray. * * @param object The object to replace * @param index The index of the object to replace * @return The object to replace the object with */ | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /** * @brief A block for replacing values in an OFMutableArray. * * @param object The object to replace * @param index The index of the object to replace * @return The object to replace the object with */ typedef id _Nonnull (^OFArrayReplaceBlock)(id object, size_t index); #endif /** * @class OFMutableArray OFArray.h ObjFW/OFArray.h * * @brief An abstract class for storing, adding and removing objects in an * array. |
︙ | ︙ | |||
78 79 80 81 82 83 84 | /** * @brief Inserts an object to the OFArray at the specified index. * * @param object An object to add * @param index The index where the object should be inserted */ | | < | < | < | < | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | /** * @brief Inserts an object to the OFArray at the specified index. * * @param object An object to add * @param index The index where the object should be inserted */ - (void)insertObject: (ObjectType)object atIndex: (size_t)index; /** * @brief Inserts the objects from the specified OFArray at the specified index. * * @param array An array of objects * @param index The index where the objects should be inserted */ - (void)insertObjectsFromArray: (OFArray OF_GENERIC(ObjectType) *)array atIndex: (size_t)index; /** * @brief Replaces the first object equivalent to the specified object with the * other specified object. * * @param oldObject The object to replace * @param newObject The replacement object */ - (void)replaceObject: (ObjectType)oldObject withObject: (ObjectType)newObject; /** * @brief Replaces the object at the specified index with the specified object. * * @param index The index of the object to replace * @param object The replacement object */ - (void)replaceObjectAtIndex: (size_t)index withObject: (ObjectType)object; /** * @brief Replaces the object at the specified index with the specified object. * * This method is the same as @ref replaceObjectAtIndex:withObject:. * * This method is also used by the subscripting syntax. * * @param index The index of the object to replace * @param object The replacement object */ - (void)setObject: (ObjectType)object atIndexedSubscript: (size_t)index; /** * @brief Replaces the first object that has the same address as the specified * object with the other specified object. * * @param oldObject The object to replace * @param newObject The replacement object |
︙ | ︙ | |||
159 160 161 162 163 164 165 | - (void)removeObjectAtIndex: (size_t)index; /** * @brief Removes the object in the specified range. * * @param range The range of the objects to remove */ | | | | < | < < < < | < | < < < < | | | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | - (void)removeObjectAtIndex: (size_t)index; /** * @brief Removes the object in the specified range. * * @param range The range of the objects to remove */ - (void)removeObjectsInRange: (OFRange)range; /** * @brief Removes the last object. */ - (void)removeLastObject; /** * @brief Removes all objects. */ - (void)removeAllObjects; #ifdef OF_HAVE_BLOCKS /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ - (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block; #endif /** * @brief Exchange the objects at the specified indices. * * @param index1 The index of the first object to exchange * @param index2 The index of the second object to exchange */ - (void)exchangeObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2; /** * @brief Sorts the array in ascending order. */ - (void)sort; /** * @brief Sorts the array using the specified selector and options. * * @param selector The selector to use to sort the array. It's signature * should be the same as that of -[compare:]. * @param options The options to use when sorting the array */ - (void)sortUsingSelector: (SEL)selector options: (OFArraySortOptions)options; #ifdef OF_HAVE_BLOCKS /** * @brief Sorts the array using the specified comparator and options. * * @param comparator The comparator to use to sort the array * @param options The options to use when sorting the array */ - (void)sortUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options; #endif /** * @brief Reverts the order of the objects in the array. */ - (void)reverse; |
︙ | ︙ |
Modified src/OFMutableArray.m from [78bab359a3] to [bf8e9eeb86].
︙ | ︙ | |||
30 31 32 33 34 35 36 | static struct { Class isa; } placeholder; @interface OFMutableArrayPlaceholder: OFMutableArray @end | | | | | | | | | | | | 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 61 62 63 64 65 | static struct { Class isa; } placeholder; @interface OFMutableArrayPlaceholder: OFMutableArray @end static OFComparisonResult compare(id left, id right, SEL selector) { OFComparisonResult (*comparator)(id, SEL, id) = (OFComparisonResult (*)(id, SEL, id)) [left methodForSelector: selector]; return comparator(left, selector, right); } static void quicksort(OFMutableArray *array, size_t left, size_t right, SEL selector, OFArraySortOptions options) { OFComparisonResult ascending, descending; if (options & OFArraySortDescending) { ascending = OFOrderedDescending; descending = OFOrderedAscending; } else { ascending = OFOrderedAscending; descending = OFOrderedDescending; } while (left < right) { size_t i = left; size_t j = right - 1; id pivot = [array objectAtIndex: right]; |
︙ | ︙ | |||
88 89 90 91 92 93 94 | left = i + 1; } } #ifdef OF_HAVE_BLOCKS static void quicksortWithBlock(OFMutableArray *array, size_t left, size_t right, | | | | | | | | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | left = i + 1; } } #ifdef OF_HAVE_BLOCKS static void quicksortWithBlock(OFMutableArray *array, size_t left, size_t right, OFComparator comparator, OFArraySortOptions options) { OFComparisonResult ascending, descending; if (options & OFArraySortDescending) { ascending = OFOrderedDescending; descending = OFOrderedAscending; } else { ascending = OFOrderedAscending; descending = OFOrderedDescending; } while (left < right) { size_t i = left; size_t j = right - 1; id pivot = [array objectAtIndex: right]; |
︙ | ︙ | |||
161 162 163 164 165 166 167 | ret = [[OFMutableAdjacentArray alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } | | < | < | 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | ret = [[OFMutableAdjacentArray alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFMutableAdjacentArray alloc] initWithObject: firstObject arguments: arguments]; } - (instancetype)initWithArray: (OFArray *)array { return (id)[[OFMutableAdjacentArray alloc] initWithArray: array]; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFMutableAdjacentArray alloc] initWithObjects: objects count: count]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { |
︙ | ︙ | |||
253 254 255 256 257 258 259 | - (id)copy { return [[OFArray alloc] initWithArray: self]; } - (void)addObject: (id)object { | | < | < | < | < | < | < < | | < | < | < | < | < | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | - (id)copy { return [[OFArray alloc] initWithArray: self]; } - (void)addObject: (id)object { [self insertObject: object atIndex: self.count]; } - (void)addObjectsFromArray: (OFArray *)array { [self insertObjectsFromArray: array atIndex: self.count]; } - (void)insertObject: (id)object atIndex: (size_t)idx { OF_UNRECOGNIZED_SELECTOR } - (void)insertObjectsFromArray: (OFArray *)array atIndex: (size_t)idx { size_t i = 0; for (id object in array) [self insertObject: object atIndex: idx + i++]; } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (void)setObject: (id)object atIndexedSubscript: (size_t)idx { [self replaceObjectAtIndex: idx withObject: object]; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; count = self.count; for (size_t i = 0; i < count; i++) { if ([[self objectAtIndex: i] isEqual: oldObject]) { [self replaceObjectAtIndex: i withObject: newObject]; return; } } } - (void)replaceObjectIdenticalTo: (id)oldObject withObject: (id)newObject { size_t count; if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exception]; count = self.count; for (size_t i = 0; i < count; i++) { if ([self objectAtIndex: i] == oldObject) { [self replaceObjectAtIndex: i withObject: newObject]; return; } } } - (void)removeObjectAtIndex: (size_t)idx |
︙ | ︙ | |||
372 373 374 375 376 377 378 | [self removeObjectAtIndex: i]; return; } } } | | | | | < | < | < | < | < | | | | < | 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | [self removeObjectAtIndex: i]; return; } } } - (void)removeObjectsInRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) [self removeObjectAtIndex: range.location]; } - (void)removeLastObject { size_t count = self.count; if (count == 0) return; [self removeObjectAtIndex: count - 1]; } - (void)removeAllObjects { [self removeObjectsInRange: OFRangeMake(0, self.count)]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (OFArrayReplaceBlock)block { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { id new = block(object, idx); if (new != object) [self replaceObjectAtIndex: idx withObject: new]; }]; } #endif - (void)exchangeObjectAtIndex: (size_t)idx1 withObjectAtIndex: (size_t)idx2 { id object1 = [self objectAtIndex: idx1]; id object2 = [self objectAtIndex: idx2]; [object1 retain]; @try { [self replaceObjectAtIndex: idx1 withObject: object2]; [self replaceObjectAtIndex: idx2 withObject: object1]; } @finally { [object1 release]; } } - (void)sort { [self sortUsingSelector: @selector(compare:) options: 0]; } - (void)sortUsingSelector: (SEL)selector options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; quicksort(self, 0, count - 1, selector, options); } #ifdef OF_HAVE_BLOCKS - (void)sortUsingComparator: (OFComparator)comparator options: (OFArraySortOptions)options { size_t count = self.count; if (count == 0 || count == 1) return; quicksortWithBlock(self, 0, count - 1, comparator, options); } #endif - (void)reverse { size_t i, j, count = self.count; if (count == 0 || count == 1) return; for (i = 0, j = count - 1; i < j; i++, j--) [self exchangeObjectAtIndex: i withObjectAtIndex: j]; } - (void)makeImmutable { } @end |
Modified src/OFMutableData.h from [0d48d79112] to [8cc32bdba7].
︙ | ︙ | |||
82 83 84 85 86 87 88 | * @brief Creates a new OFMutableData with enough memory to hold the specified * number of items which all have the same specified size. * * @param itemSize The size of a single element in the OFMutableData * @param capacity The initial capacity for the OFMutableData * @return A new autoreleased OFMutableData */ | | < | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | * @brief Creates a new OFMutableData with enough memory to hold the specified * number of items which all have the same specified size. * * @param itemSize The size of a single element in the OFMutableData * @param capacity The initial capacity for the OFMutableData * @return A new autoreleased OFMutableData */ + (instancetype)dataWithItemSize: (size_t)itemSize capacity: (size_t)capacity; /** * @brief Initializes an already allocated OFMutableData with an item size of 1. * * @return An initialized OFMutableData */ - (instancetype)init; |
︙ | ︙ | |||
120 121 122 123 124 125 126 | * hold the the specified number of items which all have the same * specified size. * * @param itemSize The size of a single element in the OFMutableData * @param capacity The initial capacity for the OFMutableData * @return An initialized OFMutableData */ | | < | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | * hold the the specified number of items which all have the same * specified size. * * @param itemSize The size of a single element in the OFMutableData * @param capacity The initial capacity for the OFMutableData * @return An initialized OFMutableData */ - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity; /** * @brief Returns a specific item of the OFMutableData. * * Modifying the returned item directly is allowed and will change the contents * of the data. * |
︙ | ︙ | |||
147 148 149 150 151 152 153 | /** * @brief Adds an item to the OFMutableData at the specified index. * * @param item A pointer to an arbitrary item * @param index The index where the item should be added */ | | < | < | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | /** * @brief Adds an item to the OFMutableData at the specified index. * * @param item A pointer to an arbitrary item * @param index The index where the item should be added */ - (void)insertItem: (const void *)item atIndex: (size_t)index; /** * @brief Adds items from a C array to the OFMutableData. * * @param items A C array containing the items to add * @param count The number of items to add */ - (void)addItems: (const void *)items count: (size_t)count; /** * @brief Adds items from a C array to the OFMutableData at the specified index. * * @param items A C array containing the items to add * @param index The index where the items should be added * @param count The number of items to add |
︙ | ︙ | |||
190 191 192 193 194 195 196 | - (void)removeItemAtIndex: (size_t)index; /** * @brief Removes the specified amount of items at the specified index. * * @param range The range of items to remove */ | | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | - (void)removeItemAtIndex: (size_t)index; /** * @brief Removes the specified amount of items at the specified index. * * @param range The range of items to remove */ - (void)removeItemsInRange: (OFRange)range; /** * @brief Removes the last item. */ - (void)removeLastItem; /** |
︙ | ︙ |
Modified src/OFMutableData.m from [636b152d9a] to [561513047f].
︙ | ︙ | |||
38 39 40 41 42 43 44 | } + (instancetype)dataWithCapacity: (size_t)capacity { return [[[self alloc] initWithCapacity: capacity] autorelease]; } | | < | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | } + (instancetype)dataWithCapacity: (size_t)capacity { return [[[self alloc] initWithCapacity: capacity] autorelease]; } + (instancetype)dataWithItemSize: (size_t)itemSize capacity: (size_t)capacity { return [[[self alloc] initWithItemSize: itemSize capacity: capacity] autorelease]; } - (instancetype)init { |
︙ | ︙ | |||
79 80 81 82 83 84 85 | - (instancetype)initWithCapacity: (size_t)capacity { return [self initWithItemSize: 1 capacity: capacity]; } | | < | | < < | < < | | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | - (instancetype)initWithCapacity: (size_t)capacity { return [self initWithItemSize: 1 capacity: capacity]; } - (instancetype)initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { self = [super init]; @try { if (itemSize == 0) @throw [OFInvalidArgumentException exception]; _items = OFAllocMemory(capacity, itemSize); _itemSize = itemSize; _capacity = capacity; _freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize { self = [super initWithItems: items count: count itemSize: itemSize]; _capacity = _count; return self; } - (instancetype)initWithItemsNoCopy: (void *)items count: (size_t)count itemSize: (size_t)itemSize freeWhenDone: (bool)freeWhenDone { self = [self initWithItems: items count: count itemSize: itemSize]; if (freeWhenDone) OFFreeMemory(items); return self; } - (instancetype)initWithStringRepresentation: (OFString *)string { self = [super initWithStringRepresentation: string]; |
︙ | ︙ | |||
166 167 168 169 170 171 172 | { if (_items == NULL || _count == 0) return NULL; return _items + (_count - 1) * _itemSize; } | | | | < | < < | < | | | | | | | | | | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | { if (_items == NULL || _count == 0) return NULL; return _items + (_count - 1) * _itemSize; } - (OFData *)subdataWithRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) @throw [OFOutOfRangeException exception]; return [OFData dataWithItems: _items + (range.location * _itemSize) count: range.length itemSize: _itemSize]; } - (void)addItem: (const void *)item { if (SIZE_MAX - _count < 1) @throw [OFOutOfRangeException exception]; if (_count + 1 > _capacity) { _items = OFResizeMemory(_items, _count + 1, _itemSize); _capacity = _count + 1; } memcpy(_items + _count * _itemSize, item, _itemSize); _count++; } - (void)insertItem: (const void *)item atIndex: (size_t)idx { [self insertItems: item atIndex: idx count: 1]; } - (void)addItems: (const void *)items count: (size_t)count { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memcpy(_items + _count * _itemSize, items, count * _itemSize); _count += count; } - (void)insertItems: (const void *)items atIndex: (size_t)idx count: (size_t)count { if (count > SIZE_MAX - _count || idx > _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memmove(_items + (idx + count) * _itemSize, _items + idx * _itemSize, (_count - idx) * _itemSize); memcpy(_items + idx * _itemSize, items, count * _itemSize); _count += count; } - (void)increaseCountBy: (size_t)count { if (count > SIZE_MAX - _count) @throw [OFOutOfRangeException exception]; if (_count + count > _capacity) { _items = OFResizeMemory(_items, _count + count, _itemSize); _capacity = _count + count; } memset(_items + _count * _itemSize, '\0', count * _itemSize); _count += count; } - (void)removeItemAtIndex: (size_t)idx { [self removeItemsInRange: OFRangeMake(idx, 1)]; } - (void)removeItemsInRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _count) @throw [OFOutOfRangeException exception]; memmove(_items + range.location * _itemSize, _items + (range.location + range.length) * _itemSize, (_count - range.location - range.length) * _itemSize); _count -= range.length; @try { _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)removeLastItem { if (_count == 0) return; _count--; @try { _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } - (void)removeAllItems { OFFreeMemory(_items); _items = NULL; _count = 0; _capacity = 0; } - (id)copy { return [[OFData alloc] initWithItems: _items count: _count itemSize: _itemSize]; } - (void)makeImmutable { if (_capacity != _count) { @try { _items = OFResizeMemory(_items, _count, _itemSize); _capacity = _count; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } object_setClass(self, [OFData class]); } @end |
Modified src/OFMutableDictionary.h from [995b885913] to [d2bbc1da30].
︙ | ︙ | |||
23 24 25 26 27 28 29 | /** * @brief A block for replacing objects in an OFMutableDictionary. * * @param key The key of the object to replace * @param object The object to replace * @return The object to replace the object with */ | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | /** * @brief A block for replacing objects in an OFMutableDictionary. * * @param key The key of the object to replace * @param object The object to replace * @return The object to replace the object with */ typedef id _Nonnull (^OFDictionaryReplaceBlock)(id key, id object); #endif /** * @class OFMutableDictionary OFDictionary.h ObjFW/OFDictionary.h * * @brief An abstract class for storing and changing objects in a dictionary. * |
︙ | ︙ | |||
67 68 69 70 71 72 73 | * @brief Sets an object for a key. * * A key can be any object that conforms to the OFCopying protocol. * * @param key The key to set * @param object The object to set the key to */ | | < | < | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | * @brief Sets an object for a key. * * A key can be any object that conforms to the OFCopying protocol. * * @param key The key to set * @param object The object to set the key to */ - (void)setObject: (ObjectType)object forKey: (KeyType)key; /** * @brief Sets an object for a key. * * A key can be any object that conforms to the OFCopying protocol. * * This method is also used by the subscripting syntax. * * @param key The key to set * @param object The object to set the key to. If it is nil, this is equal to * calling @ref removeObjectForKey:. */ - (void)setObject: (nullable ObjectType)object forKeyedSubscript: (KeyType)key; /** * @brief Removes the object for the specified key from the dictionary. * * @param key The key whose object should be removed */ - (void)removeObjectForKey: (KeyType)key; |
︙ | ︙ | |||
110 111 112 113 114 115 116 | #ifdef OF_HAVE_BLOCKS /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ | | | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | #ifdef OF_HAVE_BLOCKS /** * @brief Replaces each object with the object returned by the block. * * @param block The block which returns a new object for each object */ - (void)replaceObjectsUsingBlock: (OFDictionaryReplaceBlock)block; #endif /** * @brief Converts the mutable dictionary to an immutable dictionary. */ - (void)makeImmutable; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef KeyType # undef ObjectType #endif @end OF_ASSUME_NONNULL_END |
Modified src/OFMutableDictionary.m from [258a8f4b24] to [e5de8c4c10].
︙ | ︙ | |||
36 37 38 39 40 41 42 | - (instancetype)initWithDictionary: (OFDictionary *)dictionary { return (id)[[OFMutableMapTableDictionary alloc] initWithDictionary: dictionary]; } | | < | < | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | - (instancetype)initWithDictionary: (OFDictionary *)dictionary { return (id)[[OFMutableMapTableDictionary alloc] initWithDictionary: dictionary]; } - (instancetype)initWithObject: (id)object forKey: (id)key { return (id)[[OFMutableMapTableDictionary alloc] initWithObject: object forKey: key]; } - (instancetype)initWithObjects: (OFArray *)objects forKeys: (OFArray *)keys { return (id)[[OFMutableMapTableDictionary alloc] initWithObjects: objects forKeys: keys]; } - (instancetype)initWithObjects: (id const *)objects forKeys: (id const *)keys |
︙ | ︙ | |||
72 73 74 75 76 77 78 | ret = (id)[[OFMutableMapTableDictionary alloc] initWithKey: firstKey arguments: arguments]; va_end(arguments); return ret; } | | < | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | ret = (id)[[OFMutableMapTableDictionary alloc] initWithKey: firstKey arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments { return (id)[[OFMutableMapTableDictionary alloc] initWithKey: firstKey arguments: arguments]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { |
︙ | ︙ | |||
152 153 154 155 156 157 158 | } - (instancetype)initWithCapacity: (size_t)capacity { OF_INVALID_INIT_METHOD } | | < | < | < | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | } - (instancetype)initWithCapacity: (size_t)capacity { OF_INVALID_INIT_METHOD } - (void)setObject: (id)object forKey: (id)key { OF_UNRECOGNIZED_SELECTOR } - (void)setObject: (id)object forKeyedSubscript: (id)key { if (object != nil) [self setObject: object forKey: key]; else [self removeObjectForKey: key]; } - (void)removeObjectForKey: (id)key { OF_UNRECOGNIZED_SELECTOR |
︙ | ︙ | |||
197 198 199 200 201 202 203 | void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [dictionary keyEnumerator]; OFEnumerator *objectEnumerator = [dictionary objectEnumerator]; id key, object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) | | < | | < | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [dictionary keyEnumerator]; OFEnumerator *objectEnumerator = [dictionary objectEnumerator]; id key, object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [self setObject: object forKey: key]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (OFDictionaryReplaceBlock)block { [self enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { id new = block(key, object); if (new != object) { [self setObject: block(key, object) forKey: key]; } }]; } #endif - (void)makeImmutable { } @end |
Modified src/OFMutableMapTableDictionary.m from [01b0a38e38] to [1009eb93ce].
︙ | ︙ | |||
27 28 29 30 31 32 33 | @implementation OFMutableMapTableDictionary + (void)initialize { if (self == [OFMutableMapTableDictionary class]) [self inheritMethodsFromClass: [OFMapTableDictionary class]]; } | | < | < | | 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 | @implementation OFMutableMapTableDictionary + (void)initialize { if (self == [OFMutableMapTableDictionary class]) [self inheritMethodsFromClass: [OFMapTableDictionary class]]; } - (void)setObject: (id)object forKey: (id)key { [_mapTable setObject: object forKey: key]; } - (void)removeObjectForKey: (id)key { [_mapTable removeObjectForKey: key]; } - (void)removeAllObjects { [_mapTable removeAllObjects]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (OFDictionaryReplaceBlock)block { @try { [_mapTable replaceObjectsUsingBlock: ^ void *(void *key, void *object) { return block(key, object); }]; } @catch (OFEnumerationMutationException *e) { |
︙ | ︙ |
Modified src/OFMutableMapTableSet.m from [ece4193cc3] to [6bd4d296b2].
︙ | ︙ | |||
24 25 26 27 28 29 30 | { if (self == [OFMutableMapTableSet class]) [self inheritMethodsFromClass: [OFMapTableSet class]]; } - (void)addObject: (id)object { | | < | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | { if (self == [OFMutableMapTableSet class]) [self inheritMethodsFromClass: [OFMapTableSet class]]; } - (void)addObject: (id)object { [_mapTable setObject: (void *)1 forKey: object]; } - (void)removeObject: (id)object { [_mapTable removeObjectForKey: object]; } |
︙ | ︙ |
Modified src/OFMutablePair.m from [4ca2c970a8] to [12c9fcd056].
︙ | ︙ | |||
33 34 35 36 37 38 39 | _secondObject = [secondObject retain]; [old release]; } - (id)copy { OFMutablePair *copy = [self mutableCopy]; | < < | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | _secondObject = [secondObject retain]; [old release]; } - (id)copy { OFMutablePair *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)makeImmutable { object_setClass(self, [OFPair class]); } |
︙ | ︙ |
Modified src/OFMutableSet.m from [00cf253ec8] to [4c13c1c2d3].
︙ | ︙ | |||
54 55 56 57 58 59 60 | ret = [[OFMutableMapTableSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } | | < | < | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | ret = [[OFMutableMapTableSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFMutableMapTableSet alloc] initWithObjects: objects count: count]; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFMutableMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { |
︙ | ︙ | |||
166 167 168 169 170 171 172 | - (void)intersectSet: (OFSet *)set { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; | | | | | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | - (void)intersectSet: (OFSet *)set { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; cArray = OFAllocMemory(count, sizeof(id)); @try { size_t i; i = 0; for (id object in self) { assert(i < count); cArray[i++] = object; } for (i = 0; i < count; i++) if (![set containsObject: cArray[i]]) [self removeObject: cArray[i]]; } @finally { OFFreeMemory(cArray); } objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet *)set { |
︙ | ︙ |
Modified src/OFMutableString.h from [3c94bae91e] to [9719f9d256].
︙ | ︙ | |||
29 30 31 32 33 34 35 | @interface OFMutableString: OFString /** * @brief Sets the character at the specified index. * * @param character The character to set * @param index The index where to set the character */ | | < | < | 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 | @interface OFMutableString: OFString /** * @brief Sets the character at the specified index. * * @param character The character to set * @param index The index where to set the character */ - (void)setCharacter: (OFUnichar)character atIndex: (size_t)index; /** * @brief Appends another OFString to the OFMutableString. * * @param string An OFString to append */ - (void)appendString: (OFString *)string; /** * @brief Appends the specified characters to the OFMutableString. * * @param characters An array of characters to append * @param length The length of the array of characters */ - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Appends a UTF-8 encoded C string to the OFMutableString. * * @param UTF8String A UTF-8 encoded C string to append */ - (void)appendUTF8String: (const char *)UTF8String; |
︙ | ︙ | |||
72 73 74 75 76 77 78 | /** * @brief Appends a C string with the specified encoding to the OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string */ - (void)appendCString: (const char *)cString | | | | | | | | < | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | /** * @brief Appends a C string with the specified encoding to the OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Appends a C string with the specified encoding and length to the * OFMutableString. * * @param cString A C string to append * @param encoding The encoding of the C string * @param cStringLength The length of the UTF-8 encoded C string */ - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Appends a formatted string to the OFMutableString. * * See `printf` for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append */ - (void)appendFormat: (OFConstantString *)format, ...; /** * @brief Appends a formatted string to the OFMutableString. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A format string which generates the string to append * @param arguments The arguments used in the format string */ - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments; /** * @brief Prepends another OFString to the OFMutableString. * * @param string An OFString to prepend */ - (void)prependString: (OFString *)string; |
︙ | ︙ | |||
147 148 149 150 151 152 153 | /** * @brief Inserts a string at the specified index. * * @param string The string to insert * @param index The index */ | | < | | | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /** * @brief Inserts a string at the specified index. * * @param string The string to insert * @param index The index */ - (void)insertString: (OFString *)string atIndex: (size_t)index; /** * @brief Deletes the characters at the specified range. * * @param range The range of the characters which should be removed */ - (void)deleteCharactersInRange: (OFRange)range; /** * @brief Replaces the characters at the specified range. * * @param range The range of the characters which should be replaced * @param replacement The string to the replace the characters with */ - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)replacement; /** * @brief Replaces all occurrences of a string with another string. * * @param string The string to replace * @param replacement The string with which it should be replaced |
︙ | ︙ | |||
188 189 190 191 192 193 194 | * @param options Options modifying search behaviour * Possible values: None yet * @param range The range in which the string should be replaced */ - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options | | | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | * @param options Options modifying search behaviour * Possible values: None yet * @param range The range in which the string should be replaced */ - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range; /** * @brief Deletes all whitespaces at the beginning of the string. */ - (void)deleteLeadingWhitespaces; /** |
︙ | ︙ |
Modified src/OFMutableString.m from [b6e6846a4c] to [7608f6e984].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 | #include "config.h" #include <stdarg.h> #include <stdlib.h> #include <string.h> #import "OFString.h" #import "OFMutableUTF8String.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" | > < | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include "config.h" #include <stdarg.h> #include <stdlib.h> #include <string.h> #import "OFString.h" #import "OFASPrintF.h" #import "OFMutableUTF8String.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "unicode.h" static struct { Class isa; } placeholder; @interface OFMutableStringPlaceholder: OFMutableString |
︙ | ︙ | |||
52 53 54 55 56 57 58 | { return (id)[[OFMutableUTF8String alloc] initWithUTF8String: UTF8String length: UTF8StringLength]; } - (instancetype)initWithCString: (const char *)cString | | | | | | | | | | | | | | | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | { return (id)[[OFMutableUTF8String alloc] initWithUTF8String: UTF8String length: UTF8StringLength]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { return (id)[[OFMutableUTF8String alloc] initWithCString: cString encoding: encoding]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { return (id)[[OFMutableUTF8String alloc] initWithCString: cString encoding: encoding length: cStringLength]; } - (instancetype)initWithString: (OFString *)string { return (id)[[OFMutableUTF8String alloc] initWithString: string]; } - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length { return (id)[[OFMutableUTF8String alloc] initWithCharacters: characters length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF16String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string length: length]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFMutableUTF8String alloc] initWithUTF32String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithFormat: (OFConstantString *)format, ... |
︙ | ︙ | |||
162 163 164 165 166 167 168 | #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFMutableUTF8String alloc] initWithContentsOfFile: path]; } - (instancetype)initWithContentsOfFile: (OFString *)path | | < | < | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFMutableUTF8String alloc] initWithContentsOfFile: path]; } - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { return (id)[[OFMutableUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif - (instancetype)initWithContentsOfURL: (OFURL *)URL { return (id)[[OFMutableUTF8String alloc] initWithContentsOfURL: URL]; } - (instancetype)initWithContentsOfURL: (OFURL *)URL encoding: (OFStringEncoding)encoding { return (id)[[OFMutableUTF8String alloc] initWithContentsOfURL: URL encoding: encoding]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { return (id)[[OFMutableUTF8String alloc] initWithSerialization: element]; } - (instancetype)retain |
︙ | ︙ | |||
226 227 228 229 230 231 232 | if (self == [OFMutableString class]) return (id)&placeholder; return [super alloc]; } #ifdef OF_HAVE_UNICODE_TABLES | | | | | | | | < | > | | < | | | < | | < | < | < < | < < | < | < < < < < < | < < | < < | < | | < | < | | < | < | | | | | | | | | | | | < < < < | > > > | < | < | < | < | | < | | | | | | | | | | | | | | | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | if (self == [OFMutableString class]) return (id)&placeholder; return [super alloc]; } #ifdef OF_HAVE_UNICODE_TABLES - (void)of_convertWithWordStartTable: (const OFUnichar *const [])startTable wordMiddleTable: (const OFUnichar *const [])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; bool isStart = true; for (size_t i = 0; i < length; i++) { const OFUnichar *const *table; size_t tableSize; OFUnichar c = characters[i]; if (isStart) { table = startTable; tableSize = middleTableSize; } else { table = middleTable; tableSize = middleTableSize; } if (c >> 8 < tableSize && table[c >> 8][c & 0xFF]) [self setCharacter: table[c >> 8][c & 0xFF] atIndex: i]; isStart = OFASCIIIsSpace(c); } objc_autoreleasePoolPop(pool); } #else static void convert(OFMutableString *self, char (*startFunction)(char), char (*middleFunction)(char)) { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; bool isStart = true; for (size_t i = 0; i < length; i++) { char (*function)(char) = (isStart ? startFunction : middleFunction); OFUnichar c = characters[i]; if (c <= 0x7F) [self setCharacter: (int)function(c) atIndex: i]; isStart = OFASCIIIsSpace(c); } objc_autoreleasePoolPop(pool); } #endif - (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithCharacters: &character length: 1]; [self replaceCharactersInRange: OFRangeMake(idx, 1) withString: string]; objc_autoreleasePoolPop(pool); } - (void)appendString: (OFString *)string { [self insertString: string atIndex: self.length]; } - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCharacters: characters length: length]]; objc_autoreleasePoolPop(pool); } - (void)appendUTF8String: (const char *)UTF8String { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String]]; objc_autoreleasePoolPop(pool); } - (void)appendUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String length: UTF8StringLength]]; objc_autoreleasePoolPop(pool); } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding]]; objc_autoreleasePoolPop(pool); } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; objc_autoreleasePoolPop(pool); } - (void)appendFormat: (OFConstantString *)format, ... { va_list arguments; va_start(arguments, format); [self appendFormat: format arguments: arguments]; va_end(arguments); } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; if ((UTF8StringLength = OFVASPrintF(&UTF8String, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } - (void)prependString: (OFString *)string { [self insertString: string atIndex: 0]; } - (void)reverse { size_t i, j, length = self.length; for (i = 0, j = length - 1; i < length / 2; i++, j--) { OFUnichar tmp = [self characterAtIndex: j]; [self setCharacter: [self characterAtIndex: i] atIndex: j]; [self setCharacter: tmp atIndex: i]; } } #ifdef OF_HAVE_UNICODE_TABLES - (void)uppercase { [self of_convertWithWordStartTable: OFUnicodeUppercaseTable wordMiddleTable: OFUnicodeUppercaseTable wordStartTableSize: OFUnicodeUppercaseTableSize wordMiddleTableSize: OFUnicodeUppercaseTableSize]; } - (void)lowercase { [self of_convertWithWordStartTable: OFUnicodeLowercaseTable wordMiddleTable: OFUnicodeLowercaseTable wordStartTableSize: OFUnicodeLowercaseTableSize wordMiddleTableSize: OFUnicodeLowercaseTableSize]; } - (void)capitalize { [self of_convertWithWordStartTable: OFUnicodeTitlecaseTable wordMiddleTable: OFUnicodeLowercaseTable wordStartTableSize: OFUnicodeTitlecaseTableSize wordMiddleTableSize: OFUnicodeLowercaseTableSize]; } #else - (void)uppercase { convert(self, OFASCIIToUpper, OFASCIIToUpper); } - (void)lowercase { convert(self, OFASCIIToLower, OFASCIIToLower); } - (void)capitalize { convert(self, OFASCIIToUpper, OFASCIIToLower); } #endif - (void)insertString: (OFString *)string atIndex: (size_t)idx { [self replaceCharactersInRange: OFRangeMake(idx, 0) withString: string]; } - (void)deleteCharactersInRange: (OFRange)range { [self replaceCharactersInRange: range withString: @""]; } - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)replacement { OF_UNRECOGNIZED_SELECTOR } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { [self replaceOccurrencesOfString: string withString: replacement options: 0 range: OFRangeMake(0, self.length)]; } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { void *pool = objc_autoreleasePoolPush(), *pool2; const OFUnichar *characters; const OFUnichar *searchCharacters = string.characters; size_t searchLength = string.length; size_t replacementLength = replacement.length; if (string == nil || replacement == nil) @throw [OFInvalidArgumentException exception]; if (range.length > SIZE_MAX - range.location || range.location + range.length > self.length) @throw [OFOutOfRangeException exception]; if (searchLength > range.length) { objc_autoreleasePoolPop(pool); return; } pool2 = objc_autoreleasePoolPush(); characters = self.characters; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) != 0) continue; [self replaceCharactersInRange: OFRangeMake(i, searchLength) withString: replacement]; range.length -= searchLength; range.length += replacementLength; i += replacementLength - 1; objc_autoreleasePoolPop(pool2); pool2 = objc_autoreleasePoolPush(); characters = self.characters; } objc_autoreleasePoolPop(pool); } - (void)deleteLeadingWhitespaces { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t i, length = self.length; for (i = 0; i < length; i++) { OFUnichar c = characters[i]; if (!OFASCIIIsSpace(c)) break; } objc_autoreleasePoolPop(pool); [self deleteCharactersInRange: OFRangeMake(0, i)]; } - (void)deleteTrailingWhitespaces { void *pool; const OFUnichar *characters, *p; size_t length, d; length = self.length; if (length == 0) return; pool = objc_autoreleasePoolPush(); characters = self.characters; d = 0; for (p = characters + length - 1; p >= characters; p--) { if (!OFASCIIIsSpace(*p)) break; d++; } objc_autoreleasePoolPop(pool); [self deleteCharactersInRange: OFRangeMake(length - d, d)]; } - (void)deleteEnclosingWhitespaces { [self deleteLeadingWhitespaces]; [self deleteTrailingWhitespaces]; } |
︙ | ︙ |
Modified src/OFMutableTarArchiveEntry.h from [2d44acedbb] to [ec04d24178].
︙ | ︙ | |||
57 58 59 60 61 62 63 | * @brief The date of the last modification of the file. */ @property (readwrite, retain, nonatomic) OFDate *modificationDate; /** * @brief The type of the archive entry. * | | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | * @brief The date of the last modification of the file. */ @property (readwrite, retain, nonatomic) OFDate *modificationDate; /** * @brief The type of the archive entry. * * See @ref OFTarArchiveEntryType. */ @property (readwrite, nonatomic) OFTarArchiveEntryType type; /** * @brief The file name of the target (for a hard link or symbolic link). */ @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFString *targetFileName; |
︙ | ︙ |
Modified src/OFMutableTarArchiveEntry.m from [9a77a0f3e7] to [a864b37365].
︙ | ︙ | |||
62 63 64 65 66 67 68 | - (void)setModificationDate: (OFDate *)modificationDate { OFDate *old = _modificationDate; _modificationDate = [modificationDate retain]; [old release]; } | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | - (void)setModificationDate: (OFDate *)modificationDate { OFDate *old = _modificationDate; _modificationDate = [modificationDate retain]; [old release]; } - (void)setType: (OFTarArchiveEntryType)type { _type = type; } - (void)setTargetFileName: (OFString *)targetFileName { OFString *old = _targetFileName; |
︙ | ︙ |
Modified src/OFMutableURL.m from [990fa14b6b] to [3668c5a3ba].
︙ | ︙ | |||
22 23 24 25 26 27 28 | # import "OFFileManager.h" #endif #import "OFNumber.h" #import "OFString.h" #import "OFInvalidFormatException.h" | < < | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # import "OFFileManager.h" #endif #import "OFNumber.h" #import "OFString.h" #import "OFInvalidFormatException.h" @implementation OFMutableURL @dynamic scheme, URLEncodedScheme, host, URLEncodedHost, port, user; @dynamic URLEncodedUser, password, URLEncodedPassword, path, URLEncodedPath; @dynamic pathComponents, query, URLEncodedQuery, queryDictionary, fragment; @dynamic URLEncodedFragment; + (instancetype)URL |
︙ | ︙ | |||
53 54 55 56 57 58 59 | } - (void)setURLEncodedScheme: (OFString *)URLEncodedScheme { OFString *old; if (URLEncodedScheme != nil) | | | | | | | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | } - (void)setURLEncodedScheme: (OFString *)URLEncodedScheme { OFString *old; if (URLEncodedScheme != nil) OFURLVerifyIsEscaped(URLEncodedScheme, [OFCharacterSet URLSchemeAllowedCharacterSet]); old = _URLEncodedScheme; _URLEncodedScheme = [URLEncodedScheme copy]; [old release]; } - (void)setHost: (OFString *)host { void *pool = objc_autoreleasePoolPush(); OFString *old = _URLEncodedHost; if (OFURLIsIPv6Host(host)) _URLEncodedHost = [[OFString alloc] initWithFormat: @"[%@]", host]; else _URLEncodedHost = [[host stringByURLEncodingWithAllowedCharacters: [OFCharacterSet URLHostAllowedCharacterSet]] copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setURLEncodedHost: (OFString *)URLEncodedHost { OFString *old; if ([URLEncodedHost hasPrefix: @"["] && [URLEncodedHost hasSuffix: @"]"]) { if (!OFURLIsIPv6Host([URLEncodedHost substringWithRange: OFRangeMake(1, URLEncodedHost.length - 2)])) @throw [OFInvalidFormatException exception]; } else if (URLEncodedHost != nil) OFURLVerifyIsEscaped(URLEncodedHost, [OFCharacterSet URLHostAllowedCharacterSet]); old = _URLEncodedHost; _URLEncodedHost = [URLEncodedHost copy]; [old release]; } |
︙ | ︙ | |||
122 123 124 125 126 127 128 | } - (void)setURLEncodedUser: (OFString *)URLEncodedUser { OFString *old; if (URLEncodedUser != nil) | | | 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | } - (void)setURLEncodedUser: (OFString *)URLEncodedUser { OFString *old; if (URLEncodedUser != nil) OFURLVerifyIsEscaped(URLEncodedUser, [OFCharacterSet URLUserAllowedCharacterSet]); old = _URLEncodedUser; _URLEncodedUser = [URLEncodedUser copy]; [old release]; } |
︙ | ︙ | |||
149 150 151 152 153 154 155 | } - (void)setURLEncodedPassword: (OFString *)URLEncodedPassword { OFString *old; if (URLEncodedPassword != nil) | | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | } - (void)setURLEncodedPassword: (OFString *)URLEncodedPassword { OFString *old; if (URLEncodedPassword != nil) OFURLVerifyIsEscaped(URLEncodedPassword, [OFCharacterSet URLPasswordAllowedCharacterSet]); old = _URLEncodedPassword; _URLEncodedPassword = [URLEncodedPassword copy]; [old release]; } |
︙ | ︙ | |||
175 176 177 178 179 180 181 | } - (void)setURLEncodedPath: (OFString *)URLEncodedPath { OFString *old; if (URLEncodedPath != nil) | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | } - (void)setURLEncodedPath: (OFString *)URLEncodedPath { OFString *old; if (URLEncodedPath != nil) OFURLVerifyIsEscaped(URLEncodedPath, [OFCharacterSet URLPathAllowedCharacterSet]); old = _URLEncodedPath; _URLEncodedPath = [URLEncodedPath copy]; [old release]; } |
︙ | ︙ | |||
221 222 223 224 225 226 227 | } - (void)setURLEncodedQuery: (OFString *)URLEncodedQuery { OFString *old; if (URLEncodedQuery != nil) | | | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | } - (void)setURLEncodedQuery: (OFString *)URLEncodedQuery { OFString *old; if (URLEncodedQuery != nil) OFURLVerifyIsEscaped(URLEncodedQuery, [OFCharacterSet URLQueryAllowedCharacterSet]); old = _URLEncodedQuery; _URLEncodedQuery = [URLEncodedQuery copy]; [old release]; } |
︙ | ︙ | |||
289 290 291 292 293 294 295 | } - (void)setURLEncodedFragment: (OFString *)URLEncodedFragment { OFString *old; if (URLEncodedFragment != nil) | | | < | 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | } - (void)setURLEncodedFragment: (OFString *)URLEncodedFragment { OFString *old; if (URLEncodedFragment != nil) OFURLVerifyIsEscaped(URLEncodedFragment, [OFCharacterSet URLFragmentAllowedCharacterSet]); old = _URLEncodedFragment; _URLEncodedFragment = [URLEncodedFragment copy]; [old release]; } - (id)copy { OFMutableURL *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)appendPathComponent: (OFString *)component { [self appendPathComponent: component isDirectory: false]; #ifdef OF_HAVE_FILES if ([_URLEncodedScheme isEqual: @"file"] && ![_URLEncodedPath hasSuffix: @"/"] && [[OFFileManager defaultManager] directoryExistsAtURL: self]) { void *pool = objc_autoreleasePoolPush(); OFString *path = [_URLEncodedPath |
︙ | ︙ | |||
401 402 403 404 405 406 407 | done = false; break; } if ([current isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: | | | < | 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | done = false; break; } if ([current isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFRangeMake(i - 1, 2)]; done = false; break; } } } [array insertObject: @"" atIndex: 0]; if (endsWithEmpty) [array addObject: @""]; path = [array componentsJoinedByString: @"/"]; if (path.length == 0) path = @"/"; |
︙ | ︙ |
Modified src/OFMutableUTF8String.h from [15b5339be2] to [ef5fa816c6].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFMutableString.h" #import "OFUTF8String.h" OF_ASSUME_NONNULL_BEGIN @interface OFMutableUTF8String: OFMutableString { | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 | #import "OFMutableString.h" #import "OFUTF8String.h" OF_ASSUME_NONNULL_BEGIN @interface OFMutableUTF8String: OFMutableString { struct OFUTF8StringIvars *restrict _s; struct OFUTF8StringIvars _storage; } @end OF_ASSUME_NONNULL_END |
Modified src/OFMutableUTF8String.m from [0bce7a5121] to [8129fb7234].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include <stdarg.h> #include <stdlib.h> #include <string.h> #include <assert.h> #import "OFMutableUTF8String.h" #import "OFString.h" #import "OFUTF8String.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" | > < | | < | > | | | | | | | | | | | | | | | | | | | | | | | > | < | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | #include <stdarg.h> #include <stdlib.h> #include <string.h> #include <assert.h> #import "OFMutableUTF8String.h" #import "OFASPrintF.h" #import "OFString.h" #import "OFUTF8String.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "unicode.h" @implementation OFMutableUTF8String + (void)initialize { if (self == [OFMutableUTF8String class]) [self inheritMethodsFromClass: [OFUTF8String class]]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String]; if (freeWhenDone) OFFreeMemory(UTF8String); return self; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) OFFreeMemory(UTF8String); return self; } #ifdef OF_HAVE_UNICODE_TABLES - (void)of_convertWithWordStartTable: (const OFUnichar *const [])startTable wordMiddleTable: (const OFUnichar *const [])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { OFUnichar *unicodeString; size_t unicodeLen, newCStringLength; size_t i, j; char *newCString; bool isStart = true; if (!_s->isUTF8) { uint8_t t; const OFUnichar *const *table; assert(startTableSize >= 1 && middleTableSize >= 1); _s->hasHash = false; for (i = 0; i < _s->cStringLength; i++) { if (isStart) table = startTable; else table = middleTable; isStart = OFASCIIIsSpace(_s->cString[i]); if ((t = table[0][(uint8_t)_s->cString[i]]) != 0) _s->cString[i] = t; } return; } unicodeLen = self.length; unicodeString = OFAllocMemory(unicodeLen, sizeof(OFUnichar)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { const OFUnichar *const *table; size_t tableSize; OFUnichar c; ssize_t cLen; if (isStart) { table = startTable; tableSize = middleTableSize; } else { table = middleTable; tableSize = middleTableSize; } cLen = OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } isStart = OFASCIIIsSpace(c); if (c >> 8 < tableSize) { OFUnichar tc = table[c >> 8][c & 0xFF]; if (tc) c = tc; } unicodeString[j++] = c; if (c < 0x80) newCStringLength++; else if (c < 0x800) newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { newCString = OFAllocMemory(newCStringLength + 1, 1); } @catch (id e) { OFFreeMemory(unicodeString); @throw e; } j = 0; for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = OFUTF8StringEncode(unicodeString[i], newCString + j)) == 0) { OFFreeMemory(unicodeString); OFFreeMemory(newCString); @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; OFFreeMemory(unicodeString); OFFreeMemory(_s->cString); _s->hasHash = false; _s->cString = newCString; _s->cStringLength = newCStringLength; /* * Even though cStringLength can change, length cannot, therefore no * need to change it. */ } #endif - (void)setCharacter: (OFUnichar)character atIndex: (size_t)idx { char buffer[4]; OFUnichar c; size_t lenNew; ssize_t lenOld; if (_s->isUTF8) idx = OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); if (idx >= _s->cStringLength) @throw [OFOutOfRangeException exception]; /* Shortcut if old and new character both are ASCII */ if (character < 0x80 && !(_s->cString[idx] & 0x80)) { _s->hasHash = false; _s->cString[idx] = character; return; } if ((lenNew = OFUTF8StringEncode(character, buffer)) == 0) @throw [OFInvalidEncodingException exception]; if ((lenOld = OFUTF8StringDecode(_s->cString + idx, _s->cStringLength - idx, &c)) <= 0) @throw [OFInvalidEncodingException exception]; _s->hasHash = false; if (lenNew == (size_t)lenOld) memcpy(_s->cString + idx, buffer, lenNew); else if (lenNew > (size_t)lenOld) { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength - lenOld + lenNew + 1, 1); memmove(_s->cString + idx + lenNew, _s->cString + idx + lenOld, _s->cStringLength - idx - lenOld); memcpy(_s->cString + idx, buffer, lenNew); _s->cStringLength -= lenOld; |
︙ | ︙ | |||
244 245 246 247 248 249 250 | _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; if (character >= 0x80) _s->isUTF8 = true; @try { | | | | | | | | | | | | < | 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; if (character >= 0x80) _s->isUTF8 = true; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } } - (void)appendUTF8String: (const char *)UTF8String { size_t UTF8StringLength = strlen(UTF8String); size_t length; if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } switch (OFUTF8StringCheck(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength + 1); _s->cStringLength += UTF8StringLength; _s->length += length; } - (void)appendUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { size_t length; if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } switch (OFUTF8StringCheck(UTF8String, UTF8StringLength, &length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += length; _s->cString[_s->cStringLength] = 0; } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding { [self appendCString: cString encoding: encoding length: strlen(cString)]; } - (void)appendCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { if (encoding == OFStringEncodingUTF8) [self appendUTF8String: cString length: cStringLength]; else { void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; |
︙ | ︙ | |||
347 348 349 350 351 352 353 | size_t UTF8StringLength; if (string == nil) @throw [OFInvalidArgumentException exception]; UTF8StringLength = string.UTF8StringLength; | | | | < | | < | | | | < | | < | | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | size_t UTF8StringLength; if (string == nil) @throw [OFInvalidArgumentException exception]; UTF8StringLength = string.UTF8StringLength; _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, string.UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += string.length; _s->cString[_s->cStringLength] = 0; if ([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)string)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length { char *tmp = OFAllocMemory((length * 4) + 1, 1); @try { size_t j = 0; bool isUTF8 = false; for (size_t i = 0; i < length; i++) { size_t len = OFUTF8StringEncode(characters[i], tmp + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) isUTF8 = true; j += len; } tmp[j] = '\0'; _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + j + 1, 1); memcpy(_s->cString + _s->cStringLength, tmp, j + 1); _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { OFFreeMemory(tmp); } } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; int UTF8StringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; if ((UTF8StringLength = OFVASPrintF(&UTF8String, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self appendUTF8String: UTF8String length: UTF8StringLength]; } @finally { free(UTF8String); } } - (void)reverse { size_t i, j; _s->hasHash = false; /* We reverse all bytes and restore UTF-8 later, if necessary */ for (i = 0, j = _s->cStringLength - 1; i < _s->cStringLength / 2; i++, j--) { _s->cString[i] ^= _s->cString[j]; _s->cString[j] ^= _s->cString[i]; _s->cString[i] ^= _s->cString[j]; |
︙ | ︙ | |||
506 507 508 509 510 511 512 | } /* UTF-8 does not allow more than 4 bytes per character */ @throw [OFInvalidEncodingException exception]; } } | | < | | | | | | | | > | | | | | > | > | | | | | | | | | | | | > | | | > | | | | > | 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 | } /* UTF-8 does not allow more than 4 bytes per character */ @throw [OFInvalidEncodingException exception]; } } - (void)insertString: (OFString *)string atIndex: (size_t)idx { size_t newCStringLength; if (idx > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) idx = OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); newCStringLength = _s->cStringLength + string.UTF8StringLength; _s->hasHash = false; _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + idx + string.UTF8StringLength, _s->cString + idx, _s->cStringLength - idx); memcpy(_s->cString + idx, string.UTF8String, string.UTF8StringLength); _s->cString[newCStringLength] = '\0'; _s->cStringLength = newCStringLength; _s->length += string.length; if ([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)string)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)deleteCharactersInRange: (OFRange)range { size_t start = range.location; size_t end = range.location + range.length; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { start = OFUTF8StringIndexToPosition(_s->cString, start, _s->cStringLength); end = OFUTF8StringIndexToPosition(_s->cString, end, _s->cStringLength); } memmove(_s->cString + start, _s->cString + end, _s->cStringLength - end); _s->hasHash = false; _s->length -= range.length; _s->cStringLength -= end - start; _s->cString[_s->cStringLength] = 0; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)replacement { size_t start = range.location; size_t end = range.location + range.length; size_t newCStringLength, newLength; if (replacement == nil) @throw [OFInvalidArgumentException exception]; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; newLength = _s->length - range.length + replacement.length; if (_s->isUTF8) { start = OFUTF8StringIndexToPosition(_s->cString, start, _s->cStringLength); end = OFUTF8StringIndexToPosition(_s->cString, end, _s->cStringLength); } newCStringLength = _s->cStringLength - (end - start) + replacement.UTF8StringLength; _s->hasHash = false; /* * If the new string is bigger, we need to resize it first so we can * memmove() the rest of the string to the end. * * We must not resize the string if the new string is smaller, because * then we can't memmove() the rest of the string forward as the rest is * lost due to the resize! */ if (newCStringLength > _s->cStringLength) _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + start + replacement.UTF8StringLength, _s->cString + end, _s->cStringLength - end); memcpy(_s->cString + start, replacement.UTF8String, replacement.UTF8StringLength); _s->cString[newCStringLength] = '\0'; /* * If the new string is smaller, we can safely resize it now as we're * done with memmove(). */ if (newCStringLength < _s->cStringLength) _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)replacement)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)replaceOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { const char *searchString = string.UTF8String; const char *replacementString = replacement.UTF8String; size_t searchLength = string.UTF8StringLength; size_t replacementLength = replacement.UTF8StringLength; size_t last, newCStringLength, newLength; char *newCString; if (string == nil || replacement == nil) @throw [OFInvalidArgumentException exception]; if (range.length > SIZE_MAX - range.location || range.location + range.length > self.length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { range.location = OFUTF8StringIndexToPosition(_s->cString, range.location, _s->cStringLength); range.length = OFUTF8StringIndexToPosition( _s->cString + range.location, range.length, _s->cStringLength - range.location); } if (string.UTF8StringLength > range.length) return; newCString = NULL; newCStringLength = 0; newLength = _s->length; last = 0; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(_s->cString + i, searchString, searchLength) != 0) continue; @try { newCString = OFResizeMemory(newCString, newCStringLength + i - last + replacementLength + 1, 1); } @catch (id e) { OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, i - last); memcpy(newCString + newCStringLength + i - last, replacementString, replacementLength); newCStringLength += i - last + replacementLength; newLength = newLength - string.length + replacement.length; i += searchLength - 1; last = i + 1; } @try { newCString = OFResizeMemory(newCString, newCStringLength + _s->cStringLength - last + 1, 1); } @catch (id e) { OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, _s->cStringLength - last); newCStringLength += _s->cStringLength - last; newCString[newCStringLength] = 0; OFFreeMemory(_s->cString); _s->hasHash = false; _s->cString = newCString; _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)replacement)->_s->isUTF8) _s->isUTF8 = true; } else _s->isUTF8 = true; } - (void)deleteLeadingWhitespaces { size_t i; for (i = 0; i < _s->cStringLength; i++) if (!OFASCIIIsSpace(_s->cString[i])) break; _s->hasHash = false; _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteTrailingWhitespaces { size_t d; char *p; _s->hasHash = false; d = 0; for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) { if (!OFASCIIIsSpace(*p)) break; *p = '\0'; d++; } _s->cStringLength -= d; _s->length -= d; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteEnclosingWhitespaces { size_t d, i; char *p; _s->hasHash = false; d = 0; for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) { if (!OFASCIIIsSpace(*p)) break; *p = '\0'; d++; } _s->cStringLength -= d; _s->length -= d; for (i = 0; i < _s->cStringLength; i++) if (!OFASCIIIsSpace(_s->cString[i])) break; _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)makeImmutable { object_setClass(self, [OFUTF8String class]); } @end |
Modified src/OFMutableZIPArchiveEntry.h from [0cb20b81d1] to [bd5d60ef28].
︙ | ︙ | |||
48 49 50 51 52 53 54 | @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFData *extraField; /** * @brief The version which made the entry. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. | | | > | | > | | | | | | > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | @property OF_NULLABLE_PROPERTY (readwrite, copy, nonatomic) OFData *extraField; /** * @brief The version which made the entry. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readwrite, nonatomic) OFZIPArchiveEntryAttributeCompatibility versionMadeBy; /** * @brief The minimum version required to extract the file. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readwrite, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; /** * @brief The last modification date of the entry's file. * * @note Due to limitations of the ZIP format, this has only 2 second precision. */ @property (readwrite, retain, nonatomic) OFDate *modificationDate; /** * @brief The compression method of the entry. * * Supported values are: * Value | Description * --------------------------------------------|--------------- * OFZIPArchiveEntryCompressionMethodNone | No compression * OFZIPArchiveEntryCompressionMethodDeflate | Deflate * OFZIPArchiveEntryCompressionMethodDeflate64 | Deflate64 * * Other values may be returned, but the file cannot be extracted then. */ @property (readwrite, nonatomic) OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The compressed size of the entry's file. */ @property (readwrite, nonatomic) uint64_t compressedSize; /** |
︙ | ︙ |
Modified src/OFMutableZIPArchiveEntry.m from [1228f4a633] to [fe9804e5f1].
︙ | ︙ | |||
29 30 31 32 33 34 35 | @dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; @dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; @dynamic of_localFileHeaderOffset; - (id)copy { OFMutableZIPArchiveEntry *copy = [self mutableCopy]; | < < | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | @dynamic modificationDate, compressionMethod, compressedSize, uncompressedSize; @dynamic CRC32, versionSpecificAttributes, generalPurposeBitFlag; @dynamic of_localFileHeaderOffset; - (id)copy { OFMutableZIPArchiveEntry *copy = [self mutableCopy]; [copy makeImmutable]; return copy; } - (void)setFileName: (OFString *)fileName { void *pool = objc_autoreleasePoolPush(); OFString *old; |
︙ | ︙ | |||
83 84 85 86 87 88 89 | old = _extraField; _extraField = [extraField copy]; [old release]; objc_autoreleasePoolPop(pool); } | | > | > | > | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | old = _extraField; _extraField = [extraField copy]; [old release]; objc_autoreleasePoolPop(pool); } - (void)setVersionMadeBy: (OFZIPArchiveEntryAttributeCompatibility)versionMadeBy { _versionMadeBy = versionMadeBy; } - (void)setMinVersionNeeded: (OFZIPArchiveEntryAttributeCompatibility)minVersionNeeded { _minVersionNeeded = minVersionNeeded; } - (void)setModificationDate: (OFDate *)date { void *pool = objc_autoreleasePoolPush(); _lastModifiedFileDate = (((date.localYear - 1980) & 0xFF) << 9) | ((date.localMonthOfYear & 0x0F) << 5) | (date.localDayOfMonth & 0x1F); _lastModifiedFileTime = ((date.localHour & 0x1F) << 11) | ((date.localMinute & 0x3F) << 5) | ((date.second >> 1) & 0x0F); objc_autoreleasePoolPop(pool); } - (void)setCompressionMethod: (OFZIPArchiveEntryCompressionMethod)compressionMethod { _compressionMethod = compressionMethod; } - (void)setCompressedSize: (uint64_t)compressedSize { _compressedSize = compressedSize; |
︙ | ︙ |
Modified src/OFMutex.h from [e51e28c02b] to [5dbeab459e].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFLocking.h" | < | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFLocking.h" #import "OFPlainMutex.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFMutex OFMutex.h ObjFW/OFMutex.h * * @brief A class for creating mutual exclusions. */ @interface OFMutex: OFObject <OFLocking> { OFPlainMutex _mutex; bool _initialized; OFString *_Nullable _name; OF_RESERVE_IVARS(OFMutex, 4) } /** * @brief Creates a new mutex. |
︙ | ︙ |
Modified src/OFMutex.m from [8256799039] to [80f846e417].
︙ | ︙ | |||
33 34 35 36 37 38 39 | return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; if (OFPlainMutexNew(&_mutex) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } _initialized = true; return self; } - (void)dealloc { if (_initialized) { int error = OFPlainMutexFree(&_mutex); if (error != 0) { OFEnsure(error == EBUSY); @throw [OFStillLockedException exceptionWithLock: self]; } } [_name release]; [super dealloc]; } - (void)lock { int error = OFPlainMutexLock(&_mutex); if (error != 0) @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } - (bool)tryLock { int error = OFPlainMutexTryLock(&_mutex); if (error != 0) { if (error == EBUSY) return false; else @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } return true; } - (void)unlock { int error = OFPlainMutexUnlock(&_mutex); if (error != 0) @throw [OFUnlockFailedException exceptionWithLock: self errNo: error]; } - (OFString *)description |
︙ | ︙ |
Modified src/OFNonretainedObjectValue.h from [324b0e8add] to [2e9ab2769c].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 | OF_ASSUME_NONNULL_BEGIN @interface OFNonretainedObjectValue: OFValue { id _object; } @end OF_ASSUME_NONNULL_END | > > | 17 18 19 20 21 22 23 24 25 26 27 28 | OF_ASSUME_NONNULL_BEGIN @interface OFNonretainedObjectValue: OFValue { id _object; } - (instancetype)initWithNonretainedObject: (id)object; @end OF_ASSUME_NONNULL_END |
Modified src/OFNonretainedObjectValue.m from [f7aa33cf32] to [5a54c41595].
︙ | ︙ | |||
31 32 33 34 35 36 37 | } - (const char *)objCType { return @encode(id); } | | < | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | } - (const char *)objCType { return @encode(id); } - (void)getValue: (void *)value size: (size_t)size { if (size != sizeof(_object)) @throw [OFOutOfRangeException exception]; memcpy(value, &_object, sizeof(_object)); } |
︙ | ︙ |
Modified src/OFNull.h from [ef78922bc1] to [69babc4028].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" | < | | 10 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 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFJSONRepresentation.h" #import "OFMessagePackRepresentation.h" #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFNull OFNull.h ObjFW/OFNull.h * * @brief A class for representing null values in collections. */ OF_SUBCLASSING_RESTRICTED @interface OFNull: OFObject <OFCopying, OFSerialization, OFJSONRepresentation, OFMessagePackRepresentation> /** * @brief Returns an OFNull singleton. * * @return An OFNull singleton */ + (OFNull *)null; @end |
︙ | ︙ |
Modified src/OFNull.m from [d43d138170] to [56077ec169].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFString.h" #import "OFXMLElement.h" #import "OFData.h" #import "OFInvalidArgumentException.h" @interface OFNull () | | > | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #import "OFString.h" #import "OFXMLElement.h" #import "OFData.h" #import "OFInvalidArgumentException.h" @interface OFNull () - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end static OFNull *null = nil; @implementation OFNull + (void)initialize { |
︙ | ︙ | |||
45 46 47 48 49 50 51 | void *pool; [self release]; pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | void *pool; [self release]; pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; objc_autoreleasePoolPop(pool); return [OFNull null]; } |
︙ | ︙ | |||
69 70 71 72 73 74 75 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className | | | < | > | < | > < | < < < < < < < < < | | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { return @"null"; } - (OFData *)messagePackRepresentation { uint8_t type = 0xC0; return [OFData dataWithItems: &type count: 1]; } - (instancetype)autorelease { return self; } - (instancetype)retain { return self; } - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } - (void)dealloc { OF_DEALLOC_UNSUPPORTED } @end |
Modified src/OFNumber.h from [428bdb0cc8] to [1bc62b5876].
︙ | ︙ | |||
42 43 44 45 46 47 48 | */ #ifndef OF_NUMBER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFNumber: OFValue <OFComparing, OFSerialization, OFJSONRepresentation, OFMessagePackRepresentation> { | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | */ #ifndef OF_NUMBER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFNumber: OFValue <OFComparing, OFSerialization, OFJSONRepresentation, OFMessagePackRepresentation> { union { double float_; long long signed_; unsigned long long unsigned_; } _value; const char *_typeEncoding; } |
︙ | ︙ | |||
125 126 127 128 129 130 131 | @property (readonly, nonatomic) OFString *stringValue; #ifdef OF_HAVE_UNAVAILABLE + (instancetype)valueWithBytes: (const void *)bytes objCType: (const char *)objCType OF_UNAVAILABLE; + (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE; + (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE; | | | | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | @property (readonly, nonatomic) OFString *stringValue; #ifdef OF_HAVE_UNAVAILABLE + (instancetype)valueWithBytes: (const void *)bytes objCType: (const char *)objCType OF_UNAVAILABLE; + (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE; + (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE; + (instancetype)valueWithRange: (OFRange)range OF_UNAVAILABLE; + (instancetype)valueWithPoint: (OFPoint)point OF_UNAVAILABLE; + (instancetype)valueWithSize: (OFSize)size OF_UNAVAILABLE; + (instancetype)valueWithRect: (OFRect)rect OF_UNAVAILABLE; #endif /** * @brief Creates a new OFNumber with the specified `bool`. * * @param value The `bool` value which the OFNumber should contain * @return A new autoreleased OFNumber |
︙ | ︙ | |||
239 240 241 242 243 244 245 | */ + (instancetype)numberWithDouble: (double)value; - (instancetype)init OF_UNAVAILABLE; #ifdef OF_HAVE_UNAVAILABLE - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType OF_UNAVAILABLE; | < < < < < < | 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | */ + (instancetype)numberWithDouble: (double)value; - (instancetype)init OF_UNAVAILABLE; #ifdef OF_HAVE_UNAVAILABLE - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType OF_UNAVAILABLE; #endif /** * @brief Initializes an already allocated OFNumber with the specified `bool`. * * @param value The `bool` value which the OFNumber should contain * @return An initialized OFNumber |
︙ | ︙ | |||
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 | /** * @brief Initializes an already allocated OFNumber with the specified `double`. * * @param value The `double` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithDouble: (double)value; @end OF_ASSUME_NONNULL_END #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for number literals to work */ @compatibility_alias NSNumber OFNumber; #endif | > > > > > > > > | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | /** * @brief Initializes an already allocated OFNumber with the specified `double`. * * @param value The `double` value which the OFNumber should contain * @return An initialized OFNumber */ - (instancetype)initWithDouble: (double)value; /** * @brief Compares the number to another number. * * @param number The number to compare the number to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFNumber *)number; @end OF_ASSUME_NONNULL_END #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for number literals to work */ @compatibility_alias NSNumber OFNumber; #endif |
Modified src/OFNumber.m from [92fb9ca7c6] to [34d1acfa38].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @interface OFNumber () + (instancetype)of_alloc; | | > | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 | #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" @interface OFNumber () + (instancetype)of_alloc; - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFNumberPlaceholder: OFNumber @end @interface OFNumberSingleton: OFNumber @end #ifdef OF_OBJFW_RUNTIME enum Tag { tagChar, tagShort, tagInt, tagLong, tagLongLong, tagUnsignedChar, tagUnsignedShort, tagUnsignedInt, tagUnsignedLong, tagUnsignedLongLong, }; static const uint_fast8_t tagBits = 4; static const uintptr_t tagMask = 0xF; @interface OFTaggedPointerNumber: OFNumberSingleton @end #endif static struct { Class isa; |
︙ | ︙ | |||
146 147 148 149 150 151 152 | } } @implementation OFNumberPlaceholder - (instancetype)initWithBool: (bool)value { if (value) { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | } } @implementation OFNumberPlaceholder - (instancetype)initWithBool: (bool)value { if (value) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, trueNumberInit); return (id)trueNumber; } else { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, falseNumberInit); return (id)falseNumber; } } #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare" #endif - (instancetype)initWithChar: (signed char)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, charZeroNumberInit); return (id)charZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned char)value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned char)value << tagBits) | tagChar); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithChar: value]; } - (instancetype)initWithShort: (short)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, shortZeroNumberInit); return (id)shortZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned short)value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned short)value << tagBits) | tagShort); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithShort: value]; } - (instancetype)initWithInt: (int)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, intZeroNumberInit); return (id)intZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned int)value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned int)value << tagBits) | tagInt); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithInt: value]; } - (instancetype)initWithLong: (long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, longZeroNumberInit); return (id)longZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned long)value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned long)value << tagBits) | tagLong); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithLong: value]; } - (instancetype)initWithLongLong: (long long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, longLongZeroNumberInit); return (id)longLongZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if ((unsigned long long)value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)(unsigned long long)value << tagBits) | tagLongLong); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithLongLong: value]; } - (instancetype)initWithUnsignedChar: (unsigned char)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedCharZeroNumberInit); return (id)unsignedCharZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)value << tagBits) | tagUnsignedChar); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithUnsignedChar: value]; } - (instancetype)initWithUnsignedShort: (unsigned short)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedShortZeroNumberInit); return (id)unsignedShortZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)value << tagBits) | tagUnsignedShort); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithUnsignedShort: value]; } - (instancetype)initWithUnsignedInt: (unsigned int)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedIntZeroNumberInit); return (id)unsignedIntZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)value << tagBits) | tagUnsignedInt); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithUnsignedInt: value]; } - (instancetype)initWithUnsignedLong: (unsigned long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedLongZeroNumberInit); return (id)unsignedLongZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)value << tagBits) | tagUnsignedLong); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithUnsignedLong: value]; } - (instancetype)initWithUnsignedLongLong: (unsigned long long)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, unsignedLongLongZeroNumberInit); return (id)unsignedLongLongZeroNumber; #ifdef OF_OBJFW_RUNTIME } else if (value <= (UINTPTR_MAX >> tagBits)) { id ret = objc_createTaggedPointer(numberTag, ((uintptr_t)value << tagBits) | tagUnsignedLongLong); if (ret != nil) return ret; #endif } return (id)[[OFNumber of_alloc] initWithUnsignedLongLong: value]; } - (instancetype)initWithFloat: (float)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, floatZeroNumberInit); return (id)floatZeroNumber; } return (id)[[OFNumber of_alloc] initWithFloat: value]; } - (instancetype)initWithDouble: (double)value { if (value == 0) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, doubleZeroNumberInit); return (id)doubleZeroNumber; } return (id)[[OFNumber of_alloc] initWithDouble: value]; } - (instancetype)initWithSerialization: (OFXMLElement *)element |
︙ | ︙ | |||
399 400 401 402 403 404 405 | - (void)release { } - (unsigned int)retainCount { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } @end #ifdef OF_OBJFW_RUNTIME @implementation OFTaggedPointerNumber - (const char *)objCType { uintptr_t value = object_getTaggedPointerValue(self); switch (value & tagMask) { case tagChar: return @encode(signed char); case tagShort: return @encode(short); case tagInt: return @encode(int); case tagLong: return @encode(long); case tagLongLong: return @encode(long long); case tagUnsignedChar: return @encode(unsigned char); case tagUnsignedShort: return @encode(unsigned short); case tagUnsignedInt: return @encode(unsigned int); case tagUnsignedLong: return @encode(unsigned long); case tagUnsignedLongLong: return @encode(unsigned long long); default: @throw [OFInvalidArgumentException exception]; } } # define RETURN_VALUE \ uintptr_t value = object_getTaggedPointerValue(self); \ \ switch (value & tagMask) { \ case tagChar: \ return (signed char)(unsigned char)(value >> tagBits); \ case tagShort: \ return (short)(unsigned short)(value >> tagBits); \ case tagInt: \ return (int)(unsigned int)(value >> tagBits); \ case tagLong: \ return (long)(unsigned long)(value >> tagBits); \ case tagLongLong: \ return (long long)(unsigned long long)(value >> tagBits); \ case tagUnsignedChar: \ return (unsigned char)(value >> tagBits); \ case tagUnsignedShort: \ return (unsigned short)(value >> tagBits); \ case tagUnsignedInt: \ return (unsigned int)(value >> tagBits); \ case tagUnsignedLong: \ return (unsigned long)(value >> tagBits); \ case tagUnsignedLongLong: \ return (unsigned long long)(value >> tagBits); \ default: \ @throw [OFInvalidArgumentException exception]; \ } - (long long)longLongValue { RETURN_VALUE } - (unsigned long long)unsignedLongLongValue |
︙ | ︙ | |||
746 747 748 749 750 751 752 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![element.name isEqual: @"OFNumber"] || | | | | | 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![element.name isEqual: @"OFNumber"] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; typeString = [element attributeForName: @"type"].stringValue; if ([typeString isEqual: @"bool"]) { OFString *stringValue = element.stringValue; if ([stringValue isEqual: @"true"]) self = [self initWithBool: true]; else if ([stringValue isEqual: @"false"]) self = [self initWithBool: false]; else @throw [OFInvalidArgumentException exception]; } else if ([typeString isEqual: @"float"]) { unsigned long long value = [element unsignedLongLongValueWithBase: 16]; if (value > UINT64_MAX) @throw [OFOutOfRangeException exception]; self = [self initWithDouble: OFFromBigEndianDouble( OFRawUInt64ToDouble(OFToBigEndian64(value)))]; } else if ([typeString isEqual: @"signed"]) self = [self initWithLongLong: element.longLongValue]; else if ([typeString isEqual: @"unsigned"]) self = [self initWithUnsignedLongLong: element.unsignedLongLongValue]; else @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
790 791 792 793 794 795 796 | } - (const char *)objCType { return _typeEncoding; } | | < | 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 | } - (const char *)objCType { return _typeEncoding; } - (void)getValue: (void *)value size: (size_t)size { switch (*self.objCType) { #define CASE(enc, type, property) \ case enc: { \ type tmp = (type)self.property; \ \ if (size != sizeof(type)) \ |
︙ | ︙ | |||
939 940 941 942 943 944 945 | if (isSigned(self) || isSigned(number)) return (number.longLongValue == self.longLongValue); return (number.unsignedLongLongValue == self.unsignedLongLongValue); } | < < | | | < < | | | | | | | | | | | | | | | | 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 | if (isSigned(self) || isSigned(number)) return (number.longLongValue == self.longLongValue); return (number.unsignedLongLongValue == self.unsignedLongLongValue); } - (OFComparisonResult)compare: (OFNumber *)number { if (![number isKindOfClass: [OFNumber class]]) @throw [OFInvalidArgumentException exception]; if (isFloat(self) || isFloat(number)) { double double1 = self.doubleValue; double double2 = number.doubleValue; if (double1 > double2) return OFOrderedDescending; if (double1 < double2) return OFOrderedAscending; return OFOrderedSame; } else if (isSigned(self) || isSigned(number)) { long long int1 = self.longLongValue; long long int2 = number.longLongValue; if (int1 > int2) return OFOrderedDescending; if (int1 < int2) return OFOrderedAscending; return OFOrderedSame; } else { unsigned long long uint1 = self.unsignedLongLongValue; unsigned long long uint2 = number.unsignedLongLongValue; if (uint1 > uint2) return OFOrderedDescending; if (uint1 < uint2) return OFOrderedAscending; return OFOrderedSame; } } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); if (isFloat(self)) { double d; if (isnan(self.doubleValue)) return 0; d = OFToLittleEndianDouble(self.doubleValue); for (uint_fast8_t i = 0; i < sizeof(double); i++) OFHashAdd(&hash, ((char *)&d)[i]); } else if (isSigned(self) || isUnsigned(self)) { unsigned long long value = self.unsignedLongLongValue; while (value != 0) { OFHashAdd(&hash, value & 0xFF); value >>= 8; } } else @throw [OFInvalidFormatException exception]; OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; |
︙ | ︙ | |||
1043 1044 1045 1046 1047 1048 1049 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFNumber" | | | < | < < > | < | < | > | < | > | | < | < | | < < | < | | < < | < | < | < < | | < < | < | | < < | < | | < < | < < | < | < < | | < < | < | | < < | < | | < < | < | 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: @"OFNumber" namespace: OFSerializationNS stringValue: self.description]; if (*self.objCType == 'B') [element addAttributeWithName: @"type" stringValue: @"bool"]; else if (isFloat(self)) { [element addAttributeWithName: @"type" stringValue: @"float"]; element.stringValue = [OFString stringWithFormat: @"%016" PRIx64, OFFromBigEndian64(OFDoubleToRawUInt64(OFToBigEndianDouble( self.doubleValue)))]; } else if (isSigned(self)) [element addAttributeWithName: @"type" stringValue: @"signed"]; else if (isUnsigned(self)) [element addAttributeWithName: @"type" stringValue: @"unsigned"]; else @throw [OFInvalidFormatException exception]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { double doubleValue; if (*self.objCType == 'B') return (self.boolValue ? @"true" : @"false"); doubleValue = self.doubleValue; if (isinf(doubleValue)) { if (options & OFJSONRepresentationOptionJSON5) { if (doubleValue > 0) return @"Infinity"; else return @"-Infinity"; } else @throw [OFInvalidArgumentException exception]; } return self.description; } - (OFData *)messagePackRepresentation { OFMutableData *data; const char *typeEncoding = self.objCType; if (*typeEncoding == 'B') { uint8_t type = (self.boolValue ? 0xC3 : 0xC2); data = [OFMutableData dataWithItems: &type count: 1]; } else if (*typeEncoding == 'f') { uint8_t type = 0xCA; float tmp = OFToBigEndianFloat(self.floatValue); data = [OFMutableData dataWithCapacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (*typeEncoding == 'd') { uint8_t type = 0xCB; double tmp = OFToBigEndianDouble(self.doubleValue); data = [OFMutableData dataWithCapacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (isSigned(self)) { long long value = self.longLongValue; if (value >= -32 && value < 0) { uint8_t tmp = 0xE0 | ((uint8_t)(value - 32) & 0x1F); data = [OFMutableData dataWithItems: &tmp count: 1]; } else if (value >= INT8_MIN && value <= INT8_MAX) { uint8_t type = 0xD0; int8_t tmp = (int8_t)value; data = [OFMutableData dataWithCapacity: 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (value >= INT16_MIN && value <= INT16_MAX) { uint8_t type = 0xD1; int16_t tmp = OFToBigEndian16((int16_t)value); data = [OFMutableData dataWithCapacity: 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value >= INT32_MIN && value <= INT32_MAX) { uint8_t type = 0xD2; int32_t tmp = OFToBigEndian32((int32_t)value); data = [OFMutableData dataWithCapacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value >= INT64_MIN && value <= INT64_MAX) { uint8_t type = 0xD3; int64_t tmp = OFToBigEndian64((int64_t)value); data = [OFMutableData dataWithCapacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } else if (isUnsigned(self)) { unsigned long long value = self.unsignedLongLongValue; if (value <= 127) { uint8_t tmp = ((uint8_t)value & 0x7F); data = [OFMutableData dataWithItems: &tmp count: 1]; } else if (value <= UINT8_MAX) { uint8_t type = 0xCC; uint8_t tmp = (uint8_t)value; data = [OFMutableData dataWithCapacity: 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (value <= UINT16_MAX) { uint8_t type = 0xCD; uint16_t tmp = OFToBigEndian16((uint16_t)value); data = [OFMutableData dataWithCapacity: 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value <= UINT32_MAX) { uint8_t type = 0xCE; uint32_t tmp = OFToBigEndian32((uint32_t)value); data = [OFMutableData dataWithCapacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value <= UINT64_MAX) { uint8_t type = 0xCF; uint64_t tmp = OFToBigEndian64((uint64_t)value); data = [OFMutableData dataWithCapacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; } else @throw [OFInvalidFormatException exception]; [data makeImmutable]; return data; } @end |
Modified src/OFObject+KeyValueCoding.m from [2a9a3f450d] to [3bfea8ea41].
︙ | ︙ | |||
44 45 46 47 48 49 50 | char *name; if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } | | | | | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | char *name; if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } name = OFAllocMemory(keyLength + 3, 1); @try { memcpy(name, "is", 2); memcpy(name + 2, key.UTF8String, keyLength); name[keyLength + 2] = '\0'; name[2] = OFASCIIToUpper(name[2]); selector = sel_registerName(name); } @finally { OFFreeMemory(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == NULL) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; |
︙ | ︙ | |||
135 136 137 138 139 140 141 | objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (id)valueForUndefinedKey: (OFString *)key { | | < | < < | | | | < | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (id)valueForUndefinedKey: (OFString *)key { @throw [OFUndefinedKeyException exceptionWithObject: self key: key]; } - (void)setValue: (id)value forKey: (OFString *)key { void *pool = objc_autoreleasePoolPush(); size_t keyLength; char *name; SEL selector; OFMethodSignature *methodSignature; const char *valueType; if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } name = OFAllocMemory(keyLength + 5, 1); @try { memcpy(name, "set", 3); memcpy(name + 3, key.UTF8String, keyLength); memcpy(name + keyLength + 3, ":", 2); name[3] = OFASCIIToUpper(name[3]); selector = sel_registerName(name); } @finally { OFFreeMemory(name); } methodSignature = [self methodSignatureForSelector: selector]; if (methodSignature == nil || methodSignature.numberOfArguments != 3 || *methodSignature.methodReturnType != 'v' || *[methodSignature argumentTypeAtIndex: 0] != '@' || *[methodSignature argumentTypeAtIndex: 1] != ':') { objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } valueType = [methodSignature argumentTypeAtIndex: 2]; if (*valueType != '@' && *valueType != '#' && value == nil) { objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
224 225 226 227 228 229 230 | CASE('L', unsigned long, unsignedLongValue) CASE('Q', unsigned long long, unsignedLongLongValue) CASE('f', float, floatValue) CASE('d', double, doubleValue) #undef CASE default: objc_autoreleasePoolPop(pool); | < | | < | < | < | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | CASE('L', unsigned long, unsignedLongValue) CASE('Q', unsigned long long, unsignedLongLongValue) CASE('f', float, floatValue) CASE('d', double, doubleValue) #undef CASE default: objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } objc_autoreleasePoolPop(pool); } - (void)setValue: (id)value forKeyPath: (OFString *)keyPath { void *pool = objc_autoreleasePoolPush(); OFArray *keys = [keyPath componentsSeparatedByString: @"."]; size_t keysCount = keys.count; id object = self; size_t i = 0; for (OFString *key in keys) { if (++i == keysCount) [object setValue: value forKey: key]; else object = [object valueForKey: key]; } objc_autoreleasePoolPop(pool); } - (void)setValue: (id)value forUndefinedKey: (OFString *)key { @throw [OFUndefinedKeyException exceptionWithObject: self key: key value: value]; } - (void)setNilValueForKey: (OFString *)key { @throw [OFInvalidArgumentException exception]; } @end |
Modified src/OFObject+Serialization.m from [fe806a8af4] to [4ae1aec1cc].
︙ | ︙ | |||
38 39 40 41 42 43 44 | abort(); } pool = objc_autoreleasePoolPush(); element = ((id <OFSerialization>)self).XMLElementBySerializing; root = [OFXMLElement elementWithName: @"serialization" | | | < | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | abort(); } pool = objc_autoreleasePoolPush(); element = ((id <OFSerialization>)self).XMLElementBySerializing; root = [OFXMLElement elementWithName: @"serialization" namespace: OFSerializationNS]; [root addAttributeWithName: @"version" stringValue: @"1"]; [root addChild: element]; ret = [@"<?xml version='1.0' encoding='UTF-8'?>\n" stringByAppendingString: [root XMLStringWithIndentation: 2]]; [ret retain]; |
︙ | ︙ |
Modified src/OFObject.h from [a9ac62cb9b] to [9706bbf5bc].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #endif #include <stddef.h> #include <stdint.h> #include <stdbool.h> #include <limits.h> | | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #endif #include <stddef.h> #include <stdint.h> #include <stdbool.h> #include <limits.h> #include "macros.h" #include "OFOnce.h" /* * Some versions of MinGW require <winsock2.h> to be included before * <windows.h>. Do this here to make sure this is always done in the correct * order, even if another header includes just <windows.h>. */ #ifdef __MINGW32__ |
︙ | ︙ | |||
52 53 54 55 56 57 58 | /** @file */ /** * @brief A result of a comparison. */ typedef enum { /** The left object is smaller than the right */ | | | | | < | | | > > | > > > > | | | < | | | | | | | | | | < | | | | | | | | | | | | | < | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | | > | | < | < > | | > > > | > | > | < < | | < | < > | | | < | < | | < < | < > > | < > > > < < > | < | > | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | /** @file */ /** * @brief A result of a comparison. */ typedef enum { /** The left object is smaller than the right */ OFOrderedAscending = -1, /** Both objects are equal */ OFOrderedSame = 0, /** The left object is bigger than the right */ OFOrderedDescending = 1 } OFComparisonResult; #ifdef OF_HAVE_BLOCKS /** * @brief A comparator to compare two objects. * * @param left The left object * @param right The right object * @return The order of the objects */ typedef OFComparisonResult (^OFComparator)(id _Nonnull left, id _Nonnull right); #endif /** * @brief An enum for representing endianess. */ typedef enum { /** Most significant byte first (big endian) */ OFByteOrderBigEndian, /** Least significant byte first (little endian) */ OFByteOrderLittleEndian, /** Native byte order of the system */ #ifdef OF_BIG_ENDIAN OFByteOrderNative = OFByteOrderBigEndian #else OFByteOrderNative = OFByteOrderLittleEndian #endif } OFByteOrder; /** * @struct OFRange OFObject.h ObjFW/OFObject.h * * @brief A range. */ typedef struct OF_BOXABLE { /** The start of the range */ size_t location; /** The length of the range */ size_t length; } OFRange; /** * @brief Creates a new OFRange. * * @param start The starting index of the range * @param length The length of the range * @return An OFRangeith the specified start and length */ static OF_INLINE OFRange OF_CONST_FUNC OFRangeMake(size_t start, size_t length) { OFRange range = { start, length }; return range; } /** * @brief Returns whether the two ranges are equal. * * @param range1 The first range for the comparison * @param range2 The second range for the comparison * @return Whether the two ranges are equal */ static OF_INLINE bool OFRangeEqual(OFRange range1, OFRange range2) { if (range1.location != range2.location) return false; if (range1.length != range2.length) return false; return true; } /** * @brief A time interval in seconds. */ typedef double OFTimeInterval; /** * @struct OFPoint OFObject.h ObjFW/OFObject.h * * @brief A point. */ typedef struct OF_BOXABLE { /** The x coordinate of the point */ float x; /** The y coordinate of the point */ float y; } OFPoint; /** * @brief Creates a new OFPoint. * * @param x The x coordinate of the point * @param y The x coordinate of the point * @return An OFPoint with the specified coordinates */ static OF_INLINE OFPoint OF_CONST_FUNC OFPointMake(float x, float y) { OFPoint point = { x, y }; return point; } /** * @brief Returns whether the two points are equal. * * @param point1 The first point for the comparison * @param point2 The second point for the comparison * @return Whether the two points are equal */ static OF_INLINE bool OFPointEqual(OFPoint point1, OFPoint point2) { if (point1.x != point2.x) return false; if (point1.y != point2.y) return false; return true; } /** * @struct OFSize OFObject.h ObjFW/OFObject.h * * @brief A size. */ typedef struct OF_BOXABLE { /** The width of the size */ float width; /** The height of the size */ float height; } OFSize; /** * @brief Creates a new OFSize. * * @param width The width of the size * @param height The height of the size * @return An OFSize with the specified width and height */ static OF_INLINE OFSize OF_CONST_FUNC OFSizeMake(float width, float height) { OFSize size = { width, height }; return size; } /** * @brief Returns whether the two sizes are equal. * * @param size1 The first size for the comparison * @param size2 The second size for the comparison * @return Whether the two sizes are equal */ static OF_INLINE bool OFSizeEqual(OFSize size1, OFSize size2) { if (size1.width != size2.width) return false; if (size1.height != size2.height) return false; return true; } /** * @struct OFRect OFObject.h ObjFW/OFObject.h * * @brief A rectangle. */ typedef struct OF_BOXABLE { /** The point from where the rectangle originates */ OFPoint origin; /** The size of the rectangle */ OFSize size; } OFRect; /** * @brief Creates a new OFRect. * * @param x The x coordinate of the top left corner of the rectangle * @param y The y coordinate of the top left corner of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * @return An OFRect with the specified origin and size */ static OF_INLINE OFRect OF_CONST_FUNC OFRectMake(float x, float y, float width, float height) { OFRect rect = { OFPointMake(x, y), OFSizeMake(width, height) }; return rect; } /** * @brief Returns whether the two rectangles are equal. * * @param rect1 The first rectangle for the comparison * @param rect2 The second rectangle for the comparison * @return Whether the two rectangles are equal */ static OF_INLINE bool OFRectEqual(OFRect rect1, OFRect rect2) { if (!OFPointEqual(rect1.origin, rect2.origin)) return false; if (!OFSizeEqual(rect1.size, rect2.size)) return false; return true; } /** * @brief Adds the specified byte to the hash. * * @param hash A pointer to a hash to add the byte to * @param byte The byte to add to the hash */ static OF_INLINE void OFHashAdd(unsigned long *_Nonnull hash, unsigned char byte) { uint32_t tmp = (uint32_t)*hash; tmp += byte; tmp += tmp << 10; tmp ^= tmp >> 6; *hash = tmp; } /** * @brief Adds the specified hash to the hash. * * @param hash A pointer to a hash to add the hash to * @param otherHash The hash to add to the hash */ static OF_INLINE void OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash) { OFHashAdd(hash, (otherHash >> 24) & 0xFF); OFHashAdd(hash, (otherHash >> 16) & 0xFF); OFHashAdd(hash, (otherHash >> 8) & 0xFF); OFHashAdd(hash, otherHash & 0xFF); } /** * @brief Finalizes the specified hash. * * @param hash A pointer to the hash to finalize */ static OF_INLINE void OFHashFinalize(unsigned long *_Nonnull hash) { uint32_t tmp = (uint32_t)*hash; tmp += tmp << 3; tmp ^= tmp >> 11; tmp += tmp << 15; *hash = tmp; } static const size_t OFNotFound = SIZE_MAX; #ifdef __OBJC__ @class OFMethodSignature; @class OFString; @class OFThread; /** |
︙ | ︙ | |||
397 398 399 400 401 402 403 | * @brief Performs the specified selector with the specified object. * * @param selector The selector to perform * @param object The object that is passed to the method specified by the * selector * @return The object returned by the method specified by the selector */ | | < | 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | * @brief Performs the specified selector with the specified object. * * @param selector The selector to perform * @param object The object that is passed to the method specified by the * selector * @return The object returned by the method specified by the selector */ - (nullable id)performSelector: (SEL)selector withObject: (nullable id)object; /** * @brief Performs the specified selector with the specified objects. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector |
︙ | ︙ | |||
573 574 575 576 577 578 579 | /** * @brief A method which is called when the class is unloaded from the runtime. * * Derived classes can override this to execute their own code when the class * is unloaded. * * @warning This is not supported by the Apple runtime and currently only | | < | | 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | /** * @brief A method which is called when the class is unloaded from the runtime. * * Derived classes can override this to execute their own code when the class * is unloaded. * * @warning This is not supported by the Apple runtime and currently only * called by the ObjFW runtime when @ref objc_deinit has been called! * In the future, this might also be called by the ObjFW runtime when * the class is part of a plugin that is being unloaded. */ + (void)unload; /** * @brief A method which is called the moment before the first call to the class * is being made. * |
︙ | ︙ | |||
815 816 817 818 819 820 821 | /** * @brief Performs the specified selector after the specified delay. * * @param selector The selector to perform * @param delay The delay after which the selector will be performed */ | | < | | | | 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 | /** * @brief Performs the specified selector after the specified delay. * * @param selector The selector to perform * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified object after the * specified delay. * * @param selector The selector to perform * @param object The object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified objects after the * specified delay. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified objects after the * specified delay. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector with the specified objects after the * specified delay. * * @param selector The selector to perform * @param object1 The first object that is passed to the method specified by the |
︙ | ︙ | |||
886 887 888 889 890 891 892 | * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 | | | 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 afterDelay: (OFTimeInterval)delay; # ifdef OF_HAVE_THREADS /** * @brief Performs the specified selector on the specified thread. * * @param selector The selector to perform * @param thread The thread on which to perform the selector |
︙ | ︙ | |||
1067 1068 1069 1070 1071 1072 1073 | * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread | | | | | | 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 | * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified object after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object The object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified objects after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified objects after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector * @param object1 The first object that is passed to the method specified by the * selector * @param object2 The second object that is passed to the method specified by * the selector * @param object3 The third object that is passed to the method specified by the * selector * @param delay The delay after which the selector will be performed */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 afterDelay: (OFTimeInterval)delay; /** * @brief Performs the specified selector on the specified thread with the * specified objects after the specified delay. * * @param selector The selector to perform * @param thread The thread on which to perform the selector |
︙ | ︙ | |||
1145 1146 1147 1148 1149 1150 1151 | */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 | | | 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 | */ - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (nullable id)object1 withObject: (nullable id)object2 withObject: (nullable id)object3 withObject: (nullable id)object4 afterDelay: (OFTimeInterval)delay; # endif /** * @brief This method is called when @ref resolveClassMethod: or * @ref resolveInstanceMethod: returned false. It should return a target * to which the message should be forwarded. * |
︙ | ︙ | |||
1216 1217 1218 1219 1220 1221 1222 | @end /** * @protocol OFComparing OFObject.h ObjFW/OFObject.h * * @brief A protocol for comparing objects. * | | | | | | | | | | > > > > > > > > > | | | | > > > > > | | > > > > > | | < > > > | > | | > > > > > | > > | 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 | @end /** * @protocol OFComparing OFObject.h ObjFW/OFObject.h * * @brief A protocol for comparing objects. * * This protocol is implemented by objects that can be compared. Its only method, @ref compare:, should be overridden with a stronger type. */ @protocol OFComparing /** * @brief Compares the object to another object. * * @param object An object to compare the object to * @return The result of the comparison */ - (OFComparisonResult)compare: (id <OFComparing>)object; @end #endif #ifdef __cplusplus extern "C" { #endif /** * @brief Allocates memory for the specified number of items of the specified * size. * * To free the allocated memory, use @ref OFFreeMemory. * * Throws @ref OFOutOfMemoryException if allocating failed and * @ref OFOutOfRangeException if the requested size exceeds the address space. * * @param count The number of items to allocate * @param size The size of each item to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. */ extern void *_Nullable OFAllocMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Allocates memory for the specified number of items of the specified * size and initializes it with zeros. * * To free the allocated memory, use @ref OFFreeMemory. * * Throws @ref OFOutOfMemoryException if allocating failed and * @ref OFOutOfRangeException if the requested size exceeds the address space. * * @param size The size of each item to allocate * @param count The number of items to allocate * @return A pointer to the allocated memory. May return NULL if the specified * size or count is 0. */ extern void *_Nullable OFAllocZeroedMemory(size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Resizes memory to the specified number of items of the specified size. * * To free the allocated memory, use @ref OFFreeMemory. * * If the pointer is NULL, this is equivalent to allocating memory. * If the size or number of items is 0, this is equivalent to freeing memory. * * Throws @ref OFOutOfMemoryException if allocating failed and * @ref OFOutOfRangeException if the requested size exceeds the address space. * * @param pointer A pointer to the already allocated memory * @param size The size of each item to resize to * @param count The number of items to resize to * @return A pointer to the resized memory chunk */ extern void *_Nullable OFResizeMemory(void *_Nullable pointer, size_t count, size_t size) OF_WARN_UNUSED_RESULT; /** * @brief Frees memory allocated by @ref OFAllocMemory, @ref OFAllocZeroedMemory * or @ref OFResizeMemory. * * @param pointer A pointer to the memory to free or nil (passing nil ooes * nothing) */ extern void OFFreeMemory(void *_Nullable pointer); #ifdef OF_APPLE_RUNTIME extern void *_Null_unspecified objc_autoreleasePoolPush(void); extern void objc_autoreleasePoolPop(void *_Null_unspecified pool); # ifndef __OBJC2__ extern id _Nullable objc_constructInstance(Class _Nullable class_, void *_Nullable bytes); extern void *_Nullable objc_destructInstance(id _Nullable object); # endif #endif extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment, void *_Nullable *_Nullable extra); extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd); /** * @brief Initializes the specified hash. * * @param hash A pointer to the hash to initialize */ extern void OFHashInit(unsigned long *_Nonnull hash); /** * @brief Returns 16 bit or non-cryptographical randomness. * * @return 16 bit or non-cryptographical randomness */ extern uint16_t OFRandom16(void); /** * @brief Returns 32 bit or non-cryptographical randomness. * * @return 32 bit or non-cryptographical randomness */ extern uint32_t OFRandom32(void); /** * @brief Returns 64 bit or non-cryptographical randomness. * * @return 64 bit or non-cryptographical randomness */ extern uint64_t OFRandom64(void); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #include "OFBlock.h" #ifdef __OBJC__ # import "OFObject+KeyValueCoding.h" # import "OFObject+Serialization.h" #endif #endif |
Modified src/OFObject.m from [a0e6d07e6b] to [77711da280].
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | #ifdef HAVE_GETRANDOM # include <sys/random.h> #endif #import "OFObject.h" #import "OFArray.h" #import "OFLocale.h" #import "OFMethodSignature.h" #import "OFRunLoop.h" #import "OFThread.h" #import "OFTimer.h" #import "OFAllocFailedException.h" #import "OFEnumerationMutationException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" | > > > > > > > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #ifdef HAVE_GETRANDOM # include <sys/random.h> #endif #import "OFObject.h" #import "OFArray.h" #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #import "OFLocale.h" #import "OFMethodSignature.h" #import "OFRunLoop.h" #if !defined(OF_HAVE_ATOMIC_OPS) && defined(OF_HAVE_THREADS) # import "OFPlainMutex.h" /* For OFSpinlock */ #endif #import "OFString.h" #import "OFThread.h" #import "OFTimer.h" #import "OFAllocFailedException.h" #import "OFEnumerationMutationException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" |
︙ | ︙ | |||
56 57 58 59 60 61 62 | # include <windows.h> #endif #ifdef OF_AMIGAOS # include <proto/exec.h> #endif | < < < < < < < < | | | | | | | | < < < | < < > | | | | | > > > > > > | | < | | | | | | | | > > > > > > | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | # include <windows.h> #endif #ifdef OF_AMIGAOS # include <proto/exec.h> #endif #ifdef OF_APPLE_RUNTIME extern id _Nullable _objc_rootAutorelease(id _Nullable object); #endif #if defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR) extern id OFForward(id, SEL, ...); extern struct Stret OFForward_stret(id, SEL, ...); #else # define OFForward OFMethodNotFound # define OFForward_stret OFMethodNotFound_stret #endif struct PreIvars { int retainCount; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlock retainCountSpinlock; #endif }; #define PRE_IVARS_ALIGN ((sizeof(struct PreIvars) + \ (OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1)) #define PRE_IVARS ((struct PreIvars *)(void *)((char *)self - PRE_IVARS_ALIGN)) static struct { Class isa; } allocFailedException; unsigned long OFHashSeed; #ifdef OF_AMIGAOS unsigned long * OFHashSeedRef(void) { return &OFHashSeed; } #endif void * OFAllocMemory(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; if OF_UNLIKELY (count > SIZE_MAX / size) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((pointer = malloc(count * size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; return pointer; } void * OFAllocZeroedMemory(size_t count, size_t size) { void *pointer; if OF_UNLIKELY (count == 0 || size == 0) return NULL; /* Not all calloc implementations check for overflow. */ if OF_UNLIKELY (count > SIZE_MAX / size) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((pointer = calloc(count, size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; return pointer; } void * OFResizeMemory(void *pointer, size_t count, size_t size) { if OF_UNLIKELY (count == 0 || size == 0) return NULL; if OF_UNLIKELY (count > SIZE_MAX / size) @throw [OFOutOfRangeException exception]; if OF_UNLIKELY ((pointer = realloc(pointer, count * size)) == NULL) @throw [OFOutOfMemoryException exceptionWithRequestedSize: size]; return pointer; } void OFFreeMemory(void *pointer) { free(pointer); } #if !defined(HAVE_ARC4RANDOM) && !defined(HAVE_GETRANDOM) static void initRandom(void) { struct timeval tv; # ifdef HAVE_RANDOM gettimeofday(&tv, NULL); srandom((unsigned)(tv.tv_sec ^ tv.tv_usec)); # else gettimeofday(&tv, NULL); srand((unsigned)(tv.tv_sec ^ tv.tv_usec)); # endif } #endif uint16_t OFRandom16(void) { #if defined(HAVE_ARC4RANDOM) return arc4random(); #elif defined(HAVE_GETRANDOM) uint16_t buffer; OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer)); return buffer; #else static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initRandom); # ifdef HAVE_RANDOM return random() & 0xFFFF; # else return rand() & 0xFFFF; # endif #endif } uint32_t OFRandom32(void) { #if defined(HAVE_ARC4RANDOM) return arc4random(); #elif defined(HAVE_GETRANDOM) uint32_t buffer; OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer)); return buffer; #else return ((uint32_t)OFRandom16() << 16) | OFRandom16(); #endif } uint64_t OFRandom64(void) { #if defined(HAVE_ARC4RANDOM_BUF) uint64_t buffer; arc4random_buf(&buffer, sizeof(buffer)); return buffer; #elif defined(HAVE_GETRANDOM) uint64_t buffer; OFEnsure(getrandom(&buffer, sizeof(buffer), 0) == sizeof(buffer)); return buffer; #else return ((uint64_t)OFRandom32() << 32) | OFRandom32(); #endif } void OFHashInit(unsigned long *hash) { *hash = OFHashSeed; } static const char * typeEncodingForSelector(Class class, SEL selector) { Method method; if ((method = class_getInstanceMethod(class, selector)) == NULL) return NULL; return method_getTypeEncoding(method); } #if !defined(OF_APPLE_RUNTIME) || defined(__OBJC2__) static void uncaughtExceptionHandler(id exception) { OFString *description = [exception description]; OFArray *backtrace = nil; OFStringEncoding encoding = [OFLocale encoding]; fprintf(stderr, "\nRuntime error: Unhandled exception:\n%s\n", [description cStringWithEncoding: encoding]); if ([exception respondsToSelector: @selector(backtrace)]) backtrace = [exception backtrace]; |
︙ | ︙ | |||
274 275 276 277 278 279 280 | static void enumerationMutationHandler(id object) { @throw [OFEnumerationMutationException exceptionWithObject: object]; } void OF_NO_RETURN_FUNC | | | | | | | | | 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | static void enumerationMutationHandler(id object) { @throw [OFEnumerationMutationException exceptionWithObject: object]; } void OF_NO_RETURN_FUNC OFMethodNotFound(id object, SEL selector) { [object doesNotRecognizeSelector: selector]; /* * Just in case doesNotRecognizeSelector: returned, even though it must * never return. */ abort(); OF_UNREACHABLE } void OF_NO_RETURN_FUNC OFMethodNotFound_stret(void *stret, id object, SEL selector) { OFMethodNotFound(object, selector); } id OFAllocObject(Class class, size_t extraSize, size_t extraAlignment, void **extra) { OFObject *instance; size_t instanceSize; instanceSize = class_getInstanceSize(class); if OF_UNLIKELY (extraAlignment > 1) extraAlignment = ((instanceSize + extraAlignment - 1) & ~(extraAlignment - 1)) - extraAlignment; instance = calloc(1, PRE_IVARS_ALIGN + instanceSize + extraAlignment + extraSize); if OF_UNLIKELY (instance == nil) { allocFailedException.isa = [OFAllocFailedException class]; @throw (id)&allocFailedException; } ((struct PreIvars *)instance)->retainCount = 1; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) if OF_UNLIKELY (OFSpinlockNew( &((struct PreIvars *)instance)->retainCountSpinlock) != 0) { free(instance); @throw [OFInitializationFailedException exceptionWithClass: class]; } #endif instance = (OFObject *)(void *)((char *)instance + PRE_IVARS_ALIGN); |
︙ | ︙ | |||
371 372 373 374 375 376 377 | * handler on load, we should not set ours, as this will break * Foundation. * * Unfortunately, there is no way to check if a forward handler has * already been set, so this is the best we can do. */ if (dlsym(RTLD_DEFAULT, "NSFoundationVersionNumber") == NULL) | | | | | | | | | | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | * handler on load, we should not set ours, as this will break * Foundation. * * Unfortunately, there is no way to check if a forward handler has * already been set, so this is the best we can do. */ if (dlsym(RTLD_DEFAULT, "NSFoundationVersionNumber") == NULL) objc_setForwardHandler((void *)&OFForward, (void *)&OFForward_stret); #else objc_setForwardHandler((IMP)&OFForward, (IMP)&OFForward_stret); #endif objc_setEnumerationMutationHandler(enumerationMutationHandler); do { OFHashSeed = OFRandom32(); } while (OFHashSeed == 0); #ifdef OF_OBJFW_RUNTIME objc_setTaggedPointerSecret(sizeof(uintptr_t) == 4 ? (uintptr_t)OFRandom32() : (uintptr_t)OFRandom64()); #endif } + (void)unload { } + (void)initialize { } + (instancetype)alloc { return OFAllocObject(self, 0, 0, NULL); } + (instancetype)new { return [[self alloc] init]; } + (Class)class { return self; } + (OFString *)className { return [OFString stringWithCString: class_getName(self) encoding: OFStringEncodingASCII]; } + (bool)isSubclassOfClass: (Class)class { for (Class iter = self; iter != Nil; iter = class_getSuperclass(iter)) if (iter == class) return true; |
︙ | ︙ | |||
468 469 470 471 472 473 474 | } + (OFString *)description { return [self className]; } | | < | < | 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | } + (OFString *)description { return [self className]; } + (IMP)replaceClassMethod: (SEL)selector withMethodFromClass: (Class)class { IMP method = [class methodForSelector: selector]; if (method == NULL) @throw [OFInvalidArgumentException exception]; return class_replaceMethod(object_getClass(self), selector, method, typeEncodingForSelector(object_getClass(class), selector)); } + (IMP)replaceInstanceMethod: (SEL)selector withMethodFromClass: (Class)class { IMP method = [class instanceMethodForSelector: selector]; if (method == NULL) @throw [OFInvalidArgumentException exception]; return class_replaceMethod(self, selector, method, |
︙ | ︙ | |||
572 573 574 575 576 577 578 | { return class_getSuperclass(object_getClass(self)); } - (OFString *)className { return [OFString stringWithCString: object_getClassName(self) | | | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | { return class_getSuperclass(object_getClass(self)); } - (OFString *)className { return [OFString stringWithCString: object_getClassName(self) encoding: OFStringEncodingASCII]; } - (bool)isKindOfClass: (Class)class { for (Class iter = object_getClass(self); iter != Nil; iter = class_getSuperclass(iter)) if (iter == class) |
︙ | ︙ | |||
616 617 618 619 620 621 622 | #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL) = (id (*)(id, SEL))objc_msgSend; #endif return imp(self, selector); } | | < | 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 | #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL) = (id (*)(id, SEL))objc_msgSend; #endif return imp(self, selector); } - (id)performSelector: (SEL)selector withObject: (id)object { #if defined(OF_OBJFW_RUNTIME) id (*imp)(id, SEL, id) = (id (*)(id, SEL, id))objc_msg_lookup(self, selector); #elif defined(OF_APPLE_RUNTIME) id (*imp)(id, SEL, id) = (id (*)(id, SEL, id))objc_msgSend; #endif |
︙ | ︙ | |||
676 677 678 679 680 681 682 | id (*imp)(id, SEL, id, id, id, id) = (id (*)(id, SEL, id, id, id, id))objc_msgSend; #endif return imp(self, selector, object1, object2, object3, object4); } | | < | | | | | 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 | id (*imp)(id, SEL, id, id, id, id) = (id (*)(id, SEL, id, id, id, id))objc_msgSend; #endif return imp(self, selector, object1, object2, object3, object4); } - (void)performSelector: (SEL)selector afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 object: object3 repeats: false]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 withObject: (id)object4 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [OFTimer scheduledTimerWithTimeInterval: delay target: self selector: selector object: object1 |
︙ | ︙ | |||
969 970 971 972 973 974 975 | [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread | | | | | | | 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | [timer waitUntilDone]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object1 object: object2 object: object3 repeats: false]]; objc_autoreleasePoolPop(pool); } - (void)performSelector: (SEL)selector onThread: (OFThread *)thread withObject: (id)object1 withObject: (id)object2 withObject: (id)object3 withObject: (id)object4 afterDelay: (OFTimeInterval)delay { void *pool = objc_autoreleasePoolPush(); [thread.runLoop addTimer: [OFTimer timerWithTimeInterval: delay target: self selector: selector object: object1 |
︙ | ︙ | |||
1077 1078 1079 1080 1081 1082 1083 | { return (object == self); } - (unsigned long)hash { uintptr_t ptr = (uintptr_t)self; | | | | | | 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | { return (object == self); } - (unsigned long)hash { uintptr_t ptr = (uintptr_t)self; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < sizeof(ptr); i++) { OFHashAdd(&hash, ptr & 0xFF); ptr >>= 8; } OFHashFinalize(&hash); return hash; } - (OFString *)description { /* Classes containing data should reimplement this! */ |
︙ | ︙ | |||
1112 1113 1114 1115 1116 1117 1118 | @throw [OFNotImplementedException exceptionWithSelector: selector object: self]; } - (instancetype)retain { #if defined(OF_HAVE_ATOMIC_OPS) | | | | | | | | | | 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 | @throw [OFNotImplementedException exceptionWithSelector: selector object: self]; } - (instancetype)retain { #if defined(OF_HAVE_ATOMIC_OPS) OFAtomicIntIncrease(&PRE_IVARS->retainCount); #elif defined(OF_AMIGAOS) /* * On AmigaOS, we can only have one CPU. As increasing a variable is a * single instruction on M68K, we don't need Forbid() / Permit() on * M68K. */ # ifndef OF_AMIGAOS_M68K Forbid(); # endif PRE_IVARS->retainCount++; # ifndef OF_AMIGAOS_M68K Permit(); # endif #else OFEnsure(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0); PRE_IVARS->retainCount++; OFEnsure(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0); #endif return self; } - (unsigned int)retainCount { assert(PRE_IVARS->retainCount >= 0); return PRE_IVARS->retainCount; } - (void)release { #if defined(OF_HAVE_ATOMIC_OPS) OFReleaseMemoryBarrier(); if (OFAtomicIntDecrease(&PRE_IVARS->retainCount) <= 0) { OFAcquireMemoryBarrier(); [self dealloc]; } #elif defined(OF_AMIGAOS) int retainCount; Forbid(); retainCount = --PRE_IVARS->retainCount; Permit(); if (retainCount == 0) [self dealloc]; #else int retainCount; OFEnsure(OFSpinlockLock(&PRE_IVARS->retainCountSpinlock) == 0); retainCount = --PRE_IVARS->retainCount; OFEnsure(OFSpinlockUnlock(&PRE_IVARS->retainCountSpinlock) == 0); if (retainCount == 0) [self dealloc]; #endif } - (instancetype)autorelease |
︙ | ︙ | |||
1245 1246 1247 1248 1249 1250 1251 | + (id)autorelease { return self; } + (unsigned int)retainCount { | | | 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 | + (id)autorelease { return self; } + (unsigned int)retainCount { return OFMaxRetainCount; } + (void)release { } + (void)dealloc |
︙ | ︙ |
Renamed and modified src/once.h [82e5d91bee] to src/OFOnce.h [dbf6773006].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "objfw-defs.h" | > | > | | | | | | > > > > > > > > > | > | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "objfw-defs.h" #import "macros.h" /** @file */ #if defined(OF_HAVE_PTHREADS) # include <pthread.h> typedef pthread_once_t OFOnceControl; # define OFOnceControlInitValue PTHREAD_ONCE_INIT #elif defined(OF_HAVE_ATOMIC_OPS) typedef volatile int OFOnceControl; # define OFOnceControlInitValue 0 #elif defined(OF_AMIGAOS) || !defined(OF_HAVE_THREADS) typedef int OFOnceControl; # define OFOnceControlInitValue 0 #endif typedef void (*OFOnceFunction)(void); #ifdef __cplusplus extern "C" { #endif /** * @brief A method to call a function only once in a thread-safe manner. * * @param control The once control. This needs to be set to * OFOnceControlInitValue at compile time. * @param func The function to call only once */ extern void OFOnce(OFOnceControl *_Nonnull control, OFOnceFunction _Nonnull func); #ifdef __cplusplus } #endif |
Renamed and modified src/once.m [af444c86d5] to src/OFOnce.m [ac90a9eaf1].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include <stdbool.h> | | > > > > < < < < < | | | | | | 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 | * file. */ #include "config.h" #include <stdbool.h> #import "OFOnce.h" #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_ATOMIC_OPS) # import "OFAtomic.h" # import "OFPlainMutex.h" #endif #ifdef OF_AMIGAOS # include <proto/exec.h> #endif void OFOnce(OFOnceControl *control, void (*func)(void)) { #if !defined(OF_HAVE_THREADS) if (*control == 0) { func(); *control = 1; } #elif defined(OF_HAVE_PTHREADS) pthread_once(control, func); #elif defined(OF_HAVE_ATOMIC_OPS) /* Avoid atomic operations in case it's already done. */ if (*control == 2) return; if (OFAtomicIntCompareAndSwap(control, 0, 1)) { func(); OFMemoryBarrier(); OFAtomicIntIncrease(control); } else while (*control == 1) OFYieldThread(); #elif defined(OF_AMIGAOS) bool run = false; /* Avoid Forbid() in case it's already done. */ if (*control == 2) return; |
︙ | ︙ | |||
76 77 78 79 80 81 82 | Permit(); if (run) { func(); *control = 2; } #else | | | 75 76 77 78 79 80 81 82 83 84 | Permit(); if (run) { func(); *control = 2; } #else # error No OFOnce available #endif } |
Modified src/OFOptionsParser.h from [110ad440c1] to [aa712b561c].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #import "OFString.h" @class OFMapTable; OF_ASSUME_NONNULL_BEGIN /** | | | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #import "OFString.h" @class OFMapTable; OF_ASSUME_NONNULL_BEGIN /** * @struct OFOptionsParserOption OFOptionsParser.h ObjFW/OFOptionsParser.h * * @brief An option which can be parsed by an @ref OFOptionsParser. */ typedef struct { /** The short version (e.g. `-v`) of the option or `\0` for none. */ OFUnichar shortOption; /** * The long version (e.g. `--verbose`) of the option or `nil` for none. */ OFString *__unsafe_unretained _Nullable longOption; /** |
︙ | ︙ | |||
53 54 55 56 57 58 59 | bool *_Nullable isSpecifiedPtr; /** * An optional pointer to an `OFString *` that is set to the * argument specified for the option or `nil` for no argument. */ OFString *__autoreleasing _Nullable *_Nullable argumentPtr; | < | | | | | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | bool *_Nullable isSpecifiedPtr; /** * An optional pointer to an `OFString *` that is set to the * argument specified for the option or `nil` for no argument. */ OFString *__autoreleasing _Nullable *_Nullable argumentPtr; } OFOptionsParserOption; /** * @class OFOptionsParser OFOptionsParser.h ObjFW/OFOptionsParser.h * * @brief A class for parsing the program options specified on the command line. */ OF_SUBCLASSING_RESTRICTED @interface OFOptionsParser: OFObject { OFOptionsParserOption *_options; OFMapTable *_longOptions; OFArray OF_GENERIC(OFString *) *_arguments; size_t _index, _subIndex; OFUnichar _lastOption; OFString *_Nullable _lastLongOption, *_Nullable _argument; bool _done; } /** * @brief The last parsed option. * * If @ref nextOption returned `?` or `:`, this returns the option which was * unknown or for which the argument was missing.@n * If this returns `-`, the last option is only available as a long option (see * lastLongOption). */ @property (readonly, nonatomic) OFUnichar lastOption; /** * @brief The long option for the last parsed option, or `nil` if the last * parsed option was not passed as a long option by the user. * * In case @ref nextOption returned `?`, this contains the unknown long * option.@n |
︙ | ︙ | |||
115 116 117 118 119 120 121 | */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *remainingArguments; /** * @brief Creates a new OFOptionsParser which accepts the specified options. * | | | | | | | 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 163 164 165 | */ @property (readonly, nonatomic) OFArray OF_GENERIC(OFString *) *remainingArguments; /** * @brief Creates a new OFOptionsParser which accepts the specified options. * * @param options An array of @ref OFOptionsParserOption specifying all * accepted options, terminated with an option whose short * option is `\0` and long option is `nil`. * * @return A new, autoreleased OFOptionsParser */ + (instancetype)parserWithOptions: (const OFOptionsParserOption *)options; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFOptionsParser so that it accepts * the specified options. * * @param options An array of @ref OFOptionsParserOption specifying all * accepted options, terminated with an option whose short * option is `\0` and long option is `nil`. * * @return An initialized OFOptionsParser */ - (instancetype)initWithOptions: (const OFOptionsParserOption *)options OF_DESIGNATED_INITIALIZER; /** * @brief Returns the next option. * * If the option is only available as a long option, `-` is returned. * Otherwise, the short option is returned, even if it was specified as a long * option.@n * If an unknown option is specified, `?` is returned.@n * If the argument for the option is missing, `:` is returned.@n * If there is an argument for the option even though it takes none, `=` is * returned.@n * If all options have been parsed, `\0` is returned. * * @note You need to call @ref nextOption repeatedly until it returns `\0` to * make sure all options have been parsed, even if you only rely on the * optional pointers specified and don't do any parsing yourself. * * @return The next option */ - (OFUnichar)nextOption; @end OF_ASSUME_NONNULL_END |
Modified src/OFOptionsParser.m from [9cfc874f7b] to [4490adcde3].
︙ | ︙ | |||
34 35 36 37 38 39 40 | return [(OFString *)object1 isEqual: (OFString *)object2]; } @implementation OFOptionsParser @synthesize lastOption = _lastOption, lastLongOption = _lastLongOption; @synthesize argument = _argument; | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 | return [(OFString *)object1 isEqual: (OFString *)object2]; } @implementation OFOptionsParser @synthesize lastOption = _lastOption, lastLongOption = _lastLongOption; @synthesize argument = _argument; + (instancetype)parserWithOptions: (const OFOptionsParserOption *)options { return [[[self alloc] initWithOptions: options] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithOptions: (const OFOptionsParserOption *)options { self = [super init]; @try { size_t count = 0; const OFOptionsParserOption *iter; OFOptionsParserOption *iter2; const OFMapTableFunctions keyFunctions = { .hash = stringHash, .equal = stringEqual }; const OFMapTableFunctions objectFunctions = { NULL }; /* Count, sanity check, initialize pointers */ for (iter = options; iter->shortOption != '\0' || iter->longOption != nil; iter++) { if (iter->hasArgument < -1 || iter->hasArgument > 1) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
80 81 82 83 84 85 86 | *iter->isSpecifiedPtr = false; if (iter->argumentPtr) *iter->argumentPtr = nil; count++; } | | | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | *iter->isSpecifiedPtr = false; if (iter->argumentPtr) *iter->argumentPtr = nil; count++; } _options = OFAllocMemory(count + 1, sizeof(*_options)); _longOptions = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions objectFunctions: objectFunctions]; for (iter = options, iter2 = _options; iter->shortOption != '\0' || iter->longOption != nil; iter++, iter2++) { |
︙ | ︙ | |||
137 138 139 140 141 142 143 | return self; } - (void)dealloc { if (_options != NULL) | | | | | | 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 163 164 165 166 167 | return self; } - (void)dealloc { if (_options != NULL) for (OFOptionsParserOption *iter = _options; iter->shortOption != '\0' || iter->longOption != nil; iter++) [iter->longOption release]; OFFreeMemory(_options); [_longOptions release]; [_arguments release]; [_argument release]; [super dealloc]; } - (OFUnichar)nextOption { OFOptionsParserOption *iter; OFString *argument; if (_done || _index >= _arguments.count) return '\0'; [_lastLongOption release]; [_argument release]; |
︙ | ︙ | |||
182 183 184 185 186 187 188 | _index++; return '\0'; } if ([argument hasPrefix: @"--"]) { void *pool = objc_autoreleasePoolPush(); size_t pos; | | | | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | _index++; return '\0'; } if ([argument hasPrefix: @"--"]) { void *pool = objc_autoreleasePoolPush(); size_t pos; OFOptionsParserOption *option; _lastOption = '-'; _index++; if ((pos = [argument rangeOfString: @"="].location) != OFNotFound) _argument = [[argument substringFromIndex: pos + 1] copy]; else pos = argument.length; _lastLongOption = [[argument substringWithRange: OFRangeMake(2, pos - 2)] copy]; objc_autoreleasePoolPop(pool); option = [_longOptions objectForKey: _lastLongOption]; if (option == NULL) return '?'; |
︙ | ︙ | |||
267 268 269 270 271 272 273 | return '?'; } - (OFArray *)remainingArguments { return [_arguments objectsInRange: | | | 267 268 269 270 271 272 273 274 275 276 | return '?'; } - (OFArray *)remainingArguments { return [_arguments objectsInRange: OFRangeMake(_index, _arguments.count - _index)]; } @end |
Renamed and modified src/pbkdf2.h [eef5fddc43] to src/OFPBKDF2.h [c5d81514ad].
︙ | ︙ | |||
25 26 27 28 29 30 31 | OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFHMAC; /** | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFHMAC; /** * @brief The parameters for @ref OFPBKDF2. */ typedef struct { /** @brief The HMAC to use to derive a key. */ __unsafe_unretained OFHMAC *HMAC; /** @brief The number of iterations to perform. */ size_t iterations; /** @brief The salt to derive a key with. */ const unsigned char *salt; /** @brief The length of the salt. */ |
︙ | ︙ | |||
50 51 52 53 54 55 56 | * @brief The desired length for the derived key. * * @ref key needs to have enough storage. */ size_t keyLength; /** @brief Whether data may be stored in swappable memory. */ bool allowsSwappableMemory; | | | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | * @brief The desired length for the derived key. * * @ref key needs to have enough storage. */ size_t keyLength; /** @brief Whether data may be stored in swappable memory. */ bool allowsSwappableMemory; } OFPBKDF2Parameters; #ifdef __cplusplus extern "C" { #endif /** * @brief Derives a key from a password and a salt using PBKDF2. * * @note This will call @ref OFHMAC::reset on the `HMAC` first, making it * possible to reuse the `HMAC`, but also meaning all previous results * from the `HMAC` get invalidated if they have not been copied. * * @param parameters The parameters to use */ extern void OFPBKDF2(OFPBKDF2Parameters parameters); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Renamed and modified src/pbkdf2.m [11ab09dd1b] to src/OFPBKDF2.m [dc320d6211].
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * file. */ #include "config.h" #include <stdlib.h> #import "OFHMAC.h" #import "OFSecureData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" | > < < | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | * file. */ #include "config.h" #include <stdlib.h> #import "OFPBKDF2.h" #import "OFHMAC.h" #import "OFSecureData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" void OFPBKDF2(OFPBKDF2Parameters param) { void *pool = objc_autoreleasePoolPush(); size_t blocks, digestSize = param.HMAC.digestSize; OFSecureData *buffer = [OFSecureData dataWithCount: digestSize allowsSwappableMemory: param.allowsSwappableMemory]; OFSecureData *digest = [OFSecureData |
︙ | ︙ | |||
55 56 57 58 59 60 61 | extendedSalt = [OFSecureData dataWithCount: param.saltLength + 4 allowsSwappableMemory: param.allowsSwappableMemory]; extendedSaltItems = extendedSalt.mutableItems; @try { | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | extendedSalt = [OFSecureData dataWithCount: param.saltLength + 4 allowsSwappableMemory: param.allowsSwappableMemory]; extendedSaltItems = extendedSalt.mutableItems; @try { uint32_t i = OFToBigEndian32(1); [param.HMAC setKey: param.password length: param.passwordLength]; memcpy(extendedSaltItems, param.salt, param.saltLength); while (param.keyLength > 0) { |
︙ | ︙ | |||
92 93 94 95 96 97 98 | if (length > param.keyLength) length = param.keyLength; memcpy(param.key, bufferItems, length); param.key += length; param.keyLength -= length; | | | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | if (length > param.keyLength) length = param.keyLength; memcpy(param.key, bufferItems, length); param.key += length; param.keyLength -= length; i = OFToBigEndian32(OFFromBigEndian32(i) + 1); } } @catch (id e) { [extendedSalt zero]; [buffer zero]; [digest zero]; @throw e; } @finally { [param.HMAC zero]; } objc_autoreleasePoolPop(pool); } |
Modified src/OFPair.m from [03bda5affd] to [60a88e0dc4].
︙ | ︙ | |||
81 82 83 84 85 86 87 | return false; return true; } - (unsigned long)hash { | | | | | | | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, [_firstObject hash]); OFHashAddHash(&hash, [_secondObject hash]); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; |
︙ | ︙ |
Renamed and modified src/condition.h [61428a9c46] to src/OFPlainCondition.h [cb66a320ac].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) # error No conditions available! #endif | | < | | | | | | | | > | | | | | | | | | | 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 61 62 63 64 65 66 67 68 | #include "platform.h" #if !defined(OF_HAVE_THREADS) || \ (!defined(OF_HAVE_PTHREADS) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS)) # error No conditions available! #endif /* For OFTimeInterval */ #import "OFObject.h" #import "OFPlainMutex.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> typedef pthread_cond_t OFPlainCondition; #elif defined(OF_WINDOWS) # include <windows.h> typedef struct { HANDLE event; volatile int count; } OFPlainCondition; #elif defined(OF_AMIGAOS) # include <exec/tasks.h> typedef struct { struct OFPlainConditionWaitingTask { struct Task *task; unsigned char sigBit; struct OFPlainConditionWaitingTask *next; } *waitingTasks; } OFPlainCondition; #endif #ifdef __cplusplus extern "C" { #endif extern int OFPlainConditionNew(OFPlainCondition *condition); extern int OFPlainConditionSignal(OFPlainCondition *condition); extern int OFPlainConditionBroadcast(OFPlainCondition *condition); extern int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex); extern int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout); #ifdef OF_AMIGAOS extern int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, ULONG *signalMask); extern int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask); #endif extern int OFPlainConditionFree(OFPlainCondition *condition); #ifdef __cplusplus } #endif |
Renamed and modified src/condition.m [2b71c33bd6] to src/OFPlainCondition.m [5c92a31d36].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFPlainCondition.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFPlainCondition.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFPlainCondition.m" #endif |
Renamed and modified src/mutex.h [c50a02c698] to src/OFPlainMutex.h [d6ce7e7a04].
︙ | ︙ | |||
24 25 26 27 28 29 30 | # error No mutexes available! #endif #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 | # error No mutexes available! #endif #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> typedef pthread_mutex_t OFPlainMutex; #elif defined(OF_WINDOWS) # include <windows.h> typedef CRITICAL_SECTION OFPlainMutex; #elif defined(OF_AMIGAOS) # include <exec/semaphores.h> typedef struct SignalSemaphore OFPlainMutex; #endif #if defined(OF_HAVE_ATOMIC_OPS) # import "OFAtomic.h" typedef volatile int OFSpinlock; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) typedef pthread_spinlock_t OFSpinlock; #else typedef OFPlainMutex OFSpinlock; #endif #ifdef OF_HAVE_SCHED_YIELD # include <sched.h> #endif #if defined(OF_HAVE_RECURSIVE_PTHREAD_MUTEXES) || defined(OF_WINDOWS) || \ defined(OF_AMIGAOS) # define OFPlainRecursiveMutex OFPlainMutex #else # import "OFTLSKey.h" typedef struct { OFPlainMutex mutex; OFTLSKey count; } OFPlainRecursiveMutex; #endif #ifdef __cplusplus extern "C" { #endif extern int OFPlainMutexNew(OFPlainMutex *mutex); extern int OFPlainMutexLock(OFPlainMutex *mutex); extern int OFPlainMutexTryLock(OFPlainMutex *mutex); extern int OFPlainMutexUnlock(OFPlainMutex *mutex); extern int OFPlainMutexFree(OFPlainMutex *mutex); extern int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex); extern int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex); extern int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex); extern int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex); extern int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex); #ifdef __cplusplus } #endif /* Spinlocks are inlined for performance. */ static OF_INLINE void OFYieldThread(void) { #if defined(OF_HAVE_SCHED_YIELD) sched_yield(); #elif defined(OF_WINDOWS) Sleep(0); #endif } static OF_INLINE int OFSpinlockNew(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) *spinlock = 0; return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_init(spinlock, 0); #else return OFPlainMutexNew(spinlock); #endif } static OF_INLINE int OFSpinlockTryLock(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) if (OFAtomicIntCompareAndSwap(spinlock, 0, 1)) { OFAcquireMemoryBarrier(); return 0; } return EBUSY; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_trylock(spinlock); #else return OFPlainMutexTryLock(spinlock); #endif } static OF_INLINE int OFSpinlockLock(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) size_t i; for (i = 0; i < 10; i++) if (OFSpinlockTryLock(spinlock) == 0) return 0; while (OFSpinlockTryLock(spinlock) == EBUSY) OFYieldThread(); return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_lock(spinlock); #else return OFPlainMutexLock(spinlock); #endif } static OF_INLINE int OFSpinlockUnlock(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) bool ret = OFAtomicIntCompareAndSwap(spinlock, 1, 0); OFReleaseMemoryBarrier(); return (ret ? 0 : EINVAL); #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_unlock(spinlock); #else return OFPlainMutexUnlock(spinlock); #endif } static OF_INLINE int OFSpinlockFree(OFSpinlock *spinlock) { #if defined(OF_HAVE_ATOMIC_OPS) return 0; #elif defined(OF_HAVE_PTHREAD_SPINLOCKS) return pthread_spin_destroy(spinlock); #else return OFPlainMutexFree(spinlock); #endif } |
Renamed and modified src/mutex.m [637d387b19] to src/OFPlainMutex.m [f697ac3445].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFPlainMutex.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFPlainMutex.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFPlainMutex.m" #endif |
Renamed and modified src/thread.h [2b66252a9f] to src/OFPlainThread.h [00cdbb5121].
︙ | ︙ | |||
22 23 24 25 26 27 28 | # error No threads available! #endif #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> | | | | | | > > > | > > > > > | > > > > | > > > > > | > | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | # error No threads available! #endif #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> typedef pthread_t OFPlainThread; #elif defined(OF_WINDOWS) # include <windows.h> typedef HANDLE OFPlainThread; #elif defined(OF_AMIGAOS) # include <exec/tasks.h> # include <exec/semaphores.h> typedef struct { struct Task *task; void (*function)(id); id object; struct SignalSemaphore semaphore; struct Task *joinTask; unsigned char joinSigBit; bool detached, done; } *OFPlainThread; #endif typedef struct { float priority; size_t stackSize; } OFPlainThreadAttributes; #if defined(OF_HAVE_PTHREADS) static OF_INLINE OFPlainThread OFCurrentPlainThread(void) { return pthread_self(); } static OF_INLINE bool OFPlainThreadIsCurrent(OFPlainThread thread) { return pthread_equal(thread, pthread_self()); } #elif defined(OF_WINDOWS) static OF_INLINE OFPlainThread OFCurrentPlainThread(void) { return GetCurrentThread(); } static OF_INLINE bool OFPlainThreadIsCurrent(OFPlainThread thread) { return (thread == GetCurrentThread()); } #elif defined(OF_AMIGAOS) extern OFPlainThread OFCurrentPlainThread(void); extern bool OFPlainThreadIsCurrent(OFPlainThread); #endif #ifdef __cplusplus extern "C" { #endif extern int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr); extern int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr); extern void OFSetThreadName(const char *name); extern int OFPlainThreadJoin(OFPlainThread thread); extern int OFPlainThreadDetach(OFPlainThread thread); #ifdef __cplusplus } #endif |
Renamed and modified src/thread.m [551723b62b] to src/OFPlainThread.m [77054b78a9].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFPlainThread.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFPlainThread.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFPlainThread.m" #endif |
Modified src/OFPlugin.h from [ac829978a7] to [53f335d6bf].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFObject.h" @class OFString; #ifndef OF_WINDOWS # include <dlfcn.h> | | | | > > > | | | > > > > > > > | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | #import "OFObject.h" @class OFString; #ifndef OF_WINDOWS # include <dlfcn.h> typedef void *OFPluginHandle; typedef enum { OFDLOpenFlagLazy = RTLD_LAZY, OFDLOpenFlagNow = RTLD_NOW } OFDLOpenFlags; #else # include <windows.h> typedef HMODULE OFPluginHandle; typedef enum { OFDLOpenFlagLazy = 0, OFDLOpenFlagNow = 0 } OFDLOpenFlags; #endif OF_ASSUME_NONNULL_BEGIN /** * @class OFPlugin OFPlugin.h ObjFW/OFPlugin.h * * @brief Provides a system for loading plugins at runtime. * * A plugin must subclass @ref OFPlugin and have a global function called * `OFPluginInit`, which returns an instance of the @ref OFPlugin subclass and * takes no parameters. */ @interface OFPlugin: OFObject { OFPluginHandle _pluginHandle; OF_RESERVE_IVARS(OFPlugin, 4) } /** * @brief Loads a plugin from a file. * * @param path Path to the plugin file. The suffix is appended automatically. * @return The loaded plugin */ + (OF_KINDOF(OFPlugin *))pluginWithPath: (OFString *)path; @end #ifdef __cplusplus extern "C" { #endif extern OFPluginHandle OFDLOpen(OFString *path, OFDLOpenFlags flags); extern void *OFDLSym(OFPluginHandle handle, const char *symbol); extern OFString *_Nullable OFDLError(void); extern void OFDLClose(OFPluginHandle handle); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFPlugin.m from [12a642d8b0] to [71a9e453b8].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLoadPluginFailedException.h" | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLoadPluginFailedException.h" typedef OFPlugin *(*PluginInit)(void); OFPluginHandle OFDLOpen(OFString *path, OFDLOpenFlags flags) { #ifndef OF_WINDOWS return dlopen([path cStringWithEncoding: [OFLocale encoding]], flags); #else if (path == nil) return GetModuleHandle(NULL); if ([OFSystemInfo isWindowsNT]) return LoadLibraryW(path.UTF16String); else return LoadLibraryA( [path cStringWithEncoding: [OFLocale encoding]]); #endif } void * OFDLSym(OFPluginHandle handle, const char *symbol) { #ifndef OF_WINDOWS return dlsym(handle, symbol); #else return (void *)(uintptr_t)GetProcAddress(handle, symbol); #endif } void OFDLClose(OFPluginHandle handle) { #ifndef OF_WINDOWS dlclose(handle); #else FreeLibrary(handle); #endif } OFString * OFDLError(void) { #ifndef OF_WINDOWS return [OFString stringWithCString: dlerror() encoding: [OFLocale encoding]]; #else return nil; #endif } @implementation OFPlugin + (id)pluginWithPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFPluginHandle handle; PluginInit initPlugin; OFPlugin *plugin; #if defined(OF_MACOS) path = [path stringByAppendingFormat: @".bundle/Contents/MacOS/%@", path.lastPathComponent]; #elif defined(OF_IOS) path = [path stringByAppendingFormat: @".bundle/%@", path.lastPathComponent]; #else path = [path stringByAppendingString: @PLUGIN_SUFFIX]; #endif if ((handle = OFDLOpen(path, OFDLOpenFlagLazy)) == NULL) @throw [OFLoadPluginFailedException exceptionWithPath: path error: OFDLError()]; objc_autoreleasePoolPop(pool); initPlugin = (PluginInit)(uintptr_t)OFDLSym(handle, "OFPluginInit"); if (initPlugin == (PluginInit)0 || (plugin = initPlugin()) == nil) { OFDLClose(handle); @throw [OFInitializationFailedException exceptionWithClass: self]; } plugin->_pluginHandle = handle; return plugin; } |
︙ | ︙ | |||
130 131 132 133 134 135 136 | } return [super init]; } - (void)dealloc { | | | | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | } return [super init]; } - (void)dealloc { OFPluginHandle h = _pluginHandle; [super dealloc]; OFDLClose(h); } @end |
Modified src/OFPointValue.h from [a55ded17fa] to [4a1e3a3976].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN @interface OFPointValue: OFValue { | | > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN @interface OFPointValue: OFValue { OFPoint _point; } - (instancetype)initWithPoint: (OFPoint)point; @end OF_ASSUME_NONNULL_END |
Modified src/OFPointValue.m from [6f05fc4f1d] to [4e64632cbc].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFPointValue @synthesize pointValue = _point; | | | | < | | 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 | #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFPointValue @synthesize pointValue = _point; - (instancetype)initWithPoint: (OFPoint)point { self = [super init]; _point = point; return self; } - (const char *)objCType { return @encode(OFPoint); } - (void)getValue: (void *)value size: (size_t)size { if (size != sizeof(_point)) @throw [OFOutOfRangeException exception]; memcpy(value, &_point, sizeof(_point)); } - (OFString *)description { return [OFString stringWithFormat: @"<OFValue: OFPoint { %f, %f }>", _point.x, _point.y]; } @end |
Modified src/OFPointerValue.h from [83e44d9bb8] to [76806b79ee].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 | OF_ASSUME_NONNULL_BEGIN @interface OFPointerValue: OFValue { void *_pointer; } @end OF_ASSUME_NONNULL_END | > > | 17 18 19 20 21 22 23 24 25 26 27 28 | OF_ASSUME_NONNULL_BEGIN @interface OFPointerValue: OFValue { void *_pointer; } - (instancetype)initWithPointer: (const void *)pointer; @end OF_ASSUME_NONNULL_END |
Modified src/OFPointerValue.m from [ff9ab4b9d5] to [18e2836486].
︙ | ︙ | |||
31 32 33 34 35 36 37 | } - (const char *)objCType { return @encode(void *); } | | < | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | } - (const char *)objCType { return @encode(void *); } - (void)getValue: (void *)value size: (size_t)size { if (size != sizeof(_pointer)) @throw [OFOutOfRangeException exception]; memcpy(value, &_pointer, sizeof(_pointer)); } |
︙ | ︙ |
Modified src/OFPollKernelEventObserver.m from [e93ed3c852] to [8fcdaec4c9].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 | #ifdef HAVE_POLL_H # include <poll.h> #endif #import "OFPollKernelEventObserver.h" #import "OFData.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" | > < < | | | < | | | | | | | | | | < | | | | < | < < | < < | < < | < | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 | #ifdef HAVE_POLL_H # include <poll.h> #endif #import "OFPollKernelEventObserver.h" #import "OFData.h" #import "OFSocket+Private.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_WII # define pollfd pollsd # define fd socket #endif @implementation OFPollKernelEventObserver - (instancetype)init { self = [super init]; @try { struct pollfd p = { _cancelFD[0], POLLIN, 0 }; _FDs = [[OFMutableData alloc] initWithItemSize: sizeof(struct pollfd)]; [_FDs addItem: &p]; _maxFD = _cancelFD[0]; _FDToObject = OFAllocMemory((size_t)_maxFD + 1, sizeof(id)); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_FDs release]; OFFreeMemory(_FDToObject); [super dealloc]; } static void addObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t count; bool found; if (fd < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; count = self->_FDs.count; found = false; for (size_t i = 0; i < count; i++) { if (FDs[i].fd == fd) { FDs[i].events |= events; found = true; break; } } if (!found) { struct pollfd p = { fd, events, 0 }; if (fd > self->_maxFD) { self->_maxFD = fd; self->_FDToObject = OFResizeMemory(self->_FDToObject, (size_t)self->_maxFD + 1, sizeof(id)); } self->_FDToObject[fd] = object; [self->_FDs addItem: &p]; } } static void removeObject(OFPollKernelEventObserver *self, id object, int fd, short events) { struct pollfd *FDs; size_t nFDs; if (fd < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: EBADF]; FDs = self->_FDs.mutableItems; nFDs = self->_FDs.count; for (size_t i = 0; i < nFDs; i++) { if (FDs[i].fd == fd) { FDs[i].events &= ~events; if (FDs[i].events == 0) { /* * TODO: Remove from and resize _FDToObject, * adjust _maxFD. */ [self->_FDs removeItemAtIndex: i]; } break; } } } - (void)addObjectForReading: (id <OFReadyForReadingObserving>)object { addObject(self, object, object.fileDescriptorForReading, POLLIN); [super addObjectForReading: object]; } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { addObject(self, object, object.fileDescriptorForWriting, POLLOUT); [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { removeObject(self, object, object.fileDescriptorForReading, POLLIN); [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { removeObject(self, object, object.fileDescriptorForWriting, POLLOUT); [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { void *pool; struct pollfd *FDs; int events; size_t nFDs; if ([self of_processReadBuffers]) |
︙ | ︙ | |||
205 206 207 208 209 210 211 | if (FDs[i].revents & POLLIN) { void *pool2; if (FDs[i].fd == _cancelFD[0]) { char buffer; #ifdef OF_HAVE_PIPE | | | | | 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | if (FDs[i].revents & POLLIN) { void *pool2; if (FDs[i].fd == _cancelFD[0]) { char buffer; #ifdef OF_HAVE_PIPE OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); #else OFEnsure(recvfrom(_cancelFD[0], &buffer, 1, 0, NULL, NULL) == 1); #endif FDs[i].revents = 0; continue; } pool2 = objc_autoreleasePoolPush(); |
︙ | ︙ |
Modified src/OFRIPEMD160Hash.h from [294f0a5d27] to [887ee4002d].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | | | | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFRIPEMD160Hash OFRIPEMD160Hash.h ObjFW/OFRIPEMD160Hash.h * * @brief A class which provides methods to create a RIPEMD-160 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFRIPEMD160Hash: OFObject <OFCryptographicHash> { OFSecureData *_iVarsData; struct { uint32_t state[5]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[16]; } buffer; size_t bufferLength; } *_iVars; bool _allowsSwappableMemory; bool _calculated; |
︙ | ︙ |
Modified src/OFRIPEMD160Hash.m from [ab4f0b95de] to [b60f75a8d4].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFRIPEMD160Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #import "OFRIPEMD160Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFRIPEMD160Hash () - (void)of_resetState; @end #define F(a, b, c) ((a) ^ (b) ^ (c)) |
︙ | ︙ | |||
67 68 69 70 71 72 73 | }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length) { #ifdef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) | | | | | | | | | | | | | | | | | | | | | | | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | }; static OF_INLINE void byteSwapVectorIfBE(uint32_t *vector, uint_fast8_t length) { #ifdef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[5], new2[5]; uint_fast8_t i = 0; new[0] = new2[0] = state[0]; new[1] = new2[1] = state[1]; new[2] = new2[2] = state[2]; new[3] = new2[3] = state[3]; new[4] = new2[4] = state[4]; byteSwapVectorIfBE(buffer, 16); #define LOOP_BODY(f, g, k, k2) \ { \ uint32_t tmp; \ \ tmp = new[0] + f(new[1], new[2], new[3]) + \ buffer[wordOrder[i]] + k; \ tmp = OFRotateLeft(tmp, rotateBits[i]) + new[4]; \ \ new[0] = new[4]; \ new[4] = new[3]; \ new[3] = OFRotateLeft(new[2], 10); \ new[2] = new[1]; \ new[1] = tmp; \ \ tmp = new2[0] + g(new2[1], new2[2], new2[3]) + \ buffer[wordOrder2[i]] + k2; \ tmp = OFRotateLeft(tmp, rotateBits2[i]) + new2[4]; \ \ new2[0] = new2[4]; \ new2[4] = new2[3]; \ new2[3] = OFRotateLeft(new2[2], 10); \ new2[2] = new2[1]; \ new2[1] = tmp; \ } for (; i < 16; i++) LOOP_BODY(F, J, 0x00000000, 0x50A28BE6) for (; i < 32; i++) LOOP_BODY(G, I, 0x5A827999, 0x5C4DD124) for (; i < 48; i++) |
︙ | ︙ | |||
137 138 139 140 141 142 143 | @implementation OFRIPEMD160Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { | | | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | @implementation OFRIPEMD160Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { return digestSize; } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { |
︙ | ︙ | |||
190 191 192 193 194 195 196 | [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { | | | | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { return digestSize; } - (size_t)blockSize { return blockSize; } - (id)copy { OFRIPEMD160Hash *copy = [[OFRIPEMD160Hash alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; |
︙ | ︙ | |||
219 220 221 222 223 224 225 | _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; _iVars->state[4] = 0xC3D2E1F0; } | | < | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; _iVars->state[4] = 0xC3D2E1F0; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; |
︙ | ︙ | |||
259 260 261 262 263 264 265 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; | | | | | | | | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToLittleEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); _iVars->buffer.words[15] = OFToLittleEndian32((uint32_t)(_iVars->bits >> 32)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfBE(_iVars->state, 5); _calculated = true; return (const unsigned char *)_iVars->state; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end |
Modified src/OFRangeCharacterSet.h from [146f282cd5] to [36adda48b7].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @interface OFRangeCharacterSet: OFCharacterSet { | | | 15 16 17 18 19 20 21 22 23 24 25 26 | #import "OFCharacterSet.h" OF_ASSUME_NONNULL_BEGIN @interface OFRangeCharacterSet: OFCharacterSet { OFRange _range; } @end OF_ASSUME_NONNULL_END |
Modified src/OFRangeCharacterSet.m from [e174e57848] to [171e0115ac].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @implementation OFRangeCharacterSet - (instancetype)init { OF_INVALID_INIT_METHOD } | | | | 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 | @implementation OFRangeCharacterSet - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRange: (OFRange)range { self = [super init]; @try { if (SIZE_MAX - range.location < range.length) @throw [OFOutOfRangeException exception]; _range = range; } @catch (id e) { [self release]; @throw e; } return self; } - (bool)characterIsMember: (OFUnichar)character { return (character >= _range.location && character < _range.location + _range.length); } @end |
Modified src/OFRangeValue.h from [a296ed91e7] to [364a68b940].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN @interface OFRangeValue: OFValue { | | > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN @interface OFRangeValue: OFValue { OFRange _range; } - (instancetype)initWithRange: (OFRange)range; @end OF_ASSUME_NONNULL_END |
Modified src/OFRangeValue.m from [a40dd0a04c] to [d1e5de9d18].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFRangeValue @synthesize rangeValue = _range; | | | | < | | 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 | #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFRangeValue @synthesize rangeValue = _range; - (instancetype)initWithRange: (OFRange)range { self = [super init]; _range = range; return self; } - (const char *)objCType { return @encode(OFRange); } - (void)getValue: (void *)value size: (size_t)size { if (size != sizeof(_range)) @throw [OFOutOfRangeException exception]; memcpy(value, &_range, sizeof(_range)); } - (OFString *)description { return [OFString stringWithFormat: @"<OFValue: OFRange { %zu, %zu }>", _range.location, _range.length]; } @end |
Renamed and modified src/OFRectangleValue.h [e2767981ab] to src/OFRectValue.h [57204033f6].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN | | | > > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * file. */ #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN @interface OFRectValue: OFValue { OFRect _rect; } - (instancetype)initWithRect: (OFRect)rect; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFRectangleValue.m [189e76f543] to src/OFRectValue.m [15e6c7cc85].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | | | | | | < | | | | | | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFRectValue.h" #import "OFMethodSignature.h" #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFRectValue @synthesize rectValue = _rect; - (instancetype)initWithRect: (OFRect)rect { self = [super init]; _rect = rect; return self; } - (const char *)objCType { return @encode(OFRect); } - (void)getValue: (void *)value size: (size_t)size { if (size != sizeof(_rect)) @throw [OFOutOfRangeException exception]; memcpy(value, &_rect, sizeof(_rect)); } - (OFString *)description { return [OFString stringWithFormat: @"<OFValue: OFRect { %f, %f, %f, %f }>", _rect.origin.x, _rect.origin.y, _rect.size.width, _rect.size.height]; } @end |
Modified src/OFRecursiveMutex.h from [d6ed860e64] to [c862616f60].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFLocking.h" | < | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFLocking.h" #import "OFPlainMutex.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFRecursiveMutex OFRecursiveMutex.h ObjFW/OFRecursiveMutex.h * * @brief A class for creating mutual exclusions which can be entered * recursively. */ OF_SUBCLASSING_RESTRICTED @interface OFRecursiveMutex: OFObject <OFLocking> { OFPlainRecursiveMutex _rmutex; bool _initialized; OFString *_Nullable _name; } /** * @brief Creates a new recursive mutex. * |
︙ | ︙ |
Modified src/OFRecursiveMutex.m from [14f9082e7e] to [00172c34e4].
︙ | ︙ | |||
33 34 35 36 37 38 39 | return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; if (OFPlainRecursiveMutexNew(&_rmutex) != 0) { Class c = self.class; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } _initialized = true; return self; } - (void)dealloc { if (_initialized) { int error = OFPlainRecursiveMutexFree(&_rmutex); if (error != 0) { OFEnsure(error == EBUSY); @throw [OFStillLockedException exceptionWithLock: self]; } } [_name release]; [super dealloc]; } - (void)lock { int error = OFPlainRecursiveMutexLock(&_rmutex); if (error != 0) @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } - (bool)tryLock { int error = OFPlainRecursiveMutexTryLock(&_rmutex); if (error != 0) { if (error == EBUSY) return false; else @throw [OFLockFailedException exceptionWithLock: self errNo: error]; } return true; } - (void)unlock { int error = OFPlainRecursiveMutexUnlock(&_rmutex); if (error != 0) @throw [OFUnlockFailedException exceptionWithLock: self errNo: error]; } - (OFString *)description |
︙ | ︙ |
Modified src/OFRunLoop+Private.h from [424962bcb9] to [b73b1c9760].
︙ | ︙ | |||
35 36 37 38 39 40 41 | @interface OFRunLoop () + (void)of_setMainRunLoop: (OFRunLoop *)runLoop; #ifdef OF_HAVE_SOCKETS + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *) stream buffer: (void *)buffer length: (size_t)length | | | | | | | | < < | | < | | | < < | | | | | | | | | | | | < | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | @interface OFRunLoop () + (void)of_setMainRunLoop: (OFRunLoop *)runLoop; #ifdef OF_HAVE_SOCKETS + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *) stream buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncReadBlock)block # endif delegate: (nullable id <OFStreamDelegate>)delegate; + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *) stream buffer: (void *)buffer exactLength: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncReadBlock)block # endif delegate: (nullable id <OFStreamDelegate>)delegate; + (void)of_addAsyncReadLineForStream: (OFStream <OFReadyForReadingObserving> *) stream encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncReadLineBlock)block # endif delegate: (nullable id <OFStreamDelegate>)delegate; + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *) stream data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncWriteDataBlock)block # endif delegate: (nullable id <OFStreamDelegate>)delegate; + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *) stream string: (OFString *)string encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFStreamAsyncWriteStringBlock)block # endif delegate: (nullable id <OFStreamDelegate>)delegate; # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) + (void)of_addAsyncConnectForSocket: (id)socket mode: (OFRunLoopMode)mode delegate: (id <OFRunLoopConnectDelegate>)delegate; # endif + (void)of_addAsyncAcceptForSocket: (id)socket mode: (OFRunLoopMode)mode block: (nullable id)block delegate: (nullable id)delegate; + (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)socket buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFDatagramSocketAsyncReceiveBlock)block # endif delegate: (nullable id <OFDatagramSocketDelegate>) delegate; + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)socket data: (OFData *)data receiver: (const OFSocketAddress *)receiver mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFDatagramSocketAsyncSendDataBlock)block # endif delegate: (nullable id <OFDatagramSocketDelegate>)delegate; + (void)of_addAsyncReceiveForSequencedPacketSocket: (OFSequencedPacketSocket *)socket buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFSequencedPacketSocketAsyncReceiveBlock)block # endif delegate: (nullable id <OFSequencedPacketSocketDelegate>) delegate; + (void)of_addAsyncSendForSequencedPacketSocket: (OFSequencedPacketSocket *)socket data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (nullable OFSequencedPacketSocketAsyncSendDataBlock)block # endif delegate: (nullable id <OFSequencedPacketSocketDelegate>)delegate; + (void)of_cancelAsyncRequestsForObject: (id)object mode: (OFRunLoopMode)mode; #endif - (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode; @end OF_ASSUME_NONNULL_END |
Modified src/OFRunLoop.h from [17887708c9] to [7f5e7accfd].
︙ | ︙ | |||
35 36 37 38 39 40 41 | @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFTimer; @class OFDate; /** * @brief A mode for an OFRunLoop. */ | | | | | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); @class OFTimer; @class OFDate; /** * @brief A mode for an OFRunLoop. */ typedef OFConstantString *OFRunLoopMode; #ifdef __cplusplus extern "C" { #endif /** * @brief The default mode for an OFRunLoop. */ extern const OFRunLoopMode OFDefaultRunLoopMode; #ifdef __cplusplus } #endif /** * @class OFRunLoop OFRunLoop.h ObjFW/OFRunLoop.h * * @brief A class providing a run loop for the application and its processes. */ OF_SUBCLASSING_RESTRICTED @interface OFRunLoop: OFObject { OFMutableDictionary *_states; #ifdef OF_HAVE_THREADS OFMutex *_statesMutex; #endif OFRunLoopMode _Nullable _currentMode; volatile bool _stop; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nullable, nonatomic) OFRunLoop *mainRunLoop; @property (class, readonly, nullable, nonatomic) OFRunLoop *currentRunLoop; #endif @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFRunLoopMode currentMode; /** * @brief Returns the run loop for the main thread. * * @return The run loop for the main thread */ + (nullable OFRunLoop *)mainRunLoop; |
︙ | ︙ | |||
98 99 100 101 102 103 104 | /** * @brief Adds an OFTimer to the run loop for the specified mode. * * @param timer The timer to add * @param mode The run loop mode in which to run the timer */ | | < | < < | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | /** * @brief Adds an OFTimer to the run loop for the specified mode. * * @param timer The timer to add * @param mode The run loop mode in which to run the timer */ - (void)addTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode; #ifdef OF_AMIGAOS /** * @brief Adds an Exec Signal to the run loop. * * If a signal is added multiple times, the specified methods will be performed * in the order added. * * @note This is only available on AmigaOS! * * @param signal The signal to add * @param target The target to call when the signal was received * @param selector The selector to call on the target when the signal was * received. The selector must have one parameter for the ULONG * of the signal that was received. */ - (void)addExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector; /** * @brief Adds an Exec Signal to the run loop for the specified mode. * * If a signal is added multiple times, the specified methods will be performed * in the order added. * * @note This is only available on AmigaOS! * * @param signal The signal to add * @param mode The run loop mode in which to handle the signal * @param target The target to call when the signal was received * @param selector The selector to call on the target when the signal was * received. The selector must have one parameter for the ULONG * of the signal that was received. */ - (void)addExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector; /** * @brief Removes the specified Exec Signal with the specified target and * selector. * |
︙ | ︙ | |||
162 163 164 165 166 167 168 | * * @param signal The signal to remove * @param mode The run loop mode to which the signal was added * @param target The target which was specified when adding the signal * @param selector The selector which was specified when adding the signal */ - (void)removeExecSignal: (ULONG)signal | | | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | * * @param signal The signal to remove * @param mode The run loop mode to which the signal was added * @param target The target which was specified when adding the signal * @param selector The selector which was specified when adding the signal */ - (void)removeExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector; #endif /** * @brief Starts the run loop. */ |
︙ | ︙ | |||
186 187 188 189 190 191 192 | /** * @brief Run the run loop until an event or timer occurs or the specified * deadline is reached. * * @param mode The mode in which to run the run loop * @param deadline The date until which the run loop should run at the longest */ | < | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /** * @brief Run the run loop until an event or timer occurs or the specified * deadline is reached. * * @param mode The mode in which to run the run loop * @param deadline The date until which the run loop should run at the longest */ - (void)runMode: (OFRunLoopMode)mode beforeDate: (nullable OFDate *)deadline; /** * @brief Stops the run loop. If there is still an operation being executed, it * is finished before the run loop stops. */ - (void)stop; @end OF_ASSUME_NONNULL_END |
Modified src/OFRunLoop.m from [53e222eb32] to [0ec2ab674a].
︙ | ︙ | |||
40 41 42 43 44 45 46 47 48 49 50 51 52 53 | #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" #include "OFRunLoop_constants.m" static OFRunLoop *mainRunLoop = nil; @interface OFRunLoopState: OFObject #ifdef OF_HAVE_SOCKETS <OFKernelEventObserverDelegate> #endif { | > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | #import "OFTimer.h" #import "OFTimer+Private.h" #import "OFDate.h" #import "OFObserveFailedException.h" #include "OFRunLoop_constants.m" static OFRunLoop *mainRunLoop = nil; @interface OFRunLoopState: OFObject #ifdef OF_HAVE_SOCKETS <OFKernelEventObserverDelegate> #endif { |
︙ | ︙ | |||
72 73 74 75 76 77 78 | # ifdef OF_HAVE_THREADS OFMutex *_execSignalsMutex; # endif #endif } @end | < < < < < < | | | | | | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | # ifdef OF_HAVE_THREADS OFMutex *_execSignalsMutex; # endif #endif } @end #ifdef OF_HAVE_SOCKETS @interface OFRunLoopQueueItem: OFObject { @public id _delegate; } - (bool)handleObject: (id)object; @end @interface OFRunLoopReadQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncReadBlock _block; # endif void *_buffer; size_t _length; } @end @interface OFRunLoopExactReadQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncReadBlock _block; # endif void *_buffer; size_t _exactLength, _readLength; } @end @interface OFRunLoopReadLineQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncReadLineBlock _block; # endif OFStringEncoding _encoding; } @end @interface OFRunLoopWriteDataQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncWriteDataBlock _block; # endif OFData *_data; size_t _writtenLength; } @end @interface OFRunLoopWriteStringQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFStreamAsyncWriteStringBlock _block; # endif OFString *_string; OFStringEncoding _encoding; size_t _writtenLength; } @end # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) @interface OFRunLoopConnectQueueItem: OFRunLoopQueueItem @end |
︙ | ︙ | |||
161 162 163 164 165 166 167 | } @end @interface OFRunLoopDatagramReceiveQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS | | | | | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | } @end @interface OFRunLoopDatagramReceiveQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFDatagramSocketAsyncReceiveBlock _block; # endif void *_buffer; size_t _length; } @end @interface OFRunLoopDatagramSendQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFDatagramSocketAsyncSendDataBlock _block; # endif OFData *_data; OFSocketAddress _receiver; } @end @interface OFRunLoopPacketReceiveQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFSequencedPacketSocketAsyncReceiveBlock _block; # endif void *_buffer; size_t _length; } @end @interface OFRunLoopPacketSendQueueItem: OFRunLoopQueueItem { @public # ifdef OF_HAVE_BLOCKS OFSequencedPacketSocketAsyncSendDataBlock _block; # endif OFData *_data; } @end #endif @implementation OFRunLoopState |
︙ | ︙ | |||
278 279 280 281 282 283 284 | OFList OF_GENERIC(OF_KINDOF(OFRunLoopReadQueueItem *)) *queue = [[_readQueues objectForKey: object] retain]; assert(queue != nil); @try { if (![queue.firstObject handleObject: object]) { | | | > | | | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | OFList OF_GENERIC(OF_KINDOF(OFRunLoopReadQueueItem *)) *queue = [[_readQueues objectForKey: object] retain]; assert(queue != nil); @try { if (![queue.firstObject handleObject: object]) { OFListItem listItem = queue.firstListItem; /* * The handler might have called -[cancelAsyncRequests] * so that our queue is now empty, in which case we * should do nothing. */ if (listItem != NULL) { /* * Make sure we keep the target until after we * are done removing the object. The reason for * this is that the target might call * -[cancelAsyncRequests] in its dealloc. */ [[OFListItemObject(listItem) retain] autorelease]; [queue removeListItem: listItem]; if (queue.count == 0) { [_kernelEventObserver removeObjectForReading: object]; [_readQueues removeObjectForKey: object]; } |
︙ | ︙ | |||
321 322 323 324 325 326 327 | */ OFList *queue = [[_writeQueues objectForKey: object] retain]; assert(queue != nil); @try { if (![queue.firstObject handleObject: object]) { | | | > | | | 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | */ OFList *queue = [[_writeQueues objectForKey: object] retain]; assert(queue != nil); @try { if (![queue.firstObject handleObject: object]) { OFListItem listItem = queue.firstListItem; /* * The handler might have called -[cancelAsyncRequests] * so that our queue is now empty, in which case we * should do nothing. */ if (listItem != NULL) { /* * Make sure we keep the target until after we * are done removing the object. The reason for * this is that the target might call * -[cancelAsyncRequests] in its dealloc. */ [[OFListItemObject(listItem) retain] autorelease]; [queue removeListItem: listItem]; if (queue.count == 0) { [_kernelEventObserver removeObjectForWriting: object]; [_writeQueues removeObjectForKey: object]; } |
︙ | ︙ | |||
425 426 427 428 429 430 431 | @implementation OFRunLoopReadQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; @try { | | < | 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | @implementation OFRunLoopReadQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; @try { length = [object readIntoBuffer: _buffer length: _length]; } @catch (id e) { length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) |
︙ | ︙ | |||
734 735 736 737 738 739 740 | timerWithTimeInterval: 0 target: _delegate selector: @selector(of_socketDidConnect: exception:) object: object object: exception repeats: false]; | < | < | 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 | timerWithTimeInterval: 0 target: _delegate selector: @selector(of_socketDidConnect: exception:) object: object object: exception repeats: false]; [runLoop addTimer: timer forMode: runLoop.currentMode]; } return false; } @end # endif |
︙ | ︙ | |||
759 760 761 762 763 764 765 | acceptedSocket = nil; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) { if ([object isKindOfClass: [OFStreamSocket class]]) | | | | < | | 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | acceptedSocket = nil; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) { if ([object isKindOfClass: [OFStreamSocket class]]) return ((OFStreamSocketAsyncAcceptBlock)_block)( acceptedSocket, exception); else if ([object isKindOfClass: [OFSequencedPacketSocket class]]) return ((OFSequencedPacketSocketAsyncAcceptBlock) _block)(acceptedSocket, exception); else OFEnsure(0); } else { # endif if (![_delegate respondsToSelector: @selector(socket:didAcceptSocket:exception:)]) return false; return [_delegate socket: object |
︙ | ︙ | |||
796 797 798 799 800 801 802 | # endif @end @implementation OFRunLoopDatagramReceiveQueueItem - (bool)handleObject: (id)object { size_t length; | | | 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 | # endif @end @implementation OFRunLoopDatagramReceiveQueueItem - (bool)handleObject: (id)object { size_t length; OFSocketAddress address; id exception = nil; @try { length = [object receiveIntoBuffer: _buffer length: _length sender: &address]; } @catch (id e) { |
︙ | ︙ | |||
905 906 907 908 909 910 911 | @implementation OFRunLoopPacketReceiveQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; @try { | | < | 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 | @implementation OFRunLoopPacketReceiveQueueItem - (bool)handleObject: (id)object { size_t length; id exception = nil; @try { length = [object receiveIntoBuffer: _buffer length: _length]; } @catch (id e) { length = 0; exception = e; } # ifdef OF_HAVE_BLOCKS if (_block != NULL) |
︙ | ︙ | |||
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | #endif } + (void)of_setMainRunLoop: (OFRunLoop *)runLoop { mainRunLoop = [runLoop retain]; } #ifdef OF_HAVE_SOCKETS # define NEW_READ(type, object, mode) \ void *pool = objc_autoreleasePoolPush(); \ OFRunLoop *runLoop = [self currentRunLoop]; \ | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | < | < | < | < | | | | | | | | | | | | | | | | | | | | | | | | < | < | 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 | #endif } + (void)of_setMainRunLoop: (OFRunLoop *)runLoop { mainRunLoop = [runLoop retain]; } static OFRunLoopState * stateForMode(OFRunLoop *self, OFRunLoopMode mode, bool create) { OFRunLoopState *state; #ifdef OF_HAVE_THREADS [self->_statesMutex lock]; @try { #endif state = [self->_states objectForKey: mode]; if (create && state == nil) { state = [[OFRunLoopState alloc] init]; @try { [self->_states setObject: state forKey: mode]; } @finally { [state release]; } } #ifdef OF_HAVE_THREADS } @finally { [self->_statesMutex unlock]; } #endif return state; } #ifdef OF_HAVE_SOCKETS # define NEW_READ(type, object, mode) \ void *pool = objc_autoreleasePoolPush(); \ OFRunLoop *runLoop = [self currentRunLoop]; \ OFRunLoopState *state = stateForMode(runLoop, mode, true); \ OFList *queue = [state->_readQueues objectForKey: object]; \ type *queueItem; \ \ if (queue == nil) { \ queue = [OFList list]; \ [state->_readQueues setObject: queue forKey: object]; \ } \ \ if (queue.count == 0) \ [state->_kernelEventObserver \ addObjectForReading: object]; \ \ queueItem = [[[type alloc] init] autorelease]; # define NEW_WRITE(type, object, mode) \ void *pool = objc_autoreleasePoolPush(); \ OFRunLoop *runLoop = [self currentRunLoop]; \ OFRunLoopState *state = stateForMode(runLoop, mode, true); \ OFList *queue = [state->_writeQueues objectForKey: object]; \ type *queueItem; \ \ if (queue == nil) { \ queue = [OFList list]; \ [state->_writeQueues setObject: queue forKey: object]; \ } \ \ if (queue.count == 0) \ [state->_kernelEventObserver \ addObjectForWriting: object]; \ \ queueItem = [[[type alloc] init] autorelease]; #define QUEUE_ITEM \ [queue appendObject: queueItem]; \ \ objc_autoreleasePoolPop(pool); + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *) stream buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncReadBlock)block # endif delegate: (id <OFStreamDelegate>)delegate { NEW_READ(OFRunLoopReadQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_length = length; QUEUE_ITEM } + (void)of_addAsyncReadForStream: (OFStream <OFReadyForReadingObserving> *) stream buffer: (void *)buffer exactLength: (size_t)exactLength mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncReadBlock)block # endif delegate: (id <OFStreamDelegate>)delegate { NEW_READ(OFRunLoopExactReadQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_exactLength = exactLength; QUEUE_ITEM } + (void)of_addAsyncReadLineForStream: (OFStream <OFReadyForReadingObserving> *) stream encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncReadLineBlock)block # endif delegate: (id <OFStreamDelegate>)delegate { NEW_READ(OFRunLoopReadLineQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_encoding = encoding; QUEUE_ITEM } + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *) stream data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncWriteDataBlock)block # endif delegate: (id <OFStreamDelegate>)delegate { NEW_WRITE(OFRunLoopWriteDataQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_data = [data copy]; QUEUE_ITEM } + (void)of_addAsyncWriteForStream: (OFStream <OFReadyForWritingObserving> *) stream string: (OFString *)string encoding: (OFStringEncoding)encoding mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFStreamAsyncWriteStringBlock)block # endif delegate: (id <OFStreamDelegate>)delegate { NEW_WRITE(OFRunLoopWriteStringQueueItem, stream, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_string = [string copy]; queueItem->_encoding = encoding; QUEUE_ITEM } # if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) + (void)of_addAsyncConnectForSocket: (id)sock mode: (OFRunLoopMode)mode delegate: (id <OFRunLoopConnectDelegate>)delegate { NEW_WRITE(OFRunLoopConnectQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; QUEUE_ITEM } # endif + (void)of_addAsyncAcceptForSocket: (id)sock mode: (OFRunLoopMode)mode block: (id)block delegate: (id)delegate { NEW_READ(OFRunLoopAcceptQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif QUEUE_ITEM } + (void)of_addAsyncReceiveForDatagramSocket: (OFDatagramSocket *)sock buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFDatagramSocketAsyncReceiveBlock)block # endif delegate: (id <OFDatagramSocketDelegate>)delegate { NEW_READ(OFRunLoopDatagramReceiveQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_length = length; QUEUE_ITEM } + (void)of_addAsyncSendForDatagramSocket: (OFDatagramSocket *)sock data: (OFData *)data receiver: (const OFSocketAddress *)receiver mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFDatagramSocketAsyncSendDataBlock)block # endif delegate: (id <OFDatagramSocketDelegate>)delegate { NEW_WRITE(OFRunLoopDatagramSendQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_data = [data copy]; queueItem->_receiver = *receiver; QUEUE_ITEM } + (void)of_addAsyncReceiveForSequencedPacketSocket: (OFSequencedPacketSocket *) sock buffer: (void *)buffer length: (size_t)length mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFSequencedPacketSocketAsyncReceiveBlock)block # endif delegate: (id <OFSequencedPacketSocketDelegate>)delegate { NEW_READ(OFRunLoopPacketReceiveQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_buffer = buffer; queueItem->_length = length; QUEUE_ITEM } + (void)of_addAsyncSendForSequencedPacketSocket: (OFSequencedPacketSocket *)sock data: (OFData *)data mode: (OFRunLoopMode)mode # ifdef OF_HAVE_BLOCKS block: (OFSequencedPacketSocketAsyncSendDataBlock)block # endif delegate: (id <OFSequencedPacketSocketDelegate>)delegate { NEW_WRITE(OFRunLoopPacketSendQueueItem, sock, mode) queueItem->_delegate = [delegate retain]; # ifdef OF_HAVE_BLOCKS queueItem->_block = [block copy]; # endif queueItem->_data = [data copy]; QUEUE_ITEM } # undef NEW_READ # undef NEW_WRITE # undef QUEUE_ITEM + (void)of_cancelAsyncRequestsForObject: (id)object mode: (OFRunLoopMode)mode { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop = [self currentRunLoop]; OFRunLoopState *state = stateForMode(runLoop, mode, false); OFList *queue; if (state == nil) return; if ((queue = [state->_writeQueues objectForKey: object]) != nil) { assert(queue.count > 0); |
︙ | ︙ | |||
1339 1340 1341 1342 1343 1344 1345 | @try { OFRunLoopState *state; _states = [[OFMutableDictionary alloc] init]; state = [[OFRunLoopState alloc] init]; @try { | | < | 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 | @try { OFRunLoopState *state; _states = [[OFMutableDictionary alloc] init]; state = [[OFRunLoopState alloc] init]; @try { [_states setObject: state forKey: OFDefaultRunLoopMode]; } @finally { [state release]; } #ifdef OF_HAVE_THREADS _statesMutex = [[OFMutex alloc] init]; #endif |
︙ | ︙ | |||
1366 1367 1368 1369 1370 1371 1372 | #ifdef OF_HAVE_THREADS [_statesMutex release]; #endif [super dealloc]; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < | < | < | < | < | < < < | | | | | < < | | | < | 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 | #ifdef OF_HAVE_THREADS [_statesMutex release]; #endif [super dealloc]; } - (void)addTimer: (OFTimer *)timer { [self addTimer: timer forMode: OFDefaultRunLoopMode]; } - (void)addTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode { OFRunLoopState *state = stateForMode(self, mode, true); #ifdef OF_HAVE_THREADS [state->_timersQueueMutex lock]; @try { #endif [state->_timersQueue insertObject: timer]; #ifdef OF_HAVE_THREADS } @finally { [state->_timersQueueMutex unlock]; } #endif [timer of_setInRunLoop: self mode: mode]; #if defined(OF_HAVE_SOCKETS) [state->_kernelEventObserver cancel]; #elif defined(OF_HAVE_THREADS) [state->_condition signal]; #endif } - (void)of_removeTimer: (OFTimer *)timer forMode: (OFRunLoopMode)mode { OFRunLoopState *state = stateForMode(self, mode, false); if (state == nil) return; #ifdef OF_HAVE_THREADS [state->_timersQueueMutex lock]; @try { #endif for (OFListItem iter = state->_timersQueue.firstListItem; iter != NULL; iter = OFListItemNext(iter)) { if ([OFListItemObject(iter) isEqual: timer]) { [state->_timersQueue removeListItem: iter]; break; } } #ifdef OF_HAVE_THREADS } @finally { [state->_timersQueueMutex unlock]; } #endif } #ifdef OF_AMIGAOS - (void)addExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector { [self addExecSignal: signal forMode: OFDefaultRunLoopMode target: target selector: selector]; } - (void)addExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector { OFRunLoopState *state = stateForMode(self, mode, true); # ifdef OF_HAVE_THREADS [state->_execSignalsMutex lock]; @try { # endif [state->_execSignals addItem: &signal]; [state->_execSignalsTargets addObject: target]; |
︙ | ︙ | |||
1507 1508 1509 1510 1511 1512 1513 | } - (void)removeExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector { [self removeExecSignal: signal | | | | < | 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 | } - (void)removeExecSignal: (ULONG)signal target: (id)target selector: (SEL)selector { [self removeExecSignal: signal forMode: OFDefaultRunLoopMode target: target selector: selector]; } - (void)removeExecSignal: (ULONG)signal forMode: (OFRunLoopMode)mode target: (id)target selector: (SEL)selector { OFRunLoopState *state = stateForMode(self, mode, false); if (state == nil) return; # ifdef OF_HAVE_THREADS [state->_execSignalsMutex lock]; @try { |
︙ | ︙ | |||
1578 1579 1580 1581 1582 1583 1584 | - (void)runUntilDate: (OFDate *)deadline { _stop = false; while (!_stop && (deadline == nil || deadline.timeIntervalSinceNow >= 0)) | < | < | | | < | | | > | | | | < | 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 | - (void)runUntilDate: (OFDate *)deadline { _stop = false; while (!_stop && (deadline == nil || deadline.timeIntervalSinceNow >= 0)) [self runMode: OFDefaultRunLoopMode beforeDate: deadline]; } - (void)runMode: (OFRunLoopMode)mode beforeDate: (OFDate *)deadline { void *pool = objc_autoreleasePoolPush(); OFRunLoopMode previousMode = _currentMode; OFRunLoopState *state = stateForMode(self, mode, false); if (state == nil) return; _currentMode = mode; @try { OFDate *nextTimer; #if defined(OF_AMIGAOS) && !defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) ULONG signalMask; #endif for (;;) { OFTimer *timer; #ifdef OF_HAVE_THREADS [state->_timersQueueMutex lock]; @try { #endif OFListItem listItem = state->_timersQueue.firstListItem; if (listItem != NULL && [OFListItemObject(listItem) fireDate] .timeIntervalSinceNow <= 0) { timer = [[OFListItemObject(listItem) retain] autorelease]; [state->_timersQueue removeListItem: listItem]; [timer of_setInRunLoop: nil mode: nil]; } else break; #ifdef OF_HAVE_THREADS } @finally { [state->_timersQueueMutex unlock]; } #endif |
︙ | ︙ | |||
1648 1649 1650 1651 1652 1653 1654 | } @finally { [state->_timersQueueMutex unlock]; } #endif /* Watch for I/O events until the next timer is due */ if (nextTimer != nil || deadline != nil) { | | | 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 | } @finally { [state->_timersQueueMutex unlock]; } #endif /* Watch for I/O events until the next timer is due */ if (nextTimer != nil || deadline != nil) { OFTimeInterval timeout; if (nextTimer != nil && deadline == nil) timeout = nextTimer.timeIntervalSinceNow; else if (nextTimer == nil && deadline != nil) timeout = deadline.timeIntervalSinceNow; else timeout = [nextTimer earlierDate: deadline] |
︙ | ︙ | |||
1722 1723 1724 1725 1726 1727 1728 | } @finally { _currentMode = previousMode; } } - (void)stop { | | < | 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 | } @finally { _currentMode = previousMode; } } - (void)stop { OFRunLoopState *state = stateForMode(self, OFDefaultRunLoopMode, false); _stop = true; if (state == nil) return; #if defined(OF_HAVE_SOCKETS) [state->_kernelEventObserver cancel]; #elif defined(OF_HAVE_THREADS) [state->_condition signal]; #endif } @end |
Modified src/OFRunLoop_constants.m from [6ecf96c8ce] to [e240ef8cad].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | 9 10 11 12 13 14 15 16 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ const OFRunLoopMode OFDefaultRunLoopMode = @"OFDefaultRunLoopMode"; |
Deleted src/OFSCTPSocket.h version [d059eb2dff].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/OFSCTPSocket.m version [a0edfc0fdf].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/OFSHA1Hash.h from [1ea7850492] to [96facd340e].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | | | | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFSHA1Hash OFSHA1Hash.h ObjFW/OFSHA1Hash.h * * @brief A class which provides methods to create an SHA-1 hash. */ OF_SUBCLASSING_RESTRICTED @interface OFSHA1Hash: OFObject <OFCryptographicHash> { OFSecureData *_iVarsData; struct { uint32_t state[5]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[80]; } buffer; size_t bufferLength; } *_iVars; bool _allowsSwappableMemory; bool _calculated; |
︙ | ︙ |
Modified src/OFSHA1Hash.m from [dc358c1aca] to [477f4216b9].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFSHA1Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #import "OFSHA1Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t digestSize = 20; static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFSHA1Hash () - (void)of_resetState; @end #define F(a, b, c, d) ((d) ^ ((b) & ((c) ^ (d)))) #define G(a, b, c, d) ((b) ^ (c) ^ (d)) #define H(a, b, c, d) (((b) & (c)) | ((d) & ((b) | (c)))) #define I(a, b, c, d) ((b) ^ (c) ^ (d)) static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[5]; uint_fast8_t i; new[0] = state[0]; new[1] = state[1]; new[2] = state[2]; new[3] = state[3]; new[4] = state[4]; byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 80; i++) { uint32_t tmp = buffer[i - 3] ^ buffer[i - 8] ^ buffer[i - 14] ^ buffer[i - 16]; buffer[i] = OFRotateLeft(tmp, 1); } #define LOOP_BODY(f, k) \ { \ uint32_t tmp = OFRotateLeft(new[0], 5) + \ f(new[0], new[1], new[2], new[3]) + \ new[4] + k + buffer[i]; \ new[4] = new[3]; \ new[3] = new[2]; \ new[2] = OFRotateLeft(new[1], 30); \ new[1] = new[0]; \ new[0] = tmp; \ } for (i = 0; i < 20; i++) LOOP_BODY(F, 0x5A827999) for (; i < 40; i++) |
︙ | ︙ | |||
97 98 99 100 101 102 103 | @implementation OFSHA1Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { | | | | | 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | @implementation OFSHA1Hash @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { return digestSize; } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { |
︙ | ︙ | |||
150 151 152 153 154 155 156 | [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { | | | | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | [_iVarsData release]; [super dealloc]; } - (size_t)digestSize { return digestSize; } - (size_t)blockSize { return blockSize; } - (id)copy { OFSHA1Hash *copy = [[OFSHA1Hash alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; |
︙ | ︙ | |||
179 180 181 182 183 184 185 | _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; _iVars->state[4] = 0xC3D2E1F0; } | | < | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | _iVars->state[0] = 0x67452301; _iVars->state[1] = 0xEFCDAB89; _iVars->state[2] = 0x98BADCFE; _iVars->state[3] = 0x10325476; _iVars->state[4] = 0xC3D2E1F0; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; |
︙ | ︙ | |||
219 220 221 222 223 224 225 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; | | | | | | | | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToBigEndian32((uint32_t)(_iVars->bits >> 32)); _iVars->buffer.words[15] = OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 5); _calculated = true; return (const unsigned char *)_iVars->state; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } @end |
Modified src/OFSHA224Hash.m from [e55abead15] to [e353b5b07a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFSHA224Hash.h" | | | | | 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 | * file. */ #include "config.h" #import "OFSHA224Hash.h" static const size_t digestSize = 28; @implementation OFSHA224Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0xC1059ED8; _iVars->state[1] = 0x367CD507; _iVars->state[2] = 0x3070DD17; |
︙ | ︙ |
Modified src/OFSHA224Or256Hash.h from [25d2fa7cb5] to [502962edb9].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | | | | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFSHA224Or256Hash OFSHA224Or256Hash.h ObjFW/OFSHA224Or256Hash.h * * @brief A base class for SHA-224 and SHA-256. */ @interface OFSHA224Or256Hash: OFObject <OFCryptographicHash> { @private OFSecureData *_iVarsData; @protected struct { uint32_t state[8]; uint64_t bits; union { unsigned char bytes[64]; uint32_t words[64]; } buffer; size_t bufferLength; } *_iVars; @private bool _allowsSwappableMemory; |
︙ | ︙ |
Modified src/OFSHA224Or256Hash.m from [06995323d9] to [e18ccf9292].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFSHA224Or256Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #import "OFSHA224Or256Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 64; @interface OFSHA224Or256Hash () - (void)of_resetState; @end static const uint32_t table[] = { 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, |
︙ | ︙ | |||
50 51 52 53 54 55 56 | }; static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | }; static OF_INLINE void byteSwapVectorIfLE(uint32_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap32(vector[i]); #endif } static void processBlock(uint32_t *state, uint32_t *buffer) { uint32_t new[8]; |
︙ | ︙ | |||
75 76 77 78 79 80 81 | byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 64; i++) { uint32_t tmp; tmp = buffer[i - 2]; | | | | | | | | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 64; i++) { uint32_t tmp; tmp = buffer[i - 2]; buffer[i] = (OFRotateRight(tmp, 17) ^ OFRotateRight(tmp, 19) ^ (tmp >> 10)) + buffer[i - 7]; tmp = buffer[i - 15]; buffer[i] += (OFRotateRight(tmp, 7) ^ OFRotateRight(tmp, 18) ^ (tmp >> 3)) + buffer[i - 16]; } for (i = 0; i < 64; i++) { uint32_t tmp1 = new[7] + (OFRotateRight(new[4], 6) ^ OFRotateRight(new[4], 11) ^ OFRotateRight(new[4], 25)) + ((new[4] & (new[5] ^ new[6])) ^ new[6]) + table[i] + buffer[i]; uint32_t tmp2 = (OFRotateRight(new[0], 2) ^ OFRotateRight(new[0], 13) ^ OFRotateRight(new[0], 22)) + ((new[0] & (new[1] | new[2])) | (new[1] & new[2])); new[7] = new[6]; new[6] = new[5]; new[5] = new[4]; new[4] = new[3] + tmp1; new[3] = new[2]; |
︙ | ︙ | |||
122 123 124 125 126 127 128 | + (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { | | | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | + (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { |
︙ | ︙ | |||
180 181 182 183 184 185 186 | - (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { | | | < | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | - (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { return blockSize; } - (id)copy { OFSHA224Or256Hash *copy = [[[self class] alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; copy->_iVars = copy->_iVarsData.mutableItems; copy->_allowsSwappableMemory = _allowsSwappableMemory; copy->_calculated = _calculated; return copy; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; |
︙ | ︙ | |||
235 236 237 238 239 240 241 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; | | | | | | | | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 64 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 56) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 64); } _iVars->buffer.words[14] = OFToBigEndian32((uint32_t)(_iVars->bits >> 32)); _iVars->buffer.words[15] = OFToBigEndian32((uint32_t)(_iVars->bits & 0xFFFFFFFF)); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; return (const unsigned char *)_iVars->state; } - (void)reset { [self of_resetState]; _iVars->bits = 0; OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } - (void)of_resetState { OF_UNRECOGNIZED_SELECTOR } @end |
Modified src/OFSHA256Hash.m from [56b5919949] to [2893893023].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFSHA256Hash.h" | | | | | 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 | * file. */ #include "config.h" #import "OFSHA256Hash.h" static const size_t digestSize = 32; @implementation OFSHA256Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667; _iVars->state[1] = 0xBB67AE85; _iVars->state[2] = 0x3C6EF372; |
︙ | ︙ |
Modified src/OFSHA384Hash.m from [66a0fe7cfd] to [91f9fc35e0].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFSHA384Hash.h" | | | | | 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 | * file. */ #include "config.h" #import "OFSHA384Hash.h" static const size_t digestSize = 48; @implementation OFSHA384Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0xCBBB9D5DC1059ED8; _iVars->state[1] = 0x629A292A367CD507; _iVars->state[2] = 0x9159015A3070DD17; |
︙ | ︙ |
Modified src/OFSHA384Or512Hash.h from [f783b37416] to [e05082b6ff].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | | | | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFCryptographicHash.h" OF_ASSUME_NONNULL_BEGIN @class OFSecureData; /** * @class OFSHA384Or512Hash OFSHA384Or512Hash.h ObjFW/OFSHA384Or512Hash.h * * @brief A base class for SHA-384 and SHA-512. */ @interface OFSHA384Or512Hash: OFObject <OFCryptographicHash> { @private OFSecureData *_iVarsData; @protected struct { uint64_t state[8]; uint64_t bits[2]; union { unsigned char bytes[128]; uint64_t words[80]; } buffer; size_t bufferLength; } *_iVars; @private bool _allowsSwappableMemory; |
︙ | ︙ |
Modified src/OFSHA384Or512Hash.m from [e89cdc8f14] to [e382c5ef41].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #import "OFSHA384Or512Hash.h" #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" static const size_t blockSize = 128; @interface OFSHA384Or512Hash () - (void)of_resetState; @end static const uint64_t table[] = { 0x428A2F98D728AE22, 0x7137449123EF65CD, 0xB5C0FBCFEC4D3B2F, |
︙ | ︙ | |||
61 62 63 64 65 66 67 | }; static OF_INLINE void byteSwapVectorIfLE(uint64_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | }; static OF_INLINE void byteSwapVectorIfLE(uint64_t *vector, uint_fast8_t length) { #ifndef OF_BIG_ENDIAN for (uint_fast8_t i = 0; i < length; i++) vector[i] = OFByteSwap64(vector[i]); #endif } static void processBlock(uint64_t *state, uint64_t *buffer) { uint64_t new[8]; |
︙ | ︙ | |||
86 87 88 89 90 91 92 | byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 80; i++) { uint64_t tmp; tmp = buffer[i - 2]; | | | | | | | | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | byteSwapVectorIfLE(buffer, 16); for (i = 16; i < 80; i++) { uint64_t tmp; tmp = buffer[i - 2]; buffer[i] = (OFRotateRight(tmp, 19) ^ OFRotateRight(tmp, 61) ^ (tmp >> 6)) + buffer[i - 7]; tmp = buffer[i - 15]; buffer[i] += (OFRotateRight(tmp, 1) ^ OFRotateRight(tmp, 8) ^ (tmp >> 7)) + buffer[i - 16]; } for (i = 0; i < 80; i++) { uint64_t tmp1 = new[7] + (OFRotateRight(new[4], 14) ^ OFRotateRight(new[4], 18) ^ OFRotateRight(new[4], 41)) + ((new[4] & (new[5] ^ new[6])) ^ new[6]) + table[i] + buffer[i]; uint64_t tmp2 = (OFRotateRight(new[0], 28) ^ OFRotateRight(new[0], 34) ^ OFRotateRight(new[0], 39)) + ((new[0] & (new[1] | new[2])) | (new[1] & new[2])); new[7] = new[6]; new[6] = new[5]; new[5] = new[4]; new[4] = new[3] + tmp1; new[3] = new[2]; |
︙ | ︙ | |||
133 134 135 136 137 138 139 | + (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { | | | | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | + (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: allowsSwappableMemory] autorelease]; } - (instancetype)initWithAllowsSwappableMemory: (bool)allowsSwappableMemory { |
︙ | ︙ | |||
191 192 193 194 195 196 197 | - (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { | | | < | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | - (size_t)digestSize { OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { return blockSize; } - (id)copy { OFSHA384Or512Hash *copy = [[[self class] alloc] of_init]; copy->_iVarsData = [_iVarsData copy]; copy->_iVars = copy->_iVarsData.mutableItems; copy->_allowsSwappableMemory = _allowsSwappableMemory; copy->_calculated = _calculated; return copy; } - (void)updateWithBuffer: (const void *)buffer_ length: (size_t)length { const unsigned char *buffer = buffer_; if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithObject: self]; |
︙ | ︙ | |||
248 249 250 251 252 253 254 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; | | | | | | | | | 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | - (const unsigned char *)digest { if (_calculated) return (const unsigned char *)_iVars->state; _iVars->buffer.bytes[_iVars->bufferLength] = 0x80; OFZeroMemory(_iVars->buffer.bytes + _iVars->bufferLength + 1, 128 - _iVars->bufferLength - 1); if (_iVars->bufferLength >= 112) { processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(_iVars->buffer.bytes, 128); } _iVars->buffer.words[14] = OFToBigEndian64(_iVars->bits[1]); _iVars->buffer.words[15] = OFToBigEndian64(_iVars->bits[0]); processBlock(_iVars->state, _iVars->buffer.words); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); byteSwapVectorIfLE(_iVars->state, 8); _calculated = true; return (const unsigned char *)_iVars->state; } - (void)reset { [self of_resetState]; OFZeroMemory(_iVars->bits, sizeof(_iVars->bits)); OFZeroMemory(&_iVars->buffer, sizeof(_iVars->buffer)); _iVars->bufferLength = 0; _calculated = false; } - (void)of_resetState { OF_UNRECOGNIZED_SELECTOR } @end |
Modified src/OFSHA512Hash.m from [6f5327a8ae] to [e1893194a7].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFSHA512Hash.h" | | | | | 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 | * file. */ #include "config.h" #import "OFSHA512Hash.h" static const size_t digestSize = 64; @implementation OFSHA512Hash + (size_t)digestSize { return digestSize; } - (size_t)digestSize { return digestSize; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667F3BCC908; _iVars->state[1] = 0xBB67AE8584CAA73B; _iVars->state[2] = 0x3C6EF372FE94F82B; |
︙ | ︙ |
Modified src/OFSPXSocket.h from [20d64f5e49] to [26e1e49cc2].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^OFSPXSocketAsyncConnectBlock)(id _Nullable exception); #endif /** * @protocol OFSPXSocketDelegate OFSPXSocket.h ObjFW/OFSPXSocket.h * * A delegate for OFSPXSocket. */ |
︙ | ︙ | |||
114 115 116 117 118 119 120 | * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port | | | | | | | 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 163 164 165 | * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * * @param node The node to connect to * @param network The network on which the node to connect to is * @param port The port (sometimes also called socket number) on the node to * connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port block: (OFSPXSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFSPXSocket to the specified destination. * * @param node The node to connect to * @param network The network on which the node to connect to is * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXSocketAsyncConnectBlock)block; #endif /** * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Modified src/OFSPXSocket.m from [2af60d4b14] to [1dcd330269].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 | #include "config.h" #include <errno.h> #import "OFSPXSocket.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" #import "OFConnectionFailedException.h" #import "OFNotOpenException.h" | > > < < < | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include "config.h" #include <errno.h> #import "OFSPXSocket.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" #import "OFConnectionFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 #endif static const uint8_t SPXPacketType = 5; @interface OFSPXSocket () - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end OF_DIRECT_MEMBERS @interface OFSPXSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate> { OFSPXSocket *_socket; unsigned char _node[IPX_NODE_LEN]; uint32_t _network; uint16_t _port; #ifdef OF_HAVE_BLOCKS OFSPXSocketAsyncConnectBlock _block; #endif } - (instancetype)initWithSocket: (OFSPXSocket *)socket node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif ; - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end @implementation OFSPXSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXSocket *)sock node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; memcpy(_node, node, IPX_NODE_LEN); |
︙ | ︙ | |||
99 100 101 102 103 104 105 | #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } | | | | | < | > | > > | < | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = OFSocketAddressMakeIPX(_node, _network, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; goto inform_delegate; } _socket.canBlock = false; if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) { #ifdef OF_WINDOWS if (errNo == EINPROGRESS || errNo == EWOULDBLOCK) { #else if (errNo == EINPROGRESS) { #endif [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } [_socket of_closeSocket]; exception = [self of_connectionFailedExceptionForErrNo: errNo]; } inform_delegate: [self performSelector: @selector(of_socketDidConnect:exception:) withObject: _socket withObject: exception afterDelay: 0]; } - (void)of_socketDidConnect: (id)sock exception: (id)exception { id <OFSPXSocketDelegate> delegate = ((OFSPXSocket *)sock).delegate; if (exception == nil) ((OFSPXSocket *)sock).canBlock = true; #ifdef OF_HAVE_BLOCKS |
︙ | ︙ | |||
173 174 175 176 177 178 179 | errNo: errNo]; } @end @implementation OFSPXSocket @dynamic delegate; | | | | > | | | | | < | | < | < | | | | | | | | | | | > | | | | | | | | | | | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | errNo: errNo]; } @end @implementation OFSPXSocket @dynamic delegate; - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if ((_socket = socket(address->sockaddr.ipx.sipx_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) { *errNo = OFSocketErrNo(); return false; } #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif return true; } - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (connect(_socket, &address->sockaddr.sockaddr, address->length) != 0) { *errNo = OFSocketErrNo(); return false; } return true; } - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectionFailedException exceptionWithNode: node network: network port: port socket: self errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; @throw [OFConnectionFailedException exceptionWithNode: node network: network port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { [self asyncConnectToNode: node network: network port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self node: node network: network port: port #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port block: (OFSPXSocketAsyncConnectBlock)block { [self asyncConnectToNode: node network: network port: port runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXSocketAsyncConnectDelegate alloc] initWithSocket: self node: node network: network port: port block: block ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif - (OFSocketAddress)bindToPort: (uint16_t)port { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; address = OFSocketAddressMakeIPX(zeroNode, 0, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (OFGetSockName(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } if (address.sockaddr.sockaddr.sa_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: EAFNOSUPPORT]; } return address; } @end |
Modified src/OFSPXStreamSocket.h from [9b835a4c0b] to [8a40db9be9].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ | < | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^OFSPXStreamSocketAsyncConnectBlock)(id _Nullable exception); #endif /** * @protocol OFSPXStreamSocketDelegate OFSPXStreamSocket.h \ * ObjFW/OFSPXStreamSocket.h * * A delegate for OFSPXStreamSocket. |
︙ | ︙ | |||
118 119 120 121 122 123 124 | * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port | | | | | | | 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 163 164 165 166 167 168 169 170 | * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * * @param node The node to connect to * @param network The network on which the node to connect to is * @param port The port (sometimes also called socket number) on the node to * connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port block: (OFSPXStreamSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFSPXStreamSocket to the specified * destination. * * @param node The node to connect to * @param network The network on which the node to connect to is * @param port The port (sometimes also called socket number) on the node to * connect to * @param runLoopMode The run loop mode in which to perform the async connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXStreamSocketAsyncConnectBlock)block; #endif /** * @brief Bind the socket to the specified network, node and port. * * @param port The port (sometimes called socket number) to bind to. 0 means to * pick one and return it. * @return The address on which this socket can be reached */ - (OFSocketAddress)bindToPort: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Modified src/OFSPXStreamSocket.m from [8baafe8070] to [d6a9ec0451].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 | #include "config.h" #include <errno.h> #import "OFSPXStreamSocket.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" #import "OFConnectionFailedException.h" #import "OFNotOpenException.h" | > > < < < | | | | < | | < | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #include "config.h" #include <errno.h> #import "OFSPXStreamSocket.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" #import "OFConnectionFailedException.h" #import "OFNotOpenException.h" #ifndef NSPROTO_SPX # define NSPROTO_SPX 0 #endif static const uint8_t SPXPacketType = 5; @interface OFSPXStreamSocket () - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo; - (void)of_closeSocket; @end OF_DIRECT_MEMBERS @interface OFSPXStreamSocketAsyncConnectDelegate: OFObject <OFRunLoopConnectDelegate> { OFSPXStreamSocket *_socket; unsigned char _node[IPX_NODE_LEN]; uint32_t _network; uint16_t _port; #ifdef OF_HAVE_BLOCKS OFSPXStreamSocketAsyncConnectBlock _block; #endif } - (instancetype)initWithSocket: (OFSPXStreamSocket *)socket node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif ; - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode; @end @implementation OFSPXStreamSocketAsyncConnectDelegate - (instancetype)initWithSocket: (OFSPXStreamSocket *)sock node: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port #ifdef OF_HAVE_BLOCKS block: (OFSPXStreamSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; memcpy(_node, node, IPX_NODE_LEN); |
︙ | ︙ | |||
102 103 104 105 106 107 108 | #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } | | | | | < | > | > > | < | 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #ifdef OF_HAVE_BLOCKS [_block release]; #endif [super dealloc]; } - (void)startWithRunLoopMode: (OFRunLoopMode)runLoopMode { OFSocketAddress address = OFSocketAddressMakeIPX(_node, _network, _port); id exception = nil; int errNo; if (![_socket of_createSocketForAddress: &address errNo: &errNo]) { exception = [self of_connectionFailedExceptionForErrNo: errNo]; goto inform_delegate; } _socket.canBlock = false; if (![_socket of_connectSocketToAddress: &address errNo: &errNo]) { #ifdef OF_WINDOWS if (errNo == EINPROGRESS || errNo == EWOULDBLOCK) { #else if (errNo == EINPROGRESS) { #endif [OFRunLoop of_addAsyncConnectForSocket: _socket mode: runLoopMode delegate: self]; return; } [_socket of_closeSocket]; exception = [self of_connectionFailedExceptionForErrNo: errNo]; } inform_delegate: [self performSelector: @selector(of_socketDidConnect:exception:) withObject: _socket withObject: exception afterDelay: 0]; } - (void)of_socketDidConnect: (id)sock exception: (id)exception { id <OFSPXStreamSocketDelegate> delegate = ((OFSPXStreamSocket *)sock).delegate; if (exception == nil) ((OFSPXStreamSocket *)sock).canBlock = true; |
︙ | ︙ | |||
177 178 179 180 181 182 183 | errNo: errNo]; } @end @implementation OFSPXStreamSocket @dynamic delegate; | | | | > | | | | | < | | < | < | | | | | | | | | | | | | | | | | | | | | | | | 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 | errNo: errNo]; } @end @implementation OFSPXStreamSocket @dynamic delegate; - (int)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if ((_socket = socket(address->sockaddr.ipx.sipx_family, SOCK_SEQPACKET | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) { *errNo = OFSocketErrNo(); return false; } #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif return true; } - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (connect(_socket, &address->sockaddr.sockaddr, address->length) != 0) { *errNo = OFSocketErrNo(); return false; } return true; } - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { OFSocketAddress address = OFSocketAddressMakeIPX(node, network, port); int errNo; if (![self of_createSocketForAddress: &address errNo: &errNo]) @throw [OFConnectionFailedException exceptionWithNode: node network: network port: port socket: self errNo: errNo]; if (![self of_connectSocketToAddress: &address errNo: &errNo]) { [self of_closeSocket]; @throw [OFConnectionFailedException exceptionWithNode: node network: network port: port socket: self errNo: errNo]; } } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port { [self asyncConnectToNode: node network: network port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXStreamSocketAsyncConnectDelegate alloc] initWithSocket: self node: node network: network port: port #ifdef OF_HAVE_BLOCKS block: NULL #endif ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port block: (OFSPXStreamSocketAsyncConnectBlock)block { [self asyncConnectToNode: node network: network port: port runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToNode: (unsigned char [_Nonnull IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSPXStreamSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); [[[[OFSPXStreamSocketAsyncConnectDelegate alloc] initWithSocket: self node: node network: network port: port block: block ] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif - (OFSocketAddress)bindToPort: (uint16_t)port { const unsigned char zeroNode[IPX_NODE_LEN] = { 0 }; OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; address = OFSocketAddressMakeIPX(zeroNode, 0, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, NSPROTO_SPX)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL_H) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } memset(&address, 0, sizeof(address)); address.family = OFSocketAddressFamilyIPX; address.length = (socklen_t)sizeof(address.sockaddr); if (OFGetSockName(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: errNo]; } if (address.sockaddr.sockaddr.sa_family != AF_IPX) { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithPort: port packetType: SPXPacketType socket: self errNo: EAFNOSUPPORT]; } return address; } @end |
Modified src/OFSandbox.h from [a2013331bb] to [6bf325540a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN | < < < < < < | < < < < < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFPair OF_GENERIC(FirstType, SecondType); typedef OFPair OF_GENERIC(OFString *, OFString *) *OFSandboxUnveilPath; @interface OFSandbox: OFObject <OFCopying> { unsigned int _allowsStdIO: 1; unsigned int _allowsReadingFiles: 1; unsigned int _allowsWritingFiles: 1; unsigned int _allowsCreatingFiles: 1; unsigned int _allowsCreatingSpecialFiles: 1; |
︙ | ︙ | |||
62 63 64 65 66 67 68 | unsigned int _allowsVMInfo: 1; unsigned int _allowsChangingProcessRights: 1; unsigned int _allowsPF: 1; unsigned int _allowsAudio: 1; unsigned int _allowsBPF: 1; unsigned int _allowsUnveil: 1; unsigned int _returnsErrors: 1; | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < | < | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | unsigned int _allowsVMInfo: 1; unsigned int _allowsChangingProcessRights: 1; unsigned int _allowsPF: 1; unsigned int _allowsAudio: 1; unsigned int _allowsBPF: 1; unsigned int _allowsUnveil: 1; unsigned int _returnsErrors: 1; OFMutableArray OF_GENERIC(OFSandboxUnveilPath) *_unveiledPaths; @public size_t _unveiledPathsIndex; OF_RESERVE_IVARS(OFSandbox, 4) } @property (nonatomic) bool allowsStdIO; @property (nonatomic) bool allowsReadingFiles; @property (nonatomic) bool allowsWritingFiles; @property (nonatomic) bool allowsCreatingFiles; @property (nonatomic) bool allowsCreatingSpecialFiles; @property (nonatomic) bool allowsTemporaryFiles; @property (nonatomic) bool allowsIPSockets; @property (nonatomic) bool allowsMulticastSockets; @property (nonatomic) bool allowsChangingFileAttributes; @property (nonatomic) bool allowsFileOwnerChanges; @property (nonatomic) bool allowsFileLocks; @property (nonatomic) bool allowsUNIXSockets; @property (nonatomic) bool allowsDNS; @property (nonatomic) bool allowsUserDatabaseReading; @property (nonatomic) bool allowsFileDescriptorSending; @property (nonatomic) bool allowsFileDescriptorReceiving; @property (nonatomic) bool allowsTape; @property (nonatomic) bool allowsTTY; @property (nonatomic) bool allowsProcessOperations; @property (nonatomic) bool allowsExec; @property (nonatomic) bool allowsProtExec; @property (nonatomic) bool allowsSetTime; @property (nonatomic) bool allowsPS; @property (nonatomic) bool allowsVMInfo; @property (nonatomic) bool allowsChangingProcessRights; @property (nonatomic) bool allowsPF; @property (nonatomic) bool allowsAudio; @property (nonatomic) bool allowsBPF; @property (nonatomic) bool allowsUnveil; @property (nonatomic) bool returnsErrors; #ifdef OF_HAVE_PLEDGE @property (readonly, nonatomic) OFString *pledgeString; #endif @property (readonly, nonatomic) OFArray OF_GENERIC(OFSandboxUnveilPath) *unveiledPaths; + (instancetype)sandbox; - (void)unveilPath: (OFString *)path permissions: (OFString *)permissions; @end OF_ASSUME_NONNULL_END |
Modified src/OFSandbox.m from [c9f40044df] to [5d133469cf].
︙ | ︙ | |||
465 466 467 468 469 470 471 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAdd(&hash, _allowsStdIO); OFHashAdd(&hash, _allowsReadingFiles); OFHashAdd(&hash, _allowsWritingFiles); OFHashAdd(&hash, _allowsCreatingFiles); OFHashAdd(&hash, _allowsCreatingSpecialFiles); OFHashAdd(&hash, _allowsTemporaryFiles); OFHashAdd(&hash, _allowsIPSockets); OFHashAdd(&hash, _allowsMulticastSockets); OFHashAdd(&hash, _allowsChangingFileAttributes); OFHashAdd(&hash, _allowsFileOwnerChanges); OFHashAdd(&hash, _allowsFileLocks); OFHashAdd(&hash, _allowsUNIXSockets); OFHashAdd(&hash, _allowsDNS); OFHashAdd(&hash, _allowsUserDatabaseReading); OFHashAdd(&hash, _allowsFileDescriptorSending); OFHashAdd(&hash, _allowsFileDescriptorReceiving); OFHashAdd(&hash, _allowsTape); OFHashAdd(&hash, _allowsTTY); OFHashAdd(&hash, _allowsProcessOperations); OFHashAdd(&hash, _allowsExec); OFHashAdd(&hash, _allowsProtExec); OFHashAdd(&hash, _allowsSetTime); OFHashAdd(&hash, _allowsPS); OFHashAdd(&hash, _allowsVMInfo); OFHashAdd(&hash, _allowsChangingProcessRights); OFHashAdd(&hash, _allowsPF); OFHashAdd(&hash, _allowsAudio); OFHashAdd(&hash, _allowsBPF); OFHashAdd(&hash, _allowsUnveil); OFHashAdd(&hash, _returnsErrors); OFHashFinalize(&hash); return hash; } #ifdef OF_HAVE_PLEDGE - (OFString *)pledgeString { |
︙ | ︙ | |||
583 584 585 586 587 588 589 | objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif | | < | | 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | objc_autoreleasePoolPop(pool); return [ret autorelease]; } #endif - (void)unveilPath: (OFString *)path permissions: (OFString *)permissions { void *pool = objc_autoreleasePoolPush(); [_unveiledPaths addObject: [OFPair pairWithFirstObject: path secondObject: permissions]]; objc_autoreleasePoolPop(pool); } - (OFArray OF_GENERIC(OFSandboxUnveilPath) *)unveiledPaths { return [[_unveiledPaths copy] autorelease]; } @end |
Renamed and modified src/scrypt.h [c03ec2d00d] to src/OFScrypt.h [8506d6db7e].
︙ | ︙ | |||
25 26 27 28 29 30 31 | OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFHMAC; /** | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFHMAC; /** * @brief The parameters for @ref OFScrypt. */ typedef struct { /** @brief The block size to use. */ size_t blockSize; /** @brief The CPU/memory cost factor to use. */ size_t costFactor; /** @brief The parallelization to use. */ size_t parallelization; /** @brief The salt to derive a key with. */ |
︙ | ︙ | |||
52 53 54 55 56 57 58 | * @brief The desired length for the derived key. * * @ref key needs to have enough storage. */ size_t keyLength; /** @brief Whether data may be stored in swappable memory. */ bool allowsSwappableMemory; | | | | | | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | * @brief The desired length for the derived key. * * @ref key needs to have enough storage. */ size_t keyLength; /** @brief Whether data may be stored in swappable memory. */ bool allowsSwappableMemory; } OFScryptParameters; #ifdef __cplusplus extern "C" { #endif extern void OFSalsa20_8Core(uint32_t buffer[_Nonnull 16]); extern void OFScryptBlockMix(uint32_t *output, const uint32_t *input, size_t blockSize); extern void OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp); /** * @brief Derives a key from a password and a salt using scrypt. * * @param parameters The parameters to use */ extern void OFScrypt(OFScryptParameters parameters); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Renamed and modified src/scrypt.m [1396dd3e07] to src/OFScrypt.m [9e41cca4b0].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFSHA256Hash.h" #import "OFSecureData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #import "OFSHA256Hash.h" #import "OFSecureData.h" #import "OFInvalidArgumentException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFScrypt.h" #import "OFPBKDF2.h" void OFSalsa20_8Core(uint32_t buffer[16]) { uint32_t tmp[16]; for (uint_fast8_t i = 0; i < 16; i++) tmp[i] = OFToLittleEndian32(buffer[i]); for (uint_fast8_t i = 0; i < 8; i += 2) { tmp[ 4] ^= OFRotateLeft(tmp[ 0] + tmp[12], 7); tmp[ 8] ^= OFRotateLeft(tmp[ 4] + tmp[ 0], 9); tmp[12] ^= OFRotateLeft(tmp[ 8] + tmp[ 4], 13); tmp[ 0] ^= OFRotateLeft(tmp[12] + tmp[ 8], 18); tmp[ 9] ^= OFRotateLeft(tmp[ 5] + tmp[ 1], 7); tmp[13] ^= OFRotateLeft(tmp[ 9] + tmp[ 5], 9); tmp[ 1] ^= OFRotateLeft(tmp[13] + tmp[ 9], 13); tmp[ 5] ^= OFRotateLeft(tmp[ 1] + tmp[13], 18); tmp[14] ^= OFRotateLeft(tmp[10] + tmp[ 6], 7); tmp[ 2] ^= OFRotateLeft(tmp[14] + tmp[10], 9); tmp[ 6] ^= OFRotateLeft(tmp[ 2] + tmp[14], 13); tmp[10] ^= OFRotateLeft(tmp[ 6] + tmp[ 2], 18); tmp[ 3] ^= OFRotateLeft(tmp[15] + tmp[11], 7); tmp[ 7] ^= OFRotateLeft(tmp[ 3] + tmp[15], 9); tmp[11] ^= OFRotateLeft(tmp[ 7] + tmp[ 3], 13); tmp[15] ^= OFRotateLeft(tmp[11] + tmp[ 7], 18); tmp[ 1] ^= OFRotateLeft(tmp[ 0] + tmp[ 3], 7); tmp[ 2] ^= OFRotateLeft(tmp[ 1] + tmp[ 0], 9); tmp[ 3] ^= OFRotateLeft(tmp[ 2] + tmp[ 1], 13); tmp[ 0] ^= OFRotateLeft(tmp[ 3] + tmp[ 2], 18); tmp[ 6] ^= OFRotateLeft(tmp[ 5] + tmp[ 4], 7); tmp[ 7] ^= OFRotateLeft(tmp[ 6] + tmp[ 5], 9); tmp[ 4] ^= OFRotateLeft(tmp[ 7] + tmp[ 6], 13); tmp[ 5] ^= OFRotateLeft(tmp[ 4] + tmp[ 7], 18); tmp[11] ^= OFRotateLeft(tmp[10] + tmp[ 9], 7); tmp[ 8] ^= OFRotateLeft(tmp[11] + tmp[10], 9); tmp[ 9] ^= OFRotateLeft(tmp[ 8] + tmp[11], 13); tmp[10] ^= OFRotateLeft(tmp[ 9] + tmp[ 8], 18); tmp[12] ^= OFRotateLeft(tmp[15] + tmp[14], 7); tmp[13] ^= OFRotateLeft(tmp[12] + tmp[15], 9); tmp[14] ^= OFRotateLeft(tmp[13] + tmp[12], 13); tmp[15] ^= OFRotateLeft(tmp[14] + tmp[13], 18); } for (uint_fast8_t i = 0; i < 16; i++) buffer[i] = OFToLittleEndian32(OFFromLittleEndian32(buffer[i]) + tmp[i]); OFZeroMemory(tmp, sizeof(tmp)); } void OFScryptBlockMix(uint32_t *output, const uint32_t *input, size_t blockSize) { uint32_t tmp[16]; /* Check defined here and executed in OFScrypt() */ #define OVERFLOW_CHECK_1 \ if (param.blockSize > SIZE_MAX / 2 || \ 2 * param.blockSize - 1 > SIZE_MAX / 16) \ @throw [OFOutOfRangeException exception]; memcpy(tmp, input + (2 * blockSize - 1) * 16, 64); for (size_t i = 0; i < 2 * blockSize; i++) { for (size_t j = 0; j < 16; j++) tmp[j] ^= input[i * 16 + j]; OFSalsa20_8Core(tmp); /* * Even indices are stored in the first half and odd ones in * the second. */ memcpy(output + ((i / 2) + (i & 1) * blockSize) * 16, tmp, 64); } OFZeroMemory(tmp, sizeof(tmp)); } void OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp) { /* Check defined here and executed in OFScrypt() */ #define OVERFLOW_CHECK_2 \ if (param.blockSize > SIZE_MAX / 128 / param.costFactor) \ @throw [OFOutOfRangeException exception]; uint32_t *tmp2 = tmp + 32 * blockSize; memcpy(tmp, buffer, 128 * blockSize); for (size_t i = 0; i < costFactor; i++) { memcpy(tmp2 + i * 32 * blockSize, tmp, 128 * blockSize); OFScryptBlockMix(tmp, tmp2 + i * 32 * blockSize, blockSize); } for (size_t i = 0; i < costFactor; i++) { uint32_t j = OFFromLittleEndian32( tmp[(2 * blockSize - 1) * 16]) & (costFactor - 1); for (size_t k = 0; k < 32 * blockSize; k++) tmp[k] ^= tmp2[j * 32 * blockSize + k]; OFScryptBlockMix(buffer, tmp, blockSize); if (i < costFactor - 1) memcpy(tmp, buffer, 128 * blockSize); } } void OFScrypt(OFScryptParameters param) { OFSecureData *tmp = nil, *buffer = nil; OFHMAC *HMAC = nil; if (param.blockSize == 0 || param.costFactor <= 1 || (param.costFactor & (param.costFactor - 1)) != 0 || param.parallelization == 0) |
︙ | ︙ | |||
178 179 180 181 182 183 184 | allowsSwappableMemory: param.allowsSwappableMemory]; bufferItems = buffer.mutableItems; HMAC = [[OFHMAC alloc] initWithHashClass: [OFSHA256Hash class] allowsSwappableMemory: param.allowsSwappableMemory]; | | | | | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | allowsSwappableMemory: param.allowsSwappableMemory]; bufferItems = buffer.mutableItems; HMAC = [[OFHMAC alloc] initWithHashClass: [OFSHA256Hash class] allowsSwappableMemory: param.allowsSwappableMemory]; OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 1, .salt = param.salt, .saltLength = param.saltLength, .password = param.password, .passwordLength = param.passwordLength, .key = (unsigned char *)bufferItems, .keyLength = param.parallelization * 128 * param.blockSize, .allowsSwappableMemory = param.allowsSwappableMemory }); for (size_t i = 0; i < param.parallelization; i++) OFScryptROMix(bufferItems + i * 32 * param.blockSize, param.blockSize, param.costFactor, tmpItems); OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 1, .salt = (unsigned char *)bufferItems, .saltLength = param.parallelization * 128 * param.blockSize, .password = param.password, .passwordLength = param.passwordLength, |
︙ | ︙ |
Modified src/OFSecureData.h from [3c696dcd02] to [69bd454c65].
︙ | ︙ | |||
28 29 30 31 32 33 34 | * deallocated. Check the @ref allowsSwappableMemory property to see * whether a particular OFSecureData might be allocated in swappable * memory. */ OF_SUBCLASSING_RESTRICTED @interface OFSecureData: OFData { | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | * deallocated. Check the @ref allowsSwappableMemory property to see * whether a particular OFSecureData might be allocated in swappable * memory. */ OF_SUBCLASSING_RESTRICTED @interface OFSecureData: OFData { void *_page; bool _allowsSwappableMemory; } /** * @brief Whether the data may be stored in swappable memory. */ @property (readonly, nonatomic) bool allowsSwappableMemory; |
︙ | ︙ |
Modified src/OFSecureData.m from [3993fa04e8] to [80f9f47dea].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #ifdef HAVE_SYS_MMAN_H # include <sys/mman.h> #endif #import "OFSecureData.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" | > > > | < < | < < | | | | | | | | | | | 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 61 62 63 64 65 | #ifdef HAVE_SYS_MMAN_H # include <sys/mman.h> #endif #import "OFSecureData.h" #import "OFString.h" #import "OFSystemInfo.h" #ifdef OF_HAVE_THREADS # import "OFTLSKey.h" #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) static const size_t chunkSize = 16; struct Page { struct Page *next, *previous; void *map; unsigned char *page; }; # if defined(OF_HAVE_COMPILER_TLS) static thread_local struct Page *firstPage = NULL; static thread_local struct Page *lastPage = NULL; static thread_local struct Page **preallocatedPages = NULL; static thread_local size_t numPreallocatedPages = 0; # elif defined(OF_HAVE_THREADS) static OFTLSKey firstPageKey, lastPageKey; static OFTLSKey preallocatedPagesKey, numPreallocatedPagesKey; # else static struct Page *firstPage = NULL; static struct Page *lastPage = NULL; static struct Page **preallocatedPages = NULL; static size_t numPreallocatedPages = 0; # endif static void * mapPages(size_t numPages) { size_t pageSize = [OFSystemInfo pageSize]; |
︙ | ︙ | |||
91 92 93 94 95 96 97 | if (numPages > SIZE_MAX / pageSize) @throw [OFOutOfRangeException exception]; munlock(pointer, numPages * pageSize); munmap(pointer, numPages * pageSize); } | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | if (numPages > SIZE_MAX / pageSize) @throw [OFOutOfRangeException exception]; munlock(pointer, numPages * pageSize); munmap(pointer, numPages * pageSize); } static struct Page * addPage(bool allowPreallocated) { size_t pageSize = [OFSystemInfo pageSize]; size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / chunkSize) / 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) uintptr_t numPreallocatedPages = (uintptr_t)OFTLSKeyGet(numPreallocatedPagesKey); # endif if (numPreallocatedPages > 0) { # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct Page **preallocatedPages = OFTLSKeyGet(preallocatedPagesKey); # endif numPreallocatedPages--; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(numPreallocatedPagesKey, (void *)numPreallocatedPages) == 0); # endif page = preallocatedPages[numPreallocatedPages]; if (numPreallocatedPages == 0) { OFFreeMemory(preallocatedPages); preallocatedPages = NULL; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(preallocatedPagesKey, preallocatedPages) == 0); # endif } return page; } } page = OFAllocMemory(1, sizeof(*page)); @try { page->map = OFAllocZeroedMemory(1, mapSize); } @catch (id e) { OFFreeMemory(page); @throw e; } @try { page->page = mapPages(1); } @catch (id e) { OFFreeMemory(page->map); OFFreeMemory(page); @throw e; } OFZeroMemory(page->page, pageSize); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) lastPage = OFTLSKeyGet(lastPageKey); # endif page->previous = lastPage; page->next = NULL; if (lastPage != NULL) lastPage->next = page; # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) lastPage = page; if (firstPage == NULL) firstPage = page; # else OFEnsure(OFTLSKeySet(lastPageKey, page) == 0); if (OFTLSKeyGet(firstPageKey) == NULL) OFEnsure(OFTLSKeySet(firstPageKey, page) == 0); # endif return page; } static void removePageIfEmpty(struct Page *page) { unsigned char *map = page->map; size_t pageSize = [OFSystemInfo pageSize]; size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / chunkSize) / CHAR_BIT; for (size_t i = 0; i < mapSize; i++) if (map[i] != 0) return; unmapPages(page->page, 1); OFFreeMemory(page->map); if (page->previous != NULL) page->previous->next = page->next; if (page->next != NULL) page->next->previous = page->previous; # if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) if (firstPage == page) firstPage = page->next; if (lastPage == page) lastPage = page->previous; # else if (OFTLSKeyGet(firstPageKey) == page) OFEnsure(OFTLSKeySet(firstPageKey, page->next) == 0); if (OFTLSKeyGet(lastPageKey) == page) OFEnsure(OFTLSKeySet(lastPageKey, page->previous) == 0); # endif OFFreeMemory(page); } static void * allocateMemory(struct Page *page, size_t bytes) { size_t chunks, chunksLeft, pageSize, i, firstChunk; bytes = OFRoundUpToPowerOf2(chunkSize, bytes); chunks = chunksLeft = bytes / chunkSize; firstChunk = 0; pageSize = [OFSystemInfo pageSize]; for (i = 0; i < pageSize / chunkSize; i++) { if (OFBitsetIsSet(page->map, i)) { chunksLeft = chunks; firstChunk = i + 1; continue; } if (--chunksLeft == 0) break; } if (chunksLeft == 0) { for (size_t j = firstChunk; j < firstChunk + chunks; j++) OFBitsetSet(page->map, j); return page->page + (chunkSize * firstChunk); } return NULL; } static void freeMemory(struct Page *page, void *pointer, size_t bytes) { size_t chunks, chunkIndex; bytes = OFRoundUpToPowerOf2(chunkSize, bytes); chunks = bytes / chunkSize; chunkIndex = ((uintptr_t)pointer - (uintptr_t)page->page) / chunkSize; OFZeroMemory(pointer, bytes); for (size_t i = 0; i < chunks; i++) OFBitsetClear(page->map, chunkIndex + i); } #endif @implementation OFSecureData @synthesize allowsSwappableMemory = _allowsSwappableMemory; #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) && \ !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) + (void)initialize { if (self != [OFSecureData class]) return; if (OFTLSKeyNew(&firstPageKey) != 0 || OFTLSKeyNew(&lastPageKey) != 0 || OFTLSKeyNew(&preallocatedPagesKey) != 0 || OFTLSKeyNew(&numPreallocatedPagesKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } #endif + (void)preallocateUnswappableMemoryWithSize: (size_t)size { #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) size_t pageSize = [OFSystemInfo pageSize]; size_t numPages = OFRoundUpToPowerOf2(pageSize, size) / pageSize; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct Page **preallocatedPages = OFTLSKeyGet(preallocatedPagesKey); size_t numPreallocatedPages; # endif size_t i; if (preallocatedPages != NULL) @throw [OFInvalidArgumentException exception]; preallocatedPages = OFAllocZeroedMemory(numPages, sizeof(struct Page)); # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(preallocatedPagesKey, preallocatedPages) == 0); # endif @try { for (i = 0; i < numPages; i++) preallocatedPages[i] = addPage(false); } @catch (id e) { for (size_t j = 0; j < i; j++) removePageIfEmpty(preallocatedPages[j]); OFFreeMemory(preallocatedPages); preallocatedPages = NULL; @throw e; } numPreallocatedPages = numPages; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFEnsure(OFTLSKeySet(numPreallocatedPagesKey, (void *)(uintptr_t)numPreallocatedPages) == 0); # endif #else @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; #endif } + (instancetype)dataWithCount: (size_t)count allowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithCount: count allowsSwappableMemory: allowsSwappableMemory] autorelease]; } + (instancetype)dataWithCount: (size_t)count itemSize: (size_t)itemSize allowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithCount: count itemSize: itemSize allowsSwappableMemory: allowsSwappableMemory] autorelease]; } |
︙ | ︙ | |||
412 413 414 415 416 417 418 | size_t pageSize = [OFSystemInfo pageSize]; #endif if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; if (allowsSwappableMemory) { | | | | | | 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | size_t pageSize = [OFSystemInfo pageSize]; #endif if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; if (allowsSwappableMemory) { _items = OFAllocMemory(count, itemSize); _freeWhenDone = true; memset(_items, 0, count * itemSize); #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) } else if (count * itemSize >= pageSize) _items = mapPages(OFRoundUpToPowerOf2(pageSize, count * itemSize) / pageSize); else { # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct Page *lastPage = OFTLSKeyGet(lastPageKey); # endif for (struct Page *page = lastPage; page != NULL; page = page->previous) { _items = allocateMemory(page, count * itemSize); if (_items != NULL) { _page = page; break; } |
︙ | ︙ | |||
463 464 465 466 467 468 469 | [self release]; @throw e; } return self; } | | < | 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | [self release]; @throw e; } return self; } - (instancetype)initWithItems: (const void *)items count: (size_t)count { OF_INVALID_INIT_METHOD } - (instancetype)initWithItems: (const void *)items count: (size_t)count itemSize: (size_t)itemSize |
︙ | ︙ | |||
528 529 530 531 532 533 534 | #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) if (!_allowsSwappableMemory) { size_t pageSize = [OFSystemInfo pageSize]; if (_count * _itemSize > pageSize) unmapPages(_items, | | | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) if (!_allowsSwappableMemory) { size_t pageSize = [OFSystemInfo pageSize]; if (_count * _itemSize > pageSize) unmapPages(_items, OFRoundUpToPowerOf2(pageSize, _count * _itemSize) / pageSize); else if (_page != NULL) { if (_items != NULL) freeMemory(_page, _items, _count * _itemSize); removePageIfEmpty(_page); } |
︙ | ︙ | |||
557 558 559 560 561 562 563 | @throw [OFOutOfRangeException exception]; return _items + idx * _itemSize; } - (void)zero { | | | 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | @throw [OFOutOfRangeException exception]; return _items + idx * _itemSize; } - (void)zero { OFZeroMemory(_items, _count * _itemSize); } - (id)copy { OFSecureData *copy = [[OFSecureData alloc] initWithCount: _count itemSize: _itemSize |
︙ | ︙ |
Modified src/OFSeekableStream.h from [5d719e292c] to [641ac47994].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #endif #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN #if defined(OF_WINDOWS) | | | | | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #endif #import "OFStream.h" OF_ASSUME_NONNULL_BEGIN #if defined(OF_WINDOWS) typedef __int64 OFFileOffset; #elif defined(OF_ANDROID) typedef long long OFFileOffset; #elif defined(OF_MORPHOS) typedef signed long long OFFileOffset; #elif defined(OF_HAVE_OFF64_T) typedef off64_t OFFileOffset; #else typedef off_t OFFileOffset; #endif /** * @class OFSeekableStream OFSeekableStream.h ObjFW/OFSeekableStream.h * * @brief A stream that supports seeking. * |
︙ | ︙ | |||
67 68 69 70 71 72 73 | * Value | Description * -----------|--------------------------------------- * `SEEK_SET` | Seek to the specified byte * `SEEK_CUR` | Seek to the current location + offset * `SEEK_END` | Seek to the end of the stream + offset * @return The new offset form the start of the file */ | < | < | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | * Value | Description * -----------|--------------------------------------- * `SEEK_SET` | Seek to the specified byte * `SEEK_CUR` | Seek to the current location + offset * `SEEK_END` | Seek to the end of the stream + offset * @return The new offset form the start of the file */ - (OFFileOffset)seekToOffset: (OFFileOffset)offset whence: (int)whence; /** * @brief Seek the stream on the lowlevel. * * @warning Do not call this directly! * * @note Override this method with your actual seek implementation when * subclassing! * * @param offset The offset to seek to * @param whence From where to seek.@n * Possible values are: * Value | Description * -----------|--------------------------------------- * `SEEK_SET` | Seek to the specified byte * `SEEK_CUR` | Seek to the current location + offset * `SEEK_END` | Seek to the end of the stream + offset * @return The new offset from the start of the file */ - (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence; @end OF_ASSUME_NONNULL_END |
Modified src/OFSeekableStream.m from [e6908a8ef1] to [6ce5b58b54].
︙ | ︙ | |||
34 35 36 37 38 39 40 | @throw e; } } return [super init]; } | < | < | | < | | 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 | @throw e; } } return [super init]; } - (OFFileOffset)lowlevelSeekToOffset: (OFFileOffset)offset whence: (int)whence { OF_UNRECOGNIZED_SELECTOR } - (OFFileOffset)seekToOffset: (OFFileOffset)offset whence: (int)whence { if (whence == SEEK_CUR) offset -= _readBufferLength; offset = [self lowlevelSeekToOffset: offset whence: whence]; OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; return offset; } @end |
Modified src/OFSelectKernelEventObserver.m from [df50d21c59] to [c54e00c28f].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | > < < > > > > > | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #define __NO_EXT_QNX #include "platform.h" #ifdef OF_WINDOWS /* Win32 has a ridiculous default of 64, even though it supports much more. */ # define FD_SETSIZE 1024 #endif #include <errno.h> #include <string.h> #include <sys/time.h> #import "OFSelectKernelEventObserver.h" #import "OFArray.h" #import "OFSocket+Private.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" #ifdef OF_AMIGAOS # include <proto/exec.h> #endif #ifdef OF_HPUX /* FD_SET causes warnings on HP-UX/IA64. */ # pragma GCC diagnostic ignored "-Wstrict-aliasing" #endif @implementation OFSelectKernelEventObserver - (instancetype)init { self = [super init]; @try { |
︙ | ︙ | |||
90 91 92 93 94 95 96 | if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET((OFSocketHandle)fd, &_readFDs); [super addObjectForReading: object]; } - (void)addObjectForWriting: (id <OFReadyForWritingObserving>)object { int fd = object.fileDescriptorForWriting; |
︙ | ︙ | |||
114 115 116 117 118 119 120 | if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif if (fd > _maxFD) _maxFD = fd; FD_SET((OFSocketHandle)fd, &_writeFDs); [super addObjectForWriting: object]; } - (void)removeObjectForReading: (id <OFReadyForReadingObserving>)object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForReading; if (fd < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif FD_CLR((OFSocketHandle)fd, &_readFDs); [super removeObjectForReading: object]; } - (void)removeObjectForWriting: (id <OFReadyForWritingObserving>)object { /* TODO: Adjust _maxFD */ int fd = object.fileDescriptorForWriting; if (fd < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: EBADF]; #ifndef OF_WINDOWS if (fd >= (int)FD_SETSIZE) @throw [OFOutOfRangeException exception]; #endif FD_CLR((OFSocketHandle)fd, &_writeFDs); [super removeObjectForWriting: object]; } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { fd_set readFDs; fd_set writeFDs; struct timeval timeout; int events; #ifdef OF_AMIGAOS BYTE cancelSignal; |
︙ | ︙ | |||
225 226 227 228 229 230 231 | events = select(_maxFD + 1, &readFDs, &writeFDs, NULL, (timeInterval != -1 ? &timeout : NULL)); #endif if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self | | | | | | | 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | events = select(_maxFD + 1, &readFDs, &writeFDs, NULL, (timeInterval != -1 ? &timeout : NULL)); #endif if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: OFSocketErrNo()]; #ifdef OF_AMIGAOS if (execSignalMask != 0 && [_delegate respondsToSelector: @selector(execSignalWasReceived:)]) [_delegate execSignalWasReceived: execSignalMask]; #else if (FD_ISSET(_cancelFD[0], &readFDs)) { char buffer; # ifdef OF_HAVE_PIPE OFEnsure(read(_cancelFD[0], &buffer, 1) == 1); # else OFEnsure(recvfrom(_cancelFD[0], (void *)&buffer, 1, 0, NULL, NULL) == 1); # endif } #endif pool = objc_autoreleasePoolPush(); for (id <OFReadyForReadingObserving> object in [[_readObjects copy] autorelease]) { void *pool2 = objc_autoreleasePoolPush(); int fd = object.fileDescriptorForReading; if (FD_ISSET((OFSocketHandle)fd, &readFDs) && [_delegate respondsToSelector: @selector(objectIsReadyForReading:)]) [_delegate objectIsReadyForReading: object]; objc_autoreleasePoolPop(pool2); } for (id <OFReadyForWritingObserving> object in [[_writeObjects copy] autorelease]) { void *pool2 = objc_autoreleasePoolPush(); int fd = object.fileDescriptorForWriting; if (FD_ISSET((OFSocketHandle)fd, &writeFDs) && [_delegate respondsToSelector: @selector(objectIsReadyForWriting:)]) [_delegate objectIsReadyForWriting: object]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); } @end |
Modified src/OFSequencedPacketSocket.h from [89fbfce591] to [2a157448e9].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFKernelEventObserver.h" #import "OFRunLoop.h" | < | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFKernelEventObserver.h" #import "OFRunLoop.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFData; @class OFSequencedPacketSocket; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when a packet has been received. * * @param length The length of the packet * @param exception An exception which occurred while receiving or `nil` on * success * @return A bool whether the same block should be used for the next receive */ typedef bool (^OFSequencedPacketSocketAsyncReceiveBlock)(size_t length, id _Nullable exception); /** * @brief A block which is called when a packet has been sent. * * @param data The data which was sent * @param exception An exception which occurred while reading or `nil` on * success * @return The data to repeat the send with or nil if it should not repeat */ typedef OFData *_Nullable (^OFSequencedPacketSocketAsyncSendDataBlock)( OFData *_Nonnull data, id _Nullable exception); /** * @brief A block which is called when the socket accepted a connection. * * @param acceptedSocket The socket which has been accepted * @param exception An exception which occurred while accepting the socket or * `nil` on success * @return A bool whether the same block should be used for the next incoming * connection */ typedef bool (^OFSequencedPacketSocketAsyncAcceptBlock)( OFSequencedPacketSocket *acceptedSocket, id _Nullable exception); #endif /** * @protocol OFSequencedPacketSocketDelegate OFSequencedPacketSocket.h \ * ObjFW/OFSequencedPacketSocket.h * |
︙ | ︙ | |||
123 124 125 126 127 128 129 | * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFSequencedPacketSocket: OFObject <OFCopying, OFReadyForReadingObserving, OFReadyForWritingObserving> { | | | | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy * was called to create one "instance" for every thread! */ @interface OFSequencedPacketSocket: OFObject <OFCopying, OFReadyForReadingObserving, OFReadyForWritingObserving> { OFSocketHandle _socket; bool _canBlock, _listening; OFSocketAddress _remoteAddress; id _Nullable _delegate; OF_RESERVE_IVARS(OFSequencedPacketSocket, 4) } /** * @brief Whether the socket can block. * |
︙ | ︙ | |||
147 148 149 150 151 152 153 | @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! */ | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ |
︙ | ︙ | |||
174 175 176 177 178 179 180 | * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @return The length of the received packet */ | | < | < | < | | < | < | | | < | | < | < < | | < | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @return The length of the received packet */ - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the async receive */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @param block The block to call when the packet has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more packets have been received. * If you want the next method in the queue to handle the packet * received next, you need to return false from the method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFSequencedPacketSocketAsyncReceiveBlock)block; /** * @brief Asynchronously receives a packet and stores it into the specified * buffer. * * If the buffer is too small, the receive operation fails. * * @param buffer The buffer to write the packet to * @param length The length of the buffer * @param runLoopMode The run loop mode in which to perform the async receive * @param block The block to call when the packet has been received. If the * block returns true, it will be called again with the same * buffer and maximum length when more packets have been received. * If you want the next method in the queue to handle the packet * received next, you need to return false from the method. */ - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncReceiveBlock)block; #endif /** * @brief Sends the specified packet. * * @param buffer The buffer to send as a packet * @param length The length of the buffer */ - (void)sendBuffer: (const void *)buffer length: (size_t)length; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet */ - (void)asyncSendData: (OFData *)data; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet * @param runLoopMode The run loop mode in which to perform the async send */ - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data block: (OFSequencedPacketSocketAsyncSendDataBlock)block; /** * @brief Asynchronously sends the specified packet. * * @param data The data to send as a packet * @param runLoopMode The run loop mode in which to perform the async send * @param block The block to call when the packet has been sent. It should * return the data for the next send with the same callback or nil * if it should not repeat. */ - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncSendDataBlock)block; #endif /** * @brief Listen on the socket. * * @param backlog Maximum length for the queue of pending connections. */ |
︙ | ︙ | |||
329 330 331 332 333 334 335 | - (void)asyncAccept; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept */ | | | < > | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | - (void)asyncAccept; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept */ - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously accept an incoming connection. * * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void) asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncAcceptBlock)block; #endif /** * @brief Cancels all pending asynchronous requests on the socket. */ - (void)cancelAsyncRequests; |
︙ | ︙ |
Modified src/OFSequencedPacketSocket.m from [afdcde4505] to [d397c2379d].
︙ | ︙ | |||
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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <assert.h> #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFSequencedPacketSocket.h" #import "OFSequencedPacketSocket+Private.h" #import "OFData.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFAcceptFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFListenFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" | > > > > > > > < < < | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include <assert.h> #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFSequencedPacketSocket.h" #import "OFSequencedPacketSocket+Private.h" #import "OFData.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFAcceptFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFListenFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" @implementation OFSequencedPacketSocket @synthesize listening = _listening, delegate = _delegate; + (void)initialize { if (self != [OFSequencedPacketSocket class]) return; if (!OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)socket { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { if (self.class == [OFSequencedPacketSocket class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _socket = OFInvalidSocketHandle; _canBlock = true; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket != OFInvalidSocketHandle) [self close]; [super dealloc]; } #ifndef OF_WII - (int)of_socketError { int errNo; socklen_t len = sizeof(errNo); if (getsockopt(_socket, SOL_SOCKET, SO_ERROR, (char *)&errNo, &len) != 0) return OFSocketErrNo(); return errNo; } #endif - (id)copy { |
︙ | ︙ | |||
127 128 129 130 131 132 133 | if (fcntl(_socket, F_SETFL, flags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; _canBlock = canBlock; #elif defined(OF_WINDOWS) | | | | < | | | | < | | < | | < | | | < | | < | | | | < | < | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | if (fcntl(_socket, F_SETFL, flags) == -1) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: errno]; _canBlock = canBlock; #elif defined(OF_WINDOWS) u_long v = !canBlock; if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; _canBlock = canBlock; #else OF_UNRECOGNIZED_SELECTOR #endif } - (size_t)receiveIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS if ((ret = recv(_socket, buffer, length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: OFSocketErrNo()]; #else if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = recv(_socket, buffer, (int)length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: OFSocketErrNo()]; #endif return ret; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncReceiveForSequencedPacketSocket: self buffer: buffer length: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length block: (OFSequencedPacketSocketAsyncReceiveBlock)block { [self asyncReceiveIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void) asyncReceiveIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncReceiveBlock)block { [OFRunLoop of_addAsyncReceiveForSequencedPacketSocket: self buffer: buffer length: length mode: runLoopMode block: block delegate: nil]; } #endif - (void)sendBuffer: (const void *)buffer length: (size_t)length { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, (void *)buffer, length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: OFSocketErrNo()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, buffer, (int)length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: OFSocketErrNo()]; #endif if ((size_t)bytesWritten != length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; } - (void)asyncSendData: (OFData *)data { [self asyncSendData: data runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncSendForSequencedPacketSocket: self data: data mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncSendData: (OFData *)data block: (OFSequencedPacketSocketAsyncSendDataBlock)block { [self asyncSendData: data runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncSendData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncSendDataBlock)block { [OFRunLoop of_addAsyncSendForSequencedPacketSocket: self data: data mode: runLoopMode block: block delegate: nil]; } #endif - (void)listen { [self listenWithBacklog: SOMAXCONN]; } - (void)listenWithBacklog: (int)backlog { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) @throw [OFListenFailedException exceptionWithSocket: self backlog: backlog errNo: OFSocketErrNo()]; _listening = true; } - (instancetype)accept { OFSequencedPacketSocket *client = |
︙ | ︙ | |||
333 334 335 336 337 338 339 | client->_remoteAddress.length = (socklen_t)sizeof(client->_remoteAddress.sockaddr); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, &client->_remoteAddress.sockaddr.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == | | | | > | | | | | | | < | | | < | < > | | | | | | | | | | 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | client->_remoteAddress.length = (socklen_t)sizeof(client->_remoteAddress.sockaddr); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, &client->_remoteAddress.sockaddr.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, &client->_remoteAddress.sockaddr.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, &client->_remoteAddress.sockaddr.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) @throw [OFAcceptFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC); # endif #endif assert(client->_remoteAddress.length <= (socklen_t)sizeof(client->_remoteAddress.sockaddr)); switch (client->_remoteAddress.sockaddr.sockaddr.sa_family) { case AF_INET: client->_remoteAddress.family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: client->_remoteAddress.family = OFSocketAddressFamilyIPX; break; #endif default: client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; } - (void)asyncAccept { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode]; } - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: NULL delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncAcceptWithBlock: (OFSequencedPacketSocketAsyncAcceptBlock)block { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode block: block]; } - (void) asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFSequencedPacketSocketAsyncAcceptBlock)block { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: block delegate: nil]; } #endif - (const OFSocketAddress *)remoteAddress { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (_remoteAddress.length == 0) @throw [OFInvalidArgumentException exception]; if (_remoteAddress.length > (socklen_t)sizeof(_remoteAddress.sockaddr)) @throw [OFOutOfRangeException exception]; return &_remoteAddress; } - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self mode: OFDefaultRunLoopMode]; } - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (int)fileDescriptorForWriting { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (void)close { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; _listening = false; memset(&_remoteAddress, 0, sizeof(_remoteAddress)); closesocket(_socket); _socket = OFInvalidSocketHandle; } @end |
Modified src/OFSerialization.h from [4e7cb4c5a0] to [e824a5f7ee].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN | < < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * file. */ #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN @class OFXMLElement; /** * @protocol OFSerialization OFSerialization.h ObjFW/OFSerialization.h * * @brief A protocol for serializing objects. */ |
︙ | ︙ | |||
36 37 38 39 40 41 42 43 44 | * @brief Initializes the object with the specified XML element serialization. * * @param element An OFXMLElement with the serialized object * @return An initialized object */ - (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END | > > > > > > > > | 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | * @brief Initializes the object with the specified XML element serialization. * * @param element An OFXMLElement with the serialized object * @return An initialized object */ - (instancetype)initWithSerialization: (OFXMLElement *)element; @end #ifdef __cplusplus extern "C" { #endif extern OFString *const OFSerializationNS; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Added src/OFSerialization.m version [0a6892a6f3].
> > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /* * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFSerialization.h" #import "OFString.h" OFString *const OFSerializationNS = @"https://objfw.nil.im/serialization"; |
Modified src/OFSet.h from [17726306c1] to [b05430c060].
︙ | ︙ | |||
36 37 38 39 40 41 42 | /** * @brief A block for enumerating an OFSet. * * @param object The current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ | | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /** * @brief A block for enumerating an OFSet. * * @param object The current object * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFSetEnumerationBlock)(id object, bool *stop); /** * @brief A block for filtering an OFSet. * * @param object The object to inspect * @return Whether the object should be in the filtered set */ typedef bool (^OFSetFilterBlock)(id object); #endif /** * @class OFSet OFSet.h ObjFW/OFSet.h * * @brief An abstract class for an unordered set of unique objects. * |
︙ | ︙ | |||
159 160 161 162 163 164 165 166 167 168 169 170 171 172 | * @param firstObject The first object for the set * @param arguments A va_list with the other objects * @return An initialized set with the specified object and va_list */ - (instancetype)initWithObject: (ObjectType)firstObject arguments: (va_list)arguments; /** * @brief Returns whether the receiver is a subset of the specified set. * * @return Whether the receiver is a subset of the specified set */ - (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType) *)set; | > > > > > > > | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | * @param firstObject The first object for the set * @param arguments A va_list with the other objects * @return An initialized set with the specified object and va_list */ - (instancetype)initWithObject: (ObjectType)firstObject arguments: (va_list)arguments; /** * @brief Returns an OFEnumerator to enumerate through all objects of the set. * * @return An OFEnumerator to enumerate through all objects of the set */ - (OFEnumerator OF_GENERIC(ObjectType) *)objectEnumerator; /** * @brief Returns whether the receiver is a subset of the specified set. * * @return Whether the receiver is a subset of the specified set */ - (bool)isSubsetOfSet: (OFSet OF_GENERIC(ObjectType) *)set; |
︙ | ︙ | |||
235 236 237 238 239 240 241 | * @ref setValue:forKey: is called for each object. * * @note A @ref OFNull value is translated to nil! * * @param value The value for the specified key * @param key The key of the value to set */ | | < | | | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | * @ref setValue:forKey: is called for each object. * * @note A @ref OFNull value is translated to nil! * * @param value The value for the specified key * @param key The key of the value to set */ - (void)setValue: (nullable id)value forKey: (OFString *)key; #ifdef OF_HAVE_BLOCKS /** * @brief Executes a block for each object in the set. * * @param block The block to execute for each object in the set */ - (void)enumerateObjectsUsingBlock: (OFSetEnumerationBlock)block; /** * @brief Creates a new set, only containing the objects for which the block * returns true. * * @param block A block which determines if the object should be in the new set * @return A new, autoreleased OFSet */ - (OFSet OF_GENERIC(ObjectType) *) filteredSetUsingBlock: (OFSetFilterBlock)block; #endif #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END #import "OFMutableSet.h" |
Modified src/OFSet.m from [27e6d4b43c] to [a3dd281791].
︙ | ︙ | |||
56 57 58 59 60 61 62 | ret = [[OFMapTableSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } | | < | < | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | ret = [[OFMapTableSet alloc] initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { return (id)[[OFMapTableSet alloc] initWithObjects: objects count: count]; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { return (id)[[OFMapTableSet alloc] initWithObject: firstObject arguments: arguments]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { |
︙ | ︙ | |||
138 139 140 141 142 143 144 | ret = [[[self alloc] initWithObject: firstObject arguments: arguments] autorelease]; va_end(arguments); return ret; } | | < | 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | ret = [[[self alloc] initWithObject: firstObject arguments: arguments] autorelease]; va_end(arguments); return ret; } + (instancetype)setWithObjects: (id const *)objects count: (size_t)count { return [[[self alloc] initWithObjects: objects count: count] autorelease]; } - (instancetype)init { |
︙ | ︙ | |||
171 172 173 174 175 176 177 | } - (instancetype)initWithArray: (OFArray *)array { OF_INVALID_INIT_METHOD } | | < | < | < | 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | } - (instancetype)initWithArray: (OFArray *)array { OF_INVALID_INIT_METHOD } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { OF_INVALID_INIT_METHOD } - (instancetype)initWithObjects: (id)firstObject, ... { id ret; va_list arguments; va_start(arguments, firstObject); ret = [self initWithObject: firstObject arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { OF_INVALID_INIT_METHOD } - (instancetype)initWithSerialization: (OFXMLElement *)element { OF_INVALID_INIT_METHOD |
︙ | ︙ | |||
227 228 229 230 231 232 233 | } [ret makeImmutable]; return ret; } | | < | < | | 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | } [ret makeImmutable]; return ret; } - (void)setValue: (id)value forKey: (OFString *)key { for (id object in self) [object setValue: value forKey: key]; } - (bool)containsObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (OFEnumerator *)objectEnumerator { OF_UNRECOGNIZED_SELECTOR } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { OFEnumerator *enumerator; int i; memcpy(&enumerator, state->extra, sizeof(enumerator)); |
︙ | ︙ | |||
329 330 331 332 333 334 335 | [ret appendString: [object description]]; if (++i < count) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool2); } | | < < | 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | [ret appendString: [object description]]; if (++i < count) [ret appendString: @",\n"]; objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } |
︙ | ︙ | |||
375 376 377 378 379 380 381 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; if ([self isKindOfClass: [OFMutableSet class]]) element = [OFXMLElement elementWithName: @"OFMutableSet" | | | < < < < | < < < < | < < < < | < < < < | | | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; if ([self isKindOfClass: [OFMutableSet class]]) element = [OFXMLElement elementWithName: @"OFMutableSet" namespace: OFSerializationNS]; else element = [OFXMLElement elementWithName: @"OFSet" namespace: OFSerializationNS]; for (id <OFSerialization> object in self) { void *pool2 = objc_autoreleasePoolPush(); [element addChild: object.XMLElementBySerializing]; objc_autoreleasePoolPop(pool2); } [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFSet *)setBySubtractingSet: (OFSet *)set { OFMutableSet *new = [[self mutableCopy] autorelease]; [new minusSet: set]; [new makeImmutable]; return new; } - (OFSet *)setByIntersectingWithSet: (OFSet *)set { OFMutableSet *new = [[self mutableCopy] autorelease]; [new intersectSet: set]; [new makeImmutable]; return new; } - (OFSet *)setByAddingSet: (OFSet *)set { OFMutableSet *new = [[self mutableCopy] autorelease]; [new unionSet: set]; [new makeImmutable]; return new; } - (OFArray *)allObjects { void *pool = objc_autoreleasePoolPush(); OFArray *ret = [[[self objectEnumerator] allObjects] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (id)anyObject { void *pool = objc_autoreleasePoolPush(); id ret = [[[self objectEnumerator] nextObject] retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (OFSetEnumerationBlock)block { bool stop = false; for (id object in self) { block(object, &stop); if (stop) break; } } - (OFSet *)filteredSetUsingBlock: (OFSetFilterBlock)block { OFMutableSet *ret = [OFMutableSet set]; [self enumerateObjectsUsingBlock: ^ (id object, bool *stop) { if (block(object)) [ret addObject: object]; }]; |
︙ | ︙ |
Modified src/OFSettings.h from [99a9f5155c] to [10aa8b7158].
︙ | ︙ | |||
68 69 70 71 72 73 74 | /** * @brief Sets the specified path to the specified string. * * @param string The string to set * @param path The path to store the string at */ | | < | | | < | | < | < | < | | | | | | | | | | | | | | | < | | | < | | | < | | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | /** * @brief Sets the specified path to the specified string. * * @param string The string to set * @param path The path to store the string at */ - (void)setString: (OFString *)string forPath: (OFString *)path; /** * @brief Sets the specified path to the specified long long. * * @param longLong The long long to set * @param path The path to store the long long at */ - (void)setLongLong: (long long)longLong forPath: (OFString *)path; /** * @brief Sets the specified path to the specified bool. * * @param bool_ The bool to set * @param path The path to store the bool at */ - (void)setBool: (bool)bool_ forPath: (OFString *)path; /** * @brief Sets the specified path to the specified float. * * @param float_ The float to set * @param path The path to store the float at */ - (void)setFloat: (float)float_ forPath: (OFString *)path; /** * @brief Sets the specified path to the specified double. * * @param double_ The double to set * @param path The path to store the double at */ - (void)setDouble: (double)double_ forPath: (OFString *)path; /** * @brief Sets the specified path to the specified array of strings. * * @param array The array of strings to set * @param path The path to store the array of string at */ - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forPath: (OFString *)path; /** * @brief Returns the string for the specified path, or `nil` if the path does * not exist. * * @param path The path for which the string should be returned * @return The string of the specified path */ - (nullable OFString *)stringForPath: (OFString *)path; /** * @brief Returns the string for the specified path, or the default value if * the path does not exist. * * @param path The path for which the string should be returned * @param defaultValue The default value to return if the path does not exist * @return The string of the specified path */ - (nullable OFString *)stringForPath: (OFString *)path defaultValue: (nullable OFString *)defaultValue; /** * @brief Returns the long long for the specified path, or the default value if * the path does not exist. * * @param path The path for which the long long should be returned * @param defaultValue The default value to return if the path does not exist * @return The long long of the specified path */ - (long long)longLongForPath: (OFString *)path defaultValue: (long long)defaultValue; /** * @brief Returns the bool for the specified path, or the default value if the * path does not exist. * * @param path The path for which the bool should be returned * @param defaultValue The default value to return if the path does not exist * @return The bool of the specified path */ - (bool)boolForPath: (OFString *)path defaultValue: (bool)defaultValue; /** * @brief Returns the float for the specified path, or the default value if the * path does not exist. * * @param path The path for which the float should be returned * @param defaultValue The default value to return if the path does not exist * @return The float of the specified path */ - (float)floatForPath: (OFString *)path defaultValue: (float)defaultValue; /** * @brief Returns the double for the specified path, or the default value if * the path does not exist. * * @param path The path for which the double should be returned * @param defaultValue The default value to return if the path does not exist * @return The double of the specified path */ - (double)doubleForPath: (OFString *)path defaultValue: (double)defaultValue; /** * @brief Returns the array of strings for the specified path, or an empty * array if the path does not exist. * * @param path The path for which the array of strings should be returned * @return The array of string values of the specified path */ - (OFArray OF_GENERIC(OFString *) *)stringArrayForPath: (OFString *)path; /** * @brief Removes the value for the specified path. * * @param path The path for which the value should be removed */ - (void)removeValueForPath: (OFString *)path; |
︙ | ︙ |
Modified src/OFSettings.m from [372f573069] to [8b3ec674cd].
︙ | ︙ | |||
58 59 60 61 62 63 64 | - (void)dealloc { [_applicationName release]; [super dealloc]; } | | < < | | < | < | < | | | < | | > > > > > | < | < | < < < < < < | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | - (void)dealloc { [_applicationName release]; [super dealloc]; } - (void)setString: (OFString *)string forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setLongLong: (long long)longLong forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setBool: (bool)bool_ forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setFloat: (float)float_ forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setDouble: (double)double_ forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)setStringArray: (OFArray OF_GENERIC(OFString *) *)array forPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (OFString *)stringForPath: (OFString *)path { return [self stringForPath: path defaultValue: nil]; } - (OFString *)stringForPath: (OFString *)path defaultValue: (OFString *)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (long long)longLongForPath: (OFString *)path defaultValue: (long long)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (bool)boolForPath: (OFString *)path defaultValue: (bool)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (float)floatForPath: (OFString *)path defaultValue: (float)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (double)doubleForPath: (OFString *)path defaultValue: (double)defaultValue { OF_UNRECOGNIZED_SELECTOR } - (OFArray OF_GENERIC(OFString *) *)stringArrayForPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR } - (void)removeValueForPath: (OFString *)path { OF_UNRECOGNIZED_SELECTOR |
︙ | ︙ |
Renamed and modified src/OFDimensionValue.h [f7a2f0822f] to src/OFSizeValue.h [48dc2259c8].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN | | | > > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * file. */ #import "OFValue.h" OF_ASSUME_NONNULL_BEGIN @interface OFSizeValue: OFValue { OFSize _size; } - (instancetype)initWithSize: (OFSize)size; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFDimensionValue.m [8625e742ff] to src/OFSizeValue.m [c2a5ad86a9].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | | | | | | | | < | | | < | 9 10 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 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFSizeValue.h" #import "OFMethodSignature.h" #import "OFString.h" #import "OFOutOfRangeException.h" @implementation OFSizeValue @synthesize sizeValue = _size; - (instancetype)initWithSize: (OFSize)size { self = [super init]; _size = size; return self; } - (const char *)objCType { return @encode(OFSize); } - (void)getValue: (void *)value size: (size_t)size { if (size != sizeof(_size)) @throw [OFOutOfRangeException exception]; memcpy(value, &_size, sizeof(_size)); } - (OFString *)description { return [OFString stringWithFormat: @"<OFValue: OFSize { %f, %f }>", _size.width, _size.height]; } @end |
Renamed and modified src/socket_helpers.h [8de17e0f84] to src/OFSocket+Private.h [d80ab86a23].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #ifdef HAVE_ARPA_INET_H # include <arpa/inet.h> #endif #ifdef HAVE_NETDB_H # include <netdb.h> #endif | | < < < < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #ifdef HAVE_ARPA_INET_H # include <arpa/inet.h> #endif #ifdef HAVE_NETDB_H # include <netdb.h> #endif #include "OFSocket.h" #ifndef INADDR_NONE # define INADDR_NONE ((in_addr_t)-1) #endif #ifndef SOMAXCONN /* |
︙ | ︙ | |||
54 55 56 57 58 59 60 | # endif # include <sys/filio.h> # define closesocket(sock) CloseSocket(sock) # define ioctlsocket(fd, req, arg) IoctlSocket(fd, req, arg) # define hstrerror(err) "unknown (no hstrerror)" # define SOCKET_ERROR -1 # if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS) | | | < | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | # endif # include <sys/filio.h> # define closesocket(sock) CloseSocket(sock) # define ioctlsocket(fd, req, arg) IoctlSocket(fd, req, arg) # define hstrerror(err) "unknown (no hstrerror)" # define SOCKET_ERROR -1 # if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS) # define SocketBase ((struct Library *)OFTLSKeyGet(OFSocketBaseKey)) # ifdef OF_AMIGAOS4 # define ISocket ((struct SocketIFace *)OFTLSKeyGet(OFSocketInterfaceKey)) # endif # endif # ifdef OF_MORPHOS typedef uint32_t in_addr_t; # endif #elif !defined(OF_WINDOWS) && !defined(OF_WII) # define closesocket(sock) close(sock) |
︙ | ︙ |
Renamed and modified src/socket.h [07f169cd19] to src/OFSocket.h [2b4aae9d25].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #include <stdbool.h> #import "OFString.h" #ifdef OF_HAVE_SYS_SOCKET_H # include <sys/socket.h> #endif #ifdef OF_HAVE_NETINET_IN_H # include <netinet/in.h> #endif #ifdef OF_HAVE_NETINET_TCP_H # include <netinet/tcp.h> #endif | > > > < < < < < < < < | > | > | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #include <stdbool.h> #import "OFString.h" #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) # import "OFTLSKey.h" #endif #ifdef OF_HAVE_SYS_SOCKET_H # include <sys/socket.h> #endif #ifdef OF_HAVE_NETINET_IN_H # include <netinet/in.h> #endif #ifdef OF_HAVE_NETINET_TCP_H # include <netinet/tcp.h> #endif #ifdef OF_HAVE_NETIPX_IPX_H # include <netipx/ipx.h> #endif #ifdef OF_WINDOWS # include <windows.h> # include <ws2tcpip.h> # ifdef OF_HAVE_IPX # include <wsipx.h> # endif #endif /** @file */ #ifdef OF_WII # include <network.h> #endif #ifdef OF_PSP # include <stdint.h> #endif #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifndef OF_WINDOWS typedef int OFSocketHandle; static const OFSocketHandle OFInvalidSocketHandle = -1; #else typedef SOCKET OFSocketHandle; static const OFSocketHandle OFInvalidSocketHandle = INVALID_SOCKET; #endif #ifdef OF_WII typedef u8 sa_family_t; #endif #ifdef OF_MORPHOS typedef long socklen_t; typedef u_char sa_family_t; typedef u_short in_port_t; #endif /** * @brief A socket address family. */ typedef enum { /** An unknown address family. */ OFSocketAddressFamilyUnknown, /** IPv4 */ OFSocketAddressFamilyIPv4, /** IPv6 */ OFSocketAddressFamilyIPv6, /** IPX */ OFSocketAddressFamilyIPX, /** Any address family */ OFSocketAddressFamilyAny = 255 } OFSocketAddressFamily; #ifndef OF_HAVE_IPV6 struct sockaddr_in6 { sa_family_t sin6_family; in_port_t sin6_port; uint32_t sin6_flowinfo; struct in6_addr { |
︙ | ︙ | |||
125 126 127 128 129 130 131 | # define sipx_family sa_family # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif /** | | | | < | | > | < | | | < | | | < | | | < | | | | | | | < < | | | | | < | | | | | | | | < | | < | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | # define sipx_family sa_family # define sipx_network sa_netnum # define sipx_node sa_nodenum # define sipx_port sa_socket #endif /** * @struct OFSocketAddress OFSocket.h ObjFW/OFSocket.h * * @brief A struct which represents a host / port pair for a socket. */ typedef struct OF_BOXABLE { /* * Even though struct sockaddr contains the family, we need to use our * own family, as we need to support storing an IPv6 address on systems * that don't support IPv6. These may not have AF_INET6 defined and we * can't just define it, as the value is system-dependent and might * clash with an existing value. */ OFSocketAddressFamily family; union { struct sockaddr sockaddr; struct sockaddr_in in; struct sockaddr_in6 in6; struct sockaddr_ipx ipx; } sockaddr; socklen_t length; } OFSocketAddress; #ifdef __cplusplus extern "C" { #endif /** * @brief Parses the specified IP (either v4 or v6) and port into an * @ref OFSocketAddress. * * @param IP The IP to parse * @param port The port to use * @return The parsed IP and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv4 and port into an @ref OFSocketAddress. * * @param IP The IPv4 to parse * @param port The port to use * @return The parsed IPv4 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port); /** * @brief Parses the specified IPv6 and port into an @ref OFSocketAddress. * * @param IP The IPv6 to parse * @param port The port to use * @return The parsed IPv6 and port as an OFSocketAddress */ extern OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port); /** * @brief Creates an IPX address for the specified network, node and port. * * @param node The node in the IPX network * @param network The IPX network * @param port The IPX port (sometimes called socket number) on the node */ extern OFSocketAddress OFSocketAddressMakeIPX( const unsigned char node[_Nonnull IPX_NODE_LEN], uint32_t network, uint16_t port); /** * @brief Compares two OFSocketAddress for equality. * * @param address1 The address to compare with the second address * @param address2 The second address * @return Whether the two addresses are equal */ extern bool OFSocketAddressEqual(const OFSocketAddress *_Nonnull address1, const OFSocketAddress *_Nonnull address2); /** * @brief Returns the hash for the specified @ref OFSocketAddress. * * @param address The address to hash * @return The hash for the specified OFSocketAddress */ extern unsigned long OFSocketAddressHash( const OFSocketAddress *_Nonnull address); /** * @brief Converts the specified @ref OFSocketAddress to a string. * * @param address The address to convert to a string * @return The address as an IP string */ extern OFString *_Nonnull OFSocketAddressString( const OFSocketAddress *_Nonnull address); /** * @brief Sets the port of the specified @ref OFSocketAddress, independent of * the address family used. * * @param address The address on which to set the port * @param port The port to set on the address */ extern void OFSocketAddressSetPort(OFSocketAddress *_Nonnull address, uint16_t port); /** * @brief Returns the port of the specified @ref OFSocketAddress, independent of * the address family used. * * @param address The address on which to get the port * @return The port of the address */ extern uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address); /** * @brief Sets the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX network * @param network The IPX network to set on the address */ extern void OFSocketAddressSetIPXNetwork(OFSocketAddress *_Nonnull address, uint32_t network); /** * @brief Returns the IPX network of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX network * @return The IPX network of the address */ extern uint32_t OFSocketAddressIPXNetwork( const OFSocketAddress *_Nonnull address); /** * @brief Sets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to set the IPX node * @param node The IPX node to set on the address */ extern void OFSocketAddressSetIPXNode(OFSocketAddress *_Nonnull address, const unsigned char node[_Nonnull IPX_NODE_LEN]); /** * @brief Gets the IPX node of the specified @ref OFSocketAddress. * * @param address The address on which to get the IPX node * @param node A byte array to store the IPX node of the address */ extern void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address, unsigned char node[_Nonnull IPX_NODE_LEN]); extern bool OFSocketInit(void); #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern void OFSocketDeinit(void); #endif extern int OFSocketErrNo(void); #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) extern int OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr, socklen_t *restrict addrLen); #endif #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) extern OFTLSKey OFSocketBaseKey; # ifdef OF_AMIGAOS4 extern OFTLSKey OFSocketInterfaceKey; # endif #endif #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Renamed and modified src/socket.m [2d1d9f46b4] to src/OFSocket.m [941bbd3cbe].
︙ | ︙ | |||
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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #ifdef OF_NINTENDO_3DS # include <malloc.h> /* For memalign() */ #endif #include <errno.h> #import "OFArray.h" #import "OFCharacterSet.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFString.h" #import "OFException.h" /* For some E* -> WSAE* defines */ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" | > > > > > > > > > > > < < < < < < < | 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 55 56 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #ifdef OF_NINTENDO_3DS # include <malloc.h> /* For memalign() */ #endif #include <errno.h> #import "OFArray.h" #import "OFCharacterSet.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFOnce.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #ifdef OF_HAVE_THREADS # import "OFTLSKey.h" #endif #import "OFException.h" /* For some E* -> WSAE* defines */ #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" #ifdef OF_AMIGAOS # include <proto/exec.h> #endif #ifdef OF_NINTENDO_3DS # include <3ds/types.h> # include <3ds/services/soc.h> |
︙ | ︙ | |||
63 64 65 66 67 68 69 | #endif #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static bool initSuccessful = false; #endif #ifdef OF_AMIGAOS # if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS) | | | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | #endif #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static bool initSuccessful = false; #endif #ifdef OF_AMIGAOS # if defined(OF_HAVE_THREADS) && !defined(OF_MORPHOS) OFTLSKey OFSocketBaseKey; # ifdef OF_AMIGAOS4 OFTLSKey OFSocketInterfaceKey; # endif # else struct Library *SocketBase; # ifdef OF_AMIGAOS4 struct SocketIFace *ISocket = NULL; # endif # endif #endif #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) OF_CONSTRUCTOR() { if (OFTLSKeyNew(&OFSocketBaseKey) != 0) @throw [OFInitializationFailedException exception]; # ifdef OF_AMIGAOS4 if (OFTLSKeyNew(&OFSocketInterfaceKey) != 0) @throw [OFInitializationFailedException exception]; # endif } #endif #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static void |
︙ | ︙ | |||
128 129 130 131 132 133 134 | # endif # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) mutex = [[OFMutex alloc] init]; atexit(releaseMutex); # ifdef OF_WII | | | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | # endif # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) mutex = [[OFMutex alloc] init]; atexit(releaseMutex); # ifdef OF_WII if (OFSpinlockNew(&spinlock) != 0) return; # endif # endif initSuccessful = true; } |
︙ | ︙ | |||
151 152 153 154 155 156 157 | if (SocketBase != NULL) CloseLibrary(SocketBase); # endif } #endif bool | | | | | | | | | | | < | | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | if (SocketBase != NULL) CloseLibrary(SocketBase); # endif } #endif bool OFSocketInit(void) { #if !defined(OF_AMIGAOS) || defined(OF_MORPHOS) || !defined(OF_HAVE_THREADS) static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, init); return initSuccessful; #else struct Library *socketBase; # ifdef OF_AMIGAOS4 struct SocketIFace *socketInterface; # endif # ifdef OF_AMIGAOS4 if ((socketInterface = OFTLSKeyGet(OFSocketInterfaceKey)) != NULL) # else if ((socketBase = OFTLSKeyGet(OFSocketBaseKey)) != NULL) # endif return true; if ((socketBase = OpenLibrary("bsdsocket.library", 4)) == NULL) return false; # ifdef OF_AMIGAOS4 if ((socketInterface = (struct SocketIFace *) GetInterface(socketBase, "main", 1, NULL)) == NULL) { CloseLibrary(socketBase); return false; } # endif if (OFTLSKeySet(OFSocketBaseKey, socketBase) != 0) { CloseLibrary(socketBase); # ifdef OF_AMIGAOS4 DropInterface((struct Interface *)socketInterface); # endif return false; } # ifdef OF_AMIGAOS4 if (OFTLSKeySet(OFSocketInterfaceKey, socketInterface) != 0) { CloseLibrary(socketBase); DropInterface((struct Interface *)socketInterface); return false; } # endif return true; #endif } #if defined(OF_HAVE_THREADS) && defined(OF_AMIGAOS) && !defined(OF_MORPHOS) void OFSocketDeinit(void) { struct Library *socketBase = OFTLSKeyGet(OFSocketBaseKey); # ifdef OF_AMIGAOS4 struct SocketIFace *socketInterface = OFTLSKeyGet(OFSocketInterfaceKey); if (socketInterface != NULL) DropInterface((struct Interface *)socketInterface); # endif if (socketBase != NULL) CloseLibrary(socketBase); } #endif int OFSocketErrNo() { #if defined(OF_WINDOWS) switch (WSAGetLastError()) { case WSAEACCES: return EACCES; case WSAEADDRINUSE: return EADDRINUSE; |
︙ | ︙ | |||
322 323 324 325 326 327 328 | #else return errno; #endif } #ifndef OF_WII int | | | | | | | | | | | | | | | | | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | #else return errno; #endif } #ifndef OF_WII int OFGetSockName(OFSocketHandle sock, struct sockaddr *restrict addr, socklen_t *restrict addrLen) { int ret; # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) [mutex lock]; # endif ret = getsockname(sock, addr, addrLen); # if defined(OF_HAVE_THREADS) && (!defined(OF_AMIGAOS) || defined(OF_MORPHOS)) [mutex unlock]; # endif return ret; } #endif OFSocketAddress OFSocketAddressParseIPv4(OFString *IPv4, uint16_t port) { void *pool = objc_autoreleasePoolPush(); OFCharacterSet *whitespaceCharacterSet = [OFCharacterSet whitespaceCharacterSet]; OFSocketAddress ret; struct sockaddr_in *addrIn = &ret.sockaddr.in; OFArray OF_GENERIC(OFString *) *components; uint32_t addr; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyIPv4; #if defined(OF_WII) || defined(OF_NINTENDO_3DS) ret.length = 8; #else ret.length = sizeof(ret.sockaddr.in); #endif addrIn->sin_family = AF_INET; addrIn->sin_port = OFToBigEndian16(port); #ifdef OF_WII addrIn->sin_len = ret.length; #endif components = [IPv4 componentsSeparatedByString: @"."]; if (components.count != 4) @throw [OFInvalidFormatException exception]; addr = 0; for (OFString *component in components) { unsigned long long number; if (component.length == 0) @throw [OFInvalidFormatException exception]; if ([component indexOfCharacterFromSet: whitespaceCharacterSet] != OFNotFound) @throw [OFInvalidFormatException exception]; number = component.unsignedLongLongValue; if (number > UINT8_MAX) @throw [OFInvalidFormatException exception]; addr = (addr << 8) | ((uint32_t)number & 0xFF); } addrIn->sin_addr.s_addr = OFToBigEndian32(addr); objc_autoreleasePoolPop(pool); return ret; } static uint16_t parseIPv6Component(OFString *component) { unsigned long long number; if ([component indexOfCharacterFromSet: [OFCharacterSet whitespaceCharacterSet]] != OFNotFound) @throw [OFInvalidFormatException exception]; number = [component unsignedLongLongValueWithBase: 16]; if (number > UINT16_MAX) @throw [OFInvalidFormatException exception]; return (uint16_t)number; } OFSocketAddress OFSocketAddressParseIPv6(OFString *IPv6, uint16_t port) { void *pool = objc_autoreleasePoolPush(); OFSocketAddress ret; struct sockaddr_in6 *addrIn6 = &ret.sockaddr.in6; size_t doubleColon; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyIPv6; ret.length = sizeof(ret.sockaddr.in6); #ifdef AF_INET6 addrIn6->sin6_family = AF_INET6; #else addrIn6->sin6_family = AF_UNSPEC; #endif addrIn6->sin6_port = OFToBigEndian16(port); doubleColon = [IPv6 rangeOfString: @"::"].location; if (doubleColon != OFNotFound) { OFString *left = [IPv6 substringToIndex: doubleColon]; OFString *right = [IPv6 substringFromIndex: doubleColon + 2]; OFArray OF_GENERIC(OFString *) *leftComponents; OFArray OF_GENERIC(OFString *) *rightComponents; size_t i; if ([right hasPrefix: @":"] || [right containsString: @"::"]) |
︙ | ︙ | |||
492 493 494 495 496 497 498 | } objc_autoreleasePoolPop(pool); return ret; } | | | | | | | | | | | | | | | | | | 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | } objc_autoreleasePoolPop(pool); return ret; } OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port) { OFSocketAddress ret; @try { ret = OFSocketAddressParseIPv6(IP, port); } @catch (OFInvalidFormatException *e) { ret = OFSocketAddressParseIPv4(IP, port); } return ret; } OFSocketAddress OFSocketAddressMakeIPX(const unsigned char node[IPX_NODE_LEN], uint32_t network, uint16_t port) { OFSocketAddress ret; memset(&ret, '\0', sizeof(ret)); ret.family = OFSocketAddressFamilyIPX; ret.length = sizeof(ret.sockaddr.ipx); #ifdef AF_IPX ret.sockaddr.ipx.sipx_family = AF_IPX; #else ret.sockaddr.ipx.sipx_family = AF_UNSPEC; #endif memcpy(ret.sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); network = OFToBigEndian32(network); memcpy(&ret.sockaddr.ipx.sipx_network, &network, sizeof(ret.sockaddr.ipx.sipx_network)); ret.sockaddr.ipx.sipx_port = OFToBigEndian16(port); return ret; } bool OFSocketAddressEqual(const OFSocketAddress *address1, const OFSocketAddress *address2) { const struct sockaddr_in *addrIn1, *addrIn2; const struct sockaddr_in6 *addrIn6_1, *addrIn6_2; const struct sockaddr_ipx *addrIPX1, *addrIPX2; if (address1->family != address2->family) return false; switch (address1->family) { case OFSocketAddressFamilyIPv4: #if defined(OF_WII) || defined(OF_NINTENDO_3DS) if (address1->length < 8 || address2->length < 8) @throw [OFInvalidArgumentException exception]; #else if (address1->length < (socklen_t)sizeof(struct sockaddr_in) || address2->length < (socklen_t)sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #endif addrIn1 = &address1->sockaddr.in; addrIn2 = &address2->sockaddr.in; if (addrIn1->sin_port != addrIn2->sin_port) return false; if (addrIn1->sin_addr.s_addr != addrIn2->sin_addr.s_addr) return false; break; case OFSocketAddressFamilyIPv6: if (address1->length < (socklen_t)sizeof(struct sockaddr_in6) || address2->length < (socklen_t)sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; addrIn6_1 = &address1->sockaddr.in6; addrIn6_2 = &address2->sockaddr.in6; if (addrIn6_1->sin6_port != addrIn6_2->sin6_port) return false; if (memcmp(addrIn6_1->sin6_addr.s6_addr, addrIn6_2->sin6_addr.s6_addr, sizeof(addrIn6_1->sin6_addr.s6_addr)) != 0) return false; break; case OFSocketAddressFamilyIPX: if (address1->length < (socklen_t)sizeof(struct sockaddr_ipx) || address2->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; addrIPX1 = &address1->sockaddr.ipx; addrIPX2 = &address2->sockaddr.ipx; |
︙ | ︙ | |||
603 604 605 606 607 608 609 | @throw [OFInvalidArgumentException exception]; } return true; } unsigned long | | | | | | | | | | | | | | | | | | | | | | | | < < < | | 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | @throw [OFInvalidArgumentException exception]; } return true; } unsigned long OFSocketAddressHash(const OFSocketAddress *address) { unsigned long hash; OFHashInit(&hash); OFHashAdd(&hash, address->family); switch (address->family) { case OFSocketAddressFamilyIPv4: #if defined(OF_WII) || defined(OF_NINTENDO_3DS) if (address->length < 8) @throw [OFInvalidArgumentException exception]; #else if (address->length < (socklen_t)sizeof(struct sockaddr_in)) @throw [OFInvalidArgumentException exception]; #endif OFHashAdd(&hash, address->sockaddr.in.sin_port >> 8); OFHashAdd(&hash, address->sockaddr.in.sin_port); OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 24); OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 16); OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr >> 8); OFHashAdd(&hash, address->sockaddr.in.sin_addr.s_addr); break; case OFSocketAddressFamilyIPv6: if (address->length < (socklen_t)sizeof(struct sockaddr_in6)) @throw [OFInvalidArgumentException exception]; OFHashAdd(&hash, address->sockaddr.in6.sin6_port >> 8); OFHashAdd(&hash, address->sockaddr.in6.sin6_port); for (size_t i = 0; i < sizeof(address->sockaddr.in6.sin6_addr.s6_addr); i++) OFHashAdd(&hash, address->sockaddr.in6.sin6_addr.s6_addr[i]); break; case OFSocketAddressFamilyIPX:; unsigned char network[ sizeof(address->sockaddr.ipx.sipx_network)]; if (address->length < (socklen_t)sizeof(struct sockaddr_ipx)) @throw [OFInvalidArgumentException exception]; OFHashAdd(&hash, address->sockaddr.ipx.sipx_port >> 8); OFHashAdd(&hash, address->sockaddr.ipx.sipx_port); memcpy(network, &address->sockaddr.ipx.sipx_network, sizeof(network)); for (size_t i = 0; i < sizeof(network); i++) OFHashAdd(&hash, network[i]); for (size_t i = 0; i < IPX_NODE_LEN; i++) OFHashAdd(&hash, address->sockaddr.ipx.sipx_node[i]); break; default: @throw [OFInvalidArgumentException exception]; } OFHashFinalize(&hash); return hash; } static OFString * IPv4String(const OFSocketAddress *address) { const struct sockaddr_in *addrIn = &address->sockaddr.in; uint32_t addr = OFFromBigEndian32(addrIn->sin_addr.s_addr); OFString *string; string = [OFString stringWithFormat: @"%u.%u.%u.%u", (addr & 0xFF000000) >> 24, (addr & 0x00FF0000) >> 16, (addr & 0x0000FF00) >> 8, addr & 0x000000FF]; return string; } static OFString * IPv6String(const OFSocketAddress *address) { OFMutableString *string = [OFMutableString string]; const struct sockaddr_in6 *addrIn6 = &address->sockaddr.in6; int_fast8_t zerosStart = -1, maxZerosStart = -1; uint_fast8_t zerosCount = 0, maxZerosCount = 0; bool first = true; |
︙ | ︙ | |||
751 752 753 754 755 756 757 | addrIn6->sin6_addr.s6_addr[i + 1]]; first = false; } } [string makeImmutable]; | < < < | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 | addrIn6->sin6_addr.s6_addr[i + 1]]; first = false; } } [string makeImmutable]; return string; } OFString * OFSocketAddressString(const OFSocketAddress *address) { switch (address->family) { case OFSocketAddressFamilyIPv4: return IPv4String(address); case OFSocketAddressFamilyIPv6: return IPv6String(address); default: @throw [OFInvalidArgumentException exception]; } } void OFSocketAddressSetPort(OFSocketAddress *address, uint16_t port) { switch (address->family) { case OFSocketAddressFamilyIPv4: address->sockaddr.in.sin_port = OFToBigEndian16(port); break; case OFSocketAddressFamilyIPv6: address->sockaddr.in6.sin6_port = OFToBigEndian16(port); break; case OFSocketAddressFamilyIPX: address->sockaddr.ipx.sipx_port = OFToBigEndian16(port); break; default: @throw [OFInvalidArgumentException exception]; } } uint16_t OFSocketAddressPort(const OFSocketAddress *address) { switch (address->family) { case OFSocketAddressFamilyIPv4: return OFFromBigEndian16(address->sockaddr.in.sin_port); case OFSocketAddressFamilyIPv6: return OFFromBigEndian16(address->sockaddr.in6.sin6_port); case OFSocketAddressFamilyIPX: return OFFromBigEndian16(address->sockaddr.ipx.sipx_port); default: @throw [OFInvalidArgumentException exception]; } } void OFSocketAddressSetIPXNetwork(OFSocketAddress *address, uint32_t network) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; network = OFToBigEndian32(network); memcpy(&address->sockaddr.ipx.sipx_network, &network, sizeof(address->sockaddr.ipx.sipx_network)); } uint32_t OFSocketAddressIPXNetwork(const OFSocketAddress *address) { uint32_t network; if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(&network, &address->sockaddr.ipx.sipx_network, sizeof(network)); return OFFromBigEndian32(network); } void OFSocketAddressSetIPXNode(OFSocketAddress *address, const unsigned char node[IPX_NODE_LEN]) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(address->sockaddr.ipx.sipx_node, node, IPX_NODE_LEN); } void OFSocketAddressIPXNode(const OFSocketAddress *address, unsigned char node[IPX_NODE_LEN]) { if (address->family != OFSocketAddressFamilyIPX) @throw [OFInvalidArgumentException exception]; memcpy(node, address->sockaddr.ipx.sipx_node, IPX_NODE_LEN); } |
Modified src/OFSortedList.h from [d2fd296ecb] to [a53236cd47].
︙ | ︙ | |||
29 30 31 32 33 34 35 | #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif { OF_RESERVE_IVARS(OFSortedList, 4) } | | | | < | | < | | | 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 | #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # define ObjectType id #endif { OF_RESERVE_IVARS(OFSortedList, 4) } - (OFListItem)appendObject: (ObjectType)object OF_UNAVAILABLE; - (OFListItem)prependObject: (ObjectType)object OF_UNAVAILABLE; - (OFListItem)insertObject: (ObjectType)object beforeListItem: (OFListItem)listItem OF_UNAVAILABLE; - (OFListItem)insertObject: (ObjectType)object afterListItem: (OFListItem)listItem OF_UNAVAILABLE; /** * @brief Inserts the object to the list while keeping the list sorted. * * @param object The object to insert * @return The list object for the object just added */ - (OFListItem)insertObject: (ObjectType <OFComparing>)object; #if !defined(OF_HAVE_GENERICS) && !defined(DOXYGEN) # undef ObjectType #endif @end OF_ASSUME_NONNULL_END |
Modified src/OFSortedList.m from [1f44909bdd] to [647acba740].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "OFSortedList.h" @implementation OFSortedList | | | | < | < | | | > | > | < | 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 | */ #include "config.h" #import "OFSortedList.h" @implementation OFSortedList - (OFListItem)appendObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)prependObject: (id)object { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)insertObject: (id)object beforeListItem: (OFListItem)listItem { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)insertObject: (id)object afterListItem: (OFListItem)listItem { OF_UNRECOGNIZED_SELECTOR } - (OFListItem)insertObject: (id <OFComparing>)object { OFListItem iter; for (iter = _lastListItem; iter != NULL; iter = OFListItemPrevious(iter)) { if ([object compare: OFListItemObject(iter)] != OFOrderedAscending) return [super insertObject: object afterListItem: iter]; } return [super prependObject: object]; } @end |
Modified src/OFStdIOStream.h from [ddc90ae5f2] to [4b04bb450d].
︙ | ︙ | |||
27 28 29 30 31 32 33 | @class OFColor; /** * @class OFStdIOStream OFStdIOStream.h ObjFW/OFStdIOStream.h * * @brief A class for providing standard input, output and error as OFStream. * | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | @class OFColor; /** * @class OFStdIOStream OFStdIOStream.h ObjFW/OFStdIOStream.h * * @brief A class for providing standard input, output and error as OFStream. * * The global variables @ref OFStdIn, @ref OFStdOut and @ref OFStdErr are * instances of this class and need no initialization. */ #ifdef OF_STDIO_STREAM_WIN32_CONSOLE_H OF_SUBCLASSING_RESTRICTED #endif @interface OFStdIOStream: OFStream #if !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) |
︙ | ︙ | |||
114 115 116 117 118 119 120 | /** * @brief Moves the cursor to the specified absolute position. Does nothing if * there is no underlying terminal. * * @param position The position to move the cursor to */ | | | | | | | | | | | | | > > > > > > > > < < < < < < < < | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | /** * @brief Moves the cursor to the specified absolute position. Does nothing if * there is no underlying terminal. * * @param position The position to move the cursor to */ - (void)setCursorPosition: (OFPoint)position; /** * @brief Moves the cursor to the specified relative position. Does nothing if * there is no underlying terminal. * * @param position The position to move the cursor to */ - (void)setRelativeCursorPosition: (OFPoint)position; @end #ifdef __cplusplus extern "C" { #endif /** @file */ #ifndef OF_AMIGAOS /** * @brief The standard input as an OFStream. */ extern OFStdIOStream *_Nullable OFStdIn; /** * @brief The standard output as an OFStream. */ extern OFStdIOStream *_Nullable OFStdOut; /** * @brief The standard error as an OFStream. */ extern OFStdIOStream *_Nullable OFStdErr; #else extern OFStdIOStream *_Nonnull *_Nullable OFStdInRef(void); extern OFStdIOStream *_Nonnull *_Nullable OFStdOutRef(void); extern OFStdIOStream *_Nonnull *_Nullable OFStdErrRef(void); # define OFStdIn (*OFStdInRef()) # define OFStdOut (*OFStdOutRef()) # define OFStdErr (*OFStdErrRef()) #endif /** * @brief Logs the specified printf-style format to @ref OFStdErr. * * This prefixes the output with the date, timestamp, process name and PID and * allows `%@` as a printf-style formatted to print objects. */ extern void OFLog(OFConstantString *format, ...); /*! * @brief Logs the specified printf-style format to @ref OFStdErr. * * This prefixes the output with the date, timestamp, process name and PID and * allows `%@` as a printf-style formatted to print objects. */ extern void OFLogV(OFConstantString *format, va_list arguments); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFStdIOStream.m from [470dd5a9cf] to [2787693b17].
︙ | ︙ | |||
58 59 60 61 62 63 64 | _reference_to_OFWin32ConsoleStdIOStream(void) { [OFWin32ConsoleStdIOStream class]; } #endif #ifdef OF_AMIGAOS | | | | | | | | | | | | | | | | | | | | | | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | _reference_to_OFWin32ConsoleStdIOStream(void) { [OFWin32ConsoleStdIOStream class]; } #endif #ifdef OF_AMIGAOS # undef OFStdIn # undef OFStdOut # undef OFStdErr #endif OFStdIOStream *OFStdIn = nil; OFStdIOStream *OFStdOut = nil; OFStdIOStream *OFStdErr = nil; #ifdef OF_AMIGAOS OFStdIOStream ** OFStdInRef(void) { return &OFStdIn; } OFStdIOStream ** OFStdOutRef(void) { return &OFStdOut; } OFStdIOStream ** OFStdErrRef(void) { return &OFStdErr; } #endif #ifdef OF_AMIGAOS OF_DESTRUCTOR() { [OFStdIn dealloc]; [OFStdOut dealloc]; [OFStdErr dealloc]; } #endif void OFLog(OFConstantString *format, ...) { va_list arguments; va_start(arguments, format); OFLogV(format, arguments); va_end(arguments); } void OFLogV(OFConstantString *format, va_list arguments) { void *pool = objc_autoreleasePoolPush(); OFDate *date; OFString *dateString, *me, *msg; date = [OFDate date]; dateString = [date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; #ifdef OF_HAVE_FILES me = [OFApplication programName].lastPathComponent; #else me = [OFApplication programName]; #endif msg = [[[OFString alloc] initWithFormat: format arguments: arguments] autorelease]; [OFStdErr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, date.microsecond / 1000, me, getpid(), msg]; objc_autoreleasePoolPop(pool); } #ifdef HAVE_ISATTY static int colorToANSI(OFColor *color) |
︙ | ︙ | |||
182 183 184 185 186 187 188 | if (self != [OFStdIOStream class]) return; # ifndef OF_AMIGAOS int fd; if ((fd = fileno(stdin)) >= 0) | < | | | | 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | if (self != [OFStdIOStream class]) return; # ifndef OF_AMIGAOS int fd; if ((fd = fileno(stdin)) >= 0) OFStdIn = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = fileno(stdout)) >= 0) OFStdOut = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = fileno(stderr)) >= 0) OFStdErr = [[OFStdIOStream alloc] of_initWithFileDescriptor: fd]; # else BPTR input, output, error; bool inputClosable = false, outputClosable = false, errorClosable = false; input = Input(); |
︙ | ︙ | |||
214 215 216 217 218 219 220 | } if (error == 0) { error = Open("*", MODE_OLDFILE); errorClosable = true; } | | | | | | | | < | 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | } if (error == 0) { error = Open("*", MODE_OLDFILE); errorClosable = true; } OFStdIn = [[OFStdIOStream alloc] of_initWithHandle: input closable: inputClosable]; OFStdOut = [[OFStdIOStream alloc] of_initWithHandle: output closable: outputClosable]; OFStdErr = [[OFStdIOStream alloc] of_initWithHandle: error closable: errorClosable]; # endif } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } #ifndef OF_AMIGAOS - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super init]; _fd = fd; return self; } #else - (instancetype)of_initWithHandle: (BPTR)handle closable: (bool)closable { self = [super init]; _handle = handle; _closable = closable; return self; |
︙ | ︙ | |||
275 276 277 278 279 280 281 | if (_handle == 0) #endif @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } | | < | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | if (_handle == 0) #endif @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; #ifndef OF_AMIGAOS if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; |
︙ | ︙ | |||
317 318 319 320 321 322 323 | if (ret == 0) _atEndOfStream = true; return ret; } | | < | 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { #ifndef OF_AMIGAOS if (_fd == -1) @throw [OFNotOpenException exceptionWithObject: self]; # ifndef OF_WINDOWS ssize_t bytesWritten; |
︙ | ︙ | |||
415 416 417 418 419 420 421 | - (void)release { } - (unsigned int)retainCount { | | | 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } - (bool)hasTerminal { #ifdef HAVE_ISATTY return isatty(_fd); #else |
︙ | ︙ | |||
525 526 527 528 529 530 531 | if (!isatty(_fd)) return; [self writeFormat: @"\033[%uG", column + 1]; #endif } | | | | 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | if (!isatty(_fd)) return; [self writeFormat: @"\033[%uG", column + 1]; #endif } - (void)setCursorPosition: (OFPoint)position { if (position.x < 0 || position.y < 0) @throw [OFInvalidArgumentException exception]; #ifdef HAVE_ISATTY if (!isatty(_fd)) return; [self writeFormat: @"\033[%u;%uH", (unsigned)position.y + 1, (unsigned)position.x + 1]; #endif } - (void)setRelativeCursorPosition: (OFPoint)position { #ifdef HAVE_ISATTY if (!isatty(_fd)) return; if (position.x > 0) [self writeFormat: @"\033[%uC", (unsigned)position.x]; |
︙ | ︙ |
Renamed and modified src/of_strptime.h [49e70fc30c] to src/OFStrPTime.h [fd2cee796f].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif | | | | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "macros.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern const char *_Nullable OFStrPTime(const char *buffer, const char *format, struct tm *tm, short *tz); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Renamed and modified src/of_strptime.m [aca88fc28d] to src/OFStrPTime.m [2eebe7783d].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #include <string.h> #include <time.h> #import "macros.h" const char * | | | | | | | | < | 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 | #include <string.h> #include <time.h> #import "macros.h" const char * OFStrPTime(const char *buffer, const char *format, struct tm *tm, short *tz) { enum { stateSearchConversionSpecifier, stateInConversionSpecifier } state = stateSearchConversionSpecifier; size_t j, bufferLen, formatLen; bufferLen = strlen(buffer); formatLen = strlen(format); j = 0; for (size_t i = 0; i < formatLen; i++) { if (j >= bufferLen) return NULL; switch (state) { case stateSearchConversionSpecifier: if (format[i] == '%') state = stateInConversionSpecifier; else if (format[i] != buffer[j++]) return NULL; break; case stateInConversionSpecifier:; int k, maxLen, number = 0; switch (format[i]) { case 'd': case 'e': case 'H': case 'm': |
︙ | ︙ | |||
217 218 219 220 221 222 223 | break; case 't': if (buffer[j++] != '\t') return NULL; break; } | | | 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | break; case 't': if (buffer[j++] != '\t') return NULL; break; } state = stateSearchConversionSpecifier; break; } } return buffer + j; } |
Modified src/OFStream.h from [d7b8ceded5] to [b19f1dd539].
︙ | ︙ | |||
42 43 44 45 46 47 48 | * stream. * * @param length The length of the data that has been read * @param exception An exception which occurred while reading or `nil` on * success * @return A bool whether the same block should be used for the next read */ | < | | | | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | * stream. * * @param length The length of the data that has been read * @param exception An exception which occurred while reading or `nil` on * success * @return A bool whether the same block should be used for the next read */ typedef bool (^OFStreamAsyncReadBlock)(size_t length, id _Nullable exception); /** * @brief A block which is called when a line was read asynchronously from a * stream. * * @param line The line which has been read or `nil` when the end of stream * occurred * @param exception An exception which occurred while reading or `nil` on * success * @return A bool whether the same block should be used for the next read */ typedef bool (^OFStreamAsyncReadLineBlock)(OFString *_Nullable line, id _Nullable exception); /** * @brief A block which is called when data was written asynchronously to a * stream. * * @param data The data which was written to the stream * @param bytesWritten The number of bytes which have been written. This * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception which occurred while writing or `nil` on * success * @return The data to repeat the write with or nil if it should not repeat */ typedef OFData *_Nullable (^OFStreamAsyncWriteDataBlock)(OFData *_Nonnull data, size_t bytesWritten, id _Nullable exception); /** * @brief A block which is called when a string was written asynchronously to a * stream. * * @param string The string which was written to the stream * @param bytesWritten The number of bytes which have been written. This * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception which occurred while writing or `nil` on * success * @return The string to repeat the write with or nil if it should not repeat */ typedef OFString *_Nullable (^OFStreamAsyncWriteStringBlock)( OFString *_Nonnull string, size_t bytesWritten, id _Nullable exception); #endif /** * @protocol OFStreamDelegate OFStream.h ObjFW/OFStream.h * * A delegate for OFStream. |
︙ | ︙ | |||
157 158 159 160 161 162 163 | * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception that occurred while writing, or nil on success * @return The string to repeat the write with or nil if it should not repeat */ - (nullable OFString *)stream: (OFStream *)stream didWriteString: (OFString *)string | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | * matches the length of the specified data on the * asynchronous write if no exception was encountered. * @param exception An exception that occurred while writing, or nil on success * @return The string to repeat the write with or nil if it should not repeat */ - (nullable OFString *)stream: (OFStream *)stream didWriteString: (OFString *)string encoding: (OFStringEncoding)encoding bytesWritten: (size_t)bytesWritten exception: (nullable id)exception; @end /** * @class OFStream OFStream.h ObjFW/OFStream.h * |
︙ | ︙ | |||
244 245 246 247 248 249 250 | * result of 0 bytes. * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @return The number of bytes read */ | | < | < | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | * result of 0 bytes. * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @return The number of bytes read */ - (size_t)readIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Reads exactly the specified length bytes from the stream into a * buffer. * * Unlike @ref readIntoBuffer:length:, this method does not return when less * than the specified length has been read - instead, it waits until it got * exactly the specified length. * * @warning Only call this when you know that specified amount of data is * available! Otherwise you will get an exception! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! */ - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously reads *at most* size bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. |
︙ | ︙ | |||
286 287 288 289 290 291 292 | * for this to work! * * @param buffer The buffer into which the data is read. * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! */ | | < | 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | * for this to work! * * @param buffer The buffer into which the data is read. * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Asynchronously reads *at most* size bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use |
︙ | ︙ | |||
312 313 314 315 316 317 318 | * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length | | | < | | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | * The buffer must not be freed before the async read completed! * @param length The length of the data that should be read at most. * The buffer *must* be *at least* this big! * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; /** * @brief Asynchronously reads exactly the specified length bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:, this method does not call the * method when less than the specified length has been read - instead, it waits * until it got exactly the specified length, the stream has ended or an * exception occurred. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length; /** * @brief Asynchronously reads exactly the specified length bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:, this method does not call the * method when less than the specified length has been read - instead, it waits * until it got exactly the specified length, the stream has ended or an * exception occurred. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param buffer The buffer into which the data is read * @param length The length of the data that should be read. * The buffer *must* be *at least* this big! * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously reads *at most* ref size bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. |
︙ | ︙ | |||
382 383 384 385 386 387 388 | * If the block returns true, it will be called again with the same * buffer and maximum length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length | | | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | * If the block returns true, it will be called again with the same * buffer and maximum length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads *at most* ref size bytes from the stream into a * buffer. * * On network streams, this might read less than the specified number of bytes. * If you want to read exactly the specified number of bytes, use |
︙ | ︙ | |||
412 413 414 415 416 417 418 | * If the block returns true, it will be called again with the same * buffer and maximum length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length | | | | 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | * If the block returns true, it will be called again with the same * buffer and maximum length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads exactly the specified length bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:block:, this method does not invoke * the block when less than the specified length has been read - instead, it |
︙ | ︙ | |||
438 439 440 441 442 443 444 | * If the block returns true, it will be called again with the same * buffer and exact length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length | | | 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | * If the block returns true, it will be called again with the same * buffer and exact length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length block: (OFStreamAsyncReadBlock)block; /** * @brief Asynchronously reads exactly the specified length bytes from the * stream into a buffer. * * Unlike @ref asyncReadIntoBuffer:length:block:, this method does not invoke * the block when less than the specified length has been read - instead, it |
︙ | ︙ | |||
464 465 466 467 468 469 470 | * If the block returns true, it will be called again with the same * buffer and exact length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length | | | | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | * If the block returns true, it will be called again with the same * buffer and exact length when more data has been received. If * you want the next block in the queue to handle the data * received next, you need to return false from the block. */ - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block; # endif #endif /** * @brief Reads a uint8_t from the stream. * * @warning Only call this when you know that enough data is available! |
︙ | ︙ | |||
586 587 588 589 590 591 592 | * Otherwise you will get an exception! * * @param buffer A buffer of sufficient size to store the specified number of * floats * @param count The number of floats to read * @return The number of bytes read */ | | < | < | 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 | * Otherwise you will get an exception! * * @param buffer A buffer of sufficient size to store the specified number of * floats * @param count The number of floats to read * @return The number of bytes read */ - (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count; /** * @brief Reads the specified number of doubles from the stream which are * encoded in big endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param buffer A buffer of sufficient size to store the specified number of * doubles * @param count The number of doubles to read * @return The number of bytes read */ - (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count; /** * @brief Reads a uint16_t from the stream which is encoded in little endian. * * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * |
︙ | ︙ | |||
752 753 754 755 756 757 758 | * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param itemSize The size of each item * @param count The number of items to read * @return OFData with count items. */ | | < | 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | * @warning Only call this when you know that enough data is available! * Otherwise you will get an exception! * * @param itemSize The size of each item * @param count The number of items to read * @return OFData with count items. */ - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count; /** * @brief Returns OFData with all the remaining data of the stream. * * @return OFData with an item size of 1 with all the data of the stream until * the end of the stream is reached. */ |
︙ | ︙ | |||
795 796 797 798 799 800 801 | * Otherwise you will get an exception! * * @param encoding The encoding of the string to read from the stream * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length */ - (OFString *)readStringWithLength: (size_t)length | | | | | | | | | | | | | 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | * Otherwise you will get an exception! * * @param encoding The encoding of the string to read from the stream * @param length The length (in bytes) of the string to read from the stream * @return A string with the specified length */ - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding; /** * @brief Reads until a newline, `\0` or end of stream occurs. * * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)readLine; /** * @brief Reads with the specified encoding until a newline, `\0` or end of * stream occurs. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)readLineWithEncoding: (OFStringEncoding)encoding; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously reads until a newline, `\0`, end of stream or an * exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! */ - (void)asyncReadLine; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream * @param runLoopMode The run loop mode in which to perform the async read */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously reads until a newline, `\0`, end of stream or an * exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param block The block to call when the data has been received. * If the block returns true, it will be called again when the next * line has been received. If you want the next block in the queue * to handle the next line, you need to return false from the * block. */ - (void)asyncReadLineWithBlock: (OFStreamAsyncReadLineBlock)block; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream * @param block The block to call when the data has been received. * If the block returns true, it will be called again when the next * line has been received. If you want the next block in the queue * to handle the next line, you need to return false from the * block. */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding block: (OFStreamAsyncReadLineBlock)block; /** * @brief Asynchronously reads with the specified encoding until a newline, * `\0`, end of stream or an exception occurs. * * @note The stream must conform to @ref OFReadyForReadingObserving in order * for this to work! * * @param encoding The encoding used by the stream * @param runLoopMode The run loop mode in which to perform the async read * @param block The block to call when the data has been received. * If the block returns true, it will be called again when the next * line has been received. If you want the next block in the queue * to handle the next line, you need to return false from the * block. */ - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadLineBlock)block; # endif #endif /** * @brief Tries to read a line from the stream (see @ref readLine) and returns * `nil` if no complete line has been received yet. * |
︙ | ︙ | |||
921 922 923 924 925 926 927 | * @ref readLineWithEncoding:) and returns `nil` if no complete line has * been received yet. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet */ | | | 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 | * @ref readLineWithEncoding:) and returns `nil` if no complete line has * been received yet. * * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the line is not * complete yet */ - (nullable OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding; /** * @brief Reads until the specified string or `\0` is found or the end of * stream occurs. * * @param delimiter The delimiter * @return The line that was read, autoreleased, or `nil` if the end of the |
︙ | ︙ | |||
943 944 945 946 947 948 949 | * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)readTillDelimiter: (OFString *)delimiter | | | 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 | * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)readTillDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding; /** * @brief Tries to reads until the specified string or `\0` is found or the end * of stream (see @ref readTillDelimiter:) and returns `nil` if not * enough data has been received yet. * * @param delimiter The delimiter |
︙ | ︙ | |||
967 968 969 970 971 972 973 | * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)tryReadTillDelimiter: (OFString *)delimiter | | | < | 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 | * * @param delimiter The delimiter * @param encoding The encoding used by the stream * @return The line that was read, autoreleased, or `nil` if the end of the * stream has been reached. */ - (nullable OFString *)tryReadTillDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding; /** * @brief Writes everything in the write buffer to the stream. */ - (void)flushWriteBuffer; /** * @brief Writes from a buffer into the stream. * * @param buffer The buffer from which the data is written into the stream * @param length The length of the data that should be written * @return The number of bytes written. This can only differ from the specified * length in non-blocking mode. */ - (size_t)writeBuffer: (const void *)buffer length: (size_t)length; #ifdef OF_HAVE_SOCKETS /** * @brief Asynchronously writes data into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! |
︙ | ︙ | |||
1006 1007 1008 1009 1010 1011 1012 | * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream * @param runLoopMode The run loop mode in which to perform the async write */ - (void)asyncWriteData: (OFData *)data | | | 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 | * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream * @param runLoopMode The run loop mode in which to perform the async write */ - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode; /** * @brief Asynchronously writes a string in UTF-8 encoding into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * |
︙ | ︙ | |||
1030 1031 1032 1033 1034 1035 1036 | * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream */ - (void)asyncWriteString: (OFString *)string | | | | | | | | | | | | | | 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 | * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Asynchronously writes a string in the specified encoding into the * stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream * @param runLoopMode The run loop mode in which to perform the async write */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode; # ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously writes data into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream * @param block The block to call when the data has been written. It should * return the data for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteData: (OFData *)data block: (OFStreamAsyncWriteDataBlock)block; /** * @brief Asynchronously writes data into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param data The data which is written into the stream * @param runLoopMode The run loop mode in which to perform the async write * @param block The block to call when the data has been written. It should * return the data for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteDataBlock)block; /** * @brief Asynchronously writes a string into the stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param block The block to call when the string has been written. It should * return the string for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteString: (OFString *)string block: (OFStreamAsyncWriteStringBlock)block; /** * @brief Asynchronously writes a string in the specified encoding into the * stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream * @param block The block to call when the string has been written. It should * return the string for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding block: (OFStreamAsyncWriteStringBlock)block; /** * @brief Asynchronously writes a string in the specified encoding into the * stream. * * @note The stream must conform to @ref OFReadyForWritingObserving in order * for this to work! * * @param string The string which is written into the stream * @param encoding The encoding in which the string should be written to the * stream * @param runLoopMode The run loop mode in which to perform the async write * @param block The block to call when the string has been written. It should * return the string for the next write with the same callback or * nil if it should not repeat. */ - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteStringBlock)block; # endif #endif /** * @brief Writes a uint8_t into the stream. * * @param int8 A uint8_t |
︙ | ︙ | |||
1184 1185 1186 1187 1188 1189 1190 | * big endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of uint16_ts to write * @return The number of bytes written to the stream */ | | < | < | < | < | < | 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 | * big endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of uint16_ts to write * @return The number of bytes written to the stream */ - (size_t)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count; /** * @brief Writes the specified number of uint32_ts into the stream, encoded in * big endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of uint32_ts to write * @return The number of bytes written to the stream */ - (size_t)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count; /** * @brief Writes the specified number of uint64_ts into the stream, encoded in * big endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of uint64_ts to write * @return The number of bytes written to the stream */ - (size_t)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count; /** * @brief Writes the specified number of floats into the stream, encoded in big * endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of floats to write * @return The number of bytes written to the stream */ - (size_t)writeBigEndianFloats: (const float *)buffer count: (size_t)count; /** * @brief Writes the specified number of doubles into the stream, encoded in * big endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of doubles to write * @return The number of bytes written to the stream */ - (size_t)writeBigEndianDoubles: (const double *)buffer count: (size_t)count; /** * @brief Writes a uint16_t into the stream, encoded in little endian. * * @param int16 A uint16_t */ - (void)writeLittleEndianInt16: (uint16_t)int16; |
︙ | ︙ | |||
1315 1316 1317 1318 1319 1320 1321 | * little endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of floats to write * @return The number of bytes written to the stream */ | | < | < | 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | * little endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of floats to write * @return The number of bytes written to the stream */ - (size_t)writeLittleEndianFloats: (const float *)buffer count: (size_t)count; /** * @brief Writes the specified number of doubles into the stream, encoded in * little endian. * * @param buffer The buffer from which the data is written to the stream after * it has been byte swapped if necessary * @param count The number of doubles to write * @return The number of bytes written to the stream */ - (size_t)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count; /** * @brief Writes OFData into the stream. * * @param data The OFData to write into the stream * @return The number of bytes written */ |
︙ | ︙ | |||
1354 1355 1356 1357 1358 1359 1360 | * @brief Writes a string into the stream in the specified encoding, without * the trailing zero. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream * @return The number of bytes written */ | | < | < | | | | | < | 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 | * @brief Writes a string into the stream in the specified encoding, without * the trailing zero. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream * @return The number of bytes written */ - (size_t)writeString: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a string into the stream with a trailing newline. * * @param string The string from which the data is written to the stream * @return The number of bytes written */ - (size_t)writeLine: (OFString *)string; /** * @brief Writes a string into the stream in the specified encoding with a * trailing newline. * * @param string The string from which the data is written to the stream * @param encoding The encoding in which to write the string to the stream * @return The number of bytes written */ - (size_t)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format * @return The number of bytes written */ - (size_t)writeFormat: (OFConstantString *)format, ...; /** * @brief Writes a formatted string into the stream. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format * @param arguments The arguments used in the format string * @return The number of bytes written */ - (size_t)writeFormat: (OFConstantString *)format arguments: (va_list)arguments; #ifdef OF_HAVE_SOCKETS /** * @brief Cancels all pending asynchronous requests on the stream. */ - (void)cancelAsyncRequests; #endif |
︙ | ︙ | |||
1430 1431 1432 1433 1434 1435 1436 | * * If the stream is seekable, a seek operation will discard any data which was * unread. * * @param buffer The buffer to unread * @param length The length of the buffer to unread */ | | < | < | < | 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 | * * If the stream is seekable, a seek operation will discard any data which was * unread. * * @param buffer The buffer to unread * @param length The length of the buffer to unread */ - (void)unreadFromBuffer: (const void *)buffer length: (size_t)length; /** * @brief Closes the stream. * * @note If you override this, make sure to call `[super close]`! */ - (void)close; /** * @brief Performs a lowlevel read. * * @warning Do not call this directly! * * @note Override this method with your actual read implementation when * subclassing! * * @param buffer The buffer for the data to read * @param length The length of the buffer * @return The number of bytes read */ - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length; /** * @brief Performs a lowlevel write. * * @warning Do not call this directly! * * @note Override this method with your actual write implementation when * subclassing! * * @param buffer The buffer with the data to write * @param length The length of the data to write * @return The number of bytes written */ - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length; /** * @brief Returns whether the lowlevel is at the end of the stream. * * @warning Do not call this directly! * * @note Override this method with your actual end of stream checking |
︙ | ︙ |
Modified src/OFStream.m from [d41d938d85] to [8b3bdb0a6a].
︙ | ︙ | |||
24 25 26 27 28 29 30 | #include <stdlib.h> #include <string.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif | < < < < > > > > < | < | 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 61 62 63 64 65 66 | #include <stdlib.h> #include <string.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #include "platform.h" #if !defined(OF_WINDOWS) && !defined(OF_MORPHOS) # include <signal.h> #endif #import "OFStream.h" #import "OFStream+Private.h" #import "OFASPrintF.h" #import "OFData.h" #import "OFKernelEventObserver.h" #import "OFRunLoop+Private.h" #import "OFRunLoop.h" #ifdef OF_HAVE_SOCKETS # import "OFSocket+Private.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFSetOptionFailedException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" #define minReadSize 512 @implementation OFStream @synthesize buffersWrites = _buffersWrites; @synthesize of_waitingForDelimiter = _waitingForDelimiter, delegate = _delegate; #if defined(SIGPIPE) && defined(SIG_IGN) + (void)initialize |
︙ | ︙ | |||
89 90 91 92 93 94 95 | } return self; } - (void)dealloc { | | | | < | < | < | | | < | | > | < | | < | < | | | < | | | | | | | | | | < | < < < | < | < < | < | < < | < | < < | < | < < | < | < | < | < | | < | < | | < | < | | < | < | | < | < | < | < | < < | < | < < | < | < < | < | < < | < | < | < | | < | | < | | < | | < | | < | < | | < < | | | < | < | < | < | | | | < < | < | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | } return self; } - (void)dealloc { OFFreeMemory(_readBufferMemory); OFFreeMemory(_writeBuffer); [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { OF_UNRECOGNIZED_SELECTOR } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (id)copy { return [self retain]; } - (bool)isAtEndOfStream { if (_readBufferLength > 0) return false; return [self lowlevelIsAtEndOfStream]; } - (size_t)readIntoBuffer: (void *)buffer length: (size_t)length { if (_readBufferLength == 0) { /* * For small sizes, it is cheaper to read more and cache the * remainder - even if that means more copying of data - than * to do a syscall for every read. */ if (length < minReadSize) { char tmp[minReadSize], *readBuffer; size_t bytesRead; bytesRead = [self lowlevelReadIntoBuffer: tmp length: minReadSize]; if (bytesRead > length) { memcpy(buffer, tmp, length); readBuffer = OFAllocMemory(bytesRead - length, 1); memcpy(readBuffer, tmp + length, bytesRead - length); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bytesRead - length; return length; } else { memcpy(buffer, tmp, bytesRead); return bytesRead; } } return [self lowlevelReadIntoBuffer: buffer length: length]; } if (length >= _readBufferLength) { size_t ret = _readBufferLength; memcpy(buffer, _readBuffer, _readBufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; return ret; } else { memcpy(buffer, _readBuffer, length); _readBuffer += length; _readBufferLength -= length; return length; } } - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length { size_t readLength = 0; while (readLength < length) { if (self.atEndOfStream) @throw [OFTruncatedDataException exception]; readLength += [self readIntoBuffer: (char *)buffer + readLength length: length - readLength]; } } #ifdef OF_HAVE_SOCKETS - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length { [self asyncReadIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { OFStream <OFReadyForReadingObserving> *stream = (OFStream <OFReadyForReadingObserving> *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer length: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length { [self asyncReadIntoBuffer: buffer exactLength: length runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode { OFStream <OFReadyForReadingObserving> *stream = (OFStream <OFReadyForReadingObserving> *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer exactLength: length mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length block: (OFStreamAsyncReadBlock)block { [self asyncReadIntoBuffer: buffer length: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadIntoBuffer: (void *)buffer length: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block { OFStream <OFReadyForReadingObserving> *stream = (OFStream <OFReadyForReadingObserving> *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer length: length mode: runLoopMode block: block delegate: nil]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length block: (OFStreamAsyncReadBlock)block { [self asyncReadIntoBuffer: buffer exactLength: length runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadIntoBuffer: (void *)buffer exactLength: (size_t)length runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadBlock)block { OFStream <OFReadyForReadingObserving> *stream = (OFStream <OFReadyForReadingObserving> *)self; [OFRunLoop of_addAsyncReadForStream: stream buffer: buffer exactLength: length mode: runLoopMode block: block delegate: nil]; } # endif #endif - (uint8_t)readInt8 { uint8_t ret; [self readIntoBuffer: (char *)&ret exactLength: 1]; return ret; } - (uint16_t)readBigEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; return OFFromBigEndian16(ret); } - (uint32_t)readBigEndianInt32 { uint32_t ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromBigEndian32(ret); } - (uint64_t)readBigEndianInt64 { uint64_t ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromBigEndian64(ret); } - (float)readBigEndianFloat { float ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromBigEndianFloat(ret); } - (double)readBigEndianDouble { double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromBigEndianDouble(ret); } - (size_t)readBigEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint16_t); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwap16(buffer[i]); #endif return size; } - (size_t)readBigEndianInt32sIntoBuffer: (uint32_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint32_t); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwap32(buffer[i]); #endif return size; } - (size_t)readBigEndianInt64sIntoBuffer: (uint64_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint64_t); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwap64(buffer[i]); #endif return size; } - (size_t)readBigEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) @throw [OFOutOfRangeException exception]; size = count * sizeof(float); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwapFloat(buffer[i]); #endif return size; } - (size_t)readBigEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) @throw [OFOutOfRangeException exception]; size = count * sizeof(double); [self readIntoBuffer: buffer exactLength: size]; #ifndef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwapDouble(buffer[i]); #endif return size; } - (uint16_t)readLittleEndianInt16 { uint16_t ret; [self readIntoBuffer: (char *)&ret exactLength: 2]; return OFFromLittleEndian16(ret); } - (uint32_t)readLittleEndianInt32 { uint32_t ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromLittleEndian32(ret); } - (uint64_t)readLittleEndianInt64 { uint64_t ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromLittleEndian64(ret); } - (float)readLittleEndianFloat { float ret; [self readIntoBuffer: (char *)&ret exactLength: 4]; return OFFromLittleEndianFloat(ret); } - (double)readLittleEndianDouble { double ret; [self readIntoBuffer: (char *)&ret exactLength: 8]; return OFFromLittleEndianDouble(ret); } - (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint16_t); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwap16(buffer[i]); #endif return size; } - (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint32_t); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwap32(buffer[i]); #endif return size; } - (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint64_t); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwap64(buffer[i]); #endif return size; } - (size_t)readLittleEndianFloatsIntoBuffer: (float *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) @throw [OFOutOfRangeException exception]; size = count * sizeof(float); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwapFloat(buffer[i]); #endif return size; } - (size_t)readLittleEndianDoublesIntoBuffer: (double *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) @throw [OFOutOfRangeException exception]; size = count * sizeof(double); [self readIntoBuffer: buffer exactLength: size]; #ifdef OF_FLOAT_BIG_ENDIAN for (size_t i = 0; i < count; i++) buffer[i] = OFByteSwapDouble(buffer[i]); #endif return size; } - (OFData *)readDataWithCount: (size_t)count { return [self readDataWithItemSize: 1 count: count]; } - (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count { OFData *ret; char *buffer; if OF_UNLIKELY (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exception]; buffer = OFAllocMemory(count, itemSize); @try { [self readIntoBuffer: buffer exactLength: count * itemSize]; ret = [OFData dataWithItemsNoCopy: buffer count: count itemSize: itemSize freeWhenDone: true]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } return ret; } - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; char *buffer = OFAllocMemory(1, pageSize); @try { while (!self.atEndOfStream) { size_t length = [self readIntoBuffer: buffer length: pageSize]; [data addItems: buffer count: length]; } } @finally { OFFreeMemory(buffer); } [data makeImmutable]; return data; } - (OFString *)readStringWithLength: (size_t)length { return [self readStringWithLength: length encoding: OFStringEncodingUTF8]; } - (OFString *)readStringWithLength: (size_t)length encoding: (OFStringEncoding)encoding { OFString *ret; char *buffer = OFAllocMemory(length + 1, 1); buffer[length] = 0; @try { [self readIntoBuffer: buffer exactLength: length]; ret = [OFString stringWithCString: buffer encoding: encoding]; } @finally { OFFreeMemory(buffer); } return ret; } - (OFString *)tryReadLineWithEncoding: (OFStringEncoding)encoding { size_t pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; /* Look if there's a line or \0 in our buffer */ if (!_waitingForDelimiter && _readBuffer != NULL) { |
︙ | ︙ | |||
735 736 737 738 739 740 741 | return ret; } } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; | | | | | 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 | return ret; } } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { size_t retLength; if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } retLength = _readBufferLength; if (retLength > 0 && _readBuffer[retLength - 1] == '\r') retLength--; ret = [OFString stringWithCString: _readBuffer encoding: encoding length: retLength]; OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { size_t retLength = _readBufferLength + i; char *retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL) memcpy(retCString, _readBuffer, _readBufferLength); memcpy(retCString + _readBufferLength, buffer, i); |
︙ | ︙ | |||
794 795 796 797 798 799 800 | length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ | | | | | > | > | < | | | | | | | | | | | | | | | | | | | | | | 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { OFFreeMemory(retCString); } readBuffer = OFAllocMemory(bufferLength - i - 1, 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; } } /* There was no newline or \0 */ if (bufferLength > 0) { readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } - (OFString *)readLine { return [self readLineWithEncoding: OFStringEncodingUTF8]; } - (OFString *)readLineWithEncoding: (OFStringEncoding)encoding { OFString *line = nil; while ((line = [self tryReadLineWithEncoding: encoding]) == nil) if (self.atEndOfStream) return nil; return line; } #ifdef OF_HAVE_SOCKETS - (void)asyncReadLine { [self asyncReadLineWithEncoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding { [self asyncReadLineWithEncoding: encoding runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode { OFStream <OFReadyForReadingObserving> *stream = (OFStream <OFReadyForReadingObserving> *)self; [OFRunLoop of_addAsyncReadLineForStream: stream encoding: encoding mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS - (void)asyncReadLineWithBlock: (OFStreamAsyncReadLineBlock)block { [self asyncReadLineWithEncoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding block: (OFStreamAsyncReadLineBlock)block { [self asyncReadLineWithEncoding: encoding runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncReadLineWithEncoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncReadLineBlock)block { OFStream <OFReadyForReadingObserving> *stream = (OFStream <OFReadyForReadingObserving> *)self; [OFRunLoop of_addAsyncReadLineForStream: stream encoding: encoding mode: runLoopMode block: block delegate: nil]; } # endif #endif - (OFString *)tryReadLine { return [self tryReadLineWithEncoding: OFStringEncodingUTF8]; } - (OFString *)tryReadTillDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding { const char *delimiterCString; size_t j, delimiterLength, pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; delimiterCString = [delimiter cStringWithEncoding: encoding]; |
︙ | ︙ | |||
973 974 975 976 977 978 979 | return ret; } } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; | | | | 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 | return ret; } } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = OFAllocMemory(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } ret = [OFString stringWithCString: _readBuffer encoding: encoding length: _readBufferLength]; OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; _waitingForDelimiter = false; return ret; } |
︙ | ︙ | |||
1011 1012 1013 1014 1015 1016 1017 | char *retCString; if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; | | | 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 | char *retCString; if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; retCString = OFAllocMemory(retLength, 1); if (_readBuffer != NULL && _readBufferLength <= retLength) memcpy(retCString, _readBuffer, _readBufferLength); else if (_readBuffer != NULL) memcpy(retCString, _readBuffer, |
︙ | ︙ | |||
1035 1036 1037 1038 1039 1040 1041 | length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ | | | | | > | > | < | | | | | | < | | | < | < | | | | | | | < | | | | | | | | | | | | | < < | | < < | | < < | | < < | | < < | | < | < | < | | | < | | < | < | | | < | | < | < | | | < | | < | < | | | < | | < | < | | | < | < | | < < | | < < | | < < | | < < | | < | < | < | | | < | | < | < | | | < | | < | < | | | < | | < | < | | | < | | < | < | | | < | < > | < | < | < | < | < | | < | | < | < | | < | 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 | length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = readBuffer; _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { OFFreeMemory(retCString); } readBuffer = OFAllocMemory(bufferLength - i - 1, 1); if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength = bufferLength - i - 1; _waitingForDelimiter = false; return ret; } } /* Neither the delimiter nor \0 was found */ if (bufferLength > 0) { readBuffer = OFAllocMemory( _readBufferLength + bufferLength, 1); memcpy(readBuffer, _readBuffer, _readBufferLength); memcpy(readBuffer + _readBufferLength, buffer, bufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { OFFreeMemory(buffer); } _waitingForDelimiter = true; return nil; } - (OFString *)readTillDelimiter: (OFString *)delimiter { return [self readTillDelimiter: delimiter encoding: OFStringEncodingUTF8]; } - (OFString *)readTillDelimiter: (OFString *)delimiter encoding: (OFStringEncoding)encoding { OFString *ret = nil; while ((ret = [self tryReadTillDelimiter: delimiter encoding: encoding]) == nil) if (self.atEndOfStream) return nil; return ret; } - (OFString *)tryReadTillDelimiter: (OFString *)delimiter { return [self tryReadTillDelimiter: delimiter encoding: OFStringEncodingUTF8]; } - (void)flushWriteBuffer { if (_writeBuffer == NULL) return; [self lowlevelWriteBuffer: _writeBuffer length: _writeBufferLength]; OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; } - (size_t)writeBuffer: (const void *)buffer length: (size_t)length { if (!_buffersWrites) { size_t bytesWritten = [self lowlevelWriteBuffer: buffer length: length]; if (_canBlock && bytesWritten < length) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: bytesWritten errNo: 0]; return bytesWritten; } else { _writeBuffer = OFResizeMemory(_writeBuffer, _writeBufferLength + length, 1); memcpy(_writeBuffer + _writeBufferLength, buffer, length); _writeBufferLength += length; return length; } } #ifdef OF_HAVE_SOCKETS - (void)asyncWriteData: (OFData *)data { [self asyncWriteData: data runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode { OFStream <OFReadyForWritingObserving> *stream = (OFStream <OFReadyForWritingObserving> *)self; [OFRunLoop of_addAsyncWriteForStream: stream data: data mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } - (void)asyncWriteString: (OFString *)string { [self asyncWriteString: string encoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding { [self asyncWriteString: string encoding: encoding runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode { OFStream <OFReadyForWritingObserving> *stream = (OFStream <OFReadyForWritingObserving> *)self; [OFRunLoop of_addAsyncWriteForStream: stream string: string encoding: encoding mode: runLoopMode # ifdef OF_HAVE_BLOCKS block: NULL # endif delegate: _delegate]; } # ifdef OF_HAVE_BLOCKS - (void)asyncWriteData: (OFData *)data block: (OFStreamAsyncWriteDataBlock)block { [self asyncWriteData: data runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteData: (OFData *)data runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteDataBlock)block { OFStream <OFReadyForWritingObserving> *stream = (OFStream <OFReadyForWritingObserving> *)self; [OFRunLoop of_addAsyncWriteForStream: stream data: data mode: runLoopMode block: block delegate: nil]; } - (void)asyncWriteString: (OFString *)string block: (OFStreamAsyncWriteStringBlock)block { [self asyncWriteString: string encoding: OFStringEncodingUTF8 runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding block: (OFStreamAsyncWriteStringBlock)block { [self asyncWriteString: string encoding: encoding runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncWriteString: (OFString *)string encoding: (OFStringEncoding)encoding runLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamAsyncWriteStringBlock)block { OFStream <OFReadyForWritingObserving> *stream = (OFStream <OFReadyForWritingObserving> *)self; [OFRunLoop of_addAsyncWriteForStream: stream string: string encoding: encoding mode: runLoopMode block: block delegate: nil]; } # endif #endif - (void)writeInt8: (uint8_t)int8 { [self writeBuffer: (char *)&int8 length: 1]; } - (void)writeBigEndianInt16: (uint16_t)int16 { int16 = OFToBigEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } - (void)writeBigEndianInt32: (uint32_t)int32 { int32 = OFToBigEndian32(int32); [self writeBuffer: (char *)&int32 length: 4]; } - (void)writeBigEndianInt64: (uint64_t)int64 { int64 = OFToBigEndian64(int64); [self writeBuffer: (char *)&int64 length: 8]; } - (void)writeBigEndianFloat: (float)float_ { float_ = OFToBigEndianFloat(float_); [self writeBuffer: (char *)&float_ length: 4]; } - (void)writeBigEndianDouble: (double)double_ { double_ = OFToBigEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } - (size_t)writeBigEndianInt16s: (const uint16_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint16_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwap16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint32_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwap32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint64_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwap64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeBigEndianFloats: (const float *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) @throw [OFOutOfRangeException exception]; size = count * sizeof(float); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else float *tmp = OFAllocMemory(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwapFloat(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeBigEndianDoubles: (const double *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) @throw [OFOutOfRangeException exception]; size = count * sizeof(double); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else double *tmp = OFAllocMemory(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwapDouble(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (void)writeLittleEndianInt16: (uint16_t)int16 { int16 = OFToLittleEndian16(int16); [self writeBuffer: (char *)&int16 length: 2]; } - (void)writeLittleEndianInt32: (uint32_t)int32 { int32 = OFToLittleEndian32(int32); [self writeBuffer: (char *)&int32 length: 4]; } - (void)writeLittleEndianInt64: (uint64_t)int64 { int64 = OFToLittleEndian64(int64); [self writeBuffer: (char *)&int64 length: 8]; } - (void)writeLittleEndianFloat: (float)float_ { float_ = OFToLittleEndianFloat(float_); [self writeBuffer: (char *)&float_ length: 4]; } - (void)writeLittleEndianDouble: (double)double_ { double_ = OFToLittleEndianDouble(double_); [self writeBuffer: (char *)&double_ length: 8]; } - (size_t)writeLittleEndianInt16s: (const uint16_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint16_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint16_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint16_t *tmp = OFAllocMemory(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwap16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeLittleEndianInt32s: (const uint32_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint32_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint32_t *tmp = OFAllocMemory(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwap32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeLittleEndianInt64s: (const uint64_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint64_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint64_t *tmp = OFAllocMemory(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwap64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeLittleEndianFloats: (const float *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) @throw [OFOutOfRangeException exception]; size = count * sizeof(float); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else float *tmp = OFAllocMemory(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwapFloat(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) @throw [OFOutOfRangeException exception]; size = count * sizeof(double); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else double *tmp = OFAllocMemory(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OFByteSwapDouble(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { OFFreeMemory(tmp); } #endif return size; } - (size_t)writeData: (OFData *)data { void *pool; size_t length; if (data == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); length = data.count * data.itemSize; [self writeBuffer: data.items length: length]; objc_autoreleasePoolPop(pool); return length; } - (size_t)writeString: (OFString *)string { return [self writeString: string encoding: OFStringEncodingUTF8]; } - (size_t)writeString: (OFString *)string encoding: (OFStringEncoding)encoding { void *pool; size_t length; if (string == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); length = [string cStringLengthWithEncoding: encoding]; [self writeBuffer: [string cStringWithEncoding: encoding] length: length]; objc_autoreleasePoolPop(pool); return length; } - (size_t)writeLine: (OFString *)string { return [self writeLine: string encoding: OFStringEncodingUTF8]; } - (size_t)writeLine: (OFString *)string encoding: (OFStringEncoding)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; buffer = OFAllocMemory(stringLength + 1, 1); @try { memcpy(buffer, [string cStringWithEncoding: encoding], stringLength); buffer[stringLength] = '\n'; [self writeBuffer: buffer length: stringLength + 1]; } @finally { OFFreeMemory(buffer); } return stringLength + 1; } - (size_t)writeFormat: (OFConstantString *)format, ... { va_list arguments; size_t ret; va_start(arguments, format); ret = [self writeFormat: format arguments: arguments]; va_end(arguments); return ret; } - (size_t)writeFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; int length; if (format == nil) @throw [OFInvalidArgumentException exception]; if ((length = OFVASPrintF(&UTF8String, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; @try { [self writeBuffer: UTF8String length: length]; } @finally { free(UTF8String); } return length; } |
︙ | ︙ | |||
1856 1857 1858 1859 1860 1861 1862 | OF_UNRECOGNIZED_SELECTOR } #ifdef OF_HAVE_SOCKETS - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self | | | < | | | | | 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 | OF_UNRECOGNIZED_SELECTOR } #ifdef OF_HAVE_SOCKETS - (void)cancelAsyncRequests { [OFRunLoop of_cancelAsyncRequestsForObject: self mode: OFDefaultRunLoopMode]; } #endif - (void)unreadFromBuffer: (const void *)buffer length: (size_t)length { char *readBuffer; if (length > SIZE_MAX - _readBufferLength) @throw [OFOutOfRangeException exception]; readBuffer = OFAllocMemory(_readBufferLength + length, 1); memcpy(readBuffer, buffer, length); memcpy(readBuffer + length, _readBuffer, _readBufferLength); OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += length; } - (void)close { OFFreeMemory(_readBufferMemory); _readBuffer = _readBufferMemory = NULL; _readBufferLength = 0; OFFreeMemory(_writeBuffer); _writeBuffer = NULL; _writeBufferLength = 0; _buffersWrites = false; _waitingForDelimiter = false; } @end |
Modified src/OFStreamSocket.h from [27f4a02196] to [088cdfae75].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" | < | | | | 10 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 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStream.h" #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFStreamSocket; #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket accepted a connection. * * @param acceptedSocket The socket which has been accepted * @param exception An exception which occurred while accepting the socket or * `nil` on success * @return A bool whether the same block should be used for the next incoming * connection */ typedef bool (^OFStreamSocketAsyncAcceptBlock)(OFStreamSocket *acceptedSocket, id _Nullable exception); #endif /** * @protocol OFStreamSocketDelegate OFStreamSocket.h ObjFW/OFStreamSocket.h * * A delegate for OFStreamSocket. */ |
︙ | ︙ | |||
62 63 64 65 66 67 68 | * @class OFStreamSocket OFStreamSocket.h ObjFW/OFStreamSocket.h * * @brief A class which provides methods to create and use stream sockets. */ @interface OFStreamSocket: OFStream <OFReadyForReadingObserving, OFReadyForWritingObserving> { | | | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | * @class OFStreamSocket OFStreamSocket.h ObjFW/OFStreamSocket.h * * @brief A class which provides methods to create and use stream sockets. */ @interface OFStreamSocket: OFStream <OFReadyForReadingObserving, OFReadyForWritingObserving> { OFSocketHandle _socket; bool _atEndOfStream, _listening; OFSocketAddress _remoteAddress; OF_RESERVE_IVARS(OFStreamSocket, 4) } /** * @brief Whether the socket is a listening socket. */ @property (readonly, nonatomic, getter=isListening) bool listening; /** * @brief The remote address. * * @note This only works for accepted sockets! */ @property (readonly, nonatomic) const OFSocketAddress *remoteAddress; /** * @brief The delegate for asynchronous operations on the socket. * * @note The delegate is retained for as long as asynchronous operations are * still ongoing. */ |
︙ | ︙ | |||
125 126 127 128 129 130 131 | - (void)asyncAccept; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept */ | | | | < | | 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 | - (void)asyncAccept; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept */ - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously accept an incoming connection. * * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block; /** * @brief Asynchronously accept an incoming connection. * * @param runLoopMode The run loop mode in which to perform the async accept * @param block The block to execute when a new connection has been accepted. * Returns whether the next incoming connection should be accepted * by the specified block as well. */ - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamSocketAsyncAcceptBlock)block; #endif @end OF_ASSUME_NONNULL_END |
Modified src/OFStreamSocket.m from [37c1cc3f6d] to [5b9cb9181f].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #define __NO_EXT_QNX | > > > > > | < > < < | | | | | < | | | | < | | | | | | | | | | | | | | > | | | | | | | < | | | | < | | | | | | | 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define __NO_EXT_QNX #define _HPUX_ALT_XOPEN_SOCKET_API #include <assert.h> #include <errno.h> #include <string.h> #import "OFStreamSocket.h" #import "OFStreamSocket+Private.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket+Private.h" #import "OFAcceptFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFListenFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFSetOptionFailedException.h" #import "OFWriteFailedException.h" @implementation OFStreamSocket @dynamic delegate; @synthesize listening = _listening; + (void)initialize { if (self != [OFStreamSocket class]) return; if (!OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)socket { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; @try { if (self.class == [OFStreamSocket class]) { [self doesNotRecognizeSelector: _cmd]; abort(); } _socket = OFInvalidSocketHandle; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_socket != OFInvalidSocketHandle) [self close]; [super dealloc]; } - (bool)lowlevelIsAtEndOfStream { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { ssize_t ret; if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS if ((ret = recv(_socket, buffer, length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: OFSocketErrNo()]; #else if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((ret = recv(_socket, buffer, (int)length, 0)) < 0) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length errNo: OFSocketErrNo()]; #endif if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; #ifndef OF_WINDOWS ssize_t bytesWritten; if (length > SSIZE_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, (void *)buffer, length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: OFSocketErrNo()]; #else int bytesWritten; if (length > INT_MAX) @throw [OFOutOfRangeException exception]; if ((bytesWritten = send(_socket, buffer, (int)length, 0)) < 0) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: length bytesWritten: 0 errNo: OFSocketErrNo()]; #endif return (size_t)bytesWritten; } #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) - (void)setCanBlock: (bool)canBlock { # ifdef OF_WINDOWS u_long v = !canBlock; # else char v = !canBlock; # endif if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; _canBlock = canBlock; } #endif - (int)fileDescriptorForReading { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } - (int)fileDescriptorForWriting { #ifndef OF_WINDOWS return _socket; #else if (_socket == OFInvalidSocketHandle) return -1; if (_socket > INT_MAX) @throw [OFOutOfRangeException exception]; return (int)_socket; #endif } #ifndef OF_WII - (int)of_socketError { int errNo; socklen_t len = sizeof(errNo); if (getsockopt(_socket, SOL_SOCKET, SO_ERROR, (char *)&errNo, &len) != 0) return OFSocketErrNo(); return errNo; } #endif - (void)listen { [self listenWithBacklog: SOMAXCONN]; } - (void)listenWithBacklog: (int)backlog { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (listen(_socket, backlog) == -1) @throw [OFListenFailedException exceptionWithSocket: self backlog: backlog errNo: OFSocketErrNo()]; _listening = true; } - (instancetype)accept { OFStreamSocket *client = [[[[self class] alloc] init] autorelease]; #if (!defined(HAVE_PACCEPT) && !defined(HAVE_ACCEPT4)) || !defined(SOCK_CLOEXEC) # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; # endif #endif client->_remoteAddress.length = (socklen_t)sizeof(client->_remoteAddress.sockaddr); #if defined(HAVE_PACCEPT) && defined(SOCK_CLOEXEC) if ((client->_socket = paccept(_socket, &client->_remoteAddress.sockaddr.sockaddr, &client->_remoteAddress.length, NULL, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #elif defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) if ((client->_socket = accept4(_socket, &client->_remoteAddress.sockaddr.sockaddr, &client->_remoteAddress.length, SOCK_CLOEXEC)) == OFInvalidSocketHandle) @throw [OFAcceptFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; #else if ((client->_socket = accept(_socket, &client->_remoteAddress.sockaddr.sockaddr, &client->_remoteAddress.length)) == OFInvalidSocketHandle) @throw [OFAcceptFailedException exceptionWithSocket: self errNo: OFSocketErrNo()]; # if defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(client->_socket, F_GETFD, 0)) != -1) fcntl(client->_socket, F_SETFD, flags | FD_CLOEXEC); # endif #endif assert(client->_remoteAddress.length <= (socklen_t)sizeof(client->_remoteAddress.sockaddr)); switch (client->_remoteAddress.sockaddr.sockaddr.sa_family) { case AF_INET: client->_remoteAddress.family = OFSocketAddressFamilyIPv4; break; #ifdef OF_HAVE_IPV6 case AF_INET6: client->_remoteAddress.family = OFSocketAddressFamilyIPv6; break; #endif #ifdef OF_HAVE_IPX case AF_IPX: client->_remoteAddress.family = OFSocketAddressFamilyIPX; break; #endif default: client->_remoteAddress.family = OFSocketAddressFamilyUnknown; break; } return client; } - (void)asyncAccept { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode]; } - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: NULL delegate: _delegate]; } #ifdef OF_HAVE_BLOCKS - (void)asyncAcceptWithBlock: (OFStreamSocketAsyncAcceptBlock)block { [self asyncAcceptWithRunLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncAcceptWithRunLoopMode: (OFRunLoopMode)runLoopMode block: (OFStreamSocketAsyncAcceptBlock)block { [OFRunLoop of_addAsyncAcceptForSocket: self mode: runLoopMode block: block delegate: nil]; } #endif - (const OFSocketAddress *)remoteAddress { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; if (_remoteAddress.length == 0) @throw [OFInvalidArgumentException exception]; if (_remoteAddress.length > (socklen_t)sizeof(_remoteAddress.sockaddr)) @throw [OFOutOfRangeException exception]; return &_remoteAddress; } - (void)close { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; _listening = false; memset(&_remoteAddress, 0, sizeof(_remoteAddress)); closesocket(_socket); _socket = OFInvalidSocketHandle; _atEndOfStream = false; [super close]; } @end |
Renamed and modified src/OFString+CryptoHashing.h [562278ea0b] to src/OFString+CryptographicHashing.h [059d7ea04f].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif | | | | | | | | | | | 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 61 62 63 64 65 | #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_CryptographicHashing_reference; #ifdef __cplusplus } #endif @interface OFString (CryptographicHashing) /** * @brief The MD5 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringByMD5Hashing; /** * @brief The RIPEMD-160 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringByRIPEMD160Hashing; /** * @brief The SHA-1 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA1Hashing; /** * @brief The SHA-224 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA224Hashing; /** * @brief The SHA-256 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA256Hashing; /** * @brief The SHA-384 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA384Hashing; /** * @brief The SHA-512 hash of the string as a string. */ @property (readonly, nonatomic) OFString *stringBySHA512Hashing; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFString+CryptoHashing.m [0a23b41efc] to src/OFString+CryptographicHashing.m [7e22b6306f].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFString.h" | | | | | > | | | < | | | | | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFString.h" #import "OFCryptographicHash.h" #import "OFMD5Hash.h" #import "OFRIPEMD160Hash.h" #import "OFSHA1Hash.h" #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" int _OFString_CryptographicHashing_reference; @implementation OFString (CryptographicHashing) static OFString * stringByHashing(Class <OFCryptographicHash> class, OFString *self) { void *pool = objc_autoreleasePoolPush(); id <OFCryptographicHash> hash = [class hashWithAllowsSwappableMemory: true]; size_t digestSize = [class digestSize]; const unsigned char *digest; char cString[digestSize * 2]; [hash updateWithBuffer: self.UTF8String length: self.UTF8StringLength]; digest = hash.digest; for (size_t i = 0; i < digestSize; i++) { uint8_t high, low; high = digest[i] >> 4; low = digest[i] & 0x0F; cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } objc_autoreleasePoolPop(pool); return [OFString stringWithCString: cString encoding: OFStringEncodingASCII length: digestSize * 2]; } - (OFString *)stringByMD5Hashing { return stringByHashing([OFMD5Hash class], self); } - (OFString *)stringByRIPEMD160Hashing { return stringByHashing([OFRIPEMD160Hash class], self); } - (OFString *)stringBySHA1Hashing { return stringByHashing([OFSHA1Hash class], self); } - (OFString *)stringBySHA224Hashing { return stringByHashing([OFSHA224Hash class], self); } - (OFString *)stringBySHA256Hashing { return stringByHashing([OFSHA256Hash class], self); } - (OFString *)stringBySHA384Hashing { return stringByHashing([OFSHA384Hash class], self); } - (OFString *)stringBySHA512Hashing { return stringByHashing([OFSHA512Hash class], self); } @end |
Modified src/OFString+JSONParsing.m from [182fb0261b] to [fd3673a355].
︙ | ︙ | |||
105 106 107 108 109 110 111 | old = *pointer; skipWhitespaces(pointer, stop, line); skipComment(pointer, stop, line); } } | | | | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | old = *pointer; skipWhitespaces(pointer, stop, line); skipComment(pointer, stop, line); } } static inline OFChar16 parseUnicodeEscape(const char *pointer, const char *stop) { OFChar16 ret = 0; if (pointer + 5 >= stop) return 0xFFFF; if (pointer[0] != '\\' || pointer[1] != 'u') return 0xFFFF; |
︙ | ︙ | |||
146 147 148 149 150 151 152 | char *buffer; size_t i = 0; char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; | | | | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | char *buffer; size_t i = 0; char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; buffer = OFAllocMemory(stop - *pointer, 1); while (*pointer < stop) { /* Parse escape codes */ if (**pointer == '\\') { if (++(*pointer) >= stop) { OFFreeMemory(buffer); return nil; } switch (**pointer) { case '"': case '\\': case '/': |
︙ | ︙ | |||
185 186 187 188 189 190 191 | break; case 't': buffer[i++] = '\t'; (*pointer)++; break; /* Parse Unicode escape sequence */ case 'u':; | | | | | < | | | | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | break; case 't': buffer[i++] = '\t'; (*pointer)++; break; /* Parse Unicode escape sequence */ case 'u':; OFChar16 c1, c2; OFUnichar c; size_t l; c1 = parseUnicodeEscape(*pointer - 1, stop); if (c1 == 0xFFFF) { OFFreeMemory(buffer); return nil; } /* Low surrogate */ if ((c1 & 0xFC00) == 0xDC00) { OFFreeMemory(buffer); return nil; } /* Normal character */ if ((c1 & 0xFC00) != 0xD800) { l = OFUTF8StringEncode(c1, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 5; break; } /* * If we are still here, we only got one UTF-16 * surrogate and now need to get the other one * in order to produce UTF-8 and not CESU-8. */ c2 = parseUnicodeEscape(*pointer + 5, stop); if (c2 == 0xFFFF) { OFFreeMemory(buffer); return nil; } c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; l = OFUTF8StringEncode(c, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 11; break; |
︙ | ︙ | |||
254 255 256 257 258 259 260 | break; case '\n': (*pointer)++; (*line)++; break; default: | | | | | | | | | | | | | | | | | | | | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | break; case '\n': (*pointer)++; (*line)++; break; default: OFFreeMemory(buffer); return nil; } /* End of string found */ } else if (**pointer == delimiter) { OFString *ret; @try { ret = [OFString stringWithUTF8String: buffer length: i]; } @finally { OFFreeMemory(buffer); } (*pointer)++; return ret; /* Newlines in strings are disallowed */ } else if (**pointer == '\n' || **pointer == '\r') { (*line)++; OFFreeMemory(buffer); return nil; } else { buffer[i++] = **pointer; (*pointer)++; } } OFFreeMemory(buffer); return nil; } static inline OFString * parseIdentifier(const char **pointer, const char *stop) { char *buffer; size_t i = 0; buffer = OFAllocMemory(stop - *pointer, 1); while (*pointer < stop) { if ((**pointer >= 'a' && **pointer <= 'z') || (**pointer >= 'A' && **pointer <= 'Z') || (**pointer >= '0' && **pointer <= '9') || **pointer == '_' || **pointer == '$' || (**pointer & 0x80)) { buffer[i++] = **pointer; (*pointer)++; } else if (**pointer == '\\') { OFChar16 c1, c2; OFUnichar c; size_t l; if (++(*pointer) >= stop || **pointer != 'u') { OFFreeMemory(buffer); return nil; } c1 = parseUnicodeEscape(*pointer - 1, stop); if (c1 == 0xFFFF) { OFFreeMemory(buffer); return nil; } /* Low surrogate */ if ((c1 & 0xFC00) == 0xDC00) { OFFreeMemory(buffer); return nil; } /* Normal character */ if ((c1 & 0xFC00) != 0xD800) { l = OFUTF8StringEncode(c1, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 5; continue; } /* * If we are still here, we only got one UTF-16 * surrogate and now need to get the other one in order * to produce UTF-8 and not CESU-8. */ c2 = parseUnicodeEscape(*pointer + 5, stop); if (c2 == 0xFFFF) { OFFreeMemory(buffer); return nil; } c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; l = OFUTF8StringEncode(c, buffer + i); if (l == 0) { OFFreeMemory(buffer); return nil; } i += l; *pointer += 11; } else { OFString *ret; if (i == 0 || (buffer[0] >= '0' && buffer[0] <= '9')) { OFFreeMemory(buffer); return nil; } @try { ret = [OFString stringWithUTF8String: buffer length: i]; } @finally { OFFreeMemory(buffer); } return ret; } } /* * It is never possible to end with an identifier, thus we should never * reach stop. */ OFFreeMemory(buffer); return nil; } static inline OFMutableArray * parseArray(const char **pointer, const char *stop, size_t *line, size_t depthLimit) { |
︙ | ︙ | |||
500 501 502 503 504 505 506 | (*pointer)++; object = nextObject(pointer, stop, line, depthLimit); if (object == nil) return nil; | | < | 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | (*pointer)++; object = nextObject(pointer, stop, line, depthLimit); if (object == nil) return nil; [dictionary setObject: object forKey: key]; skipWhitespacesAndComments(pointer, stop, line); if (*pointer >= stop) return nil; if (**pointer == ',') { (*pointer)++; |
︙ | ︙ | |||
546 547 548 549 550 551 552 | if ((*pointer)[i] == '\n') (*line)++; break; } } | | < | 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | if ((*pointer)[i] == '\n') (*line)++; break; } } string = [[OFString alloc] initWithUTF8String: *pointer length: i]; *pointer += i; @try { if (hasDecimal) number = [OFNumber numberWithDouble: string.doubleValue]; else if ([string isEqual: @"Infinity"]) |
︙ | ︙ |
Modified src/OFString+PathAdditions.h from [5bff0ead4d] to [0d70d05c92].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN | < < < < < < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * file. */ #import "OFString.h" OF_ASSUME_NONNULL_BEGIN #ifdef __cplusplus extern "C" { #endif extern int _OFString_PathAdditions_reference; #ifdef __cplusplus } #endif |
︙ | ︙ |
Modified src/OFString+PathAdditions.m from [ea7cb030e3] to [6ba7aac1d0].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include "platform.h" #if defined(OF_WINDOWS) || defined(OF_MSDOS) | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "config.h" #include "platform.h" #if defined(OF_WINDOWS) || defined(OF_MSDOS) # import "platform/Windows/OFString+PathAdditions.m" #elif defined(OF_AMIGAOS) # import "platform/AmigaOS/OFString+PathAdditions.m" #elif defined(OF_NINTENDO_3DS) || defined(OF_WII) # import "platform/libfat/OFString+PathAdditions.m" #else # import "platform/POSIX/OFString+PathAdditions.m" #endif |
Modified src/OFString+PropertyListParsing.m from [3a2aedc9eb] to [c7b4407cc2].
︙ | ︙ | |||
62 63 64 65 66 67 68 | enumerator = [children objectEnumerator]; while ((key = [enumerator nextObject]) && (object = [enumerator nextObject])) { if (key.namespace != nil || key.attributes.count != 0 || ![key.name isEqual: @"key"]) @throw [OFInvalidFormatException exception]; | | < | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | enumerator = [children objectEnumerator]; while ((key = [enumerator nextObject]) && (object = [enumerator nextObject])) { if (key.namespace != nil || key.attributes.count != 0 || ![key.name isEqual: @"key"]) @throw [OFInvalidFormatException exception]; [ret setObject: parseElement(object) forKey: key.stringValue]; } [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; |
︙ | ︙ |
Modified src/OFString+Serialization.m from [8faf6d47b7] to [8e1b78d5c6].
︙ | ︙ | |||
50 51 52 53 54 55 56 | if (version == nil) @throw [OFInvalidArgumentException exception]; if (version.unsignedLongLongValue != 1) @throw [OFUnsupportedVersionException exceptionWithVersion: version]; | | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | if (version == nil) @throw [OFInvalidArgumentException exception]; if (version.unsignedLongLongValue != 1) @throw [OFUnsupportedVersionException exceptionWithVersion: version]; elements = [root elementsForNamespace: OFSerializationNS]; if (elements.count != 1) @throw [OFInvalidArgumentException exception]; object = [[elements.firstObject objectByDeserializing] retain]; objc_autoreleasePoolPop(pool); |
︙ | ︙ |
Modified src/OFString+URLEncoding.m from [e71fa29471] to [136d9c5f3e].
︙ | ︙ | |||
30 31 32 33 34 35 36 | @implementation OFString (URLEncoding) - (OFString *)stringByURLEncodingWithAllowedCharacters: (OFCharacterSet *)allowedCharacters { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); | | | | | | < | | < | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | @implementation OFString (URLEncoding) - (OFString *)stringByURLEncodingWithAllowedCharacters: (OFCharacterSet *)allowedCharacters { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[allowedCharacters methodForSelector: @selector(characterIsMember:)]; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; if (characterIsMember(allowedCharacters, @selector(characterIsMember:), c)) [ret appendCharacters: &c length: 1]; else { char buffer[4]; size_t bufferLen; if ((bufferLen = OFUTF8StringEncode(c, buffer)) == 0) @throw [OFInvalidEncodingException exception]; for (size_t j = 0; j < bufferLen; j++) { unsigned char byte = buffer[j]; unsigned char high = byte >> 4; unsigned char low = byte & 0x0F; char escaped[3]; escaped[0] = '%'; escaped[1] = (high > 9 ? high - 10 + 'A' : high + '0'); escaped[2] = (low > 9 ? low - 10 + 'A' : low + '0'); [ret appendUTF8String: escaped length: 3]; } } } objc_autoreleasePoolPop(pool); return ret; } - (OFString *)stringByURLDecoding { void *pool = objc_autoreleasePoolPush(); const char *string = self.UTF8String; size_t length = self.UTF8StringLength; char *retCString; char byte = 0; int state = 0; size_t i = 0; retCString = OFAllocMemory(length + 1, 1); while (length--) { char c = *string++; switch (state) { case 0: if (c == '%') |
︙ | ︙ | |||
106 107 108 109 110 111 112 | if (c >= '0' && c <= '9') byte += (c - '0') << shift; else if (c >= 'A' && c <= 'F') byte += (c - 'A' + 10) << shift; else if (c >= 'a' && c <= 'f') byte += (c - 'a' + 10) << shift; else { | | | | | | 104 105 106 107 108 109 110 111 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 | if (c >= '0' && c <= '9') byte += (c - '0') << shift; else if (c >= 'A' && c <= 'F') byte += (c - 'A' + 10) << shift; else if (c >= 'a' && c <= 'f') byte += (c - 'a' + 10) << shift; else { OFFreeMemory(retCString); @throw [OFInvalidFormatException exception]; } if (++state == 3) { retCString[i++] = byte; state = 0; byte = 0; } break; } } retCString[i] = '\0'; objc_autoreleasePoolPop(pool); if (state != 0) { OFFreeMemory(retCString); @throw [OFInvalidFormatException exception]; } @try { retCString = OFResizeMemory(retCString, 1, i + 1); } @catch (OFOutOfMemoryException *e) { /* We don't care if it fails, as we only made it smaller. */ } @try { return [OFString stringWithUTF8StringNoCopy: retCString length: i freeWhenDone: true]; } @catch (id e) { OFFreeMemory(retCString); @throw e; } } @end |
Modified src/OFString+XMLEscaping.m from [5be8f79e31] to [44dcba40f2].
︙ | ︙ | |||
36 37 38 39 40 41 42 | OFString *ret; string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | OFString *ret; string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; retCString = OFAllocMemory(retLength, 1); for (size_t i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; appendLen = 4; break; |
︙ | ︙ | |||
71 72 73 74 75 76 77 | default: append = NULL; appendLen = 0; } if (append != NULL) { @try { | | | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | default: append = NULL; appendLen = 0; } if (append != NULL) { @try { retCString = OFResizeMemory(retCString, 1, retLength + appendLen); } @catch (id e) { OFFreeMemory(retCString); @throw e; } retLength += appendLen - 1; memcpy(retCString + j, append, appendLen); j += appendLen; } else retCString[j++] = string[i]; } assert(j == retLength); objc_autoreleasePoolPop(pool); @try { ret = [OFString stringWithUTF8String: retCString length: retLength]; } @finally { OFFreeMemory(retCString); } return ret; } @end |
Modified src/OFString+XMLUnescaping.h from [d4c2a5d60a] to [cbe997ff43].
︙ | ︙ | |||
32 33 34 35 36 37 38 | * @brief A block which is called to replace unknown XML entities in an XML * string. * * @param string The XML string which contains an unknown entity * @param entity The XML entity which is unknown * @return A replacement string for the unknown entity */ | | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | * @brief A block which is called to replace unknown XML entities in an XML * string. * * @param string The XML string which contains an unknown entity * @param entity The XML entity which is unknown * @return A replacement string for the unknown entity */ typedef OFString *_Nullable (^OFStringXMLUnescapingBlock)(OFString *string, OFString *entity); #endif /** * @protocol OFStringXMLUnescapingDelegate OFString.h ObjFW/OFString.h * * @brief A protocol that needs to be implemented by delegates for * stringByXMLUnescapingWithHandler:. |
︙ | ︙ | |||
81 82 83 84 85 86 87 | #ifdef OF_HAVE_BLOCKS /** * @brief Unescapes XML in the string and uses the specified block for unknown * entities. * * @param block A block which handles unknown entities */ | | < | 81 82 83 84 85 86 87 88 89 90 91 92 | #ifdef OF_HAVE_BLOCKS /** * @brief Unescapes XML in the string and uses the specified block for unknown * entities. * * @param block A block which handles unknown entities */ - (OFString *)stringByXMLUnescapingWithBlock: (OFStringXMLUnescapingBlock)block; #endif @end OF_ASSUME_NONNULL_END |
Modified src/OFString+XMLUnescaping.m from [563c6e6449] to [0941da3dc0].
︙ | ︙ | |||
23 24 25 26 27 28 29 | #import "OFUnknownXMLEntityException.h" int _OFString_XMLUnescaping_reference; static OF_INLINE OFString * parseNumericEntity(const char *entity, size_t length) { | | | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #import "OFUnknownXMLEntityException.h" int _OFString_XMLUnescaping_reference; static OF_INLINE OFString * parseNumericEntity(const char *entity, size_t length) { OFUnichar c; size_t i; char buffer[5]; if (length == 1 || *entity != '#') return nil; c = 0; |
︙ | ︙ | |||
60 61 62 63 64 65 66 | if (entity[i] >= '0' && entity[i] <= '9') c = (c * 10) + (entity[i] - '0'); else return nil; } } | | | < | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | if (entity[i] >= '0' && entity[i] <= '9') c = (c * 10) + (entity[i] - '0'); else return nil; } } if ((i = OFUTF8StringEncode(c, buffer)) == 0) return nil; buffer[i] = 0; return [OFString stringWithUTF8String: buffer length: i]; } static OFString * parseEntities(OFString *self, id (*lookup)(void *, OFString *, OFString *), void *context) { OFMutableString *ret; |
︙ | ︙ | |||
90 91 92 93 94 95 96 | length = self.UTF8StringLength; last = 0; inEntity = false; for (i = 0; i < length; i++) { if (!inEntity && string[i] == '&') { | | < < | | | | | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | length = self.UTF8StringLength; last = 0; inEntity = false; for (i = 0; i < length; i++) { if (!inEntity && string[i] == '&') { [ret appendUTF8String: string + last length: i - last]; last = i + 1; inEntity = true; } else if (inEntity && string[i] == ';') { const char *entity = string + last; size_t entityLength = i - last; if (entityLength == 2 && memcmp(entity, "lt", 2) == 0) [ret appendCString: "<" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 2 && memcmp(entity, "gt", 2) == 0) [ret appendCString: ">" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 4 && memcmp(entity, "quot", 4) == 0) [ret appendCString: "\"" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 4 && memcmp(entity, "apos", 4) == 0) [ret appendCString: "'" encoding: OFStringEncodingASCII length: 1]; else if (entityLength == 3 && memcmp(entity, "amp", 3) == 0) [ret appendCString: "&" encoding: OFStringEncodingASCII length: 1]; else if (entity[0] == '#') { void *pool2; OFString *tmp; pool2 = objc_autoreleasePoolPush(); tmp = parseNumericEntity(entity, |
︙ | ︙ | |||
166 167 168 169 170 171 172 | inEntity = false; } } if (inEntity) @throw [OFInvalidFormatException exception]; | | < < < | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | inEntity = false; } } if (inEntity) @throw [OFInvalidFormatException exception]; [ret appendUTF8String: string + last length: i - last]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); return ret; } static id lookupUsingDelegate(void *context, OFString *self, OFString *entity) { id <OFStringXMLUnescapingDelegate> delegate = context; if (delegate == nil) return nil; return [delegate string: self containsUnknownEntityNamed: entity]; } #ifdef OF_HAVE_BLOCKS static id lookupUsingBlock(void *context, OFString *self, OFString *entity) { OFStringXMLUnescapingBlock block = context; if (block == NULL) return nil; return block(self, entity); } #endif |
︙ | ︙ | |||
214 215 216 217 218 219 220 | - (OFString *)stringByXMLUnescapingWithDelegate: (id <OFStringXMLUnescapingDelegate>)delegate { return parseEntities(self, lookupUsingDelegate, delegate); } #ifdef OF_HAVE_BLOCKS | | < | 208 209 210 211 212 213 214 215 216 217 218 219 220 | - (OFString *)stringByXMLUnescapingWithDelegate: (id <OFStringXMLUnescapingDelegate>)delegate { return parseEntities(self, lookupUsingDelegate, delegate); } #ifdef OF_HAVE_BLOCKS - (OFString *)stringByXMLUnescapingWithBlock: (OFStringXMLUnescapingBlock)block { return parseEntities(self, lookupUsingBlock, block); } #endif @end |
Modified src/OFString.h from [c803b1d0df] to [e4caed5e17].
︙ | ︙ | |||
50 51 52 53 54 55 56 | @class OFConstantString; @class OFString; #else typedef void OFString; #endif #if defined(__cplusplus) && __cplusplus >= 201103L | | | | | | | | | | | | | | | | | | | | | | | > > > > > | > | > | < > > > > > > > > > | | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | @class OFConstantString; @class OFString; #else typedef void OFString; #endif #if defined(__cplusplus) && __cplusplus >= 201103L typedef char16_t OFChar16; typedef char32_t OFChar32; #else typedef uint_least16_t OFChar16; typedef uint_least32_t OFChar32; #endif typedef OFChar32 OFUnichar; /** * @brief The encoding of a string. */ typedef enum { /* * UTF-8 *has* to be 0, so that if the current @ref OFLocale is * `nil`, `[OFLocale encoding]` returns UTF-8. */ /** UTF-8 */ OFStringEncodingUTF8, /** ASCII */ OFStringEncodingASCII, /** ISO 8859-1 */ OFStringEncodingISO8859_1, /** ISO 8859-2 */ OFStringEncodingISO8859_2, /** ISO 8859-3 */ OFStringEncodingISO8859_3, /** ISO 8859-15 */ OFStringEncodingISO8859_15, /** Windows-1251 */ OFStringEncodingWindows1251, /** Windows-1252 */ OFStringEncodingWindows1252, /** Codepage 437 */ OFStringEncodingCodepage437, /** Codepage 850 */ OFStringEncodingCodepage850, /** Codepage 858 */ OFStringEncodingCodepage858, /** Mac OS Roman */ OFStringEncodingMacRoman, /** KOI8-R */ OFStringEncodingKOI8R, /** KOI8-U */ OFStringEncodingKOI8U, /** Try to automatically detect the encoding */ OFStringEncodingAutodetect = 0xFF } OFStringEncoding; /** * @brief Options for searching in strings. * * This is a bit mask. */ typedef enum { /** Search backwards in the string */ OFStringSearchBackwards = 1 } OFStringSearchOptions; /** * @brief Options for separating strings. * * This is a bit mask. */ typedef enum { /** Skip empty components */ OFStringSkipEmptyComponents = 1 } OFStringSeparationOptions; #ifdef OF_HAVE_BLOCKS /** * @brief A block for enumerating the lines of a string. * * @param line The current line * @param stop A pointer to a variable that can be set to true to stop the * enumeration */ typedef void (^OFStringLineEnumerationBlock)(OFString *line, bool *stop); #endif #ifdef __OBJC__ @class OFArray OF_GENERIC(ObjectType); @class OFCharacterSet; @class OFURL; |
︙ | ︙ | |||
213 214 215 216 217 218 219 | /** * @brief The string as an array of Unicode characters. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ | | | | | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | /** * @brief The string as an array of Unicode characters. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) const OFUnichar *characters OF_RETURNS_INNER_POINTER; /** * @brief The string in UTF-16 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) const OFChar16 *UTF16String OF_RETURNS_INNER_POINTER; /** * @brief The length of the string in UTF-16 characters. */ @property (readonly, nonatomic) size_t UTF16StringLength; /** * @brief The string in UTF-32 encoding with native byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. */ @property (readonly, nonatomic) const OFChar32 *UTF32String OF_RETURNS_INNER_POINTER; /** * @brief The string with leading whitespaces deleted. */ @property (readonly, nonatomic) OFString *stringByDeletingLeadingWhitespaces; |
︙ | ︙ | |||
347 348 349 350 351 352 353 | * @brief Creates a new OFString from a C string with the specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return A new autoreleased OFString */ + (instancetype)stringWithCString: (const char *)cString | | | | | | | | | | | | | | | | | | | | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | * @brief Creates a new OFString from a C string with the specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return A new autoreleased OFString */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Creates a new OFString from a C string with the specified encoding * and length. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return A new autoreleased OFString */ + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Creates a new OFString from OFData with the specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An new autoreleased OFString */ + (instancetype)stringWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** * @brief Creates a new OFString from another string. * * @param string A string to initialize the OFString with * @return A new autoreleased OFString */ + (instancetype)stringWithString: (OFString *)string; /** * @brief Creates a new OFString from a Unicode string with the specified * length. * * @param characters An array of Unicode characters * @param length The length of the Unicode character array * @return A new autoreleased OFString */ + (instancetype)stringWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Creates a new OFString from a UTF-16 encoded string. * * @param string The UTF-16 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string; /** * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length. * * @param string The UTF-16 string * @param length The length of the UTF-16 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** * @brief Creates a new OFString from a UTF-16 encoded string, assuming the * specified byte order if no byte order mark is found. * * @param string The UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-16 encoded string with the * specified length, assuming the specified byte order if no byte order * mark is found. * * @param string The UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-32 encoded string. * * @param string The UTF-32 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string; /** * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length. * * @param string The UTF-32 string * @param length The length of the UTF-32 string * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length; /** * @brief Creates a new OFString from a UTF-32 encoded string, assuming the * specified byte order if no byte order mark is found. * * @param string The UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a UTF-32 encoded string with the * specified length, assuming the specified byte order if no byte order * mark is found. * * @param string The UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return A new autoreleased OFString */ + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Creates a new OFString from a format string. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return A new autoreleased OFString */ + (instancetype)stringWithFormat: (OFConstantString *)format, ...; # ifdef OF_HAVE_FILES |
︙ | ︙ | |||
510 511 512 513 514 515 516 | * specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path | | < | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | * specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Creates a new OFString with the contents of the specified URL. * * If the URL's scheme is file, it tries UTF-8 encoding. * * If the URL's scheme is http(s), it tries to detect the encoding from the HTTP * headers. If it could not detect the encoding using the HTTP headers, it tries |
︙ | ︙ | |||
537 538 539 540 541 542 543 | * specified encoding. * * @param URL The URL to the contents for the string * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURL: (OFURL *)URL | | < | 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 | * specified encoding. * * @param URL The URL to the contents for the string * @param encoding The encoding to assume * @return A new autoreleased OFString */ + (instancetype)stringWithContentsOfURL: (OFURL *)URL encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString from a UTF-8 encoded C * string. * * @param UTF8String A UTF-8 encoded C string to initialize the OFString with * @return An initialized OFString |
︙ | ︙ | |||
606 607 608 609 610 611 612 | * specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return An initialized OFString */ - (instancetype)initWithCString: (const char *)cString | | | | | | | | | | | | | | | | | | | | | | 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | * specified encoding. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @return An initialized OFString */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString from a C string with the * specified encoding and length. * * @param cString A C string to initialize the OFString with * @param encoding The encoding of the C string * @param cStringLength The length of the C string * @return An initialized OFString */ - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength; /** * @brief Initializes an already allocated OFString from OFData with the * specified encoding. * * @param data OFData with the contents of the string * @param encoding The encoding in which the string is stored in the OFData * @return An initialized OFString */ - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding; /** * @brief Initializes an already allocated OFString with another string. * * @param string A string to initialize the OFString with * @return An initialized OFString */ - (instancetype)initWithString: (OFString *)string; /** * @brief Initializes an already allocated OFString with a Unicode string with * the specified length. * * @param characters An array of Unicode characters * @param length The length of the Unicode character array * @return An initialized OFString */ - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-16 string. * * @param string The UTF-16 string * @return An initialized OFString */ - (instancetype)initWithUTF16String: (const OFChar16 *)string; /** * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length. * * @param string The UTF-16 string * @param length The length of the UTF-16 string * @return An initialized OFString */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-16 string, * assuming the specified byte order if no byte order mark is found. * * @param string The UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-16 string with * the specified length, assuming the specified byte order if no byte * order mark is found. * * @param string The UTF-16 string * @param length The length of the UTF-16 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-32 string. * * @param string The UTF-32 string * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string; /** * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length * * @param string The UTF-32 string * @param length The length of the UTF-32 string * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length; /** * @brief Initializes an already allocated OFString with a UTF-32 string, * assuming the specified byte order if no byte order mark is found. * * @param string The UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a UTF-32 string with * the specified length, assuming the specified byte order if no byte * order mark is found. * * @param string The UTF-32 string * @param length The length of the UTF-32 string * @param byteOrder The byte order to assume if there is no byte order mark * @return An initialized OFString */ - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder; /** * @brief Initializes an already allocated OFString with a format string. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @return An initialized OFString */ - (instancetype)initWithFormat: (OFConstantString *)format, ...; /** * @brief Initializes an already allocated OFString with a format string. * * See printf for the format syntax. As an addition, `%@` is available as * format specifier for objects, `%C` for `OFUnichar` and `%S` for * `const OFUnichar *`. * * @param format A string used as format to initialize the OFString * @param arguments The arguments used in the format string * @return An initialized OFString */ - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments; |
︙ | ︙ | |||
784 785 786 787 788 789 790 | * specified file in the specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return An initialized OFString */ - (instancetype)initWithContentsOfFile: (OFString *)path | | | 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | * specified file in the specified encoding. * * @param path The path to the file * @param encoding The encoding of the file * @return An initialized OFString */ - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Initializes an already allocated OFString with the contents of the * specified URL. * * If the URL's scheme is file, it tries UTF-8 encoding. |
︙ | ︙ | |||
811 812 813 814 815 816 817 | * specified URL in the specified encoding. * * @param URL The URL to the contents for the string * @param encoding The encoding to assume * @return An initialized OFString */ - (instancetype)initWithContentsOfURL: (OFURL *)URL | | | | | | | | > > > > > | > > | | | | | < | | | < < < < | | | | < < < < | | | | | | < < < < | | | < < < < | | | | 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 | * specified URL in the specified encoding. * * @param URL The URL to the contents for the string * @param encoding The encoding to assume * @return An initialized OFString */ - (instancetype)initWithContentsOfURL: (OFURL *)URL encoding: (OFStringEncoding)encoding; /** * @brief Writes the OFString into the specified C string with the specified * encoding. * * @param cString The C string to write into * @param maxLength The maximum number of bytes to write into the C string, * including the terminating zero * @param encoding The encoding to use for writing into the C string * @return The number of bytes written into the C string, without the * terminating zero */ - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding; /** * @brief Writes the OFString into the specified C string with the specified * encoding, replacing characters that cannot be represented in the * specified encoding with a question mark. * * @param cString The C string to write into * @param maxLength The maximum number of bytes to write into the C string, * including the terminating zero * @param encoding The encoding to use for writing into the C string * @return The number of bytes written into the C string, without the * terminating zero */ - (size_t)getLossyCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding; /** * @brief Returns the OFString as a C string in the specified encoding. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding */ - (const char *)cStringWithEncoding: (OFStringEncoding)encoding OF_RETURNS_INNER_POINTER; /** * @brief Returns the OFString as a C string in the specified encoding, * replacing characters that cannot be represented in the specified * encoding with a question mark. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param encoding The encoding for the C string * @return The OFString as a C string in the specified encoding */ - (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding OF_RETURNS_INNER_POINTER; /** * @brief Returns the number of bytes the string needs in the specified * encoding. * * @param encoding The encoding for the string * @return The number of bytes the string needs in the specified encoding. */ - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding; /** * @brief Compares the string to another string. * * @param string The string to compare the string to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFString *)string; /** * @brief Compares the string to another string without caring about the case. * * @param string The string to compare the string to * @return The result of the comparison */ - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string; /** * @brief Returns the Unicode character at the specified index. * * @param index The index of the Unicode character to return * @return The Unicode character at the specified index */ - (OFUnichar)characterAtIndex: (size_t)index; /** * @brief Copies the Unicode characters in the specified range to the specified * buffer. * * @param buffer The buffer to store the Unicode characters * @param range The range of the Unicode characters to copy */ - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range; /** * @brief Returns the range of the first occurrence of the string. * * @param string The string to search * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ - (OFRange)rangeOfString: (OFString *)string; /** * @brief Returns the range of the string. * * @param string The string to search * @param options Options modifying search behavior * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options; /** * @brief Returns the range of the string in the specified range. * * @param string The string to search * @param options Options modifying search behaviour * @param range The range in which to search * @return The range of the first occurrence of the string or a range with * `OFNotFound` as start position if it was not found */ - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range; /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet; /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for * @param options Options modifying search behaviour * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options; /** * @brief Returns the index of the first character from the set. * * @param characterSet The set of characters to search for * @param options Options modifying search behaviour * @param range The range in which to search * @return The index of the first occurrence of a character from the set or * `OFNotFound` if it was not found */ - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options range: (OFRange)range; /** * @brief Returns whether the string contains the specified string. * * @param string The string to search * @return Whether the string contains the specified string */ |
︙ | ︙ | |||
1020 1021 1022 1023 1024 1025 1026 | /** * @brief Creates a substring with the specified range. * * @param range The range of the substring * @return The substring as a new autoreleased OFString */ | | | 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | /** * @brief Creates a substring with the specified range. * * @param range The range of the substring * @return The substring as a new autoreleased OFString */ - (OFString *)substringWithRange: (OFRange)range; /** * @brief The value of the string in the specified base as a `long long`. * * Leading and trailing whitespaces are ignored. * * If the string contains any non-number characters, an |
︙ | ︙ | |||
1121 1122 1123 1124 1125 1126 1127 | * * None yet * @param range The range in which to replace the string * @return A new string with the occurrences of the specified string replaced */ - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options | | | 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 | * * None yet * @param range The range in which to replace the string * @return A new string with the occurrences of the specified string replaced */ - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range; /** * @brief Checks whether the string has the specified prefix. * * @param prefix The prefix to check for * @return A boolean whether the string has the specified prefix */ |
︙ | ︙ | |||
1154 1155 1156 1157 1158 1159 1160 | componentsSeparatedByString: (OFString *)delimiter; /** * @brief Separates the string into an array of strings, split by the specified * delimiter. * * @param delimiter The delimiter for separating | | < < < < | | < < < < | | | | | < | < | > > > > > > > > > > > | > > > > > > | | > > | | | | | 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 | componentsSeparatedByString: (OFString *)delimiter; /** * @brief Separates the string into an array of strings, split by the specified * delimiter. * * @param delimiter The delimiter for separating * @param options Options according to which the string should be separated * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options; /** * @brief Separates the string into an array of strings, split by characters in * the specified set. * * @param characterSet The character set for separating * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet; /** * @brief Separates the string into an array of strings, split by characters in * the specified set. * * @param characterSet The character set for separating * @param options Options according to which the string should be separated * @return An autoreleased OFArray with the separated string */ - (OFArray OF_GENERIC(OFString *) *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet options: (OFStringSeparationOptions)options; /** * @brief Returns the string in UTF-16 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param byteOrder The byte order for the UTF-16 encoding * @return The string in UTF-16 encoding with the specified byte order */ - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; /** * @brief Returns the string in UTF-32 encoding with the specified byte order. * * The result is valid until the autorelease pool is released. If you want to * use the result outside the scope of the current autorelease pool, you have to * copy it. * * @param byteOrder The byte order for the UTF-32 encoding * @return The string in UTF-32 encoding with the specified byte order */ - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder OF_RETURNS_INNER_POINTER; /** * @brief Returns the string as OFData with the specified encoding. * * @param encoding The encoding to use for the returned OFData * @return The string as OFData with the specified encoding */ - (OFData *)dataWithEncoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_FILES /** * @brief Writes the string into the specified file using UTF-8 encoding. * * @param path The path of the file to write to */ - (void)writeToFile: (OFString *)path; /** * @brief Writes the string into the specified file using the specified * encoding. * * @param path The path of the file to write to * @param encoding The encoding to use to write the string into the file */ - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding; # endif /** * @brief Writes the string to the specified URL using UTF-8 encoding. * * @param URL The URL to write to */ - (void)writeToURL: (OFURL *)URL; /** * @brief Writes the string to the specified URL using the specified encoding. * * @param URL The URL to write to * @param encoding The encoding to use to write the string to the URL */ - (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding; # ifdef OF_HAVE_BLOCKS /** * Enumerates all lines in the receiver using the specified block. * * @brief block The block to call for each line */ - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block; # endif @end #endif #ifdef __cplusplus extern "C" { #endif /** * @brief Parses the specified string encoding name and returns the * OFStringEncoding for it. * * Throws @ref OFInvalidArgumentException if the specified name is not a valid * encoding name. * * @param name The name to parse as a string encoding * @return The OFStringEncoding for the specified name */ extern OFStringEncoding OFStringEncodingParseName(OFString *name); /** * @brief Returns the name of the specified OFStringEncoding. * * @param encoding The encoding for which to return the name * @return The name of the specified OFStringEncoding */ extern OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding); extern char *_Nullable OFStrDup(const char *_Nonnull); extern size_t OFUTF8StringEncode(OFUnichar, char *); extern ssize_t OFUTF8StringDecode(const char *, size_t, OFUnichar *); extern size_t OFUTF16StringLength(const OFChar16 *); extern size_t OFUTF32StringLength(const OFChar32 *); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #include "OFConstantString.h" #include "OFMutableString.h" #ifdef __OBJC__ # import "OFString+CryptographicHashing.h" # import "OFString+JSONParsing.h" # ifdef OF_HAVE_FILES # import "OFString+PathAdditions.h" # endif # import "OFString+PropertyListParsing.h" # import "OFString+Serialization.h" # import "OFString+URLEncoding.h" |
︙ | ︙ |
Modified src/OFString.m from [f5bfcef342] to [d4404e2d68].
︙ | ︙ | |||
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | # include <locale.h> #endif #ifdef HAVE_XLOCALE_H # include <xlocale.h> #endif #import "OFString.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" | > | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # include <locale.h> #endif #ifdef HAVE_XLOCALE_H # include <xlocale.h> #endif #import "OFString.h" #import "OFASPrintF.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" # import "OFFileManager.h" |
︙ | ︙ | |||
55 56 57 58 59 60 61 | #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFRetrieveItemAttributesFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" | < | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #import "OFOpenItemFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "OFRetrieveItemAttributesFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "unicode.h" /* * It seems strtod is buggy on Win32. * However, the MinGW version __strtod seems to be ok. */ #ifdef __MINGW32__ |
︙ | ︙ | |||
85 86 87 88 89 90 91 | #if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) static locale_t cLocale; #endif @interface OFString () - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | #if defined(HAVE_STRTOF_L) || defined(HAVE_STRTOD_L) static locale_t cLocale; #endif @interface OFString () - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding lossy: (bool)lossy OF_DIRECT; - (const char *)of_cStringWithEncoding: (OFStringEncoding)encoding lossy: (bool)lossy OF_DIRECT; - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth; @end @interface OFStringPlaceholder: OFString @end extern bool OFUnicodeToISO8859_2(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToISO8859_3(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToISO8859_15(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToWindows1251(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToWindows1252(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToCodepage437(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToCodepage850(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToCodepage858(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToMacRoman(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToKOI8R(const OFUnichar *, unsigned char *, size_t, bool); extern bool OFUnicodeToKOI8U(const OFUnichar *, unsigned char *, size_t, bool); /* References for static linking */ void _references_to_categories_of_OFString(void) { _OFString_CryptographicHashing_reference = 1; _OFString_JSONParsing_reference = 1; #ifdef OF_HAVE_FILES _OFString_PathAdditions_reference = 1; #endif _OFString_PropertyListParsing_reference = 1; _OFString_Serialization_reference = 1; _OFString_URLEncoding_reference = 1; _OFString_XMLEscaping_reference = 1; _OFString_XMLUnescaping_reference = 1; } void _reference_to_OFConstantString(void) { [OFConstantString class]; } OFStringEncoding OFStringEncodingParseName(OFString *string) { void *pool = objc_autoreleasePoolPush(); OFStringEncoding encoding; string = string.lowercaseString; if ([string isEqual: @"utf8"] || [string isEqual: @"utf-8"]) encoding = OFStringEncodingUTF8; else if ([string isEqual: @"ascii"] || [string isEqual: @"us-ascii"]) encoding = OFStringEncodingASCII; else if ([string isEqual: @"iso-8859-1"] || [string isEqual: @"iso_8859-1"]) encoding = OFStringEncodingISO8859_1; else if ([string isEqual: @"iso-8859-2"] || [string isEqual: @"iso_8859-2"]) encoding = OFStringEncodingISO8859_2; else if ([string isEqual: @"iso-8859-3"] || [string isEqual: @"iso_8859-3"]) encoding = OFStringEncodingISO8859_3; else if ([string isEqual: @"iso-8859-15"] || [string isEqual: @"iso_8859-15"]) encoding = OFStringEncodingISO8859_15; else if ([string isEqual: @"windows-1251"] || [string isEqual: @"cp1251"] || [string isEqual: @"cp-1251"] || [string isEqual: @"1251"]) encoding = OFStringEncodingWindows1251; else if ([string isEqual: @"windows-1252"] || [string isEqual: @"cp1252"] || [string isEqual: @"cp-1252"] || [string isEqual: @"1252"]) encoding = OFStringEncodingWindows1252; else if ([string isEqual: @"cp437"] || [string isEqual: @"cp-437"] || [string isEqual: @"ibm437"] || [string isEqual: @"437"]) encoding = OFStringEncodingCodepage437; else if ([string isEqual: @"cp850"] || [string isEqual: @"cp-850"] || [string isEqual: @"ibm850"] || [string isEqual: @"850"]) encoding = OFStringEncodingCodepage850; else if ([string isEqual: @"cp858"] || [string isEqual: @"cp-858"] || [string isEqual: @"ibm858"] || [string isEqual: @"858"]) encoding = OFStringEncodingCodepage858; else if ([string isEqual: @"macintosh"] || [string isEqual: @"mac"]) encoding = OFStringEncodingMacRoman; else if ([string isEqual: @"koi8-r"]) encoding = OFStringEncodingKOI8R; else if ([string isEqual: @"koi8-u"]) encoding = OFStringEncodingKOI8U; else @throw [OFInvalidArgumentException exception]; objc_autoreleasePoolPop(pool); return encoding; } OFString * OFStringEncodingName(OFStringEncoding encoding) { switch (encoding) { case OFStringEncodingUTF8: return @"UTF-8"; case OFStringEncodingASCII: return @"ASCII"; case OFStringEncodingISO8859_1: return @"ISO 8859-1"; case OFStringEncodingISO8859_2: return @"ISO 8859-2"; case OFStringEncodingISO8859_3: return @"ISO 8859-3"; case OFStringEncodingISO8859_15: return @"ISO 8859-15"; case OFStringEncodingWindows1251: return @"Windows-1251"; case OFStringEncodingWindows1252: return @"Windows-1252"; case OFStringEncodingCodepage437: return @"Codepage 437"; case OFStringEncodingCodepage850: return @"Codepage 850"; case OFStringEncodingCodepage858: return @"Codepage 858"; case OFStringEncodingMacRoman: return @"Mac Roman"; case OFStringEncodingKOI8R: return @"KOI8-R"; case OFStringEncodingKOI8U: return @"KOI8-U"; case OFStringEncodingAutodetect: return @"autodetect"; } return nil; } size_t OFUTF8StringEncode(OFUnichar character, char *buffer) { if (character < 0x80) { buffer[0] = character; return 1; } else if (character < 0x800) { buffer[0] = 0xC0 | (character >> 6); buffer[1] = 0x80 | (character & 0x3F); |
︙ | ︙ | |||
262 263 264 265 266 267 268 | return 4; } return 0; } ssize_t | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | return 4; } return 0; } ssize_t OFUTF8StringDecode(const char *buffer_, size_t length, OFUnichar *ret) { const unsigned char *buffer = (const unsigned char *)buffer_; if (!(*buffer & 0x80)) { *ret = buffer[0]; return 1; } |
︙ | ︙ | |||
312 313 314 315 316 317 318 | return 4; } return 0; } size_t | | | > > > > > > > > > > | | | < | < | 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | return 4; } return 0; } size_t OFUTF16StringLength(const OFChar16 *string) { size_t length = 0; while (*string++ != 0) length++; return length; } size_t OFUTF32StringLength(const OFChar32 *string) { size_t length = 0; while (*string++ != 0) length++; return length; } char * OFStrDup(const char *string) { size_t length = strlen(string); char *copy = (char *)OFAllocMemory(1, length + 1); memcpy(copy, string, length + 1); return copy; } #ifdef OF_HAVE_UNICODE_TABLES static OFString * decomposedString(OFString *self, const char *const *const *table, size_t size) { OFMutableString *ret = [OFMutableString string]; void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; const char *const *page; if (c >= size) { [ret appendCharacters: &c length: 1]; continue; } page = table[c >> 8]; if (page != NULL && page[c & 0xFF] != NULL) [ret appendUTF8String: page[c & 0xFF]]; else [ret appendCharacters: &c length: 1]; } objc_autoreleasePoolPop(pool); return ret; } #endif |
︙ | ︙ | |||
379 380 381 382 383 384 385 | - (instancetype)initWithUTF8String: (const char *)UTF8String { OFUTF8String *string; size_t length; void *storage; length = strlen(UTF8String); | | | | 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | - (instancetype)initWithUTF8String: (const char *)UTF8String { OFUTF8String *string; size_t length; void *storage; length = strlen(UTF8String); string = OFAllocObject([OFUTF8String class], length + 1, 1, &storage); return (id)[string of_initWithUTF8String: UTF8String length: length storage: storage]; } - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { OFUTF8String *string; void *storage; string = OFAllocObject([OFUTF8String class], UTF8StringLength + 1, 1, &storage); return (id)[string of_initWithUTF8String: UTF8String length: UTF8StringLength storage: storage]; } |
︙ | ︙ | |||
419 420 421 422 423 424 425 | return (id)[[OFUTF8String alloc] initWithUTF8StringNoCopy: UTF8String length: UTF8StringLength freeWhenDone: freeWhenDone]; } - (instancetype)initWithCString: (const char *)cString | | | | | | | | | | | | | | | | | | | | | | | 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | return (id)[[OFUTF8String alloc] initWithUTF8StringNoCopy: UTF8String length: UTF8StringLength freeWhenDone: freeWhenDone]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { if (encoding == OFStringEncodingUTF8) { OFUTF8String *string; size_t length; void *storage; length = strlen(cString); string = OFAllocObject([OFUTF8String class], length + 1, 1, &storage); return (id)[string of_initWithUTF8String: cString length: length storage: storage]; } return (id)[[OFUTF8String alloc] initWithCString: cString encoding: encoding]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { if (encoding == OFStringEncodingUTF8) { OFUTF8String *string; void *storage; string = OFAllocObject([OFUTF8String class], cStringLength + 1, 1, &storage); return (id)[string of_initWithUTF8String: cString length: cStringLength storage: storage]; } return (id)[[OFUTF8String alloc] initWithCString: cString encoding: encoding length: cStringLength]; } - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithData: data encoding: encoding]; } - (instancetype)initWithString: (OFString *)string { return (id)[[OFUTF8String alloc] initWithString: string]; } - (instancetype)initWithCharacters: (const OFUnichar *)string length: (size_t)length { return (id)[[OFUTF8String alloc] initWithCharacters: string length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string { return (id)[[OFUTF8String alloc] initWithUTF16String: string]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length { return (id)[[OFUTF8String alloc] initWithUTF16String: string length: length]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF16String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF16String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string { return (id)[[OFUTF8String alloc] initWithUTF32String: string]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length { return (id)[[OFUTF8String alloc] initWithUTF32String: string length: length]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF32String: string byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return (id)[[OFUTF8String alloc] initWithUTF32String: string length: length byteOrder: byteOrder]; } - (instancetype)initWithFormat: (OFConstantString *)format, ... |
︙ | ︙ | |||
562 563 564 565 566 567 568 | #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFUTF8String alloc] initWithContentsOfFile: path]; } - (instancetype)initWithContentsOfFile: (OFString *)path | | < | < | 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 | #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return (id)[[OFUTF8String alloc] initWithContentsOfFile: path]; } - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithContentsOfFile: path encoding: encoding]; } #endif - (instancetype)initWithContentsOfURL: (OFURL *)URL { return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL]; } - (instancetype)initWithContentsOfURL: (OFURL *)URL encoding: (OFStringEncoding)encoding { return (id)[[OFUTF8String alloc] initWithContentsOfURL: URL encoding: encoding]; } - (instancetype)initWithSerialization: (OFXMLElement *)element { return (id)[[OFUTF8String alloc] initWithSerialization: element]; } - (instancetype)retain |
︙ | ︙ | |||
668 669 670 671 672 673 674 | return [[[self alloc] initWithUTF8StringNoCopy: UTF8String length: UTF8StringLength freeWhenDone: freeWhenDone] autorelease]; } + (instancetype)stringWithCString: (const char *)cString | | | | | | | | | | | | | | | | | | 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | return [[[self alloc] initWithUTF8StringNoCopy: UTF8String length: UTF8StringLength freeWhenDone: freeWhenDone] autorelease]; } + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithCString: cString encoding: encoding] autorelease]; } + (instancetype)stringWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { return [[[self alloc] initWithCString: cString encoding: encoding length: cStringLength] autorelease]; } + (instancetype)stringWithData: (OFData *)data encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithData: data encoding: encoding] autorelease]; } + (instancetype)stringWithString: (OFString *)string { return [[[self alloc] initWithString: string] autorelease]; } + (instancetype)stringWithCharacters: (const OFUnichar *)string length: (size_t)length { return [[[self alloc] initWithCharacters: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string { return [[[self alloc] initWithUTF16String: string] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length { return [[[self alloc] initWithUTF16String: string length: length] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF16String: string byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF16String: string length: length byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string { return [[[self alloc] initWithUTF32String: string] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length { return [[[self alloc] initWithUTF32String: string length: length] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF32String: string byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { return [[[self alloc] initWithUTF32String: string length: length byteOrder: byteOrder] autorelease]; } + (instancetype)stringWithFormat: (OFConstantString *)format, ... |
︙ | ︙ | |||
778 779 780 781 782 783 784 | #ifdef OF_HAVE_FILES + (instancetype)stringWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } + (instancetype)stringWithContentsOfFile: (OFString *)path | | < | < | | | | < | | | | | 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 | #ifdef OF_HAVE_FILES + (instancetype)stringWithContentsOfFile: (OFString *)path { return [[[self alloc] initWithContentsOfFile: path] autorelease]; } + (instancetype)stringWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithContentsOfFile: path encoding: encoding] autorelease]; } #endif + (instancetype)stringWithContentsOfURL: (OFURL *)URL { return [[[self alloc] initWithContentsOfURL: URL] autorelease]; } + (instancetype)stringWithContentsOfURL: (OFURL *)URL encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithContentsOfURL: URL encoding: encoding] autorelease]; } - (instancetype)init { if ([self isMemberOfClass: [OFString class]]) { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @throw e; } abort(); } return [super init]; } - (instancetype)initWithUTF8String: (const char *)UTF8String { return [self initWithCString: UTF8String encoding: OFStringEncodingUTF8 length: strlen(UTF8String)]; } - (instancetype)initWithUTF8String: (const char *)UTF8String length: (size_t)UTF8StringLength { return [self initWithCString: UTF8String encoding: OFStringEncodingUTF8 length: UTF8StringLength]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { id ret = [self initWithUTF8String: UTF8String]; if (freeWhenDone) OFFreeMemory(UTF8String); return ret; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { id ret = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) OFFreeMemory(UTF8String); return ret; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding { return [self initWithCString: cString encoding: encoding length: strlen(cString)]; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { OF_INVALID_INIT_METHOD } - (instancetype)initWithData: (OFData *)data encoding: (OFStringEncoding)encoding { @try { if (data.itemSize != 1) @throw [OFInvalidArgumentException exception]; } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
892 893 894 895 896 897 898 | } - (instancetype)initWithString: (OFString *)string { OF_INVALID_INIT_METHOD } | | | | | | | | | | | | | | | | | | | | | | | < | | | 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | } - (instancetype)initWithString: (OFString *)string { OF_INVALID_INIT_METHOD } - (instancetype)initWithCharacters: (const OFUnichar *)string length: (size_t)length { OF_INVALID_INIT_METHOD } - (instancetype)initWithUTF16String: (const OFChar16 *)string { return [self initWithUTF16String: string length: OFUTF16StringLength(string) byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length { return [self initWithUTF16String: string length: length byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string byteOrder: (OFByteOrder)byteOrder { return [self initWithUTF16String: string length: OFUTF16StringLength(string) byteOrder: byteOrder]; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { OF_INVALID_INIT_METHOD } - (instancetype)initWithUTF32String: (const OFChar32 *)string { return [self initWithUTF32String: string length: OFUTF32StringLength(string) byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length { return [self initWithUTF32String: string length: length byteOrder: OFByteOrderNative]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string byteOrder: (OFByteOrder)byteOrder { return [self initWithUTF32String: string length: OFUTF32StringLength(string) byteOrder: byteOrder]; } - (instancetype)initWithUTF32String: (const OFChar32 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { OF_INVALID_INIT_METHOD } - (instancetype)initWithFormat: (OFConstantString *)format, ... { id ret; va_list arguments; va_start(arguments, format); ret = [self initWithFormat: format arguments: arguments]; va_end(arguments); return ret; } - (instancetype)initWithFormat: (OFConstantString *)format arguments: (va_list)arguments { OF_INVALID_INIT_METHOD } #ifdef OF_HAVE_FILES - (instancetype)initWithContentsOfFile: (OFString *)path { return [self initWithContentsOfFile: path encoding: OFStringEncodingUTF8]; } - (instancetype)initWithContentsOfFile: (OFString *)path encoding: (OFStringEncoding)encoding { char *tmp; unsigned long long fileSize; @try { void *pool = objc_autoreleasePoolPush(); OFFile *file = nil; |
︙ | ︙ | |||
1018 1019 1020 1021 1022 1023 1024 | /* * We need one extra byte for the terminating zero if we want * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; | | | < < | | | | | | | 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | /* * We need one extra byte for the terminating zero if we want * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; tmp = OFAllocMemory((size_t)fileSize + 1, 1); @try { file = [[OFFile alloc] initWithPath: path mode: @"r"]; [file readIntoBuffer: tmp exactLength: (size_t)fileSize]; } @catch (id e) { OFFreeMemory(tmp); @throw e; } @finally { [file release]; } tmp[(size_t)fileSize] = '\0'; } @catch (id e) { [self release]; @throw e; } if (encoding == OFStringEncodingUTF8) { @try { self = [self initWithUTF8StringNoCopy: tmp length: (size_t)fileSize freeWhenDone: true]; } @catch (id e) { OFFreeMemory(tmp); @throw e; } } else { @try { self = [self initWithCString: tmp encoding: encoding length: (size_t)fileSize]; } @finally { OFFreeMemory(tmp); } } return self; } #endif - (instancetype)initWithContentsOfURL: (OFURL *)URL { return [self initWithContentsOfURL: URL encoding: OFStringEncodingAutodetect]; } - (instancetype)initWithContentsOfURL: (OFURL *)URL encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFData *data; @try { data = [OFData dataWithContentsOfURL: URL]; } @catch (id e) { |
︙ | ︙ | |||
1095 1096 1097 1098 1099 1100 1101 | - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { | | | 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 | - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { if (![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; if ([self isKindOfClass: [OFMutableString class]]) { if (![element.name isEqual: @"OFMutableString"]) @throw [OFInvalidArgumentException exception]; } else { if (![element.name isEqual: @"OFString"]) |
︙ | ︙ | |||
1121 1122 1123 1124 1125 1126 1127 | objc_autoreleasePoolPop(pool); return self; } - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength | | | | | < | 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 | objc_autoreleasePoolPop(pool); return self; } - (size_t)of_getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding lossy: (bool)lossy { const OFUnichar *characters = self.characters; size_t i, length = self.length; switch (encoding) { case OFStringEncodingUTF8:; size_t j = 0; for (i = 0; i < length; i++) { char buffer[4]; size_t len = OFUTF8StringEncode(characters[i], buffer); /* * Check for one more than the current index, as we * need one for the terminating zero. */ if (j + len >= maxLength) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
1165 1166 1167 1168 1169 1170 1171 | break; } } cString[j] = '\0'; return j; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | < | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | < | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 | break; } } cString[j] = '\0'; return j; case OFStringEncodingASCII: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (characters[i] > 0x80) { if (lossy) cString[i] = '?'; else @throw [OFInvalidEncodingException exception]; } else cString[i] = (unsigned char)characters[i]; } cString[i] = '\0'; return length; case OFStringEncodingISO8859_1: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; for (i = 0; i < length; i++) { if OF_UNLIKELY (characters[i] > 0xFF) { if (lossy) cString[i] = '?'; else @throw [OFInvalidEncodingException exception]; } else cString[i] = (unsigned char)characters[i]; } cString[i] = '\0'; return length; #ifdef HAVE_ISO_8859_2 case OFStringEncodingISO8859_2: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToISO8859_2(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_ISO_8859_3 case OFStringEncodingISO8859_3: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToISO8859_3(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_ISO_8859_15 case OFStringEncodingISO8859_15: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToISO8859_15(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_WINDOWS_1251 case OFStringEncodingWindows1251: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToWindows1251(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_WINDOWS_1252 case OFStringEncodingWindows1252: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToWindows1252(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_CODEPAGE_437 case OFStringEncodingCodepage437: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToCodepage437(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_CODEPAGE_850 case OFStringEncodingCodepage850: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToCodepage850(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_CODEPAGE_858 case OFStringEncodingCodepage858: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToCodepage858(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_MAC_ROMAN case OFStringEncodingMacRoman: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToMacRoman(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_KOI8_R case OFStringEncodingKOI8R: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToKOI8R(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif #ifdef HAVE_KOI8_U case OFStringEncodingKOI8U: if (length + 1 > maxLength) @throw [OFOutOfRangeException exception]; if (!OFUnicodeToKOI8U(characters, (unsigned char *)cString, length, lossy)) @throw [OFInvalidEncodingException exception]; cString[length] = '\0'; return length; #endif default: @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; } } - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { return [self of_getCString: cString maxLength: maxLength encoding: encoding lossy: false]; } - (size_t)getLossyCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { return [self of_getCString: cString maxLength: maxLength encoding: encoding lossy: true]; } - (const char *)of_cStringWithEncoding: (OFStringEncoding)encoding lossy: (bool)lossy { size_t length = self.length; char *cString; size_t cStringLength; switch (encoding) { case OFStringEncodingUTF8: cString = OFAllocMemory((length * 4) + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: (length * 4) + 1 encoding: OFStringEncodingUTF8 lossy: lossy]; } @catch (id e) { OFFreeMemory(cString); @throw e; } @try { cString = OFResizeMemory(cString, cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } break; case OFStringEncodingASCII: case OFStringEncodingISO8859_1: case OFStringEncodingISO8859_2: case OFStringEncodingISO8859_3: case OFStringEncodingISO8859_15: case OFStringEncodingWindows1251: case OFStringEncodingWindows1252: case OFStringEncodingCodepage437: case OFStringEncodingCodepage850: case OFStringEncodingCodepage858: case OFStringEncodingMacRoman: case OFStringEncodingKOI8R: case OFStringEncodingKOI8U: cString = OFAllocMemory(length + 1, 1); @try { cStringLength = [self of_getCString: cString maxLength: length + 1 encoding: encoding lossy: lossy]; } @catch (id e) { OFFreeMemory(cString); @throw e; } break; default: @throw [OFInvalidEncodingException exception]; } @try { return [[OFData dataWithItemsNoCopy: cString count: cStringLength + 1 freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(cString); @throw e; } } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { return [self of_cStringWithEncoding: encoding lossy: false]; } - (const char *)lossyCStringWithEncoding: (OFStringEncoding)encoding { return [self of_cStringWithEncoding: encoding lossy: true]; } - (const char *)UTF8String { return [self cStringWithEncoding: OFStringEncodingUTF8]; } - (size_t)length { OF_UNRECOGNIZED_SELECTOR } - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingUTF8:; const OFUnichar *characters; size_t length, UTF8StringLength = 0; characters = self.characters; length = self.length; for (size_t i = 0; i < length; i++) { char buffer[4]; size_t len = OFUTF8StringEncode(characters[i], buffer); if (len == 0) @throw [OFInvalidEncodingException exception]; UTF8StringLength += len; } return UTF8StringLength; case OFStringEncodingASCII: case OFStringEncodingISO8859_1: case OFStringEncodingISO8859_2: case OFStringEncodingISO8859_3: case OFStringEncodingISO8859_15: case OFStringEncodingWindows1251: case OFStringEncodingWindows1252: case OFStringEncodingCodepage437: case OFStringEncodingCodepage850: case OFStringEncodingCodepage858: case OFStringEncodingMacRoman: case OFStringEncodingKOI8R: case OFStringEncodingKOI8U: return self.length; default: @throw [OFInvalidEncodingException exception]; } } - (size_t)UTF8StringLength { return [self cStringLengthWithEncoding: OFStringEncodingUTF8]; } - (OFUnichar)characterAtIndex: (size_t)idx { OF_UNRECOGNIZED_SELECTOR } - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range { for (size_t i = 0; i < range.length; i++) buffer[i] = [self characterAtIndex: range.location + i]; } - (bool)isEqual: (id)object { void *pool; OFString *string; const OFUnichar *characters, *otherCharacters; size_t length; if (object == self) return true; if (![object isKindOfClass: [OFString class]]) return false; string = object; length = self.length; if (string.length != length) return false; pool = objc_autoreleasePoolPush(); characters = self.characters; otherCharacters = string.characters; if (memcmp(characters, otherCharacters, length * sizeof(OFUnichar)) != 0) { objc_autoreleasePoolPop(pool); return false; } objc_autoreleasePoolPop(pool); return true; } - (id)copy { return [self retain]; } - (id)mutableCopy { return [[OFMutableString alloc] initWithString: self]; } - (OFComparisonResult)compare: (OFString *)string { void *pool; const OFUnichar *characters, *otherCharacters; size_t minimumLength; if (string == self) return OFOrderedSame; if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; minimumLength = (self.length > string.length ? string.length : self.length); pool = objc_autoreleasePoolPush(); characters = self.characters; otherCharacters = string.characters; for (size_t i = 0; i < minimumLength; i++) { if (characters[i] > otherCharacters[i]) { objc_autoreleasePoolPop(pool); return OFOrderedDescending; } if (characters[i] < otherCharacters[i]) { objc_autoreleasePoolPop(pool); return OFOrderedAscending; } } objc_autoreleasePoolPop(pool); if (self.length > string.length) return OFOrderedDescending; if (self.length < string.length) return OFOrderedAscending; return OFOrderedSame; } - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters, *otherCharacters; size_t length, otherLength, minimumLength; if (string == self) return OFOrderedSame; characters = self.characters; otherCharacters = string.characters; length = self.length; otherLength = string.length; minimumLength = (length > otherLength ? otherLength : length); for (size_t i = 0; i < minimumLength; i++) { OFUnichar c = characters[i]; OFUnichar oc = otherCharacters[i]; #ifdef OF_HAVE_UNICODE_TABLES if (c >> 8 < OFUnicodeCaseFoldingTableSize) { OFUnichar tc = OFUnicodeCaseFoldingTable[c >> 8][c & 0xFF]; if (tc) c = tc; } if (oc >> 8 < OFUnicodeCaseFoldingTableSize) { OFUnichar tc = OFUnicodeCaseFoldingTable[oc >> 8][oc & 0xFF]; if (tc) oc = tc; } #else c = OFASCIIToUpper(c); oc = OFASCIIToUpper(oc); #endif if (c > oc) { objc_autoreleasePoolPop(pool); return OFOrderedDescending; } if (c < oc) { objc_autoreleasePoolPop(pool); return OFOrderedAscending; } } objc_autoreleasePoolPop(pool); if (length > otherLength) return OFOrderedDescending; if (length < otherLength) return OFOrderedAscending; return OFOrderedSame; } - (unsigned long)hash { const OFUnichar *characters = self.characters; size_t length = self.length; unsigned long hash; OFHashInit(&hash); for (size_t i = 0; i < length; i++) { const OFUnichar c = characters[i]; OFHashAdd(&hash, (c & 0xFF0000) >> 16); OFHashAdd(&hash, (c & 0x00FF00) >> 8); OFHashAdd(&hash, c & 0x0000FF); } OFHashFinalize(&hash); return hash; } - (OFString *)description { return [[self copy] autorelease]; |
︙ | ︙ | |||
1706 1707 1708 1709 1710 1711 1712 | if ([self isKindOfClass: [OFMutableString class]]) className = @"OFMutableString"; else className = @"OFString"; element = [OFXMLElement elementWithName: className | | | < | > | < | > | | < | < | < | < | < | < | | < | | | < | < < | < < | | < < | < | | < < | < | < | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | | < | | | | | | | | | 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 | if ([self isKindOfClass: [OFMutableString class]]) className = @"OFMutableString"; else className = @"OFString"; element = [OFXMLElement elementWithName: className namespace: OFSerializationNS stringValue: self]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFString *)JSONRepresentation { return [self of_JSONRepresentationWithOptions: 0 depth: 0]; } - (OFString *)JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options { return [self of_JSONRepresentationWithOptions: options depth: 0]; } - (OFString *) of_JSONRepresentationWithOptions: (OFJSONRepresentationOptions)options depth: (size_t)depth { OFMutableString *JSON = [[self mutableCopy] autorelease]; /* FIXME: This is slow! Write it in pure C! */ [JSON replaceOccurrencesOfString: @"\\" withString: @"\\\\"]; [JSON replaceOccurrencesOfString: @"\"" withString: @"\\\""]; [JSON replaceOccurrencesOfString: @"\b" withString: @"\\b"]; [JSON replaceOccurrencesOfString: @"\f" withString: @"\\f"]; [JSON replaceOccurrencesOfString: @"\r" withString: @"\\r"]; [JSON replaceOccurrencesOfString: @"\t" withString: @"\\t"]; if (options & OFJSONRepresentationOptionJSON5) { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\\n"]; if (options & OFJSONRepresentationOptionIsIdentifier) { const char *cString = self.UTF8String; if ((!OFASCIIIsAlpha(cString[0]) && cString[0] != '_' && cString[0] != '$') || strpbrk(cString, " \n\r\t\b\f\\\"'") != NULL) { [JSON prependString: @"\""]; [JSON appendString: @"\""]; } } else { [JSON prependString: @"\""]; [JSON appendString: @"\""]; } } else { [JSON replaceOccurrencesOfString: @"\n" withString: @"\\n"]; [JSON prependString: @"\""]; [JSON appendString: @"\""]; } [JSON makeImmutable]; return JSON; } - (OFData *)messagePackRepresentation { OFMutableData *data; size_t length; length = self.UTF8StringLength; if (length <= 31) { uint8_t tmp = 0xA0 | ((uint8_t)length & 0x1F); data = [OFMutableData dataWithCapacity: length + 1]; [data addItem: &tmp]; } else if (length <= UINT8_MAX) { uint8_t type = 0xD9; uint8_t tmp = (uint8_t)length; data = [OFMutableData dataWithCapacity: length + 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (length <= UINT16_MAX) { uint8_t type = 0xDA; uint16_t tmp = OFToBigEndian16((uint16_t)length); data = [OFMutableData dataWithCapacity: length + 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (length <= UINT32_MAX) { uint8_t type = 0xDB; uint32_t tmp = OFToBigEndian32((uint32_t)length); data = [OFMutableData dataWithCapacity: length + 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exception]; [data addItems: self.UTF8String count: length]; return data; } - (OFRange)rangeOfString: (OFString *)string { return [self rangeOfString: string options: 0 range: OFRangeMake(0, self.length)]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options { return [self rangeOfString: string options: options range: OFRangeMake(0, self.length)]; } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { void *pool; const OFUnichar *searchCharacters; OFUnichar *characters; size_t searchLength; if ((searchLength = string.length) == 0) return OFRangeMake(0, 0); if (searchLength > range.length) return OFRangeMake(OFNotFound, 0); if (range.length > SIZE_MAX / sizeof(OFUnichar)) @throw [OFOutOfRangeException exception]; pool = objc_autoreleasePoolPush(); searchCharacters = string.characters; characters = OFAllocMemory(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; if (options & OFStringSearchBackwards) { for (size_t i = range.length - searchLength;; i--) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return OFRangeMake(range.location + i, searchLength); } /* No match and we're at the last character */ if (i == 0) break; } } else { for (size_t i = 0; i <= range.length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return OFRangeMake(range.location + i, searchLength); } } } } @finally { OFFreeMemory(characters); } objc_autoreleasePoolPop(pool); return OFRangeMake(OFNotFound, 0); } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet { return [self indexOfCharacterFromSet: characterSet options: 0 range: OFRangeMake(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options { return [self indexOfCharacterFromSet: characterSet options: options range: OFRangeMake(0, self.length)]; } - (size_t)indexOfCharacterFromSet: (OFCharacterSet *)characterSet options: (OFStringSearchOptions)options range: (OFRange)range { bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[characterSet methodForSelector: @selector(characterIsMember:)]; OFUnichar *characters; if (range.length == 0) return OFNotFound; if (range.length > SIZE_MAX / sizeof(OFUnichar)) @throw [OFOutOfRangeException exception]; characters = OFAllocMemory(range.length, sizeof(OFUnichar)); @try { [self getCharacters: characters inRange: range]; if (options & OFStringSearchBackwards) { for (size_t i = range.length - 1;; i--) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) return range.location + i; /* No match and we're at the last character */ if (i == 0) break; } } else { for (size_t i = 0; i < range.length; i++) if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) return range.location + i; } } @finally { OFFreeMemory(characters); } return OFNotFound; } - (bool)containsString: (OFString *)string { void *pool; const OFUnichar *characters, *searchCharacters; size_t length, searchLength; if ((searchLength = string.length) == 0) return true; if (searchLength > (length = self.length)) return false; pool = objc_autoreleasePoolPush(); characters = self.characters; searchCharacters = string.characters; for (size_t i = 0; i <= length - searchLength; i++) { if (memcmp(characters + i, searchCharacters, searchLength * sizeof(OFUnichar)) == 0) { objc_autoreleasePoolPop(pool); return true; } } objc_autoreleasePoolPop(pool); return false; } - (OFString *)substringFromIndex: (size_t)idx { return [self substringWithRange: OFRangeMake(idx, self.length - idx)]; } - (OFString *)substringToIndex: (size_t)idx { return [self substringWithRange: OFRangeMake(0, idx)]; } - (OFString *)substringWithRange: (OFRange)range { void *pool; OFString *ret; if (range.length > SIZE_MAX - range.location || range.location + range.length > self.length) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
2040 2041 2042 2043 2044 2045 2046 | - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ... { OFString *ret; va_list arguments; va_start(arguments, format); | | < < < | | < < < < < < < | < < < | < < < < < < < < < < < < < < < < < < < < < | | | < | | | | | | | | | < | | | | 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 | - (OFString *)stringByAppendingFormat: (OFConstantString *)format, ... { OFString *ret; va_list arguments; va_start(arguments, format); ret = [self stringByAppendingFormat: format arguments: arguments]; va_end(arguments); return ret; } - (OFString *)stringByAppendingFormat: (OFConstantString *)format arguments: (va_list)arguments { OFMutableString *new = [OFMutableString stringWithString: self]; [new appendFormat: format arguments: arguments]; [new makeImmutable]; return new; } - (OFString *)stringByPrependingString: (OFString *)string { OFMutableString *new = [[string mutableCopy] autorelease]; [new appendString: self]; [new makeImmutable]; return new; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement]; [new makeImmutable]; return new; } - (OFString *)stringByReplacingOccurrencesOfString: (OFString *)string withString: (OFString *)replacement options: (int)options range: (OFRange)range { OFMutableString *new = [[self mutableCopy] autorelease]; [new replaceOccurrencesOfString: string withString: replacement options: options range: range]; [new makeImmutable]; return new; } - (OFString *)uppercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new uppercase]; [new makeImmutable]; return new; } - (OFString *)lowercaseString { OFMutableString *new = [[self mutableCopy] autorelease]; [new lowercase]; [new makeImmutable]; return new; } - (OFString *)capitalizedString { OFMutableString *new = [[self mutableCopy] autorelease]; [new capitalize]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingLeadingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteLeadingWhitespaces]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingTrailingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteTrailingWhitespaces]; [new makeImmutable]; return new; } - (OFString *)stringByDeletingEnclosingWhitespaces { OFMutableString *new = [[self mutableCopy] autorelease]; [new deleteEnclosingWhitespaces]; [new makeImmutable]; return new; } - (bool)hasPrefix: (OFString *)prefix { OFUnichar *tmp; size_t prefixLength; bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; tmp = OFAllocMemory(prefixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFRangeMake(0, prefixLength)]; hasPrefix = (memcmp(tmp, prefix.characters, prefixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); } @finally { OFFreeMemory(tmp); } return hasPrefix; } - (bool)hasSuffix: (OFString *)suffix { OFUnichar *tmp; const OFUnichar *suffixCharacters; size_t length, suffixLength; bool hasSuffix; if ((suffixLength = suffix.length) > self.length) return false; length = self.length; tmp = OFAllocMemory(suffixLength, sizeof(OFUnichar)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: OFRangeMake(length - suffixLength, suffixLength)]; suffixCharacters = suffix.characters; hasSuffix = (memcmp(tmp, suffixCharacters, suffixLength * sizeof(OFUnichar)) == 0); objc_autoreleasePoolPop(pool); } @finally { OFFreeMemory(tmp); } return hasSuffix; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter { return [self componentsSeparatedByString: delimiter options: 0]; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options { void *pool; OFMutableArray *array; const OFUnichar *characters, *delimiterCharacters; bool skipEmpty = (options & OFStringSkipEmptyComponents); size_t length = self.length; size_t delimiterLength = delimiter.length; size_t last; OFString *component; if (delimiter == nil) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ | |||
2269 2270 2271 2272 2273 2274 2275 | return array; } last = 0; for (size_t i = 0; i <= length - delimiterLength; i++) { if (memcmp(characters + i, delimiterCharacters, | | | > | | | | | | | | | 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 | return array; } last = 0; for (size_t i = 0; i <= length - delimiterLength; i++) { if (memcmp(characters + i, delimiterCharacters, delimiterLength * sizeof(OFUnichar)) != 0) continue; component = [self substringWithRange: OFRangeMake(last, i - last)]; if (!skipEmpty || component.length > 0) [array addObject: component]; i += delimiterLength - 1; last = i + 1; } component = [self substringWithRange: OFRangeMake(last, length - last)]; if (!skipEmpty || component.length > 0) [array addObject: component]; [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet { return [self componentsSeparatedByCharactersInSet: characterSet options: 0]; } - (OFArray *) componentsSeparatedByCharactersInSet: (OFCharacterSet *)characterSet options: (OFStringSeparationOptions)options { OFMutableArray *array = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); bool skipEmpty = (options & OFStringSkipEmptyComponents); const OFUnichar *characters = self.characters; size_t length = self.length; bool (*characterIsMember)(id, SEL, OFUnichar) = (bool (*)(id, SEL, OFUnichar))[characterSet methodForSelector: @selector(characterIsMember:)]; size_t last; last = 0; for (size_t i = 0; i < length; i++) { if (characterIsMember(characterSet, @selector(characterIsMember:), characters[i])) { if (!skipEmpty || i != last) { OFString *component = [self substringWithRange: OFRangeMake(last, i - last)]; [array addObject: component]; } last = i + 1; } } if (!skipEmpty || length != last) { OFString *component = [self substringWithRange: OFRangeMake(last, length - last)]; [array addObject: component]; } [array makeImmutable]; objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
2349 2350 2351 2352 2353 2354 2355 | - (long long)longLongValueWithBase: (int)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; bool negative = false; long long value = 0; | | | 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 | - (long long)longLongValueWithBase: (int)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; bool negative = false; long long value = 0; while (OFASCIIIsSpace(*UTF8String)) UTF8String++; switch (*UTF8String) { case '-': negative = true; case '+': UTF8String++; |
︙ | ︙ | |||
2380 2381 2382 2383 2384 2385 2386 | } } if (base == 0) base = 10; while (*UTF8String != '\0') { | | | | | 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 | } } if (base == 0) base = 10; while (*UTF8String != '\0') { unsigned char c = OFASCIIToUpper(*UTF8String++); if (c >= '0' && c <= '9') c -= '0'; else if (c >= 'A' && c <= 'Z') c -= ('A' - 10); else if (OFASCIIIsSpace(c)) { while (*UTF8String != '\0') if (!OFASCIIIsSpace(*UTF8String++)) @throw [OFInvalidFormatException exception]; break; } else @throw [OFInvalidFormatException exception]; |
︙ | ︙ | |||
2424 2425 2426 2427 2428 2429 2430 | - (unsigned long long)unsignedLongLongValueWithBase: (int)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; unsigned long long value = 0; | | | 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 | - (unsigned long long)unsignedLongLongValueWithBase: (int)base { void *pool = objc_autoreleasePoolPush(); const char *UTF8String = self.UTF8String; unsigned long long value = 0; while (OFASCIIIsSpace(*UTF8String)) UTF8String++; switch (*UTF8String) { case '-': @throw [OFInvalidFormatException exception]; case '+': UTF8String++; |
︙ | ︙ | |||
2455 2456 2457 2458 2459 2460 2461 | } } if (base == 0) base = 10; while (*UTF8String != '\0') { | | | | | 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 | } } if (base == 0) base = 10; while (*UTF8String != '\0') { unsigned char c = OFASCIIToUpper(*UTF8String++); if (c >= '0' && c <= '9') c -= '0'; else if (c >= 'A' && c <= 'Z') c -= ('A' - 10); else if (OFASCIIIsSpace(c)) { while (*UTF8String != '\0') if (!OFASCIIIsSpace(*UTF8String++)) @throw [OFInvalidFormatException exception]; break; } else @throw [OFInvalidFormatException exception]; |
︙ | ︙ | |||
2491 2492 2493 2494 2495 2496 2497 | } - (float)floatValue { void *pool = objc_autoreleasePoolPush(); OFString *stripped = self.stringByDeletingEnclosingWhitespaces; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | > | | | | | | | | | | | | | < | | | | | | | | | | | < | < < < | < | < < | < | < | < | < | | | | | 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 | } - (float)floatValue { void *pool = objc_autoreleasePoolPush(); OFString *stripped = self.stringByDeletingEnclosingWhitespaces; if ([stripped caseInsensitiveCompare: @"INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"INFINITY"] == OFOrderedSame) return INFINITY; if ([stripped caseInsensitiveCompare: @"-INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame) return -INFINITY; if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame) return NAN; if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame) return -NAN; #ifdef HAVE_STRTOF_L const char *UTF8String = self.UTF8String; #else /* * If we have no strtof_l, we have no other choice but to replace "." * with the locale's decimal point. */ OFString *decimalPoint = [OFLocale decimalPoint]; const char *UTF8String = [self stringByReplacingOccurrencesOfString: @"." withString: decimalPoint].UTF8String; #endif char *endPtr = NULL; float value; errno = 0; #ifdef HAVE_STRTOF_L value = strtof_l(UTF8String, &endPtr, cLocale); #else value = strtof(UTF8String, &endPtr); #endif if (value == HUGE_VALF && errno == ERANGE) @throw [OFOutOfRangeException exception]; /* Check if there are any invalid chars left */ if (endPtr != NULL) for (; *endPtr != '\0'; endPtr++) /* Use isspace since strtof uses the same. */ if (!isspace((unsigned char)*endPtr)) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; } - (double)doubleValue { void *pool = objc_autoreleasePoolPush(); OFString *stripped = self.stringByDeletingEnclosingWhitespaces; if ([stripped caseInsensitiveCompare: @"INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"INFINITY"] == OFOrderedSame) return INFINITY; if ([stripped caseInsensitiveCompare: @"-INF"] == OFOrderedSame || [stripped caseInsensitiveCompare: @"-INFINITY"] == OFOrderedSame) return -INFINITY; if ([stripped caseInsensitiveCompare: @"NAN"] == OFOrderedSame) return NAN; if ([stripped caseInsensitiveCompare: @"-NAN"] == OFOrderedSame) return -NAN; #ifdef HAVE_STRTOD_L const char *UTF8String = self.UTF8String; #else /* * If we have no strtod_l, we have no other choice but to replace "." * with the locale's decimal point. */ OFString *decimalPoint = [OFLocale decimalPoint]; const char *UTF8String = [self stringByReplacingOccurrencesOfString: @"." withString: decimalPoint].UTF8String; #endif char *endPtr = NULL; double value; errno = 0; #ifdef HAVE_STRTOD_L value = strtod_l(UTF8String, &endPtr, cLocale); #else value = strtod(UTF8String, &endPtr); #endif if (value == HUGE_VAL && errno == ERANGE) @throw [OFOutOfRangeException exception]; /* Check if there are any invalid chars left */ if (endPtr != NULL) for (; *endPtr != '\0'; endPtr++) /* Use isspace since strtod uses the same. */ if (!isspace((unsigned char)*endPtr)) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; } - (const OFUnichar *)characters { size_t length = self.length; OFUnichar *buffer; buffer = OFAllocMemory(length, sizeof(OFUnichar)); @try { [self getCharacters: buffer inRange: OFRangeMake(0, length)]; return [[OFData dataWithItemsNoCopy: buffer count: length itemSize: sizeof(OFUnichar) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } } - (const OFChar16 *)UTF16String { return [self UTF16StringWithByteOrder: OFByteOrderNative]; } - (const OFChar16 *)UTF16StringWithByteOrder: (OFByteOrder)byteOrder { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t length = self.length; OFChar16 *buffer; size_t j; bool swap = (byteOrder != OFByteOrderNative); /* Allocate memory for the worst case */ buffer = OFAllocMemory((length + 1) * 2, sizeof(OFChar16)); j = 0; for (size_t i = 0; i < length; i++) { OFUnichar c = characters[i]; if (c > 0x10FFFF) { OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } if (swap) { if (c > 0xFFFF) { c -= 0x10000; buffer[j++] = OFByteSwap16(0xD800 | (c >> 10)); buffer[j++] = OFByteSwap16(0xDC00 | (c & 0x3FF)); } else buffer[j++] = OFByteSwap16(c); } else { if (c > 0xFFFF) { c -= 0x10000; buffer[j++] = 0xD800 | (c >> 10); buffer[j++] = 0xDC00 | (c & 0x3FF); } else buffer[j++] = c; } } buffer[j] = 0; @try { buffer = OFResizeMemory(buffer, j + 1, sizeof(OFChar16)); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); @try { return [[OFData dataWithItemsNoCopy: buffer count: j + 1 itemSize: sizeof(OFChar16) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } } - (size_t)UTF16StringLength { const OFUnichar *characters = self.characters; size_t length, UTF16StringLength; length = UTF16StringLength = self.length; for (size_t i = 0; i < length; i++) if (characters[i] > 0xFFFF) UTF16StringLength++; return UTF16StringLength; } - (const OFChar32 *)UTF32String { return [self UTF32StringWithByteOrder: OFByteOrderNative]; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { size_t length = self.length; OFChar32 *buffer; buffer = OFAllocMemory(length + 1, sizeof(OFChar32)); @try { [self getCharacters: buffer inRange: OFRangeMake(0, length)]; buffer[length] = 0; if (byteOrder != OFByteOrderNative) for (size_t i = 0; i < length; i++) buffer[i] = OFByteSwap32(buffer[i]); return [[OFData dataWithItemsNoCopy: buffer count: length + 1 itemSize: sizeof(OFChar32) freeWhenDone: true] items]; } @catch (id e) { OFFreeMemory(buffer); @throw e; } } - (OFData *)dataWithEncoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFData *data = [OFData dataWithItems: [self cStringWithEncoding: encoding] count: [self cStringLengthWithEncoding: encoding]]; [data retain]; objc_autoreleasePoolPop(pool); return [data autorelease]; } #ifdef OF_HAVE_UNICODE_TABLES - (OFString *)decomposedStringWithCanonicalMapping { return decomposedString(self, OFUnicodeDecompositionTable, OFUnicodeDecompositionTableSize); } - (OFString *)decomposedStringWithCompatibilityMapping { return decomposedString(self, OFUnicodeDecompositionCompatTable, OFUnicodeDecompositionCompatTableSize); } #endif #ifdef OF_WINDOWS - (OFString *)stringByExpandingWindowsEnvironmentStrings { if ([OFSystemInfo isWindowsNT]) { wchar_t buffer[512]; size_t length; if ((length = ExpandEnvironmentStringsW(self.UTF16String, buffer, sizeof(buffer))) == 0) return self; return [OFString stringWithUTF16String: buffer length: length - 1]; } else { OFStringEncoding encoding = [OFLocale encoding]; char buffer[512]; size_t length; if ((length = ExpandEnvironmentStringsA( [self cStringWithEncoding: encoding], buffer, sizeof(buffer))) == 0) return self; return [OFString stringWithCString: buffer encoding: encoding length: length - 1]; } } #endif #ifdef OF_HAVE_FILES - (void)writeToFile: (OFString *)path { [self writeToFile: path encoding: OFStringEncodingUTF8]; } - (void)writeToFile: (OFString *)path encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: path mode: @"w"]; [file writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #endif - (void)writeToURL: (OFURL *)URL { [self writeToURL: URL encoding: OFStringEncodingUTF8]; } - (void)writeToURL: (OFURL *)URL encoding: (OFStringEncoding)encoding { void *pool = objc_autoreleasePoolPush(); OFURLHandler *URLHandler; OFStream *stream; if ((URLHandler = [OFURLHandler handlerForURL: URL]) == nil) @throw [OFUnsupportedProtocolException exceptionWithURL: URL]; stream = [URLHandler openItemAtURL: URL mode: @"w"]; [stream writeString: self encoding: encoding]; objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block { void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; size_t i, last = 0, length = self.length; bool stop = false, lastCarriageReturn = false; for (i = 0; i < length && !stop; i++) { if (lastCarriageReturn && characters[i] == '\n') { lastCarriageReturn = false; last++; continue; } if (characters[i] == '\n' || characters[i] == '\r') { void *pool2 = objc_autoreleasePoolPush(); block([self substringWithRange: OFRangeMake(last, i - last)], &stop); last = i + 1; objc_autoreleasePoolPop(pool2); } lastCarriageReturn = (characters[i] == '\r'); } if (!stop) block([self substringWithRange: OFRangeMake(last, i - last)], &stop); objc_autoreleasePoolPop(pool); } #endif @end |
Modified src/OFSubarray.h from [9f4e68e06f] to [398ae6fbae].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFArray.h" OF_ASSUME_NONNULL_BEGIN @interface OFSubarray: OFArray { OFArray *_array; | | | < | < | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #import "OFArray.h" OF_ASSUME_NONNULL_BEGIN @interface OFSubarray: OFArray { OFArray *_array; OFRange _range; } + (instancetype)arrayWithArray: (OFArray *)array range: (OFRange)range; - (instancetype)initWithArray: (OFArray *)array range: (OFRange)range; @end OF_ASSUME_NONNULL_END |
Modified src/OFSubarray.m from [8ab33d1782] to [d5bd07084c].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #import "OFSubarray.h" #import "OFOutOfRangeException.h" @implementation OFSubarray | | < | < | < | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include "config.h" #import "OFSubarray.h" #import "OFOutOfRangeException.h" @implementation OFSubarray + (instancetype)arrayWithArray: (OFArray *)array range: (OFRange)range { return [[[self alloc] initWithArray: array range: range] autorelease]; } - (instancetype)initWithArray: (OFArray *)array range: (OFRange)range { self = [super init]; @try { /* Should usually be retain, as it's useless with a copy */ _array = [array copy]; _range = range; |
︙ | ︙ | |||
60 61 62 63 64 65 66 | { if (idx >= _range.length) @throw [OFOutOfRangeException exception]; return [_array objectAtIndex: idx + _range.location]; } | | < | < | | | | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | { if (idx >= _range.length) @throw [OFOutOfRangeException exception]; return [_array objectAtIndex: idx + _range.location]; } - (void)getObjects: (id *)buffer inRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _range.length) @throw [OFOutOfRangeException exception]; range.location += _range.location; [_array getObjects: buffer inRange: range]; } - (size_t)indexOfObject: (id)object { size_t idx = [_array indexOfObject: object]; if (idx < _range.location) return OFNotFound; idx -= _range.location; if (idx >= _range.length) return OFNotFound; return idx; } - (size_t)indexOfObjectIdenticalTo: (id)object { size_t idx = [_array indexOfObjectIdenticalTo: object]; if (idx < _range.location) return OFNotFound; idx -= _range.location; if (idx >= _range.length) return OFNotFound; return idx; } - (OFArray *)objectsInRange: (OFRange)range { if (range.length > SIZE_MAX - range.location || range.location + range.length > _range.length) @throw [OFOutOfRangeException exception]; range.location += _range.location; return [_array objectsInRange: range]; } @end |
Renamed and modified src/OFProcess.h [a7b8fab4c5] to src/OFSubprocess.h [a6ce8bbc81].
︙ | ︙ | |||
36 37 38 39 40 41 42 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | | > | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFDictionary OF_GENERIC(KeyType, ObjectType); /** * @class OFSubprocess OFSubprocess.h ObjFW/OFSubprocess.h * * @brief A class for stream-like communication with a newly created subprocess. */ OF_SUBCLASSING_RESTRICTED @interface OFSubprocess: OFStream #ifndef OF_WINDOWS <OFReadyForReadingObserving, OFReadyForWritingObserving> #endif { #ifndef OF_WINDOWS pid_t _pid; int _readPipe[2], _writePipe[2]; #else HANDLE _handle, _readPipe[2], _writePipe[2]; #endif int _status; bool _atEndOfStream; } /** * @brief Creates a new OFSubprocess with the specified program and invokes the * program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @return A new, autoreleased OFSubprocess. */ + (instancetype)subprocessWithProgram: (OFString *)program; /** * @brief Creates a new OFSubprocess with the specified program and arguments * and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param arguments The arguments to pass to the program, or `nil` * @return A new, autoreleased OFSubprocess. */ + (instancetype) subProcessWithProgram: (OFString *)program arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Creates a new OFSubprocess with the specified program, program name * and arguments and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @return A new, autoreleased OFSubprocess. */ + (instancetype) subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Creates a new OFSubprocess with the specified program, program name, * arguments and environment and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @param environment The environment to pass to the program, or `nil`. If it * is not `nil`, the passed dictionary will be used to * override the environment. If you want to add to the * existing environment, you need to get the existing * environment first, copy it, modify it and then pass it. * @return A new, autoreleased OFSubprocess. */ + (instancetype) subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments environment: (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFSubprocess with the specified * program and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @return An initialized OFSubprocess. */ - (instancetype)initWithProgram: (OFString *)program; /** * @brief Initializes an already allocated OFSubprocess with the specified * program and arguments and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param arguments The arguments to pass to the program, or `nil` * @return An initialized OFSubprocess. */ - (instancetype) initWithProgram: (OFString *)program arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Initializes an already allocated OFSubprocess with the specified * program, program name and arguments and invokes the program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @return An initialized OFSubprocess. */ - (instancetype) initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments; /** * @brief Initializes an already allocated OFSubprocess with the specified * program, program name, arguments and environment and invokes the * program. * * @param program The program to execute. If it does not start with a slash, the * search path specified in PATH is used. * @param programName The program name for the program to invoke (argv[0]). * Usually, this is equal to program. * @param arguments The arguments to pass to the program, or `nil` * @param environment The environment to pass to the program, or `nil`. If it * is not `nil`, the passed dictionary will be used to * override the environment. If you want to add to the * existing environment, you need to get the existing * environment first, copy it, modify it and then pass it. * @return An initialized OFSubprocess. */ - (instancetype) initWithProgram: (OFString *)program programName: (OFString *)programName arguments: (nullable OFArray OF_GENERIC(OFString *) *)arguments environment: (nullable OFDictionary OF_GENERIC(OFString *, OFString *) *)environment OF_DESIGNATED_INITIALIZER; /** * @brief Closes the write direction of the subprocess. * * This method needs to be called for some programs before data can be read, * since some programs don't start processing before the write direction is * closed. */ - (void)closeForWriting; /** * @brief Waits for the subprocess to terminate and returns the exit status. * * If the subprocess has already exited, this returns the exit status * immediately. */ - (int)waitForTermination; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFProcess.m [80953e8b4c] to src/OFSubprocess.m [f686b80ad6].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include "platform.h" #ifdef OF_WINDOWS | | | | 14 15 16 17 18 19 20 21 22 23 24 | */ #include "config.h" #include "platform.h" #ifdef OF_WINDOWS # include "platform/Windows/OFSubprocess.m" #else # include "platform/POSIX/OFSubprocess.m" #endif |
Modified src/OFSystemInfo.m from [d40194da67] to [6fd50f8c07].
︙ | ︙ | |||
39 40 41 42 43 44 45 46 47 48 49 | #endif #import "OFSystemInfo.h" #import "OFApplication.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFString.h" #import "OFNotImplementedException.h" | > < < | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #endif #import "OFSystemInfo.h" #import "OFApplication.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFOnce.h" #import "OFString.h" #import "OFNotImplementedException.h" #if defined(OF_MACOS) || defined(OF_IOS) # ifdef HAVE_SYSDIR_H # include <sysdir.h> # endif #endif #ifdef OF_WINDOWS # include <windows.h> |
︙ | ︙ | |||
87 88 89 90 91 92 93 | extern NSSearchPathEnumerationState NSStartSearchPathEnumeration( NSSearchPathDirectory, NSSearchPathDomainMask); extern NSSearchPathEnumerationState NSGetNextSearchPathEnumeration( NSSearchPathEnumerationState, char *); #endif #if defined(OF_X86_64) || defined(OF_X86) | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | extern NSSearchPathEnumerationState NSStartSearchPathEnumeration( NSSearchPathDirectory, NSSearchPathDomainMask); extern NSSearchPathEnumerationState NSGetNextSearchPathEnumeration( NSSearchPathEnumerationState, char *); #endif #if defined(OF_X86_64) || defined(OF_X86) struct X86Regs { uint32_t eax, ebx, ecx, edx; }; #endif static size_t pageSize = 4096; static size_t numberOfCPUs = 1; static OFString *operatingSystemName = nil; |
︙ | ︙ | |||
160 161 162 163 164 165 166 | } # endif #elif defined(OF_WINDOWS) # ifdef OF_HAVE_FILES void *pool = objc_autoreleasePoolPush(); @try { | | | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | } # endif #elif defined(OF_WINDOWS) # ifdef OF_HAVE_FILES void *pool = objc_autoreleasePoolPush(); @try { OFStringEncoding encoding = [OFLocale encoding]; char systemDir[PATH_MAX]; UINT systemDirLen; OFString *systemDirString; const char *path; void *buffer; DWORD bufferLen; |
︙ | ︙ | |||
233 234 235 236 237 238 239 | operatingSystemVersion = [[OFString alloc] initWithCString: utsname.release encoding: [OFLocale encoding]]; #endif } #if defined(OF_X86_64) || defined(OF_X86) | | | | | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | operatingSystemVersion = [[OFString alloc] initWithCString: utsname.release encoding: [OFLocale encoding]]; #endif } #if defined(OF_X86_64) || defined(OF_X86) static OF_INLINE struct X86Regs OF_CONST_FUNC x86CPUID(uint32_t eax, uint32_t ecx) { struct X86Regs regs; # if defined(OF_X86_64) && defined(__GNUC__) __asm__ ( "cpuid" : "=a"(regs.eax), "=b"(regs.ebx), "=c"(regs.ecx), "=d"(regs.edx) : "a"(eax), "c"(ecx) ); |
︙ | ︙ | |||
329 330 331 332 333 334 335 | + (unsigned int)ObjFWVersionMinor { return OBJFW_VERSION_MINOR; } + (OFString *)operatingSystemName { | | | | | | 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | + (unsigned int)ObjFWVersionMinor { return OBJFW_VERSION_MINOR; } + (OFString *)operatingSystemName { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initOperatingSystemName); return operatingSystemName; } + (OFString *)operatingSystemVersion { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initOperatingSystemVersion); return operatingSystemVersion; } #ifdef OF_HAVE_FILES + (OFString *)userDataPath { |
︙ | ︙ | |||
386 387 388 389 390 391 392 | OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; | | | 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; [path deleteCharactersInRange: OFRangeMake(0, 1)]; [path prependString: home]; } [path makeImmutable]; return path; # elif defined(OF_WINDOWS) |
︙ | ︙ | |||
478 479 480 481 482 483 484 | OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; | | < | 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | OFString *home; if ((home = [env objectForKey: @"HOME"]) == nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; [path deleteCharactersInRange: OFRangeMake(0, 1)]; [path prependString: home]; } [path appendString: @"/Preferences"]; [path makeImmutable]; return path; # elif defined(OF_WINDOWS) OFDictionary *env = [OFApplication environment]; OFString *appData; |
︙ | ︙ | |||
527 528 529 530 531 532 533 | # endif } #endif + (OFString *)CPUVendor { #if (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__) | | | | | | | | | | | | | | | | | | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | # endif } #endif + (OFString *)CPUVendor { #if (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__) struct X86Regs regs = x86CPUID(0, 0); uint32_t buffer[3]; if (regs.eax == 0) return nil; buffer[0] = regs.ebx; buffer[1] = regs.edx; buffer[2] = regs.ecx; return [OFString stringWithCString: (char *)buffer encoding: OFStringEncodingASCII length: 12]; #else return nil; #endif } + (OFString *)CPUModel { #if (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__) uint32_t buffer[12]; size_t i; i = 0; for (uint32_t eax = 0x80000002; eax <= 0x80000004; eax++) { struct X86Regs regs = x86CPUID(eax, 0); buffer[i++] = regs.eax; buffer[i++] = regs.ebx; buffer[i++] = regs.ecx; buffer[i++] = regs.edx; } return [OFString stringWithCString: (char *)buffer encoding: OFStringEncodingASCII]; #elif defined(OF_AMIGAOS4) CONST_STRPTR model, version; GetCPUInfoTags(GCIT_ModelString, &model, GCIT_VersionString, &version, TAG_END); if (version != NULL) return [OFString stringWithFormat: @"%s V%s", model, version]; else return [OFString stringWithCString: model encoding: OFStringEncodingASCII]; #else return nil; #endif } #if defined(OF_X86_64) || defined(OF_X86) + (bool)supportsMMX { return (x86CPUID(1, 0).edx & (1u << 23)); } + (bool)supportsSSE { return (x86CPUID(1, 0).edx & (1u << 25)); } + (bool)supportsSSE2 { return (x86CPUID(1, 0).edx & (1u << 26)); } + (bool)supportsSSE3 { return (x86CPUID(1, 0).ecx & (1u << 0)); } + (bool)supportsSSSE3 { return (x86CPUID(1, 0).ecx & (1u << 9)); } + (bool)supportsSSE41 { return (x86CPUID(1, 0).ecx & (1u << 19)); } + (bool)supportsSSE42 { return (x86CPUID(1, 0).ecx & (1u << 20)); } + (bool)supportsAVX { return (x86CPUID(1, 0).ecx & (1u << 28)); } + (bool)supportsAVX2 { return x86CPUID(0, 0).eax >= 7 && (x86CPUID(7, 0).ebx & (1u << 5)); } + (bool)supportsAESNI { return (x86CPUID(1, 0).ecx & (1u << 25)); } + (bool)supportsSHAExtensions { return (x86CPUID(7, 0).ebx & (1u << 29)); } #endif #if defined(OF_POWERPC) || defined(OF_POWERPC64) + (bool)supportsAltiVec { # if defined(OF_MACOS) |
︙ | ︙ |
Modified src/OFTCPSocket.h from [cdec3df6fd] to [9ae8ba1677].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when the socket connected. * * @param exception An exception which occurred while connecting the socket or * `nil` on success */ typedef void (^OFTCPSocketAsyncConnectBlock)(id _Nullable exception); #endif /** * @protocol OFTCPSocketDelegate OFTCPSocket.h ObjFW/OFTCPSocket.h * * A delegate for OFTCPSocket. */ |
︙ | ︙ | |||
147 148 149 150 151 152 153 | /** * @brief Connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to */ | | < | < | | | | | < | | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | /** * @brief Connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to */ - (void)connectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port; /** * @brief Asynchronously connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param runLoopMode The run loop mode in which to perform the async connect */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode; #ifdef OF_HAVE_BLOCKS /** * @brief Asynchronously connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param block The block to execute once the connection has been established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port block: (OFTCPSocketAsyncConnectBlock)block; /** * @brief Asynchronously connect the OFTCPSocket to the specified destination. * * @param host The host to connect to * @param port The port on the host to connect to * @param runLoopMode The run loop mode in which to perform the async connect * @param block The block to execute once the connection has been established */ - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFTCPSocketAsyncConnectBlock)block; #endif /** * @brief Bind the socket to the specified host and port. * * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end #ifdef __cplusplus extern "C" { #endif extern Class _Nullable OFTLSSocketClass; #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFTCPSocket.m from [d1c99c42fa] to [d37354390e].
︙ | ︙ | |||
9 10 11 12 13 14 15 16 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #define __NO_EXT_QNX | > > > > > | < > > < < | | < | | 9 10 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 55 56 57 58 59 60 61 62 63 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define __NO_EXT_QNX #define _HPUX_ALT_XOPEN_SOCKET_API #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFTCPSocket.h" #import "OFDNSResolver.h" #import "OFData.h" #import "OFDate.h" #import "OFIPSocketAsyncConnector.h" #import "OFRunLoop.h" #import "OFRunLoop+Private.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFString.h" #import "OFTCPSocketSOCKS5Connector.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" #import "OFGetOptionFailedException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFSetOptionFailedException.h" static const OFRunLoopMode connectRunLoopMode = @"OFTCPSocketConnectRunLoopMode"; Class OFTLSSocketClass = Nil; static OFString *defaultSOCKS5Host = nil; static uint16_t defaultSOCKS5Port = 1080; @interface OFTCPSocket () <OFIPSocketAsyncConnecting> @end |
︙ | ︙ | |||
128 129 130 131 132 133 134 | - (void)dealloc { [_SOCKS5Host release]; [super dealloc]; } | | | | | | | | | | < | < | < | < | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | - (void)dealloc { [_SOCKS5Host release]; [super dealloc]; } - (bool)of_createSocketForAddress: (const OFSocketAddress *)address errNo: (int *)errNo { #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if ((_socket = socket(address->sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) { *errNo = OFSocketErrNo(); return false; } #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif return true; } - (bool)of_connectSocketToAddress: (const OFSocketAddress *)address errNo: (int *)errNo { if (_socket == OFInvalidSocketHandle) @throw [OFNotOpenException exceptionWithObject: self]; /* Cast needed for AmigaOS, where the argument is declared non-const */ if (connect(_socket, (struct sockaddr *)&address->sockaddr.sockaddr, address->length) != 0) { *errNo = OFSocketErrNo(); return false; } return true; } - (void)of_closeSocket { closesocket(_socket); _socket = OFInvalidSocketHandle; } - (void)connectToHost: (OFString *)host port: (uint16_t)port { void *pool = objc_autoreleasePoolPush(); id <OFTCPSocketDelegate> delegate = _delegate; OFTCPSocketConnectDelegate *connectDelegate = [[[OFTCPSocketConnectDelegate alloc] init] autorelease]; OFRunLoop *runLoop = [OFRunLoop currentRunLoop]; self.delegate = connectDelegate; [self asyncConnectToHost: host port: port runLoopMode: connectRunLoopMode]; while (!connectDelegate->_done) [runLoop runMode: connectRunLoopMode beforeDate: nil]; /* Cleanup */ [runLoop runMode: connectRunLoopMode beforeDate: [OFDate date]]; if (connectDelegate->_exception != nil) @throw connectDelegate->_exception; self.delegate = delegate; objc_autoreleasePoolPop(pool); } - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port { [self asyncConnectToHost: host port: port runLoopMode: OFDefaultRunLoopMode]; } - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode { void *pool = objc_autoreleasePoolPush(); id <OFTCPSocketDelegate> delegate; if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port |
︙ | ︙ | |||
251 252 253 254 255 256 257 | objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port | | | | | | | 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port block: (OFTCPSocketAsyncConnectBlock)block { [self asyncConnectToHost: host port: port runLoopMode: OFDefaultRunLoopMode block: block]; } - (void)asyncConnectToHost: (OFString *)host port: (uint16_t)port runLoopMode: (OFRunLoopMode)runLoopMode block: (OFTCPSocketAsyncConnectBlock)block { void *pool = objc_autoreleasePoolPush(); id <OFTCPSocketDelegate> delegate = nil; if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if (_SOCKS5Host != nil) { delegate = [[[OFTCPSocketSOCKS5Connector alloc] initWithSocket: self host: host port: port |
︙ | ︙ | |||
293 294 295 296 297 298 299 | block: (delegate == nil ? block : NULL)] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif | | < | | | | | | | | | | | | | | | | | | | | | | | | | 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | block: (delegate == nil ? block : NULL)] autorelease] startWithRunLoopMode: runLoopMode]; objc_autoreleasePoolPop(pool); } #endif - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port { const int one = 1; void *pool = objc_autoreleasePoolPush(); OFData *socketAddresses; OFSocketAddress address; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; if (_SOCKS5Host != nil) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; OFSocketAddressSetPort(&address, port); if ((_socket = socket(address.sockaddr.sockaddr.sa_family, SOCK_STREAM | SOCK_CLOEXEC, 0)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); #endif setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&one, (socklen_t)sizeof(one)); #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) if (port != 0) { #endif if (bind(_socket, &address.sockaddr.sockaddr, address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { for (;;) { uint16_t rnd = 0; int ret; while (rnd < 1024) rnd = (uint16_t)rand(); OFSocketAddressSetPort(&address, rnd); if ((ret = bind(_socket, &address.sockaddr.sockaddr, address.length)) == 0) { port = rnd; break; } if (OFSocketErrNo() != EADDRINUSE) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } } } #endif objc_autoreleasePoolPop(pool); if (port > 0) return port; #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) memset(&address, 0, sizeof(address)); address.length = (socklen_t)sizeof(address.sockaddr); if (OFGetSockName(_socket, &address.sockaddr.sockaddr, &address.length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } if (address.sockaddr.sockaddr.sa_family == AF_INET) return OFFromBigEndian16(address.sockaddr.in.sin_port); # ifdef OF_HAVE_IPV6 else if (address.sockaddr.sockaddr.sa_family == AF_INET6) return OFFromBigEndian16(address.sockaddr.in6.sin6_port); # endif else { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: EADDRNOTAVAIL]; #endif } #if !defined(OF_WII) && !defined(OF_NINTENDO_3DS) - (void)setSendsKeepAlives: (bool)sendsKeepAlives { int v = sendsKeepAlives; if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char *)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; } - (bool)sendsKeepAlives { int v; socklen_t len = sizeof(v); if (getsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char *)&v, &len) != 0 || len != sizeof(v)) @throw [OFGetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; return v; } #endif #ifndef OF_WII - (void)setCanDelaySendingSegments: (bool)canDelaySendingSegments { int v = !canDelaySendingSegments; if (setsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&v, (socklen_t)sizeof(v)) != 0) @throw [OFSetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; } - (bool)canDelaySendingSegments { int v; socklen_t len = sizeof(v); if (getsockopt(_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&v, &len) != 0 || len != sizeof(v)) @throw [OFGetOptionFailedException exceptionWithObject: self errNo: OFSocketErrNo()]; return !v; } #endif - (void)close { |
︙ | ︙ |
Modified src/OFTCPSocketSOCKS5Connector.h from [edab2535a4] to [a3decd0834].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @interface OFTCPSocketSOCKS5Connector: OFObject <OFTCPSocketDelegate> { OFTCPSocket *_socket; OFString *_host; uint16_t _port; id <OFTCPSocketDelegate> _Nullable _delegate; #ifdef OF_HAVE_BLOCKS | | < < < < < < < | | < | 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 | @interface OFTCPSocketSOCKS5Connector: OFObject <OFTCPSocketDelegate> { OFTCPSocket *_socket; OFString *_host; uint16_t _port; id <OFTCPSocketDelegate> _Nullable _delegate; #ifdef OF_HAVE_BLOCKS OFTCPSocketAsyncConnectBlock _Nullable _block; #endif id _Nullable _exception; uint_least8_t _SOCKS5State; /* Longest read is domain name (max 255 bytes) + port */ unsigned char _buffer[257]; OFMutableData *_Nullable _request; } - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port delegate: (nullable id <OFTCPSocketDelegate>)delegate #ifdef OF_HAVE_BLOCKS block: (nullable OFTCPSocketAsyncConnectBlock)block #endif ; - (void)didConnect; @end OF_ASSUME_NONNULL_END |
Modified src/OFTCPSocketSOCKS5Connector.m from [9fddf9f0fe] to [cef61681e6].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFTCPSocketSOCKS5Connector.h" #import "OFData.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFConnectionFailedException.h" @implementation OFTCPSocketSOCKS5Connector - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port delegate: (id <OFTCPSocketDelegate>)delegate #ifdef OF_HAVE_BLOCKS | > > > > > > > > > | | 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 | #import "OFTCPSocketSOCKS5Connector.h" #import "OFData.h" #import "OFRunLoop.h" #import "OFString.h" #import "OFConnectionFailedException.h" enum { stateSendAuthentication = 1, stateReadVersion, stateSendRequest, stateReadResponse, stateReadAddress, stateReadAddressLength, }; @implementation OFTCPSocketSOCKS5Connector - (instancetype)initWithSocket: (OFTCPSocket *)sock host: (OFString *)host port: (uint16_t)port delegate: (id <OFTCPSocketDelegate>)delegate #ifdef OF_HAVE_BLOCKS block: (OFTCPSocketAsyncConnectBlock)block #endif { self = [super init]; @try { _socket = [sock retain]; _host = [host copy]; |
︙ | ︙ | |||
78 79 80 81 82 83 84 | #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_exception); else { #endif if ([_delegate respondsToSelector: @selector(socket:didConnectToHost:port:exception:)]) | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(_exception); else { #endif if ([_delegate respondsToSelector: @selector(socket:didConnectToHost:port:exception:)]) [_delegate socket: _socket didConnectToHost: _host port: _port exception: _exception]; #ifdef OF_HAVE_BLOCKS } #endif } |
︙ | ︙ | |||
100 101 102 103 104 105 106 | if (exception != nil) { _exception = [exception retain]; [self didConnect]; return; } | | < | | | | < | < | < | | < | | 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | if (exception != nil) { _exception = [exception retain]; [self didConnect]; return; } data = [OFData dataWithItems: "\x05\x01\x00" count: 3]; _SOCKS5State = stateSendAuthentication; [_socket asyncWriteData: data runLoopMode: [OFRunLoop currentRunLoop].currentMode]; } - (bool)stream: (OFStream *)sock didReadIntoBuffer: (void *)buffer length: (size_t)length exception: (id)exception { OFRunLoopMode runLoopMode; unsigned char *SOCKSVersion; uint8_t hostLength; unsigned char port[2]; unsigned char *response, *addressLength; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return false; } runLoopMode = [OFRunLoop currentRunLoop].currentMode; switch (_SOCKS5State) { case stateReadVersion: SOCKSVersion = buffer; if (SOCKSVersion[0] != 5 || SOCKSVersion[1] != 0) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; return false; } [_request release]; _request = [[OFMutableData alloc] init]; [_request addItems: "\x05\x01\x00\x03" count: 4]; hostLength = (uint8_t)_host.UTF8StringLength; [_request addItem: &hostLength]; [_request addItems: _host.UTF8String count: hostLength]; port[0] = _port >> 8; port[1] = _port & 0xFF; [_request addItems: port count: 2]; _SOCKS5State = stateSendRequest; [_socket asyncWriteData: _request runLoopMode: runLoopMode]; return false; case stateReadResponse: response = buffer; if (response[0] != 5 || response[2] != 0) { _exception = [[OFConnectionFailedException alloc] initWithHost: _host port: _port socket: self |
︙ | ︙ | |||
220 221 222 223 224 225 226 | [self didConnect]; return false; } /* Skip the rest of the response */ switch (response[3]) { case 1: /* IPv4 */ | | | | | | | | | | | | | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | [self didConnect]; return false; } /* Skip the rest of the response */ switch (response[3]) { case 1: /* IPv4 */ _SOCKS5State = stateReadAddress; [_socket asyncReadIntoBuffer: _buffer exactLength: 4 + 2 runLoopMode: runLoopMode]; return false; case 3: /* Domain name */ _SOCKS5State = stateReadAddressLength; [_socket asyncReadIntoBuffer: _buffer exactLength: 1 runLoopMode: runLoopMode]; return false; case 4: /* IPv6 */ _SOCKS5State = stateReadAddress; [_socket asyncReadIntoBuffer: _buffer exactLength: 16 + 2 runLoopMode: runLoopMode]; return false; default: _exception = [[OFConnectionFailedException alloc] initWithHost: _host port: _port socket: self errNo: EPROTONOSUPPORT]; [self didConnect]; return false; } return false; case stateReadAddress: [self didConnect]; return false; case stateReadAddressLength: addressLength = buffer; _SOCKS5State = stateReadAddress; [_socket asyncReadIntoBuffer: _buffer exactLength: addressLength[0] + 2 runLoopMode: runLoopMode]; return false; default: assert(0); return false; } } - (OFData *)stream: (OFStream *)sock didWriteData: (OFData *)data bytesWritten: (size_t)bytesWritten exception: (id)exception { OFRunLoopMode runLoopMode; if (exception != nil) { _exception = [exception retain]; [self didConnect]; return nil; } runLoopMode = [OFRunLoop currentRunLoop].currentMode; switch (_SOCKS5State) { case stateSendAuthentication: _SOCKS5State = stateReadVersion; [_socket asyncReadIntoBuffer: _buffer exactLength: 2 runLoopMode: runLoopMode]; return nil; case stateSendRequest: [_request release]; _request = nil; _SOCKS5State = stateReadResponse; [_socket asyncReadIntoBuffer: _buffer exactLength: 4 runLoopMode: runLoopMode]; return nil; default: assert(0); return nil; } } @end |
Renamed and modified src/tlskey.h [d958bbae58] to src/OFTLSKey.h [befb515045].
︙ | ︙ | |||
24 25 26 27 28 29 30 | # error No thread-local storage available! #endif #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | # error No thread-local storage available! #endif #import "macros.h" #if defined(OF_HAVE_PTHREADS) # include <pthread.h> typedef pthread_key_t OFTLSKey; #elif defined(OF_WINDOWS) # include <windows.h> typedef DWORD OFTLSKey; #elif defined(OF_MORPHOS) # include <proto/exec.h> typedef ULONG OFTLSKey; #elif defined(OF_AMIGAOS) typedef struct _OFTLSKey { struct objc_hashtable *table; struct _OFTLSKey *next, *previous; } *OFTLSKey; #endif #ifdef __cplusplus extern "C" { #endif extern int OFTLSKeyNew(OFTLSKey *key); extern int OFTLSKeyFree(OFTLSKey key); #ifdef __cplusplus } #endif /* TLS keys are inlined for performance. */ #if defined(OF_HAVE_PTHREADS) static OF_INLINE void * OFTLSKeyGet(OFTLSKey key) { return pthread_getspecific(key); } static OF_INLINE int OFTLSKeySet(OFTLSKey key, void *ptr) { return pthread_setspecific(key, ptr); } #elif defined(OF_WINDOWS) static OF_INLINE void * OFTLSKeyGet(OFTLSKey key) { return TlsGetValue(key); } static OF_INLINE int OFTLSKeySet(OFTLSKey key, void *ptr) { return (TlsSetValue(key, ptr) ? 0 : EINVAL); } #elif defined(OF_MORPHOS) static OF_INLINE void * OFTLSKeyGet(OFTLSKey key) { return (void *)TLSGetValue(key); } static OF_INLINE int OFTLSKeySet(OFTLSKey key, void *ptr) { return (TLSSetValue(key, (APTR)ptr) ? 0 : EINVAL); } #elif defined(OF_AMIGAOS) /* Those are too big too inline. */ # ifdef __cplusplus extern "C" { # endif extern void *OFTLSKeyGet(OFTLSKey key); extern int OFTLSKeySet(OFTLSKey key, void *ptr); # ifdef __cplusplus } # endif #endif |
Renamed and modified src/tlskey.m [d602541981] to src/OFTLSKey.m [d2717c869a].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) | | | | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | */ #include "config.h" #include "platform.h" #if defined(OF_HAVE_PTHREADS) # include "platform/POSIX/OFTLSKey.m" #elif defined(OF_WINDOWS) # include "platform/Windows/OFTLSKey.m" #elif defined(OF_MORPHOS) # include "platform/MorphOs/OFTLSKey.m" #elif defined(OF_AMIGAOS) # include "platform/AmigaOS/OFTLSKey.m" #endif |
Modified src/OFTarArchive.h from [4162b0edcc] to [0ba5d85fe3].
︙ | ︙ | |||
27 28 29 30 31 32 33 | * * @brief A class for accessing and manipulating tar archives. */ OF_SUBCLASSING_RESTRICTED @interface OFTarArchive: OFObject { OFStream *_stream; | | | | | | | | 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 | * * @brief A class for accessing and manipulating tar archives. */ OF_SUBCLASSING_RESTRICTED @interface OFTarArchive: OFObject { OFStream *_stream; enum OFTarArchiveMode { OFTarArchiveModeRead, OFTarArchiveModeWrite, OFTarArchiveModeAppend } _mode; OFStringEncoding _encoding; OFStream *_Nullable _lastReturnedStream; } /** * @brief The encoding to use for the archive. Defaults to UTF-8. */ @property (nonatomic) OFStringEncoding encoding; /** * @brief A stream for reading the current entry. * * @note This is only available in read mode. * * @note The returned stream conforms to @ref OFReadyForReadingObserving if the |
︙ | ︙ | |||
61 62 63 64 65 66 67 | * @param stream A stream from which the tar archive will be read. * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive */ | | < | < | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | * @param stream A stream from which the tar archive will be read. * For append mode, this needs to be an OFSeekableStream. * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; #ifdef OF_HAVE_FILES /** * @brief Creates a new OFTarArchive object with the specified file. * * @param path The path to the tar archive * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFTarArchive */ + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFTarArchive object with the * specified stream. |
︙ | ︙ | |||
105 106 107 108 109 110 111 | * * @param path The path to the tar archive * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFTarArchive */ | | < | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | * * @param path The path to the tar archive * @param mode The mode for the tar file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFTarArchive */ - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; #endif /** * @brief Returns the next entry from the tar archive or `nil` if all entries * have been read. * * @note This is only available in read mode. |
︙ | ︙ |
Modified src/OFTarArchive.m from [a40561e369] to [6412c1538f].
︙ | ︙ | |||
57 58 59 60 61 62 63 | - (instancetype)of_initWithStream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry; @end @implementation OFTarArchive: OFObject @synthesize encoding = _encoding; | | < | < | < | < | < | | | | | < | | < | < | < | < | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | - (instancetype)of_initWithStream: (OFStream *)stream entry: (OFTarArchiveEntry *)entry; @end @implementation OFTarArchive: OFObject @synthesize encoding = _encoding; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode { return [[[self alloc] initWithPath: path mode: mode] autorelease]; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { _stream = [stream retain]; if ([mode isEqual: @"r"]) _mode = OFTarArchiveModeRead; else if ([mode isEqual: @"w"]) _mode = OFTarArchiveModeWrite; else if ([mode isEqual: @"a"]) _mode = OFTarArchiveModeAppend; else @throw [OFInvalidArgumentException exception]; if (_mode == OFTarArchiveModeAppend) { uint32_t buffer[1024 / sizeof(uint32_t)]; bool empty = true; if (![_stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; [(OFSeekableStream *)_stream seekToOffset: -1024 whence: SEEK_END]; [_stream readIntoBuffer: buffer exactLength: 1024]; for (size_t i = 0; i < 1024 / sizeof(uint32_t); i++) if (buffer[i] != 0) empty = false; if (!empty) @throw [OFInvalidFormatException exception]; [(OFSeekableStream *)stream seekToOffset: -1024 whence: SEEK_END]; } _encoding = OFStringEncodingUTF8; } @catch (id e) { [self release]; @throw e; } return self; } #ifdef OF_HAVE_FILES - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode { OFFile *file; if ([mode isEqual: @"a"]) file = [[OFFile alloc] initWithPath: path mode: @"r+"]; else file = [[OFFile alloc] initWithPath: path mode: mode]; @try { self = [self initWithStream: file mode: mode]; } @finally { [file release]; } return self; } #endif |
︙ | ︙ | |||
164 165 166 167 168 169 170 | - (OFTarArchiveEntry *)nextEntry { OFTarArchiveEntry *entry; uint32_t buffer[512 / sizeof(uint32_t)]; bool empty = true; | | | < | < | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | - (OFTarArchiveEntry *)nextEntry { OFTarArchiveEntry *entry; uint32_t buffer[512 / sizeof(uint32_t)]; bool empty = true; if (_mode != OFTarArchiveModeRead) @throw [OFInvalidArgumentException exception]; [(OFTarArchiveFileReadStream *)_lastReturnedStream of_skip]; @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } [_lastReturnedStream release]; _lastReturnedStream = nil; if (_stream.atEndOfStream) return nil; [_stream readIntoBuffer: buffer exactLength: 512]; for (size_t i = 0; i < 512 / sizeof(uint32_t); i++) if (buffer[i] != 0) empty = false; if (empty) { [_stream readIntoBuffer: buffer exactLength: 512]; for (size_t i = 0; i < 512 / sizeof(uint32_t); i++) if (buffer[i] != 0) @throw [OFInvalidFormatException exception]; return nil; } |
︙ | ︙ | |||
210 211 212 213 214 215 216 | entry: entry]; return entry; } - (OFStream *)streamForReadingCurrentEntry { | | | < | < | 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | entry: entry]; return entry; } - (OFStream *)streamForReadingCurrentEntry { if (_mode != OFTarArchiveModeRead) @throw [OFInvalidArgumentException exception]; if (_lastReturnedStream == nil) @throw [OFInvalidArgumentException exception]; return [[(OFTarArchiveFileReadStream *)_lastReturnedStream retain] autorelease]; } - (OFStream *)streamForWritingEntry: (OFTarArchiveEntry *)entry { void *pool; if (_mode != OFTarArchiveModeWrite && _mode != OFTarArchiveModeAppend) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } [_lastReturnedStream release]; _lastReturnedStream = nil; [entry of_writeToStream: _stream encoding: _encoding]; _lastReturnedStream = [[OFTarArchiveFileWriteStream alloc] of_initWithStream: _stream entry: entry]; objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
264 265 266 267 268 269 270 | [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } [_lastReturnedStream release]; _lastReturnedStream = nil; | | < | < | 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } [_lastReturnedStream release]; _lastReturnedStream = nil; if (_mode == OFTarArchiveModeWrite || _mode == OFTarArchiveModeAppend) { char buffer[1024]; memset(buffer, '\0', 1024); [_stream writeBuffer: buffer length: 1024]; } [_stream release]; _stream = nil; } @end |
︙ | ︙ | |||
324 325 326 327 328 329 330 | if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif if ((uint64_t)length > _toRead) length = (size_t)_toRead; | | < < | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif if ((uint64_t)length > _toRead) length = (size_t)_toRead; ret = [_stream readIntoBuffer: buffer length: length]; if (ret == 0) _atEndOfStream = true; _toRead -= ret; return ret; } |
︙ | ︙ | |||
373 374 375 376 377 378 379 | - (void)of_skip { if (_stream == nil || _skipped) return; if ([_stream isKindOfClass: [OFSeekableStream class]] && | | | | < | 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | - (void)of_skip { if (_stream == nil || _skipped) return; if ([_stream isKindOfClass: [OFSeekableStream class]] && _toRead <= INT64_MAX && (OFFileOffset)_toRead == (int64_t)_toRead) { uint64_t size; [(OFSeekableStream *)_stream seekToOffset: (OFFileOffset)_toRead whence: SEEK_CUR]; _toRead = 0; size = _entry.size; if (size % 512 != 0) [(OFSeekableStream *)_stream seekToOffset: 512 - (size % 512) whence: SEEK_CUR]; } else { char buffer[512]; uint64_t size; while (_toRead >= 512) { [_stream readIntoBuffer: buffer exactLength: 512]; _toRead -= 512; } if (_toRead > 0) { [_stream readIntoBuffer: buffer exactLength: (size_t)_toRead]; _toRead = 0; |
︙ | ︙ | |||
442 443 444 445 446 447 448 | [self close]; [_entry release]; [super dealloc]; } | | < | 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | [self close]; [_entry release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { size_t bytesWritten; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if ((uint64_t)length > _toWrite) |
︙ | ︙ |
Modified src/OFTarArchiveEntry+Private.h from [e07f2ba876] to [929bab9877].
︙ | ︙ | |||
19 20 21 22 23 24 25 | OF_ASSUME_NONNULL_BEGIN @class OFStream; OF_DIRECT_MEMBERS @interface OFTarArchiveEntry () - (instancetype)of_initWithHeader: (unsigned char [_Nonnull 512])header | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | OF_ASSUME_NONNULL_BEGIN @class OFStream; OF_DIRECT_MEMBERS @interface OFTarArchiveEntry () - (instancetype)of_initWithHeader: (unsigned char [_Nonnull 512])header encoding: (OFStringEncoding)encoding OF_METHOD_FAMILY(init); - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding; @end OF_ASSUME_NONNULL_END |
Modified src/OFTarArchiveEntry.h from [e9a73505d7] to [933ac56d6f].
︙ | ︙ | |||
20 21 22 23 24 25 26 | /** @file */ @class OFDate; /** * @brief The type of the archive entry. */ | | | | | | | | | | | | | 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 61 62 63 64 65 | /** @file */ @class OFDate; /** * @brief The type of the archive entry. */ typedef enum { /** Normal file */ OFTarArchiveEntryTypeFile = '0', /** Hard link */ OFTarArchiveEntryTypeLink = '1', /** Symbolic link */ OFTarArchiveEntryTypeSymlink = '2', /** Character device */ OFTarArchiveEntryTypeCharacterDevice = '3', /** Block device */ OFTarArchiveEntryTypeBlockDevice = '4', /** Directory */ OFTarArchiveEntryTypeDirectory = '5', /** FIFO */ OFTarArchiveEntryTypeFIFO = '6', /** Contiguous file */ OFTarArchiveEntryTypeContiguousFile = '7', } OFTarArchiveEntryType; /** * @class OFTarArchiveEntry OFTarArchiveEntry.h ObjFW/OFTarArchiveEntry.h * * @brief A class which represents an entry of a tar archive. */ @interface OFTarArchiveEntry: OFObject <OFCopying, OFMutableCopying> { OFString *_fileName; unsigned long _mode; unsigned long long _size; unsigned long _UID, _GID; OFDate *_modificationDate; OFTarArchiveEntryType _type; OFString *_Nullable _targetFileName; OFString *_Nullable _owner, *_Nullable _group; unsigned long _deviceMajor, _deviceMinor; OF_RESERVE_IVARS(OFTarArchiveEntry, 4) } /** |
︙ | ︙ | |||
91 92 93 94 95 96 97 | * @brief The date of the last modification of the file. */ @property (readonly, retain, nonatomic) OFDate *modificationDate; /** * @brief The type of the archive entry. * | | | | 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | * @brief The date of the last modification of the file. */ @property (readonly, retain, nonatomic) OFDate *modificationDate; /** * @brief The type of the archive entry. * * See @ref OFTarArchiveEntryType. */ @property (readonly, nonatomic) OFTarArchiveEntryType type; /** * @brief The file name of the target (for a hard link or symbolic link). */ @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFString *targetFileName; |
︙ | ︙ |
Modified src/OFTarArchiveEntry.m from [e22a0061ae] to [4eb33d5a79].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "OFStream.h" #import "OFString.h" #import "OFOutOfRangeException.h" static OFString * stringFromBuffer(const unsigned char *buffer, size_t length, | | | | 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 | #import "OFStream.h" #import "OFString.h" #import "OFOutOfRangeException.h" static OFString * stringFromBuffer(const unsigned char *buffer, size_t length, OFStringEncoding encoding) { for (size_t i = 0; i < length; i++) if (buffer[i] == '\0') length = i; return [OFString stringWithCString: (const char *)buffer encoding: encoding length: length]; } static void stringToBuffer(unsigned char *buffer, OFString *string, size_t length, OFStringEncoding encoding) { size_t cStringLength = [string cStringLengthWithEncoding: encoding]; if (cStringLength > length) @throw [OFOutOfRangeException exception]; memcpy(buffer, [string cStringWithEncoding: encoding], cStringLength); |
︙ | ︙ | |||
61 62 63 64 65 66 67 | return 0; if (buffer[0] == 0x80) { for (size_t i = 1; i < length; i++) value = (value << 8) | buffer[i]; } else value = [stringFromBuffer(buffer, length, | | | | | | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | return 0; if (buffer[0] == 0x80) { for (size_t i = 1; i < length; i++) value = (value << 8) | buffer[i]; } else value = [stringFromBuffer(buffer, length, OFStringEncodingASCII) unsignedLongLongValueWithBase: 8]; if (value > max) @throw [OFOutOfRangeException exception]; return value; } @implementation OFTarArchiveEntry + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithHeader: (unsigned char [512])header encoding: (OFStringEncoding)encoding { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFString *targetFileName; _fileName = [stringFromBuffer(header, 100, encoding) copy]; _mode = (unsigned long)octalValueFromBuffer( header + 100, 8, ULONG_MAX); _UID = (unsigned long)octalValueFromBuffer( header + 108, 8, ULONG_MAX); _GID = (unsigned long)octalValueFromBuffer( header + 116, 8, ULONG_MAX); _size = (unsigned long long)octalValueFromBuffer( header + 124, 12, ULLONG_MAX); _modificationDate = [[OFDate alloc] initWithTimeIntervalSince1970: (OFTimeInterval)octalValueFromBuffer( header + 136, 12, ULLONG_MAX)]; _type = header[156]; targetFileName = stringFromBuffer(header + 157, 100, encoding); if (targetFileName.length > 0) _targetFileName = [targetFileName copy]; if (_type == '\0') _type = OFTarArchiveEntryTypeFile; if (memcmp(header + 257, "ustar\0" "00", 8) == 0) { OFString *prefix; _owner = [stringFromBuffer(header + 265, 32, encoding) copy]; _group = [stringFromBuffer(header + 297, 32, encoding) |
︙ | ︙ | |||
149 150 151 152 153 154 155 | - (instancetype)initWithFileName: (OFString *)fileName { self = [super init]; @try { _fileName = [fileName copy]; | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | - (instancetype)initWithFileName: (OFString *)fileName { self = [super init]; @try { _fileName = [fileName copy]; _type = OFTarArchiveEntryTypeFile; _mode = 0644; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ | |||
228 229 230 231 232 233 234 | } - (OFDate *)modificationDate { return _modificationDate; } | | | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | } - (OFDate *)modificationDate { return _modificationDate; } - (OFTarArchiveEntryType)type { return _type; } - (OFString *)targetFileName { return _targetFileName; |
︙ | ︙ | |||
286 287 288 289 290 291 292 | objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)of_writeToStream: (OFStream *)stream | | | | | | | | | | | < | 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)of_writeToStream: (OFStream *)stream encoding: (OFStringEncoding)encoding { unsigned char buffer[512]; unsigned long long modificationDate; uint16_t checksum = 0; stringToBuffer(buffer, _fileName, 100, encoding); stringToBuffer(buffer + 100, [OFString stringWithFormat: @"%06" PRIo16 " ", _mode], 8, OFStringEncodingASCII); stringToBuffer(buffer + 108, [OFString stringWithFormat: @"%06" PRIo16 " ", _UID], 8, OFStringEncodingASCII); stringToBuffer(buffer + 116, [OFString stringWithFormat: @"%06" PRIo16 " ", _GID], 8, OFStringEncodingASCII); stringToBuffer(buffer + 124, [OFString stringWithFormat: @"%011" PRIo64 " ", _size], 12, OFStringEncodingASCII); modificationDate = _modificationDate.timeIntervalSince1970; stringToBuffer(buffer + 136, [OFString stringWithFormat: @"%011llo", modificationDate], 12, OFStringEncodingASCII); /* * During checksumming, the checksum field is expected to be set to 8 * spaces. */ memset(buffer + 148, ' ', 8); buffer[156] = _type; stringToBuffer(buffer + 157, _targetFileName, 100, encoding); /* ustar */ memcpy(buffer + 257, "ustar\0" "00", 8); stringToBuffer(buffer + 265, _owner, 32, encoding); stringToBuffer(buffer + 297, _group, 32, encoding); stringToBuffer(buffer + 329, [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMajor], 8, OFStringEncodingASCII); stringToBuffer(buffer + 337, [OFString stringWithFormat: @"%06" PRIo32 " ", _deviceMinor], 8, OFStringEncodingASCII); memset(buffer + 345, '\0', 155 + 12); /* Fill in the checksum */ for (size_t i = 0; i < 500; i++) checksum += buffer[i]; stringToBuffer(buffer + 148, [OFString stringWithFormat: @"%06" PRIo16, checksum], 7, OFStringEncodingASCII); [stream writeBuffer: buffer length: sizeof(buffer)]; } @end |
Modified src/OFThread.h from [f4a6bc3a11] to [1a5414b6ff].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include <setjmp.h> #import "OFObject.h" | < | | | 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 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include <setjmp.h> #import "OFObject.h" #ifdef OF_HAVE_THREADS # import "OFPlainThread.h" #endif OF_ASSUME_NONNULL_BEGIN /** @file */ @class OFDate; #ifdef OF_HAVE_SOCKETS @class OFDNSResolver; #endif @class OFRunLoop; @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); #if defined(OF_HAVE_THREADS) && defined(OF_HAVE_BLOCKS) /** * @brief A block to be executed in a new thread. * * @return The object which should be returned when the thread is joined */ typedef id _Nullable (^OFThreadBlock)(void); #endif /** * @class OFThread OFThread.h ObjFW/OFThread.h * * @brief A class which provides portable threads. * |
︙ | ︙ | |||
60 61 62 63 64 65 66 | * so context can be associated with a thread. */ @interface OFThread: OFObject #ifdef OF_HAVE_THREADS <OFCopying> { @private | | | | | | | | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | * so context can be associated with a thread. */ @interface OFThread: OFObject #ifdef OF_HAVE_THREADS <OFCopying> { @private OFPlainThread _thread; OFPlainThreadAttributes _attr; enum OFThreadState { OFThreadStateNotRunning, OFThreadStateRunning, OFThreadStateWaitingForJoin } _running; # ifndef OF_OBJFW_RUNTIME void *_pool; # endif # ifdef OF_HAVE_BLOCKS OFThreadBlock _Nullable _threadBlock; # endif jmp_buf _exitEnv; id _returnValue; bool _supportsSockets; OFRunLoop *_Nullable _runLoop; OFMutableDictionary *_threadDictionary; OFString *_Nullable _name; |
︙ | ︙ | |||
115 116 117 118 119 120 121 | */ @property OF_NULLABLE_PROPERTY (copy) OFString *name; # ifdef OF_HAVE_BLOCKS /** * @brief The block to execute in the thread. */ | | < | 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | */ @property OF_NULLABLE_PROPERTY (copy) OFString *name; # ifdef OF_HAVE_BLOCKS /** * @brief The block to execute in the thread. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFThreadBlock threadBlock; # endif /** * @brief The run loop for the thread. */ @property (readonly, nonatomic) OFRunLoop *runLoop; |
︙ | ︙ | |||
165 166 167 168 169 170 171 | # ifdef OF_HAVE_BLOCKS /** * @brief Creates a new thread with the specified block. * * @param threadBlock A block which is executed by the thread * @return A new, autoreleased thread */ | | | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | # ifdef OF_HAVE_BLOCKS /** * @brief Creates a new thread with the specified block. * * @param threadBlock A block which is executed by the thread * @return A new, autoreleased thread */ + (instancetype)threadWithThreadBlock: (OFThreadBlock)threadBlock; # endif /** * @brief Returns the current thread. * * @return The current thread */ |
︙ | ︙ | |||
213 214 215 216 217 218 219 | /** * @brief Suspends execution of the current thread for the specified time * interval. * * @param timeInterval The number of seconds to sleep */ | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | /** * @brief Suspends execution of the current thread for the specified time * interval. * * @param timeInterval The number of seconds to sleep */ + (void)sleepForTimeInterval: (OFTimeInterval)timeInterval; /** * @brief Suspends execution of the current thread until the specified date. * * @param date The date to wait for */ + (void)sleepUntilDate: (OFDate *)date; |
︙ | ︙ | |||
265 266 267 268 269 270 271 | # ifdef OF_HAVE_BLOCKS /** * @brief Initializes an already allocated thread with the specified block. * * @param threadBlock A block which is executed by the thread * @return An initialized OFThread. */ | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | # ifdef OF_HAVE_BLOCKS /** * @brief Initializes an already allocated thread with the specified block. * * @param threadBlock A block which is executed by the thread * @return An initialized OFThread. */ - (instancetype)initWithThreadBlock: (OFThreadBlock)threadBlock; # endif /** * @brief The main routine of the thread. You need to reimplement this! * * @return The object the join method should return when called for this thread */ |
︙ | ︙ |
Modified src/OFThread.m from [9da78353a7] to [b51d41216b].
︙ | ︙ | |||
44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #ifdef OF_NINTENDO_3DS # include <3ds/svc.h> #endif #import "OFThread.h" #import "OFThread+Private.h" #import "OFDate.h" #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFDNSResolver.h" #endif #import "OFLocale.h" #import "OFRunLoop.h" | > > > | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | #ifdef OF_NINTENDO_3DS # include <3ds/svc.h> #endif #import "OFThread.h" #import "OFThread+Private.h" #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #import "OFDate.h" #import "OFDictionary.h" #ifdef OF_HAVE_SOCKETS # import "OFDNSResolver.h" #endif #import "OFLocale.h" #import "OFRunLoop.h" |
︙ | ︙ | |||
73 74 75 76 77 78 79 | #import "OFOutOfRangeException.h" #ifdef OF_HAVE_THREADS # import "OFThreadJoinFailedException.h" # import "OFThreadStartFailedException.h" # import "OFThreadStillRunningException.h" #endif | < < < < | | | | | | | | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | #import "OFOutOfRangeException.h" #ifdef OF_HAVE_THREADS # import "OFThreadJoinFailedException.h" # import "OFThreadStartFailedException.h" # import "OFThreadStillRunningException.h" #endif #if defined(OF_HAVE_THREADS) # import "OFTLSKey.h" # if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS) # import "OFSocket.h" # endif static OFTLSKey threadSelfKey; static OFThread *mainThread; #elif defined(OF_HAVE_SOCKETS) static OFDNSResolver *DNSResolver; #endif @implementation OFThread #ifdef OF_HAVE_THREADS static void callMain(id object) { OFThread *thread = (OFThread *)object; OFString *name; if (OFTLSKeySet(threadSelfKey, thread) != 0) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; #ifndef OF_OBJFW_RUNTIME thread->_pool = objc_autoreleasePoolPush(); #endif name = thread.name; if (name != nil) OFSetThreadName( [name cStringWithEncoding: [OFLocale encoding]]); else OFSetThreadName(object_getClassName(thread)); #if defined(OF_AMIGAOS) && defined(OF_HAVE_SOCKETS) if (thread.supportsSockets) if (!OFSocketInit()) @throw [OFInitializationFailedException exceptionWithClass: thread.class]; #endif /* * Nasty workaround for thread implementations which can't return a * pointer on join, or don't have a way to exit a thread. |
︙ | ︙ | |||
142 143 144 145 146 147 148 | objc_autoreleasePoolPop((void *)(uintptr_t)-1); #else objc_autoreleasePoolPop(thread->_pool); #endif #if defined(OF_AMIGAOS) && !defined(OF_MORPHOS) && defined(OF_HAVE_SOCKETS) if (thread.supportsSockets) | | | | | | | | | | | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | objc_autoreleasePoolPop((void *)(uintptr_t)-1); #else objc_autoreleasePoolPop(thread->_pool); #endif #if defined(OF_AMIGAOS) && !defined(OF_MORPHOS) && defined(OF_HAVE_SOCKETS) if (thread.supportsSockets) OFSocketDeinit(); #endif thread->_running = OFThreadStateWaitingForJoin; [thread release]; } @synthesize name = _name; # ifdef OF_HAVE_BLOCKS @synthesize threadBlock = _threadBlock; # endif + (void)initialize { if (self != [OFThread class]) return; if (OFTLSKeyNew(&threadSelfKey) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } + (instancetype)thread { return [[[self alloc] init] autorelease]; } # ifdef OF_HAVE_BLOCKS + (instancetype)threadWithThreadBlock: (OFThreadBlock)threadBlock { return [[[self alloc] initWithThreadBlock: threadBlock] autorelease]; } # endif + (OFThread *)currentThread { return OFTLSKeyGet(threadSelfKey); } + (OFThread *)mainThread { return mainThread; } + (bool)isMainThread { if (mainThread == nil) return false; return (OFTLSKeyGet(threadSelfKey) == mainThread); } + (OFMutableDictionary *)threadDictionary { OFThread *thread = OFTLSKeyGet(threadSelfKey); if (thread == nil) return nil; if (thread->_threadDictionary == nil) thread->_threadDictionary = [[OFMutableDictionary alloc] init]; return thread->_threadDictionary; } #endif #ifdef OF_HAVE_SOCKETS + (OFDNSResolver *)DNSResolver { # ifdef OF_HAVE_THREADS OFThread *thread = OFTLSKeyGet(threadSelfKey); if (thread == nil) return nil; if (thread->_DNSResolver == nil) thread->_DNSResolver = [[OFDNSResolver alloc] init]; return thread->_DNSResolver; # else if (DNSResolver == nil) DNSResolver = [[OFDNSResolver alloc] init]; return DNSResolver; # endif } #endif + (void)sleepForTimeInterval: (OFTimeInterval)timeInterval { if (timeInterval < 0) return; #if defined(OF_WINDOWS) if (timeInterval * 1000 > UINT_MAX) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
315 316 317 318 319 320 321 | * returns while being declared OF_NO_RETURN. */ OF_UNREACHABLE } + (void)terminateWithObject: (id)object { | | | | | | | | | | | 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | * returns while being declared OF_NO_RETURN. */ OF_UNREACHABLE } + (void)terminateWithObject: (id)object { OFThread *thread = OFTLSKeyGet(threadSelfKey); if (thread == mainThread) @throw [OFInvalidArgumentException exception]; OFEnsure(thread != nil); thread->_returnValue = [object retain]; longjmp(thread->_exitEnv, 1); OF_UNREACHABLE } + (void)setName: (OFString *)name { [OFThread currentThread].name = name; if (name != nil) OFSetThreadName( [name cStringWithEncoding: [OFLocale encoding]]); else OFSetThreadName(class_getName([self class])); } + (OFString *)name { return [OFThread currentThread].name; } + (void)of_createMainThread { mainThread = [[OFThread alloc] init]; mainThread->_thread = OFCurrentPlainThread(); mainThread->_running = OFThreadStateRunning; if (OFTLSKeySet(threadSelfKey, mainThread) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; } - (instancetype)init { self = [super init]; @try { if (OFPlainThreadAttributesInit(&_attr) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @catch (id e) { [self release]; @throw e; } return self; } # ifdef OF_HAVE_BLOCKS - (instancetype)initWithThreadBlock: (OFThreadBlock)threadBlock { self = [self init]; @try { _threadBlock = [threadBlock copy]; } @catch (id e) { [self release]; |
︙ | ︙ | |||
413 414 415 416 417 418 419 | # endif } - (void)start { int error; | | | | | | | | | > | | | | | | | | 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | # endif } - (void)start { int error; if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; if (_running == OFThreadStateWaitingForJoin) { OFPlainThreadDetach(_thread); [_returnValue release]; } [self retain]; _running = OFThreadStateRunning; if ((error = OFPlainThreadNew(&_thread, [_name cStringWithEncoding: [OFLocale encoding]], callMain, self, &_attr)) != 0) { [self release]; @throw [OFThreadStartFailedException exceptionWithThread: self errNo: error]; } } - (id)join { int error; if (_running == OFThreadStateNotRunning) @throw [OFThreadJoinFailedException exceptionWithThread: self errNo: EINVAL]; if ((error = OFPlainThreadJoin(_thread)) != 0) @throw [OFThreadJoinFailedException exceptionWithThread: self errNo: error]; _running = OFThreadStateNotRunning; return _returnValue; } - (id)copy { return [self retain]; } - (OFRunLoop *)runLoop { # if defined(OF_HAVE_ATOMIC_OPS) && !defined(__clang_analyzer__) if (_runLoop == nil) { OFRunLoop *tmp = [[OFRunLoop alloc] init]; if (!OFAtomicPointerCompareAndSwap( (void **)&_runLoop, nil, tmp)) [tmp release]; } # else @synchronized (self) { if (_runLoop == nil) _runLoop = [[OFRunLoop alloc] init]; } # endif return _runLoop; } - (float)priority { return _attr.priority; } - (void)setPriority: (float)priority { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; _attr.priority = priority; } - (size_t)stackSize { return _attr.stackSize; } - (void)setStackSize: (size_t)stackSize { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; _attr.stackSize = stackSize; } - (bool)supportsSockets { return _supportsSockets; } - (void)setSupportsSockets: (bool)supportsSockets { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; _supportsSockets = supportsSockets; } - (void)dealloc { if (_running == OFThreadStateRunning) @throw [OFThreadStillRunningException exceptionWithThread: self]; /* * We should not be running anymore, but call detach in order to free * the resources. */ if (_running == OFThreadStateWaitingForJoin) OFPlainThreadDetach(_thread); [_returnValue release]; # ifdef OF_HAVE_BLOCKS [_threadBlock release]; # endif [super dealloc]; |
︙ | ︙ |
Modified src/OFThreadPool.h from [7948e1d39c] to [4da774feaf].
︙ | ︙ | |||
19 20 21 22 23 24 25 | /** @file */ #ifdef OF_HAVE_BLOCKS /** * @brief A block for a job which should be executed in a thread pool. */ | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | /** @file */ #ifdef OF_HAVE_BLOCKS /** * @brief A block for a job which should be executed in a thread pool. */ typedef void (^OFThreadPoolBlock)(void); #endif @class OFCondition; @class OFList OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFThreadPoolJob; |
︙ | ︙ | |||
100 101 102 103 104 105 106 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes the specified block as soon as a thread is ready. * * @param block The block to execute */ | | | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | #ifdef OF_HAVE_BLOCKS /** * @brief Executes the specified block as soon as a thread is ready. * * @param block The block to execute */ - (void)dispatchWithBlock: (OFThreadPoolBlock)block; #endif /** * @brief Waits until all jobs are done. */ - (void)waitUntilDone; @end OF_ASSUME_NONNULL_END |
Modified src/OFThreadPool.m from [1ccbdebec3] to [bf37211055].
︙ | ︙ | |||
27 28 29 30 31 32 33 | OF_DIRECT_MEMBERS @interface OFThreadPoolJob: OFObject { id _target; SEL _selector; id _object; #ifdef OF_HAVE_BLOCKS | | | | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | OF_DIRECT_MEMBERS @interface OFThreadPoolJob: OFObject { id _target; SEL _selector; id _object; #ifdef OF_HAVE_BLOCKS OFThreadPoolBlock _block; #endif } - (instancetype)initWithTarget: (id)target selector: (SEL)selector object: (id)object; #ifdef OF_HAVE_BLOCKS - (instancetype)initWithBlock: (OFThreadPoolBlock)block; #endif - (void)perform; @end @implementation OFThreadPoolJob - (instancetype)initWithTarget: (id)target selector: (SEL)selector |
︙ | ︙ | |||
60 61 62 63 64 65 66 | @throw e; } return self; } #ifdef OF_HAVE_BLOCKS | | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | @throw e; } return self; } #ifdef OF_HAVE_BLOCKS - (instancetype)initWithBlock: (OFThreadPoolBlock)block { self = [super init]; @try { _block = [block copy]; } @catch (id e) { [self release]; |
︙ | ︙ | |||
93 94 95 96 97 98 99 | - (void)perform { #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(); else #endif | | < | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | - (void)perform { #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(); else #endif [_target performSelector: _selector withObject: _object]; } @end OF_DIRECT_MEMBERS @interface OFThreadPoolThread: OFThread { OFList *_queue; |
︙ | ︙ | |||
159 160 161 162 163 164 165 | pool = objc_autoreleasePoolPush(); for (;;) { OFThreadPoolJob *job; [_queueCondition lock]; @try { | | | | | | | | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | pool = objc_autoreleasePoolPush(); for (;;) { OFThreadPoolJob *job; [_queueCondition lock]; @try { OFListItem listItem; if (_terminate) { objc_autoreleasePoolPop(pool); return nil; } listItem = _queue.firstListItem; while (listItem == NULL) { [_queueCondition wait]; if (_terminate) { objc_autoreleasePoolPop(pool); return nil; } listItem = _queue.firstListItem; } job = [[OFListItemObject(listItem) retain] autorelease]; [_queue removeListItem: listItem]; } @finally { [_queueCondition unlock]; } if (_terminate) { objc_autoreleasePoolPop(pool); return nil; |
︙ | ︙ | |||
339 340 341 342 343 344 345 | [self of_dispatchJob: job]; } @finally { [job release]; } } #ifdef OF_HAVE_BLOCKS | | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | [self of_dispatchJob: job]; } @finally { [job release]; } } #ifdef OF_HAVE_BLOCKS - (void)dispatchWithBlock: (OFThreadPoolBlock)block { OFThreadPoolJob *job = [[OFThreadPoolJob alloc] initWithBlock: block]; @try { [self of_dispatchJob: job]; } @finally { [job release]; } |
︙ | ︙ |
Modified src/OFTimer+Private.h from [a79edf83ef] to [766374c70a].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFTimer.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFTimer () - (void)of_setInRunLoop: (nullable OFRunLoop *)runLoop | | | 16 17 18 19 20 21 22 23 24 25 26 | #import "OFTimer.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFTimer () - (void)of_setInRunLoop: (nullable OFRunLoop *)runLoop mode: (nullable OFRunLoopMode)mode; @end OF_ASSUME_NONNULL_END |
Modified src/OFTimer.h from [7ce735d772] to [7b53dae76c].
︙ | ︙ | |||
28 29 30 31 32 33 34 | #ifdef OF_HAVE_BLOCKS /** * @brief A block to execute when a timer fires. * * @param timer The timer which fired */ | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #ifdef OF_HAVE_BLOCKS /** * @brief A block to execute when a timer fires. * * @param timer The timer which fired */ typedef void (^OFTimerBlock)(OFTimer *timer); #endif /** * @class OFTimer OFTimer.h ObjFW/OFTimer.h * * @brief A class for creating and firing timers. */ OF_SUBCLASSING_RESTRICTED @interface OFTimer: OFObject <OFComparing> { OFDate *_fireDate; OFTimeInterval _interval; id _target; id _Nullable _object1, _object2, _object3, _object4; SEL _selector; unsigned char _arguments; bool _repeats; #ifdef OF_HAVE_BLOCKS OFTimerBlock _block; #endif bool _valid; #ifdef OF_HAVE_THREADS OFCondition *_condition; bool _done; #endif OFRunLoop *_Nullable _inRunLoop; OFRunLoopMode _Nullable _inRunLoopMode; } /** * @brief The time interval in which the timer will repeat, if it is a * repeating timer. */ @property (readonly, nonatomic) OFTimeInterval timeInterval; /** * @brief Whether the timer repeats. */ @property (readonly, nonatomic) bool repeats; /** * @brief Whether the timer is valid. */ @property (readonly, nonatomic, getter=isValid) bool valid; /** |
︙ | ︙ | |||
93 94 95 96 97 98 99 | * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ | | | | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats; /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object An object to pass when calling the selector on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object repeats: (bool)repeats; /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 repeats: (bool)repeats; /** |
︙ | ︙ | |||
149 150 151 152 153 154 155 | * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 repeats: (bool)repeats; |
︙ | ︙ | |||
174 175 176 177 178 179 180 | * @param object3 The third object to pass when calling the selector on the * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ | | | | | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | * @param object3 The third object to pass when calling the selector on the * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 object: (nullable id)object4 repeats: (bool)repeats; #ifdef OF_HAVE_BLOCKS /** * @brief Creates and schedules a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param repeats Whether the timer repeats after it has been executed * @param block The block to invoke when the timer fires * @return A new, autoreleased timer */ + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block; #endif /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats; /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object An object to pass when calling the selector on the target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object repeats: (bool)repeats; /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object1 The first object to pass when calling the selector on the * target * @param object2 The second object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 repeats: (bool)repeats; /** |
︙ | ︙ | |||
262 263 264 265 266 267 268 | * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ | | | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | * @param object2 The second object to pass when calling the selector on the * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 repeats: (bool)repeats; |
︙ | ︙ | |||
287 288 289 290 291 292 293 | * @param object3 The third object to pass when calling the selector on the * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ | | | | | | | 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | * @param object3 The third object to pass when calling the selector on the * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 object: (nullable id)object4 repeats: (bool)repeats; #ifdef OF_HAVE_BLOCKS /** * @brief Creates a new timer with the specified time interval. * * @param timeInterval The time interval after which the timer should be fired * @param repeats Whether the timer repeats after it has been executed * @param block The block to invoke when the timer fires * @return A new, autoreleased timer */ + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param target The target on which to call the selector * @param selector The selector to call on the target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector repeats: (bool)repeats; /** * @brief Initializes an already allocated timer with the specified time * interval. * * @param fireDate The date at which the timer should fire * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param target The target on which to call the selector * @param selector The selector to call on the target * @param object An object to pass when calling the selector on the target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object repeats: (bool)repeats; /** * @brief Initializes an already allocated timer with the specified time |
︙ | ︙ | |||
367 368 369 370 371 372 373 | * target * @param object2 The second object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate | | | 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | * target * @param object2 The second object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 repeats: (bool)repeats; /** |
︙ | ︙ | |||
393 394 395 396 397 398 399 | * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate | | | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | * target * @param object3 The third object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 repeats: (bool)repeats; |
︙ | ︙ | |||
422 423 424 425 426 427 428 | * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate | | | 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | * target * @param object4 The fourth object to pass when calling the selector on the * target * @param repeats Whether the timer repeats after it has been executed * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (nullable id)object1 object: (nullable id)object2 object: (nullable id)object3 object: (nullable id)object4 repeats: (bool)repeats; |
︙ | ︙ | |||
444 445 446 447 448 449 450 | * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param repeats Whether the timer repeats after it has been executed * @param block The block to invoke when the timer fires * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate | | | > > > > > > > > | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | * @param interval The time interval after which to repeat the timer, if it is * a repeating timer * @param repeats Whether the timer repeats after it has been executed * @param block The block to invoke when the timer fires * @return An initialized timer */ - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval repeats: (bool)repeats block: (OFTimerBlock)block; #endif /** * @brief Compares the timer to another timer. * * @param timer The timer to compare the string to * @return The result of the comparison */ - (OFComparisonResult)compare: (OFTimer *)timer; /** * @brief Fires the timer, meaning it will execute the specified selector on the * target. */ - (void)fire; /** |
︙ | ︙ |
Modified src/OFTimer.m from [f2217d4a17] to [4643374dad].
︙ | ︙ | |||
27 28 29 30 31 32 33 | #ifdef OF_HAVE_THREADS # import "OFCondition.h" #endif #import "OFInvalidArgumentException.h" @implementation OFTimer | | | | | 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 61 62 63 64 | #ifdef OF_HAVE_THREADS # import "OFCondition.h" #endif #import "OFInvalidArgumentException.h" @implementation OFTimer @synthesize timeInterval = _interval, repeats = _repeats, valid = _valid; + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector repeats: repeats] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; |
︙ | ︙ | |||
73 74 75 76 77 78 79 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
98 99 100 101 102 103 104 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 repeats: (bool)repeats { |
︙ | ︙ | |||
125 126 127 128 129 130 131 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 repeats: (bool)repeats |
︙ | ︙ | |||
155 156 157 158 159 160 161 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #ifdef OF_HAVE_BLOCKS | | | | | | | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #ifdef OF_HAVE_BLOCKS + (instancetype)scheduledTimerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval repeats: repeats block: block] autorelease]; [[OFRunLoop currentRunLoop] addTimer: timer]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #endif + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector repeats: repeats] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval target: target selector: selector object: object repeats: repeats] autorelease]; [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 repeats: (bool)repeats { void *pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
238 239 240 241 242 243 244 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } | | | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 repeats: (bool)repeats { |
︙ | ︙ | |||
263 264 265 266 267 268 269 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 repeats: (bool)repeats |
︙ | ︙ | |||
291 292 293 294 295 296 297 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #ifdef OF_HAVE_BLOCKS | | | | 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | [timer retain]; objc_autoreleasePoolPop(pool); return [timer autorelease]; } #ifdef OF_HAVE_BLOCKS + (instancetype)timerWithTimeInterval: (OFTimeInterval)timeInterval repeats: (bool)repeats block: (OFTimerBlock)block { void *pool = objc_autoreleasePoolPush(); OFDate *fireDate = [OFDate dateWithTimeIntervalSinceNow: timeInterval]; id timer = [[[self alloc] initWithFireDate: fireDate interval: timeInterval repeats: repeats block: block] autorelease]; |
︙ | ︙ | |||
315 316 317 318 319 320 321 | - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithFireDate: (OFDate *)fireDate | | | 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)of_initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 arguments: (unsigned char)arguments |
︙ | ︙ | |||
352 353 354 355 356 357 358 | @throw e; } return self; } - (instancetype)initWithFireDate: (OFDate *)fireDate | | | | | | | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | @throw e; } return self; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: nil object: nil object: nil object: nil arguments: 0 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: object object: nil object: nil object: nil arguments: 1 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: object1 object: object2 object: nil object: nil arguments: 2 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 repeats: (bool)repeats { return [self of_initWithFireDate: fireDate interval: interval target: target selector: selector object: object1 object: object2 object: object3 object: nil arguments: 3 repeats: repeats]; } - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval target: (id)target selector: (SEL)selector object: (id)object1 object: (id)object2 object: (id)object3 object: (id)object4 repeats: (bool)repeats |
︙ | ︙ | |||
453 454 455 456 457 458 459 | object: object4 arguments: 4 repeats: repeats]; } #ifdef OF_HAVE_BLOCKS - (instancetype)initWithFireDate: (OFDate *)fireDate | | | | 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | object: object4 arguments: 4 repeats: repeats]; } #ifdef OF_HAVE_BLOCKS - (instancetype)initWithFireDate: (OFDate *)fireDate interval: (OFTimeInterval)interval repeats: (bool)repeats block: (OFTimerBlock)block { self = [super init]; @try { _fireDate = [fireDate retain]; _interval = interval; _repeats = repeats; |
︙ | ︙ | |||
502 503 504 505 506 507 508 | #ifdef OF_HAVE_THREADS [_condition release]; #endif [super dealloc]; } | < < | | | < < | < | | | | < | < | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | #ifdef OF_HAVE_THREADS [_condition release]; #endif [super dealloc]; } - (OFComparisonResult)compare: (OFTimer *)timer { if (![timer isKindOfClass: [OFTimer class]]) @throw [OFInvalidArgumentException exception]; return [_fireDate compare: timer->_fireDate]; } - (void)of_setInRunLoop: (OFRunLoop *)runLoop mode: (OFRunLoopMode)mode { OFRunLoop *oldInRunLoop = _inRunLoop; OFRunLoopMode oldInRunLoopMode = _inRunLoopMode; _inRunLoop = [runLoop retain]; [oldInRunLoop release]; _inRunLoopMode = [mode copy]; [oldInRunLoopMode release]; } - (void)fire { void *pool = objc_autoreleasePoolPush(); id target = [[_target retain] autorelease]; id object1 = [[_object1 retain] autorelease]; id object2 = [[_object2 retain] autorelease]; id object3 = [[_object3 retain] autorelease]; id object4 = [[_object4 retain] autorelease]; OFEnsure(_arguments <= 4); if (_repeats && _valid) { int64_t missedIntervals = -_fireDate.timeIntervalSinceNow / _interval; OFTimeInterval newFireDate; OFRunLoop *runLoop; /* In case the clock was changed backwards */ if (missedIntervals < 0) missedIntervals = 0; newFireDate = _fireDate.timeIntervalSince1970 + (missedIntervals + 1) * _interval; [_fireDate release]; _fireDate = [[OFDate alloc] initWithTimeIntervalSince1970: newFireDate]; runLoop = [OFRunLoop currentRunLoop]; [runLoop addTimer: self forMode: runLoop.currentMode]; } else [self invalidate]; #ifdef OF_HAVE_BLOCKS if (_block != NULL) _block(self); else { #endif switch (_arguments) { case 0: [target performSelector: _selector]; break; case 1: [target performSelector: _selector withObject: object1]; break; case 2: [target performSelector: _selector withObject: object1 withObject: object2]; break; case 3: |
︙ | ︙ | |||
629 630 631 632 633 634 635 | [_inRunLoop of_removeTimer: self forMode: _inRunLoopMode]; old = _fireDate; _fireDate = [fireDate copy]; [old release]; | | < | 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | [_inRunLoop of_removeTimer: self forMode: _inRunLoopMode]; old = _fireDate; _fireDate = [fireDate copy]; [old release]; [_inRunLoop addTimer: self forMode: _inRunLoopMode]; } } @finally { [self release]; } } - (void)invalidate |
︙ | ︙ | |||
670 671 672 673 674 675 676 677 | [_condition wait]; } @finally { [_condition unlock]; } } #endif @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 | [_condition wait]; } @finally { [_condition unlock]; } } #endif - (OFString *)description { #ifdef OF_HAVE_BLOCKS if (_block != NULL) return [OFString stringWithFormat: @"<%@:\n" @"\tFire date: %@\n" @"\tInterval: %lf\n" @"\tRepeats: %s\n" @"\tBlock: %@\n" @"\tValid: %s\n" @">", self.class, _fireDate, _interval, (_repeats ? "yes" : "no"), _block, (_valid ? "yes" : "no")]; else #endif return [OFString stringWithFormat: @"<%@:\n" @"\tFire date: %@\n" @"\tInterval: %lf\n" @"\tRepeats: %s\n" @"\tTarget: %@\n" @"\tSelector: %s\n" @"\tValid: %s\n" @">", self.class, _fireDate, _interval, (_repeats ? "yes" : "no"), _target, sel_getName(_selector), (_valid ? "yes" : "no")]; } @end |
Modified src/OFTriple.m from [2b97357c4c] to [444aed5be2].
︙ | ︙ | |||
95 96 97 98 99 100 101 | return false; return true; } - (unsigned long)hash { | | | | | | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, [_firstObject hash]); OFHashAddHash(&hash, [_secondObject hash]); OFHashAddHash(&hash, [_thirdObject hash]); OFHashFinalize(&hash); return hash; } - (id)copy { return [self retain]; |
︙ | ︙ |
Modified src/OFUDPSocket+Private.h from [de17aba506] to [6c9ef7ed56].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFUDPSocket.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFUDPSocket () | | | 15 16 17 18 19 20 21 22 23 24 25 26 | #import "OFUDPSocket.h" OF_ASSUME_NONNULL_BEGIN OF_DIRECT_MEMBERS @interface OFUDPSocket () - (uint16_t)of_bindToAddress: (OFSocketAddress *)address extraType: (int)extraType; @end OF_ASSUME_NONNULL_END |
Modified src/OFUDPSocket.h from [c77d39725a] to [7fc9c66432].
︙ | ︙ | |||
28 29 30 31 32 33 34 | @end /** * @class OFUDPSocket OFUDPSocket.h ObjFW/OFUDPSocket.h * * @brief A class which provides methods to create and use UDP sockets. * | | | | > | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | @end /** * @class OFUDPSocket OFUDPSocket.h ObjFW/OFUDPSocket.h * * @brief A class which provides methods to create and use UDP sockets. * * Addresses are of type @ref OFSocketAddress. You can use the current thread's * @ref OFDNSResolver to create an address for a host / port pair, * @ref OFSocketAddressString to get the IP address string for an address and * @ref OFSocketAddressPort to get the port for an address. If you want to * compare two addresses, you can use * @ref OFSocketAddressEqual and you can use @ref OFSocketAddressHash to get a * hash to use in e.g. @ref OFMapTable. * * @warning Even though the OFCopying protocol is implemented, it does *not* * return an independent copy of the socket, but instead retains it. * This is so that the socket can be used as a key for a dictionary, * so context can be associated with a socket. Using a socket in more * than one thread at the same time is not thread-safe, even if copy |
︙ | ︙ | |||
68 69 70 71 72 73 74 | * * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to */ | | < | 69 70 71 72 73 74 75 76 77 78 79 | * * @param host The host to bind to. Use `@"0.0.0.0"` for IPv4 or `@"::"` for * IPv6 to bind to all. * @param port The port to bind to. If the port is 0, an unused port will be * chosen, which can be obtained using the return value. * @return The port the socket was bound to */ - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port; @end OF_ASSUME_NONNULL_END |
Modified src/OFUDPSocket.m from [284e645ef0] to [5d65cff83a].
︙ | ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFUDPSocket.h" #import "OFUDPSocket+Private.h" #import "OFDNSResolver.h" #import "OFData.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" | > > > > > > > < < < | < | < | | | < | | | < | > | | | | | | > > | < < | | | | < | > | | | | | | < | > | | | | < | > | | | | < | | | | | | < | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #ifndef _XOPEN_SOURCE_EXTENDED # define _XOPEN_SOURCE_EXTENDED #endif #define _HPUX_ALT_XOPEN_SOCKET_API #include <errno.h> #ifdef HAVE_FCNTL_H # include <fcntl.h> #endif #import "OFUDPSocket.h" #import "OFUDPSocket+Private.h" #import "OFDNSResolver.h" #import "OFData.h" #import "OFSocket.h" #import "OFSocket+Private.h" #import "OFThread.h" #import "OFAlreadyConnectedException.h" #import "OFBindFailedException.h" @implementation OFUDPSocket @dynamic delegate; - (uint16_t)of_bindToAddress: (OFSocketAddress *)address extraType: (int)extraType OF_DIRECT { void *pool = objc_autoreleasePoolPush(); uint16_t port; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) int flags; #endif if ((_socket = socket(address->sockaddr.sockaddr.sa_family, SOCK_DGRAM | SOCK_CLOEXEC | extraType, 0)) == OFInvalidSocketHandle) @throw [OFBindFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: OFSocketErrNo()]; _canBlock = true; #if SOCK_CLOEXEC == 0 && defined(HAVE_FCNTL) && defined(FD_CLOEXEC) /* {} needed to avoid warning with Clang 10 if next #if is false. */ if ((flags = fcntl(_socket, F_GETFD, 0)) != -1) { fcntl(_socket, F_SETFD, flags | FD_CLOEXEC); } #endif #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) if (OFSocketAddressPort(address) != 0) { #endif if (bind(_socket, &address->sockaddr.sockaddr, address->length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: errNo]; } #if defined(OF_HPUX) || defined(OF_WII) || defined(OF_NINTENDO_3DS) } else { for (;;) { uint16_t rnd = 0; int ret; while (rnd < 1024) rnd = (uint16_t)rand(); OFSocketAddressSetPort(address, rnd); if ((ret = bind(_socket, &address->sockaddr.sockaddr, address->length)) == 0) { port = rnd; break; } if (OFSocketErrNo() != EADDRINUSE) { int errNo = OFSocketErrNo(); OFString *host = OFSocketAddressString(address); uint16_t port = OFSocketAddressPort(port); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: host port: port socket: self errNo: errNo]; } } } #endif objc_autoreleasePoolPop(pool); if ((port = OFSocketAddressPort(address)) > 0) return port; #if !defined(OF_HPUX) && !defined(OF_WII) && !defined(OF_NINTENDO_3DS) memset(address, 0, sizeof(*address)); address->length = (socklen_t)sizeof(address->sockaddr); if (OFGetSockName(_socket, &address->sockaddr.sockaddr, &address->length) != 0) { int errNo = OFSocketErrNo(); closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: errNo]; } if (address->sockaddr.sockaddr.sa_family == AF_INET) return OFFromBigEndian16(address->sockaddr.in.sin_port); # ifdef OF_HAVE_IPV6 else if (address->sockaddr.sockaddr.sa_family == AF_INET6) return OFFromBigEndian16(address->sockaddr.in6.sin6_port); # endif else { closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: EAFNOSUPPORT]; } #else closesocket(_socket); _socket = OFInvalidSocketHandle; @throw [OFBindFailedException exceptionWithHost: OFSocketAddressString(address) port: OFSocketAddressPort(address) socket: self errNo: EADDRNOTAVAIL]; #endif } - (uint16_t)bindToHost: (OFString *)host port: (uint16_t)port { void *pool = objc_autoreleasePoolPush(); OFData *socketAddresses; OFSocketAddress address; if (_socket != OFInvalidSocketHandle) @throw [OFAlreadyConnectedException exceptionWithSocket: self]; socketAddresses = [[OFThread DNSResolver] resolveAddressesForHost: host addressFamily: OFSocketAddressFamilyAny]; address = *(OFSocketAddress *)[socketAddresses itemAtIndex: 0]; OFSocketAddressSetPort(&address, port); port = [self of_bindToAddress: &address extraType: 0]; objc_autoreleasePoolPop(pool); return port; } @end |
Modified src/OFURL.h from [8e156f58b1] to [4f2aa36df7].
︙ | ︙ | |||
185 186 187 188 189 190 191 | * @brief Creates a new URL with the specified string relative to the * specified URL. * * @param string A string describing a URL * @param URL An URL to which the string is relative * @return A new, autoreleased OFURL */ | | < | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | * @brief Creates a new URL with the specified string relative to the * specified URL. * * @param string A string describing a URL * @param URL An URL to which the string is relative * @return A new, autoreleased OFURL */ + (instancetype)URLWithString: (OFString *)string relativeToURL: (OFURL *)URL; #ifdef OF_HAVE_FILES /** * @brief Creates a new URL with the specified local file path. * * If a directory exists at the specified path, a slash is appended if there is * no slash yet. |
︙ | ︙ | |||
228 229 230 231 232 233 234 | * @brief Initializes an already allocated OFURL with the specified string and * relative URL. * * @param string A string describing a URL * @param URL A URL to which the string is relative * @return An initialized OFURL */ | | < | 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | * @brief Initializes an already allocated OFURL with the specified string and * relative URL. * * @param string A string describing a URL * @param URL A URL to which the string is relative * @return An initialized OFURL */ - (instancetype)initWithString: (OFString *)string relativeToURL: (OFURL *)URL; #ifdef OF_HAVE_FILES /** * @brief Initializes an already allocated OFURL with the specified local file * path. * * If a directory exists at the specified path, a slash is appended if there is |
︙ | ︙ | |||
365 366 367 368 369 370 371 | */ + (OFCharacterSet *)URLFragmentAllowedCharacterSet; @end #ifdef __cplusplus extern "C" { #endif | | > | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | */ + (OFCharacterSet *)URLFragmentAllowedCharacterSet; @end #ifdef __cplusplus extern "C" { #endif extern bool OFURLIsIPv6Host(OFString *host); extern void OFURLVerifyIsEscaped(OFString *, OFCharacterSet *); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFMutableURL.h" |
Modified src/OFURL.m from [a106091d83] to [110acb1505].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #include <stdlib.h> #include <string.h> #import "OFURL.h" #import "OFArray.h" #import "OFDictionary.h" | < < < < > > > > < < | 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 | #include <stdlib.h> #include <string.h> #import "OFURL.h" #import "OFArray.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFileManager.h" # import "OFFileURLHandler.h" #endif #import "OFNumber.h" #import "OFOnce.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" @interface OFURLAllowedCharacterSetBase: OFCharacterSet @end @interface OFURLAllowedCharacterSet: OFURLAllowedCharacterSetBase @end @interface OFURLSchemeAllowedCharacterSet: OFURLAllowedCharacterSetBase |
︙ | ︙ | |||
56 57 58 59 60 61 62 | static OFCharacterSet *URLAllowedCharacterSet = nil; static OFCharacterSet *URLSchemeAllowedCharacterSet = nil; static OFCharacterSet *URLPathAllowedCharacterSet = nil; static OFCharacterSet *URLQueryOrFragmentAllowedCharacterSet = nil; static OFCharacterSet *URLQueryKeyValueAllowedCharacterSet = nil; | | | > | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | static OFCharacterSet *URLAllowedCharacterSet = nil; static OFCharacterSet *URLSchemeAllowedCharacterSet = nil; static OFCharacterSet *URLPathAllowedCharacterSet = nil; static OFCharacterSet *URLQueryOrFragmentAllowedCharacterSet = nil; static OFCharacterSet *URLQueryKeyValueAllowedCharacterSet = nil; static OFOnceControl URLAllowedCharacterSetOnce = OFOnceControlInitValue; static OFOnceControl URLQueryOrFragmentAllowedCharacterSetOnce = OFOnceControlInitValue; static void initURLAllowedCharacterSet(void) { URLAllowedCharacterSet = [[OFURLAllowedCharacterSet alloc] init]; } |
︙ | ︙ | |||
97 98 99 100 101 102 103 | [[OFURLQueryKeyValueAllowedCharacterSet alloc] init]; } OF_DIRECT_MEMBERS @interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet { OFCharacterSet *_characterSet; | | | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | [[OFURLQueryKeyValueAllowedCharacterSet alloc] init]; } OF_DIRECT_MEMBERS @interface OFInvertedCharacterSetWithoutPercent: OFCharacterSet { OFCharacterSet *_characterSet; bool (*_characterIsMember)(id, SEL, OFUnichar); } - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet; @end bool OFURLIsIPv6Host(OFString *host) { const char *UTF8String = host.UTF8String; bool hasColon = false; while (*UTF8String != '\0') { if (!OFASCIIIsDigit(*UTF8String) && *UTF8String != ':' && (*UTF8String < 'a' || *UTF8String > 'f') && (*UTF8String < 'A' || *UTF8String > 'F')) return false; if (*UTF8String == ':') hasColon = true; |
︙ | ︙ | |||
141 142 143 144 145 146 147 | - (void)release { } - (unsigned int)retainCount { | | | | | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | - (void)release { } - (unsigned int)retainCount { return OFMaxRetainCount; } @end @implementation OFURLAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': case '.': case '_': case '~': |
︙ | ︙ | |||
175 176 177 178 179 180 181 | default: return false; } } @end @implementation OFURLSchemeAllowedCharacterSet | | | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | default: return false; } } @end @implementation OFURLSchemeAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '+': case '-': case '.': return true; default: return false; } } @end @implementation OFURLPathAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': case '.': case '_': case '~': |
︙ | ︙ | |||
224 225 226 227 228 229 230 | default: return false; } } @end @implementation OFURLQueryOrFragmentAllowedCharacterSet | | | | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | default: return false; } } @end @implementation OFURLQueryOrFragmentAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': case '.': case '_': case '~': |
︙ | ︙ | |||
257 258 259 260 261 262 263 | default: return false; } } @end @implementation OFURLQueryKeyValueAllowedCharacterSet | | | | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | default: return false; } } @end @implementation OFURLQueryKeyValueAllowedCharacterSet - (bool)characterIsMember: (OFUnichar)character { if (character < CHAR_MAX && OFASCIIIsAlnum(character)) return true; switch (character) { case '-': case '.': case '_': case '~': |
︙ | ︙ | |||
294 295 296 297 298 299 300 | @implementation OFInvertedCharacterSetWithoutPercent - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet { self = [super init]; @try { _characterSet = [characterSet retain]; | | | | | | | | | | | | | | | | | 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 | @implementation OFInvertedCharacterSetWithoutPercent - (instancetype)initWithCharacterSet: (OFCharacterSet *)characterSet { self = [super init]; @try { _characterSet = [characterSet retain]; _characterIsMember = (bool (*)(id, SEL, OFUnichar)) [_characterSet methodForSelector: @selector(characterIsMember:)]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_characterSet release]; [super dealloc]; } - (bool)characterIsMember: (OFUnichar)character { return (character != '%' && !_characterIsMember(_characterSet, @selector(characterIsMember:), character)); } @end void OFURLVerifyIsEscaped(OFString *string, OFCharacterSet *characterSet) { void *pool = objc_autoreleasePoolPush(); characterSet = [[[OFInvertedCharacterSetWithoutPercent alloc] initWithCharacterSet: characterSet] autorelease]; if ([string indexOfCharacterFromSet: characterSet] != OFNotFound) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); } @implementation OFCharacterSet (URLCharacterSets) + (OFCharacterSet *)URLSchemeAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initURLSchemeAllowedCharacterSet); return URLSchemeAllowedCharacterSet; } + (OFCharacterSet *)URLHostAllowedCharacterSet { OFOnce(&URLAllowedCharacterSetOnce, initURLAllowedCharacterSet); return URLAllowedCharacterSet; } + (OFCharacterSet *)URLUserAllowedCharacterSet { OFOnce(&URLAllowedCharacterSetOnce, initURLAllowedCharacterSet); return URLAllowedCharacterSet; } + (OFCharacterSet *)URLPasswordAllowedCharacterSet { OFOnce(&URLAllowedCharacterSetOnce, initURLAllowedCharacterSet); return URLAllowedCharacterSet; } + (OFCharacterSet *)URLPathAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initURLPathAllowedCharacterSet); return URLPathAllowedCharacterSet; } + (OFCharacterSet *)URLQueryAllowedCharacterSet { OFOnce(&URLQueryOrFragmentAllowedCharacterSetOnce, initURLQueryOrFragmentAllowedCharacterSet); return URLQueryOrFragmentAllowedCharacterSet; } + (OFCharacterSet *)URLQueryKeyValueAllowedCharacterSet { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, initURLQueryKeyValueAllowedCharacterSet); return URLQueryKeyValueAllowedCharacterSet; } + (OFCharacterSet *)URLFragmentAllowedCharacterSet { OFOnce(&URLQueryOrFragmentAllowedCharacterSetOnce, initURLQueryOrFragmentAllowedCharacterSet); return URLQueryOrFragmentAllowedCharacterSet; } @end @implementation OFURL |
︙ | ︙ | |||
439 440 441 442 443 444 445 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); char *tmp, *tmp2; bool isIPv6Host = false; | < < < < < | | | | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); char *tmp, *tmp2; bool isIPv6Host = false; UTF8String = UTF8String2 = OFStrDup(string.UTF8String); if ((tmp = strchr(UTF8String, ':')) == NULL) @throw [OFInvalidFormatException exception]; if (strncmp(tmp, "://", 3) != 0) @throw [OFInvalidFormatException exception]; for (tmp2 = UTF8String; tmp2 < tmp; tmp2++) *tmp2 = OFASCIIToLower(*tmp2); _URLEncodedScheme = [[OFString alloc] initWithUTF8String: UTF8String length: tmp - UTF8String]; OFURLVerifyIsEscaped(_URLEncodedScheme, [OFCharacterSet URLSchemeAllowedCharacterSet]); UTF8String = tmp + 3; if ((tmp = strchr(UTF8String, '/')) != NULL) { *tmp = '\0'; tmp++; |
︙ | ︙ | |||
484 485 486 487 488 489 490 | tmp3++; _URLEncodedUser = [[OFString alloc] initWithUTF8String: UTF8String]; _URLEncodedPassword = [[OFString alloc] initWithUTF8String: tmp3]; | | | | | | 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | tmp3++; _URLEncodedUser = [[OFString alloc] initWithUTF8String: UTF8String]; _URLEncodedPassword = [[OFString alloc] initWithUTF8String: tmp3]; OFURLVerifyIsEscaped(_URLEncodedPassword, [OFCharacterSet URLPasswordAllowedCharacterSet]); } else _URLEncodedUser = [[OFString alloc] initWithUTF8String: UTF8String]; OFURLVerifyIsEscaped(_URLEncodedUser, [OFCharacterSet URLUserAllowedCharacterSet]); UTF8String = tmp2; } if (UTF8String[0] == '[') { tmp2 = UTF8String++; while (OFASCIIIsDigit(*UTF8String) || *UTF8String == ':' || (*UTF8String >= 'a' && *UTF8String <= 'f') || (*UTF8String >= 'A' && *UTF8String <= 'F')) UTF8String++; if (*UTF8String != ']') @throw [OFInvalidFormatException exception]; UTF8String++; _URLEncodedHost = [[OFString alloc] initWithUTF8String: tmp2 length: UTF8String - tmp2]; if (*UTF8String == ':') { OFString *portString; tmp2 = ++UTF8String; while (*UTF8String != '\0') { if (!OFASCIIIsDigit(*UTF8String)) @throw [OFInvalidFormatException exception]; UTF8String++; } portString = [OFString |
︙ | ︙ | |||
564 565 566 567 568 569 570 | _port = [[OFNumber alloc] initWithUnsignedShort: portString.unsignedLongLongValue]; } else _URLEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String]; if (!isIPv6Host) | | | | | | | < < < < < < | | | | | | | | < < | < | 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | _port = [[OFNumber alloc] initWithUnsignedShort: portString.unsignedLongLongValue]; } else _URLEncodedHost = [[OFString alloc] initWithUTF8String: UTF8String]; if (!isIPv6Host) OFURLVerifyIsEscaped(_URLEncodedHost, [OFCharacterSet URLHostAllowedCharacterSet]); if ((UTF8String = tmp) != NULL) { if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; _URLEncodedFragment = [[OFString alloc] initWithUTF8String: tmp + 1]; OFURLVerifyIsEscaped(_URLEncodedFragment, [OFCharacterSet URLFragmentAllowedCharacterSet]); } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; _URLEncodedQuery = [[OFString alloc] initWithUTF8String: tmp + 1]; OFURLVerifyIsEscaped(_URLEncodedQuery, [OFCharacterSet URLQueryAllowedCharacterSet]); } UTF8String--; *UTF8String = '/'; _URLEncodedPath = [[OFString alloc] initWithUTF8String: UTF8String]; OFURLVerifyIsEscaped(_URLEncodedPath, [OFCharacterSet URLPathAllowedCharacterSet]); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @finally { OFFreeMemory(UTF8String2); } return self; } - (instancetype)initWithString: (OFString *)string relativeToURL: (OFURL *)URL { char *UTF8String, *UTF8String2 = NULL; if ([string containsString: @"://"]) return [self initWithString: string]; self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); char *tmp; _URLEncodedScheme = [URL->_URLEncodedScheme copy]; _URLEncodedHost = [URL->_URLEncodedHost copy]; _port = [URL->_port copy]; _URLEncodedUser = [URL->_URLEncodedUser copy]; _URLEncodedPassword = [URL->_URLEncodedPassword copy]; UTF8String = UTF8String2 = OFStrDup(string.UTF8String); if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; _URLEncodedFragment = [[OFString alloc] initWithUTF8String: tmp + 1]; OFURLVerifyIsEscaped(_URLEncodedFragment, [OFCharacterSet URLFragmentAllowedCharacterSet]); } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; _URLEncodedQuery = [[OFString alloc] initWithUTF8String: tmp + 1]; OFURLVerifyIsEscaped(_URLEncodedQuery, [OFCharacterSet URLQueryAllowedCharacterSet]); } if (*UTF8String == '/') _URLEncodedPath = [[OFString alloc] initWithUTF8String: UTF8String]; else { OFString *relativePath = [OFString stringWithUTF8String: UTF8String]; if ([URL->_URLEncodedPath hasSuffix: @"/"]) _URLEncodedPath = [[URL->_URLEncodedPath stringByAppendingString: relativePath] copy]; else { OFMutableString *path = [OFMutableString stringWithString: (URL->_URLEncodedPath != nil ? URL->_URLEncodedPath : @"/")]; OFRange range = [path rangeOfString: @"/" options: OFStringSearchBackwards]; if (range.location == OFNotFound) @throw [OFInvalidFormatException exception]; range.location++; range.length = path.length - range.location; [path replaceCharactersInRange: range withString: relativePath]; [path makeImmutable]; _URLEncodedPath = [path copy]; } } OFURLVerifyIsEscaped(_URLEncodedPath, [OFCharacterSet URLPathAllowedCharacterSet]); objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @finally { OFFreeMemory(UTF8String2); } return self; } #ifdef OF_HAVE_FILES - (instancetype)initFileURLWithPath: (OFString *)path { bool isDirectory; @try { void *pool = objc_autoreleasePoolPush(); isDirectory = [path of_isDirectoryPath]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } self = [self initFileURLWithPath: path isDirectory: isDirectory]; return self; } - (instancetype)initFileURLWithPath: (OFString *)path isDirectory: (bool)isDirectory { |
︙ | ︙ | |||
775 776 777 778 779 780 781 | - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { if (![element.name isEqual: self.className] || | | | 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 | - (instancetype)initWithSerialization: (OFXMLElement *)element { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @try { if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; stringValue = element.stringValue; } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
846 847 848 849 850 851 852 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | | | | | 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _URLEncodedScheme.hash); OFHashAddHash(&hash, _URLEncodedHost.hash); OFHashAddHash(&hash, _port.hash); OFHashAddHash(&hash, _URLEncodedUser.hash); OFHashAddHash(&hash, _URLEncodedPassword.hash); OFHashAddHash(&hash, _URLEncodedPath.hash); OFHashAddHash(&hash, _URLEncodedQuery.hash); OFHashAddHash(&hash, _URLEncodedFragment.hash); OFHashFinalize(&hash); return hash; } - (OFString *)scheme { return _URLEncodedScheme.stringByURLDecoding; } - (OFString *)URLEncodedScheme { return _URLEncodedScheme; } - (OFString *)host { if ([_URLEncodedHost hasPrefix: @"["] && [_URLEncodedHost hasSuffix: @"]"]) { OFString *host = [_URLEncodedHost substringWithRange: OFRangeMake(1, _URLEncodedHost.length - 2)]; if (!OFURLIsIPv6Host(host)) @throw [OFInvalidArgumentException exception]; return host; } return _URLEncodedHost.stringByURLDecoding; } |
︙ | ︙ | |||
946 947 948 949 950 951 952 | #ifdef OF_HAVE_FILES if (isFile) { OFString *path = [_URLEncodedPath of_URLPathToPathWithURLEncodedHost: nil]; ret = [[path.pathComponents mutableCopy] autorelease]; if (![ret.firstObject isEqual: @"/"]) | | < | < | 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 | #ifdef OF_HAVE_FILES if (isFile) { OFString *path = [_URLEncodedPath of_URLPathToPathWithURLEncodedHost: nil]; ret = [[path.pathComponents mutableCopy] autorelease]; if (![ret.firstObject isEqual: @"/"]) [ret insertObject: @"/" atIndex: 0]; } else #endif ret = [[[_URLEncodedPath componentsSeparatedByString: @"/"] mutableCopy] autorelease]; count = ret.count; if (count > 0 && [ret.firstObject length] == 0) [ret replaceObjectAtIndex: 0 withObject: @"/"]; for (size_t i = 0; i < count; i++) { OFString *component = [ret objectAtIndex: i]; #ifdef OF_HAVE_FILES if (isFile) component = |
︙ | ︙ | |||
1158 1159 1160 1161 1162 1163 1164 | return [path autorelease]; } #endif - (OFURL *)URLByAppendingPathComponent: (OFString *)component { OFMutableURL *URL = [[self mutableCopy] autorelease]; | < < < | < < < < | | 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 | return [path autorelease]; } #endif - (OFURL *)URLByAppendingPathComponent: (OFString *)component { OFMutableURL *URL = [[self mutableCopy] autorelease]; [URL appendPathComponent: component]; [URL makeImmutable]; return URL; } - (OFURL *)URLByAppendingPathComponent: (OFString *)component isDirectory: (bool)isDirectory { OFMutableURL *URL = [[self mutableCopy] autorelease]; [URL appendPathComponent: component isDirectory: isDirectory]; [URL makeImmutable]; return URL; } - (OFURL *)URLByStandardizingPath { OFMutableURL *URL = [[self mutableCopy] autorelease]; [URL standardizePath]; [URL makeImmutable]; return URL; } - (OFString *)description { return [OFString stringWithFormat: @"<%@: %@>", self.class, self.string]; } - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: self.string]; [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } @end |
Modified src/OFURLHandler.h from [c6421bd016] to [aebd1b72ac].
︙ | ︙ | |||
47 48 49 50 51 52 53 | * created per scheme. * * @param class_ The class to register as the handler for the specified scheme * @param scheme The scheme for which to register the handler * @return Whether the class was successfully registered. If a handler for the * same scheme is already registered, registration fails. */ | | < | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | * created per scheme. * * @param class_ The class to register as the handler for the specified scheme * @param scheme The scheme for which to register the handler * @return Whether the class was successfully registered. If a handler for the * same scheme is already registered, registration fails. */ + (bool)registerClass: (Class)class_ forScheme: (OFString *)scheme; /** * @brief Returns the handler for the specified URL. * * @return The handler for the specified URL. */ + (nullable OF_KINDOF(OFURLHandler *))handlerForURL: (OFURL *)URL; |
︙ | ︙ | |||
88 89 90 91 92 93 94 | * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @n * The handler is allowed to not implement all modes and is also * allowed to implement additional, scheme-specific modes. */ | | < | | < | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | * `w+x` | Read-write, create or fail, exclusive * `a` | Write-only, create or append * `a+` | Read-write, create or append * @n * The handler is allowed to not implement all modes and is also * allowed to implement additional, scheme-specific modes. */ - (OFStream *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode; /** * @brief Returns the attributes for the item at the specified URL. * * @param URL The URL to return the attributes for * @return A dictionary of attributes for the specified URL, with the keys of * type @ref OFFileAttributeKey */ - (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL; /** * @brief Sets the attributes for the item at the specified URL. * * All attributes not part of the dictionary are left unchanged. * * @param attributes The attributes to set for the specified URL * @param URL The URL of the item to set the attributes for */ - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL; /** * @brief Checks whether a file exists at the specified URL. * * @param URL The URL to check * @return A boolean whether there is a file at the specified URL */ |
︙ | ︙ | |||
135 136 137 138 139 140 141 | * @brief Creates a directory at the specified URL. * * @param URL The URL of the directory to create */ - (void)createDirectoryAtURL: (OFURL *)URL; /** | | > | | | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | * @brief Creates a directory at the specified URL. * * @param URL The URL of the directory to create */ - (void)createDirectoryAtURL: (OFURL *)URL; /** * @brief Returns an array with the URLs of the items in the specified * directory. * * @note `.` and `..` are not part of the returned array. * * @param URL The URL to the directory whose items should be returned * @return An array with the URLs of the items in the specified directory */ - (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL; /** * @brief Removes the item at the specified URL. * * If the item at the specified URL is a directory, it is removed recursively. * * @param URL The URL to the item which should be removed |
︙ | ︙ | |||
164 165 166 167 168 169 170 | * name of the item. * * This method is not available for all URLs. * * @param source The URL to the item for which a link should be created * @param destination The URL to the item which should link to the source */ | | < | 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | * name of the item. * * This method is not available for all URLs. * * @param source The URL to the item for which a link should be created * @param destination The URL to the item which should link to the source */ - (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination; /** * @brief Creates a symbolic link for an item. * * The destination uRL must have a full path, which means it must include the * name of the item. * |
︙ | ︙ | |||
201 202 203 204 205 206 207 | * * @param source The file, directory or symbolic link to copy * @param destination The destination URL * @return True if an efficient copy was performed, false if an efficient copy * was not possible. Note that errors while performing a copy are * reported via exceptions and not by returning false! */ | | < | < | 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | * * @param source The file, directory or symbolic link to copy * @param destination The destination URL * @return True if an efficient copy was performed, false if an efficient copy * was not possible. Note that errors while performing a copy are * reported via exceptions and not by returning false! */ - (bool)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination; /** * @brief Tries to efficiently move an item. If a move would only be possible * by copying the source and deleting it, it returns false. * * The destination URL must have a full path, which means it must include the * name of the item. * * If the destination is on a different logical device or uses a different * scheme, an efficient move is not possible and false is returned. * * @param source The item to rename * @param destination The new name for the item * @return True if an efficient move was performed, false if an efficient move * was not possible. Note that errors while performing a move are * reported via exceptions and not by returning false! */ - (bool)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination; @end OF_ASSUME_NONNULL_END |
Modified src/OFURLHandler.m from [a30f3ee6ac] to [d88aa91e77].
︙ | ︙ | |||
53 54 55 56 57 58 59 | handlers = [[OFMutableDictionary alloc] init]; #ifdef OF_HAVE_THREADS mutex = [[OFMutex alloc] init]; atexit(releaseMutex); #endif #ifdef OF_HAVE_FILES | | < | < | < | < | < | 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | handlers = [[OFMutableDictionary alloc] init]; #ifdef OF_HAVE_THREADS mutex = [[OFMutex alloc] init]; atexit(releaseMutex); #endif #ifdef OF_HAVE_FILES [self registerClass: [OFFileURLHandler class] forScheme: @"file"]; #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self registerClass: [OFHTTPURLHandler class] forScheme: @"http"]; [self registerClass: [OFHTTPURLHandler class] forScheme: @"https"]; #endif } + (bool)registerClass: (Class)class forScheme: (OFString *)scheme { #ifdef OF_HAVE_THREADS [mutex lock]; @try { #endif OFURLHandler *handler; if ([handlers objectForKey: scheme] != nil) return false; handler = [[class alloc] initWithScheme: scheme]; @try { [handlers setObject: handler forKey: scheme]; } @finally { [handler release]; } #ifdef OF_HAVE_THREADS } @finally { [mutex unlock]; } |
︙ | ︙ | |||
136 137 138 139 140 141 142 | - (void)dealloc { [_scheme release]; [super dealloc]; } | | < | < | | | < | < | < | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | - (void)dealloc { [_scheme release]; [super dealloc]; } - (OFStream *)openItemAtURL: (OFURL *)URL mode: (OFString *)mode { OF_UNRECOGNIZED_SELECTOR } - (OFFileAttributes)attributesOfItemAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (void)setAttributes: (OFFileAttributes)attributes ofItemAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (bool)fileExistsAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (bool)directoryExistsAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (void)createDirectoryAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (OFArray OF_GENERIC(OFURL *) *)contentsOfDirectoryAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (void)removeItemAtURL: (OFURL *)URL { OF_UNRECOGNIZED_SELECTOR } - (void)linkItemAtURL: (OFURL *)source toURL: (OFURL *)destination { OF_UNRECOGNIZED_SELECTOR } - (void)createSymbolicLinkAtURL: (OFURL *)destination withDestinationPath: (OFString *)source { OF_UNRECOGNIZED_SELECTOR } - (bool)copyItemAtURL: (OFURL *)source toURL: (OFURL *)destination { return false; } - (bool)moveItemAtURL: (OFURL *)source toURL: (OFURL *)destination { return false; } @end |
Modified src/OFUTF8String.h from [bd916580b9] to [4e86bf2737].
︙ | ︙ | |||
22 23 24 25 26 27 28 | /* * A pointer to the actual data. * * Since constant strings don't have `_storage`, they have to allocate * it on the first access. Strings created at runtime just set the * pointer to `&_storage`. */ | | | | | < | | 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 | /* * A pointer to the actual data. * * Since constant strings don't have `_storage`, they have to allocate * it on the first access. Strings created at runtime just set the * pointer to `&_storage`. */ struct OFUTF8StringIvars { char *cString; size_t cStringLength; bool isUTF8; size_t length; bool hasHash; unsigned long hash; bool freeWhenDone; } *restrict _s; struct OFUTF8StringIvars _storage; } @end #ifdef __cplusplus extern "C" { #endif extern int OFUTF8StringCheck(const char *, size_t, size_t *); extern size_t OFUTF8StringIndexToPosition(const char *, size_t, size_t); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFUTF8String.m from [0d15ab4aab] to [18e27cfd00].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFArray.h" #import "OFData.h" #import "OFMutableUTF8String.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" | > < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFASPrintF.h" #import "OFArray.h" #import "OFData.h" #import "OFMutableUTF8String.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" #import "unicode.h" extern const OFChar16 OFISO8859_2Table[]; extern const size_t OFISO8859_2TableOffset; extern const OFChar16 OFISO8859_3Table[]; extern const size_t OFISO8859_3TableOffset; extern const OFChar16 OFISO8859_15Table[]; extern const size_t OFISO8859_15TableOffset; extern const OFChar16 OFWindows1251Table[]; extern const size_t OFWindows1251TableOffset; extern const OFChar16 OFWindows1252Table[]; extern const size_t OFWindows1252TableOffset; extern const OFChar16 OFCodepage437Table[]; extern const size_t OFCodepage437TableOffset; extern const OFChar16 OFCodepage850Table[]; extern const size_t OFCodepage850TableOffset; extern const OFChar16 OFCodepage858Table[]; extern const size_t OFCodepage858TableOffset; extern const OFChar16 OFMacRomanTable[]; extern const size_t OFMacRomanTableOffset; extern const OFChar16 OFKOI8RTable[]; extern const size_t OFKOI8RTableOffset; extern const OFChar16 OFKOI8UTable[]; extern const size_t OFKOI8UTableOffset; static inline int memcasecmp(const char *first, const char *second, size_t length) { for (size_t i = 0; i < length; i++) { unsigned char f = first[i]; unsigned char s = second[i]; f = OFASCIIToUpper(f); s = OFASCIIToUpper(s); if (f > s) return OFOrderedDescending; if (f < s) return OFOrderedAscending; } return OFOrderedSame; } int OFUTF8StringCheck(const char *UTF8String, size_t UTF8Length, size_t *length) { size_t tmpLength = UTF8Length; int isUTF8 = 0; for (size_t i = 0; i < UTF8Length; i++) { /* No sign of UTF-8 here */ if OF_LIKELY (!(UTF8String[i] & 0x80)) |
︙ | ︙ | |||
145 146 147 148 149 150 151 | if (length != NULL) *length = tmpLength; return isUTF8; } size_t | | | | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | if (length != NULL) *length = tmpLength; return isUTF8; } size_t positionToIndex(const char *string, size_t position) { size_t idx = position; for (size_t i = 0; i < position; i++) if OF_UNLIKELY ((string[i] & 0xC0) == 0x80) idx--; return idx; } size_t OFUTF8StringIndexToPosition(const char *string, size_t idx, size_t length) { for (size_t i = 0; i <= idx; i++) if OF_UNLIKELY ((string[i] & 0xC0) == 0x80) if (++idx > length) @throw [OFInvalidFormatException exception]; return idx; } @implementation OFUTF8String - (instancetype)init { self = [super init]; @try { _s = &_storage; _s->cString = OFAllocZeroedMemory(1, 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ | |||
203 204 205 206 207 208 209 | } _s = &_storage; _s->cString = storage; _s->cStringLength = UTF8StringLength; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | } _s = &_storage; _s->cString = storage; _s->cStringLength = UTF8StringLength; switch (OFUTF8StringCheck(UTF8String, UTF8StringLength, &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } memcpy(_s->cString, UTF8String, UTF8StringLength); _s->cString[UTF8StringLength] = 0; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)cStringLength { self = [super init]; @try { const OFChar16 *table; size_t tableOffset, j; if (encoding == OFStringEncodingUTF8 && cStringLength >= 3 && memcmp(cString, "\xEF\xBB\xBF", 3) == 0) { cString += 3; cStringLength -= 3; } _s = &_storage; _s->cString = OFAllocMemory(cStringLength + 1, 1); _s->cStringLength = cStringLength; _s->freeWhenDone = true; if (encoding == OFStringEncodingUTF8 || encoding == OFStringEncodingASCII) { switch (OFUTF8StringCheck(cString, cStringLength, &_s->length)) { case 1: if (encoding == OFStringEncodingASCII) @throw [OFInvalidEncodingException exception]; _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } memcpy(_s->cString, cString, cStringLength); _s->cString[cStringLength] = 0; return self; } /* All other encodings we support are single byte encodings */ _s->length = cStringLength; if (encoding == OFStringEncodingISO8859_1) { j = 0; for (size_t i = 0; i < cStringLength; i++) { char buffer[4]; size_t bytes; if (!(cString[i] & 0x80)) { _s->cString[j++] = cString[i]; continue; } _s->isUTF8 = true; bytes = OFUTF8StringEncode( (uint8_t)cString[i], buffer); if (bytes == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += bytes - 1; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, bytes); j += bytes; } _s->cString[_s->cStringLength] = 0; return self; } switch (encoding) { #define CASE(encoding, var) \ case encoding: \ table = var; \ tableOffset = var##Offset; \ break; #ifdef HAVE_ISO_8859_2 CASE(OFStringEncodingISO8859_2, OFISO8859_2Table) #endif #ifdef HAVE_ISO_8859_3 CASE(OFStringEncodingISO8859_3, OFISO8859_3Table) #endif #ifdef HAVE_ISO_8859_15 CASE(OFStringEncodingISO8859_15, OFISO8859_15Table) #endif #ifdef HAVE_WINDOWS_1251 CASE(OFStringEncodingWindows1251, OFWindows1251Table) #endif #ifdef HAVE_WINDOWS_1252 CASE(OFStringEncodingWindows1252, OFWindows1252Table) #endif #ifdef HAVE_CODEPAGE_437 CASE(OFStringEncodingCodepage437, OFCodepage437Table) #endif #ifdef HAVE_CODEPAGE_850 CASE(OFStringEncodingCodepage850, OFCodepage850Table) #endif #ifdef HAVE_CODEPAGE_858 CASE(OFStringEncodingCodepage858, OFCodepage858Table) #endif #ifdef HAVE_MAC_ROMAN CASE(OFStringEncodingMacRoman, OFMacRomanTable) #endif #ifdef HAVE_KOI8_R CASE(OFStringEncodingKOI8R, OFKOI8RTable) #endif #ifdef HAVE_KOI8_U CASE(OFStringEncodingKOI8U, OFKOI8UTable) #endif #undef CASE default: @throw [OFInvalidEncodingException exception]; } j = 0; for (size_t i = 0; i < cStringLength; i++) { unsigned char character = (unsigned char)cString[i]; OFUnichar unichar; char buffer[4]; size_t byteLength; if (character < tableOffset) { _s->cString[j++] = cString[i]; continue; } unichar = table[character - tableOffset]; if (unichar == 0xFFFF) @throw [OFInvalidEncodingException exception]; _s->isUTF8 = true; byteLength = OFUTF8StringEncode(unichar, buffer); if (byteLength == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += byteLength - 1; _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, byteLength); j += byteLength; } _s->cString[_s->cStringLength] = 0; |
︙ | ︙ | |||
409 410 411 412 413 414 415 | if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } | | | 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | if (UTF8StringLength >= 3 && memcmp(UTF8String, "\xEF\xBB\xBF", 3) == 0) { UTF8String += 3; UTF8StringLength -= 3; } switch (OFUTF8StringCheck(UTF8String, UTF8StringLength, &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } |
︙ | ︙ | |||
446 447 448 449 450 451 452 | [string isKindOfClass: [OFMutableUTF8String class]]) _s->isUTF8 = ((OFUTF8String *)string)->_s->isUTF8; else _s->isUTF8 = true; _s->length = string.length; | | | | | | | | | | | | | | | | | | | | | > | | 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 | [string isKindOfClass: [OFMutableUTF8String class]]) _s->isUTF8 = ((OFUTF8String *)string)->_s->isUTF8; else _s->isUTF8 = true; _s->length = string.length; _s->cString = OFAllocMemory(_s->cStringLength + 1, 1); memcpy(_s->cString, string.UTF8String, _s->cStringLength + 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithCharacters: (const OFUnichar *)characters length: (size_t)length { self = [super init]; @try { size_t j; _s = &_storage; _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { size_t len = OFUTF8StringEncode(characters[i], _s->cString + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) _s->isUTF8 = true; j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF16String: (const OFChar16 *)string length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { size_t j; bool swap = false; if (length > 0 && *string == 0xFEFF) { string++; length--; } else if (length > 0 && *string == 0xFFFE) { swap = true; string++; length--; } else if (byteOrder != OFByteOrderNative) swap = true; _s = &_storage; _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { OFUnichar character = (swap ? OFByteSwap16(string[i]) : string[i]); size_t len; /* Missing high surrogate */ if ((character & 0xFC00) == 0xDC00) @throw [OFInvalidEncodingException exception]; if ((character & 0xFC00) == 0xD800) { OFChar16 nextCharacter; if (length <= i + 1) @throw [OFInvalidEncodingException exception]; nextCharacter = (swap ? OFByteSwap16(string[i + 1]) : string[i + 1]); if ((nextCharacter & 0xFC00) != 0xDC00) @throw [OFInvalidEncodingException exception]; character = (((character & 0x3FF) << 10) | (nextCharacter & 0x3FF)) + 0x10000; i++; _s->length--; } len = OFUTF8StringEncode(character, _s->cString + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) _s->isUTF8 = true; j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF32String: (const OFChar32 *)characters length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { size_t j; bool swap = false; if (length > 0 && *characters == 0xFEFF) { characters++; length--; } else if (length > 0 && *characters == 0xFFFE0000) { swap = true; characters++; length--; } else if (byteOrder != OFByteOrderNative) swap = true; _s = &_storage; _s->cString = OFAllocMemory((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { char buffer[4]; size_t len = OFUTF8StringEncode((swap ? OFByteSwap32(characters[i]) : characters[i]), buffer); switch (len) { case 1: _s->cString[j++] = buffer[0]; break; case 2: |
︙ | ︙ | |||
641 642 643 644 645 646 647 | } } _s->cString[j] = '\0'; _s->cStringLength = j; @try { | | | 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | } } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = OFResizeMemory(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
667 668 669 670 671 672 673 | int cStringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; _s = &_storage; | | | | | | | | | | | | | | | | | | | | | < | | | < | | | < | | | | | | | | | | < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | | | 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 | int cStringLength; if (format == nil) @throw [OFInvalidArgumentException exception]; _s = &_storage; if ((cStringLength = OFVASPrintF(&tmp, format.UTF8String, arguments)) == -1) @throw [OFInvalidFormatException exception]; _s->cStringLength = cStringLength; @try { switch (OFUTF8StringCheck(tmp, cStringLength, &_s->length)) { case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->cString = OFAllocMemory(cStringLength + 1, 1); memcpy(_s->cString, tmp, cStringLength + 1); _s->freeWhenDone = true; } @finally { OFFreeMemory(tmp); } } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_s != NULL && _s->freeWhenDone) OFFreeMemory(_s->cString); [super dealloc]; } - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingASCII: if (_s->isUTF8) @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OFStringEncodingUTF8: if (_s->cStringLength + 1 > maxLength) @throw [OFOutOfRangeException exception]; memcpy(cString, _s->cString, _s->cStringLength + 1); return _s->cStringLength; default: return [super getCString: cString maxLength: maxLength encoding: encoding]; } } - (const char *)cStringWithEncoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingASCII: if (_s->isUTF8) @throw [OFInvalidEncodingException exception]; /* intentional fall-through */ case OFStringEncodingUTF8: return _s->cString; default: return [super cStringWithEncoding: encoding]; } } - (const char *)UTF8String { return _s->cString; } - (size_t)length { return _s->length; } - (size_t)cStringLengthWithEncoding: (OFStringEncoding)encoding { switch (encoding) { case OFStringEncodingUTF8: case OFStringEncodingASCII: return _s->cStringLength; default: return [super cStringLengthWithEncoding: encoding]; } } - (size_t)UTF8StringLength { return _s->cStringLength; } - (bool)isEqual: (id)object { OFUTF8String *string; if (object == self) return true; if (![object isKindOfClass: [OFString class]]) return false; string = object; if (string.UTF8StringLength != _s->cStringLength || string.length != _s->length) return false; if (([string isKindOfClass: [OFUTF8String class]] || [string isKindOfClass: [OFMutableUTF8String class]]) && _s->hasHash && string->_s->hasHash && _s->hash != string->_s->hash) return false; if (strcmp(_s->cString, string.UTF8String) != 0) return false; return true; } - (OFComparisonResult)compare: (OFString *)string { size_t otherCStringLength, minimumCStringLength; int compare; if (string == self) return OFOrderedSame; if (![string isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exception]; otherCStringLength = string.UTF8StringLength; minimumCStringLength = (_s->cStringLength > otherCStringLength ? otherCStringLength : _s->cStringLength); if ((compare = memcmp(_s->cString, string.UTF8String, minimumCStringLength)) == 0) { if (_s->cStringLength > otherCStringLength) return OFOrderedDescending; if (_s->cStringLength < otherCStringLength) return OFOrderedAscending; return OFOrderedSame; } if (compare > 0) return OFOrderedDescending; else return OFOrderedAscending; } - (OFComparisonResult)caseInsensitiveCompare: (OFString *)string { const char *otherCString; size_t otherCStringLength, minimumCStringLength; #ifdef OF_HAVE_UNICODE_TABLES size_t i, j; #endif int compare; if (string == self) return OFOrderedSame; otherCString = string.UTF8String; otherCStringLength = string.UTF8StringLength; #ifdef OF_HAVE_UNICODE_TABLES if (!_s->isUTF8) { #endif minimumCStringLength = (_s->cStringLength > otherCStringLength ? otherCStringLength : _s->cStringLength); if ((compare = memcasecmp(_s->cString, otherCString, minimumCStringLength)) == 0) { if (_s->cStringLength > otherCStringLength) return OFOrderedDescending; if (_s->cStringLength < otherCStringLength) return OFOrderedAscending; return OFOrderedSame; } if (compare > 0) return OFOrderedDescending; else return OFOrderedAscending; #ifdef OF_HAVE_UNICODE_TABLES } i = j = 0; while (i < _s->cStringLength && j < otherCStringLength) { OFUnichar c1, c2; ssize_t l1, l2; l1 = OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c1); l2 = OFUTF8StringDecode(otherCString + j, otherCStringLength - j, &c2); if (l1 <= 0 || l2 <= 0 || c1 > 0x10FFFF || c2 > 0x10FFFF) @throw [OFInvalidEncodingException exception]; if (c1 >> 8 < OFUnicodeCaseFoldingTableSize) { OFUnichar tc = OFUnicodeCaseFoldingTable[c1 >> 8][c1 & 0xFF]; if (tc) c1 = tc; } if (c2 >> 8 < OFUnicodeCaseFoldingTableSize) { OFUnichar tc = OFUnicodeCaseFoldingTable[c2 >> 8][c2 & 0xFF]; if (tc) c2 = tc; } if (c1 > c2) return OFOrderedDescending; if (c1 < c2) return OFOrderedAscending; i += l1; j += l2; } if (_s->cStringLength - i > otherCStringLength - j) return OFOrderedDescending; else if (_s->cStringLength - i < otherCStringLength - j) return OFOrderedAscending; #endif return OFOrderedSame; } - (unsigned long)hash { unsigned long hash; if (_s->hasHash) return _s->hash; OFHashInit(&hash); for (size_t i = 0; i < _s->cStringLength; i++) { OFUnichar c; ssize_t length; if ((length = OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c)) <= 0) @throw [OFInvalidEncodingException exception]; OFHashAdd(&hash, (c & 0xFF0000) >> 16); OFHashAdd(&hash, (c & 0x00FF00) >> 8); OFHashAdd(&hash, c & 0x0000FF); i += length - 1; } OFHashFinalize(&hash); _s->hash = hash; _s->hasHash = true; return hash; } - (OFUnichar)characterAtIndex: (size_t)idx { OFUnichar character; if (idx >= _s->length) @throw [OFOutOfRangeException exception]; if (!_s->isUTF8) return _s->cString[idx]; idx = OFUTF8StringIndexToPosition(_s->cString, idx, _s->cStringLength); if (OFUTF8StringDecode(_s->cString + idx, _s->cStringLength - idx, &character) <= 0) @throw [OFInvalidEncodingException exception]; return character; } - (void)getCharacters: (OFUnichar *)buffer inRange: (OFRange)range { /* TODO: Could be slightly optimized */ void *pool = objc_autoreleasePoolPush(); const OFUnichar *characters = self.characters; if (range.length > SIZE_MAX - range.location || range.location + range.length > _s->length) @throw [OFOutOfRangeException exception]; memcpy(buffer, characters + range.location, range.length * sizeof(OFUnichar)); objc_autoreleasePoolPop(pool); } - (OFRange)rangeOfString: (OFString *)string options: (OFStringSearchOptions)options range: (OFRange)range { const char *cString = string.UTF8String; size_t cStringLength = string.UTF8StringLength; size_t rangeLocation, rangeLength; if (range.length > SIZE_MAX - range.location || range.location + range.length > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { rangeLocation = OFUTF8StringIndexToPosition( _s->cString, range.location, _s->cStringLength); rangeLength = OFUTF8StringIndexToPosition( _s->cString + rangeLocation, range.length, _s->cStringLength - rangeLocation); } else { rangeLocation = range.location; rangeLength = range.length; } if (cStringLength == 0) return OFRangeMake(0, 0); if (cStringLength > rangeLength) return OFRangeMake(OFNotFound, 0); if (options & OFStringSearchBackwards) { for (size_t i = rangeLength - cStringLength;; i--) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += positionToIndex( _s->cString + rangeLocation, i); range.length = string.length; return range; } /* Did not match and we're at the last char */ if (i == 0) return OFRangeMake(OFNotFound, 0); } } else { for (size_t i = 0; i <= rangeLength - cStringLength; i++) { if (memcmp(_s->cString + rangeLocation + i, cString, cStringLength) == 0) { range.location += positionToIndex( _s->cString + rangeLocation, i); range.length = string.length; return range; } } } return OFRangeMake(OFNotFound, 0); } - (bool)containsString: (OFString *)string { const char *cString = string.UTF8String; size_t cStringLength = string.UTF8StringLength; if (cStringLength == 0) return true; if (cStringLength > _s->cStringLength) return false; for (size_t i = 0; i <= _s->cStringLength - cStringLength; i++) if (memcmp(_s->cString + i, cString, cStringLength) == 0) return true; return false; } - (OFString *)substringWithRange: (OFRange)range { size_t start = range.location; size_t end = range.location + range.length; if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exception]; if (_s->isUTF8) { start = OFUTF8StringIndexToPosition(_s->cString, start, _s->cStringLength); end = OFUTF8StringIndexToPosition(_s->cString, end, _s->cStringLength); } return [OFString stringWithUTF8String: _s->cString + start length: end - start]; } |
︙ | ︙ | |||
1103 1104 1105 1106 1107 1108 1109 | return false; return (memcmp(_s->cString + (_s->cStringLength - cStringLength), suffix.UTF8String, cStringLength) == 0); } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter | | | | 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | return false; return (memcmp(_s->cString + (_s->cStringLength - cStringLength), suffix.UTF8String, cStringLength) == 0); } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter options: (OFStringSeparationOptions)options { void *pool; OFMutableArray *array; const char *cString; size_t cStringLength; bool skipEmpty = (options & OFStringSkipEmptyComponents); size_t last; OFString *component; if (delimiter == nil) @throw [OFInvalidArgumentException exception]; if (delimiter.length == 0) |
︙ | ︙ | |||
1155 1156 1157 1158 1159 1160 1161 | [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } | | | | | | | | | | | | | | | | | < | > | 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 | [array makeImmutable]; objc_autoreleasePoolPop(pool); return array; } - (const OFUnichar *)characters { OFUnichar *buffer = OFAllocMemory(_s->length, sizeof(OFUnichar)); size_t i = 0, j = 0; while (i < _s->cStringLength) { OFUnichar c; ssize_t cLen; cLen = OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } buffer[j++] = c; i += cLen; } return [[OFData dataWithItemsNoCopy: buffer count: _s->length itemSize: sizeof(OFUnichar) freeWhenDone: true] items]; } - (const OFChar32 *)UTF32StringWithByteOrder: (OFByteOrder)byteOrder { OFChar32 *buffer = OFAllocMemory(_s->length + 1, sizeof(OFChar32)); size_t i = 0, j = 0; while (i < _s->cStringLength) { OFChar32 c; ssize_t cLen; cLen = OFUTF8StringDecode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { OFFreeMemory(buffer); @throw [OFInvalidEncodingException exception]; } if (byteOrder != OFByteOrderNative) buffer[j++] = OFByteSwap32(c); else buffer[j++] = c; i += cLen; } buffer[j] = 0; return [[OFData dataWithItemsNoCopy: buffer count: _s->length + 1 itemSize: sizeof(OFChar32) freeWhenDone: true] items]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (OFStringLineEnumerationBlock)block { void *pool; const char *cString = _s->cString; const char *last = cString; bool stop = false, lastCarriageReturn = false; while (!stop && *cString != 0) { if (lastCarriageReturn && *cString == '\n') { lastCarriageReturn = false; cString++; last++; continue; } if (*cString == '\n' || *cString == '\r') { pool = objc_autoreleasePoolPush(); block([OFString stringWithUTF8String: last length: cString - last], &stop); last = cString + 1; objc_autoreleasePoolPop(pool); } lastCarriageReturn = (*cString == '\r'); cString++; |
︙ | ︙ |
Modified src/OFValue.h from [dc50b95f98] to [df3acd707a].
︙ | ︙ | |||
43 44 45 46 47 48 49 | * @brief The value as a non-retained object. * * If the value is not pointer-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) id nonretainedObjectValue; /** | | | | | | | | | | | | | | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | * @brief The value as a non-retained object. * * If the value is not pointer-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) id nonretainedObjectValue; /** * @brief The value as an OFRange. * * If the value is not OFRange-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) OFRange rangeValue; /** * @brief The value as an OFPoint. * * If the value is not OFPoint-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) OFPoint pointValue; /** * @brief The value as an OFSize. * * If the value is not OFSize-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) OFSize sizeValue; /** * @brief The value as a OFRect. * * If the value is not OFRect-sized, @ref OFOutOfRangeException is thrown. */ @property (readonly, nonatomic) OFRect rectValue; /** * @brief Creates a new, autorelease OFValue with the specified bytes of the * specified type. * * @param bytes The bytes containing the value * @param objCType The ObjC type encoding for the value |
︙ | ︙ | |||
109 110 111 112 113 114 115 | /** * @brief Creates a new, autoreleased OFValue containing the specified range. * * @param range The range the OFValue should contain * @return A new, autoreleased OFValue */ | | | | < | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < | 109 110 111 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 163 164 165 166 167 168 169 170 171 | /** * @brief Creates a new, autoreleased OFValue containing the specified range. * * @param range The range the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithRange: (OFRange)range; /** * @brief Creates a new, autoreleased OFValue containing the specified point. * * @param point The point the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithPoint: (OFPoint)point; /** * @brief Creates a new, autoreleased OFValue containing the specified size. * * @param size The size the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithSize: (OFSize)size; /** * @brief Creates a new, autoreleased OFValue containing the specified * rectangle. * * @param rect The rectangle the OFValue should contain * @return A new, autoreleased OFValue */ + (instancetype)valueWithRect: (OFRect)rect; /** * @brief Initializes an already allocated OFValue with the specified bytes of * the specified type. * * @param bytes The bytes containing the value * @param objCType The ObjC type encoding for the value * @return An initialized OFValue */ - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType; /** * @brief Gets the value. * * If the specified size does not match, this raises an * @ref OFOutOfRangeException. * * @param value The buffer to copy the value into * @param size The size of the value */ - (void)getValue: (void *)value size: (size_t)size; @end OF_ASSUME_NONNULL_END #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules) /* Required for array literals to work */ @compatibility_alias NSValue OFValue; #endif |
Modified src/OFValue.m from [1c056221ee] to [2892e2bc96].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFValue.h" #import "OFBytesValue.h" | < | > < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | > | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFValue.h" #import "OFBytesValue.h" #import "OFMethodSignature.h" #import "OFNonretainedObjectValue.h" #import "OFPointValue.h" #import "OFPointerValue.h" #import "OFRangeValue.h" #import "OFRectValue.h" #import "OFSizeValue.h" #import "OFString.h" #import "OFOutOfMemoryException.h" @implementation OFValue + (instancetype)alloc { if (self == [OFValue class]) return [OFBytesValue alloc]; return [super alloc]; } + (instancetype)valueWithBytes: (const void *)bytes objCType: (const char *)objCType { return [[[OFBytesValue alloc] initWithBytes: bytes objCType: objCType] autorelease]; } + (instancetype)valueWithPointer: (const void *)pointer { return [[[OFPointerValue alloc] initWithPointer: pointer] autorelease]; } + (instancetype)valueWithNonretainedObject: (id)object { return [[[OFNonretainedObjectValue alloc] initWithNonretainedObject: object] autorelease]; } + (instancetype)valueWithRange: (OFRange)range { return [[[OFRangeValue alloc] initWithRange: range] autorelease]; } + (instancetype)valueWithPoint: (OFPoint)point { return [[[OFPointValue alloc] initWithPoint: point] autorelease]; } + (instancetype)valueWithSize: (OFSize)size { return [[[OFSizeValue alloc] initWithSize: size] autorelease]; } + (instancetype)valueWithRect: (OFRect)rect { return [[[OFRectValue alloc] initWithRect: rect] autorelease]; } - (instancetype)initWithBytes: (const void *)bytes objCType: (const char *)objCType { OF_INVALID_INIT_METHOD } - (bool)isEqual: (id)object { const char *objCType; size_t size; |
︙ | ︙ | |||
175 176 177 178 179 180 181 | return false; objCType = self.objCType; if (strcmp([object objCType], objCType) != 0) return false; | | | | | | < | < < | | | | | | < | | | | | < < | < < < | < < | < | | < < | | < < | < | | < | < < | | < | < < | | | < | | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | return false; objCType = self.objCType; if (strcmp([object objCType], objCType) != 0) return false; size = OFSizeOfTypeEncoding(objCType); value = OFAllocMemory(1, size); @try { otherValue = OFAllocMemory(1, size); } @catch (id e) { OFFreeMemory(value); @throw e; } @try { [self getValue: value size: size]; [object getValue: otherValue size: size]; ret = (memcmp(value, otherValue, size) == 0); } @finally { OFFreeMemory(value); OFFreeMemory(otherValue); } return ret; } - (unsigned long)hash { size_t size = OFSizeOfTypeEncoding(self.objCType); unsigned char *value; unsigned long hash; value = OFAllocMemory(1, size); @try { [self getValue: value size: size]; OFHashInit(&hash); for (size_t i = 0; i < size; i++) OFHashAdd(&hash, value[i]); OFHashFinalize(&hash); } @finally { OFFreeMemory(value); } return hash; } - (id)copy { return [self retain]; } - (const char *)objCType { OF_UNRECOGNIZED_SELECTOR } - (void)getValue: (void *)value size: (size_t)size { OF_UNRECOGNIZED_SELECTOR } - (void *)pointerValue { void *ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (id)nonretainedObjectValue { id ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFRange)rangeValue { OFRange ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFPoint)pointValue { OFPoint ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFSize)sizeValue { OFSize ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFRect)rectValue { OFRect ret; [self getValue: &ret size: sizeof(ret)]; return ret; } - (OFString *)description { OFMutableString *ret = [OFMutableString stringWithString: @"<OFValue: "]; size_t size = OFSizeOfTypeEncoding(self.objCType); unsigned char *value; value = OFAllocMemory(1, size); @try { [self getValue: value size: size]; for (size_t i = 0; i < size; i++) { if (i > 0) [ret appendString: @" "]; [ret appendFormat: @"%02x", value[i]]; } } @finally { OFFreeMemory(value); } [ret appendString: @">"]; [ret makeImmutable]; return ret; } @end |
Modified src/OFWin32ConsoleStdIOStream.h from [2abff1d7d9] to [fa1a5ee975].
︙ | ︙ | |||
9 10 11 12 13 14 15 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ | < < | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFStdIOStream.h" OF_ASSUME_NONNULL_BEGIN @interface OFWin32ConsoleStdIOStream: OFStdIOStream { HANDLE _handle; WORD _attributes; OFChar16 _incompleteUTF16Surrogate; char _incompleteUTF8Surrogate[4]; size_t _incompleteUTF8SurrogateLen; } @end OF_ASSUME_NONNULL_END |
Modified src/OFWin32ConsoleStdIOStream.m from [fb543571fa] to [dea67afd15].
︙ | ︙ | |||
22 23 24 25 26 27 28 | * For example, on Windows XP, when using Windows XP's console, changing the * codepage to UTF-8 mostly breaks write() and completely breaks read(): * write() suddenly returns the number of characters - instead of bytes - * written and read() just returns 0 as soon as a Unicode character is being * read. * * Therefore, instead of just using the UTF-8 codepage, this captures all reads | | < < | 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 | * For example, on Windows XP, when using Windows XP's console, changing the * codepage to UTF-8 mostly breaks write() and completely breaks read(): * write() suddenly returns the number of characters - instead of bytes - * written and read() just returns 0 as soon as a Unicode character is being * read. * * Therefore, instead of just using the UTF-8 codepage, this captures all reads * and writes to OFStd{In,Out,Err} on the low level, interprets the buffer as * UTF-8 and converts to / from UTF-16 to use ReadConsoleW() / WriteConsoleW(). * Doing so is safe, as the console only supports text anyway and thus it does * not matter if binary gets garbled by the conversion (e.g. because invalid * UTF-8 gets converted to U+FFFD). * * In order to not do this when redirecting input / output to a file (as the * file would then be read / written in the wrong encoding and break reading / * writing binary), it checks that the handle is indeed a console. */ #include "config.h" #include <assert.h> #include <errno.h> #include <io.h> #import "OFWin32ConsoleStdIOStream.h" |
︙ | ︙ | |||
56 57 58 59 60 61 62 | #import "OFInvalidEncodingException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #include <windows.h> | | | | | | | | | | | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #import "OFInvalidEncodingException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #include <windows.h> static OFStringEncoding codepageToEncoding(UINT codepage) { switch (codepage) { case 437: return OFStringEncodingCodepage437; case 850: return OFStringEncodingCodepage850; case 858: return OFStringEncodingCodepage858; case 1251: return OFStringEncodingWindows1251; case 1252: return OFStringEncodingWindows1252; default: @throw [OFInvalidEncodingException exception]; } } @implementation OFWin32ConsoleStdIOStream + (void)load { int fd; if (self != [OFWin32ConsoleStdIOStream class]) return; if ((fd = _fileno(stdin)) >= 0) OFStdIn = [[OFWin32ConsoleStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = _fileno(stdout)) >= 0) OFStdOut = [[OFWin32ConsoleStdIOStream alloc] of_initWithFileDescriptor: fd]; if ((fd = _fileno(stderr)) >= 0) OFStdErr = [[OFWin32ConsoleStdIOStream alloc] of_initWithFileDescriptor: fd]; } - (instancetype)of_initWithFileDescriptor: (int)fd { self = [super of_initWithFileDescriptor: fd]; |
︙ | ︙ | |||
120 121 122 123 124 125 126 | [self release]; @throw e; } return self; } | | < | | | | 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 | [self release]; @throw e; } return self; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer_ length: (size_t)length { void *pool = objc_autoreleasePoolPush(); char *buffer = buffer_; OFChar16 *UTF16; size_t j = 0; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; UTF16 = OFAllocMemory(length, sizeof(OFChar16)); @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; if ([OFSystemInfo isWindowsNT]) { if (!ReadConsoleW(_handle, UTF16, (DWORD)length, &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self requestedLength: length * 2 errNo: EIO]; } else { OFStringEncoding encoding; OFString *string; size_t stringLen; if (!ReadConsoleA(_handle, (char *)UTF16, (DWORD)length, &UTF16Len, NULL)) @throw [OFReadFailedException exceptionWithObject: self |
︙ | ︙ | |||
170 171 172 173 174 175 176 | @throw [OFOutOfRangeException exception]; UTF16Len = (DWORD)stringLen; memcpy(UTF16, string.UTF16String, stringLen); } if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) { | | | | < | | | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | @throw [OFOutOfRangeException exception]; UTF16Len = (DWORD)stringLen; memcpy(UTF16, string.UTF16String, stringLen); } if (UTF16Len > 0 && _incompleteUTF16Surrogate != 0) { OFUnichar c = (((_incompleteUTF16Surrogate & 0x3FF) << 10) | (UTF16[0] & 0x3FF)) + 0x10000; char UTF8[4]; size_t UTF8Len; if ((UTF8Len = OFUTF8StringEncode(c, UTF8)) == 0) @throw [OFInvalidEncodingException exception]; if (UTF8Len <= length) { memcpy(buffer, UTF8, UTF8Len); j += UTF8Len; } else { if (rest == nil) rest = [OFMutableData data]; [rest addItems: UTF8 count: UTF8Len]; } _incompleteUTF16Surrogate = 0; i++; } for (; i < UTF16Len; i++) { OFUnichar c = UTF16[i]; char UTF8[4]; size_t UTF8Len; /* Missing high surrogate */ if ((c & 0xFC00) == 0xDC00) @throw [OFInvalidEncodingException exception]; if ((c & 0xFC00) == 0xD800) { OFChar16 next; if (UTF16Len <= i + 1) { _incompleteUTF16Surrogate = c; if (rest != nil) { const char *items = rest.items; size_t count = rest.count; |
︙ | ︙ | |||
234 235 236 237 238 239 240 | c = (((c & 0x3FF) << 10) | (next & 0x3FF)) + 0x10000; i++; } | | | < | < | | < | | | | | | | 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | c = (((c & 0x3FF) << 10) | (next & 0x3FF)) + 0x10000; i++; } if ((UTF8Len = OFUTF8StringEncode(c, UTF8)) == 0) @throw [OFInvalidEncodingException exception]; if (j + UTF8Len <= length) { memcpy(buffer + j, UTF8, UTF8Len); j += UTF8Len; } else { if (rest == nil) rest = [OFMutableData data]; [rest addItems: UTF8 count: UTF8Len]; } } if (rest != nil) [self unreadFromBuffer: rest.items length: rest.count]; } @finally { OFFreeMemory(UTF16); } objc_autoreleasePoolPop(pool); return j; } - (size_t)lowlevelWriteBuffer: (const void *)buffer_ length: (size_t)length { const char *buffer = buffer_; OFChar16 *tmp; size_t i = 0, j = 0; if (length > SIZE_MAX / 2) @throw [OFOutOfRangeException exception]; if (_incompleteUTF8SurrogateLen > 0) { OFUnichar c; OFChar16 UTF16[2]; ssize_t UTF8Len; size_t toCopy; DWORD UTF16Len, bytesWritten; UTF8Len = -OFUTF8StringDecode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); OFEnsure(UTF8Len > 0); toCopy = UTF8Len - _incompleteUTF8SurrogateLen; if (toCopy > length) toCopy = length; memcpy(_incompleteUTF8Surrogate + _incompleteUTF8SurrogateLen, buffer, toCopy); _incompleteUTF8SurrogateLen += toCopy; if (_incompleteUTF8SurrogateLen < (size_t)UTF8Len) return 0; UTF8Len = OFUTF8StringDecode( _incompleteUTF8Surrogate, _incompleteUTF8SurrogateLen, &c); if (UTF8Len <= 0 || c > 0x10FFFF) { assert(UTF8Len == 0 || UTF8Len < -4); UTF16[0] = 0xFFFD; UTF16Len = 1; |
︙ | ︙ | |||
327 328 329 330 331 332 333 | bytesWritten: bytesWritten * 2 errNo: EIO]; } else { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithUTF16String: UTF16 length: UTF16Len]; | | | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | bytesWritten: bytesWritten * 2 errNo: EIO]; } else { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithUTF16String: UTF16 length: UTF16Len]; OFStringEncoding encoding = codepageToEncoding(GetConsoleOutputCP()); size_t nativeLen = [string cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
358 359 360 361 362 363 364 | bytesWritten: bytesWritten * 2 errNo: 0]; _incompleteUTF8SurrogateLen = 0; i += toCopy; } | | | | | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | bytesWritten: bytesWritten * 2 errNo: 0]; _incompleteUTF8SurrogateLen = 0; i += toCopy; } tmp = OFAllocMemory(length * 2, sizeof(OFChar16)); @try { DWORD bytesWritten; while (i < length) { OFUnichar c; ssize_t UTF8Len; UTF8Len = OFUTF8StringDecode(buffer + i, length - i, &c); if (UTF8Len < 0 && UTF8Len >= -4) { OFEnsure(length - i < 4); memcpy(_incompleteUTF8Surrogate, buffer + i, length - i); _incompleteUTF8SurrogateLen = length - i; break; } |
︙ | ︙ | |||
410 411 412 413 414 415 416 | requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; } else { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithUTF16String: tmp length: j]; | | | 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 | requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: EIO]; } else { void *pool = objc_autoreleasePoolPush(); OFString *string = [OFString stringWithUTF16String: tmp length: j]; OFStringEncoding encoding = codepageToEncoding(GetConsoleOutputCP()); size_t nativeLen = [string cStringLengthWithEncoding: encoding]; if (nativeLen > UINT32_MAX) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
437 438 439 440 441 442 443 | if (bytesWritten != j) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { | | | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | if (bytesWritten != j) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { OFFreeMemory(tmp); } /* * We do not count in bytes when writing to the Win32 console. But * since any incomplete write is an exception here anyway, we can just * return length. */ |
︙ | ︙ | |||
487 488 489 490 491 492 493 | if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.wAttributes &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); | | < < < | 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.wAttributes &= ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY); [color getRed: &red green: &green blue: &blue alpha: NULL]; if (red >= 0.25) csbi.wAttributes |= FOREGROUND_RED; if (green >= 0.25) csbi.wAttributes |= FOREGROUND_GREEN; if (blue >= 0.25) csbi.wAttributes |= FOREGROUND_BLUE; |
︙ | ︙ | |||
516 517 518 519 520 521 522 | if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.wAttributes &= ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY); | | < < < | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.wAttributes &= ~(BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY); [color getRed: &red green: &green blue: &blue alpha: NULL]; if (red >= 0.25) csbi.wAttributes |= BACKGROUND_RED; if (green >= 0.25) csbi.wAttributes |= BACKGROUND_GREEN; if (blue >= 0.25) csbi.wAttributes |= BACKGROUND_BLUE; |
︙ | ︙ | |||
589 590 591 592 593 594 595 | return; csbi.dwCursorPosition.X = column; SetConsoleCursorPosition(_handle, csbi.dwCursorPosition); } | | | | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | return; csbi.dwCursorPosition.X = column; SetConsoleCursorPosition(_handle, csbi.dwCursorPosition); } - (void)setCursorPosition: (OFPoint)position { if (position.x < 0 || position.y < 0) @throw [OFInvalidArgumentException exception]; SetConsoleCursorPosition(_handle, (COORD){ position.x, position.y }); } - (void)setRelativeCursorPosition: (OFPoint)position { CONSOLE_SCREEN_BUFFER_INFO csbi; if (!GetConsoleScreenBufferInfo(_handle, &csbi)) return; csbi.dwCursorPosition.X += position.x; csbi.dwCursorPosition.Y += position.y; SetConsoleCursorPosition(_handle, csbi.dwCursorPosition); } @end |
Modified src/OFWindowsRegistryKey.h from [98ae2dd014] to [0f79595dd4].
︙ | ︙ | |||
132 133 134 135 136 137 138 | securityAndAccessRights: (REGSAM)securityAndAccessRights securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes disposition: (nullable DWORD *)disposition; /** * @brief Returns the data for the specified value at the specified path. * | | | | | | | | | | | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | securityAndAccessRights: (REGSAM)securityAndAccessRights securityAttributes: (nullable SECURITY_ATTRIBUTES *)securityAttributes disposition: (nullable DWORD *)disposition; /** * @brief Returns the data for the specified value at the specified path. * * @param name The name of the value to return * @param type A pointer to store the type of the value, or NULL * @return The data for the specified value */ - (nullable OFData *)dataForValueNamed: (nullable OFString *)name type: (nullable DWORD *)type; /** * @brief Sets the data for the specified value. * * @param data The data to set the value to * @param name The name of the value to set * @param type The type for the value */ - (void)setData: (nullable OFData *)data forValueNamed: (nullable OFString *)name type: (DWORD)type; /** * @brief Returns the string for the specified value at the specified path. * * @param name The name of the value to return * @return The string for the specified value */ - (nullable OFString *)stringForValueNamed: (nullable OFString *)name; /** * @brief Returns the string for the specified value at the specified path. * * @param name The name of the value to return * @param type A pointer to store the type of the value, or NULL * @return The string for the specified value */ - (nullable OFString *)stringForValueNamed: (nullable OFString *)name type: (nullable DWORD *)type; /** * @brief Sets the string for the specified value. * * @param string The string to set the value to * @param name The name of the value to set */ - (void)setString: (nullable OFString *)string forValueNamed: (nullable OFString *)name; /** * @brief Sets the string for the specified value. * * @param string The string to set the value to * @param name The name of the value to set * @param type The type for the value */ - (void)setString: (nullable OFString *)string forValueNamed: (nullable OFString *)name type: (DWORD)type; /** * @brief Deletes the specified value. * * @param name The value to delete */ - (void)deleteValueNamed: (nullable OFString *)name; /** * @brief Deletes the specified subkey. * * @param subkeyPath The path of the subkey to delete */ - (void)deleteSubkeyAtPath: (OFString *)subkeyPath; |
︙ | ︙ |
Modified src/OFWindowsRegistryKey.m from [ccda58f080] to [c8ce2ece61].
︙ | ︙ | |||
30 31 32 33 34 35 36 | #import "OFInvalidFormatException.h" #import "OFOpenWindowsRegistryKeyFailedException.h" #import "OFOutOfRangeException.h" #import "OFSetWindowsRegistryValueFailedException.h" OF_DIRECT_MEMBERS @interface OFWindowsRegistryKey () | | < | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #import "OFInvalidFormatException.h" #import "OFOpenWindowsRegistryKeyFailedException.h" #import "OFOutOfRangeException.h" #import "OFSetWindowsRegistryValueFailedException.h" OF_DIRECT_MEMBERS @interface OFWindowsRegistryKey () - (instancetype)of_initWithHKey: (HKEY)hKey close: (bool)close; @end @implementation OFWindowsRegistryKey + (instancetype)classesRootKey { return [[[self alloc] of_initWithHKey: HKEY_CLASSES_ROOT close: false] autorelease]; |
︙ | ︙ | |||
65 66 67 68 69 70 71 | + (instancetype)usersKey { return [[[self alloc] of_initWithHKey: HKEY_USERS close: false] autorelease]; } | | < | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | + (instancetype)usersKey { return [[[self alloc] of_initWithHKey: HKEY_USERS close: false] autorelease]; } - (instancetype)of_initWithHKey: (HKEY)hKey close: (bool)close { self = [super init]; _hKey = hKey; _close = close; return self; |
︙ | ︙ | |||
181 182 183 184 185 186 187 | objc_autoreleasePoolPop(pool); return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey close: true] autorelease]; } | | < | | | 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | objc_autoreleasePoolPop(pool); return [[[OFWindowsRegistryKey alloc] of_initWithHKey: subKey close: true] autorelease]; } - (OFData *)dataForValueNamed: (OFString *)name type: (DWORD *)type { void *pool = objc_autoreleasePoolPush(); BYTE stackBuffer[256], *buffer = stackBuffer; DWORD length = sizeof(stackBuffer); OFMutableData *ret = nil; bool winNT = [OFSystemInfo isWindowsNT]; LSTATUS status; for (;;) { if (winNT) status = RegQueryValueExW(_hKey, name.UTF16String, NULL, type, buffer, &length); else status = RegQueryValueExA(_hKey, [name cStringWithEncoding: [OFLocale encoding]], NULL, type, buffer, &length); switch (status) { case ERROR_SUCCESS: if (buffer == stackBuffer) { objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
231 232 233 234 235 236 237 | [ret increaseCountBy: length]; buffer = ret.mutableItems; continue; default: @throw [OFGetWindowsRegistryValueFailedException exceptionWithRegistryKey: self | | | | | | | | < | < | < | | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | [ret increaseCountBy: length]; buffer = ret.mutableItems; continue; default: @throw [OFGetWindowsRegistryValueFailedException exceptionWithRegistryKey: self valueName: name status: status]; } } } - (void)setData: (OFData *)data forValueNamed: (OFString *)name type: (DWORD)type { size_t length = data.count * data.itemSize; LSTATUS status; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; if ([OFSystemInfo isWindowsNT]) status = RegSetValueExW(_hKey, name.UTF16String, 0, type, data.items, (DWORD)length); else status = RegSetValueExA(_hKey, [name cStringWithEncoding: [OFLocale encoding]], 0, type, data.items, (DWORD)length); if (status != ERROR_SUCCESS) @throw [OFSetWindowsRegistryValueFailedException exceptionWithRegistryKey: self valueName: name data: data type: type status: status]; } - (OFString *)stringForValueNamed: (OFString *)name { return [self stringForValueNamed: name type: NULL]; } - (OFString *)stringForValueNamed: (OFString *)name type: (DWORD *)typeOut { void *pool = objc_autoreleasePoolPush(); DWORD type; OFData *data = [self dataForValueNamed: name type: &type]; OFString *ret; if (data == nil) return nil; if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_LINK) @throw [OFInvalidEncodingException exception]; if (data.itemSize != 1) @throw [OFInvalidFormatException exception]; if ([OFSystemInfo isWindowsNT]) { const OFChar16 *UTF16String = data.items; size_t length = data.count; if (length % 2 == 1) @throw [OFInvalidFormatException exception]; length /= 2; |
︙ | ︙ | |||
338 339 340 341 342 343 344 | *typeOut = type; objc_autoreleasePoolPop(pool); return [ret autorelease]; } | | < | < < | | | | < | < < | | | | | 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | *typeOut = type; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (void)setString: (OFString *)string forValueNamed: (OFString *)name { [self setString: string forValueNamed: name type: REG_SZ]; } - (void)setString: (OFString *)string forValueNamed: (OFString *)name type: (DWORD)type { void *pool = objc_autoreleasePoolPush(); OFData *data; if ([OFSystemInfo isWindowsNT]) data = [OFData dataWithItems: string.UTF16String count: string.UTF16StringLength + 1 itemSize: sizeof(OFChar16)]; else { OFStringEncoding encoding = [OFLocale encoding]; const char *cString = [string cStringWithEncoding: encoding]; size_t length = [string cStringLengthWithEncoding: encoding]; data = [OFData dataWithItems: cString count: length + 1]; } [self setData: data forValueNamed: name type: type]; objc_autoreleasePoolPop(pool); } - (void)deleteValueNamed: (OFString *)name { void *pool = objc_autoreleasePoolPush(); LSTATUS status; if ([OFSystemInfo isWindowsNT]) status = RegDeleteValueW(_hKey, name.UTF16String); else status = RegDeleteValueA(_hKey, [name cStringWithEncoding: [OFLocale encoding]]); if (status != ERROR_SUCCESS) @throw [OFDeleteWindowsRegistryValueFailedException exceptionWithRegistryKey: self valueName: name status: status]; objc_autoreleasePoolPop(pool); } - (void)deleteSubkeyAtPath: (OFString *)subkeyPath { |
︙ | ︙ |
Modified src/OFXMLAttribute.m from [29268ae3e9] to [21dca426df].
︙ | ︙ | |||
72 73 74 75 76 77 78 | { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || | | | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _name = [[element attributeForName: @"name"].stringValue copy]; _namespace = [[element attributeForName: @"namespace"] .stringValue copy]; _stringValue = [[element attributeForName: @"stringValue"] .stringValue copy]; |
︙ | ︙ | |||
136 137 138 139 140 141 142 | return false; return true; } - (unsigned long)hash { | | | | | | | | < | < | 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 163 164 165 166 167 168 169 170 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _namespace.hash); OFHashAddHash(&hash, _stringValue.hash); OFHashFinalize(&hash); return hash; } - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS]; [element addAttributeWithName: @"name" stringValue: _name]; if (_namespace != nil) [element addAttributeWithName: @"namespace" stringValue: _namespace]; [element addAttributeWithName: @"stringValue" stringValue: _stringValue]; |
︙ | ︙ |
Modified src/OFXMLCDATA.m from [f763238cef] to [22eb5b46a5].
︙ | ︙ | |||
46 47 48 49 50 51 52 | { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _CDATA = [element.stringValue copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; |
︙ | ︙ | |||
118 119 120 121 122 123 124 | - (OFString *)XMLStringWithIndentation: (unsigned int)indentation { return self.XMLString; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation | | | | 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 | - (OFString *)XMLStringWithIndentation: (unsigned int)indentation { return self.XMLString; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { return self.XMLString; } - (OFString *)description { return self.XMLString; } - (OFXMLElement *)XMLElementBySerializing { OFXMLElement *element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS]; [element addChild: self]; return element; } @end |
Modified src/OFXMLCharacters.m from [e5ae18f07a] to [f6eb447f0f].
︙ | ︙ | |||
46 47 48 49 50 51 52 | { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _characters = [element.stringValue copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | { return _characters.stringByXMLEscaping; } - (OFXMLElement *)XMLElementBySerializing { return [OFXMLElement elementWithName: self.className | | | 123 124 125 126 127 128 129 130 131 132 133 | { return _characters.stringByXMLEscaping; } - (OFXMLElement *)XMLElementBySerializing { return [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: _characters]; } @end |
Modified src/OFXMLComment.h from [bf4f3dc402] to [48d39c6a70].
︙ | ︙ | |||
20 21 22 23 24 25 26 | /** * @class OFXMLComment OFXMLComment.h ObjFW/OFXMLComment.h * * @brief A class for representing XML comments. */ @interface OFXMLComment: OFXMLNode { | | > > > > > | | | | | | | 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 | /** * @class OFXMLComment OFXMLComment.h ObjFW/OFXMLComment.h * * @brief A class for representing XML comments. */ @interface OFXMLComment: OFXMLNode { OFString *_text; OF_RESERVE_IVARS(OFXMLComment, 4) } /** * @brief The comment text. */ @property (readonly, nonatomic) OFString *text; /** * @brief Creates a new OFXMLComment with the specified text. * * @param text The text for the comment * @return A new OFXMLComment */ + (instancetype)commentWithText: (OFString *)text; /** * @brief Initializes an already allocated OFXMLComment with the specified * text. * * @param text The text for the comment * @return An initialized OFXMLComment */ - (instancetype)initWithText: (OFString *)text; - (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END |
Modified src/OFXMLComment.m from [5cb4fa05d6] to [ba94b5bb12].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "OFXMLNode+Private.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" @implementation OFXMLComment | > > | | | | | | | | | | | | | < | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #import "OFXMLNode+Private.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" @implementation OFXMLComment @synthesize text = _text; + (instancetype)commentWithText: (OFString *)text { return [[[self alloc] initWithText: text] autorelease]; } - (instancetype)initWithText: (OFString *)text { self = [super of_init]; @try { _text = [text copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { self = [super of_init]; @try { void *pool = objc_autoreleasePoolPush(); if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _text = [element.stringValue copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_text release]; [super dealloc]; } - (bool)isEqual: (id)object { OFXMLComment *comment; if (object == self) return true; if (![object isKindOfClass: [OFXMLComment class]]) return false; comment = object; return ([comment->_text isEqual: _text]); } - (unsigned long)hash { return _text.hash; } - (OFString *)stringValue { return @""; } - (OFString *)XMLString { return [OFString stringWithFormat: @"<!--%@-->", _text]; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation { return [OFString stringWithFormat: @"<!--%@-->", _text]; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { char *whitespaces = OFAllocMemory((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s<!--%@-->", whitespaces, _text]; } @finally { OFFreeMemory(whitespaces); } } else ret = [OFString stringWithFormat: @"<!--%@-->", _text]; return ret; } - (OFString *)description { return [OFString stringWithFormat: @"<!--%@-->", _text]; } - (OFXMLElement *)XMLElementBySerializing { return [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: _text]; } @end |
Modified src/OFXMLElement+Serialization.m from [e82061841d] to [805366e391].
︙ | ︙ | |||
28 29 30 31 32 33 34 | - (id)objectByDeserializing { void *pool = objc_autoreleasePoolPush(); Class class; id object; if ((class = objc_getClass([_name cStringWithEncoding: | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | - (id)objectByDeserializing { void *pool = objc_autoreleasePoolPush(); Class class; id object; if ((class = objc_getClass([_name cStringWithEncoding: OFStringEncodingASCII])) == Nil) @throw [OFInvalidArgumentException exception]; if (![class conformsToProtocol: @protocol(OFSerialization)]) @throw [OFInvalidArgumentException exception]; object = [[class alloc] initWithSerialization: self]; |
︙ | ︙ |
Modified src/OFXMLElement.h from [c1a14c4328] to [28fb815e61].
︙ | ︙ | |||
228 229 230 231 232 233 234 | /** * @brief Sets a prefix for a namespace. * * @param prefix The prefix for the namespace * @param namespace_ The namespace for which the prefix is set */ | | < | < | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | /** * @brief Sets a prefix for a namespace. * * @param prefix The prefix for the namespace * @param namespace_ The namespace for which the prefix is set */ - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace_; /** * @brief Binds a prefix for a namespace. * * @param prefix The prefix for the namespace * @param namespace_ The namespace for which the prefix is bound */ - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace_; /** * @brief Adds the specified attribute. * * If an attribute with the same name and namespace already exists, it is not * added. * |
︙ | ︙ | |||
324 325 326 327 328 329 330 | /** * @brief Inserts a child at the specified index. * * @param child An OFXMLNode which is added as a child * @param index The index where the child is added */ | | < | 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | /** * @brief Inserts a child at the specified index. * * @param child An OFXMLNode which is added as a child * @param index The index where the child is added */ - (void)insertChild: (OFXMLNode *)child atIndex: (size_t)index; /** * @brief Inserts the specified children at the specified index. * * @param children An array of OFXMLNodes which are added as children * @param index The index where the child is added */ |
︙ | ︙ | |||
357 358 359 360 361 362 363 | /** * @brief Replaces the first child that is equal to the specified OFXMLNode * with the specified node. * * @param child The child to replace * @param node The node to replace the child with */ | | < | < | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | /** * @brief Replaces the first child that is equal to the specified OFXMLNode * with the specified node. * * @param child The child to replace * @param node The node to replace the child with */ - (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node; /** * @brief Replaces the child at the specified index with the specified node. * * @param index The index of the child to replace * @param node The node to replace the child with */ - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode *)node; /** * @brief Returns all children that have the specified namespace. * * @return All children that have the specified namespace */ - (OFArray OF_GENERIC(OFXMLElement *) *)elementsForNamespace: |
︙ | ︙ |
Modified src/OFXMLElement.m from [c1c758c150] to [7a0a61d375].
︙ | ︙ | |||
121 122 123 124 125 126 127 | - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name { | | < < | < < | 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 | - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithName: (OFString *)name { return [self initWithName: name namespace: nil stringValue: nil]; } - (instancetype)initWithName: (OFString *)name stringValue: (OFString *)stringValue { return [self initWithName: name namespace: nil stringValue: stringValue]; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace { return [self initWithName: name namespace: namespace stringValue: nil]; } - (instancetype)initWithName: (OFString *)name namespace: (OFString *)namespace stringValue: (OFString *)stringValue { self = [super of_init]; |
︙ | ︙ | |||
208 209 210 211 212 213 214 | if (string == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | if (string == nil) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; [parser parseString: string]; |
︙ | ︙ | |||
239 240 241 242 243 244 245 | OFXMLElementElementBuilderDelegate *delegate; [self release]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; | | | 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | OFXMLElementElementBuilderDelegate *delegate; [self release]; pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder builder]; delegate = [[[OFXMLElementElementBuilderDelegate alloc] init] autorelease]; parser.delegate = builder; builder.delegate = delegate; [parser parseStream: stream]; |
︙ | ︙ | |||
270 271 272 273 274 275 276 | void *pool = objc_autoreleasePoolPush(); OFXMLElement *attributesElement, *namespacesElement; OFXMLElement *childrenElement; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; if (![element.name isEqual: self.className] || | | | | | | | | | 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | void *pool = objc_autoreleasePoolPush(); OFXMLElement *attributesElement, *namespacesElement; OFXMLElement *childrenElement; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; _name = [[element attributeForName: @"name"].stringValue copy]; _namespace = [[element attributeForName: @"namespace"] .stringValue copy]; _defaultNamespace = [[element attributeForName: @"defaultNamespace"].stringValue copy]; attributesElement = [[element elementForName: @"attributes" namespace: OFSerializationNS] elementsForNamespace: OFSerializationNS].firstObject; namespacesElement = [[element elementForName: @"namespaces" namespace: OFSerializationNS] elementsForNamespace: OFSerializationNS].firstObject; childrenElement = [[element elementForName: @"children" namespace: OFSerializationNS] elementsForNamespace: OFSerializationNS].firstObject; _attributes = [attributesElement.objectByDeserializing mutableCopy]; _namespaces = [namespacesElement.objectByDeserializing mutableCopy]; _children = [childrenElement.objectByDeserializing mutableCopy]; |
︙ | ︙ | |||
434 435 436 437 438 439 440 | OFMutableDictionary *tmp; OFString *key, *object; tmp = [[allNS mutableCopy] autorelease]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) | | < | | | | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | OFMutableDictionary *tmp; OFString *key, *object; tmp = [[allNS mutableCopy] autorelease]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [tmp setObject: object forKey: key]; allNS = tmp; } else allNS = _namespaces; prefix = [allNS objectForKey: (_namespace != nil ? _namespace : (OFString *)@"")]; if (parent != nil && parent->_namespace != nil && parentPrefix == nil) defaultNS = parent->_namespace; else if (parent != nil && parent->_defaultNamespace != nil) defaultNS = parent->_defaultNamespace; else defaultNS = _defaultNamespace; i = 0; length = _name.UTF8StringLength + 3 + (level * indentation); cString = OFAllocMemory(length, 1); @try { memset(cString + i, ' ', level * indentation); i += level * indentation; /* Start of tag */ cString[i++] = '<'; if (prefix != nil && ![_namespace isEqual: defaultNS]) { length += prefix.UTF8StringLength + 1; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); i += _name.UTF8StringLength; /* xmlns if necessary */ if (prefix == nil && ((_namespace != nil && ![_namespace isEqual: defaultNS]) || (_namespace == nil && defaultNS != nil))) { length += _namespace.UTF8StringLength + 9; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, " xmlns='", 8); i += 8; memcpy(cString + i, _namespace.UTF8String, _namespace.UTF8StringLength); i += _namespace.UTF8StringLength; cString[i++] = '\''; |
︙ | ︙ | |||
513 514 515 516 517 518 519 | @throw [OFUnboundNamespaceException exceptionWithNamespace: attribute.namespace element: self]; length += attributeNameLength + (attributePrefix != nil ? attributePrefix.UTF8StringLength + 1 : 0) + tmp.UTF8StringLength + 4; | | | 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | @throw [OFUnboundNamespaceException exceptionWithNamespace: attribute.namespace element: self]; length += attributeNameLength + (attributePrefix != nil ? attributePrefix.UTF8StringLength + 1 : 0) + tmp.UTF8StringLength + 4; cString = OFResizeMemory(cString, length, 1); cString[i++] = ' '; if (attributePrefix != nil) { memcpy(cString + i, attributePrefix.UTF8String, attributePrefix.UTF8StringLength); i += attributePrefix.UTF8StringLength; cString[i++] = ':'; |
︙ | ︙ | |||
583 584 585 586 587 588 589 | } if (indent) [tmp addItem: "\n"]; length += tmp.count + _name.UTF8StringLength + 2 + (indent ? level * indentation : 0); | | | | | 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | } if (indent) [tmp addItem: "\n"]; length += tmp.count + _name.UTF8StringLength + 2 + (indent ? level * indentation : 0); cString = OFResizeMemory(cString, length, 1); cString[i++] = '>'; memcpy(cString + i, tmp.items, tmp.count); i += tmp.count; if (indent) { memset(cString + i, ' ', level * indentation); i += level * indentation; } cString[i++] = '<'; cString[i++] = '/'; if (prefix != nil) { length += prefix.UTF8StringLength + 1; cString = OFResizeMemory(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); i += _name.UTF8StringLength; } else cString[i++] = '/'; cString[i++] = '>'; assert(i == length); objc_autoreleasePoolPop(pool); ret = [OFString stringWithUTF8String: cString length: length]; } @finally { OFFreeMemory(cString); } return ret; } - (OFString *)XMLString { return [self of_XMLStringWithParent: nil |
︙ | ︙ | |||
656 657 658 659 660 661 662 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className | | | < | | | | 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | - (OFXMLElement *)XMLElementBySerializing { void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS]; if (_name != nil) [element addAttributeWithName: @"name" stringValue: _name]; if (_namespace != nil) [element addAttributeWithName: @"namespace" stringValue: _namespace]; if (_defaultNamespace != nil) [element addAttributeWithName: @"defaultNamespace" stringValue: _defaultNamespace]; if (_attributes != nil) { OFXMLElement *attributesElement; attributesElement = [OFXMLElement elementWithName: @"attributes" namespace: OFSerializationNS]; [attributesElement addChild: _attributes.XMLElementBySerializing]; [element addChild: attributesElement]; } if (_namespaces != nil) { OFXMLElement *namespacesElement; OFMutableDictionary *namespacesCopy = [[_namespaces mutableCopy] autorelease]; [namespacesCopy removeObjectForKey: @"http://www.w3.org/XML/1998/namespace"]; [namespacesCopy removeObjectForKey: @"http://www.w3.org/2000/xmlns/"]; if (namespacesCopy.count > 0) { namespacesElement = [OFXMLElement elementWithName: @"namespaces" namespace: OFSerializationNS]; [namespacesElement addChild: namespacesCopy.XMLElementBySerializing]; [element addChild: namespacesElement]; } } if (_children != nil) { OFXMLElement *childrenElement; childrenElement = [OFXMLElement elementWithName: @"children" namespace: OFSerializationNS]; [childrenElement addChild: _children.XMLElementBySerializing]; [element addChild: childrenElement]; } [element retain]; objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
814 815 816 817 818 819 820 | [objects[i]->_name isEqual: attributeName]) { [_attributes removeObjectAtIndex: i]; return; } } } | | < | < | < | < | < | < | < | < | < | < | < | < | 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | [objects[i]->_name isEqual: attributeName]) { [_attributes removeObjectAtIndex: i]; return; } } } - (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { if (prefix.length == 0) @throw [OFInvalidArgumentException exception]; if (namespace == nil) namespace = @""; [_namespaces setObject: prefix forKey: namespace]; } - (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace { [self setPrefix: prefix forNamespace: namespace]; [self addAttributeWithName: prefix namespace: @"http://www.w3.org/2000/xmlns/" stringValue: namespace]; } - (void)addChild: (OFXMLNode *)child { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; if (_children == nil) _children = [[OFMutableArray alloc] init]; [_children addObject: child]; } - (void)insertChild: (OFXMLNode *)child atIndex: (size_t)idx { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; if (_children == nil) _children = [[OFMutableArray alloc] init]; [_children insertObject: child atIndex: idx]; } - (void)insertChildren: (OFArray *)children atIndex: (size_t)idx { for (OFXMLNode *node in children) if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children insertObjectsFromArray: children atIndex: idx]; } - (void)removeChild: (OFXMLNode *)child { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children removeObject: child]; } - (void)removeChildAtIndex: (size_t)idx { [_children removeObjectAtIndex: idx]; } - (void)replaceChild: (OFXMLNode *)child withNode: (OFXMLNode *)node { if ([node isKindOfClass: [OFXMLAttribute class]] || [child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children replaceObject: child withObject: node]; } - (void)replaceChildAtIndex: (size_t)idx withNode: (OFXMLNode *)node { if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exception]; [_children replaceObjectAtIndex: idx withObject: node]; } - (OFXMLElement *)elementForName: (OFString *)elementName { return [self elementsForName: elementName].firstObject; } |
︙ | ︙ | |||
1028 1029 1030 1031 1032 1033 1034 | return false; return true; } - (unsigned long)hash { | | | | | | | | | | | 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _name.hash); OFHashAddHash(&hash, _namespace.hash); OFHashAddHash(&hash, _defaultNamespace.hash); OFHashAddHash(&hash, _attributes.hash); OFHashAddHash(&hash, _namespaces.hash); OFHashAddHash(&hash, _children.hash); OFHashFinalize(&hash); return hash; } - (id)copy { return [[[self class] alloc] initWithElement: self]; } @end |
Modified src/OFXMLElementBuilder.h from [702d1ff1af] to [21b424ead3].
︙ | ︙ | |||
116 117 118 119 120 121 122 | id <OFXMLElementBuilderDelegate> delegate; /** * @brief Creates a new element builder. * * @return A new, autoreleased OFXMLElementBuilder */ | | | 116 117 118 119 120 121 122 123 124 125 126 | id <OFXMLElementBuilderDelegate> delegate; /** * @brief Creates a new element builder. * * @return A new, autoreleased OFXMLElementBuilder */ + (instancetype)builder; @end OF_ASSUME_NONNULL_END |
Modified src/OFXMLElementBuilder.m from [ff12f91bf6] to [a53bbdbeea].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFXMLElementBuilder.h" | | | | | | | | 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 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFXMLElementBuilder.h" #import "OFArray.h" #import "OFXMLAttribute.h" #import "OFXMLCDATA.h" #import "OFXMLCharacters.h" #import "OFXMLComment.h" #import "OFXMLElement.h" #import "OFXMLParser.h" #import "OFXMLProcessingInstruction.h" #import "OFMalformedXMLException.h" @implementation OFXMLElementBuilder @synthesize delegate = _delegate; + (instancetype)builder { return [[[self alloc] init] autorelease]; } - (instancetype)init { self = [super init]; |
︙ | ︙ | |||
52 53 54 55 56 57 58 | - (void)dealloc { [_stack release]; [super dealloc]; } | | | > | | > | < | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | - (void)dealloc { [_stack release]; [super dealloc]; } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target data: (OFString *)data { OFXMLProcessingInstruction *node = [OFXMLProcessingInstruction processingInstructionWithTarget: target data: data]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) [_delegate elementBuilder: self didBuildParentlessNode: node]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attributes |
︙ | ︙ | |||
132 133 134 135 136 137 138 | node = [OFXMLCharacters charactersWithString: characters]; parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) | | < | < | | < | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | node = [OFXMLCharacters charactersWithString: characters]; parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) [_delegate elementBuilder: self didBuildParentlessNode: node]; } - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA { OFXMLCDATA *node = [OFXMLCDATA CDATAWithString: CDATA]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) [_delegate elementBuilder: self didBuildParentlessNode: node]; } - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment { OFXMLComment *node = [OFXMLComment commentWithText: comment]; OFXMLElement *parent = _stack.lastObject; if (parent != nil) [parent addChild: node]; else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) [_delegate elementBuilder: self didBuildParentlessNode: node]; } - (OFString *)parser: (OFXMLParser *)parser foundUnknownEntityNamed: (OFString *)entity { if ([_delegate respondsToSelector: @selector(elementBuilder:foundUnknownEntityNamed:)]) return [_delegate elementBuilder: self foundUnknownEntityNamed: entity]; return nil; } @end |
Modified src/OFXMLNode.m from [d7c9563cf3] to [7f68e69172].
︙ | ︙ | |||
72 73 74 75 76 77 78 | - (double)doubleValue { return self.stringValue.doubleValue; } - (OFString *)XMLString { | | < | < | | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | - (double)doubleValue { return self.stringValue.doubleValue; } - (OFString *)XMLString { return [self XMLStringWithIndentation: 0 level: 0]; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation { return [self XMLStringWithIndentation: 0 level: 0]; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { OF_UNRECOGNIZED_SELECTOR } - (OFString *)description { return [self XMLStringWithIndentation: 2 level: 0]; } - (OFXMLElement *)XMLElementBySerializing { OF_UNRECOGNIZED_SELECTOR } |
︙ | ︙ |
Modified src/OFXMLParser.h from [de5e16977e] to [fd86d1b01d].
︙ | ︙ | |||
30 31 32 33 34 35 36 | * @protocol OFXMLParserDelegate OFXMLParser.h ObjFW/OFXMLParser.h * * @brief A protocol that needs to be implemented by delegates for OFXMLParser. */ @protocol OFXMLParserDelegate <OFObject> @optional /** | | | | > | | | > | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | * @protocol OFXMLParserDelegate OFXMLParser.h ObjFW/OFXMLParser.h * * @brief A protocol that needs to be implemented by delegates for OFXMLParser. */ @protocol OFXMLParserDelegate <OFObject> @optional /** * @brief This callback is called when the XML parser found a processing * instruction. * * @param parser The parser which found a processing instruction * @param target The target of the processing instruction * @param data The data of the processing instruction */ - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target data: (OFString *)data; /** * @brief This callback is called when the XML parser found the start of a new * tag. * * @param parser The parser which found a new tag * @param name The name of the tag which just started |
︙ | ︙ | |||
78 79 80 81 82 83 84 | * * In case there are comments or CDATA, it is possible that this callback is * called multiple times in a row. * * @param parser The parser which found a string * @param characters The characters the XML parser found */ | < | | < | < | 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | * * In case there are comments or CDATA, it is possible that this callback is * called multiple times in a row. * * @param parser The parser which found a string * @param characters The characters the XML parser found */ - (void)parser: (OFXMLParser *)parser foundCharacters: (OFString *)characters; /** * @brief This callback is called when the XML parser found CDATA. * * @param parser The parser which found a string * @param CDATA The CDATA the XML parser found */ - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA; /** * @brief This callback is called when the XML parser found a comment. * * @param parser The parser which found a comment * @param comment The comment the XML parser found */ - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment; /** * @brief This callback is called when the XML parser found an entity it * doesn't know. * * The callback is supposed to return a substitution for the entity or `nil` if * it is not known to the callback as well, in which case an exception will be |
︙ | ︙ | |||
127 128 129 130 131 132 133 | * OFXMLParser is an event-based XML parser which calls the delegate's callbacks * as soon as it finds something, thus suitable for streams as well. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLParser: OFObject { id <OFXMLParserDelegate> _Nullable _delegate; | < < < < < < < < < < < < < < < < < < < < < | | | 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 | * OFXMLParser is an event-based XML parser which calls the delegate's callbacks * as soon as it finds something, thus suitable for streams as well. */ OF_SUBCLASSING_RESTRICTED @interface OFXMLParser: OFObject { id <OFXMLParserDelegate> _Nullable _delegate; uint_least8_t _state; size_t _i, _last; const char *_Nullable _data; OFMutableData *_buffer; OFString *_Nullable _name, *_Nullable _prefix; OFMutableArray OF_GENERIC(OFMutableDictionary OF_GENERIC(OFString *, OFString *) *) *_namespaces; OFMutableArray OF_GENERIC(OFXMLAttribute *) *_attributes; OFString *_Nullable _attributeName, *_Nullable _attributePrefix; char _delimiter; OFMutableArray OF_GENERIC(OFString *) *_previous; size_t _level; bool _acceptProlog; size_t _lineNumber; bool _lastCarriageReturn, _finishedParsing; OFStringEncoding _encoding; size_t _depthLimit; } /** * @brief The delegate that is used by the XML parser. */ @property OF_NULLABLE_PROPERTY (assign, nonatomic) |
︙ | ︙ | |||
206 207 208 209 210 211 212 | /** * @brief Parses the specified buffer with the specified size. * * @param buffer The buffer to parse * @param length The length of the buffer */ | | < | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | /** * @brief Parses the specified buffer with the specified size. * * @param buffer The buffer to parse * @param length The length of the buffer */ - (void)parseBuffer: (const char *)buffer length: (size_t)length; /** * @brief Parses the specified string. * * @param string The string to parse */ - (void)parseString: (OFString *)string; |
︙ | ︙ |
Modified src/OFXMLParser.m from [08bf6cc4f2] to [885a5c6d01].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #define OF_XML_PARSER_M #include <string.h> #import "OFXMLParser.h" | | | < < | > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | < | | | | | < | < | | | | | | | | | | | | | | < | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | #include "config.h" #define OF_XML_PARSER_M #include <string.h> #import "OFXMLParser.h" #import "OFArray.h" #import "OFCharacterSet.h" #import "OFData.h" #import "OFDictionary.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFStream.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLAttribute.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFOutOfRangeException.h" #import "OFUnboundPrefixException.h" enum { stateInByteOrderMark, stateOutsideTag, stateTagOpened, stateInProcessingInstruction, stateInTagName, stateInCloseTagName, stateInTag, stateInAttributeName, stateExpectAttributeEqualSign, stateExpectAttributeDelimiter, stateInAttributeValue, stateExpectTagClose, stateExpectSpaceOrTagClose, stateInExclamationMark, stateInCDATAOpening, stateInCDATA, stateInCommentOpening, stateInComment1, stateInComment2, stateInDOCTYPE }; @interface OFXMLParser () <OFStringXMLUnescapingDelegate> @end static void inByteOrderMarkState(OFXMLParser *); static void outsideTagState(OFXMLParser *); static void tagOpenedState(OFXMLParser *); static void inProcessingInstructionState(OFXMLParser *); static void inTagNameState(OFXMLParser *); static void inCloseTagNameState(OFXMLParser *); static void inTagState(OFXMLParser *); static void inAttributeNameState(OFXMLParser *); static void expectAttributeEqualSignState(OFXMLParser *); static void expectAttributeDelimiterState(OFXMLParser *); static void inAttributeValueState(OFXMLParser *); static void expectTagCloseState(OFXMLParser *); static void expectSpaceOrTagCloseState(OFXMLParser *); static void inExclamationMarkState(OFXMLParser *); static void inCDATAOpeningState(OFXMLParser *); static void inCDATAState(OFXMLParser *); static void inCommentOpeningState(OFXMLParser *); static void inCommentState1(OFXMLParser *); static void inCommentState2(OFXMLParser *); static void inDOCTYPEState(OFXMLParser *); typedef void (*StateFunction)(OFXMLParser *); static StateFunction lookupTable[] = { [stateInByteOrderMark] = inByteOrderMarkState, [stateOutsideTag] = outsideTagState, [stateTagOpened] = tagOpenedState, [stateInProcessingInstruction] = inProcessingInstructionState, [stateInTagName] = inTagNameState, [stateInCloseTagName] = inCloseTagNameState, [stateInTag] = inTagState, [stateInAttributeName] = inAttributeNameState, [stateExpectAttributeEqualSign] = expectAttributeEqualSignState, [stateExpectAttributeDelimiter] = expectAttributeDelimiterState, [stateInAttributeValue] = inAttributeValueState, [stateExpectTagClose] = expectTagCloseState, [stateExpectSpaceOrTagClose] = expectSpaceOrTagCloseState, [stateInExclamationMark] = inExclamationMarkState, [stateInCDATAOpening] = inCDATAOpeningState, [stateInCDATA] = inCDATAState, [stateInCommentOpening] = inCommentOpeningState, [stateInComment1] = inCommentState1, [stateInComment2] = inCommentState2, [stateInDOCTYPE] = inDOCTYPEState }; static OF_INLINE void appendToBuffer(OFMutableData *buffer, const char *string, OFStringEncoding encoding, size_t length) { if OF_LIKELY(encoding == OFStringEncodingUTF8) [buffer addItems: string count: length]; else { void *pool = objc_autoreleasePoolPush(); OFString *tmp = [OFString stringWithCString: string encoding: encoding length: length]; [buffer addItems: tmp.UTF8String count: tmp.UTF8StringLength]; objc_autoreleasePoolPop(pool); } } static OFString * transformString(OFXMLParser *parser, OFMutableData *buffer, size_t cut, bool unescape) |
︙ | ︙ | |||
126 127 128 129 130 131 132 | length--; } else items[i] = '\n'; } else if (items[i] == '&') hasEntities = true; } | | < | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | length--; } else items[i] = '\n'; } else if (items[i] == '&') hasEntities = true; } ret = [OFString stringWithUTF8String: items length: length]; if (unescape && hasEntities) { @try { return [ret stringByXMLUnescapingWithDelegate: parser]; } @catch (OFInvalidFormatException *e) { @throw [OFMalformedXMLException exceptionWithParser: parser]; |
︙ | ︙ | |||
210 211 212 213 214 215 216 | dict = [OFMutableDictionary dictionaryWithKeysAndObjects: @"xml", @"http://www.w3.org/XML/1998/namespace", @"xmlns", @"http://www.w3.org/2000/xmlns/", nil]; [_namespaces addObject: dict]; _acceptProlog = true; _lineNumber = 1; | | | 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | dict = [OFMutableDictionary dictionaryWithKeysAndObjects: @"xml", @"http://www.w3.org/XML/1998/namespace", @"xmlns", @"http://www.w3.org/2000/xmlns/", nil]; [_namespaces addObject: dict]; _acceptProlog = true; _lineNumber = 1; _encoding = OFStringEncodingUTF8; _depthLimit = 32; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
236 237 238 239 240 241 242 | [_attributeName release]; [_attributePrefix release]; [_previous release]; [super dealloc]; } | | < | | | < | < | < | | | | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | [_attributeName release]; [_attributePrefix release]; [_previous release]; [super dealloc]; } - (void)parseBuffer: (const char *)buffer length: (size_t)length { _data = buffer; for (_i = _last = 0; _i < length; _i++) { size_t j = _i; lookupTable[_state](self); /* Ensure we don't count this character twice */ if (_i != j) continue; if (_data[_i] == '\r' || (_data[_i] == '\n' && !_lastCarriageReturn)) _lineNumber++; _lastCarriageReturn = (_data[_i] == '\r'); } /* In stateInTag, there can be only spaces */ if (length - _last > 0 && _state != stateInTag) appendToBuffer(_buffer, _data + _last, _encoding, length - _last); } - (void)parseString: (OFString *)string { [self parseBuffer: string.UTF8String length: string.UTF8StringLength]; } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; char *buffer = OFAllocMemory(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; [self parseBuffer: buffer length: length]; } } @finally { OFFreeMemory(buffer); } } static void inByteOrderMarkState(OFXMLParser *self) { if (self->_data[self->_i] != "\xEF\xBB\xBF"[self->_level]) { if (self->_level == 0) { self->_state = stateOutsideTag; self->_i--; return; } @throw [OFMalformedXMLException exceptionWithParser: self]; } if (self->_level++ == 2) self->_state = stateOutsideTag; self->_last = self->_i + 1; } /* Not in a tag */ static void outsideTagState(OFXMLParser *self) |
︙ | ︙ | |||
341 342 343 344 345 346 347 | objc_autoreleasePoolPop(pool); } [self->_buffer removeAllItems]; self->_last = self->_i + 1; | | | | | | | < < < | | | 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | objc_autoreleasePoolPop(pool); } [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateTagOpened; } /* Tag was just opened */ static void tagOpenedState(OFXMLParser *self) { if (self->_finishedParsing && self->_data[self->_i] != '!' && self->_data[self->_i] != '?') @throw [OFMalformedXMLException exceptionWithParser: self]; switch (self->_data[self->_i]) { case '?': self->_last = self->_i + 1; self->_state = stateInProcessingInstruction; self->_level = 0; break; case '/': self->_last = self->_i + 1; self->_state = stateInCloseTagName; self->_acceptProlog = false; break; case '!': self->_last = self->_i + 1; self->_state = stateInExclamationMark; self->_acceptProlog = false; break; default: if (self->_depthLimit > 0 && self->_previous.count >= self->_depthLimit) @throw [OFOutOfRangeException exception]; self->_state = stateInTagName; self->_acceptProlog = false; self->_i--; break; } } /* <?xml […]?> */ static bool parseXMLProcessingInstruction(OFXMLParser *self, OFString *data) { const char *cString; size_t length, last; int PIState = 0; OFString *attribute = nil; OFMutableString *value = nil; char piDelimiter = 0; bool hasVersion = false; if (!self->_acceptProlog) return false; self->_acceptProlog = false; cString = data.UTF8String; length = data.UTF8StringLength; last = 0; for (size_t i = 0; i < length; i++) { switch (PIState) { case 0: if (cString[i] == ' ' || cString[i] == '\t' || cString[i] == '\r' || cString[i] == '\n') |
︙ | ︙ | |||
456 457 458 459 460 461 462 | hasVersion = true; } if ([attribute isEqual: @"encoding"]) { @try { self->_encoding = | | | | | > > > > > > > > > | > > > > | | | | | | | > | | 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | hasVersion = true; } if ([attribute isEqual: @"encoding"]) { @try { self->_encoding = OFStringEncodingParseName(value); } @catch (OFInvalidArgumentException *e) { @throw [OFInvalidEncodingException exception]; } } last = i + 1; PIState = 0; break; } } if (PIState != 0 || !hasVersion) return false; return true; } /* Inside processing instruction */ static void inProcessingInstructionState(OFXMLParser *self) { if (self->_data[self->_i] == '?') self->_level = 1; else if (self->_level == 1 && self->_data[self->_i] == '>') { void *pool = objc_autoreleasePoolPush(); OFString *PI, *target, *data = nil; OFCharacterSet *whitespaceCS; size_t pos; appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); PI = transformString(self, self->_buffer, 1, false); whitespaceCS = [OFCharacterSet characterSetWithCharactersInString: @" \r\n\r"]; pos = [PI indexOfCharacterFromSet: whitespaceCS]; if (pos != OFNotFound) { target = [PI substringToIndex: pos]; data = [[PI substringFromIndex: pos + 1] stringByDeletingEnclosingWhitespaces]; if (data.length == 0) data = nil; } else target = PI; if ([target caseInsensitiveCompare: @"xml"] == OFOrderedSame) if (!parseXMLProcessingInstruction(self, data)) @throw [OFMalformedXMLException exceptionWithParser: self]; if ([self->_delegate respondsToSelector: @selector( parser:foundProcessingInstructionWithTarget:data:)]) [self->_delegate parser: self foundProcessingInstructionWithTarget: target data: data]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateOutsideTag; } else self->_level = 0; } /* Inside a tag, no name yet */ static void inTagNameState(OFXMLParser *self) |
︙ | ︙ | |||
551 552 553 554 555 556 557 | length: tmp - bufferCString]; } else { self->_name = [bufferString copy]; self->_prefix = nil; } if (self->_data[self->_i] == '>' || self->_data[self->_i] == '/') { | < < | | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | length: tmp - bufferCString]; } else { self->_name = [bufferString copy]; self->_prefix = nil; } if (self->_data[self->_i] == '>' || self->_data[self->_i] == '/') { OFString *namespace = namespaceForPrefix(self->_prefix, self->_namespaces); if (self->_prefix != nil && namespace == nil) @throw [OFUnboundPrefixException exceptionWithPrefix: self->_prefix parser: self]; |
︙ | ︙ | |||
587 588 589 590 591 592 593 | [self->_previous addObject: bufferString]; [self->_name release]; [self->_prefix release]; self->_name = self->_prefix = nil; self->_state = (self->_data[self->_i] == '/' | | < | | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | [self->_previous addObject: bufferString]; [self->_name release]; [self->_prefix release]; self->_name = self->_prefix = nil; self->_state = (self->_data[self->_i] == '/' ? stateExpectTagClose : stateOutsideTag); } else self->_state = stateInTag; if (self->_data[self->_i] != '/') [self->_namespaces addObject: [OFMutableDictionary dictionary]]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; |
︙ | ︙ | |||
668 669 670 671 672 673 674 | [self->_namespaces removeLastObject]; [self->_name release]; [self->_prefix release]; self->_name = self->_prefix = nil; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '>' | | < | | 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 | [self->_namespaces removeLastObject]; [self->_name release]; [self->_prefix release]; self->_name = self->_prefix = nil; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '>' ? stateOutsideTag : stateExpectSpaceOrTagClose); if (self->_previous.count == 0) self->_finishedParsing = true; } /* Inside a tag, name found */ static void inTagState(OFXMLParser *self) { void *pool; OFString *namespace; OFXMLAttribute *const *attributesObjects; size_t attributesCount; if (self->_data[self->_i] != '>' && self->_data[self->_i] != '/') { if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r') { self->_last = self->_i; self->_state = stateInAttributeName; self->_i--; } return; } attributesObjects = self->_attributes.objects; |
︙ | ︙ | |||
749 750 751 752 753 754 755 | [self->_name release]; [self->_prefix release]; [self->_attributes removeAllObjects]; self->_name = self->_prefix = nil; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '/' | | < | 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 | [self->_name release]; [self->_prefix release]; [self->_attributes removeAllObjects]; self->_name = self->_prefix = nil; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '/' ? stateExpectTagClose : stateOutsideTag); } /* Looking for attribute name */ static void inAttributeNameState(OFXMLParser *self) { void *pool; |
︙ | ︙ | |||
798 799 800 801 802 803 804 | objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '=' | | < | | 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 | objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = (self->_data[self->_i] == '=' ? stateExpectAttributeDelimiter : stateExpectAttributeEqualSign); } /* Expecting equal sign of an attribute */ static void expectAttributeEqualSignState(OFXMLParser *self) { if (self->_data[self->_i] == '=') { self->_last = self->_i + 1; self->_state = stateExpectAttributeDelimiter; return; } if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r') @throw [OFMalformedXMLException exceptionWithParser: self]; } |
︙ | ︙ | |||
831 832 833 834 835 836 837 | self->_data[self->_i] == '\n' || self->_data[self->_i] == '\r') return; if (self->_data[self->_i] != '\'' && self->_data[self->_i] != '"') @throw [OFMalformedXMLException exceptionWithParser: self]; self->_delimiter = self->_data[self->_i]; | | | 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 | self->_data[self->_i] == '\n' || self->_data[self->_i] == '\r') return; if (self->_data[self->_i] != '\'' && self->_data[self->_i] != '"') @throw [OFMalformedXMLException exceptionWithParser: self]; self->_delimiter = self->_data[self->_i]; self->_state = stateInAttributeValue; } /* Looking for attribute value */ static void inAttributeValueState(OFXMLParser *self) { void *pool; |
︙ | ︙ | |||
875 876 877 878 879 880 881 | [self->_buffer removeAllItems]; [self->_attributeName release]; [self->_attributePrefix release]; self->_attributeName = self->_attributePrefix = nil; self->_last = self->_i + 1; | | | | | | | | | 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | [self->_buffer removeAllItems]; [self->_attributeName release]; [self->_attributePrefix release]; self->_attributeName = self->_attributePrefix = nil; self->_last = self->_i + 1; self->_state = stateInTag; } /* Expecting closing '>' */ static void expectTagCloseState(OFXMLParser *self) { if (self->_data[self->_i] == '>') { self->_last = self->_i + 1; self->_state = stateOutsideTag; } else @throw [OFMalformedXMLException exceptionWithParser: self]; } /* Expecting closing '>' or space */ static void expectSpaceOrTagCloseState(OFXMLParser *self) { if (self->_data[self->_i] == '>') { self->_last = self->_i + 1; self->_state = stateOutsideTag; } else if (self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r') @throw [OFMalformedXMLException exceptionWithParser: self]; } /* In <! */ static void inExclamationMarkState(OFXMLParser *self) { if (self->_finishedParsing && self->_data[self->_i] != '-') @throw [OFMalformedXMLException exceptionWithParser: self]; if (self->_data[self->_i] == '-') self->_state = stateInCommentOpening; else if (self->_data[self->_i] == '[') { self->_state = stateInCDATAOpening; self->_level = 0; } else if (self->_data[self->_i] == 'D') { self->_state = stateInDOCTYPE; self->_level = 0; } else @throw [OFMalformedXMLException exceptionWithParser: self]; self->_last = self->_i + 1; } /* CDATA */ static void inCDATAOpeningState(OFXMLParser *self) { if (self->_data[self->_i] != "CDATA["[self->_level]) @throw [OFMalformedXMLException exceptionWithParser: self]; if (++self->_level == 6) { self->_state = stateInCDATA; self->_level = 0; } self->_last = self->_i + 1; } static void |
︙ | ︙ | |||
953 954 955 956 957 958 959 | appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); CDATA = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundCDATA:)]) | | < | | | | < | | | < | 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 | appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); CDATA = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundCDATA:)]) [self->_delegate parser: self foundCDATA: CDATA]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateOutsideTag; } else self->_level = 0; } /* Comment */ static void inCommentOpeningState(OFXMLParser *self) { if (self->_data[self->_i] != '-') @throw [OFMalformedXMLException exceptionWithParser: self]; self->_last = self->_i + 1; self->_state = stateInComment1; self->_level = 0; } static void inCommentState1(OFXMLParser *self) { if (self->_data[self->_i] == '-') self->_level++; else self->_level = 0; if (self->_level == 2) self->_state = stateInComment2; } static void inCommentState2(OFXMLParser *self) { void *pool; OFString *comment; if (self->_data[self->_i] != '>') @throw [OFMalformedXMLException exceptionWithParser: self]; pool = objc_autoreleasePoolPush(); appendToBuffer(self->_buffer, self->_data + self->_last, self->_encoding, self->_i - self->_last); comment = transformString(self, self->_buffer, 2, false); if ([self->_delegate respondsToSelector: @selector(parser:foundComment:)]) [self->_delegate parser: self foundComment: comment]; objc_autoreleasePoolPop(pool); [self->_buffer removeAllItems]; self->_last = self->_i + 1; self->_state = stateOutsideTag; } /* In <!DOCTYPE ...> */ static void inDOCTYPEState(OFXMLParser *self) { if ((self->_level < 6 && self->_data[self->_i] != "OCTYPE"[self->_level]) || (self->_level == 6 && self->_data[self->_i] != ' ' && self->_data[self->_i] != '\t' && self->_data[self->_i] != '\n' && self->_data[self->_i] != '\r')) @throw [OFMalformedXMLException exceptionWithParser: self]; self->_level++; if (self->_level > 6 && self->_data[self->_i] == '>') self->_state = stateOutsideTag; self->_last = self->_i + 1; } - (size_t)lineNumber { return _lineNumber; } - (bool)hasFinishedParsing { return _finishedParsing; } - (OFString *)string: (OFString *)string containsUnknownEntityNamed: (OFString *)entity { if ([_delegate respondsToSelector: @selector(parser:foundUnknownEntityNamed:)]) return [_delegate parser: self foundUnknownEntityNamed: entity]; return nil; } @end |
Renamed and modified src/OFXMLProcessingInstructions.h [9211767771] to src/OFXMLProcessingInstruction.h [86de9b9bcd].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN /** | | | | | | | > > > > > > > > > > | > > | | | > | | > | | | > | 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 61 62 63 64 65 66 67 | */ #import "OFXMLNode.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFXMLProcessingInstruction \ * OFXMLProcessingInstruction.h ObjFW/OFXMLProcessingInstruction.h * * @brief A class for representing an XML processing instruction. */ @interface OFXMLProcessingInstruction: OFXMLNode { OFString *_target, *_data; OF_RESERVE_IVARS(OFXMLProcessingInstruction, 4) } /** * @brief The target of the processing instruction. */ @property (readonly, nonatomic) OFString *target; /** * @brief The data of the processing instruction. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *data; /** * @brief Creates a new OFXMLProcessingInstruction with the specified target * and data. * * @param target The target for the processing instruction * @param data The data for the processing instruction * @return A new OFXMLProcessingInstruction */ + (instancetype)processingInstructionWithTarget: (OFString *)target data: (OFString *)data; /** * @brief Initializes an already allocated OFXMLProcessingInstruction with the * specified target and data. * * @param target The target for the processing instruction * @param data The data for the processing instruction * @return An initialized OFXMLProcessingInstruction */ - (instancetype)initWithTarget: (OFString *)target data: (OFString *)data OF_DESIGNATED_INITIALIZER; - (instancetype)initWithSerialization: (OFXMLElement *)element; @end OF_ASSUME_NONNULL_END |
Renamed and modified src/OFXMLProcessingInstructions.m [aed6fd90fa] to src/OFXMLProcessingInstruction.m [f3e07ddc76].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include <string.h> | | | | > | > > | > | > | > > | < < > | > > > > > > | > | | | | > > > | | > > > > > > > > > > | > | > > > | < < > | > | > > > > | | < < < | > > | | | | > > > > > > > > | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | * file. */ #include "config.h" #include <string.h> #import "OFXMLProcessingInstruction.h" #import "OFString.h" #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFXMLNode+Private.h" #import "OFInvalidArgumentException.h" @implementation OFXMLProcessingInstruction @synthesize target = _target, data = _data; + (instancetype)processingInstructionWithTarget: (OFString *)target data: (OFString *)data { return [[[self alloc] initWithTarget: target data: data] autorelease]; } - (instancetype)initWithTarget: (OFString *)target data: (OFString *)data { self = [super of_init]; @try { _target = [target copy]; _data = [data copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithSerialization: (OFXMLElement *)element { @try { void *pool = objc_autoreleasePoolPush(); OFXMLAttribute *targetAttr; if (![element.name isEqual: self.className] || ![element.namespace isEqual: OFSerializationNS]) @throw [OFInvalidArgumentException exception]; targetAttr = [element attributeForName: @"target" namespace: OFSerializationNS]; if (targetAttr.stringValue.length == 0) @throw [OFInvalidArgumentException exception]; self = [self initWithTarget: targetAttr.stringValue data: element.stringValue]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_target release]; [_data release]; [super dealloc]; } - (bool)isEqual: (id)object { OFXMLProcessingInstruction *processingInstruction; if (object == self) return true; if (![object isKindOfClass: [OFXMLProcessingInstruction class]]) return false; processingInstruction = object; if (![processingInstruction->_target isEqual: _target]) return false; if (processingInstruction->_data != _data && ![processingInstruction->_data isEqual: _data]) return false; return true; } - (unsigned long)hash { unsigned long hash; OFHashInit(&hash); OFHashAddHash(&hash, _target.hash); OFHashAddHash(&hash, _data.hash); OFHashFinalize(&hash); return hash; } - (OFString *)stringValue { return @""; } - (OFString *)XMLString { if (_data.length > 0) return [OFString stringWithFormat: @"<?%@ %@?>", _target, _data]; else return [OFString stringWithFormat: @"<?%@?>", _target]; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation { return self.XMLString; } - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { if (indentation > 0 && level > 0) { OFString *ret; char *whitespaces = OFAllocMemory((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { if (_data.length > 0) ret = [OFString stringWithFormat: @"%s<?%@ %@?>", whitespaces, _target, _data]; else ret = [OFString stringWithFormat: @"%s<?%@?>", whitespaces, _target]; } @finally { OFFreeMemory(whitespaces); } return ret; } else return self.XMLString; } - (OFString *)description { return self.XMLString; } - (OFXMLElement *)XMLElementBySerializing { OFXMLElement *ret = [OFXMLElement elementWithName: self.className namespace: OFSerializationNS stringValue: _data]; void *pool = objc_autoreleasePoolPush(); [ret addAttribute: [OFXMLAttribute attributeWithName: @"target" stringValue: _target]]; objc_autoreleasePoolPop(pool); return ret; } @end |
Modified src/OFZIPArchive.h from [c179867587] to [3dde37049e].
︙ | ︙ | |||
30 31 32 33 34 35 36 | * @brief A class for accessing and manipulating ZIP files. */ OF_SUBCLASSING_RESTRICTED @interface OFZIPArchive: OFObject { OFStream *_stream; int64_t _offset; | < < < < | | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | * @brief A class for accessing and manipulating ZIP files. */ OF_SUBCLASSING_RESTRICTED @interface OFZIPArchive: OFObject { OFStream *_stream; int64_t _offset; uint_least8_t _mode; uint32_t _diskNumber, _centralDirectoryDisk; uint64_t _centralDirectoryEntriesInDisk, _centralDirectoryEntries; uint64_t _centralDirectorySize; int64_t _centralDirectoryOffset; OFString *_Nullable _archiveComment; OFMutableArray OF_GENERIC(OFZIPArchiveEntry *) *_entries; OFMutableDictionary OF_GENERIC(OFString *, OFZIPArchiveEntry *) |
︙ | ︙ | |||
72 73 74 75 76 77 78 | * @param stream A stream from which the ZIP archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive */ | | < | < | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | * @param stream A stream from which the ZIP archive will be read. * For read and append mode, this needs to be an OFSeekableStream. * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive */ + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode; #ifdef OF_HAVE_FILES /** * @brief Creates a new OFZIPArchive object with the specified file. * * @param path The path to the ZIP file * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return A new, autoreleased OFZIPArchive */ + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode; #endif - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated OFZIPArchive object with the * specified stream. |
︙ | ︙ | |||
116 117 118 119 120 121 122 | * * @param path The path to the ZIP file * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFZIPArchive */ | | < | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | * * @param path The path to the ZIP file * @param mode The mode for the ZIP file. Valid modes are "r" for reading, * "w" for creating a new file and "a" for appending to an existing * archive. * @return An initialized OFZIPArchive */ - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode; #endif /** * @brief Returns a stream for reading the specified file from the archive. * * @note This method is only available in read mode. * |
︙ | ︙ | |||
170 171 172 173 174 175 176 177 178 | - (OFStream *)streamForWritingEntry: (OFZIPArchiveEntry *)entry; /** * @brief Closes the OFZIPArchive. */ - (void)close; @end OF_ASSUME_NONNULL_END | > > > > > > > > > > > | 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | - (OFStream *)streamForWritingEntry: (OFZIPArchiveEntry *)entry; /** * @brief Closes the OFZIPArchive. */ - (void)close; @end #ifdef __cplusplus extern "C" { #endif extern uint32_t OFZIPArchiveReadField32(const uint8_t *_Nonnull *_Nonnull, uint16_t *_Nonnull); extern uint64_t OFZIPArchiveReadField64(const uint8_t *_Nonnull *_Nonnull, uint16_t *_Nonnull); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/OFZIPArchive.m from [f8c3fbc96e] to [952e87c05c].
︙ | ︙ | |||
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include "config.h" #include <errno.h> #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" #import "OFData.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFStream.h" #import "OFSeekableStream.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFInflateStream.h" #import "OFInflate64Stream.h" | > < < > > > > > > | 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 61 62 63 | #include "config.h" #include <errno.h> #import "OFZIPArchive.h" #import "OFZIPArchiveEntry.h" #import "OFZIPArchiveEntry+Private.h" #import "OFCRC32.h" #import "OFData.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFStream.h" #import "OFSeekableStream.h" #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFInflateStream.h" #import "OFInflate64Stream.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFSeekFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" /* * FIXME: Current limitations: * - Split archives are not supported. * - Encrypted files cannot be read. */ enum { modeRead, modeWrite, modeAppend }; OF_DIRECT_MEMBERS @interface OFZIPArchive () - (void)of_readZIPInfo; - (void)of_readEntries; - (void)of_closeLastReturnedStream; - (void)of_writeCentralDirectory; |
︙ | ︙ | |||
99 100 101 102 103 104 105 | } - (instancetype)initWithStream: (OFStream *)stream entry: (OFMutableZIPArchiveEntry *)entry; @end uint32_t | | | | | < | < | < | < | < | < | | | | < | | | < | < | < | < | 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | } - (instancetype)initWithStream: (OFStream *)stream entry: (OFMutableZIPArchiveEntry *)entry; @end uint32_t OFZIPArchiveReadField32(const uint8_t **data, uint16_t *size) { uint32_t field = 0; if (*size < 4) @throw [OFInvalidFormatException exception]; for (uint8_t i = 0; i < 4; i++) field |= (uint32_t)(*data)[i] << (i * 8); *data += 4; *size -= 4; return field; } uint64_t OFZIPArchiveReadField64(const uint8_t **data, uint16_t *size) { uint64_t field = 0; if (*size < 8) @throw [OFInvalidFormatException exception]; for (uint8_t i = 0; i < 8; i++) field |= (uint64_t)(*data)[i] << (i * 8); *data += 8; *size -= 8; return field; } static void seekOrThrowInvalidFormat(OFSeekableStream *stream, OFFileOffset offset, int whence) { @try { [stream seekToOffset: offset whence: whence]; } @catch (OFSeekFailedException *e) { if (e.errNo == EINVAL) @throw [OFInvalidFormatException exception]; @throw e; } } @implementation OFZIPArchive @synthesize archiveComment = _archiveComment; + (instancetype)archiveWithStream: (OFStream *)stream mode: (OFString *)mode { return [[[self alloc] initWithStream: stream mode: mode] autorelease]; } #ifdef OF_HAVE_FILES + (instancetype)archiveWithPath: (OFString *)path mode: (OFString *)mode { return [[[self alloc] initWithPath: path mode: mode] autorelease]; } #endif - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFStream *)stream mode: (OFString *)mode { self = [super init]; @try { if ([mode isEqual: @"r"]) _mode = modeRead; else if ([mode isEqual: @"w"]) _mode = modeWrite; else if ([mode isEqual: @"a"]) _mode = modeAppend; else @throw [OFInvalidArgumentException exception]; _stream = [stream retain]; _entries = [[OFMutableArray alloc] init]; _pathToEntryMap = [[OFMutableDictionary alloc] init]; if (_mode == modeRead || _mode == modeAppend) { if (![stream isKindOfClass: [OFSeekableStream class]]) @throw [OFInvalidArgumentException exception]; [self of_readZIPInfo]; [self of_readEntries]; } if (_mode == modeAppend) { _offset = _centralDirectoryOffset; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFFileOffset)_offset, SEEK_SET); } } @catch (id e) { /* * If we are in write or append mode, we do not want -[close] * to write anything to it on error - after all, it might not * be a ZIP file which we would destroy otherwise. */ [_stream release]; _stream = nil; [self release]; @throw e; } return self; } #ifdef OF_HAVE_FILES - (instancetype)initWithPath: (OFString *)path mode: (OFString *)mode { OFFile *file; if ([mode isEqual: @"a"]) file = [[OFFile alloc] initWithPath: path mode: @"r+"]; else file = [[OFFile alloc] initWithPath: path mode: mode]; @try { self = [self initWithStream: file mode: mode]; } @finally { [file release]; } return self; } #endif |
︙ | ︙ | |||
262 263 264 265 266 267 268 | [super dealloc]; } - (void)of_readZIPInfo { void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; | | | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | [super dealloc]; } - (void)of_readZIPInfo { void *pool = objc_autoreleasePoolPush(); uint16_t commentLength; OFFileOffset offset = -22; bool valid = false; do { seekOrThrowInvalidFormat((OFSeekableStream *)_stream, offset, SEEK_END); if ([_stream readLittleEndianInt32] == 0x06054B50) { |
︙ | ︙ | |||
288 289 290 291 292 293 294 | _centralDirectoryEntries = [_stream readLittleEndianInt16]; _centralDirectorySize = [_stream readLittleEndianInt32]; _centralDirectoryOffset = [_stream readLittleEndianInt32]; commentLength = [_stream readLittleEndianInt16]; _archiveComment = [[_stream readStringWithLength: commentLength | | | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | _centralDirectoryEntries = [_stream readLittleEndianInt16]; _centralDirectorySize = [_stream readLittleEndianInt32]; _centralDirectoryOffset = [_stream readLittleEndianInt32]; commentLength = [_stream readLittleEndianInt16]; _archiveComment = [[_stream readStringWithLength: commentLength encoding: OFStringEncodingCodepage437] copy]; if (_diskNumber == 0xFFFF || _centralDirectoryDisk == 0xFFFF || _centralDirectoryEntriesInDisk == 0xFFFF || _centralDirectoryEntries == 0xFFFF || _centralDirectorySize == 0xFFFFFFFF || _centralDirectoryOffset == 0xFFFFFFFF) { |
︙ | ︙ | |||
314 315 316 317 318 319 320 | /* * FIXME: Handle number of the disk containing ZIP64 end of * central directory record. */ [_stream readLittleEndianInt32]; offset64 = [_stream readLittleEndianInt64]; | | | | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | /* * FIXME: Handle number of the disk containing ZIP64 end of * central directory record. */ [_stream readLittleEndianInt32]; offset64 = [_stream readLittleEndianInt64]; if (offset64 < 0 || (OFFileOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFFileOffset)offset64, SEEK_SET); if ([_stream readLittleEndianInt32] != 0x06064B50) @throw [OFInvalidFormatException exception]; size = [_stream readLittleEndianInt64]; if (size < 44) @throw [OFInvalidFormatException exception]; |
︙ | ︙ | |||
341 342 343 344 345 346 347 | _centralDirectoryEntriesInDisk = [_stream readLittleEndianInt64]; _centralDirectoryEntries = [_stream readLittleEndianInt64]; _centralDirectorySize = [_stream readLittleEndianInt64]; _centralDirectoryOffset = [_stream readLittleEndianInt64]; if (_centralDirectoryOffset < 0 || | | | | | < | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | _centralDirectoryEntriesInDisk = [_stream readLittleEndianInt64]; _centralDirectoryEntries = [_stream readLittleEndianInt64]; _centralDirectorySize = [_stream readLittleEndianInt64]; _centralDirectoryOffset = [_stream readLittleEndianInt64]; if (_centralDirectoryOffset < 0 || (OFFileOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; } objc_autoreleasePoolPop(pool); } - (void)of_readEntries { void *pool = objc_autoreleasePoolPush(); if (_centralDirectoryOffset < 0 || (OFFileOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFFileOffset)_centralDirectoryOffset, SEEK_SET); for (size_t i = 0; i < _centralDirectoryEntries; i++) { OFZIPArchiveEntry *entry = [[[OFZIPArchiveEntry alloc] of_initWithStream: _stream] autorelease]; if ([_pathToEntryMap objectForKey: entry.fileName] != nil) @throw [OFInvalidFormatException exception]; [_entries addObject: entry]; [_pathToEntryMap setObject: entry forKey: entry.fileName]; } objc_autoreleasePoolPop(pool); } - (OFArray *)entries { |
︙ | ︙ | |||
408 409 410 411 412 413 414 | { @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } | | < | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | { @try { [_lastReturnedStream close]; } @catch (OFNotOpenException *e) { /* Might have already been closed by the user - that's fine. */ } if ((_mode == modeWrite || _mode == modeAppend) && [_lastReturnedStream isKindOfClass: [OFZIPArchiveFileWriteStream class]]) { OFZIPArchiveFileWriteStream *stream = (OFZIPArchiveFileWriteStream *)_lastReturnedStream; if (INT64_MAX - _offset < stream->_bytesWritten) @throw [OFOutOfRangeException exception]; |
︙ | ︙ | |||
438 439 440 441 442 443 444 | - (OFStream *)streamForReadingFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry; OFZIPArchiveLocalFileHeader *localFileHeader; int64_t offset64; | | | | | 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | - (OFStream *)streamForReadingFile: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFZIPArchiveEntry *entry; OFZIPArchiveLocalFileHeader *localFileHeader; int64_t offset64; if (_mode != modeRead) @throw [OFInvalidArgumentException exception]; if ((entry = [_pathToEntryMap objectForKey: path]) == nil) @throw [OFOpenItemFailedException exceptionWithPath: path mode: @"r" errNo: ENOENT]; [self of_closeLastReturnedStream]; offset64 = entry.of_localFileHeaderOffset; if (offset64 < 0 || (OFFileOffset)offset64 != offset64) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat((OFSeekableStream *)_stream, (OFFileOffset)offset64, SEEK_SET); localFileHeader = [[[OFZIPArchiveLocalFileHeader alloc] initWithStream: _stream] autorelease]; if (![localFileHeader matchesEntry: entry]) @throw [OFInvalidFormatException exception]; if ((localFileHeader->_minVersionNeeded & 0xFF) > 45) { |
︙ | ︙ | |||
488 489 490 491 492 493 494 | int64_t offsetAdd = 0; void *pool; OFMutableZIPArchiveEntry *entry; OFString *fileName; OFData *extraField; uint16_t fileNameLength, extraFieldLength; | | < | < | 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | int64_t offsetAdd = 0; void *pool; OFMutableZIPArchiveEntry *entry; OFString *fileName; OFData *extraField; uint16_t fileNameLength, extraFieldLength; if (_mode != modeWrite && _mode != modeAppend) @throw [OFInvalidArgumentException exception]; pool = objc_autoreleasePoolPush(); entry = [[entry_ mutableCopy] autorelease]; if ([_pathToEntryMap objectForKey: entry.fileName] != nil) @throw [OFOpenItemFailedException exceptionWithPath: entry.fileName mode: @"w" errNo: EEXIST]; if (entry.compressionMethod != OFZIPArchiveEntryCompressionMethodNone) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; [self of_closeLastReturnedStream]; fileName = entry.fileName; fileNameLength = fileName.UTF8StringLength; |
︙ | ︙ | |||
542 543 544 545 546 547 548 | [_stream writeLittleEndianInt16: fileNameLength]; [_stream writeLittleEndianInt16: extraFieldLength + 20]; offsetAdd += 4 + (5 * 2) + (3 * 4) + (2 * 2); [_stream writeString: fileName]; offsetAdd += fileNameLength; | | < | 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | [_stream writeLittleEndianInt16: fileNameLength]; [_stream writeLittleEndianInt16: extraFieldLength + 20]; offsetAdd += 4 + (5 * 2) + (3 * 4) + (2 * 2); [_stream writeString: fileName]; offsetAdd += fileNameLength; [_stream writeLittleEndianInt16: OFZIPArchiveEntryExtraFieldTagZIP64]; [_stream writeLittleEndianInt16: 16]; /* We use the data descriptor */ [_stream writeLittleEndianInt64: 0]; [_stream writeLittleEndianInt64: 0]; offsetAdd += (2 * 2) + (2 * 8); if (extraField != nil) |
︙ | ︙ | |||
624 625 626 627 628 629 630 | - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; [self of_closeLastReturnedStream]; | | < | | < | | | | | | | | 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; [self of_closeLastReturnedStream]; if (_mode == modeWrite || _mode == modeAppend) [self of_writeCentralDirectory]; [_stream release]; _stream = nil; } @end @implementation OFZIPArchiveLocalFileHeader - (instancetype)initWithStream: (OFStream *)stream { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *extraField = nil; uint16_t fileNameLength, extraFieldLength; OFStringEncoding encoding; size_t ZIP64Index; uint16_t ZIP64Size; if ([stream readLittleEndianInt32] != 0x04034B50) @throw [OFInvalidFormatException exception]; _minVersionNeeded = [stream readLittleEndianInt16]; _generalPurposeBitFlag = [stream readLittleEndianInt16]; _compressionMethod = [stream readLittleEndianInt16]; _lastModifiedFileTime = [stream readLittleEndianInt16]; _lastModifiedFileDate = [stream readLittleEndianInt16]; _CRC32 = [stream readLittleEndianInt32]; _compressedSize = [stream readLittleEndianInt32]; _uncompressedSize = [stream readLittleEndianInt32]; fileNameLength = [stream readLittleEndianInt16]; extraFieldLength = [stream readLittleEndianInt16]; encoding = (_generalPurposeBitFlag & (1u << 11) ? OFStringEncodingUTF8 : OFStringEncodingCodepage437); _fileName = [[stream readStringWithLength: fileNameLength encoding: encoding] copy]; if (extraFieldLength > 0) extraField = [[[stream readDataWithCount: extraFieldLength] mutableCopy] autorelease]; ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = OFRangeMake(ZIP64Index - 4, ZIP64Size + 4); if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_compressedSize == 0xFFFFFFFF) _compressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (ZIP64Size > 0) @throw [OFInvalidFormatException exception]; [extraField removeItemsInRange: range]; } |
︙ | ︙ | |||
743 744 745 746 747 748 749 | { self = [super init]; @try { _stream = [stream retain]; switch (entry.compressionMethod) { | | | | | 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | { self = [super init]; @try { _stream = [stream retain]; switch (entry.compressionMethod) { case OFZIPArchiveEntryCompressionMethodNone: _decompressedStream = [stream retain]; break; case OFZIPArchiveEntryCompressionMethodDeflate: _decompressedStream = [[OFInflateStream alloc] initWithStream: stream]; break; case OFZIPArchiveEntryCompressionMethodDeflate64: _decompressedStream = [[OFInflate64Stream alloc] initWithStream: stream]; break; default: @throw [OFNotImplementedException exceptionWithSelector: _cmd object: nil]; |
︙ | ︙ | |||
789 790 791 792 793 794 795 | { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } | | < | < | | 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { size_t ret; if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if (_stream.atEndOfStream && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; #if SIZE_MAX >= UINT64_MAX if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif if ((uint64_t)length > _toRead) length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC32 = OFCRC32(_CRC32, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (~_CRC32 != _entry.CRC32) { OFString *actualChecksum = [OFString stringWithFormat: @"%08" PRIX32, ~_CRC32]; |
︙ | ︙ | |||
885 886 887 888 889 890 891 | [self close]; [_entry release]; [super dealloc]; } | | < | < | | 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 | [self close]; [_entry release]; [super dealloc]; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { size_t bytesWritten; #if SIZE_MAX >= INT64_MAX if (length > INT64_MAX) @throw [OFOutOfRangeException exception]; #endif if (INT64_MAX - _bytesWritten < (int64_t)length) @throw [OFOutOfRangeException exception]; bytesWritten = [_stream writeBuffer: buffer length: length]; _bytesWritten += (int64_t)bytesWritten; _CRC32 = OFCRC32(_CRC32, buffer, length); return bytesWritten; } - (void)close { if (_stream == nil) |
︙ | ︙ |
Modified src/OFZIPArchiveEntry.h from [2df45ec20c] to [e18b985df3].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** @file */ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > | > | < > > > | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #import "OFObject.h" OF_ASSUME_NONNULL_BEGIN /** @file */ typedef enum { OFZIPArchiveEntryCompressionMethodNone = 0, OFZIPArchiveEntryCompressionMethodShrink = 1, OFZIPArchiveEntryCompressionMethodReduceFactor1 = 2, OFZIPArchiveEntryCompressionMethodReduceFactor2 = 3, OFZIPArchiveEntryCompressionMethodReduceFactor3 = 4, OFZIPArchiveEntryCompressionMethodReduceFactor4 = 5, OFZIPArchiveEntryCompressionMethodImplode = 6, OFZIPArchiveEntryCompressionMethodDeflate = 8, OFZIPArchiveEntryCompressionMethodDeflate64 = 9, OFZIPArchiveEntryCompressionMethodBZIP2 = 12, OFZIPArchiveEntryCompressionMethodLZMA = 14, OFZIPArchiveEntryCompressionMethodWavPack = 97, OFZIPArchiveEntryCompressionMethodPPMd = 98 } OFZIPArchiveEntryCompressionMethod; /** * @brief Attribute compatibility part of ZIP versions. */ typedef enum { /** MS-DOS and OS/2 */ OFZIPArchiveEntryAttributeCompatibilityMSDOS = 0, /** Amiga */ OFZIPArchiveEntryAttributeCompatibilityAmiga = 1, /** OpenVMS */ OFZIPArchiveEntryAttributeCompatibilityOpenVMS = 2, /** UNIX */ OFZIPArchiveEntryAttributeCompatibilityUNIX = 3, /** VM/CMS */ OFZIPArchiveEntryAttributeCompatibilityVM_CMS = 4, /** Atari ST */ OFZIPArchiveEntryAttributeCompatibilityAtariST = 5, /** OS/2 HPFS */ OFZIPArchiveEntryAttributeCompatibilityOS2HPFS = 6, /** Macintosh */ OFZIPArchiveEntryAttributeCompatibilityMacintosh = 7, /** Z-System */ OFZIPArchiveEntryAttributeCompatibilityZSystem = 8, /** CP/M */ OFZIPArchiveEntryAttributeCompatibilityCPM = 9, /** Windows NTFS */ OFZIPArchiveEntryAttributeCompatibilityWindowsNTFS = 10, /** MVS (OS/390 - Z/OS) */ OFZIPArchiveEntryAttributeCompatibilityMVS = 11, /** VSE */ OFZIPArchiveEntryAttributeCompatibilityVSE = 12, /** Acorn RISC OS */ OFZIPArchiveEntryAttributeCompatibilityAcornRISCOS = 13, /** VFAT */ OFZIPArchiveEntryAttributeCompatibilityVFAT = 14, /** Alternate MVS */ OFZIPArchiveEntryAttributeCompatibilityAlternateMVS = 15, /** BeOS */ OFZIPArchiveEntryAttributeCompatibilityBeOS = 16, /** Tandem */ OFZIPArchiveEntryAttributeCompatibilityTandem = 17, /** OS/400 */ OFZIPArchiveEntryAttributeCompatibilityOS400 = 18, /** OS X (Darwin) */ OFZIPArchiveEntryAttributeCompatibilityOSX = 19 } OFZIPArchiveEntryAttributeCompatibility; /** * @brief Tags for the extra field. */ typedef enum { /** ZIP64 extra field tag */ OFZIPArchiveEntryExtraFieldTagZIP64 = 0x0001 } OFZIPArchiveEntryExtraFieldTag; @class OFString; @class OFData; @class OFFile; @class OFDate; /** * @class OFZIPArchiveEntry OFZIPArchiveEntry.h ObjFW/OFZIPArchiveEntry.h * * @brief A class which represents an entry in the central directory of a ZIP * archive. */ @interface OFZIPArchiveEntry: OFObject <OFCopying, OFMutableCopying> { OFZIPArchiveEntryAttributeCompatibility _versionMadeBy; OFZIPArchiveEntryAttributeCompatibility _minVersionNeeded; uint16_t _generalPurposeBitFlag; OFZIPArchiveEntryCompressionMethod _compressionMethod; uint16_t _lastModifiedFileTime, _lastModifiedFileDate; uint32_t _CRC32; uint64_t _compressedSize, _uncompressedSize; OFString *_fileName; OFData *_Nullable _extraField; OFString *_Nullable _fileComment; uint32_t _startDiskNumber; |
︙ | ︙ | |||
132 133 134 135 136 137 138 | @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFData *extraField; /** * @brief The version which made the entry. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. | | | > | | > | | | | | | > | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | @property OF_NULLABLE_PROPERTY (readonly, copy, nonatomic) OFData *extraField; /** * @brief The version which made the entry. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readonly, nonatomic) OFZIPArchiveEntryAttributeCompatibility versionMadeBy; /** * @brief The minimum version required to extract the file. * * The lower 8 bits are the ZIP specification version.@n * The upper 8 bits are the attribute compatibility. * See @ref OFZIPArchiveEntryAttributeCompatibility. */ @property (readonly, nonatomic) OFZIPArchiveEntryAttributeCompatibility minVersionNeeded; /** * @brief The last modification date of the entry's file. * * @note Due to limitations of the ZIP format, this has only 2 second precision. */ @property (readonly, retain, nonatomic) OFDate *modificationDate; /** * @brief The compression method of the entry. * * Supported values are: * Value | Description * --------------------------------------------|--------------- * OFZIPArchiveEntryCompressionMethodNone | No compression * OFZIPArchiveEntryCompressionMethodDeflate | Deflate * OFZIPArchiveEntryCompressionMethodDeflate64 | Deflate64 * * Other values may be returned, but the file cannot be extracted then. */ @property (readonly, nonatomic) OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The compressed size of the entry's file. */ @property (readonly, nonatomic) uint64_t compressedSize; /** |
︙ | ︙ | |||
225 226 227 228 229 230 231 | #endif /** * @brief Converts the ZIP entry version to a string. * * @param version The ZIP entry version to convert to a string * @return The ZIP entry version as a string */ | | | | | | | | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | #endif /** * @brief Converts the ZIP entry version to a string. * * @param version The ZIP entry version to convert to a string * @return The ZIP entry version as a string */ extern OFString *OFZIPArchiveEntryVersionToString(uint16_t version); /** * @brief Convers the ZIP entry compression method to a string. * * @param compressionMethod The ZIP entry compression method to convert to a * string * @return The ZIP entry compression method as a string */ extern OFString *OFZIPArchiveEntryCompressionMethodName( OFZIPArchiveEntryCompressionMethod compressionMethod); /** * @brief Gets a pointer to and the size of the extensible data field with the * specified tag. * * @param extraField The extra field to search for an extensible data field with * the specified tag * @param tag The tag to look for * @param size A pointer to an uint16_t that should be set to the size * @return The index at which the extra field content starts in the OFData, or * `OFNotFound` */ extern size_t OFZIPArchiveEntryExtraFieldFind(OFData *extraField, OFZIPArchiveEntryExtraFieldTag tag, uint16_t *size); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END #import "OFMutableZIPArchiveEntry.h" |
Modified src/OFZIPArchiveEntry.m from [1b0f865f32] to [a82b90cc04].
︙ | ︙ | |||
22 23 24 25 26 27 28 | #import "OFStream.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" | < < < | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #import "OFStream.h" #import "OFString.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" OFString * OFZIPArchiveEntryVersionToString(uint16_t version) { const char *attrCompat = NULL; switch (version >> 8) { case OFZIPArchiveEntryAttributeCompatibilityMSDOS: attrCompat = "MS-DOS or OS/2"; break; case OFZIPArchiveEntryAttributeCompatibilityAmiga: attrCompat = "Amiga"; break; case OFZIPArchiveEntryAttributeCompatibilityOpenVMS: attrCompat = "OpenVMS"; break; case OFZIPArchiveEntryAttributeCompatibilityUNIX: attrCompat = "UNIX"; break; case OFZIPArchiveEntryAttributeCompatibilityVM_CMS: attrCompat = "VM/CMS"; break; case OFZIPArchiveEntryAttributeCompatibilityAtariST: attrCompat = "Atari ST"; break; case OFZIPArchiveEntryAttributeCompatibilityOS2HPFS: attrCompat = "OS/2 HPFS"; break; case OFZIPArchiveEntryAttributeCompatibilityMacintosh: attrCompat = "Macintosh"; break; case OFZIPArchiveEntryAttributeCompatibilityZSystem: attrCompat = "Z-System"; break; case OFZIPArchiveEntryAttributeCompatibilityCPM: attrCompat = "CP/M"; break; case OFZIPArchiveEntryAttributeCompatibilityWindowsNTFS: attrCompat = "Windows NTFS"; break; case OFZIPArchiveEntryAttributeCompatibilityMVS: attrCompat = "MVS (OS/390 - Z/OS)"; break; case OFZIPArchiveEntryAttributeCompatibilityVSE: attrCompat = "VSE"; break; case OFZIPArchiveEntryAttributeCompatibilityAcornRISCOS: attrCompat = "Acorn RISC OS"; break; case OFZIPArchiveEntryAttributeCompatibilityVFAT: attrCompat = "VFAT"; break; case OFZIPArchiveEntryAttributeCompatibilityAlternateMVS: attrCompat = "Alternate MVS"; break; case OFZIPArchiveEntryAttributeCompatibilityBeOS: attrCompat = "BeOS"; break; case OFZIPArchiveEntryAttributeCompatibilityTandem: attrCompat = "Tandem"; break; case OFZIPArchiveEntryAttributeCompatibilityOS400: attrCompat = "OS/400"; break; case OFZIPArchiveEntryAttributeCompatibilityOSX: attrCompat = "OS X (Darwin)"; break; } if (attrCompat != NULL) return [OFString stringWithFormat: @"%u.%u, %s", (version & 0xFF) / 10, (version & 0xFF) % 10, attrCompat]; else return [OFString stringWithFormat: @"%u.%u, unknown %02X", (version % 0xFF) / 10, (version & 0xFF) % 10, version >> 8]; } OFString * OFZIPArchiveEntryCompressionMethodName( OFZIPArchiveEntryCompressionMethod compressionMethod) { switch (compressionMethod) { case OFZIPArchiveEntryCompressionMethodNone: return @"none"; case OFZIPArchiveEntryCompressionMethodShrink: return @"Shrink"; case OFZIPArchiveEntryCompressionMethodReduceFactor1: return @"Reduce (factor 1)"; case OFZIPArchiveEntryCompressionMethodReduceFactor2: return @"Reduce (factor 2)"; case OFZIPArchiveEntryCompressionMethodReduceFactor3: return @"Reduce (factor 3)"; case OFZIPArchiveEntryCompressionMethodReduceFactor4: return @"Reduce (factor 4)"; case OFZIPArchiveEntryCompressionMethodImplode: return @"Implode"; case OFZIPArchiveEntryCompressionMethodDeflate: return @"Deflate"; case OFZIPArchiveEntryCompressionMethodDeflate64: return @"Deflate64"; case OFZIPArchiveEntryCompressionMethodBZIP2: return @"BZip2"; case OFZIPArchiveEntryCompressionMethodLZMA: return @"LZMA"; case OFZIPArchiveEntryCompressionMethodWavPack: return @"WavPack"; case OFZIPArchiveEntryCompressionMethodPPMd: return @"PPMd"; default: return @"unknown"; } } size_t OFZIPArchiveEntryExtraFieldFind(OFData *extraField, OFZIPArchiveEntryExtraFieldTag tag, uint16_t *size) { const uint8_t *bytes = extraField.items; size_t count = extraField.count; for (size_t i = 0; i < count;) { uint16_t currentTag, currentSize; |
︙ | ︙ | |||
166 167 168 169 170 171 172 | return i + 4; } i += 4 + currentSize; } *size = 0; | | | 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | return i + 4; } i += 4 + currentSize; } *size = 0; return OFNotFound; } @implementation OFZIPArchiveEntry + (instancetype)entryWithFileName: (OFString *)fileName { return [[[self alloc] initWithFileName: fileName] autorelease]; } |
︙ | ︙ | |||
209 210 211 212 213 214 215 | { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *extraField = nil; uint16_t fileNameLength, extraFieldLength, fileCommentLength; | | | 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); OFMutableData *extraField = nil; uint16_t fileNameLength, extraFieldLength, fileCommentLength; OFStringEncoding encoding; size_t ZIP64Index; uint16_t ZIP64Size; if ([stream readLittleEndianInt32] != 0x02014B50) @throw [OFInvalidFormatException exception]; _versionMadeBy = [stream readLittleEndianInt16]; |
︙ | ︙ | |||
234 235 236 237 238 239 240 | fileCommentLength = [stream readLittleEndianInt16]; _startDiskNumber = [stream readLittleEndianInt16]; _internalAttributes = [stream readLittleEndianInt16]; _versionSpecificAttributes = [stream readLittleEndianInt32]; _localFileHeaderOffset = [stream readLittleEndianInt32]; encoding = (_generalPurposeBitFlag & (1u << 11) | | < | | | | | | | < | | | 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | fileCommentLength = [stream readLittleEndianInt16]; _startDiskNumber = [stream readLittleEndianInt16]; _internalAttributes = [stream readLittleEndianInt16]; _versionSpecificAttributes = [stream readLittleEndianInt32]; _localFileHeaderOffset = [stream readLittleEndianInt32]; encoding = (_generalPurposeBitFlag & (1u << 11) ? OFStringEncodingUTF8 : OFStringEncodingCodepage437); _fileName = [[stream readStringWithLength: fileNameLength encoding: encoding] copy]; if (extraFieldLength > 0) extraField = [[[stream readDataWithCount: extraFieldLength] mutableCopy] autorelease]; if (fileCommentLength > 0) _fileComment = [[stream readStringWithLength: fileCommentLength encoding: encoding] copy]; ZIP64Index = OFZIPArchiveEntryExtraFieldFind(extraField, OFZIPArchiveEntryExtraFieldTagZIP64, &ZIP64Size); if (ZIP64Index != OFNotFound) { const uint8_t *ZIP64 = [extraField itemAtIndex: ZIP64Index]; OFRange range = OFRangeMake(ZIP64Index - 4, ZIP64Size + 4); if (_uncompressedSize == 0xFFFFFFFF) _uncompressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_compressedSize == 0xFFFFFFFF) _compressedSize = OFZIPArchiveReadField64( &ZIP64, &ZIP64Size); if (_localFileHeaderOffset == 0xFFFFFFFF) _localFileHeaderOffset = OFZIPArchiveReadField64(&ZIP64, &ZIP64Size); if (_startDiskNumber == 0xFFFF) _startDiskNumber = OFZIPArchiveReadField32( &ZIP64, &ZIP64Size); if (ZIP64Size > 0 || _localFileHeaderOffset < 0) @throw [OFInvalidFormatException exception]; [extraField removeItemsInRange: range]; } |
︙ | ︙ | |||
348 349 350 351 352 353 354 | } - (OFData *)extraField { return _extraField; } | | | | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | } - (OFData *)extraField { return _extraField; } - (OFZIPArchiveEntryAttributeCompatibility)versionMadeBy { return _versionMadeBy; } - (OFZIPArchiveEntryAttributeCompatibility)minVersionNeeded { return _minVersionNeeded; } - (OFDate *)modificationDate { void *pool = objc_autoreleasePoolPush(); |
︙ | ︙ | |||
382 383 384 385 386 387 388 | format: @"%Y-%m-%d %H:%M:%S"]; objc_autoreleasePoolPop(pool); return [date autorelease]; } | | | 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | format: @"%Y-%m-%d %H:%M:%S"]; objc_autoreleasePoolPop(pool); return [date autorelease]; } - (OFZIPArchiveEntryCompressionMethod)compressionMethod { return _compressionMethod; } - (uint64_t)compressedSize { return _compressedSize; |
︙ | ︙ | |||
431 432 433 434 435 436 437 | return _localFileHeaderOffset; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *compressionMethod = | < | | 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | return _localFileHeaderOffset; } - (OFString *)description { void *pool = objc_autoreleasePoolPush(); OFString *compressionMethod = OFZIPArchiveEntryCompressionMethodName(_compressionMethod); OFString *ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tFile comment = %@\n" @"\tGeneral purpose bit flag = %u\n" @"\tCompressed size = %" @PRIu64 "\n" @"\tUncompressed size = %" @PRIu64 "\n" |
︙ | ︙ | |||
487 488 489 490 491 492 493 | [stream writeLittleEndianInt32: _versionSpecificAttributes]; [stream writeLittleEndianInt32: 0xFFFFFFFF]; size += (4 + (6 * 2) + (3 * 4) + (5 * 2) + (2 * 4)); [stream writeString: _fileName]; size += (uint64_t)_fileName.UTF8StringLength; | | | 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | [stream writeLittleEndianInt32: _versionSpecificAttributes]; [stream writeLittleEndianInt32: 0xFFFFFFFF]; size += (4 + (6 * 2) + (3 * 4) + (5 * 2) + (2 * 4)); [stream writeString: _fileName]; size += (uint64_t)_fileName.UTF8StringLength; [stream writeLittleEndianInt16: OFZIPArchiveEntryExtraFieldTagZIP64]; [stream writeLittleEndianInt16: 28]; [stream writeLittleEndianInt64: _uncompressedSize]; [stream writeLittleEndianInt64: _compressedSize]; [stream writeLittleEndianInt64: _localFileHeaderOffset]; [stream writeLittleEndianInt32: _startDiskNumber]; size += (2 * 2) + (3 * 8) + 4; |
︙ | ︙ |
Modified src/ObjFW.h from [b6085669fc] to [304cf44661].
︙ | ︙ | |||
79 80 81 82 83 84 85 | # import "OFDNSResponse.h" # import "OFDNSResolver.h" # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # import "OFSPXSocket.h" # import "OFSPXStreamSocket.h" # endif | < < < | | | | < < < < < < < < < < < < < | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | # import "OFDNSResponse.h" # import "OFDNSResolver.h" # ifdef OF_HAVE_IPX # import "OFIPXSocket.h" # import "OFSPXSocket.h" # import "OFSPXStreamSocket.h" # endif #endif #ifdef OF_HAVE_SOCKETS # ifdef OF_HAVE_THREADS # import "OFHTTPClient.h" # endif # import "OFHTTPCookie.h" # import "OFHTTPCookieManager.h" # import "OFHTTPRequest.h" # import "OFHTTPResponse.h" # import "OFHTTPServer.h" #endif #ifdef OF_HAVE_SUBPROCESSES # import "OFSubprocess.h" #endif #import "OFCryptographicHash.h" #import "OFMD5Hash.h" #import "OFRIPEMD160Hash.h" #import "OFSHA1Hash.h" #import "OFSHA224Hash.h" #import "OFSHA256Hash.h" #import "OFSHA384Hash.h" #import "OFSHA512Hash.h" #import "OFHMAC.h" #import "OFXMLAttribute.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFXMLCharacters.h" #import "OFXMLCDATA.h" #import "OFXMLComment.h" #import "OFXMLProcessingInstruction.h" #import "OFXMLParser.h" #import "OFXMLElementBuilder.h" #import "OFMessagePackExtension.h" #import "OFApplication.h" #import "OFSystemInfo.h" #import "OFLocale.h" #import "OFOptionsParser.h" #import "OFTimer.h" #import "OFRunLoop.h" #ifdef OF_WINDOWS # import "OFWindowsRegistryKey.h" #endif #import "OFAllocFailedException.h" #import "OFException.h" #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindFailedException.h" #endif |
︙ | ︙ | |||
223 224 225 226 227 228 229 | #import "OFReadFailedException.h" #import "OFReadOrWriteFailedException.h" #import "OFRemoveItemFailedException.h" #ifdef OF_HAVE_SOCKETS # import "OFResolveHostFailedException.h" #endif #import "OFRetrieveItemAttributesFailedException.h" | < | 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | #import "OFReadFailedException.h" #import "OFReadOrWriteFailedException.h" #import "OFRemoveItemFailedException.h" #ifdef OF_HAVE_SOCKETS # import "OFResolveHostFailedException.h" #endif #import "OFRetrieveItemAttributesFailedException.h" #import "OFSeekFailedException.h" #import "OFSetItemAttributesFailedException.h" #import "OFSetOptionFailedException.h" #ifdef OF_WINDOWS # import "OFSetWindowsRegistryValueFailedException.h" #endif #import "OFStillLockedException.h" |
︙ | ︙ | |||
251 252 253 254 255 256 257 | #import "OFWriteFailedException.h" #ifdef OF_HAVE_PLUGINS # import "OFPlugin.h" #endif #ifdef OF_HAVE_ATOMIC_OPS | | < | | | | | < | | | > | | | | | | | | < < < | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | #import "OFWriteFailedException.h" #ifdef OF_HAVE_PLUGINS # import "OFPlugin.h" #endif #ifdef OF_HAVE_ATOMIC_OPS # import "OFAtomic.h" #endif #import "OFLocking.h" #import "OFOnce.h" #import "OFThread.h" #ifdef OF_HAVE_THREADS # import "OFCondition.h" # import "OFMutex.h" # import "OFPlainCondition.h" # import "OFPlainMutex.h" # import "OFPlainThread.h" # import "OFRecursiveMutex.h" # import "OFTLSKey.h" # import "OFThreadPool.h" #endif #import "OFASPrintF.h" #import "OFBase64.h" #import "OFCRC16.h" #import "OFCRC32.h" #import "OFHuffmanTree.h" #import "OFPBKDF2.h" #import "OFScrypt.h" #import "OFStrPTime.h" |
Modified src/amiga-funcarray.inc from [2929560b57] to [49370bf0a9].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ /* This file is automatically generated from library.xml */ | | | | | | | | | | | | | | | | | | | | | > > > > | | | | | | | | | | | | | | | | | | | | > | | | | > | | | > > > | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ /* This file is automatically generated from library.xml */ (CONST_APTR)glue_OFInit, (CONST_APTR)glue_OFAllocMemory, (CONST_APTR)glue_OFAllocZeroedMemory, (CONST_APTR)glue_OFResizeMemory, (CONST_APTR)glue_OFFreeMemory, (CONST_APTR)glue_OFHashInit, (CONST_APTR)glue_OFRandom16, (CONST_APTR)glue_OFRandom32, (CONST_APTR)glue_OFRandom64, (CONST_APTR)glue_OFHashSeedRef, (CONST_APTR)glue_OFStdInRef, (CONST_APTR)glue_OFStdOutRef, (CONST_APTR)glue_OFStdErrRef, (CONST_APTR)glue_OFLogV, (CONST_APTR)glue_OFApplicationMain, (CONST_APTR)glue__Block_copy, (CONST_APTR)glue__Block_release, (CONST_APTR)glue_OFDNSClassName, (CONST_APTR)glue_OFDNSRecordTypeName, (CONST_APTR)glue_OFDNSClassParseName, (CONST_APTR)glue_OFDNSRecordTypeParseName, (CONST_APTR)glue_OFHTTPRequestMethodName, (CONST_APTR)glue_OFHTTPRequestMethodParseName, (CONST_APTR)glue_OFHTTPStatusCodeString, (CONST_APTR)glue_OFListItemNext, (CONST_APTR)glue_OFListItemPrevious, (CONST_APTR)glue_OFListItemObject, (CONST_APTR)glue_OFSizeOfTypeEncoding, (CONST_APTR)glue_OFAlignmentOfTypeEncoding, (CONST_APTR)glue_OFOnce, (CONST_APTR)glue_OFPBKDF2, (CONST_APTR)glue_OFScrypt, (CONST_APTR)glue_OFSalsa20_8Core, (CONST_APTR)glue_OFScryptBlockMix, (CONST_APTR)glue_OFScryptROMix, (CONST_APTR)glue_OFSocketAddressParseIP, (CONST_APTR)glue_OFSocketAddressParseIPv4, (CONST_APTR)glue_OFSocketAddressParseIPv6, (CONST_APTR)glue_OFSocketAddressMakeIPX, (CONST_APTR)glue_OFSocketAddressEqual, (CONST_APTR)glue_OFSocketAddressHash, (CONST_APTR)glue_OFSocketAddressString, (CONST_APTR)glue_OFSocketAddressSetPort, (CONST_APTR)glue_OFSocketAddressPort, (CONST_APTR)glue_OFSocketAddressSetIPXNetwork, (CONST_APTR)glue_OFSocketAddressIPXNetwork, (CONST_APTR)glue_OFSocketAddressSetIPXNode, (CONST_APTR)glue_OFSocketAddressIPXNode, (CONST_APTR)glue_OFStrPTime, (CONST_APTR)glue_OFStringEncodingParseName, (CONST_APTR)glue_OFStringEncodingName, (CONST_APTR)glue_OFUTF16StringLength, (CONST_APTR)glue_OFUTF32StringLength, (CONST_APTR)glue_OFZIPArchiveEntryVersionToString, (CONST_APTR)glue_OFZIPArchiveEntryCompressionMethodName, (CONST_APTR)glue_OFZIPArchiveEntryExtraFieldFind, |
Modified src/amiga-glue.h from [ac796e9fe8] to [2e0af03a29].
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 | /* This file is automatically generated from library.xml */ #import "amiga-library.h" #import "OFObject.h" #import "OFStdIOStream.h" #import "OFApplication.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFMethodSignature.h" | > > > | | | | | | | | | | | > > > | > > | | | | | > > > > > > | | | > > > | | | < | < < < < < < | | | | < < | | | | | | | | | | | | | > > | > > | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | /* This file is automatically generated from library.xml */ #import "amiga-library.h" #import "OFObject.h" #import "OFStdIOStream.h" #import "OFApplication.h" #import "OFBlock.h" #import "OFDNSResourceRecord.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFList.h" #import "OFMethodSignature.h" #import "OFOnce.h" #import "OFPBKDF2.h" #import "OFScrypt.h" #import "OFSocket.h" #import "OFStrPTime.h" #import "OFString.h" #import "OFZIPArchiveEntry.h" #ifdef OF_AMIGAOS_M68K # define PPC_PARAMS(...) (void) # define M68K_ARG(type, name, reg) \ register type reg##name __asm__(#reg); \ type name = reg##name; #else # define PPC_PARAMS(...) (__VA_ARGS__) # define M68K_ARG(...) #endif extern bool glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc, FILE *_Nonnull *_Nonnull sF); extern void *_Nullable glue_OFAllocMemory PPC_PARAMS(size_t count, size_t size); extern void *_Nullable glue_OFAllocZeroedMemory PPC_PARAMS(size_t count, size_t size); extern void *_Nullable glue_OFResizeMemory PPC_PARAMS(void *_Nullable pointer, size_t count, size_t size); extern void glue_OFFreeMemory PPC_PARAMS(void *_Nullable pointer); extern void glue_OFHashInit PPC_PARAMS(unsigned long *_Nonnull hash); extern uint16_t glue_OFRandom16(void); extern uint32_t glue_OFRandom32(void); extern uint64_t glue_OFRandom64(void); extern unsigned long *_Nonnull glue_OFHashSeedRef(void); extern OFStdIOStream *_Nonnull *_Nullable glue_OFStdInRef(void); extern OFStdIOStream *_Nonnull *_Nullable glue_OFStdOutRef(void); extern OFStdIOStream *_Nonnull *_Nullable glue_OFStdErrRef(void); extern void glue_OFLogV PPC_PARAMS(OFConstantString *format, va_list arguments); extern int glue_OFApplicationMain PPC_PARAMS(int *_Nonnull argc, char *_Nullable *_Nonnull *_Nonnull argv, id <OFApplicationDelegate> delegate); extern void *_Nullable glue__Block_copy PPC_PARAMS(const void *_Nullable block); extern void glue__Block_release PPC_PARAMS(const void *_Nullable block); extern OFString *_Nonnull glue_OFDNSClassName PPC_PARAMS(OFDNSClass DNSClass); extern OFString *_Nonnull glue_OFDNSRecordTypeName PPC_PARAMS(OFDNSRecordType recordType); extern OFDNSClass glue_OFDNSClassParseName PPC_PARAMS(OFString *_Nonnull string); extern OFDNSRecordType glue_OFDNSRecordTypeParseName PPC_PARAMS(OFString *_Nonnull string); extern const char *_Nullable glue_OFHTTPRequestMethodName PPC_PARAMS(OFHTTPRequestMethod method); extern OFHTTPRequestMethod glue_OFHTTPRequestMethodParseName PPC_PARAMS(OFString *string); extern OFString *_Nonnull glue_OFHTTPStatusCodeString PPC_PARAMS(short code); extern OFListItem _Nullable glue_OFListItemNext PPC_PARAMS(OFListItem _Nonnull listItem); extern OFListItem _Nullable glue_OFListItemPrevious PPC_PARAMS(OFListItem _Nonnull listItem); extern id _Nonnull glue_OFListItemObject PPC_PARAMS(OFListItem _Nonnull listItem); extern size_t glue_OFSizeOfTypeEncoding PPC_PARAMS(const char *type); extern size_t glue_OFAlignmentOfTypeEncoding PPC_PARAMS(const char *type); extern void glue_OFOnce PPC_PARAMS(OFOnceControl *_Nonnull control, OFOnceFunction _Nonnull func); extern void glue_OFPBKDF2 PPC_PARAMS(OFPBKDF2Parameters parameters); extern void glue_OFScrypt PPC_PARAMS(OFScryptParameters parameters); extern void glue_OFSalsa20_8Core PPC_PARAMS(uint32_t *_Nonnull buffer); extern void glue_OFScryptBlockMix PPC_PARAMS(uint32_t *_Nonnull output, const uint32_t *_Nonnull input, size_t blockSize); extern void glue_OFScryptROMix PPC_PARAMS(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp); extern OFSocketAddress glue_OFSocketAddressParseIP PPC_PARAMS(OFString *IP, uint16_t port); extern OFSocketAddress glue_OFSocketAddressParseIPv4 PPC_PARAMS(OFString *IP, uint16_t port); extern OFSocketAddress glue_OFSocketAddressParseIPv6 PPC_PARAMS(OFString *IP, uint16_t port); extern OFSocketAddress glue_OFSocketAddressMakeIPX PPC_PARAMS(const unsigned char *_Nonnull node, uint32_t network, uint16_t port); extern bool glue_OFSocketAddressEqual PPC_PARAMS(const OFSocketAddress *_Nonnull address1, const OFSocketAddress *_Nonnull address2); extern unsigned long glue_OFSocketAddressHash PPC_PARAMS(const OFSocketAddress *_Nonnull address); extern OFString *_Nonnull glue_OFSocketAddressString PPC_PARAMS(const OFSocketAddress *_Nonnull address); extern void glue_OFSocketAddressSetPort PPC_PARAMS(OFSocketAddress *_Nonnull address, uint16_t port); extern uint16_t glue_OFSocketAddressPort PPC_PARAMS(const OFSocketAddress *_Nonnull address); extern void glue_OFSocketAddressSetIPXNetwork PPC_PARAMS(OFSocketAddress *_Nonnull address, uint32_t network); extern uint32_t glue_OFSocketAddressIPXNetwork PPC_PARAMS(const OFSocketAddress *_Nonnull address); extern void glue_OFSocketAddressSetIPXNode PPC_PARAMS(OFSocketAddress *_Nonnull address, const unsigned char *_Nonnull node); extern void glue_OFSocketAddressIPXNode PPC_PARAMS(const OFSocketAddress *_Nonnull address, unsigned char *_Nonnull node); extern const char *_Nullable glue_OFStrPTime PPC_PARAMS(const char *buffer, const char *format, struct tm *tm, int16_t *_Nullable tz); extern OFStringEncoding glue_OFStringEncodingParseName PPC_PARAMS(OFString *string); extern OFString *_Nullable glue_OFStringEncodingName PPC_PARAMS(OFStringEncoding encoding); extern size_t glue_OFUTF16StringLength PPC_PARAMS(const OFChar16 *string); extern size_t glue_OFUTF32StringLength PPC_PARAMS(const OFChar32 *string); extern OFString *_Nonnull glue_OFZIPArchiveEntryVersionToString PPC_PARAMS(uint16_t version); extern OFString *_Nonnull glue_OFZIPArchiveEntryCompressionMethodName PPC_PARAMS(OFZIPArchiveEntryCompressionMethod compressionMethod); extern size_t glue_OFZIPArchiveEntryExtraFieldFind PPC_PARAMS(OFData *extraField, OFZIPArchiveEntryExtraFieldTag tag, uint16_t *size); |
Modified src/amiga-glue.m from [eb6613e2c6] to [adf8c12199].
︙ | ︙ | |||
27 28 29 30 31 32 33 | "__restore_r13:\n" " lwz %r13, 44(%r12)\n" " blr\n" ); #endif bool __saveds | | | | | | | | | | | > > > | > > | > > > > | > | > > > > | > > | > > > | > > > > > > > > > | | > > > > | > > | | | | | | | | | | | > | > | < | < | | | | | | | > > > | < < < | | | | | > > | > > > > | > | | > | | | | | < | | | | | | > > | > > | > | > | | | | | | | | | < | < | > | > | | > | < > | | | < < < > | | | | | | | | | | | < | < < | < < | < < < < | < | | < < | < < < < < | < | < | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | > > > > > > > > > > > | | > > > > > > > | > | > | | < | < > | | | | | | > | > | | > > > > | > > > > > | > | | > | | > | > | > | | | > > | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | "__restore_r13:\n" " lwz %r13, 44(%r12)\n" " blr\n" ); #endif bool __saveds glue_OFInit PPC_PARAMS(unsigned int version, struct OFLibC *_Nonnull libc, FILE *_Nonnull *_Nonnull sF) { M68K_ARG(unsigned int, version, d0) M68K_ARG(struct OFLibC *_Nonnull, libc, a0) M68K_ARG(FILE *_Nonnull *_Nonnull, sF, a1) return OFInit(version, libc, sF); } void *_Nullable __saveds glue_OFAllocMemory PPC_PARAMS(size_t count, size_t size) { M68K_ARG(size_t, count, d0) M68K_ARG(size_t, size, d1) return OFAllocMemory(count, size); } void *_Nullable __saveds glue_OFAllocZeroedMemory PPC_PARAMS(size_t count, size_t size) { M68K_ARG(size_t, count, d0) M68K_ARG(size_t, size, d1) return OFAllocZeroedMemory(count, size); } void *_Nullable __saveds glue_OFResizeMemory PPC_PARAMS(void *_Nullable pointer, size_t count, size_t size) { M68K_ARG(void *_Nullable, pointer, a0) M68K_ARG(size_t, count, d0) M68K_ARG(size_t, size, d1) return OFResizeMemory(pointer, count, size); } void __saveds glue_OFFreeMemory PPC_PARAMS(void *_Nullable pointer) { M68K_ARG(void *_Nullable, pointer, a0) OFFreeMemory(pointer); } void __saveds glue_OFHashInit PPC_PARAMS(unsigned long *_Nonnull hash) { M68K_ARG(unsigned long *_Nonnull, hash, a0) OFHashInit(hash); } uint16_t __saveds glue_OFRandom16(void) { return OFRandom16(); } uint32_t __saveds glue_OFRandom32(void) { return OFRandom32(); } uint64_t __saveds glue_OFRandom64(void) { return OFRandom64(); } unsigned long *_Nonnull __saveds glue_OFHashSeedRef(void) { return OFHashSeedRef(); } OFStdIOStream *_Nonnull *_Nullable __saveds glue_OFStdInRef(void) { return OFStdInRef(); } OFStdIOStream *_Nonnull *_Nullable __saveds glue_OFStdOutRef(void) { return OFStdOutRef(); } OFStdIOStream *_Nonnull *_Nullable __saveds glue_OFStdErrRef(void) { return OFStdErrRef(); } void __saveds glue_OFLogV PPC_PARAMS(OFConstantString *format, va_list arguments) { M68K_ARG(OFConstantString *, format, a0) M68K_ARG(va_list, arguments, a1) OFLogV(format, arguments); } int __saveds glue_OFApplicationMain PPC_PARAMS(int *_Nonnull argc, char *_Nullable *_Nonnull *_Nonnull argv, id <OFApplicationDelegate> delegate) { M68K_ARG(int *_Nonnull, argc, a0) M68K_ARG(char *_Nullable *_Nonnull *_Nonnull, argv, a1) M68K_ARG(id <OFApplicationDelegate>, delegate, a2) return OFApplicationMain(argc, argv, delegate); } void *_Nullable __saveds glue__Block_copy PPC_PARAMS(const void *_Nullable block) { M68K_ARG(const void *_Nullable, block, a0) return _Block_copy(block); } void __saveds glue__Block_release PPC_PARAMS(const void *_Nullable block) { M68K_ARG(const void *_Nullable, block, a0) _Block_release(block); } OFString *_Nonnull __saveds glue_OFDNSClassName PPC_PARAMS(OFDNSClass DNSClass) { M68K_ARG(OFDNSClass, DNSClass, d0) return OFDNSClassName(DNSClass); } OFString *_Nonnull __saveds glue_OFDNSRecordTypeName PPC_PARAMS(OFDNSRecordType recordType) { M68K_ARG(OFDNSRecordType, recordType, d0) return OFDNSRecordTypeName(recordType); } OFDNSClass __saveds glue_OFDNSClassParseName PPC_PARAMS(OFString *_Nonnull string) { M68K_ARG(OFString *_Nonnull, string, a0) return OFDNSClassParseName(string); } OFDNSRecordType __saveds glue_OFDNSRecordTypeParseName PPC_PARAMS(OFString *_Nonnull string) { M68K_ARG(OFString *_Nonnull, string, a0) return OFDNSRecordTypeParseName(string); } const char *_Nullable __saveds glue_OFHTTPRequestMethodName PPC_PARAMS(OFHTTPRequestMethod method) { M68K_ARG(OFHTTPRequestMethod, method, d0) return OFHTTPRequestMethodName(method); } OFHTTPRequestMethod __saveds glue_OFHTTPRequestMethodParseName PPC_PARAMS(OFString *string) { M68K_ARG(OFString *, string, a0) return OFHTTPRequestMethodParseName(string); } OFString *_Nonnull __saveds glue_OFHTTPStatusCodeString PPC_PARAMS(short code) { M68K_ARG(short, code, d0) return OFHTTPStatusCodeString(code); } OFListItem _Nullable __saveds glue_OFListItemNext PPC_PARAMS(OFListItem _Nonnull listItem) { M68K_ARG(OFListItem _Nonnull, listItem, a0) return OFListItemNext(listItem); } OFListItem _Nullable __saveds glue_OFListItemPrevious PPC_PARAMS(OFListItem _Nonnull listItem) { M68K_ARG(OFListItem _Nonnull, listItem, a0) return OFListItemPrevious(listItem); } id _Nonnull __saveds glue_OFListItemObject PPC_PARAMS(OFListItem _Nonnull listItem) { M68K_ARG(OFListItem _Nonnull, listItem, a0) return OFListItemObject(listItem); } size_t __saveds glue_OFSizeOfTypeEncoding PPC_PARAMS(const char *type) { M68K_ARG(const char *, type, a0) return OFSizeOfTypeEncoding(type); } size_t __saveds glue_OFAlignmentOfTypeEncoding PPC_PARAMS(const char *type) { M68K_ARG(const char *, type, a0) return OFAlignmentOfTypeEncoding(type); } void __saveds glue_OFOnce PPC_PARAMS(OFOnceControl *_Nonnull control, OFOnceFunction _Nonnull func) { M68K_ARG(OFOnceControl *_Nonnull, control, (nil)) M68K_ARG(OFOnceFunction _Nonnull, func, (nil)) OFOnce(control, func); } void __saveds glue_OFPBKDF2 PPC_PARAMS(OFPBKDF2Parameters parameters) { M68K_ARG(OFPBKDF2Parameters, parameters, a0) OFPBKDF2(parameters); } void __saveds glue_OFScrypt PPC_PARAMS(OFScryptParameters parameters) { M68K_ARG(OFScryptParameters, parameters, a0) OFScrypt(parameters); } void __saveds glue_OFSalsa20_8Core PPC_PARAMS(uint32_t *_Nonnull buffer) { M68K_ARG(uint32_t *_Nonnull, buffer, a0) OFSalsa20_8Core(buffer); } void __saveds glue_OFScryptBlockMix PPC_PARAMS(uint32_t *_Nonnull output, const uint32_t *_Nonnull input, size_t blockSize) { M68K_ARG(uint32_t *_Nonnull, output, a0) M68K_ARG(const uint32_t *_Nonnull, input, a1) M68K_ARG(size_t, blockSize, d0) OFScryptBlockMix(output, input, blockSize); } void __saveds glue_OFScryptROMix PPC_PARAMS(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp) { M68K_ARG(uint32_t *, buffer, a0) M68K_ARG(size_t, blockSize, d0) M68K_ARG(size_t, costFactor, d1) M68K_ARG(uint32_t *, tmp, a1) OFScryptROMix(buffer, blockSize, costFactor, tmp); } OFSocketAddress __saveds glue_OFSocketAddressParseIP PPC_PARAMS(OFString *IP, uint16_t port) { M68K_ARG(OFString *, IP, a0) M68K_ARG(uint16_t, port, d0) return OFSocketAddressParseIP(IP, port); } OFSocketAddress __saveds glue_OFSocketAddressParseIPv4 PPC_PARAMS(OFString *IP, uint16_t port) { M68K_ARG(OFString *, IP, a0) M68K_ARG(uint16_t, port, d0) return OFSocketAddressParseIPv4(IP, port); } OFSocketAddress __saveds glue_OFSocketAddressParseIPv6 PPC_PARAMS(OFString *IP, uint16_t port) { M68K_ARG(OFString *, IP, a0) M68K_ARG(uint16_t, port, d0) return OFSocketAddressParseIPv6(IP, port); } OFSocketAddress __saveds glue_OFSocketAddressMakeIPX PPC_PARAMS(const unsigned char *_Nonnull node, uint32_t network, uint16_t port) { M68K_ARG(const unsigned char *_Nonnull, node, a0) M68K_ARG(uint32_t, network, d0) M68K_ARG(uint16_t, port, d1) return OFSocketAddressMakeIPX(node, network, port); } bool __saveds glue_OFSocketAddressEqual PPC_PARAMS(const OFSocketAddress *_Nonnull address1, const OFSocketAddress *_Nonnull address2) { M68K_ARG(const OFSocketAddress *_Nonnull, address1, a0) M68K_ARG(const OFSocketAddress *_Nonnull, address2, a1) return OFSocketAddressEqual(address1, address2); } unsigned long __saveds glue_OFSocketAddressHash PPC_PARAMS(const OFSocketAddress *_Nonnull address) { M68K_ARG(const OFSocketAddress *_Nonnull, address, a0) return OFSocketAddressHash(address); } OFString *_Nonnull __saveds glue_OFSocketAddressString PPC_PARAMS(const OFSocketAddress *_Nonnull address) { M68K_ARG(const OFSocketAddress *_Nonnull, address, a0) return OFSocketAddressString(address); } void __saveds glue_OFSocketAddressSetPort PPC_PARAMS(OFSocketAddress *_Nonnull address, uint16_t port) { M68K_ARG(OFSocketAddress *_Nonnull, address, a0) M68K_ARG(uint16_t, port, d0) OFSocketAddressSetPort(address, port); } uint16_t __saveds glue_OFSocketAddressPort PPC_PARAMS(const OFSocketAddress *_Nonnull address) { M68K_ARG(const OFSocketAddress *_Nonnull, address, a0) return OFSocketAddressPort(address); } void __saveds glue_OFSocketAddressSetIPXNetwork PPC_PARAMS(OFSocketAddress *_Nonnull address, uint32_t network) { M68K_ARG(OFSocketAddress *_Nonnull, address, a0) M68K_ARG(uint32_t, network, d0) OFSocketAddressSetIPXNetwork(address, network); } uint32_t __saveds glue_OFSocketAddressIPXNetwork PPC_PARAMS(const OFSocketAddress *_Nonnull address) { M68K_ARG(const OFSocketAddress *_Nonnull, address, a0) return OFSocketAddressIPXNetwork(address); } void __saveds glue_OFSocketAddressSetIPXNode PPC_PARAMS(OFSocketAddress *_Nonnull address, const unsigned char *_Nonnull node) { M68K_ARG(OFSocketAddress *_Nonnull, address, a0) M68K_ARG(const unsigned char *_Nonnull, node, a1) OFSocketAddressSetIPXNode(address, node); } void __saveds glue_OFSocketAddressIPXNode PPC_PARAMS(const OFSocketAddress *_Nonnull address, unsigned char *_Nonnull node) { M68K_ARG(const OFSocketAddress *_Nonnull, address, a0) M68K_ARG(unsigned char *_Nonnull, node, a1) OFSocketAddressIPXNode(address, node); } const char *_Nullable __saveds glue_OFStrPTime PPC_PARAMS(const char *buffer, const char *format, struct tm *tm, int16_t *_Nullable tz) { M68K_ARG(const char *, buffer, a0) M68K_ARG(const char *, format, a1) M68K_ARG(struct tm *, tm, a2) M68K_ARG(int16_t *_Nullable, tz, a3) return OFStrPTime(buffer, format, tm, tz); } OFStringEncoding __saveds glue_OFStringEncodingParseName PPC_PARAMS(OFString *string) { M68K_ARG(OFString *, string, a0) return OFStringEncodingParseName(string); } OFString *_Nullable __saveds glue_OFStringEncodingName PPC_PARAMS(OFStringEncoding encoding) { M68K_ARG(OFStringEncoding, encoding, d0) return OFStringEncodingName(encoding); } size_t __saveds glue_OFUTF16StringLength PPC_PARAMS(const OFChar16 *string) { M68K_ARG(const OFChar16 *, string, a0) return OFUTF16StringLength(string); } size_t __saveds glue_OFUTF32StringLength PPC_PARAMS(const OFChar32 *string) { M68K_ARG(const OFChar32 *, string, a0) return OFUTF32StringLength(string); } OFString *_Nonnull __saveds glue_OFZIPArchiveEntryVersionToString PPC_PARAMS(uint16_t version) { M68K_ARG(uint16_t, version, d0) return OFZIPArchiveEntryVersionToString(version); } OFString *_Nonnull __saveds glue_OFZIPArchiveEntryCompressionMethodName PPC_PARAMS(OFZIPArchiveEntryCompressionMethod compressionMethod) { M68K_ARG(OFZIPArchiveEntryCompressionMethod, compressionMethod, d0) return OFZIPArchiveEntryCompressionMethodName(compressionMethod); } size_t __saveds glue_OFZIPArchiveEntryExtraFieldFind PPC_PARAMS(OFData *extraField, OFZIPArchiveEntryExtraFieldTag tag, uint16_t *size) { M68K_ARG(OFData *, extraField, a0) M68K_ARG(OFZIPArchiveEntryExtraFieldTag, tag, d0) M68K_ARG(uint16_t *, size, a1) return OFZIPArchiveEntryExtraFieldFind(extraField, tag, size); } |
Modified src/amiga-library.h from [40766eef6f] to [5c085b12df].
︙ | ︙ | |||
20 21 22 23 24 25 26 | # define OF_M68K_ARG(type, name, reg) type name = (type)REG_##reg; #else # define OF_M68K_ARG(type, name, reg) \ register type reg_##name __asm__(#reg); \ type name = reg_##name; #endif | | | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # define OF_M68K_ARG(type, name, reg) type name = (type)REG_##reg; #else # define OF_M68K_ARG(type, name, reg) \ register type reg_##name __asm__(#reg); \ type name = reg_##name; #endif typedef void (*OFSignalHandler)(int); struct OFLibC { /* * Needed by the runtime. Some of them are also used by ObjFW, but we * need all of them to pass them along to the runtime. */ void *_Nullable (*_Nonnull malloc)(size_t); void *_Nullable (*_Nonnull calloc)(size_t, size_t); void *_Nullable (*_Nonnull realloc)(void *_Nullable, size_t); |
︙ | ︙ | |||
65 66 67 68 69 70 71 | void *_Nullable (*_Nonnull __deregister_frame_info)( const void *_Nonnull); #endif #ifdef OF_MORPHOS void (*_Nonnull __register_frame)(void *_Nonnull); void (*_Nonnull __deregister_frame)(void *_Nonnull); #endif | | | | > | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | void *_Nullable (*_Nonnull __deregister_frame_info)( const void *_Nonnull); #endif #ifdef OF_MORPHOS void (*_Nonnull __register_frame)(void *_Nonnull); void (*_Nonnull __deregister_frame)(void *_Nonnull); #endif int *_Nonnull (*_Nonnull errNo)(void); /* Needed only by ObjFW. */ int (*_Nonnull vsnprintf)(char *_Nonnull restrict, size_t, const char *_Nonnull restrict, va_list); #ifdef OF_AMIGAOS_M68K /* strtod() uses sscanf() internally */ int (*_Nonnull vsscanf)(const char *_Nonnull restrict, const char *_Nonnull restrict, va_list); #endif void (*_Nonnull exit)(int); int (*_Nonnull atexit)(void (*_Nonnull)(void)); OFSignalHandler _Nullable (*_Nonnull signal)(int, OFSignalHandler _Nullable); char *_Nullable (*_Nonnull setlocale)(int, const char *_Nullable); int (*_Nonnull _Unwind_Backtrace)(int (*_Nonnull)(void *_Nonnull, void *_Null_unspecified), void *_Null_unspecified); }; extern bool OFInit(unsigned int version, struct OFLibC *libC, FILE **sF); extern unsigned long *OFHashSeedRef(void); |
Modified src/amiga-library.m from [4eb80f8cc9] to [fdc1473cd0].
︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 | #include <exec/libraries.h> #include <exec/nodes.h> #include <exec/resident.h> #include <proto/exec.h> #import "OFDNSResourceRecord.h" #import "OFHTTPRequest.h" #import "OFStdIOStream.h" #import "OFString.h" #import "amiga-library.h" #import "macros.h" | > < | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <exec/libraries.h> #include <exec/nodes.h> #include <exec/resident.h> #include <proto/exec.h> #import "OFDNSResourceRecord.h" #import "OFHTTPRequest.h" #import "OFSocket.h" #import "OFStdIOStream.h" #import "OFString.h" #import "amiga-library.h" #import "macros.h" #define CONCAT_VERSION2(major, minor) #major "." #minor #define CONCAT_VERSION(major, minor) CONCAT_VERSION2(major, minor) #define VERSION_STRING CONCAT_VERSION(OBJFW_LIB_MAJOR, OBJFW_LIB_MINOR) #if defined(OF_AMIGAOS_M68K) # define DATA_OFFSET 0x7FFE |
︙ | ︙ | |||
62 63 64 65 66 67 68 | #ifdef OF_AMIGAOS_M68K extern uintptr_t __CTOR_LIST__[]; extern const void *_EH_FRAME_BEGINS__; extern void *_EH_FRAME_OBJECTS__; #endif | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #ifdef OF_AMIGAOS_M68K extern uintptr_t __CTOR_LIST__[]; extern const void *_EH_FRAME_BEGINS__; extern void *_EH_FRAME_OBJECTS__; #endif #include "amiga-glue.h" #ifdef OF_AMIGAOS_M68K void __init_eh(void) { /* Taken care of by OFInit() */ } #endif #ifdef OF_MORPHOS const ULONG __abox__ = 1; #endif struct ExecBase *SysBase; struct OFLibC libC; FILE **__sF; #if defined(OF_AMIGAOS_M68K) __asm__ ( ".text\n" ".globl ___restore_a4\n" ".align 1\n" |
︙ | ︙ | |||
215 216 217 218 219 220 221 | ); #endif return dataDataRelocs; } static struct Library * | | | 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | ); #endif return dataDataRelocs; } static struct Library * libInit(struct ObjFWBase *base OF_M68K_REG(d0), void *segList OF_M68K_REG(a0), struct ExecBase *sysBase OF_M68K_REG(a6)) { #if defined(OF_AMIGAOS_M68K) __asm__ __volatile__ ( "move.l a6, _SysBase" :: "a"(sysBase) ); |
︙ | ︙ | |||
239 240 241 242 243 244 245 | base->parent = NULL; base->dataSeg = getDataSeg(); return &base->library; } struct Library *__saveds | | | | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | base->parent = NULL; base->dataSeg = getDataSeg(); return &base->library; } struct Library *__saveds libOpen(void) { OF_M68K_ARG(struct ObjFWBase *, base, a6) struct ObjFWBase *child; size_t dataSize, *dataDataRelocs; ptrdiff_t displacement; if (base->parent != NULL) return NULL; base->library.lib_OpenCnt++; base->library.lib_Flags &= ~LIBF_DELEXP; /* * We cannot use malloc here, as that depends on the libC passed from * the application. */ if ((child = AllocMem(base->library.lib_NegSize + base->library.lib_PosSize, MEMF_ANY)) == NULL) { base->library.lib_OpenCnt--; return NULL; } |
︙ | ︙ | |||
319 320 321 322 323 324 325 | base->library.lib_NegSize + base->library.lib_PosSize); return segList; #undef SysBase } static void *__saveds | | | | | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | base->library.lib_NegSize + base->library.lib_PosSize); return segList; #undef SysBase } static void *__saveds libExpunge(void) { OF_M68K_ARG(struct ObjFWBase *, base, a6) return expunge(base, SysBase); } static void *__saveds libClose(void) { /* * SysBase becomes invalid during this function, so we store it in * sysBase and add a define to make the inlines use the right one. */ struct ExecBase *sysBase = SysBase; #define SysBase sysBase OF_M68K_ARG(struct ObjFWBase *, base, a6) if (base->parent != NULL) { struct ObjFWBase *parent; #ifdef OF_AMIGAOS_M68K if (base->initialized) for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++) libC.__deregister_frame_info( (&_EH_FRAME_BEGINS__)[i]); #endif parent = base->parent; FreeMem(base->dataSeg - DATA_OFFSET, getDataSize()); FreeMem((char *)base - base->library.lib_NegSize, |
︙ | ︙ | |||
366 367 368 369 370 371 372 | return expunge(base, sysBase); return NULL; #undef SysBase } static void * | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | return expunge(base, sysBase); return NULL; #undef SysBase } static void * libNull(void) { return NULL; } bool __saveds OFInit(unsigned int version, struct OFLibC *libC_, FILE **sF) { #ifdef OF_AMIGAOS_M68K OF_M68K_ARG(struct ObjFWBase *, base, a6) #else register struct ObjFWBase *r12 __asm__("r12"); struct ObjFWBase *base = r12; #endif #ifdef OF_MORPHOS void *frame; #endif uintptr_t *iter, *iter0; if (version > 1) return false; if (base->initialized) return true; memcpy(&libC, libC_, sizeof(libC)); __sF = sF; #ifdef OF_AMIGAOS_M68K if ((size_t)_EH_FRAME_BEGINS__ != (size_t)_EH_FRAME_OBJECTS__) return false; for (size_t i = 1; i <= (size_t)_EH_FRAME_BEGINS__; i++) libC.__register_frame_info((&_EH_FRAME_BEGINS__)[i], (&_EH_FRAME_OBJECTS__)[i]); iter0 = &__CTOR_LIST__[1]; #elif defined(OF_MORPHOS) __asm__ ( "lis %0, __EH_FRAME_BEGIN__@ha\n\t" "la %0, __EH_FRAME_BEGIN__@l(%0)\n\t" "lis %1, __CTOR_LIST__@ha\n\t" "la %1, __CTOR_LIST__@l(%1)\n\t" : "=r"(frame), "=r"(iter0) ); libC.__register_frame(frame); #endif for (iter = iter0; *iter != 0; iter++); while (iter > iter0) { void (*ctor)(void) = (void (*)(void))*--iter; ctor(); } base->initialized = true; return true; } void * malloc(size_t size) { return libC.malloc(size); } void * calloc(size_t count, size_t size) { return libC.calloc(count, size); } void * realloc(void *ptr, size_t size) { return libC.realloc(ptr, size); } void free(void *ptr) { libC.free(ptr); } int fprintf(FILE *restrict stream, const char *restrict fmt, ...) { int ret; va_list args; va_start(args, fmt); ret = libC.vfprintf(stream, fmt, args); va_end(args); return ret; } int vfprintf(FILE *restrict stream, const char *restrict fmt, va_list args) { return libC.vfprintf(stream, fmt, args); } int fflush(FILE *restrict stream) { return libC.fflush(stream); } void abort(void) { libC.abort(); OF_UNREACHABLE } #ifdef HAVE_SJLJ_EXCEPTIONS int _Unwind_SjLj_RaiseException(void *ex) { return libC._Unwind_SjLj_RaiseException(ex); } #else int _Unwind_RaiseException(void *ex) { return libC._Unwind_RaiseException(ex); } #endif void _Unwind_DeleteException(void *ex) { libC._Unwind_DeleteException(ex); } void * _Unwind_GetLanguageSpecificData(void *ctx) { return libC._Unwind_GetLanguageSpecificData(ctx); } uintptr_t _Unwind_GetRegionStart(void *ctx) { return libC._Unwind_GetRegionStart(ctx); } uintptr_t _Unwind_GetDataRelBase(void *ctx) { return libC._Unwind_GetDataRelBase(ctx); } uintptr_t _Unwind_GetTextRelBase(void *ctx) { return libC._Unwind_GetTextRelBase(ctx); } uintptr_t _Unwind_GetIP(void *ctx) { return libC._Unwind_GetIP(ctx); } uintptr_t _Unwind_GetGR(void *ctx, int gr) { return libC._Unwind_GetGR(ctx, gr); } void _Unwind_SetIP(void *ctx, uintptr_t ip) { libC._Unwind_SetIP(ctx, ip); } void _Unwind_SetGR(void *ctx, int gr, uintptr_t value) { libC._Unwind_SetGR(ctx, gr, value); } #ifdef HAVE_SJLJ_EXCEPTIONS void _Unwind_SjLj_Resume(void *ex) { libC._Unwind_SjLj_Resume(ex); } #else void _Unwind_Resume(void *ex) { libC._Unwind_Resume(ex); } #endif #ifdef OF_AMIGAOS_M68K void __register_frame_info(const void *begin, void *object) { libC.__register_frame_info(begin, object); } void *__deregister_frame_info(const void *begin) { return libC.__deregister_frame_info(begin); } #endif #ifdef OF_MORPHOS void __register_frame(void *frame) { libC.__register_frame(frame); } void __deregister_frame(void *frame) { libC.__deregister_frame(frame); } #endif int * OFErrNo(void) { return libC.errNo(); } int vsnprintf(char *restrict str, size_t size, const char *restrict fmt, va_list args) { return libC.vsnprintf(str, size, fmt, args); } #ifdef OF_AMIGAOS_M68K int sscanf(const char *restrict str, const char *restrict fmt, ...) { int ret; va_list args; va_start(args, fmt); ret = libC.vsscanf(str, fmt, args); va_end(args); return ret; } #endif void exit(int status) { libC.exit(status); OF_UNREACHABLE } int atexit(void (*function)(void)) { return libC.atexit(function); } OFSignalHandler signal(int sig, OFSignalHandler func) { return libC.signal(sig, func); } char * setlocale(int category, const char *locale) { return libC.setlocale(category, locale); } int _Unwind_Backtrace(int (*callback)(void *, void *), void *data) { return libC._Unwind_Backtrace(callback, data); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" static CONST_APTR functionTable[] = { #ifdef OF_MORPHOS (CONST_APTR)FUNCARRAY_BEGIN, (CONST_APTR)FUNCARRAY_32BIT_NATIVE, #endif (CONST_APTR)libOpen, (CONST_APTR)libClose, (CONST_APTR)libExpunge, (CONST_APTR)libNull, #ifdef OF_MORPHOS (CONST_APTR)-1, (CONST_APTR)FUNCARRAY_32BIT_SYSTEMV, #endif #include "amiga-funcarray.inc" (CONST_APTR)-1, #ifdef OF_MORPHOS (CONST_APTR)FUNCARRAY_END #endif }; #pragma GCC diagnostic pop static struct { ULONG dataSize; CONST_APTR *functionTable; ULONG *dataTable; struct Library *(*initFunc)( struct ObjFWBase *base OF_M68K_REG(d0), void *segList OF_M68K_REG(a0), struct ExecBase *execBase OF_M68K_REG(a6)); } init_table = { sizeof(struct ObjFWBase), functionTable, NULL, libInit }; struct Resident resident = { .rt_MatchWord = RTC_MATCHWORD, .rt_MatchTag = &resident, .rt_EndSkip = &resident + 1, .rt_Flags = RTF_AUTOINIT |
︙ | ︙ |
Deleted src/amigaos3.sfd version [cb0789f446].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/atomic_no_threads.h version [5ca4dac2a4].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/block.h version [1fa9cdbfc6].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/bridge/OFException+Swift.h from [565c9aa41a] to [0fe4c6bbbc].
︙ | ︙ | |||
43 44 45 46 47 48 49 | * @brief Execute the specified try block and finally call the finally block. * * @note This is only useful for Swift. * * @param try The try block to execute * @param finally The finally block to call at the end */ | | < | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | * @brief Execute the specified try block and finally call the finally block. * * @note This is only useful for Swift. * * @param try The try block to execute * @param finally The finally block to call at the end */ + (void)try: (void (^)(void))try finally: (void (^)(void))finally; /** * @brief Execute the specified try block and call the catch block if an * OFException occurred and finally call the finally block. * * @note This is only useful to catch OFExceptions in Swift. * |
︙ | ︙ |
Modified src/encodings/codepage-437.m from [e06381bb1c] to [1ff55c3103].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFCodepage437Table[] = { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229, 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0 }; const size_t OFCodepage437TableOffset = 256 - (sizeof(OFCodepage437Table) / sizeof(*OFCodepage437Table)); static const unsigned char page0[] = { 0xFF, 0xAD, 0x9B, 0x9C, 0x00, 0x9D, 0x00, 0x00, 0x00, 0x00, 0xA6, 0xAE, 0xAA, 0x00, 0x00, 0x00, 0xF8, 0xF1, 0xFD, 0x00, 0x00, 0xE6, 0x00, 0xFA, 0x00, 0x00, 0xA7, 0xAF, 0xAC, 0xAB, 0x00, 0xA8, 0x00, 0x00, 0x00, 0x00, 0x8E, 0x8F, 0x92, 0x80, |
︙ | ︙ | |||
125 126 127 128 129 130 131 | 0xDE, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool | | | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | 0xDE, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OFUnicodeToCodepage437(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/codepage-850.m from [3c49f43469] to [8a999f8dc5].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFCodepage850Table[] = { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 }; const size_t OFCodepage850TableOffset = 256 - (sizeof(OFCodepage850Table) / sizeof(*OFCodepage850Table)); static const unsigned char page0[] = { 0xFF, 0xAD, 0xBD, 0x9C, 0xCF, 0xBE, 0xDD, 0xF5, 0xF9, 0xB8, 0xA6, 0xAE, 0xAA, 0xF0, 0xA9, 0xEE, 0xF8, 0xF1, 0xFD, 0xFC, 0xEF, 0xE6, 0xF4, 0xFA, 0xF7, 0xFB, 0xA7, 0xAF, 0xAC, 0xAB, 0xF3, 0xA8, |
︙ | ︙ | |||
101 102 103 104 105 106 107 | 0x00, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool | | | | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 0x00, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OFUnicodeToCodepage850(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/codepage-858.m from [3ce6d4c463] to [eb400d443e].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFCodepage858Table[] = { 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, 0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192, 0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4, 0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x20AC, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580, 0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4, 0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0 }; const size_t OFCodepage858TableOffset = 256 - (sizeof(OFCodepage858Table) / sizeof(*OFCodepage858Table)); static const unsigned char page0[] = { 0xFF, 0xAD, 0xBD, 0x9C, 0xCF, 0xBE, 0xDD, 0xF5, 0xF9, 0xB8, 0xA6, 0xAE, 0xAA, 0xF0, 0xA9, 0xEE, 0xF8, 0xF1, 0xFD, 0xFC, 0xEF, 0xE6, 0xF4, 0xFA, 0xF7, 0xFB, 0xA7, 0xAF, 0xAC, 0xAB, 0xF3, 0xA8, |
︙ | ︙ | |||
107 108 109 110 111 112 113 | 0x00, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | 0x00, 0xB0, 0xB1, 0xB2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE }; static const uint8_t page25Start = 0x00; bool OFUnicodeToCodepage858(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/iso-8859-15.m from [66f31de0ef] to [22626a7166].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFISO8859_15Table[] = { 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AC, 0x00A5, 0x0160, 0x00A7, 0x0161, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x017D, 0x00B5, 0x00B6, 0x00B7, 0x017E, 0x00B9, 0x00BA, 0x00BB, 0x0152, 0x0153, 0x0178, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; const size_t OFISO8859_15TableOffset = 256 - (sizeof(OFISO8859_15Table) / sizeof(*OFISO8859_15Table)); static const unsigned char page0[] = { 0x00, 0xA5, 0x00, 0xA7, 0x00, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, 0x00, 0xB5, 0xB6, 0xB7, 0x00, 0xB9, 0xBA, 0xBB, 0x00, 0x00, 0x00 }; |
︙ | ︙ | |||
56 57 58 59 60 61 62 | static const unsigned char page20[] = { 0xA4 }; static const uint8_t page20Start = 0xAC; bool | | | | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | static const unsigned char page20[] = { 0xA4 }; static const uint8_t page20Start = 0xAC; bool OFUnicodeToISO8859_15(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/iso-8859-2.m from [3fe77cae41] to [e41926d484].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFISO8859_2Table[] = { 0x00A0, 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8, 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0, 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8, 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, 0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, 0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, 0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, 0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9 }; const size_t OFISO8859_2TableOffset = 256 - (sizeof(OFISO8859_2Table) / sizeof(*OFISO8859_2Table)); static const unsigned char page0[] = { 0xA0, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0xA7, 0xA8, 0x00, 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00, 0xB0, 0x00, 0x00, 0x00, 0xB4, 0x00, 0x00, 0x00, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC1, 0xC2, 0x00, 0xC4, 0x00, 0x00, 0xC7, |
︙ | ︙ | |||
76 77 78 79 80 81 82 | 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0xFF, 0x00, 0xB2, 0x00, 0xBD }; static const uint8_t page2Start = 0xC7; bool | | | | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | 0xB7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0xFF, 0x00, 0xB2, 0x00, 0xBD }; static const uint8_t page2Start = 0xC7; bool OFUnicodeToISO8859_2(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/iso-8859-3.m from [b571fab6a6] to [5ad1bdc273].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFISO8859_3Table[] = { 0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0xFFFF, 0x0124, 0x00A7, 0x00A8, 0x0130, 0x015E, 0x011E, 0x0134, 0x00AD, 0xFFFF, 0x017B, 0x00B0, 0x0127, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x0125, 0x00B7, 0x00B8, 0x0131, 0x015F, 0x011F, 0x0135, 0x00BD, 0xFFFF, 0x017C, 0x00C0, 0x00C1, 0x00C2, 0xFFFF, 0x00C4, 0x010A, 0x0108, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0xFFFF, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7, 0x011C, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0xFFFF, 0x00E4, 0x010B, 0x0109, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0xFFFF, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7, 0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9 }; const size_t OFISO8859_3TableOffset = 256 - (sizeof(OFISO8859_3Table) / sizeof(*OFISO8859_3Table)); static const unsigned char page0[] = { 0xA0, 0x00, 0x00, 0xA3, 0xA4, 0x00, 0x00, 0xA7, 0xA8, 0x00, 0x00, 0x00, 0x00, 0xAD, 0x00, 0x00, 0xB0, 0x00, 0xB2, 0xB3, 0xB4, 0xB5, 0x00, 0xB7, 0xB8, 0x00, 0x00, 0x00, 0x00, 0xBD, 0x00, 0x00, 0xC0, 0xC1, 0xC2, 0x00, 0xC4, 0x00, 0x00, 0xC7, |
︙ | ︙ | |||
73 74 75 76 77 78 79 | static const unsigned char page2[] = { 0xA2, 0xFF }; static const uint8_t page2Start = 0xD8; bool | | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | static const unsigned char page2[] = { 0xA2, 0xFF }; static const uint8_t page2Start = 0xD8; bool OFUnicodeToISO8859_3(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/koi8-r.m from [b612dc985f] to [bf43e53144].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFKOI8RTable[] = { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248, 0x2264, 0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7, 0x2550, 0x2551, 0x2552, 0x0451, 0x2553, 0x2554, 0x2555, 0x2556, 0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x255C, 0x255D, 0x255E, 0x255F, 0x2560, 0x2561, 0x0401, 0x2562, 0x2563, 0x2564, 0x2565, 0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x256B, 0x256C, 0x00A9, 0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, 0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A, 0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, 0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, 0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A }; const size_t OFKOI8RTableOffset = 256 - (sizeof(OFKOI8RTable) / sizeof(*OFKOI8RTable)); static const unsigned char page0[] = { 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
︙ | ︙ | |||
111 112 113 114 115 116 117 | 0x8F, 0x90, 0x91, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool | | | | | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | 0x8F, 0x90, 0x91, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool OFUnicodeToKOI8R(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/koi8-u.m from [bc833d67fc] to [71921000c0].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFKOI8UTable[] = { 0x2500, 0x2502, 0x250C, 0x2510, 0x2514, 0x2518, 0x251C, 0x2524, 0x252C, 0x2534, 0x253C, 0x2580, 0x2584, 0x2588, 0x258C, 0x2590, 0x2591, 0x2592, 0x2593, 0x2320, 0x25A0, 0x2219, 0x221A, 0x2248, 0x2264, 0x2265, 0x00A0, 0x2321, 0x00B0, 0x00B2, 0x00B7, 0x00F7, 0x2550, 0x2551, 0x2552, 0x0451, 0x0454, 0x2554, 0x0456, 0x0457, 0x2557, 0x2558, 0x2559, 0x255A, 0x255B, 0x0491, 0x255D, 0x255E, 0x255F, 0x2560, 0x2561, 0x0401, 0x0404, 0x2563, 0x0406, 0x0407, 0x2566, 0x2567, 0x2568, 0x2569, 0x256A, 0x0490, 0x256C, 0x00A9, 0x044E, 0x0430, 0x0431, 0x0446, 0x0434, 0x0435, 0x0444, 0x0433, 0x0445, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x044F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0436, 0x0432, 0x044C, 0x044B, 0x0437, 0x0448, 0x044D, 0x0449, 0x0447, 0x044A, 0x042E, 0x0410, 0x0411, 0x0426, 0x0414, 0x0415, 0x0424, 0x0413, 0x0425, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x042F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0416, 0x0412, 0x042C, 0x042B, 0x0417, 0x0428, 0x042D, 0x0429, 0x0427, 0x042A }; const size_t OFKOI8UTableOffset = 256 - (sizeof(OFKOI8UTable) / sizeof(*OFKOI8UTable)); static const unsigned char page0[] = { 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x00, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x9E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
︙ | ︙ | |||
119 120 121 122 123 124 125 | 0x8F, 0x90, 0x91, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool | | | | | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | 0x8F, 0x90, 0x91, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94 }; static const uint8_t page25Start = 0x00; bool OFUnicodeToKOI8U(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/mac-roman.m from [db14d68482] to [3797f74af2].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFMacRomanTable[] = { 0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1, 0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8, 0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3, 0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC, 0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF, 0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8, 0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211, 0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8, 0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB, 0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153, 0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA, 0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02, 0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1, 0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4, 0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC, 0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7 }; const size_t OFMacRomanTableOffset = 256 - (sizeof(OFMacRomanTable) / sizeof(*OFMacRomanTable)); static const unsigned char page0[] = { 0xCA, 0xC1, 0xA2, 0xA3, 0x00, 0xB4, 0x00, 0xA4, 0xAC, 0xA9, 0xBB, 0xC7, 0xC2, 0x00, 0xA8, 0xF8, 0xA1, 0xB1, 0x00, 0x00, 0xAB, 0xB5, 0xA6, 0xE1, 0xFC, 0x00, 0xBC, 0xC8, 0x00, 0x00, 0x00, 0xC0, 0xCB, 0xE7, 0xE5, 0xCC, 0x80, 0x81, 0xAE, 0x82, |
︙ | ︙ | |||
145 146 147 148 149 150 151 | static const unsigned char pageFB[] = { 0xDE, 0xDF }; static const uint8_t pageFBStart = 0x01; bool | | | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | static const unsigned char pageFB[] = { 0xDE, 0xDF }; static const uint8_t pageFBStart = 0x01; bool OFUnicodeToMacRoman(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/windows-1251.m from [baa2d5d34b] to [05f0643067].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFWindows1251Table[] = { 0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021, 0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F, 0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0xFFFF, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F, 0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7, 0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407, 0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7, 0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457, 0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F, 0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F, 0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F, 0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F }; const size_t OFWindows1251TableOffset = 256 - (sizeof(OFWindows1251Table) / sizeof(*OFWindows1251Table)); static const unsigned char page0[] = { 0xA0, 0x00, 0x00, 0x00, 0xA4, 0x00, 0xA6, 0xA7, 0x00, 0xA9, 0x00, 0xAB, 0xAC, 0xAD, 0xAE, 0x00, 0xB0, 0xB1, 0x00, 0x00, 0x00, 0xB5, 0xB6, 0xB7, 0x00, 0x00, 0x00, 0xBB }; |
︙ | ︙ | |||
98 99 100 101 102 103 104 | static const unsigned char page21[] = { 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99 }; static const uint8_t page21Start = 0x16; bool | | | | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | static const unsigned char page21[] = { 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99 }; static const uint8_t page21Start = 0x16; bool OFUnicodeToWindows1251(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/encodings/windows-1252.m from [d5fc246852] to [b4937f91b7].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFString.h" #import "common.h" | | | | | 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 | #include "config.h" #import "OFString.h" #import "common.h" const OFChar16 OFWindows1252Table[] = { 0x20AC, 0xFFFF, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021, 0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0xFFFF, 0x017D, 0xFFFF, 0xFFFF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, 0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0xFFFF, 0x017E, 0x0178, 0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7, 0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF }; const size_t OFWindows1252TableOffset = 256 - (sizeof(OFWindows1252Table) / sizeof(*OFWindows1252Table)); static const unsigned char page0[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
︙ | ︙ | |||
94 95 96 97 98 99 100 | static const unsigned char page21[] = { 0x99 }; static const uint8_t page21Start = 0x22; bool | | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | static const unsigned char page21[] = { 0x99 }; static const uint8_t page21Start = 0x22; bool OFUnicodeToWindows1252(const OFUnichar *input, unsigned char *output, size_t length, bool lossy) { for (size_t i = 0; i < length; i++) { OFUnichar c = input[i]; if OF_UNLIKELY (c > 0x7F) { uint8_t idx; if OF_UNLIKELY (c > 0xFFFF) { if (lossy) { output[i] = '?'; |
︙ | ︙ |
Modified src/exceptions/Makefile from [e9d0c08ed2] to [dbddffb6d5].
︙ | ︙ | |||
30 31 32 33 34 35 36 | OFOpenItemFailedException.m \ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRemoveItemFailedException.m \ OFRetrieveItemAttributesFailedException.m \ | < | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | OFOpenItemFailedException.m \ OFOutOfMemoryException.m \ OFOutOfRangeException.m \ OFReadFailedException.m \ OFReadOrWriteFailedException.m \ OFRemoveItemFailedException.m \ OFRetrieveItemAttributesFailedException.m \ OFSeekFailedException.m \ OFSetItemAttributesFailedException.m \ OFSetOptionFailedException.m \ OFStillLockedException.m \ OFTruncatedDataException.m \ OFUnboundNamespaceException.m \ OFUnboundPrefixException.m \ |
︙ | ︙ | |||
74 75 76 77 78 79 80 | SRCS_WINDOWS = OFCreateWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryValueFailedException.m \ OFGetWindowsRegistryValueFailedException.m \ OFOpenWindowsRegistryKeyFailedException.m \ OFSetWindowsRegistryValueFailedException.m | | > > | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | SRCS_WINDOWS = OFCreateWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryKeyFailedException.m \ OFDeleteWindowsRegistryValueFailedException.m \ OFGetWindowsRegistryValueFailedException.m \ OFOpenWindowsRegistryKeyFailedException.m \ OFSetWindowsRegistryValueFailedException.m INCLUDES := ${SRCS:.m=.h} SRCS += OFSandboxActivationFailedException.m include ../../buildsys.mk CPPFLAGS += -I. -I.. -I../.. -I../runtime |
Modified src/exceptions/OFAcceptFailedException.h from [3870d05797] to [8b9e60c1c1].
︙ | ︙ | |||
48 49 50 51 52 53 54 | /** * @brief Creates a new, autoreleased accept failed exception. * * @param socket The socket which could not accept a connection * @param errNo The errno for the error * @return A new, autoreleased accept failed exception */ | | < | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | /** * @brief Creates a new, autoreleased accept failed exception. * * @param socket The socket which could not accept a connection * @param errNo The errno for the error * @return A new, autoreleased accept failed exception */ + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated accept failed exception. * * @param socket The socket which could not accept a connection |
︙ | ︙ |
Modified src/exceptions/OFAcceptFailedException.m from [262ff1ad4e] to [f160570582].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize socket = _socket, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | | 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 61 62 | @synthesize socket = _socket, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSocket: (id)socket errNo: (int)errNo { return [[[self alloc] initWithSocket: socket errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSocket: (id)socket errNo: (int)errNo { self = [super init]; _socket = [socket retain]; _errNo = errNo; return self; } - (void)dealloc { [_socket release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to accept connection in socket of class %@: %@", [_socket class], OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFAllocFailedException.m from [891598484b] to [22ee2bf80a].
︙ | ︙ | |||
42 43 44 45 46 47 48 | - (instancetype)autorelease { return self; } - (unsigned int)retainCount { | | | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | - (instancetype)autorelease { return self; } - (unsigned int)retainCount { return OFMaxRetainCount; } - (void)release { } - (void)dealloc |
︙ | ︙ |
Modified src/exceptions/OFBindFailedException.h from [f49a2c3ca2] to [fa6db74dc4].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFBindFailedException \ * OFBindFailedException.h ObjFW/OFBindFailedException.h * |
︙ | ︙ |
Modified src/exceptions/OFBindFailedException.m from [8a08ee6973] to [5d40ea5e4f].
︙ | ︙ | |||
104 105 106 107 108 109 110 | - (OFString *)description { if (_host != nil) return [OFString stringWithFormat: @"Binding to port %" @PRIu16 @" on host %@ failed in " @"socket of type %@: %@", | | | | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | - (OFString *)description { if (_host != nil) return [OFString stringWithFormat: @"Binding to port %" @PRIu16 @" on host %@ failed in " @"socket of type %@: %@", _port, _host, [_socket class], OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Binding to port %" @PRIx16 @" for packet type %" @PRIx8 @" failed in socket of type %@: %@", _port, _packetType, [_socket class], OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFChangeCurrentDirectoryPathFailedException.h from [74500bb098] to [31ad4bfc89].
︙ | ︙ | |||
49 50 51 52 53 54 55 | * exception. * * @param path The path of the directory to which the current path could not be * changed * @param errNo The errno of the error that occurred * @return A new, autoreleased change current directory path failed exception */ | | < | 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | * exception. * * @param path The path of the directory to which the current path could not be * changed * @param errNo The errno of the error that occurred * @return A new, autoreleased change current directory path failed exception */ + (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated change directory failed exception. * * @param path The path of the directory to which the current path could not be |
︙ | ︙ |
Modified src/exceptions/OFChangeCurrentDirectoryPathFailedException.m from [4c59b51695] to [c3f3d9bb60].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize path = _path, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | 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 | @synthesize path = _path, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithPath: (OFString *)path errNo: (int)errNo { return [[[self alloc] initWithPath: path errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithPath: (OFString *)path errNo: (int)errNo { self = [super init]; @try { _path = [path copy]; _errNo = errNo; } @catch (id e) { |
︙ | ︙ | |||
61 62 63 64 65 66 67 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to change the current directory path to %@: %@", | | | 58 59 60 61 62 63 64 65 66 67 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to change the current directory path to %@: %@", _path, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFConditionBroadcastFailedException.m from [b529ecf85c] to [37d5470bb0].
︙ | ︙ | |||
27 28 29 30 31 32 33 | + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } | | < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo { self = [super init]; _condition = [condition retain]; _errNo = errNo; return self; |
︙ | ︙ |
Modified src/exceptions/OFConditionSignalFailedException.m from [3ded66a36b] to [816e893d46].
︙ | ︙ | |||
27 28 29 30 31 32 33 | + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } | | < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo { self = [super init]; _condition = [condition retain]; _errNo = errNo; return self; |
︙ | ︙ |
Modified src/exceptions/OFConditionWaitFailedException.m from [ec7442c12c] to [7ea539fb7f].
︙ | ︙ | |||
27 28 29 30 31 32 33 | + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } | | < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | + (instancetype)exceptionWithCondition: (OFCondition *)condition errNo: (int)errNo { return [[[self alloc] initWithCondition: condition errNo: errNo] autorelease]; } - (instancetype)initWithCondition: (OFCondition *)condition errNo: (int)errNo { self = [super init]; _condition = [condition retain]; _errNo = errNo; return self; |
︙ | ︙ |
Modified src/exceptions/OFConnectionFailedException.h from [47bb6c6702] to [0eaf506d9d].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #import "OFException.h" #ifndef OF_HAVE_SOCKETS # error No sockets available! #endif #import "OFSocket.h" OF_ASSUME_NONNULL_BEGIN /** * @class OFConnectionFailedException \ * OFConnectionFailedException.h ObjFW/OFConnectionFailedException.h * |
︙ | ︙ |
Modified src/exceptions/OFConnectionFailedException.m from [55b2b79014] to [847ad9798b].
︙ | ︙ | |||
113 114 115 116 117 118 119 | - (OFString *)description { if (_host != nil) return [OFString stringWithFormat: @"A connection to %@ on port %" @PRIu16 @" could not be " @"established in socket of type %@: %@", | | | | | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | - (OFString *)description { if (_host != nil) return [OFString stringWithFormat: @"A connection to %@ on port %" @PRIu16 @" could not be " @"established in socket of type %@: %@", _host, _port, [_socket class], OFStrError(_errNo)]; else if (memcmp(_node, "\0\0\0\0\0", IPX_NODE_LEN) == 0) return [OFString stringWithFormat: @"A connection to %02X%02X%02X%02X%02X%02X port %" @PRIu16 @" on network %" @PRIX32 " could not be established in " @"socket of type %@: %@", _node[0], _node[1], _node[2], _node[3], _node[4], _node[5], _port, _network, [_socket class], OFStrError(_errNo)]; else return [OFString stringWithFormat: @"A connection could not be established in socket of " @"type %@: %@", [_socket class], OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFCopyItemFailedException.m from [f16ddfd26e] to [4f3c187188].
︙ | ︙ | |||
67 68 69 70 71 72 73 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to copy item %@ to %@: %@", | | | 67 68 69 70 71 72 73 74 75 76 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to copy item %@ to %@: %@", _sourceURL, _destinationURL, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFCreateDirectoryFailedException.h from [7c0067efd5] to [176b8e9e1d].
︙ | ︙ | |||
47 48 49 50 51 52 53 | /** * @brief Creates a new, autoreleased create directory failed exception. * * @param URL The URL of the directory which could not be created * @param errNo The errno of the error that occurred * @return A new, autoreleased create directory failed exception */ | | < | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | /** * @brief Creates a new, autoreleased create directory failed exception. * * @param URL The URL of the directory which could not be created * @param errNo The errno of the error that occurred * @return A new, autoreleased create directory failed exception */ + (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated create directory failed exception. * * @param URL The URL of the directory which could not be created |
︙ | ︙ |
Modified src/exceptions/OFCreateDirectoryFailedException.m from [e59e1de340] to [1ed32763da].
︙ | ︙ | |||
23 24 25 26 27 28 29 | @synthesize URL = _URL, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | 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 | @synthesize URL = _URL, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo { return [[[self alloc] initWithURL: URL errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo { self = [super init]; @try { _URL = [URL copy]; _errNo = errNo; } @catch (id e) { |
︙ | ︙ | |||
61 62 63 64 65 66 67 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: | | | 58 59 60 61 62 63 64 65 66 67 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create directory %@: %@", _URL, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFCreateSymbolicLinkFailedException.m from [eb17d03171] to [0a310f1939].
︙ | ︙ | |||
67 68 69 70 71 72 73 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create symbolic link %@ with target %@: %@", | | | 67 68 69 70 71 72 73 74 75 76 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create symbolic link %@ with target %@: %@", _URL, _target, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFCreateWindowsRegistryKeyFailedException.m from [c06da68133] to [e5fd8452ce].
︙ | ︙ | |||
76 77 78 79 80 81 82 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create subkey at path %@: %@", | | | 76 77 78 79 80 81 82 83 84 85 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to create subkey at path %@: %@", _path, OFWindowsStatusToString(_status)]; } @end |
Modified src/exceptions/OFDNSQueryFailedException.h from [2099448a57] to [c8142bd5dd].
︙ | ︙ | |||
25 26 27 28 29 30 31 | * OFDNSQueryFailedException.h ObjFW/OFDNSQueryFailedException.h * * @brief An exception indicating that a DNS query failed. */ @interface OFDNSQueryFailedException: OFException { OFDNSQuery *_query; | | | | | | | | | > | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | * OFDNSQueryFailedException.h ObjFW/OFDNSQueryFailedException.h * * @brief An exception indicating that a DNS query failed. */ @interface OFDNSQueryFailedException: OFException { OFDNSQuery *_query; OFDNSResolverErrorCode _errorCode; } /** * @brief The query which could not be performed. */ @property (readonly, nonatomic) OFDNSQuery *query; /** * @brief The error code from the resolver. */ @property (readonly, nonatomic) OFDNSResolverErrorCode errorCode; /** * @brief Creates a new, autoreleased DNS query failed exception. * * @param query The query which could not be performed * @param errorCode The error from the resolver * @return A new, autoreleased address translation failed exception */ + (instancetype)exceptionWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode; /** * @brief Initializes an already allocated DNS query failed exception. * * @param query The query which could not be performed * @param errorCode The error from the resolver * @return An initialized address translation failed exception */ - (instancetype)initWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode; @end #ifdef __cplusplus extern "C" { #endif extern OFString *OFDNSResolverErrorCodeDescription( OFDNSResolverErrorCode errorCode); #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFDNSQueryFailedException.m from [a8cb654585] to [892da944ca].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "OFDNSQueryFailedException.h" #import "OFString.h" OFString * | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #include "config.h" #import "OFDNSQueryFailedException.h" #import "OFString.h" OFString * OFDNSResolverErrorCodeDescription(OFDNSResolverErrorCode errorCode) { switch (errorCode) { case OFDNSResolverErrorCodeTimeout: return @"The query timed out."; case OFDNSResolverErrorCodeCanceled: return @"The query was canceled."; case OFDNSResolverErrorCodeNoResult: return @"No result for the specified host with the specified " @"type and class."; case OFDNSResolverErrorCodeServerInvalidFormat: return @"The server considered the query to be malformed."; case OFDNSResolverErrorCodeServerFailure: return @"The server was unable to process due to an internal " @"error."; case OFDNSResolverErrorCodeServerNameError: return @"The server returned an error that the domain does not " @"exist."; case OFDNSResolverErrorCodeServerNotImplemented: return @"The server does not have support for the requested " @"query."; case OFDNSResolverErrorCodeServerRefused: return @"The server refused the query."; case OFDNSResolverErrorCodeNoNameServer: return @"There was no name server to query."; default: return @"Unknown error."; } } @implementation OFDNSQueryFailedException @synthesize query = _query, errorCode = _errorCode; + (instancetype)exceptionWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode { return [[[self alloc] initWithQuery: query errorCode: errorCode] autorelease]; } - (instancetype)initWithQuery: (OFDNSQuery *)query errorCode: (OFDNSResolverErrorCode)errorCode { self = [super init]; @try { _query = [query copy]; _errorCode = errorCode; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_query release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"DNS query %@ could not be performed: %@", _query, OFDNSResolverErrorCodeDescription(_errorCode)]; } @end |
Modified src/exceptions/OFDeleteWindowsRegistryKeyFailedException.m from [4d5d00ab16] to [f6719643c7].
︙ | ︙ | |||
63 64 65 66 67 68 69 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to delete subkey at path %@: %@", | | | 63 64 65 66 67 68 69 70 71 72 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to delete subkey at path %@: %@", _subkeyPath, OFWindowsStatusToString(_status)]; } @end |
Modified src/exceptions/OFDeleteWindowsRegistryValueFailedException.h from [57d4edb21a] to [aa5651f4bf].
︙ | ︙ | |||
26 27 28 29 30 31 32 | * ObjFW/OFDeleteWindowsRegistryValueFailedException.h * * @brief An exception indicating that deleting a Windows registry value failed. */ @interface OFDeleteWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | * ObjFW/OFDeleteWindowsRegistryValueFailedException.h * * @brief An exception indicating that deleting a Windows registry value failed. */ @interface OFDeleteWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; LSTATUS _status; } /** * @brief The registry key on which deleting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The name of the value which could not be deleted. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *valueName; /** * @brief The status returned by RegDeleteValueEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased delete Windows registry value failed * exception. * * @param registryKey The registry key on which deleting the value failed * @param valueName The name of the value which could not be deleted * @param status The status returned by RegDeleteValueEx() * @return A new, autoreleased delete Windows registry value failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated delete Windows registry value failed * exception. * * @param registryKey The registry key on which deleting the value failed * @param valueName The name of the value which could not be deleted * @param status The status returned by RegDeleteValueEx() * @return An initialized delete Windows registry value failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFDeleteWindowsRegistryValueFailedException.m from [202f3abbb4] to [d0d9c24736].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #import "OFDeleteWindowsRegistryValueFailedException.h" #import "OFData.h" @implementation OFDeleteWindowsRegistryValueFailedException | | > | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 | #include "config.h" #import "OFDeleteWindowsRegistryValueFailedException.h" #import "OFData.h" @implementation OFDeleteWindowsRegistryValueFailedException @synthesize registryKey = _registryKey, valueName = _valueName; @synthesize status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey valueName: valueName status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _valueName = [valueName copy]; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_registryKey release]; [_valueName release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to delete value named %@: %@", _valueName, OFWindowsStatusToString(_status)]; } @end |
Modified src/exceptions/OFException.h from [2793460901] to [0c9aa4e00f].
︙ | ︙ | |||
21 22 23 24 25 26 27 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFString; | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | OF_ASSUME_NONNULL_BEGIN @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFString; #define OFBacktraceSize 16 #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # ifndef EADDRINUSE # define EADDRINUSE WSAEADDRINUSE # endif # ifndef EADDRNOTAVAIL # define EADDRNOTAVAIL WSAEADDRNOTAVAIL |
︙ | ︙ | |||
141 142 143 144 145 146 147 | * @brief The base class for all exceptions in ObjFW * * The OFException class is the base class for all exceptions in ObjFW, except * the OFAllocFailedException. */ @interface OFException: OFObject { | | | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | * @brief The base class for all exceptions in ObjFW * * The OFException class is the base class for all exceptions in ObjFW, except * the OFAllocFailedException. */ @interface OFException: OFObject { void *_backtrace[OFBacktraceSize]; } /** * @brief Creates a new, autoreleased exception. * * @return A new, autoreleased exception */ |
︙ | ︙ | |||
170 171 172 173 174 175 176 | */ - (nullable OFArray OF_GENERIC(OFString *) *)backtrace; @end #ifdef __cplusplus extern "C" { #endif | | | | 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | */ - (nullable OFArray OF_GENERIC(OFString *) *)backtrace; @end #ifdef __cplusplus extern "C" { #endif extern OFString *OFStrError(int errNo); #ifdef OF_WINDOWS extern OFString *OFWindowsStatusToString(LSTATUS status); #endif #ifdef __cplusplus } #endif OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFException.m from [c381d0d5f6] to [5ced4219b2].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #ifdef HAVE_DLFCN_H # include <dlfcn.h> #endif #import "OFException.h" #import "OFArray.h" #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" | > > > < < < < | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | #ifdef HAVE_DLFCN_H # include <dlfcn.h> #endif #import "OFException.h" #import "OFArray.h" #import "OFLocale.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLockFailedException.h" #import "OFUnlockFailedException.h" #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # include <winerror.h> #endif #if defined(OF_ARM) && !defined(__ARM_DWARF_EH__) # define HAVE_ARM_EHABI_EXCEPTIONS #endif struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_END_OF_STACK = 5 } _Unwind_Reason_Code; struct BacktraceCtx { void **backtrace; uint8_t i; }; #ifdef HAVE__UNWIND_BACKTRACE extern _Unwind_Reason_Code _Unwind_Backtrace( _Unwind_Reason_Code (*)(struct _Unwind_Context *, void *), void *); #endif #ifndef HAVE_ARM_EHABI_EXCEPTIONS extern uintptr_t _Unwind_GetIP(struct _Unwind_Context *); #else extern int _Unwind_VRS_Get(struct _Unwind_Context *, int, uint32_t, int, void *); #endif #if !defined(HAVE_STRERROR_R) && defined(OF_HAVE_THREADS) static OFPlainMutex mutex; OF_CONSTRUCTOR() { OFEnsure(OFPlainMutexNew(&mutex) == 0); } OF_DESTRUCTOR() { OFPlainMutexFree(&mutex); } #endif OFString * OFStrError(int errNo) { OFString *ret; #ifdef HAVE_STRERROR_R char buffer[256]; #endif if (errNo == 0) |
︙ | ︙ | |||
187 188 189 190 191 192 193 | if (strerror_r(errNo, buffer, 256) != 0) return @"Unknown error (strerror_r failed)"; ret = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; #else # ifdef OF_HAVE_THREADS | | | | | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | if (strerror_r(errNo, buffer, 256) != 0) return @"Unknown error (strerror_r failed)"; ret = [OFString stringWithCString: buffer encoding: [OFLocale encoding]]; #else # ifdef OF_HAVE_THREADS if (OFPlainMutexLock(&mutex) != 0) @throw [OFLockFailedException exception]; @try { # endif ret = [OFString stringWithCString: strerror(errNo) encoding: [OFLocale encoding]]; # ifdef OF_HAVE_THREADS } @finally { if (OFPlainMutexUnlock(&mutex) != 0) @throw [OFUnlockFailedException exception]; } # endif #endif return ret; } #ifdef OF_WINDOWS OFString * OFWindowsStatusToString(LSTATUS status) { OFString *string = nil; void *buffer; if ([OFSystemInfo isWindowsNT]) { if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | |
︙ | ︙ | |||
251 252 253 254 255 256 257 | return string; } #endif #ifdef HAVE__UNWIND_BACKTRACE static _Unwind_Reason_Code | | | | | 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | return string; } #endif #ifdef HAVE__UNWIND_BACKTRACE static _Unwind_Reason_Code backtraceCallback(struct _Unwind_Context *ctx, void *data) { struct BacktraceCtx *bt = data; if (bt->i < OFBacktraceSize) { # ifndef HAVE_ARM_EHABI_EXCEPTIONS bt->backtrace[bt->i++] = (void *)_Unwind_GetIP(ctx); # else uintptr_t ip; _Unwind_VRS_Get(ctx, 0, 15, 0, &ip); bt->backtrace[bt->i++] = (void *)(ip & ~1); |
︙ | ︙ | |||
280 281 282 283 284 285 286 | { return [[[self alloc] init] autorelease]; } #ifdef HAVE__UNWIND_BACKTRACE - (instancetype)init { | | | | < | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | { return [[[self alloc] init] autorelease]; } #ifdef HAVE__UNWIND_BACKTRACE - (instancetype)init { struct BacktraceCtx ctx; self = [super init]; ctx.backtrace = _backtrace; ctx.i = 0; _Unwind_Backtrace(backtraceCallback, &ctx); return self; } #endif - (OFString *)description { return [OFString stringWithFormat: @"An exception of type %@ occurred!", self.class]; } - (OFArray OF_GENERIC(OFString *) *)backtrace { #ifdef HAVE__UNWIND_BACKTRACE OFMutableArray OF_GENERIC(OFString *) *backtrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); for (uint8_t i = 0; i < OFBacktraceSize && _backtrace[i] != NULL; i++) { # ifdef HAVE_DLADDR Dl_info info; if (dladdr(_backtrace[i], &info)) { OFString *frame; if (info.dli_sname != NULL) { |
︙ | ︙ |
Modified src/exceptions/OFGetCurrentDirectoryPathFailedException.m from [c7ac43f203] to [df9ee71b64].
︙ | ︙ | |||
45 46 47 48 49 50 51 | return self; } - (OFString *)description { return [OFString stringWithFormat: @"Getting the current directory path failed: %@", | | | 45 46 47 48 49 50 51 52 53 54 | return self; } - (OFString *)description { return [OFString stringWithFormat: @"Getting the current directory path failed: %@", OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFGetOptionFailedException.h from [50223e7393] to [ad1a96e3af].
︙ | ︙ | |||
44 45 46 47 48 49 50 | /** * @brief Creates a new, autoreleased get option failed exception. * * @param object The object for which the option could not be retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased get option failed exception */ | | < | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /** * @brief Creates a new, autoreleased get option failed exception. * * @param object The object for which the option could not be retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased get option failed exception */ + (instancetype)exceptionWithObject: (id)object errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated get option failed exception. * * @param object The object for which the option could not be retrieved |
︙ | ︙ |
Modified src/exceptions/OFGetOptionFailedException.m from [af5f02ec1a] to [8f4ec296f2].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize object = _object, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | | 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 61 62 | @synthesize object = _object, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object errNo: (int)errNo { return [[[self alloc] initWithObject: object errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object errNo: (int)errNo { self = [super init]; _object = [object retain]; _errNo = errNo; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Getting an option in an object of type %@ failed: %@", [_object class], OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFGetWindowsRegistryValueFailedException.h from [5f718555eb] to [92b5996830].
︙ | ︙ | |||
26 27 28 29 30 31 32 | * ObjFW/OFGetWindowsRegistryValueFailedException.h * * @brief An exception indicating that getting a Windows registry value failed. */ @interface OFGetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | * ObjFW/OFGetWindowsRegistryValueFailedException.h * * @brief An exception indicating that getting a Windows registry value failed. */ @interface OFGetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; DWORD _flags; LSTATUS _status; } /** * @brief The registry key on which getting the value at the key path failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The name of the value which could not be retrieved. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *valueName; /** * @brief The status returned by RegGetValueEx(). */ @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased get Windows registry value failed * exception. * * @param registryKey The registry key on which getting the value at the sub * key path failed * @param valueName The name of the value which could not be retrieved * @param status The status returned by RegGetValueEx() * @return A new, autoreleased get Windows registry value failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated get Windows registry value failed * exception. * * @param registryKey The registry key on which getting the value at the sub * key path failed * @param valueName The name of the value which could not be retrieved * @param status The status returned by RegGetValueEx() * @return An initialized get Windows registry value failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFGetWindowsRegistryValueFailedException.m from [b88e4fd32c] to [1e9584387f].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "OFGetWindowsRegistryValueFailedException.h" @implementation OFGetWindowsRegistryValueFailedException | | > | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 | */ #include "config.h" #import "OFGetWindowsRegistryValueFailedException.h" @implementation OFGetWindowsRegistryValueFailedException @synthesize registryKey = _registryKey, valueName = _valueName; @synthesize status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey valueName: valueName status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _valueName = [valueName copy]; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_registryKey release]; [_valueName release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to get value named %@: %@", _valueName, OFWindowsStatusToString(_status)]; } @end |
Modified src/exceptions/OFHTTPRequestFailedException.m from [5d6244b48f] to [e96bd6a5f5].
︙ | ︙ | |||
57 58 59 60 61 62 63 | [_response release]; [super dealloc]; } - (OFString *)description { | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | [_response release]; [super dealloc]; } - (OFString *)description { const char *method = OFHTTPRequestMethodName(_request.method); return [OFString stringWithFormat: @"An HTTP %s request with URL %@ failed with code %hd!", method, _request.URL, _response.statusCode]; } @end |
Modified src/exceptions/OFInvalidJSONException.m from [9fef81c79e] to [6576de8b7b].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize string = _string, line = _line; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | 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 | @synthesize string = _string, line = _line; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithString: (OFString *)string line: (size_t)line { return [[[self alloc] initWithString: string line: line] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithString: (OFString *)string line: (size_t)line { self = [super init]; @try { _string = [string copy]; _line = line; } @catch (id e) { |
︙ | ︙ |
Modified src/exceptions/OFLinkFailedException.m from [1249431f65] to [aad9720e68].
︙ | ︙ | |||
67 68 69 70 71 72 73 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to link file %@ to %@: %@", | | | 67 68 69 70 71 72 73 74 75 76 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to link file %@ to %@: %@", _sourceURL, _destinationURL, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFListenFailedException.m from [f550e41673] to [076a85098b].
︙ | ︙ | |||
60 61 62 63 64 65 66 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to listen in socket of type %@ with a back log of %d: %@", | | | 60 61 62 63 64 65 66 67 68 69 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to listen in socket of type %@ with a back log of %d: %@", [_socket class], _backlog, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFLoadPluginFailedException.m from [8b15607f59] to [25e1a9ba80].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize path = _path, error = _error; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | 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 | @synthesize path = _path, error = _error; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithPath: (OFString *)path error: (OFString *)error { return [[[self alloc] initWithPath: path error: error] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithPath: (OFString *)path error: (OFString *)error { self = [super init]; @try { _path = [path copy]; _error = [error copy]; } @catch (id e) { |
︙ | ︙ |
Modified src/exceptions/OFLockFailedException.m from [464bc473e0] to [71085e6a43].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFLockFailedException.h" #import "OFString.h" @implementation OFLockFailedException @synthesize lock = _lock, errNo = _errNo; | | < | < | < | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFLockFailedException.h" #import "OFString.h" @implementation OFLockFailedException @synthesize lock = _lock, errNo = _errNo; + (instancetype)exceptionWithLock: (id <OFLocking>)lock errNo: (int)errNo { return [[[self alloc] initWithLock: lock errNo: errNo] autorelease]; } - (instancetype)initWithLock: (id <OFLocking>)lock errNo: (int)errNo { self = [super init]; _lock = [lock retain]; _errNo = errNo; return self; |
︙ | ︙ |
Modified src/exceptions/OFMemoryNotPartOfObjectException.m from [11976b53bf] to [505924293a].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize pointer = _pointer, object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | 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 | @synthesize pointer = _pointer, object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithPointer: (void *)pointer object: (id)object { return [[[self alloc] initWithPointer: pointer object: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithPointer: (void *)pointer object: (id)object { self = [super init]; _pointer = pointer; _object = [object retain]; return self; |
︙ | ︙ |
Modified src/exceptions/OFMoveItemFailedException.m from [eb728a5a4c] to [d1d30c8ee6].
︙ | ︙ | |||
26 27 28 29 30 31 32 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceURL: (OFURL *)sourceURL destinationURL: (OFURL *)destinationURL | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSourceURL: (OFURL *)sourceURL destinationURL: (OFURL *)destinationURL errNo: (int)errNo { return [[[self alloc] initWithSourceURL: sourceURL destinationURL: destinationURL errNo: errNo] autorelease]; } - (instancetype)init |
︙ | ︙ | |||
68 69 70 71 72 73 74 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to move item at %@ to %@: %@", | | | 68 69 70 71 72 73 74 75 76 77 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to move item at %@ to %@: %@", _sourceURL, _destinationURL, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFNotImplementedException.m from [21c9b375d3] to [7ae6cd8f84].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize selector = _selector, object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | 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 | @synthesize selector = _selector, object = _object; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSelector: (SEL)selector object: (id)object { return [[[self alloc] initWithSelector: selector object: object] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSelector: (SEL)selector object: (id)object { self = [super init]; _selector = selector; _object = [object retain]; return self; |
︙ | ︙ |
Modified src/exceptions/OFObserveFailedException.m from [c747f6dbae] to [2a1e03a9a1].
︙ | ︙ | |||
62 63 64 65 66 67 68 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"An observer of class %@ failed to observe: %@", | | | 62 63 64 65 66 67 68 69 70 71 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"An observer of class %@ failed to observe: %@", _observer.class, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFOpenItemFailedException.m from [90bc6b3814] to [f27f277ad9].
︙ | ︙ | |||
103 104 105 106 107 108 109 | item = _URL; else if (_path != nil) item = _path; if (_mode != nil) return [OFString stringWithFormat: @"Failed to open item %@ with mode %@: %@", | | | | 103 104 105 106 107 108 109 110 111 112 113 114 115 | item = _URL; else if (_path != nil) item = _path; if (_mode != nil) return [OFString stringWithFormat: @"Failed to open item %@ with mode %@: %@", item, _mode, OFStrError(_errNo)]; else return [OFString stringWithFormat: @"Failed to open item %@: %@", item, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFOpenWindowsRegistryKeyFailedException.m from [44e8721e49] to [55725614ec].
︙ | ︙ | |||
72 73 74 75 76 77 78 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to open subkey at path %@: %@", | | | 72 73 74 75 76 77 78 79 80 81 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to open subkey at path %@: %@", _path, OFWindowsStatusToString(_status)]; } @end |
Modified src/exceptions/OFReadFailedException.m from [ac90b3b64d] to [acb3de62d5].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFString.h" @implementation OFReadFailedException - (OFString *)description { return [OFString stringWithFormat: @"Failed to read %zu bytes from an object of type %@: %@", | | | 19 20 21 22 23 24 25 26 27 28 | #import "OFString.h" @implementation OFReadFailedException - (OFString *)description { return [OFString stringWithFormat: @"Failed to read %zu bytes from an object of type %@: %@", _requestedLength, [_object class], OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFReadOrWriteFailedException.m from [18185f7c97] to [dadaef8eb0].
︙ | ︙ | |||
62 63 64 65 66 67 68 | } - (OFString *)description { return [OFString stringWithFormat: @"Failed to read or write %zu bytes from / to an object of type " @"%@: %@", | | | 62 63 64 65 66 67 68 69 70 71 | } - (OFString *)description { return [OFString stringWithFormat: @"Failed to read or write %zu bytes from / to an object of type " @"%@: %@", _requestedLength, [_object class], OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFRemoveItemFailedException.h from [2b8b92f842] to [26cb046811].
︙ | ︙ | |||
46 47 48 49 50 51 52 | /** * @brief Creates a new, autoreleased remove failed exception. * * @param URL The URL of the item which could not be removed * @param errNo The errno of the error that occurred * @return A new, autoreleased remove item failed exception */ | | < | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | /** * @brief Creates a new, autoreleased remove failed exception. * * @param URL The URL of the item which could not be removed * @param errNo The errno of the error that occurred * @return A new, autoreleased remove item failed exception */ + (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated remove failed exception. * * @param URL The URL of the item which could not be removed |
︙ | ︙ |
Modified src/exceptions/OFRemoveItemFailedException.m from [2a6d0a2121] to [fd424614b6].
︙ | ︙ | |||
23 24 25 26 27 28 29 | @synthesize URL = _URL, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | 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 | @synthesize URL = _URL, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo { return [[[self alloc] initWithURL: URL errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo { self = [super init]; @try { _URL = [URL copy]; _errNo = errNo; } @catch (id e) { |
︙ | ︙ | |||
61 62 63 64 65 66 67 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: | | | 58 59 60 61 62 63 64 65 66 67 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to remove item at URL %@: %@", _URL, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFResolveHostFailedException.h from [48c5873ef6] to [d0ecf642c4].
︙ | ︙ | |||
23 24 25 26 27 28 29 | * OFResolveHostFailedException.h ObjFW/OFResolveHostFailedException.h * * @brief An exception indicating that resolving a host failed. */ @interface OFResolveHostFailedException: OFException { OFString *_host; | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | * OFResolveHostFailedException.h ObjFW/OFResolveHostFailedException.h * * @brief An exception indicating that resolving a host failed. */ @interface OFResolveHostFailedException: OFException { OFString *_host; OFSocketAddressFamily _addressFamily; OFDNSResolverErrorCode _errorCode; } /** * @brief The host which could not be resolved. */ @property (readonly, nonatomic) OFString *host; /** * @brief The address family for which the host could not be resolved. */ @property (readonly, nonatomic) OFSocketAddressFamily addressFamily; /** * @brief The error code from the resolver. */ @property (readonly, nonatomic) OFDNSResolverErrorCode errorCode; /** * @brief Creates a new, autoreleased resolve host failed exception. * * @param host The host which could not be resolved * @param addressFamily The address family for which the host could not be * resolved * @param errorCode The error code from the resolver * @return A new, autoreleased address translation failed exception */ + (instancetype)exceptionWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode; /** * @brief Initializes an already allocated resolve host failed exception. * * @param host The host which could not be resolved * @param addressFamily The address family for which the host could not be * resolved * @param errorCode The error code from the resolver * @return An initialized address translation failed exception */ - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFResolveHostFailedException.m from [5ef786dbbc] to [f2477f01e8].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #import "OFResolveHostFailedException.h" #import "OFDNSQueryFailedException.h" #import "OFString.h" @implementation OFResolveHostFailedException | | > | | | | | | | | 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 61 62 63 64 65 66 | #include "config.h" #import "OFResolveHostFailedException.h" #import "OFDNSQueryFailedException.h" #import "OFString.h" @implementation OFResolveHostFailedException @synthesize host = _host, addressFamily = _addressFamily; @synthesize errorCode = _errorCode; + (instancetype)exceptionWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode { return [[[self alloc] initWithHost: host addressFamily: addressFamily errorCode: errorCode] autorelease]; } - (instancetype)initWithHost: (OFString *)host addressFamily: (OFSocketAddressFamily)addressFamily errorCode: (OFDNSResolverErrorCode)errorCode { self = [super init]; @try { _host = [host copy]; _addressFamily = addressFamily; _errorCode = errorCode; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_host release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The host %@ could not be resolved: %@", _host, OFDNSResolverErrorCodeDescription(_errorCode)]; } @end |
Modified src/exceptions/OFRetrieveItemAttributesFailedException.h from [6fe2b96a6a] to [48a96c5a3a].
︙ | ︙ | |||
47 48 49 50 51 52 53 | /** * @brief Creates a new, autoreleased retrieve item attributes failed exception. * * @param URL The URL of the item whose attributes could not be retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased retrieve item attributes failed exception */ | | < | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | /** * @brief Creates a new, autoreleased retrieve item attributes failed exception. * * @param URL The URL of the item whose attributes could not be retrieved * @param errNo The errno of the error that occurred * @return A new, autoreleased retrieve item attributes failed exception */ + (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated retrieve item attributes failed * exception. * |
︙ | ︙ |
Modified src/exceptions/OFRetrieveItemAttributesFailedException.m from [62a4e002af] to [44d875971e].
︙ | ︙ | |||
23 24 25 26 27 28 29 | @synthesize URL = _URL, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | 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 | @synthesize URL = _URL, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURL: (OFURL *)URL errNo: (int)errNo { return [[[self alloc] initWithURL: URL errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURL: (OFURL *)URL errNo: (int)errNo { self = [super init]; @try { _URL = [URL copy]; _errNo = errNo; } @catch (id e) { |
︙ | ︙ | |||
62 63 64 65 66 67 68 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to retrieve attributes for item %@: %@", | | | 59 60 61 62 63 64 65 66 67 68 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to retrieve attributes for item %@: %@", _URL, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFSandboxActivationFailedException.h from [733e9e1e23] to [c3a79f74bb].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFSandbox; | < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFException.h" OF_ASSUME_NONNULL_BEGIN @class OFSandbox; @interface OFSandboxActivationFailedException: OFException { OFSandbox *_sandbox; int _errNo; } @property (readonly, nonatomic) OFSandbox *sandbox; @property (readonly, nonatomic) int errNo; + (instancetype)exception OF_UNAVAILABLE; + (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; - (instancetype)initWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFSandboxActivationFailedException.m from [2a85c28f4a] to [32c83692ab].
︙ | ︙ | |||
23 24 25 26 27 28 29 | @synthesize sandbox = _sandbox, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | | 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 61 62 63 | @synthesize sandbox = _sandbox, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo { return [[[self alloc] initWithSandbox: sandbox errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithSandbox: (OFSandbox *)sandbox errNo: (int)errNo { self = [super init]; _sandbox = [sandbox retain]; _errNo = errNo; return self; } - (void)dealloc { [_sandbox release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"The sandbox could not be applied: %@", OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFSeekFailedException.h from [4ea22d805a] to [7803a36cf1].
︙ | ︙ | |||
23 24 25 26 27 28 29 | * OFSeekFailedException.h ObjFW/OFSeekFailedException.h * * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; | | | | 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 | * OFSeekFailedException.h ObjFW/OFSeekFailedException.h * * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { OFSeekableStream *_stream; OFFileOffset _offset; int _whence, _errNo; } /** * @brief The stream for which seeking failed. */ @property (readonly, nonatomic) OFSeekableStream *stream; /** * @brief The offset to which seeking failed. */ @property (readonly, nonatomic) OFFileOffset offset; /** * @brief To what the offset is relative. */ @property (readonly, nonatomic) int whence; /** |
︙ | ︙ | |||
59 60 61 62 63 64 65 | * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return A new, autoreleased seek failed exception */ + (instancetype)exceptionWithStream: (OFSeekableStream *)stream | | | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return A new, autoreleased seek failed exception */ + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (OFFileOffset)offset whence: (int)whence errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated seek failed exception. * * @param stream The stream for which seeking failed * @param offset The offset to which seeking failed * @param whence To what the offset is relative * @param errNo The errno of the error that occurred * @return An initialized seek failed exception */ - (instancetype)initWithStream: (OFSeekableStream *)stream offset: (OFFileOffset)offset whence: (int)whence errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFSeekFailedException.m from [9c2e801f1d] to [47b84af63f].
︙ | ︙ | |||
25 26 27 28 29 30 31 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream | | | | 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 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithStream: (OFSeekableStream *)stream offset: (OFFileOffset)offset whence: (int)whence errNo: (int)errNo { return [[[self alloc] initWithStream: stream offset: offset whence: whence errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithStream: (OFSeekableStream *)stream offset: (OFFileOffset)offset whence: (int)whence errNo: (int)errNo { self = [super init]; _stream = [stream retain]; _offset = offset; |
︙ | ︙ | |||
66 67 68 69 70 71 72 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Seeking failed in stream of type %@: %@", | | | 66 67 68 69 70 71 72 73 74 75 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Seeking failed in stream of type %@: %@", _stream.class, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFSetItemAttributesFailedException.h from [d9ce8daea6] to [82396088b1].
︙ | ︙ | |||
26 27 28 29 30 31 32 | * ObjFW/OFSetItemAttributesFailedException.h * * @brief An exception indicating an item's attributes could not be set. */ @interface OFSetItemAttributesFailedException: OFException { OFURL *_URL; | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | * ObjFW/OFSetItemAttributesFailedException.h * * @brief An exception indicating an item's attributes could not be set. */ @interface OFSetItemAttributesFailedException: OFException { OFURL *_URL; OFFileAttributes _attributes; OFFileAttributeKey _failedAttribute; int _errNo; } /** * @brief The URL of the item whose attributes could not be set. */ @property (readonly, nonatomic) OFURL *URL; /** * @brief The errno of the error that occurred. */ @property (readonly, nonatomic) int errNo; /** * @brief The attributes that should have been set. */ @property (readonly, nonatomic) OFFileAttributes attributes; /** * @brief The first attribute that could not be set. */ @property (readonly, nonatomic) OFFileAttributeKey failedAttribute; + (instancetype)exception OF_UNAVAILABLE; /** * @brief Creates a new, autoreleased set item attributes failed exception. * * @param URL The URL of the item whose attributes could not be set * @param attributes The attributes that should have been set for the specified * item. * @param failedAttribute The first attribute that could not be set * @param errNo The errno of the error that occurred * @return A new, autoreleased set item attributes failed exception */ + (instancetype)exceptionWithURL: (OFURL *)URL attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated set item attributes failed exception. * * @param URL The URL of the item whose attributes could not be set * @param attributes The attributes that should have been set for the specified * item. * @param failedAttribute The first attribute that could not be set * @param errNo The errno of the error that occurred * @return An initialized set item attributes failed exception */ - (instancetype)initWithURL: (OFURL *)URL attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFSetItemAttributesFailedException.m from [86a87692ad] to [f92ac392b8].
︙ | ︙ | |||
25 26 27 28 29 30 31 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURL: (OFURL *)URL | | | | | | 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 | + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithURL: (OFURL *)URL attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo { return [[[self alloc] initWithURL: URL attributes: attributes failedAttribute: failedAttribute errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithURL: (OFURL *)URL attributes: (OFFileAttributes)attributes failedAttribute: (OFFileAttributeKey)failedAttribute errNo: (int)errNo { self = [super init]; @try { _URL = [URL copy]; _attributes = [attributes copy]; |
︙ | ︙ | |||
73 74 75 76 77 78 79 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to set attribute %@ for item %@: %@", | | | 73 74 75 76 77 78 79 80 81 82 | [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to set attribute %@ for item %@: %@", _failedAttribute, _URL, OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFSetOptionFailedException.h from [2b0c0efdc7] to [c0acfc31e0].
︙ | ︙ | |||
44 45 46 47 48 49 50 | /** * @brief Creates a new, autoreleased set option failed exception. * * @param object The object for which the option could not be set * @param errNo The errno of the error that occurred * @return A new, autoreleased set option failed exception */ | | < | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | /** * @brief Creates a new, autoreleased set option failed exception. * * @param object The object for which the option could not be set * @param errNo The errno of the error that occurred * @return A new, autoreleased set option failed exception */ + (instancetype)exceptionWithObject: (id)object errNo: (int)errNo; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated set option failed exception. * * @param object The object for which the option could not be set |
︙ | ︙ |
Modified src/exceptions/OFSetOptionFailedException.m from [463fe4cf45] to [80d83b74a4].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize object = _object, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | | 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 61 62 | @synthesize object = _object, errNo = _errNo; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object errNo: (int)errNo { return [[[self alloc] initWithObject: object errNo: errNo] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object errNo: (int)errNo { self = [super init]; _object = [object retain]; _errNo = errNo; return self; } - (void)dealloc { [_object release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Setting an option in an object of type %@ failed: %@", [_object class], OFStrError(_errNo)]; } @end |
Modified src/exceptions/OFSetWindowsRegistryValueFailedException.h from [608bf7a61e] to [55399fbd54].
︙ | ︙ | |||
26 27 28 29 30 31 32 | * ObjFW/OFSetWindowsRegistryValueFailedException.h * * @brief An exception indicating that setting a Windows registry value failed. */ @interface OFSetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; | | | | | 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 | * ObjFW/OFSetWindowsRegistryValueFailedException.h * * @brief An exception indicating that setting a Windows registry value failed. */ @interface OFSetWindowsRegistryValueFailedException: OFException { OFWindowsRegistryKey *_registryKey; OFString *_Nullable _valueName; OFData *_Nullable _data; DWORD _type; LSTATUS _status; } /** * @brief The registry key on which setting the value failed. */ @property (readonly, nonatomic) OFWindowsRegistryKey *registryKey; /** * @brief The name of the value which could not be set. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *valueName; /** * @brief The data to which the value could not be set. */ @property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFData *data; /** |
︙ | ︙ | |||
62 63 64 65 66 67 68 | @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased set Windows registry value failed * exception. * * @param registryKey The registry key on which setting the value failed | | | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | @property (readonly, nonatomic) LSTATUS status; /** * @brief Creates a new, autoreleased set Windows registry value failed * exception. * * @param registryKey The registry key on which setting the value failed * @param valueName The name of the value which could not be set * @param data The data to which the value could not be set * @param type The type for the value that could not be set * @param status The status returned by RegSetValueEx() * @return A new, autoreleased set Windows registry value failed exception */ + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName data: (nullable OFData *)data type: (DWORD)type status: (LSTATUS)status; - (instancetype)init OF_UNAVAILABLE; /** * @brief Initializes an already allocated set Windows registry value failed * exception. * * @param registryKey The registry key on which setting the value failed * @param valueName The name of the value which could not be set * @param data The data to which the value could not be set * @param type The type for the value that could not be set * @param status The status returned by RegSetValueEx() * @return An initialized set Windows registry value failed exception */ - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (nullable OFString *)valueName data: (nullable OFData *)data type: (DWORD)type status: (LSTATUS)status OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Modified src/exceptions/OFSetWindowsRegistryValueFailedException.m from [b5d9f2531b] to [ae444c6b4a].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #import "OFSetWindowsRegistryValueFailedException.h" #import "OFData.h" @implementation OFSetWindowsRegistryValueFailedException | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | #include "config.h" #import "OFSetWindowsRegistryValueFailedException.h" #import "OFData.h" @implementation OFSetWindowsRegistryValueFailedException @synthesize registryKey = _registryKey, valueName = _valueName, data = _data; @synthesize type = _type, status = _status; + (instancetype)exceptionWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName data: (OFData *)data type: (DWORD)type status: (LSTATUS)status { return [[[self alloc] initWithRegistryKey: registryKey valueName: valueName data: data type: type status: status] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithRegistryKey: (OFWindowsRegistryKey *)registryKey valueName: (OFString *)valueName data: (OFData *)data type: (DWORD)type status: (LSTATUS)status { self = [super init]; @try { _registryKey = [registryKey retain]; _valueName = [valueName copy]; _data = [data copy]; _type = type; _status = status; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_registryKey release]; [_valueName release]; [_data release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Failed to set value named %@ of type %u: %@", _valueName, _type, OFWindowsStatusToString(_status)]; } @end |
Modified src/exceptions/OFThreadJoinFailedException.m from [9aa0b98405] to [69fa9314a9].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFThreadJoinFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadJoinFailedException @synthesize thread = _thread, errNo = _errNo; | | < | < | < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #import "OFThreadJoinFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadJoinFailedException @synthesize thread = _thread, errNo = _errNo; + (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo { return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; } - (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo { self = [super init]; _thread = [thread retain]; _errNo = errNo; return self; |
︙ | ︙ |
Modified src/exceptions/OFThreadStartFailedException.m from [c02dc6c663] to [1ba940b160].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFThreadStartFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadStartFailedException @synthesize thread = _thread, errNo = _errNo; | | < | < | < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #import "OFThreadStartFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadStartFailedException @synthesize thread = _thread, errNo = _errNo; + (instancetype)exceptionWithThread: (OFThread *)thread errNo: (int)errNo { return [[[self alloc] initWithThread: thread errNo: errNo] autorelease]; } - (instancetype)initWithThread: (OFThread *)thread errNo: (int)errNo { self = [super init]; _thread = [thread retain]; _errNo = errNo; return self; |
︙ | ︙ |
Modified src/exceptions/OFUnboundPrefixException.m from [f4a0e227c8] to [636055adfc].
︙ | ︙ | |||
35 36 37 38 39 40 41 | } - (instancetype)init { OF_INVALID_INIT_METHOD } | | < | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithPrefix: (OFString *)prefix parser: (OFXMLParser *)parser { self = [super init]; @try { _prefix = [prefix copy]; _parser = [parser retain]; } @catch (id e) { |
︙ | ︙ |
Modified src/exceptions/OFUndefinedKeyException.h from [867e9e731b] to [dcded81ec7].
︙ | ︙ | |||
52 53 54 55 56 57 58 | * @brief Creates a new, autoreleased undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * * @return A new, autoreleased undefined key exception */ | | < | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | * @brief Creates a new, autoreleased undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * * @return A new, autoreleased undefined key exception */ + (instancetype)exceptionWithObject: (id)object key: (OFString *)key; /** * @brief Creates a new, autoreleased undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * @param value The value for the undefined key |
︙ | ︙ | |||
78 79 80 81 82 83 84 | * @brief Initializes an already allocated undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * * @return An initialized undefined key exception */ | | < | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | * @brief Initializes an already allocated undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * * @return An initialized undefined key exception */ - (instancetype)initWithObject: (id)object key: (OFString *)key; /** * @brief Initializes an already allocated undefined key exception. * * @param object The object on which the key is undefined * @param key The key which is undefined * @param value The value for the undefined key |
︙ | ︙ |
Modified src/exceptions/OFUndefinedKeyException.m from [c33af96db7] to [a23aa824a4].
︙ | ︙ | |||
22 23 24 25 26 27 28 | @synthesize object = _object, key = _key, value = _value; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } | | < | < | < | < < | < < | 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 | @synthesize object = _object, key = _key, value = _value; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithObject: (id)object key: (OFString *)key { return [[[self alloc] initWithObject: object key: key] autorelease]; } + (instancetype)exceptionWithObject: (id)object key: (OFString *)key value: (id)value { return [[[self alloc] initWithObject: object key: key value: value] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithObject: (id)object key: (OFString *)key { return [self initWithObject: object key: key value: nil]; } - (instancetype)initWithObject: (id)object key: (OFString *)key value: (id)value { self = [super init]; @try { _object = [object retain]; _key = [key copy]; _value = [value retain]; |
︙ | ︙ |
Modified src/exceptions/OFUnlockFailedException.m from [4450bdd3cc] to [ae9174489f].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFUnlockFailedException.h" #import "OFString.h" @implementation OFUnlockFailedException @synthesize lock = _lock, errNo = _errNo; | | < | < | < | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFUnlockFailedException.h" #import "OFString.h" @implementation OFUnlockFailedException @synthesize lock = _lock, errNo = _errNo; + (instancetype)exceptionWithLock: (id <OFLocking>)lock errNo: (int)errNo { return [[[self alloc] initWithLock: lock errNo: errNo] autorelease]; } - (instancetype)initWithLock: (id <OFLocking>)lock errNo: (int)errNo { self = [super init]; _lock = [lock retain]; _errNo = errNo; return self; |
︙ | ︙ |
Modified src/exceptions/OFWriteFailedException.m from [0afa5a091c] to [6f0f1c63f5].
︙ | ︙ | |||
64 65 66 67 68 69 70 | - (OFString *)description { return [OFString stringWithFormat: @"Failed to write %zu bytes (after %zu bytes written) to an " @"object of type %@: %@", _requestedLength, _bytesWritten, [_object class], | | | 64 65 66 67 68 69 70 71 72 73 | - (OFString *)description { return [OFString stringWithFormat: @"Failed to write %zu bytes (after %zu bytes written) to an " @"object of type %@: %@", _requestedLength, _bytesWritten, [_object class], OFStrError(_errNo)]; } @end |
Modified src/forwarding/apple-forwarding-arm.S from [818da0b02a] to [909cff10e5].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __objc_methname, cstring_literals str_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __DATA, __objc_selrefs, literal_pointers, no_dead_strip sel_forwardingTargetForSelector_: .long str_forwardingTargetForSelector_ .section __DATA, __objc_imageinfo, regular, no_dead_strip .long 0, 0 .section __TEXT, __text, regular, pure_instructions .arm .align 2 _OFForward: stmfd sp!, {r0-r4, lr} vstmdb sp!, {d0-d7} ldr r4, sel_forwardingTargetForSelector_$indirect_L0 L0: ldr r4, [pc, r4] |
︙ | ︙ | |||
64 65 66 67 68 69 70 | ldmfd sp!, {r1-r4, lr} b _objc_msgSend 0: vldmia sp!, {d0-d7} ldmfd sp!, {r0-r4, lr} | | | | 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | ldmfd sp!, {r1-r4, lr} b _objc_msgSend 0: vldmia sp!, {d0-d7} ldmfd sp!, {r0-r4, lr} b _OFMethodNotFound .data_region sel_forwardingTargetForSelector_$indirect_L0: .long sel_forwardingTargetForSelector_-(L0+8) .end_data_region .align 2 _OFForward_stret: stmfd sp!, {r0-r4, lr} vstmdb sp!, {d0-d7} ldr r4, sel_forwardingTargetForSelector_$indirect_L1 L1: ldr r4, [pc, r4] |
︙ | ︙ | |||
112 113 114 115 116 117 118 | ldmfd sp!, {r2-r4, lr} b _objc_msgSend_stret 0: vldmia sp!, {d0-d7} ldmfd sp!, {r0-r4, lr} | | | 112 113 114 115 116 117 118 119 120 121 122 123 124 | ldmfd sp!, {r2-r4, lr} b _objc_msgSend_stret 0: vldmia sp!, {d0-d7} ldmfd sp!, {r0-r4, lr} b _OFMethodNotFound_stret .data_region sel_forwardingTargetForSelector_$indirect_L1: .long sel_forwardingTargetForSelector_-(L1+8) .end_data_region |
Modified src/forwarding/apple-forwarding-arm64.S from [a5ded6a46a] to [9cba63c991].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __objc_methname, cstring_literals str_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __DATA, __objc_selrefs, literal_pointers, no_dead_strip sel_forwardingTargetForSelector_: .quad str_forwardingTargetForSelector_ .section __DATA, __objc_imageinfo, regular, no_dead_strip .long 0, 0 .section __TEXT, __text, regular, pure_instructions .align 2 _OFForward: _OFForward_stret: stp fp, lr, [sp, #-208]! mov fp, sp sub sp, sp, #208 /* Save all arguments, x8 and x19 */ stp x0, x1, [sp] stp x2, x3, [sp, #16] |
︙ | ︙ | |||
91 92 93 94 95 96 97 | 0: ldp x0, x1, [sp] ldr x19, [sp, #72] mov sp, fp ldp fp, lr, [sp], #208 | | | 91 92 93 94 95 96 97 98 | 0: ldp x0, x1, [sp] ldr x19, [sp, #72] mov sp, fp ldp fp, lr, [sp], #208 b _OFMethodNotFound |
Modified src/forwarding/apple-forwarding-i386.S from [242ac0ef8b] to [8720a29870].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | | | | | | | | | | | | | < | < | | | | < | | | | < | | | | | | | | | | | | | | | | | | < | < | | | | < | > > > > < < < < < | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __cstring, cstring_literals str_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __OBJC, __message_refs, literal_pointers, no_dead_strip sel_forwardingTargetForSelector_: .long str_forwardingTargetForSelector_ .section __OBJC, __image_info .long 0, 0 .section __TEXT, __text, regular, pure_instructions _OFForward: pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call get_eip 0: movl 8(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl sel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 8(%ebp), %eax movl %eax, (%esp) movl sel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) movl 12(%ebp), %eax movl %eax, 8(%esp) call _objc_msgSend testl %eax, %eax jz 0f cmpl 8(%ebp), %eax je 0f movl %eax, 8(%ebp) addl $20, %esp popl %ebx popl %ebp jmp _objc_msgSend 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound _OFForward_stret: pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call get_eip 0: movl 12(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl sel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 12(%ebp), %eax movl %eax, (%esp) movl sel_forwardingTargetForSelector_-0b(%ebx), %eax movl %eax, 4(%esp) movl 16(%ebp), %eax movl %eax, 8(%esp) call _objc_msgSend testl %eax, %eax jz 0f cmpl 12(%ebp), %eax je 0f movl %eax, 12(%ebp) addl $20, %esp popl %ebx popl %ebp jmp _objc_msgSend_stret 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound_stret get_eip: movl (%esp), %ebx ret |
Modified src/forwarding/apple-forwarding-powerpc.S from [caae32d345] to [df92748799].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __cstring, cstring_literals str_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __OBJC, __message_refs sel_forwardingTargetForSelector_: .long str_forwardingTargetForSelector_ .section __OBJC, __image_info .long 0, 0 .section __TEXT, __text, regular, pure_instructions _OFForward: mflr r0 stw r0, 8(r1) stwu r1, -192(r1) /* * Save all arguments and r13. * |
︙ | ︙ | |||
126 127 128 129 130 131 132 | lwz r3, 216(r1) lwz r4, 220(r1) addi r1, r1, 192 lwz r0, 8(r1) mtlr r0 | | | | 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | lwz r3, 216(r1) lwz r4, 220(r1) addi r1, r1, 192 lwz r0, 8(r1) mtlr r0 b _OFMethodNotFound _OFForward_stret: mflr r0 stw r0, 8(r1) stwu r1, -184(r1) /* * Save all arguments and r13. * |
︙ | ︙ | |||
232 233 234 235 236 237 238 | lwz r4, 212(r1) lwz r5, 216(r1) addi r1, r1, 184 lwz r0, 8(r1) mtlr r0 | | | 232 233 234 235 236 237 238 239 | lwz r4, 212(r1) lwz r5, 216(r1) addi r1, r1, 184 lwz r0, 8(r1) mtlr r0 b _OFMethodNotFound_stret |
Modified src/forwarding/apple-forwarding-x86_64.S from [5aadb3b06b] to [0da6f95099].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __objc_methname, cstring_literals str_forwardingTargetForSelector_: .asciz "forwardingTargetForSelector:" .section __DATA, __objc_selrefs, literal_pointers, no_dead_strip sel_forwardingTargetForSelector_: .quad str_forwardingTargetForSelector_ .section __DATA, __objc_imageinfo, regular, no_dead_strip .long 0, 0 .section __TEXT, __text, regular, pure_instructions _OFForward: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) call _object_getClass movq %rax, %rdi movq sel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x10(%rbp), %rdi movq sel_forwardingTargetForSelector_(%rip), %rsi movq -0x18(%rbp), %rdx call _objc_msgSend testq %rax, %rax jz 0f cmpq -0x10(%rbp), %rax je 0f movq %rax, %rdi /* Restore all arguments, except %rdi */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmp _objc_msgSend 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound _OFForward_stret: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) movq %rsi, %rdi call _object_getClass movq %rax, %rdi movq sel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x18(%rbp), %rdi movq sel_forwardingTargetForSelector_(%rip), %rsi movq -0x20(%rbp), %rdx call _objc_msgSend testq %rax, %rax jz 0f cmpq -0x18(%rbp), %rax je 0f movq %rax, %rsi /* Restore all arguments, except %rsi */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmp _objc_msgSend_stret 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq -0x20(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound_stret |
Modified src/forwarding/forwarding-arm-elf.S from [cf76c10b12] to [9186955894].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #include "platform.h" #ifdef HAVE_VFP2 .fpu vfp #endif | | | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include "platform.h" #ifdef HAVE_VFP2 .fpu vfp #endif .globl OFForward .globl OFForward_stret .section .text OFForward: #ifdef HAVE_VFP2 vstmdb sp!, {d0-d7} #endif stmfd sp!, {r0-r4, lr} ldr r4, sel_forwardingTargetForSelector_$indirect_.L0 .L0: |
︙ | ︙ | |||
72 73 74 75 76 77 78 | bx r12 0: ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif | | | | | | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | bx r12 0: ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif b OFMethodNotFound(PLT) .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: #ifdef HAVE_VFP2 vstmdb sp!, {d0-d7} #endif stmfd sp!, {r0-r4, lr} ldr r4, sel_forwardingTargetForSelector_$indirect_.L1 .L1: |
︙ | ︙ | |||
128 129 130 131 132 133 134 | bx r12 0: ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif | | | | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | bx r12 0: ldmfd sp!, {r0-r4, lr} #ifdef HAVE_VFP2 vldmia sp!, {d0-d7} #endif b OFMethodNotFound_stret(PLT) .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: ldr r0, module$indirect_.L2 .L2: add r0, pc b __objc_exec_class(PLT) |
︙ | ︙ |
Modified src/forwarding/forwarding-arm64-elf.S from [8475d93bd5] to [853844ab33].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | * file. */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: OFForward_stret: stp fp, lr, [sp, #-208]! mov fp, sp sub sp, sp, #208 /* Save all arguments, x8 and x19 */ stp x0, x1, [sp] stp x2, x3, [sp, #16] |
︙ | ︙ | |||
92 93 94 95 96 97 98 | 0: ldp x0, x1, [sp] ldr x19, [sp, #72] mov sp, fp ldp fp, lr, [sp], #208 | | | | | | | 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | 0: ldp x0, x1, [sp] ldr x19, [sp, #72] mov sp, fp ldp fp, lr, [sp], #208 b OFMethodNotFound .type OFForward, %function .size OFForward, .-OFForward .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: adrp x0, module add x0, x0, :lo12:module b __objc_exec_class .section .init_array, "aw", %init_array |
︙ | ︙ |
Modified src/forwarding/forwarding-mips-elf.S from [b9346e9fc8] to [82117db4a0].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | | | | | 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 | * file. */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret #ifdef OF_PIC .macro j_pic symbol lw $t9, %call16(\symbol)($gp) jr $t9 .endm .macro jal_pic symbol lw $t9, %call16(\symbol)($gp) jalr $t9 .endm #else .macro j_pic symbol j \symbol .endm .macro jal_pic symbol jal \symbol .endm #endif .section .text OFForward: #ifdef OF_PIC lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 #endif addiu $sp, $sp, -96 |
︙ | ︙ | |||
156 157 158 159 160 161 162 | lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 j_pic of_method_not_found | | | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 j_pic of_method_not_found .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: #ifdef OF_PIC lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 #endif addiu $sp, $sp, -96 |
︙ | ︙ | |||
282 283 284 285 286 287 288 | lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 j_pic of_method_not_found_stret | | | | 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | lw $s1, 24($sp) lw $s0, 20($sp) lw $ra, 16($sp) addiu $sp, $sp, 96 j_pic of_method_not_found_stret .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: #ifdef OF_PIC lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 |
︙ | ︙ |
Modified src/forwarding/forwarding-powerpc-elf.S from [77e163195d] to [aa95b3885f].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * file. */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: stwu %r1, -112(%r1) mflr %r0 stw %r0, 116(%r1) #ifdef OF_PIC stw %r30, 104(%r1) bl 0f |
︙ | ︙ | |||
137 138 139 140 141 142 143 | bctr 0: lwz %r3, 8(%r1) lwz %r4, 12(%r1) #ifdef OF_PIC | | | | | | | 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 163 164 165 166 167 168 | bctr 0: lwz %r3, 8(%r1) lwz %r4, 12(%r1) #ifdef OF_PIC lwz %r0, .Lgot_OFMethodNotFound-.Lbiased_got2(%r30) mtctr %r0 lwz %r30, 104(%r1) #endif lwz %r0, 116(%r1) mtlr %r0 addi %r1, %r1, 112 #ifdef OF_PIC bctr #else b OFMethodNotFound #endif .type OFForward, @function .size OFForward, .-OFForward OFForward_stret: stwu %r1, -112(%r1) mflr %r0 stw %r0, 116(%r1) #ifdef OF_PIC stw %r30, 104(%r1) bl 0f |
︙ | ︙ | |||
276 277 278 279 280 281 282 | 0: lwz %r3, 8(%r1) lwz %r4, 12(%r1) lwz %r5, 16(%r1) #ifdef OF_PIC | | | | | | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | 0: lwz %r3, 8(%r1) lwz %r4, 12(%r1) lwz %r5, 16(%r1) #ifdef OF_PIC lwz %r0, .Lgot_OFMethodNotFound_stret-.Lbiased_got2(%r30) mtctr %r0 lwz %r30, 104(%r1) #endif lwz %r0, 116(%r1) mtlr %r0 addi %r1, %r1, 112 #ifdef OF_PIC bctr #else b OFMethodNotFound_stret #endif .type OFForward_stret, @function .size OFForward_stret, .-OFForward_stret init: stwu %r1, -16(%r1) mflr %r0 stw %r0, 20(%r1) #ifdef OF_PIC stw %r30, 8(%r1) |
︙ | ︙ | |||
347 348 349 350 351 352 353 | #ifdef OF_PIC .section .got2, "aw" .Lbiased_got2 = .+0x8000 .Lgot_module: .long module .Lgot_sel_forwardingTargetForSelector_: .long sel_forwardingTargetForSelector_ | | | | | | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | #ifdef OF_PIC .section .got2, "aw" .Lbiased_got2 = .+0x8000 .Lgot_module: .long module .Lgot_sel_forwardingTargetForSelector_: .long sel_forwardingTargetForSelector_ .Lgot_OFMethodNotFound: .long OFMethodNotFound .Lgot_OFMethodNotFound_stret: .long OFMethodNotFound_stret #endif #ifdef OF_LINUX .section .note.GNU-stack, "", @progbits #endif |
Modified src/forwarding/forwarding-sparc-elf.S from [7f326e78b6] to [561fb7b970].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * file. */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: save %sp, -96, %sp #ifdef OF_PIC sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call add_pc add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 #endif |
︙ | ︙ | |||
73 74 75 76 77 78 79 | call objc_msg_lookup mov %i1, %o1 jmpl %o0, %g0 restore 0: | | | | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | call objc_msg_lookup mov %i1, %o1 jmpl %o0, %g0 restore 0: call OFMethodNotFound restore .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: save %sp, -96, %sp #ifdef OF_PIC sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call add_pc add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 #endif |
︙ | ︙ | |||
134 135 136 137 138 139 140 | call objc_msg_lookup mov %i2, %o1 jmpl %o0, %g0 restore 0: | | | | | 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | call objc_msg_lookup mov %i2, %o1 jmpl %o0, %g0 restore 0: call OFMethodNotFound_stret restore .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: save %sp, -96, %sp #ifdef OF_PIC sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call add_pc |
︙ | ︙ |
Modified src/forwarding/forwarding-sparc64-elf.S from [4c8170f46f] to [bd5584b259].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * file. */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret #define BIAS 2047 .section .text OFForward: save %sp, -304, %sp /* * Save all floating point registers as they can be used for parameter * passing. */ std %f0, [%sp + BIAS + 176] |
︙ | ︙ | |||
107 108 109 110 111 112 113 | ldd [%sp + BIAS + 288], %f28 ldd [%sp + BIAS + 296], %f30 jmpl %o0, %g0 restore 0: | | | | | | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | ldd [%sp + BIAS + 288], %f28 ldd [%sp + BIAS + 296], %f30 jmpl %o0, %g0 restore 0: call OFMethodNotFound restore .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: save %sp, -304, %sp /* * Save all floating point registers as they can be used for parameter * passing. */ std %f0, [%sp + BIAS + 176] |
︙ | ︙ | |||
200 201 202 203 204 205 206 | ldd [%sp + BIAS + 288], %f28 ldd [%sp + BIAS + 296], %f30 jmpl %o0, %g0 restore 0: | | | | | 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | ldd [%sp + BIAS + 288], %f28 ldd [%sp + BIAS + 296], %f30 jmpl %o0, %g0 restore 0: call OFMethodNotFound_stret restore .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: save %sp, -176, %sp sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %l7 call add_pc add %l7, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %l7 |
︙ | ︙ |
Modified src/forwarding/forwarding-x86-elf.S from [919ceb5d84] to [b0f736c46b].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | < < | | | | | | | | | | | | | | | | | | | | | | > > > > < < < < | | | | | | | | | | | > > < < | | | | | | | | | | | > < | | | | | | | | | | | | | | | | | | | | | | | < < < | > | > > | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | * file. */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call get_eip addl $_GLOBAL_OFFSET_TABLE_, %ebx movl 8(%ebp), %eax movl %eax, (%esp) call object_getClass@PLT movl %eax, (%esp) leal sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call class_respondsToSelector@PLT testl %eax, %eax jz 0f movl 8(%ebp), %eax movl %eax, (%esp) leal sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call objc_msg_lookup@PLT movl 8(%ebp), %edx movl %edx, (%esp) leal sel_forwardingTargetForSelector_@GOTOFF(%ebx), %edx movl %edx, 4(%esp) movl 12(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 8(%ebp), %eax je 0f movl %eax, 8(%ebp) movl %eax, (%esp) movl 12(%ebp), %eax movl %eax, 4(%esp) call objc_msg_lookup@PLT addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: leal OFMethodNotFound@GOTOFF(%ebx), %eax addl $20, %esp popl %ebx popl %ebp jmp *%eax .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp call get_eip addl $_GLOBAL_OFFSET_TABLE_, %ebx movl 12(%ebp), %eax movl %eax, (%esp) call object_getClass@PLT movl %eax, (%esp) leal sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call class_respondsToSelector@PLT testl %eax, %eax jz 0f movl 12(%ebp), %eax movl %eax, (%esp) leal sel_forwardingTargetForSelector_@GOTOFF(%ebx), %eax movl %eax, 4(%esp) call objc_msg_lookup@PLT movl 12(%ebp), %edx movl %edx, (%esp) leal sel_forwardingTargetForSelector_@GOTOFF(%ebx), %edx movl %edx, 4(%esp) movl 16(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 12(%ebp), %eax je 0f movl %eax, 12(%ebp) movl %eax, (%esp) movl 16(%ebp), %eax movl %eax, 4(%esp) call objc_msg_lookup_stret@PLT addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: leal OFMethodNotFound_stret@GOTOFF(%ebx), %eax addl $20, %esp popl %ebx popl %ebp jmp *%eax .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: pushl %ebp movl %esp, %ebp pushl %ebx subl $4, %esp call get_eip addl $_GLOBAL_OFFSET_TABLE_, %ebx leal module@GOTOFF(%ebx), %eax movl %eax, (%esp) call __objc_exec_class@PLT addl $4, %esp popl %ebx popl %ebp ret get_eip: movl (%esp), %ebx ret #ifdef OF_SOLARIS .section .init_array, "aw" #else .section .ctors, "aw", %progbits #endif |
︙ | ︙ |
Modified src/forwarding/forwarding-x86-win32.S from [5db1a76db3] to [7197d1ad71].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > > | | > | > | < < | | | | | | | | | | | | | | | | | | | | | | > > > | < < | < | | | | | | | | > > > > | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _OFForward .globl _OFForward_stret .section .text _OFForward: pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp movl 8(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl $sel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 8(%ebp), %eax movl %eax, (%esp) movl $sel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _objc_msg_lookup movl 8(%ebp), %edx movl %edx, (%esp) movl $sel_forwardingTargetForSelector_, %edx movl %edx, 4(%esp) movl 12(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 8(%ebp), %eax je 0f movl %eax, 8(%ebp) movl %eax, (%esp) movl 12(%ebp), %eax movl %eax, 4(%esp) call _objc_msg_lookup addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound .def _OFForward .scl 2 .type 32 .endef _OFForward_stret: pushl %ebp movl %esp, %ebp pushl %ebx subl $20, %esp movl 12(%ebp), %eax movl %eax, (%esp) call _object_getClass movl %eax, (%esp) movl $sel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _class_respondsToSelector testl %eax, %eax jz 0f movl 12(%ebp), %eax movl %eax, (%esp) movl $sel_forwardingTargetForSelector_, %eax movl %eax, 4(%esp) call _objc_msg_lookup movl 12(%ebp), %edx movl %edx, (%esp) movl $sel_forwardingTargetForSelector_, %edx movl %edx, 4(%esp) movl 16(%ebp), %edx movl %edx, 8(%esp) call *%eax testl %eax, %eax jz 0f cmpl 12(%ebp), %eax je 0f movl %eax, 12(%ebp) movl %eax, (%esp) movl 16(%ebp), %eax movl %eax, 4(%esp) call _objc_msg_lookup_stret addl $20, %esp popl %ebx popl %ebp jmp *%eax 0: addl $20, %esp popl %ebx popl %ebp jmp _OFMethodNotFound_stret .def _OFForward_stret .scl 2 .type 32 .endef init: pushl %ebp movl %esp, %ebp pushl %ebx subl $4, %esp movl $module, %eax movl %eax, (%esp) call ___objc_exec_class addl $4, %esp popl %ebx popl %ebp ret .section .ctors, "aw" .long init .section .rodata str_forwardingTargetForSelector_: |
︙ | ︙ |
Modified src/forwarding/forwarding-x86_64-elf.S from [20eb6983b1] to [8ad5ac6701].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | < < | | | | | | | | | | | | | | | | > | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < > > > | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | * file. */ #include "config.h" #include "platform.h" .globl OFForward .globl OFForward_stret .section .text OFForward: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) call object_getClass@PLT movq %rax, %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call class_respondsToSelector@PLT testq %rax, %rax jz 0f movq -0x10(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call objc_msg_lookup@PLT movq -0x10(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi movq -0x18(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x10(%rbp), %rax je 0f movq %rax, -0x10(%rbp) movq %rax, %rdi movq -0x18(%rbp), %rsi call objc_msg_lookup@PLT movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq %rbp, %rsp popq %rbp jmp OFMethodNotFound@PLT .type OFForward, %function .size OFForward, .-OFForward OFForward_stret: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) movq %rsi, %rdi call object_getClass@PLT movq %rax, %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call class_respondsToSelector@PLT testq %rax, %rax jz 0f movq -0x18(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call objc_msg_lookup@PLT movq -0x18(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi movq -0x20(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x18(%rbp), %rax je 0f movq %rax, -0x18(%rbp) movq %rax, %rdi movq -0x20(%rbp), %rsi call objc_msg_lookup_stret@PLT movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq -0x20(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp OFMethodNotFound_stret@PLT .type OFForward_stret, %function .size OFForward_stret, .-OFForward_stret init: leaq module(%rip), %rdi jmp __objc_exec_class@PLT #ifdef OF_SOLARIS .section .init_array, "aw" #else .section .ctors, "aw", %progbits #endif |
︙ | ︙ |
Modified src/forwarding/forwarding-x86_64-macho.S from [d39aa9c238] to [96ab2eb2d0].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | < < | | | | | | | | | | | | | | | | > | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | > | | | | | | | | | | < < > > | | | | | | | | | | | | | | | < < < < > > > > | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | * file. */ #include "config.h" #include "platform.h" .globl _OFForward .globl _OFForward_stret .section __TEXT, __text, regular, pure_instructions _OFForward: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) call _object_getClass movq %rax, %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x10(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call _objc_msg_lookup movq -0x10(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi movq -0x18(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x10(%rbp), %rax je 0f movq %rax, -0x10(%rbp) movq %rax, %rdi movq -0x18(%rbp), %rsi call _objc_msg_lookup movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound _OFForward_stret: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0xC0, %rsp /* 16-byte alignment */ movq %rax, -0x8(%rbp) movq %rdi, -0x10(%rbp) movq %rsi, -0x18(%rbp) movq %rdx, -0x20(%rbp) movq %rcx, -0x28(%rbp) movq %r8, -0x30(%rbp) movq %r9, -0x38(%rbp) movaps %xmm0, -0x50(%rbp) movaps %xmm1, -0x60(%rbp) movaps %xmm2, -0x70(%rbp) movaps %xmm3, -0x80(%rbp) movaps %xmm4, -0x90(%rbp) movaps %xmm5, -0xA0(%rbp) movaps %xmm6, -0xB0(%rbp) movaps %xmm7, -0xC0(%rbp) movq %rsi, %rdi call _object_getClass movq %rax, %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call _class_respondsToSelector testq %rax, %rax jz 0f movq -0x18(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi call _objc_msg_lookup movq -0x18(%rbp), %rdi leaq sel_forwardingTargetForSelector_(%rip), %rsi movq -0x20(%rbp), %rdx call *%rax testq %rax, %rax jz 0f cmpq -0x18(%rbp), %rax je 0f movq %rax, -0x18(%rbp) movq %rax, %rdi movq -0x20(%rbp), %rsi call _objc_msg_lookup_stret movq %rax, %r11 /* Restore all arguments */ movaps -0xC0(%rbp), %xmm7 movaps -0xB0(%rbp), %xmm6 movaps -0xA0(%rbp), %xmm5 movaps -0x90(%rbp), %xmm4 movaps -0x80(%rbp), %xmm3 movaps -0x70(%rbp), %xmm2 movaps -0x60(%rbp), %xmm1 movaps -0x50(%rbp), %xmm0 movq -0x38(%rbp), %r9 movq -0x30(%rbp), %r8 movq -0x28(%rbp), %rcx movq -0x20(%rbp), %rdx movq -0x18(%rbp), %rsi movq -0x10(%rbp), %rdi movq -0x8(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x10(%rbp), %rdi movq -0x18(%rbp), %rsi movq -0x20(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp _OFMethodNotFound_stret init: leaq module(%rip), %rdi jmp ___objc_exec_class .section __DATA, __mod_init_func, mod_init_funcs .quad init .section __TEXT, __cstring, cstring_literals str_forwardingTargetForSelector_: |
︙ | ︙ |
Modified src/forwarding/forwarding-x86_64-win64.S from [c7e60b4820] to [b8c0737017].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | | | | | | | | | | | | | | | | | | | | | | | | | > > < < | | | | | | | | | | | | | | | < > | | | | | | | | > > > > | | | | | | | | | | | | | | > | < | | | | | | | | | | | | | | | | | | | | | | | | | > | > < < | | | | | | | | > > > > | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl OFForward .globl OFForward_stret .section .text OFForward: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0x90, %rsp /* 16-byte alignment */ movq %rax, -0x28(%rbp) movq %rcx, -0x30(%rbp) movq %rdx, -0x38(%rbp) movq %r8, -0x40(%rbp) movq %r9, -0x48(%rbp) movaps %xmm0, -0x60(%rbp) movaps %xmm1, -0x70(%rbp) movaps %xmm2, -0x80(%rbp) movaps %xmm3, -0x90(%rbp) call object_getClass movq %rax, %rcx leaq sel_forwardingTargetForSelector_(%rip), %rdx call class_respondsToSelector testq %rax, %rax jz 0f movq -0x30(%rbp), %rcx leaq sel_forwardingTargetForSelector_(%rip), %rdx call objc_msg_lookup movq -0x30(%rbp), %rcx leaq sel_forwardingTargetForSelector_(%rip), %rdx movq -0x38(%rbp), %r8 call *%rax testq %rax, %rax jz 0f cmpq -0x30(%rbp), %rax je 0f movq %rax, -0x30(%rbp) movq %rax, %rcx movq -0x38(%rbp), %rdx call objc_msg_lookup movq %rax, %r11 /* Restore all arguments */ movaps -0x90(%rbp), %xmm3 movaps -0x80(%rbp), %xmm2 movaps -0x70(%rbp), %xmm1 movaps -0x60(%rbp), %xmm0 movq -0x48(%rbp), %r9 movq -0x40(%rbp), %r8 movq -0x38(%rbp), %rdx movq -0x30(%rbp), %rcx movq -0x28(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x30(%rbp), %rcx movq -0x38(%rbp), %rdx movq %rbp, %rsp popq %rbp jmp OFMethodNotFound .def OFForward .scl 2 .type 32 .endef OFForward_stret: pushq %rbp movq %rsp, %rbp /* Save all arguments */ subq $0x90, %rsp /* 16-byte alignment */ movq %rax, -0x28(%rbp) movq %rcx, -0x30(%rbp) movq %rdx, -0x38(%rbp) movq %r8, -0x40(%rbp) movq %r9, -0x48(%rbp) movaps %xmm0, -0x60(%rbp) movaps %xmm1, -0x70(%rbp) movaps %xmm2, -0x80(%rbp) movaps %xmm3, -0x90(%rbp) movq %rdx, %rcx call object_getClass movq %rax, %rcx leaq sel_forwardingTargetForSelector_(%rip), %rdx call class_respondsToSelector testq %rax, %rax jz 0f movq -0x38(%rbp), %rcx leaq sel_forwardingTargetForSelector_(%rip), %rdx call objc_msg_lookup movq -0x38(%rbp), %rcx leaq sel_forwardingTargetForSelector_(%rip), %rdx movq -0x40(%rbp), %r8 call *%rax testq %rax, %rax jz 0f cmpq -0x38(%rbp), %rax je 0f movq %rax, -0x38(%rbp) movq %rax, %rcx movq -0x40(%rbp), %rdx call objc_msg_lookup_stret movq %rax, %r11 /* Restore all arguments */ movaps -0x90(%rbp), %xmm3 movaps -0x80(%rbp), %xmm2 movaps -0x70(%rbp), %xmm1 movaps -0x60(%rbp), %xmm0 movq -0x48(%rbp), %r9 movq -0x40(%rbp), %r8 movq -0x38(%rbp), %rdx movq -0x30(%rbp), %rcx movq -0x28(%rbp), %rax movq %rbp, %rsp popq %rbp jmpq *%r11 0: movq -0x30(%rbp), %rcx movq -0x38(%rbp), %rdx movq -0x40(%rbp), %r8 movq %rbp, %rsp popq %rbp jmp OFMethodNotFound_stret .def OFForward_stret .scl 2 .type 32 .endef init: leaq module(%rip), %rcx jmp __objc_exec_class .section .ctors, "aw" .quad init .section .rodata str_forwardingTargetForSelector_: |
︙ | ︙ |
Deleted src/invocation/Makefile version [b7f33f0f15].
|
| < < < < < < < < < < < < < |
Deleted src/invocation/apple-call-x86_64.S version [11cbf74197].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/invocation/call-x86_64-elf.S version [d7ef9dafa4].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/invocation/call.S version [c8172ab4a1].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/invocation/invoke-x86_64.h version [0f6289615c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/invocation/invoke-x86_64.m version [e0c747a83e].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/invocation/invoke.m version [09adc50790].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/library.xml from [8a66b6f69a] to [25b5953f80].
1 2 3 | <amiga-library version='1.0' base='ObjFWBase'> <include>amiga-library.h</include> <!-- The following function is only for the linklib. --> | | | | | | > > > | > > > > > > | | | | | > > > > > > > > > > > > > > > > > > > > < | | | | < | | | | | | < | | < < < > | < | | | < < < < | | | > | | < < < < < < < < < | < | | | | | | | < < < < < < < < < < | | | < | < | | | | | | | | < | | < | | | | < | | | | | | > > > > > > > > | > > > | > > > | > > > > | | | | > > | > > | | 1 2 3 4 5 6 7 8 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | <amiga-library version='1.0' base='ObjFWBase'> <include>amiga-library.h</include> <!-- The following function is only for the linklib. --> <function name='OFInit' return-type='bool'> <argument name='version' type='unsigned int' m68k-reg='d0'/> <argument name='libc' type='struct OFLibC *_Nonnull' m68k-reg='a0'/> <argument name='sF' type='FILE *_Nonnull *_Nonnull' m68k-reg='a1'/> </function> <include>OFObject.h</include> <function name='OFAllocMemory' return-type='void *_Nullable'> <argument name='count' type='size_t' m68k-reg='d0'/> <argument name='size' type='size_t' m68k-reg='d1'/> </function> <function name='OFAllocZeroedMemory' return-type='void *_Nullable'> <argument name='count' type='size_t' m68k-reg='d0'/> <argument name='size' type='size_t' m68k-reg='d1'/> </function> <function name='OFResizeMemory' return-type='void *_Nullable'> <argument name='pointer' type='void *_Nullable' m68k-reg='a0'/> <argument name='count' type='size_t' m68k-reg='d0'/> <argument name='size' type='size_t' m68k-reg='d1'/> </function> <function name='OFFreeMemory'> <argument name='pointer' type='void *_Nullable' m68k-reg='a0'/> </function> <function name='OFHashInit'> <argument name='hash' type='unsigned long *_Nonnull' m68k-reg='a0'/> </function> <function name='OFRandom16' return-type='uint16_t'/> <function name='OFRandom32' return-type='uint32_t'/> <function name='OFRandom64' return-type='uint64_t'/> <function name='OFHashSeedRef' return-type='unsigned long *_Nonnull'/> <include>OFStdIOStream.h</include> <function name='OFStdInRef' return-type='OFStdIOStream *_Nonnull *_Nullable'/> <function name='OFStdOutRef' return-type='OFStdIOStream *_Nonnull *_Nullable'/> <function name='OFStdErrRef' return-type='OFStdIOStream *_Nonnull *_Nullable'/> <function name='OFLogV'> <argument name='format' type='OFConstantString *' m68k-reg='a0'/> <argument name='arguments' type='va_list' m68k-reg='a1'/> </function> <include>OFApplication.h</include> <function name='OFApplicationMain' return-type='int'> <argument name='argc' type='int *_Nonnull' m68k-reg='a0'/> <argument name='argv' type='char *_Nullable *_Nonnull *_Nonnull' m68k-reg='a1'/> <argument name='delegate' type='id <OFApplicationDelegate>' m68k-reg='a2'/> </function> <include>OFBlock.h</include> <function name='_Block_copy' return-type='void *_Nullable'> <argument name='block' type='const void *_Nullable' m68k-reg='a0'/> </function> <function name='_Block_release'> <argument name='block' type='const void *_Nullable' m68k-reg='a0'/> </function> <include>OFDNSResourceRecord.h</include> <function name='OFDNSClassName' return-type='OFString *_Nonnull'> <argument name='DNSClass' type='OFDNSClass' m68k-reg='d0'/> </function> <function name='OFDNSRecordTypeName' return-type='OFString *_Nonnull'> <argument name='recordType' type='OFDNSRecordType' m68k-reg='d0'/> </function> <function name='OFDNSClassParseName' return-type='OFDNSClass'> <argument name='string' type='OFString *_Nonnull' m68k-reg='a0'/> </function> <function name='OFDNSRecordTypeParseName' return-type='OFDNSRecordType'> <argument name='string' type='OFString *_Nonnull' m68k-reg='a0'/> </function> <include>OFHTTPRequest.h</include> <function name='OFHTTPRequestMethodName' return-type='const char *_Nullable'> <argument name='method' type='OFHTTPRequestMethod' m68k-reg='d0'/> </function> <function name='OFHTTPRequestMethodParseName' return-type='OFHTTPRequestMethod'> <argument name='string' type='OFString *' m68k-reg='a0'/> </function> <include>OFHTTPResponse.h</include> <function name='OFHTTPStatusCodeString' return-type='OFString *_Nonnull'> <argument name='code' type='short' m68k-reg='d0'/> </function> <include>OFList.h</include> <function name='OFListItemNext' return-type='OFListItem _Nullable'> <argument name='listItem' type='OFListItem _Nonnull' m68k-reg='a0'/> </function> <function name='OFListItemPrevious' return-type='OFListItem _Nullable'> <argument name='listItem' type='OFListItem _Nonnull' m68k-reg='a0'/> </function> <function name='OFListItemObject' return-type='id _Nonnull'> <argument name='listItem' type='OFListItem _Nonnull' m68k-reg='a0'/> </function> <include>OFMethodSignature.h</include> <function name='OFSizeOfTypeEncoding' return-type='size_t'> <argument name='type' type='const char *' m68k-reg='a0'/> </function> <function name='OFAlignmentOfTypeEncoding' return-type='size_t'> <argument name='type' type='const char *' m68k-reg='a0'/> </function> <include>OFOnce.h</include> <function name='OFOnce'> <argument name='control' type='OFOnceControl *_Nonnull' m68k-arg='a0'/> <argument name='func' type='OFOnceFunction _Nonnull' m68k-arg='a1'/> </function> <include>OFPBKDF2.h</include> <function name='OFPBKDF2'> <argument name='parameters' type='OFPBKDF2Parameters' m68k-reg='a0'/> </function> <include>OFScrypt.h</include> <function name='OFScrypt'> <argument name='parameters' type='OFScryptParameters' m68k-reg='a0'/> </function> <!-- The following scrypt functions are only for tests. --> <function name='OFSalsa20_8Core'> <argument name='buffer' type='uint32_t *_Nonnull' m68k-reg='a0'/> </function> <function name='OFScryptBlockMix'> <argument name='output' type='uint32_t *_Nonnull' m68k-reg='a0'/> <argument name='input' type='const uint32_t *_Nonnull' m68k-reg='a1'/> <argument name='blockSize' type='size_t' m68k-reg='d0'/> </function> <function name='OFScryptROMix'> <argument name='buffer' type='uint32_t *' m68k-reg='a0'/> <argument name='blockSize' type='size_t' m68k-reg='d0'/> <argument name='costFactor' type='size_t' m68k-reg='d1'/> <argument name='tmp' type='uint32_t *' m68k-reg='a1'/> </function> <include>OFSocket.h</include> <function name='OFSocketAddressParseIP' return-type='OFSocketAddress'> <argument name='IP' type='OFString *' m68k-reg='a0'/> <argument name='port' type='uint16_t' m68k-reg='d0'/> </function> <function name='OFSocketAddressParseIPv4' return-type='OFSocketAddress'> <argument name='IP' type='OFString *' m68k-reg='a0'/> <argument name='port' type='uint16_t' m68k-reg='d0'/> </function> <function name='OFSocketAddressParseIPv6' return-type='OFSocketAddress'> <argument name='IP' type='OFString *' m68k-reg='a0'/> <argument name='port' type='uint16_t' m68k-reg='d0'/> </function> <function name='OFSocketAddressMakeIPX' return-type='OFSocketAddress'> <argument name='node' type='const unsigned char *_Nonnull' m68k-reg='a0'/> <argument name='network' type='uint32_t' m68k-reg='d0'/> <argument name='port' type='uint16_t' m68k-reg='d1'/> </function> <function name='OFSocketAddressEqual' return-type='bool'> <argument name='address1' type='const OFSocketAddress *_Nonnull' m68k-reg='a0'/> <argument name='address2' type='const OFSocketAddress *_Nonnull' m68k-reg='a1'/> </function> <function name='OFSocketAddressHash' return-type='unsigned long'> <argument name='address' type='const OFSocketAddress *_Nonnull' m68k-reg='a0'/> </function> <function name='OFSocketAddressString' return-type='OFString *_Nonnull'> <argument name='address' type='const OFSocketAddress *_Nonnull' m68k-reg='a0'/> </function> <function name='OFSocketAddressSetPort'> <argument name='address' type='OFSocketAddress *_Nonnull' m68k-reg='a0'/> <argument name='port' type='uint16_t' m68k-reg='d0'/> </function> <function name='OFSocketAddressPort' return-type='uint16_t'> <argument name='address' type='const OFSocketAddress *_Nonnull' m68k-reg='a0'/> </function> <function name='OFSocketAddressSetIPXNetwork'> <argument name='address' type='OFSocketAddress *_Nonnull' m68k-reg='a0'/> <argument name='network' type='uint32_t' m68k-reg='d0'/> </function> <function name='OFSocketAddressIPXNetwork' return-type='uint32_t'> <argument name='address' type='const OFSocketAddress *_Nonnull' m68k-reg='a0'/> </function> <function name='OFSocketAddressSetIPXNode'> <argument name='address' type='OFSocketAddress *_Nonnull' m68k-reg='a0'/> <argument name='node' type='const unsigned char *_Nonnull' m68k-reg='a1'/> </function> <function name='OFSocketAddressIPXNode'> <argument name='address' type='const OFSocketAddress *_Nonnull' m68k-reg='a0'/> <argument name='node' type='unsigned char *_Nonnull' m68k-reg='a1'/> </function> <!-- Only for tests. --> <include>OFStrPTime.h</include> <function name='OFStrPTime' return-type='const char *_Nullable'> <argument name='buffer' type='const char *' m68k-reg='a0'/> <argument name='format' type='const char *' m68k-reg='a1'/> <argument name='tm' type='struct tm *' m68k-reg='a2'/> <argument name='tz' type='int16_t *_Nullable' m68k-reg='a3'/> </function> <include>OFString.h</include> <function name='OFStringEncodingParseName' return-type='OFStringEncoding'> <argument name='string' type='OFString *' m68k-reg='a0'/> </function> <function name='OFStringEncodingName' return-type='OFString *_Nullable'> <argument name='encoding' type='OFStringEncoding' m68k-reg='d0'/> </function> <function name='OFUTF16StringLength' return-type='size_t'> <argument name='string' type='const OFChar16 *' m68k-reg='a0'/> </function> <function name='OFUTF32StringLength' return-type='size_t'> <argument name='string' type='const OFChar32 *' m68k-reg='a0'/> </function> <include>OFZIPArchiveEntry.h</include> <function name='OFZIPArchiveEntryVersionToString' return-type='OFString *_Nonnull'> <argument name='version' type='uint16_t' m68k-reg='d0'/> </function> <function name='OFZIPArchiveEntryCompressionMethodName' return-type='OFString *_Nonnull'> <argument name='compressionMethod' type='OFZIPArchiveEntryCompressionMethod' m68k-reg='d0'/> </function> <function name='OFZIPArchiveEntryExtraFieldFind' return-type='size_t'> <argument name='extraField' type='OFData *' m68k-reg='a0'/> <argument name='tag' type='OFZIPArchiveEntryExtraFieldTag' m68k-reg='d0'/> <argument name='size' type='uint16_t *' m68k-reg='a1'/> </function> </amiga-library> |
Modified src/linklib/init.m from [1b5f3bd0d7] to [911e384ae6].
︙ | ︙ | |||
297 298 299 300 301 302 303 | CloseLibrary(IntuitionBase); } exit(EXIT_FAILURE); } static int * | | | | 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | CloseLibrary(IntuitionBase); } exit(EXIT_FAILURE); } static int * errNo(void) { return &errno; } static void __attribute__((__used__)) ctor(void) { static bool initialized = false; struct OFLibC libC = { .malloc = malloc, .calloc = calloc, .realloc = realloc, .free = free, .vfprintf = vfprintf, .fflush = fflush, .abort = abort, |
︙ | ︙ | |||
342 343 344 345 346 347 348 | .__register_frame_info = __register_frame_info, .__deregister_frame_info = __deregister_frame_info, #endif #ifdef OF_MORPHOS .__register_frame = __register_frame, .__deregister_frame = __deregister_frame, #endif | | | | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | .__register_frame_info = __register_frame_info, .__deregister_frame_info = __deregister_frame_info, #endif #ifdef OF_MORPHOS .__register_frame = __register_frame, .__deregister_frame = __deregister_frame, #endif .errNo = errNo, .vsnprintf = vsnprintf, #ifdef OF_AMIGAOS_M68K .vsscanf = vsscanf, #endif .exit = exit, .atexit = atexit, .signal = signal, .setlocale = setlocale, ._Unwind_Backtrace = _Unwind_Backtrace }; if (initialized) return; if ((ObjFWBase = OpenLibrary(OBJFW_AMIGA_LIB, OBJFW_LIB_MINOR)) == NULL) error("Failed to open " OBJFW_AMIGA_LIB " version %lu!", OBJFW_LIB_MINOR); if (!OFInit(1, &libC, __sF)) error("Failed to initialize " OBJFW_AMIGA_LIB "!", 0); initialized = true; } static void __attribute__((__used__)) dtor(void) |
︙ | ︙ |
Modified src/linklib/linklib.m from [b7fdb6530f] to [cf788a72bc].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 | #include "config.h" #import "amiga-library.h" #import "OFObject.h" #import "OFStdIOStream.h" #import "OFApplication.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFMethodSignature.h" | > > > | | | | | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > | > > > | > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | | | | < < < < < < | < < < < < < < < < < < | < < < < < < < < < < < < | < < < | < < | < < < | < < < < < < < < < < < < < < < < < < < < < < < < < | < < < | < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < | < < < < < < < < < | < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 | #include "config.h" #import "amiga-library.h" #import "OFObject.h" #import "OFStdIOStream.h" #import "OFApplication.h" #import "OFBlock.h" #import "OFDNSResourceRecord.h" #import "OFHTTPRequest.h" #import "OFHTTPResponse.h" #import "OFList.h" #import "OFMethodSignature.h" #import "OFOnce.h" #import "OFPBKDF2.h" #import "OFScrypt.h" #import "OFSocket.h" #import "OFStrPTime.h" #import "OFString.h" #import "OFZIPArchiveEntry.h" extern struct Library *ObjFWBase; bool OFInit(unsigned int version, struct OFLibC *_Nonnull libc, FILE *_Nonnull *_Nonnull sF) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((bool (*)(unsigned int __asm__("d0"), struct OFLibC *_Nonnull __asm__("a0"), FILE *_Nonnull *_Nonnull __asm__("a1")))(((uintptr_t)ObjFWBase) - 30))(version, libc, sF); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((bool (*)(unsigned int, struct OFLibC *_Nonnull, FILE *_Nonnull *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 28))(version, libc, sF); #endif } void *_Nullable OFAllocMemory(size_t count, size_t size) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((void *_Nullable (*)(size_t __asm__("d0"), size_t __asm__("d1")))(((uintptr_t)ObjFWBase) - 36))(count, size); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((void *_Nullable (*)(size_t, size_t))*(void **)(((uintptr_t)ObjFWBase) - 34))(count, size); #endif } void *_Nullable OFAllocZeroedMemory(size_t count, size_t size) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((void *_Nullable (*)(size_t __asm__("d0"), size_t __asm__("d1")))(((uintptr_t)ObjFWBase) - 42))(count, size); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((void *_Nullable (*)(size_t, size_t))*(void **)(((uintptr_t)ObjFWBase) - 40))(count, size); #endif } void *_Nullable OFResizeMemory(void *_Nullable pointer, size_t count, size_t size) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((void *_Nullable (*)(void *_Nullable __asm__("a0"), size_t __asm__("d0"), size_t __asm__("d1")))(((uintptr_t)ObjFWBase) - 48))(pointer, count, size); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((void *_Nullable (*)(void *_Nullable, size_t, size_t))*(void **)(((uintptr_t)ObjFWBase) - 46))(pointer, count, size); #endif } void OFFreeMemory(void *_Nullable pointer) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(void *_Nullable __asm__("a0")))(((uintptr_t)ObjFWBase) - 54))(pointer); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(void *_Nullable))*(void **)(((uintptr_t)ObjFWBase) - 52))(pointer); #endif } void OFHashInit(unsigned long *_Nonnull hash) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(unsigned long *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 60))(hash); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(unsigned long *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 58))(hash); #endif } uint16_t OFRandom16() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((uint16_t (*)())(((uintptr_t)ObjFWBase) - 66))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((uint16_t (*)())*(void **)(((uintptr_t)ObjFWBase) - 64))(); #endif } uint32_t OFRandom32() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((uint32_t (*)())(((uintptr_t)ObjFWBase) - 72))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((uint32_t (*)())*(void **)(((uintptr_t)ObjFWBase) - 70))(); #endif } uint64_t OFRandom64() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((uint64_t (*)())(((uintptr_t)ObjFWBase) - 78))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((uint64_t (*)())*(void **)(((uintptr_t)ObjFWBase) - 76))(); #endif } unsigned long *_Nonnull OFHashSeedRef() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((unsigned long *_Nonnull (*)())(((uintptr_t)ObjFWBase) - 84))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((unsigned long *_Nonnull (*)())*(void **)(((uintptr_t)ObjFWBase) - 82))(); #endif } OFStdIOStream *_Nonnull *_Nullable OFStdInRef() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFStdIOStream *_Nonnull *_Nullable (*)())(((uintptr_t)ObjFWBase) - 90))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFStdIOStream *_Nonnull *_Nullable (*)())*(void **)(((uintptr_t)ObjFWBase) - 88))(); #endif } OFStdIOStream *_Nonnull *_Nullable OFStdOutRef() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFStdIOStream *_Nonnull *_Nullable (*)())(((uintptr_t)ObjFWBase) - 96))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFStdIOStream *_Nonnull *_Nullable (*)())*(void **)(((uintptr_t)ObjFWBase) - 94))(); #endif } OFStdIOStream *_Nonnull *_Nullable OFStdErrRef() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFStdIOStream *_Nonnull *_Nullable (*)())(((uintptr_t)ObjFWBase) - 102))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFStdIOStream *_Nonnull *_Nullable (*)())*(void **)(((uintptr_t)ObjFWBase) - 100))(); #endif } void OFLogV(OFConstantString *format, va_list arguments) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(OFConstantString *__asm__("a0"), va_list __asm__("a1")))(((uintptr_t)ObjFWBase) - 108))(format, arguments); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(OFConstantString *, va_list))*(void **)(((uintptr_t)ObjFWBase) - 106))(format, arguments); #endif } int OFApplicationMain(int *_Nonnull argc, char *_Nullable *_Nonnull *_Nonnull argv, id <OFApplicationDelegate> delegate) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((int (*)(int *_Nonnull __asm__("a0"), char *_Nullable *_Nonnull *_Nonnull __asm__("a1"), id <OFApplicationDelegate> __asm__("a2")))(((uintptr_t)ObjFWBase) - 114))(argc, argv, delegate); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((int (*)(int *_Nonnull, char *_Nullable *_Nonnull *_Nonnull, id <OFApplicationDelegate>))*(void **)(((uintptr_t)ObjFWBase) - 112))(argc, argv, delegate); #endif } void *_Nullable _Block_copy(const void *_Nullable block) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((void *_Nullable (*)(const void *_Nullable __asm__("a0")))(((uintptr_t)ObjFWBase) - 120))(block); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((void *_Nullable (*)(const void *_Nullable))*(void **)(((uintptr_t)ObjFWBase) - 118))(block); #endif } void _Block_release(const void *_Nullable block) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(const void *_Nullable __asm__("a0")))(((uintptr_t)ObjFWBase) - 126))(block); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(const void *_Nullable))*(void **)(((uintptr_t)ObjFWBase) - 124))(block); #endif } OFString *_Nonnull OFDNSClassName(OFDNSClass DNSClass) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFString *_Nonnull (*)(OFDNSClass __asm__("d0")))(((uintptr_t)ObjFWBase) - 132))(DNSClass); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFString *_Nonnull (*)(OFDNSClass))*(void **)(((uintptr_t)ObjFWBase) - 130))(DNSClass); #endif } OFString *_Nonnull OFDNSRecordTypeName(OFDNSRecordType recordType) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFString *_Nonnull (*)(OFDNSRecordType __asm__("d0")))(((uintptr_t)ObjFWBase) - 138))(recordType); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFString *_Nonnull (*)(OFDNSRecordType))*(void **)(((uintptr_t)ObjFWBase) - 136))(recordType); #endif } OFDNSClass OFDNSClassParseName(OFString *_Nonnull string) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFDNSClass (*)(OFString *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 144))(string); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFDNSClass (*)(OFString *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 142))(string); #endif } OFDNSRecordType OFDNSRecordTypeParseName(OFString *_Nonnull string) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFDNSRecordType (*)(OFString *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 150))(string); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFDNSRecordType (*)(OFString *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 148))(string); #endif } const char *_Nullable OFHTTPRequestMethodName(OFHTTPRequestMethod method) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((const char *_Nullable (*)(OFHTTPRequestMethod __asm__("d0")))(((uintptr_t)ObjFWBase) - 156))(method); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((const char *_Nullable (*)(OFHTTPRequestMethod))*(void **)(((uintptr_t)ObjFWBase) - 154))(method); #endif } OFHTTPRequestMethod OFHTTPRequestMethodParseName(OFString *string) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFHTTPRequestMethod (*)(OFString *__asm__("a0")))(((uintptr_t)ObjFWBase) - 162))(string); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFHTTPRequestMethod (*)(OFString *))*(void **)(((uintptr_t)ObjFWBase) - 160))(string); #endif } OFString *_Nonnull OFHTTPStatusCodeString(short code) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFString *_Nonnull (*)(short __asm__("d0")))(((uintptr_t)ObjFWBase) - 168))(code); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFString *_Nonnull (*)(short))*(void **)(((uintptr_t)ObjFWBase) - 166))(code); #endif } OFListItem _Nullable OFListItemNext(OFListItem _Nonnull listItem) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFListItem _Nullable (*)(OFListItem _Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 174))(listItem); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFListItem _Nullable (*)(OFListItem _Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 172))(listItem); #endif } OFListItem _Nullable OFListItemPrevious(OFListItem _Nonnull listItem) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFListItem _Nullable (*)(OFListItem _Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 180))(listItem); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFListItem _Nullable (*)(OFListItem _Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 178))(listItem); #endif } id _Nonnull OFListItemObject(OFListItem _Nonnull listItem) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((id _Nonnull (*)(OFListItem _Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 186))(listItem); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((id _Nonnull (*)(OFListItem _Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 184))(listItem); #endif } size_t OFSizeOfTypeEncoding(const char *type) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((size_t (*)(const char *__asm__("a0")))(((uintptr_t)ObjFWBase) - 192))(type); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((size_t (*)(const char *))*(void **)(((uintptr_t)ObjFWBase) - 190))(type); #endif } size_t OFAlignmentOfTypeEncoding(const char *type) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((size_t (*)(const char *__asm__("a0")))(((uintptr_t)ObjFWBase) - 198))(type); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((size_t (*)(const char *))*(void **)(((uintptr_t)ObjFWBase) - 196))(type); #endif } void OFOnce(OFOnceControl *_Nonnull control, OFOnceFunction _Nonnull func) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(OFOnceControl *_Nonnull __asm__("(nil)"), OFOnceFunction _Nonnull __asm__("(nil)")))(((uintptr_t)ObjFWBase) - 204))(control, func); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(OFOnceControl *_Nonnull, OFOnceFunction _Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 202))(control, func); #endif } void OFPBKDF2(OFPBKDF2Parameters parameters) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(OFPBKDF2Parameters __asm__("a0")))(((uintptr_t)ObjFWBase) - 210))(parameters); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(OFPBKDF2Parameters))*(void **)(((uintptr_t)ObjFWBase) - 208))(parameters); #endif } void OFScrypt(OFScryptParameters parameters) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(OFScryptParameters __asm__("a0")))(((uintptr_t)ObjFWBase) - 216))(parameters); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(OFScryptParameters))*(void **)(((uintptr_t)ObjFWBase) - 214))(parameters); #endif } void OFSalsa20_8Core(uint32_t *_Nonnull buffer) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(uint32_t *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 222))(buffer); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(uint32_t *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 220))(buffer); #endif } void OFScryptBlockMix(uint32_t *_Nonnull output, const uint32_t *_Nonnull input, size_t blockSize) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(uint32_t *_Nonnull __asm__("a0"), const uint32_t *_Nonnull __asm__("a1"), size_t __asm__("d0")))(((uintptr_t)ObjFWBase) - 228))(output, input, blockSize); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(uint32_t *_Nonnull, const uint32_t *_Nonnull, size_t))*(void **)(((uintptr_t)ObjFWBase) - 226))(output, input, blockSize); #endif } void OFScryptROMix(uint32_t *buffer, size_t blockSize, size_t costFactor, uint32_t *tmp) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(uint32_t *__asm__("a0"), size_t __asm__("d0"), size_t __asm__("d1"), uint32_t *__asm__("a1")))(((uintptr_t)ObjFWBase) - 234))(buffer, blockSize, costFactor, tmp); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(uint32_t *, size_t, size_t, uint32_t *))*(void **)(((uintptr_t)ObjFWBase) - 232))(buffer, blockSize, costFactor, tmp); #endif } OFSocketAddress OFSocketAddressParseIP(OFString *IP, uint16_t port) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFSocketAddress (*)(OFString *__asm__("a0"), uint16_t __asm__("d0")))(((uintptr_t)ObjFWBase) - 240))(IP, port); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFSocketAddress (*)(OFString *, uint16_t))*(void **)(((uintptr_t)ObjFWBase) - 238))(IP, port); #endif } OFSocketAddress OFSocketAddressParseIPv4(OFString *IP, uint16_t port) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFSocketAddress (*)(OFString *__asm__("a0"), uint16_t __asm__("d0")))(((uintptr_t)ObjFWBase) - 246))(IP, port); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFSocketAddress (*)(OFString *, uint16_t))*(void **)(((uintptr_t)ObjFWBase) - 244))(IP, port); #endif } OFSocketAddress OFSocketAddressParseIPv6(OFString *IP, uint16_t port) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFSocketAddress (*)(OFString *__asm__("a0"), uint16_t __asm__("d0")))(((uintptr_t)ObjFWBase) - 252))(IP, port); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFSocketAddress (*)(OFString *, uint16_t))*(void **)(((uintptr_t)ObjFWBase) - 250))(IP, port); #endif } OFSocketAddress OFSocketAddressMakeIPX(const unsigned char *_Nonnull node, uint32_t network, uint16_t port) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFSocketAddress (*)(const unsigned char *_Nonnull __asm__("a0"), uint32_t __asm__("d0"), uint16_t __asm__("d1")))(((uintptr_t)ObjFWBase) - 258))(node, network, port); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFSocketAddress (*)(const unsigned char *_Nonnull, uint32_t, uint16_t))*(void **)(((uintptr_t)ObjFWBase) - 256))(node, network, port); #endif } bool OFSocketAddressEqual(const OFSocketAddress *_Nonnull address1, const OFSocketAddress *_Nonnull address2) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((bool (*)(const OFSocketAddress *_Nonnull __asm__("a0"), const OFSocketAddress *_Nonnull __asm__("a1")))(((uintptr_t)ObjFWBase) - 264))(address1, address2); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((bool (*)(const OFSocketAddress *_Nonnull, const OFSocketAddress *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 262))(address1, address2); #endif } unsigned long OFSocketAddressHash(const OFSocketAddress *_Nonnull address) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((unsigned long (*)(const OFSocketAddress *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 270))(address); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((unsigned long (*)(const OFSocketAddress *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 268))(address); #endif } OFString *_Nonnull OFSocketAddressString(const OFSocketAddress *_Nonnull address) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFString *_Nonnull (*)(const OFSocketAddress *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 276))(address); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFString *_Nonnull (*)(const OFSocketAddress *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 274))(address); #endif } void OFSocketAddressSetPort(OFSocketAddress *_Nonnull address, uint16_t port) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(OFSocketAddress *_Nonnull __asm__("a0"), uint16_t __asm__("d0")))(((uintptr_t)ObjFWBase) - 282))(address, port); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(OFSocketAddress *_Nonnull, uint16_t))*(void **)(((uintptr_t)ObjFWBase) - 280))(address, port); #endif } uint16_t OFSocketAddressPort(const OFSocketAddress *_Nonnull address) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((uint16_t (*)(const OFSocketAddress *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 288))(address); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((uint16_t (*)(const OFSocketAddress *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 286))(address); #endif } void OFSocketAddressSetIPXNetwork(OFSocketAddress *_Nonnull address, uint32_t network) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(OFSocketAddress *_Nonnull __asm__("a0"), uint32_t __asm__("d0")))(((uintptr_t)ObjFWBase) - 294))(address, network); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(OFSocketAddress *_Nonnull, uint32_t))*(void **)(((uintptr_t)ObjFWBase) - 292))(address, network); #endif } uint32_t OFSocketAddressIPXNetwork(const OFSocketAddress *_Nonnull address) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((uint32_t (*)(const OFSocketAddress *_Nonnull __asm__("a0")))(((uintptr_t)ObjFWBase) - 300))(address); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((uint32_t (*)(const OFSocketAddress *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 298))(address); #endif } void OFSocketAddressSetIPXNode(OFSocketAddress *_Nonnull address, const unsigned char *_Nonnull node) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(OFSocketAddress *_Nonnull __asm__("a0"), const unsigned char *_Nonnull __asm__("a1")))(((uintptr_t)ObjFWBase) - 306))(address, node); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(OFSocketAddress *_Nonnull, const unsigned char *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 304))(address, node); #endif } void OFSocketAddressIPXNode(const OFSocketAddress *_Nonnull address, unsigned char *_Nonnull node) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; ((void (*)(const OFSocketAddress *_Nonnull __asm__("a0"), unsigned char *_Nonnull __asm__("a1")))(((uintptr_t)ObjFWBase) - 312))(address, node); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); __extension__ ((void (*)(const OFSocketAddress *_Nonnull, unsigned char *_Nonnull))*(void **)(((uintptr_t)ObjFWBase) - 310))(address, node); #endif } const char *_Nullable OFStrPTime(const char *buffer, const char *format, struct tm *tm, int16_t *_Nullable tz) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((const char *_Nullable (*)(const char *__asm__("a0"), const char *__asm__("a1"), struct tm *__asm__("a2"), int16_t *_Nullable __asm__("a3")))(((uintptr_t)ObjFWBase) - 318))(buffer, format, tm, tz); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((const char *_Nullable (*)(const char *, const char *, struct tm *, int16_t *_Nullable))*(void **)(((uintptr_t)ObjFWBase) - 316))(buffer, format, tm, tz); #endif } OFStringEncoding OFStringEncodingParseName(OFString *string) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFStringEncoding (*)(OFString *__asm__("a0")))(((uintptr_t)ObjFWBase) - 324))(string); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFStringEncoding (*)(OFString *))*(void **)(((uintptr_t)ObjFWBase) - 322))(string); #endif } OFString *_Nullable OFStringEncodingName(OFStringEncoding encoding) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFString *_Nullable (*)(OFStringEncoding __asm__("d0")))(((uintptr_t)ObjFWBase) - 330))(encoding); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFString *_Nullable (*)(OFStringEncoding))*(void **)(((uintptr_t)ObjFWBase) - 328))(encoding); #endif } size_t OFUTF16StringLength(const OFChar16 *string) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((size_t (*)(const OFChar16 *__asm__("a0")))(((uintptr_t)ObjFWBase) - 336))(string); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((size_t (*)(const OFChar16 *))*(void **)(((uintptr_t)ObjFWBase) - 334))(string); #endif } size_t OFUTF32StringLength(const OFChar32 *string) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((size_t (*)(const OFChar32 *__asm__("a0")))(((uintptr_t)ObjFWBase) - 342))(string); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((size_t (*)(const OFChar32 *))*(void **)(((uintptr_t)ObjFWBase) - 340))(string); #endif } OFString *_Nonnull OFZIPArchiveEntryVersionToString(uint16_t version) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFString *_Nonnull (*)(uint16_t __asm__("d0")))(((uintptr_t)ObjFWBase) - 348))(version); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFString *_Nonnull (*)(uint16_t))*(void **)(((uintptr_t)ObjFWBase) - 346))(version); #endif } OFString *_Nonnull OFZIPArchiveEntryCompressionMethodName(OFZIPArchiveEntryCompressionMethod compressionMethod) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((OFString *_Nonnull (*)(OFZIPArchiveEntryCompressionMethod __asm__("d0")))(((uintptr_t)ObjFWBase) - 354))(compressionMethod); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((OFString *_Nonnull (*)(OFZIPArchiveEntryCompressionMethod))*(void **)(((uintptr_t)ObjFWBase) - 352))(compressionMethod); #endif } size_t OFZIPArchiveEntryExtraFieldFind(OFData *extraField, OFZIPArchiveEntryExtraFieldTag tag, uint16_t *size) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWBase; (void)a6; return ((size_t (*)(OFData *__asm__("a0"), OFZIPArchiveEntryExtraFieldTag __asm__("d0"), uint16_t *__asm__("a1")))(((uintptr_t)ObjFWBase) - 360))(extraField, tag, size); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWBase) : "r12" ); return __extension__ ((size_t (*)(OFData *, OFZIPArchiveEntryExtraFieldTag, uint16_t *))*(void **)(((uintptr_t)ObjFWBase) - 358))(extraField, tag, size); #endif } |
Modified src/macros.h from [9c93ab715b] to [e163f96b10].
︙ | ︙ | |||
98 99 100 101 102 103 104 | # define OF_LIKELY(cond) (cond) # define OF_UNLIKELY(cond) (cond) # define OF_CONST_FUNC # define OF_NO_RETURN_FUNC # define OF_WEAK_REF(sym) #endif | < < < < < < | 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | # define OF_LIKELY(cond) (cond) # define OF_UNLIKELY(cond) (cond) # define OF_CONST_FUNC # define OF_NO_RETURN_FUNC # define OF_WEAK_REF(sym) #endif #if __STDC_VERSION__ >= 201112L # define OF_ALIGNOF(type) _Alignof(type) # define OF_ALIGNAS(type) _Alignas(type) #else # define OF_ALIGNOF(type) __alignof__(type) # define OF_ALIGNAS(type) __attribute__((__aligned__(__alignof__(type)))) #endif |
︙ | ︙ | |||
320 321 322 323 324 325 326 | # define OF_DIRECT_MEMBERS __attribute__((__objc_direct_members__)) #else # define OF_DIRECT_MEMBERS #endif #ifdef OF_COMPILING_AMIGA_LIBRARY # undef errno | | | | 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | # define OF_DIRECT_MEMBERS __attribute__((__objc_direct_members__)) #else # define OF_DIRECT_MEMBERS #endif #ifdef OF_COMPILING_AMIGA_LIBRARY # undef errno extern int *_Nonnull OFErrNo(void); # define errno (*OFErrNo()) #endif #ifdef OF_APPLE_RUNTIME # if defined(OF_X86_64) || defined(OF_X86) || defined(OF_ARM64) || \ defined(OF_ARM) || defined(OF_POWERPC) # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET |
︙ | ︙ | |||
357 358 359 360 361 362 363 | # if __OBJFW_RUNTIME_ABI__ >= 800 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET # endif # endif # endif #endif | < | | | | | | | 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | # if __OBJFW_RUNTIME_ABI__ >= 800 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET # endif # endif # endif #endif #define OFMaxRetainCount UINT_MAX #ifdef OBJC_COMPILING_RUNTIME # define OFEnsure(cond) \ do { \ if OF_UNLIKELY (!(cond)) \ objc_error("ObjFWRT @ " __FILE__ ":" \ OF_STRINGIFY(__LINE__), \ "Failed to ensure condition:\n" #cond); \ } while(0) #else # define OFEnsure(cond) \ do { \ if OF_UNLIKELY (!(cond)) { \ fprintf(stderr, "Failed to ensure condition " \ "in " __FILE__ ":%d:\n" #cond "\n", \ __LINE__); \ abort(); \ } \ } while (0) #endif #define OF_UNRECOGNIZED_SELECTOR OFMethodNotFound(self, _cmd); #if __has_feature(objc_arc) # define OF_INVALID_INIT_METHOD OFMethodNotFound(self, _cmd); #else # define OF_INVALID_INIT_METHOD \ @try { \ OFMethodNotFound(self, _cmd); \ } @catch (id e) { \ [self release]; \ @throw e; \ } \ \ abort(); #endif |
︙ | ︙ | |||
420 421 422 423 424 425 426 | static void __attribute__((__constructor__(prio))) \ OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void) #define OF_DESTRUCTOR(prio) \ static void __attribute__((__destructor__(prio))) \ OF_PREPROCESSOR_CONCAT(destructor, __LINE__)(void) static OF_INLINE uint16_t OF_CONST_FUNC | | | | | | 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | static void __attribute__((__constructor__(prio))) \ OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void) #define OF_DESTRUCTOR(prio) \ static void __attribute__((__destructor__(prio))) \ OF_PREPROCESSOR_CONCAT(destructor, __LINE__)(void) static OF_INLINE uint16_t OF_CONST_FUNC OFByteSwap16Const(uint16_t i) { return (i & 0xFF00) >> 8 | (i & 0x00FF) << 8; } static OF_INLINE uint32_t OF_CONST_FUNC OFByteSwap32Const(uint32_t i) { return (i & 0xFF000000) >> 24 | (i & 0x00FF0000) >> 8 | (i & 0x0000FF00) << 8 | (i & 0x000000FF) << 24; } static OF_INLINE uint64_t OF_CONST_FUNC OFByteSwap64Const(uint64_t i) { return (i & 0xFF00000000000000) >> 56 | (i & 0x00FF000000000000) >> 40 | (i & 0x0000FF0000000000) >> 24 | (i & 0x000000FF00000000) >> 8 | (i & 0x00000000FF000000) << 8 | (i & 0x0000000000FF0000) << 24 | (i & 0x000000000000FF00) << 40 | (i & 0x00000000000000FF) << 56; } static OF_INLINE uint16_t OF_CONST_FUNC OFByteSwap16NonConst(uint16_t i) { #if defined(OF_HAVE_BUILTIN_BSWAP16) return __builtin_bswap16(i); #elif (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__) __asm__ ( "xchgb %h0, %b0" : "=Q"(i) |
︙ | ︙ | |||
472 473 474 475 476 477 478 | i = (i & UINT16_C(0xFF00)) >> 8 | (i & UINT16_C(0x00FF)) << 8; #endif return i; } static OF_INLINE uint32_t OF_CONST_FUNC | | | 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | i = (i & UINT16_C(0xFF00)) >> 8 | (i & UINT16_C(0x00FF)) << 8; #endif return i; } static OF_INLINE uint32_t OF_CONST_FUNC OFByteSwap32NonConst(uint32_t i) { #if defined(OF_HAVE_BUILTIN_BSWAP32) return __builtin_bswap32(i); #elif (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__) __asm__ ( "bswap %0" : "=q"(i) |
︙ | ︙ | |||
504 505 506 507 508 509 510 | (i & UINT32_C(0x0000FF00)) << 8 | (i & UINT32_C(0x000000FF)) << 24; #endif return i; } static OF_INLINE uint64_t OF_CONST_FUNC | | | | | | | | | | | | | | | | | | | | | | | | > > > | | | > > > > > > | | | > > > | | | | | > > | | > > > > | | > > | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | > | < < < < < < < < < < < < < < < < < < < < < < | | | < < < < < < < < < < < < < < | | | | | | | | | | 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 | (i & UINT32_C(0x0000FF00)) << 8 | (i & UINT32_C(0x000000FF)) << 24; #endif return i; } static OF_INLINE uint64_t OF_CONST_FUNC OFByteSwap64NonConst(uint64_t i) { #if defined(OF_HAVE_BUILTIN_BSWAP64) return __builtin_bswap64(i); #elif defined(OF_X86_64) && defined(__GNUC__) __asm__ ( "bswap %0" : "=r"(i) : "0"(i) ); #elif defined(OF_X86) && defined(__GNUC__) __asm__ ( "bswap %%eax\n\t" "bswap %%edx\n\t" "xchgl %%eax, %%edx" : "=A"(i) : "0"(i) ); #else i = (uint64_t)OFByteSwap32NonConst((uint32_t)(i & 0xFFFFFFFF)) << 32 | OFByteSwap32NonConst((uint32_t)(i >> 32)); #endif return i; } #ifdef __GNUC__ # define OFByteSwap16(i) \ (__builtin_constant_p(i) ? OFByteSwap16Const(i) : OFByteSwap16NonConst(i)) # define OFByteSwap32(i) \ (__builtin_constant_p(i) ? OFByteSwap32Const(i) : OFByteSwap32NonConst(i)) # define OFByteSwap64(i) \ (__builtin_constant_p(i) ? OFByteSwap64Const(i) : OFByteSwap64NonConst(i)) #else # define OFByteSwap16(i) OFByteSwap16Const(i) # define OFByteSwap32(i) OFByteSwap32Const(i) # define OFByteSwap64(i) OFByteSwap64Const(i) #endif static OF_INLINE uint32_t OFFloatToRawUInt32(float f) { uint32_t ret; memcpy(&ret, &f, 4); return ret; } static OF_INLINE float OFRawUInt32ToFloat(uint32_t uInt32) { float ret; memcpy(&ret, &uInt32, 4); return ret; } static OF_INLINE uint64_t OFDoubleToRawUInt64(double d) { uint64_t ret; memcpy(&ret, &d, 8); return ret; } static OF_INLINE double OFRawUInt64ToDouble(uint64_t uInt64) { double ret; memcpy(&ret, &uInt64, 8); return ret; } static OF_INLINE float OF_CONST_FUNC OFByteSwapFloat(float f) { return OFRawUInt32ToFloat(OFByteSwap32(OFFloatToRawUInt32(f))); } static OF_INLINE double OF_CONST_FUNC OFByteSwapDouble(double d) { return OFRawUInt64ToDouble(OFByteSwap64(OFDoubleToRawUInt64(d))); } #ifdef OF_BIG_ENDIAN # define OFFromBigEndian16(i) (i) # define OFFromBigEndian32(i) (i) # define OFFromBigEndian64(i) (i) # define OFFromLittleEndian16(i) OFByteSwap16(i) # define OFFromLittleEndian32(i) OFByteSwap32(i) # define OFFromLittleEndian64(i) OFByteSwap64(i) # define OFToBigEndian16(i) (i) # define OFToBigEndian32(i) (i) # define OFToBigEndian64(i) (i) # define OFToLittleEndian16(i) OFByteSwap16(i) # define OFToLittleEndian32(i) OFByteSwap32(i) # define OFToLittleEndian64(i) OFByteSwap64(i) #else # define OFFromBigEndian16(i) OFByteSwap16(i) # define OFFromBigEndian32(i) OFByteSwap32(i) # define OFFromBigEndian64(i) OFByteSwap64(i) # define OFFromLittleEndian16(i) (i) # define OFFromLittleEndian32(i) (i) # define OFFromLittleEndian64(i) (i) # define OFToBigEndian16(i) OFByteSwap16(i) # define OFToBigEndian32(i) OFByteSwap32(i) # define OFToBigEndian64(i) OFByteSwap64(i) # define OFToLittleEndian16(i) (i) # define OFToLittleEndian32(i) (i) # define OFToLittleEndian64(i) (i) #endif #ifdef OF_FLOAT_BIG_ENDIAN # define OFFromBigEndianFloat(f) (f) # define OFFromBigEndianDouble(d) (d) # define OFFromLittleEndianFloat(f) OFByteSwapFloat(f) # define OFFromLittleEndianDouble(d) OFByteSwapDouble(d) # define OFToBigEndianFloat(f) (f) # define OFToBigEndianDouble(d) (d) # define OFToLittleEndianFloat(f) OFByteSwapFloat(f) # define OFToLittleEndianDouble(d) OFByteSwapDouble(d) #else # define OFFromBigEndianFloat(f) OFByteSwapFloat(f) # define OFFromBigEndianDouble(d) OFByteSwapDouble(d) # define OFFromLittleEndianFloat(f) (f) # define OFFromLittleEndianDouble(d) (d) # define OFToBigEndianFloat(f) OFByteSwapFloat(f) # define OFToBigEndianDouble(d) OFByteSwapDouble(d) # define OFToLittleEndianFloat(f) (f) # define OFToLittleEndianDouble(d) (d) #endif #define OFRotateLeft(value, bits) \ (((bits) % (sizeof(value) * 8)) > 0 \ ? ((value) << ((bits) % (sizeof(value) * 8))) | \ ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \ : (value)) #define OFRotateRight(value, bits) \ (((bits) % (sizeof(value) * 8)) > 0 \ ? ((value) >> ((bits) % (sizeof(value) * 8))) | \ ((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \ : (value)) #define OFRoundUpToPowerOf2(pow2, value) \ (((value) + (pow2) - 1) & ~((pow2) - 1)) static OF_INLINE bool OFBitsetIsSet(unsigned char *_Nonnull storage, size_t idx) { return storage[idx / CHAR_BIT] & (1u << (idx % CHAR_BIT)); } static OF_INLINE void OFBitsetSet(unsigned char *_Nonnull storage, size_t idx) { storage[idx / CHAR_BIT] |= (1u << (idx % CHAR_BIT)); } static OF_INLINE void OFBitsetClear(unsigned char *_Nonnull storage, size_t idx) { storage[idx / CHAR_BIT] &= ~(1u << (idx % CHAR_BIT)); } static OF_INLINE void OFZeroMemory(void *_Nonnull buffer_, size_t length) { volatile unsigned char *buffer = (volatile unsigned char *)buffer_; while (buffer < (unsigned char *)buffer_ + length) *buffer++ = '\0'; } static OF_INLINE bool OFASCIIIsAlpha(char c) { return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); } static OF_INLINE bool OFASCIIIsDigit(char c) { return (c >= '0' && c <= '9'); } static OF_INLINE bool OFASCIIIsAlnum(char c) { return (OFASCIIIsAlpha(c) || OFASCIIIsDigit(c)); } static OF_INLINE bool OFASCIIIsSpace(char c) { return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v'); } static OF_INLINE char OFASCIIToUpper(char c) { return (c >= 'a' && c <= 'z' ? 'A' + (c - 'a') : c); } static OF_INLINE char OFASCIIToLower(char c) { return (c >= 'A' && c <= 'Z' ? 'a' + (c - 'A') : c); } #endif |
Modified src/module.modulemap from [46be0ed236] to [33c24fc753].
1 2 3 4 | framework module ObjFW { umbrella header "ObjFW.h" /* | | | | | | < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | framework module ObjFW { umbrella header "ObjFW.h" /* * These are included by OFAtomic.h, but should never be included * directly. */ exclude header "platform/GCC4/OFAtomic.h" exclude header "platform/GCC4.7/OFAtomic.h" exclude header "platform/PowerPC/OFAtomic.h" exclude header "platform/macOS/OFAtomic.h" exclude header "platform/x86/OFAtomic.h" export * } |
Deleted src/morphos-clib.h version [3f0a43908f].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/morphos.fd version [a8f469aa2a].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/objfw-defs.h.in from [cb58f5fac1] to [dc6785c3be].
︙ | ︙ | |||
12 13 14 15 16 17 18 | #undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR #undef OF_HAVE_IPV6 #undef OF_HAVE_IPX #undef OF_HAVE_LIMITS_H #undef OF_HAVE_LINK #undef OF_HAVE_MAX_ALIGN_T #undef OF_HAVE_NETINET_IN_H | < | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR #undef OF_HAVE_IPV6 #undef OF_HAVE_IPX #undef OF_HAVE_LIMITS_H #undef OF_HAVE_LINK #undef OF_HAVE_MAX_ALIGN_T #undef OF_HAVE_NETINET_IN_H #undef OF_HAVE_NETINET_TCP_H #undef OF_HAVE_NETIPX_IPX_H #undef OF_HAVE_OSATOMIC #undef OF_HAVE_OSATOMIC_64 #undef OF_HAVE_PIPE #undef OF_HAVE_PLEDGE #undef OF_HAVE_PLUGINS |
︙ | ︙ |
Modified src/platform.h from [0f756c2d58] to [d7b9159bac].
︙ | ︙ | |||
62 63 64 65 66 67 68 | #elif defined(__mips_eabi) && _MIPS_SZPTR == 32 # define OF_MIPS # define OF_MIPS_EABI #elif defined(__sparc64__) || (defined(__sparc__) && defined(__arch64__)) # define OF_SPARC64 #elif defined(__sparc__) && !defined(__arch64__) # define OF_SPARC | | > | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #elif defined(__mips_eabi) && _MIPS_SZPTR == 32 # define OF_MIPS # define OF_MIPS_EABI #elif defined(__sparc64__) || (defined(__sparc__) && defined(__arch64__)) # define OF_SPARC64 #elif defined(__sparc__) && !defined(__arch64__) # define OF_SPARC #elif defined(__hppa64__) || defined(_PA_RISC2_0) # define OF_PA_RISC_2_0 #elif defined(__hppa__) || defined(_PA_RISC1_0) || defined(_PA_RISC1_1) # define OF_PA_RISC #elif defined(__ia64__) || defined(__IA64__) # define OF_ITANIUM #elif defined(__m68k__) # define OF_M68K # ifdef __mc68060__ # define OF_M68060 |
︙ | ︙ |
Renamed and modified src/platform/amiga/condition.m [fd8eb39931] to src/platform/AmigaOS/OFPlainCondition.m [e78dc05f49].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include <errno.h> | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | * file. */ #include "config.h" #include <errno.h> #import "OFPlainCondition.h" #include <proto/exec.h> #include <devices/timer.h> #ifndef OF_AMIGAOS4 # include <clib/alib_protos.h> #endif int OFPlainConditionNew(OFPlainCondition *condition) { condition->waitingTasks = NULL; return 0; } int OFPlainConditionSignal(OFPlainCondition *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) return 0; Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); condition->waitingTasks = condition->waitingTasks->next; } @finally { Permit(); } return 0; } int OFPlainConditionBroadcast(OFPlainCondition *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) return 0; while (condition->waitingTasks != NULL) { Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); condition->waitingTasks = condition->waitingTasks->next; } } @finally { Permit(); } return 0; } int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex) { ULONG signalMask = 0; return OFPlainConditionWaitOrExecSignal(condition, mutex, &signalMask); } int OFPlainConditionWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, ULONG *signalMask) { struct OFPlainConditionWaitingTask waitingTask = { .task = FindTask(NULL), .sigBit = AllocSignal(-1) }; int error = 0; ULONG mask; if (waitingTask.sigBit == -1) return EAGAIN; Forbid(); if ((error = OFPlainMutexUnlock(mutex)) != 0) { FreeSignal(waitingTask.sigBit); return error; } waitingTask.next = condition->waitingTasks; condition->waitingTasks = &waitingTask; mask = Wait((1ul << waitingTask.sigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) error = OFPlainMutexLock(mutex); else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ error = EINTR; FreeSignal(waitingTask.sigBit); Permit(); return error; } int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout) { ULONG signalMask = 0; return OFPlainConditionTimedWaitOrExecSignal(condition, mutex, timeout, &signalMask); } int OFPlainConditionTimedWaitOrExecSignal(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout, ULONG *signalMask) { struct OFPlainConditionWaitingTask waitingTask = { .task = FindTask(NULL), .sigBit = AllocSignal(-1) }; struct MsgPort port = { .mp_Node = { .ln_Type = NT_MSGPORT }, |
︙ | ︙ | |||
190 191 192 193 194 195 196 | (struct IORequest *)&request, 0) != 0) { error = EAGAIN; goto fail; } Forbid(); | | | | 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | (struct IORequest *)&request, 0) != 0) { error = EAGAIN; goto fail; } Forbid(); if ((error = OFPlainMutexUnlock(mutex)) != 0) { Permit(); goto fail; } waitingTask.next = condition->waitingTasks; condition->waitingTasks = &waitingTask; SendIO((struct IORequest *)&request); mask = Wait((1ul << waitingTask.sigBit) | (1ul << port.mp_SigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) error = OFPlainMutexLock(mutex); else if (mask & (1ul << port.mp_SigBit)) error = ETIMEDOUT; else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ |
︙ | ︙ | |||
233 234 235 236 237 238 239 | if (port.mp_SigBit != -1) FreeSignal(port.mp_SigBit); return error; } int | | | 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | if (port.mp_SigBit != -1) FreeSignal(port.mp_SigBit); return error; } int OFPlainConditionFree(OFPlainCondition *condition) { Forbid(); @try { if (condition->waitingTasks != NULL) return EBUSY; } @finally { Permit(); } return 0; } |
Renamed and modified src/platform/amiga/mutex.m [e7b8301e49] to src/platform/AmigaOS/OFPlainMutex.m [1bb52194dd].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include <errno.h> | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | * file. */ #include "config.h" #include <errno.h> #import "OFPlainMutex.h" #include <proto/exec.h> int OFPlainMutexNew(OFPlainMutex *mutex) { InitSemaphore(mutex); return 0; } int OFPlainMutexLock(OFPlainMutex *mutex) { ObtainSemaphore(mutex); return 0; } int OFPlainMutexTryLock(OFPlainMutex *mutex) { if (!AttemptSemaphore(mutex)) return EBUSY; return 0; } int OFPlainMutexUnlock(OFPlainMutex *mutex) { ReleaseSemaphore(mutex); return 0; } int OFPlainMutexFree(OFPlainMutex *mutex) { return 0; } int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexNew(rmutex); } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexLock(rmutex); } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexTryLock(rmutex); } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexUnlock(rmutex); } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexFree(rmutex); } |
Renamed and modified src/platform/amiga/thread.m [7e3609752c] to src/platform/AmigaOS/OFPlainThread.m [874b38ae30].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include <assert.h> #include <errno.h> | | < | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | */ #include "config.h" #include <assert.h> #include <errno.h> #import "OFPlainThread.h" #import "OFData.h" #import "OFTLSKey.h" #include <dos/dostags.h> #include <proto/dos.h> #include <proto/exec.h> #ifndef OF_MORPHOS extern void OFTLSKeyThreadExited(void); #endif static OFTLSKey threadKey; OF_CONSTRUCTOR() { OFEnsure(OFTLSKeyNew(&threadKey) == 0); } static void functionWrapper(void) { bool detached = false; OFPlainThread thread = (OFPlainThread)((struct Process *)FindTask(NULL))->pr_ExitData; OFEnsure(OFTLSKeySet(threadKey, thread) == 0); thread->function(thread->object); ObtainSemaphore(&thread->semaphore); @try { thread->done = true; #ifndef OF_MORPHOS OFTLSKeyThreadExited(); #endif if (thread->detached) detached = true; else if (thread->joinTask != NULL) Signal(thread->joinTask, (1ul << thread->joinSigBit)); } @finally { ReleaseSemaphore(&thread->semaphore); } if (detached) free(thread); } int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr) { attr->priority = 0; attr->stackSize = 0; return 0; } int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr) { OFMutableData *tags = nil; if ((*thread = calloc(1, sizeof(**thread))) == NULL) return ENOMEM; @try { |
︙ | ︙ | |||
151 152 153 154 155 156 157 | } @finally { [tags release]; } return 0; } | | | | > > > > > > | | 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | } @finally { [tags release]; } return 0; } OFPlainThread OFCurrentPlainThread(void) { return OFTLSKeyGet(threadKey); } bool OFPlainThreadIsCurrent(OFPlainThread thread) { return (thread->task == FindTask(NULL)); } int OFPlainThreadJoin(OFPlainThread thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) { ReleaseSemaphore(&thread->semaphore); free(thread); |
︙ | ︙ | |||
191 192 193 194 195 196 197 | assert(thread->done); free(thread); return 0; } int | | | | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | assert(thread->done); free(thread); return 0; } int OFPlainThreadDetach(OFPlainThread thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) free(thread); else thread->detached = true; ReleaseSemaphore(&thread->semaphore); return 0; } void OFSetThreadName(const char *name) { } |
Renamed and modified src/platform/amiga/OFString+PathAdditions.m [770b7197d1] to src/platform/AmigaOS/OFString+PathAdditions.m [3fc44c52a7].
︙ | ︙ | |||
115 116 117 118 119 120 121 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." | | | | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; |
︙ | ︙ | |||
151 152 153 154 155 156 157 | } objc_autoreleasePoolPop(pool); return @""; } components = [components objectsInRange: | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | } objc_autoreleasePoolPop(pool); return @""; } components = [components objectsInRange: OFRangeMake(0, components.count - 1)]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } |
︙ | ︙ | |||
174 175 176 177 178 179 180 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; |
︙ | ︙ | |||
231 232 233 234 235 236 237 | done = false; break; } if ([component isEqual: @"/"] && parent != nil && ![parent isEqual: @"/"]) { [array removeObjectsInRange: | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | done = false; break; } if ([component isEqual: @"/"] && parent != nil && ![parent isEqual: @"/"]) { [array removeObjectsInRange: OFRangeMake(i - 1, 2)]; done = false; break; } } } |
︙ | ︙ | |||
320 321 322 323 324 325 326 | count--; i--; continue; } if ([component isEqual: @".."]) | | < | 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 | count--; i--; continue; } if ([component isEqual: @".."]) [components replaceObjectAtIndex: i withObject: @"/"]; } return [OFString pathWithComponents: components]; } - (OFString *)of_pathComponentToURLPathComponent { return self; } @end |
Renamed and modified src/platform/amiga/tlskey.m [b1056ea624] to src/platform/AmigaOS/OFTLSKey.m [35debb70a7].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFTLSKey.h" #include <exec/semaphores.h> #include <proto/exec.h> /* * As we use this file in both the runtime and ObjFW, and since AmigaOS always * has the runtime, use the hashtable from the runtime. */ #import "runtime/private.h" static OFTLSKey firstKey = NULL, lastKey = NULL; static struct SignalSemaphore semaphore; static bool semaphoreInitialized = false; static uint32_t hashFunc(const void *ptr) { return (uint32_t)(uintptr_t)ptr; |
︙ | ︙ | |||
47 48 49 50 51 52 53 | if (!semaphoreInitialized) { InitSemaphore(&semaphore); semaphoreInitialized = true; } } int | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | if (!semaphoreInitialized) { InitSemaphore(&semaphore); semaphoreInitialized = true; } } int OFTLSKeyNew(OFTLSKey *key) { if (!semaphoreInitialized) { /* * We might be called from another constructor, while ours has * not run yet. This is safe, as the constructor is definitely * run before a thread is spawned. */ |
︙ | ︙ | |||
85 86 87 88 89 90 91 | } /* We create the hash table lazily. */ return 0; } int | | | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | } /* We create the hash table lazily. */ return 0; } int OFTLSKeyFree(OFTLSKey key) { ObtainSemaphore(&semaphore); @try { if (key->previous != NULL) key->previous->next = key->next; if (key->next != NULL) key->next->previous = key->previous; |
︙ | ︙ | |||
109 110 111 112 113 114 115 | ReleaseSemaphore(&semaphore); } return 0; } void * | | | | | < | 109 110 111 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 163 164 165 166 167 | ReleaseSemaphore(&semaphore); } return 0; } void * OFTLSKeyGet(OFTLSKey key) { void *ret; ObtainSemaphore(&semaphore); @try { if (key->table == NULL) return NULL; ret = objc_hashtable_get(key->table, FindTask(NULL)); } @finally { ReleaseSemaphore(&semaphore); } return ret; } int OFTLSKeySet(OFTLSKey key, void *ptr) { ObtainSemaphore(&semaphore); @try { struct Task *task = FindTask(NULL); if (key->table == NULL) key->table = objc_hashtable_new(hashFunc, equalFunc, 2); if (ptr == NULL) objc_hashtable_delete(key->table, task); else objc_hashtable_set(key->table, task, ptr); } @finally { ReleaseSemaphore(&semaphore); } return 0; } void OFTLSKeyThreadExited(void) { ObtainSemaphore(&semaphore); @try { struct Task *task = FindTask(NULL); for (OFTLSKey iter = firstKey; iter != NULL; iter = iter->next) if (iter->table != NULL) objc_hashtable_delete(iter->table, task); } @finally { ReleaseSemaphore(&semaphore); } } |
Renamed and modified src/atomic_builtins.h [f2deeb95f9] to src/platform/GCC4.7/OFAtomic.h [100821f588].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ static OF_INLINE int | | | | | | | | | | | | | | | | | | > > > > > > > < < < < < < < | | | | | 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return __atomic_add_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return __atomic_add_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __atomic_add_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return __atomic_sub_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return __atomic_sub_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __atomic_sub_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return __atomic_add_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return __atomic_add_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return __atomic_sub_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return __atomic_sub_fetch(p, 1, __ATOMIC_RELAXED); } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return __atomic_or_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return __atomic_or_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return __atomic_and_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return __atomic_and_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return __atomic_xor_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return __atomic_xor_fetch(p, i, __ATOMIC_RELAXED); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { return __atomic_compare_exchange(p, &o, &n, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { return __atomic_compare_exchange(p, &o, &n, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { return __atomic_compare_exchange(p, &o, &n, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED); } static OF_INLINE void OFMemoryBarrier(void) { __atomic_thread_fence(__ATOMIC_SEQ_CST); } static OF_INLINE void OFAcquireMemoryBarrier(void) { __atomic_thread_fence(__ATOMIC_ACQUIRE); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __atomic_thread_fence(__ATOMIC_RELEASE); } |
Renamed and modified src/atomic_sync_builtins.h [7ba8dbb2f0] to src/platform/GCC4/OFAtomic.h [16dfce6eb3].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ static OF_INLINE int | | | | | | | | | | | | | | | | | | | | | | | | 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return __sync_add_and_fetch(p, i); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return __sync_add_and_fetch(p, i); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __sync_add_and_fetch(p, (void *)i); } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return __sync_sub_and_fetch(p, i); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return __sync_sub_and_fetch(p, i); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { return __sync_sub_and_fetch(p, (void *)i); } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return __sync_add_and_fetch(p, 1); } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return __sync_add_and_fetch(p, 1); } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return __sync_sub_and_fetch(p, 1); } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return __sync_sub_and_fetch(p, 1); } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return __sync_or_and_fetch(p, i); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return __sync_or_and_fetch(p, i); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return __sync_and_and_fetch(p, i); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return __sync_and_and_fetch(p, i); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return __sync_xor_and_fetch(p, i); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return __sync_xor_and_fetch(p, i); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { return __sync_bool_compare_and_swap(p, o, n); } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { return __sync_bool_compare_and_swap(p, o, n); } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { return __sync_bool_compare_and_swap(p, o, n); } static OF_INLINE void OFMemoryBarrier(void) { __sync_synchronize(); } static OF_INLINE void OFAcquireMemoryBarrier(void) { __sync_synchronize(); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __sync_synchronize(); } |
Renamed and modified src/platform/morphos/tlskey.m [7b92aa6b53] to src/platform/MorphOS/OFTLSKey.m [493207d475].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFTLSKey.h" int OFTLSKeyNew(OFTLSKey *key) { *key = TLSAllocA(NULL); if (*key == TLS_INVALID_INDEX) return EAGAIN; return 0; } int OFTLSKeyFree(OFTLSKey key) { return (TLSFree(key) ? 0 : EINVAL); } |
Renamed and modified src/platform/posix/condition.m [118d5cf68b] to src/platform/POSIX/OFPlainCondition.m [7572711cd5].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | | | | | | 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 55 56 57 58 59 60 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFPlainCondition.h" int OFPlainConditionNew(OFPlainCondition *condition) { return pthread_cond_init(condition, NULL); } int OFPlainConditionSignal(OFPlainCondition *condition) { return pthread_cond_signal(condition); } int OFPlainConditionBroadcast(OFPlainCondition *condition) { return pthread_cond_broadcast(condition); } int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex) { return pthread_cond_wait(condition, mutex); } int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout) { struct timespec ts; ts.tv_sec = (time_t)timeout; ts.tv_nsec = (long)((timeout - ts.tv_sec) * 1000000000); return pthread_cond_timedwait(condition, mutex, &ts); } int OFPlainConditionFree(OFPlainCondition *condition) { return pthread_cond_destroy(condition); } |
Renamed and modified src/platform/posix/mutex.m [49be18c2e5] to src/platform/POSIX/OFPlainMutex.m [d80afbd5eb].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | | | | | 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 55 56 57 58 59 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFPlainMutex.h" int OFPlainMutexNew(OFPlainMutex *mutex) { return pthread_mutex_init(mutex, NULL); } int OFPlainMutexLock(OFPlainMutex *mutex) { return pthread_mutex_lock(mutex); } int OFPlainMutexTryLock(OFPlainMutex *mutex) { return pthread_mutex_trylock(mutex); } int OFPlainMutexUnlock(OFPlainMutex *mutex) { return pthread_mutex_unlock(mutex); } int OFPlainMutexFree(OFPlainMutex *mutex) { return pthread_mutex_destroy(mutex); } #ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { int error; pthread_mutexattr_t attr; if ((error = pthread_mutexattr_init(&attr)) != 0) return error; |
︙ | ︙ | |||
67 68 69 70 71 72 73 | if ((error = pthread_mutexattr_destroy(&attr)) != 0) return error; return 0; } int | > > > > | > > | | | < < < < | < < | | | | | | | | | | | | | | | | | | | | | | | | | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | if ((error = pthread_mutexattr_destroy(&attr)) != 0) return error; return 0; } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexLock(rmutex); } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexTryLock(rmutex); } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexUnlock(rmutex); } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexFree(rmutex); } #else int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { int error; if ((error = OFPlainMutexNew(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeyNew(&rmutex->count)) != 0) return error; return 0; } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { uintptr_t count = (uintptr_t)OFTLSKeyGet(rmutex->count); int error; if (count > 0) { if ((error = OFTLSKeySet(rmutex->count, (void *)(count + 1))) != 0) return error; return 0; } if ((error = OFPlainMutexLock(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeySet(rmutex->count, (void *)1)) != 0) { OFPlainMutexUnlock(&rmutex->mutex); return error; } return 0; } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { uintptr_t count = (uintptr_t)OFTLSKeyGet(rmutex->count); int error; if (count > 0) { if ((error = OFTLSKeySet(rmutex->count, (void *)(count + 1))) != 0) return error; return 0; } if ((error = OFPlainMutexTryLock(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeySet(rmutex->count, (void *)1)) != 0) { OFPlainMutexUnlock(&rmutex->mutex); return error; } return 0; } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { uintptr_t count = (uintptr_t)OFTLSKeyGet(rmutex->count); int error; if (count > 1) { if ((error = OFTLSKeySet(rmutex->count, (void *)(count - 1))) != 0) return error; return 0; } if ((error = OFTLSKeySet(rmutex->count, (void *)0)) != 0) return error; if ((error = OFPlainMutexUnlock(&rmutex->mutex)) != 0) return error; return 0; } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { int error; if ((error = OFPlainMutexFree(&rmutex->mutex)) != 0) return error; if ((error = OFTLSKeyFree(rmutex->count)) != 0) return error; return 0; } #endif |
Renamed and modified src/platform/posix/thread.m [5a946f82c1] to src/platform/POSIX/OFPlainThread.m [59ba7d304a].
︙ | ︙ | |||
21 22 23 24 25 26 27 | # include <pthread_np.h> #endif #ifdef OF_HAIKU # include <kernel/OS.h> #endif | | > | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | # include <pthread_np.h> #endif #ifdef OF_HAIKU # include <kernel/OS.h> #endif #import "OFPlainThread.h" #import "macros.h" static int minPrio = 0, maxPrio = 0, normalPrio = 0; struct ThreadContext { void (*function)(id object); id object; const char *name; }; /* * This is done here to make sure this is done as early as possible in the main |
︙ | ︙ | |||
68 69 70 71 72 73 74 | pthread_attr_destroy(&attr); } } static void * functionWrapper(void *data) { | | | | | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | pthread_attr_destroy(&attr); } } static void * functionWrapper(void *data) { struct ThreadContext *ctx = data; if (ctx->name != NULL) OFSetThreadName(ctx->name); pthread_cleanup_push(free, data); ctx->function(ctx->object); pthread_cleanup_pop(1); return NULL; } int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr) { int error; pthread_attr_t POSIXAttr; attr->priority = 0; attr->stackSize = 0; |
︙ | ︙ | |||
105 106 107 108 109 110 111 | pthread_attr_destroy(&POSIXAttr); return error; } int | | | | > > > | | > > > > > | > | | | | 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | pthread_attr_destroy(&POSIXAttr); return error; } int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr) { int error = 0; pthread_attr_t POSIXAttr; bool POSIXAttrAvailable = true; if ((error = pthread_attr_init(&POSIXAttr)) != 0) { if (error == ENOSYS) POSIXAttrAvailable = false; else return error; } @try { struct ThreadContext *ctx; if (attr != NULL && POSIXAttrAvailable) { #ifndef OF_HPUX struct sched_param param; #endif if (attr->priority < -1 || attr->priority > 1) return EINVAL; #ifndef OF_HPUX # ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED if ((error = pthread_attr_setinheritsched(&POSIXAttr, PTHREAD_EXPLICIT_SCHED)) != 0) return error; # endif if ((error = pthread_attr_getschedparam(&POSIXAttr, ¶m)) != 0) return error; if (attr->priority < 0) { param.sched_priority = minPrio + (1.0f + attr->priority) * (normalPrio - minPrio); } else param.sched_priority = normalPrio + attr->priority * (maxPrio - normalPrio); if ((error = pthread_attr_setschedparam(&POSIXAttr, ¶m)) != 0) return error; #endif if (attr->stackSize > 0) { if ((error = pthread_attr_setstacksize( &POSIXAttr, attr->stackSize)) != 0) return error; } } if ((ctx = malloc(sizeof(*ctx))) == NULL) return ENOMEM; ctx->function = function; ctx->object = object; ctx->name = name; error = pthread_create(thread, (POSIXAttrAvailable ? &POSIXAttr : NULL), functionWrapper, ctx); } @finally { if (POSIXAttrAvailable) pthread_attr_destroy(&POSIXAttr); } return error; } int OFPlainThreadJoin(OFPlainThread thread) { void *ret; return pthread_join(thread, &ret); } int OFPlainThreadDetach(OFPlainThread thread) { return pthread_detach(thread); } void OFSetThreadName(const char *name) { #if defined(OF_HAIKU) rename_thread(find_thread(NULL), name); #elif defined(HAVE_PTHREAD_SET_NAME_NP) pthread_set_name_np(pthread_self(), name); #elif defined(HAVE_PTHREAD_SETNAME_NP) # if defined(OF_MACOS) || defined(OF_IOS) |
︙ | ︙ |
Renamed and modified src/platform/posix/OFString+PathAdditions.m [1b42dd0767] to src/platform/POSIX/OFString+PathAdditions.m [27ce85898f].
︙ | ︙ | |||
142 143 144 145 146 147 148 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." | | | | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; |
︙ | ︙ | |||
211 212 213 214 215 216 217 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." | | | | 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: [components count] - 1 withObject: fileName]; |
︙ | ︙ | |||
273 274 275 276 277 278 279 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: | | | < | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFRangeMake(i - 1, 2)]; done = false; break; } } } if (startsWithSlash) [array insertObject: @"" atIndex: 0]; if ([self hasSuffix: @"/"]) [array addObject: @""]; ret = [[array componentsJoinedByString: @"/"] retain]; objc_autoreleasePoolPop(pool); |
︙ | ︙ |
Renamed and modified src/platform/posix/OFProcess.m [e243a4e88a] to src/platform/POSIX/OFSubprocess.m [3ba49dc037].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #endif #include "unistd_wrapper.h" #ifdef HAVE_SPAWN_H # include <spawn.h> #endif | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #endif #include "unistd_wrapper.h" #ifdef HAVE_SPAWN_H # include <spawn.h> #endif #import "OFSubprocess.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #ifndef HAVE_POSIX_SPAWNP extern char **environ; #endif @interface OFSubprocess () - (void)of_getArgv: (char ***)argv forProgramName: (OFString *)programName andArguments: (OFArray *)arguments; - (char **)of_environmentForDictionary: (OFDictionary *)dictionary; @end @implementation OFSubprocess + (instancetype)subprocessWithProgram: (OFString *)program { return [[[self alloc] initWithProgram: program] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments environment: (OFDictionary *)environment { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments environment: environment] autorelease]; } |
︙ | ︙ | |||
203 204 205 206 207 208 209 | exceptionWithClass: self.class]; #endif } @finally { char **iter; close(_readPipe[1]); close(_writePipe[0]); | | | | | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | exceptionWithClass: self.class]; #endif } @finally { char **iter; close(_readPipe[1]); close(_writePipe[0]); OFFreeMemory(argv); for (iter = env; *iter != NULL; iter++) OFFreeMemory(*iter); OFFreeMemory(env); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
234 235 236 237 238 239 240 | - (void)of_getArgv: (char ***)argv forProgramName: (OFString *)programName andArguments: (OFArray *)arguments { OFString *const *objects = arguments.objects; size_t i, count = arguments.count; | | | | | | | | | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | - (void)of_getArgv: (char ***)argv forProgramName: (OFString *)programName andArguments: (OFArray *)arguments { OFString *const *objects = arguments.objects; size_t i, count = arguments.count; OFStringEncoding encoding; *argv = OFAllocMemory(count + 2, sizeof(char *)); encoding = [OFLocale encoding]; (*argv)[0] = (char *)[programName cStringWithEncoding: encoding]; for (i = 0; i < count; i++) (*argv)[i + 1] = (char *)[objects[i] cStringWithEncoding: encoding]; (*argv)[i + 1] = NULL; } - (char **)of_environmentForDictionary: (OFDictionary *)environment { char **envp; size_t count; OFStringEncoding encoding; if (environment == nil) return NULL; encoding = [OFLocale encoding]; count = environment.count; envp = OFAllocZeroedMemory(count + 1, sizeof(char *)); @try { OFEnumerator *keyEnumerator = [environment keyEnumerator]; OFEnumerator *objectEnumerator = [environment objectEnumerator]; for (size_t i = 0; i < count; i++) { OFString *key; OFString *object; size_t keyLen, objectLen; key = [keyEnumerator nextObject]; object = [objectEnumerator nextObject]; keyLen = [key cStringLengthWithEncoding: encoding]; objectLen = [object cStringLengthWithEncoding: encoding]; envp[i] = OFAllocMemory(keyLen + objectLen + 2, 1); memcpy(envp[i], [key cStringWithEncoding: encoding], keyLen); envp[i][keyLen] = '='; memcpy(envp[i] + keyLen + 1, [object cStringWithEncoding: encoding], objectLen); envp[i][keyLen + objectLen + 1] = '\0'; } } @catch (id e) { for (size_t i = 0; i < count; i++) OFFreeMemory(envp[i]); OFFreeMemory(envp); @throw e; } return envp; } |
︙ | ︙ |
Renamed and modified src/platform/posix/tlskey.m [dfb4cf3035] to src/platform/POSIX/OFTLSKey.m [47a306e613].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFTLSKey.h" int OFTLSKeyNew(OFTLSKey *key) { return pthread_key_create(key, NULL); } int OFTLSKeyFree(OFTLSKey key) { return pthread_key_delete(key); } |
Renamed and modified src/atomic_powerpc.h [a52241434a] to src/platform/PowerPC/OFAtomic.h [44b886c5c2].
︙ | ︙ | |||
10 11 12 13 14 15 16 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ static OF_INLINE int | | | | | | | | | | | | | | | | | | > > > > > > > > > > > > > > > > > > > > > > > > > > | 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "add %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "add %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "add %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return (void *)i; } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "sub %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "sub %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "sub %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return (void *)i; } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { int i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "addi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r"(i) : "r"(p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "addi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r"(i) : "r"(p) : "cc", "memory" ); return i; } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { int i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "subi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r"(i) : "r"(p) : "cc", "memory" ); return i; } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %1\n\t" "subi %0, %0, 1\n\t" "stwcx. %0, 0, %1\n\t" "bne- 0b" : "=&r"(i) : "r"(p) : "cc", "memory" ); return i; } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "or %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "or %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "and %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "and %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "xor %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %2\n\t" "xor %0, %0, %1\n\t" "stwcx. %0, 0, %2\n\t" "bne- 0b" : "=&r"(i) : "r"(i), "r"(p) : "cc", "memory" ); return i; } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { int r; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %3\n\t" "cmpw %0, %1\n\t" "bne 1f\n\t" "stwcx. %2, 0, %3\n\t" "bne- 0b\n\t" "li %0, 1\n\t" "b 2f\n\t" "1:\n\t" "stwcx. %0, 0, %3\n\t" "li %0, 0\n\t" "2:" : "=&r"(r) : "r"(o), "r"(n), "r"(p) : "cc", "memory" ); return r; } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { int r; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %3\n\t" "cmpw %0, %1\n\t" |
︙ | ︙ | |||
316 317 318 319 320 321 322 | : "cc", "memory" ); return r; } static OF_INLINE bool | < < < < < < < < < < < < < < < < < < < < < < < < < < | | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | : "cc", "memory" ); return r; } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { int r; __asm__ __volatile__ ( "0:\n\t" "lwarx %0, 0, %3\n\t" |
︙ | ︙ | |||
369 370 371 372 373 374 375 | : "cc", "memory" ); return r; } static OF_INLINE void | | | | | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | : "cc", "memory" ); return r; } static OF_INLINE void OFMemoryBarrier(void) { __asm__ __volatile__ ( ".long 0x7C2004AC /* lwsync */" ::: "memory" ); } static OF_INLINE void OFAcquireMemoryBarrier(void) { __asm__ __volatile__ ( ".long 0x7C2004AC /* lwsync */" ::: "memory" ); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __asm__ __volatile__ ( ".long 0x7C2004AC /* lwsync */" ::: "memory" ); } |
Renamed and modified src/platform/windows/condition.m [cc03ce6342] to src/platform/Windows/OFPlainCondition.m [a5005b7f00].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include <errno.h> | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | * file. */ #include "config.h" #include <errno.h> #import "OFPlainCondition.h" #include <windows.h> int OFPlainConditionNew(OFPlainCondition *condition) { condition->count = 0; if ((condition->event = CreateEvent(NULL, FALSE, 0, NULL)) == NULL) return EAGAIN; return 0; } int OFPlainConditionSignal(OFPlainCondition *condition) { if (!SetEvent(condition->event)) { switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } } return 0; } int OFPlainConditionBroadcast(OFPlainCondition *condition) { int count = condition->count; for (int i = 0; i < count; i++) { if (!SetEvent(condition->event)) { switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } } } return 0; } int OFPlainConditionWait(OFPlainCondition *condition, OFPlainMutex *mutex) { int error; DWORD status; if ((error = OFPlainMutexUnlock(mutex)) != 0) return error; OFAtomicIntIncrease(&condition->count); status = WaitForSingleObject(condition->event, INFINITE); OFAtomicIntDecrease(&condition->count); switch (status) { case WAIT_OBJECT_0: return OFPlainMutexLock(mutex); case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } default: OFEnsure(0); } } int OFPlainConditionTimedWait(OFPlainCondition *condition, OFPlainMutex *mutex, OFTimeInterval timeout) { int error; DWORD status; if ((error = OFPlainMutexUnlock(mutex)) != 0) return error; OFAtomicIntIncrease(&condition->count); status = WaitForSingleObject(condition->event, timeout * 1000); OFAtomicIntDecrease(&condition->count); switch (status) { case WAIT_OBJECT_0: return OFPlainMutexLock(mutex); case WAIT_TIMEOUT: return ETIMEDOUT; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } default: OFEnsure(0); } } int OFPlainConditionFree(OFPlainCondition *condition) { if (condition->count != 0) return EBUSY; return (CloseHandle(condition->event) ? 0 : EINVAL); } |
Renamed and modified src/platform/windows/mutex.m [ed38f771ab] to src/platform/Windows/OFPlainMutex.m [7e4b30c2dd].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include <errno.h> | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | * file. */ #include "config.h" #include <errno.h> #import "OFPlainMutex.h" #include <windows.h> int OFPlainMutexNew(OFPlainMutex *mutex) { InitializeCriticalSection(mutex); return 0; } int OFPlainMutexLock(OFPlainMutex *mutex) { EnterCriticalSection(mutex); return 0; } int OFPlainMutexTryLock(OFPlainMutex *mutex) { if (!TryEnterCriticalSection(mutex)) return EBUSY; return 0; } int OFPlainMutexUnlock(OFPlainMutex *mutex) { LeaveCriticalSection(mutex); return 0; } int OFPlainMutexFree(OFPlainMutex *mutex) { DeleteCriticalSection(mutex); return 0; } int OFPlainRecursiveMutexNew(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexNew(rmutex); } int OFPlainRecursiveMutexLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexLock(rmutex); } int OFPlainRecursiveMutexTryLock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexTryLock(rmutex); } int OFPlainRecursiveMutexUnlock(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexUnlock(rmutex); } int OFPlainRecursiveMutexFree(OFPlainRecursiveMutex *rmutex) { return OFPlainMutexFree(rmutex); } |
Renamed and modified src/platform/windows/thread.m [5512169ec5] to src/platform/Windows/OFPlainThread.m [eb57469e6d].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include <errno.h> | | > | | | | | | | 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 | * file. */ #include "config.h" #include <errno.h> #import "OFPlainThread.h" #import "macros.h" #include <windows.h> struct ThreadContext { void (*function)(id); id object; }; static WINAPI void functionWrapper(struct ThreadContext *context) { context->function(context->object); free(context); } int OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr) { attr->priority = 0; attr->stackSize = 0; return 0; } int OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), id object, const OFPlainThreadAttributes *attr) { DWORD priority = THREAD_PRIORITY_NORMAL; struct ThreadContext *context; DWORD threadID; if (attr != NULL && attr->priority != 0) { if (attr->priority < -1 || attr->priority > 1) return EINVAL; if (attr->priority < 0) |
︙ | ︙ | |||
82 83 84 85 86 87 88 | case ERROR_NOT_ENOUGH_MEMORY: error = ENOMEM; break; case ERROR_ACCESS_DENIED: error = EACCES; break; default: | | | | | | | | | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | case ERROR_NOT_ENOUGH_MEMORY: error = ENOMEM; break; case ERROR_ACCESS_DENIED: error = EACCES; break; default: OFEnsure(0); } free(context); return error; } if (attr != NULL && attr->priority != 0) OFEnsure(!SetThreadPriority(*thread, priority)); return 0; } int OFPlainThreadJoin(OFPlainThread thread) { switch (WaitForSingleObject(thread, INFINITE)) { case WAIT_OBJECT_0: CloseHandle(thread); return 0; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OFEnsure(0); } default: OFEnsure(0); } } int OFPlainThreadDetach(OFPlainThread thread) { CloseHandle(thread); return 0; } void OFSetThreadName(const char *name) { } |
Renamed and modified src/platform/windows/OFString+PathAdditions.m [41e0a20445] to src/platform/Windows/OFString+PathAdditions.m [adef09bc0d].
︙ | ︙ | |||
153 154 155 156 157 158 159 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." | | | | 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; |
︙ | ︙ | |||
199 200 201 202 203 204 205 | } objc_autoreleasePoolPop(pool); return @"."; } components = [components objectsInRange: | | | 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | } objc_autoreleasePoolPop(pool); return @"."; } components = [components objectsInRange: OFRangeMake(0, components.count - 1)]; ret = [OFString pathWithComponents: components]; [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } |
︙ | ︙ | |||
222 223 224 225 226 227 228 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." | | | | 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; |
︙ | ︙ | |||
284 285 286 287 288 289 290 | if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."] && ![parent hasSuffix: @":"] && ![parent hasSuffix: @":\\"] && ![parent hasSuffix: @"://"] && (![parent hasPrefix: @"\\"] || i != 1)) { [array removeObjectsInRange: | | | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."] && ![parent hasSuffix: @":"] && ![parent hasSuffix: @":\\"] && ![parent hasSuffix: @"://"] && (![parent hasPrefix: @"\\"] || i != 1)) { [array removeObjectsInRange: OFRangeMake(i - 1, 2)]; done = false; break; } } } |
︙ | ︙ | |||
335 336 337 338 339 340 341 | if (components.count < 2) @throw [OFInvalidFormatException exception]; *URLEncodedHost = [[components objectAtIndex: 1] stringByURLEncodingWithAllowedCharacters: [OFCharacterSet URLHostAllowedCharacterSet]]; path = [OFString pathWithComponents: [components | | | 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | if (components.count < 2) @throw [OFInvalidFormatException exception]; *URLEncodedHost = [[components objectAtIndex: 1] stringByURLEncodingWithAllowedCharacters: [OFCharacterSet URLHostAllowedCharacterSet]]; path = [OFString pathWithComponents: [components objectsInRange: OFRangeMake(2, components.count - 2)]]; } path = [path stringByReplacingOccurrencesOfString: @"\\" withString: @"/"]; path = [path stringByPrependingString: @"/"]; return path; |
︙ | ︙ |
Renamed and modified src/platform/windows/OFProcess.m [5bdba7aa5b] to src/platform/Windows/OFSubprocess.m [b8e69b2ddb].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #include <errno.h> #include <string.h> | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | */ #include "config.h" #include <errno.h> #include <string.h> #import "OFSubprocess.h" #import "OFArray.h" #import "OFData.h" #import "OFDictionary.h" #import "OFLocale.h" #import "OFString.h" #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFNotOpenException.h" #import "OFOutOfRangeException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #include <windows.h> @interface OFSubprocess () - (OFChar16 *)of_wideEnvironmentForDictionary: (OFDictionary *)dictionary; - (char *)of_environmentForDictionary: (OFDictionary *)environment; @end @implementation OFSubprocess + (instancetype)subprocessWithProgram: (OFString *)program { return [[[self alloc] initWithProgram: program] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments] autorelease]; } + (instancetype)subprocessWithProgram: (OFString *)program programName: (OFString *)programName arguments: (OFArray *)arguments environment: (OFDictionary *)environment { return [[[self alloc] initWithProgram: program programName: programName arguments: arguments environment: environment] autorelease]; } |
︙ | ︙ | |||
113 114 115 116 117 118 119 | @try { SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; void *pool; OFMutableString *argumentsString; | | | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | @try { SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; void *pool; OFMutableString *argumentsString; _handle = INVALID_HANDLE_VALUE; _readPipe[0] = _writePipe[1] = NULL; sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; if (!CreatePipe(&_readPipe[0], &_readPipe[1], &sa, 0)) |
︙ | ︙ | |||
178 179 180 181 182 183 184 | if (containsSpaces) [argumentsString appendString: @"\""]; } if ([OFSystemInfo isWindowsNT]) { size_t length; | | | | | | | | | | | | < | < | < | < | | < | < | < | < | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | if (containsSpaces) [argumentsString appendString: @"\""]; } if ([OFSystemInfo isWindowsNT]) { size_t length; OFChar16 *argumentsCopy; STARTUPINFOW si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.hStdInput = _writePipe[0]; si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; length = argumentsString.UTF16StringLength; argumentsCopy = OFAllocMemory(length + 1, sizeof(OFChar16)); memcpy(argumentsCopy, argumentsString.UTF16String, (length + 1) * 2); @try { if (!CreateProcessW(program.UTF16String, argumentsCopy, NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT, [self of_wideEnvironmentForDictionary: environment], NULL, &si, &pi)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @finally { OFFreeMemory(argumentsCopy); } } else { OFStringEncoding encoding = [OFLocale encoding]; STARTUPINFO si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); si.hStdInput = _writePipe[0]; si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; if (!CreateProcessA([program cStringWithEncoding: encoding], (char *)[argumentsString cStringWithEncoding: encoding], NULL, NULL, TRUE, 0, [self of_environmentForDictionary: environment], NULL, &si, &pi)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } objc_autoreleasePoolPop(pool); _handle = pi.hProcess; CloseHandle(pi.hThread); CloseHandle(_readPipe[1]); CloseHandle(_writePipe[0]); } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_readPipe[0] != NULL) [self close]; [super dealloc]; } - (OFChar16 *)of_wideEnvironmentForDictionary: (OFDictionary *)environment { OFMutableData *env; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; const OFChar16 equal = '='; const OFChar16 zero[2] = { 0, 0 }; if (environment == nil) return NULL; env = [OFMutableData dataWithItemSize: sizeof(OFChar16)]; keyEnumerator = [environment keyEnumerator]; objectEnumerator = [environment objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { [env addItems: key.UTF16String count: key.UTF16StringLength]; [env addItems: &equal count: 1]; [env addItems: object.UTF16String count: object.UTF16StringLength]; [env addItems: &zero count: 1]; } [env addItems: zero count: 2]; return env.mutableItems; } - (char *)of_environmentForDictionary: (OFDictionary *)environment { OFStringEncoding encoding = [OFLocale encoding]; OFMutableData *env; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; if (environment == nil) return NULL; env = [OFMutableData data]; keyEnumerator = [environment keyEnumerator]; objectEnumerator = [environment objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { [env addItems: [key cStringWithEncoding: encoding] count: [key cStringLengthWithEncoding: encoding]]; [env addItems: "=" count: 1]; [env addItems: [object cStringWithEncoding: encoding] count: [object cStringLengthWithEncoding: encoding]]; [env addItems: "" count: 1]; } [env addItems: "\0" count: 2]; return env.mutableItems; } - (bool)lowlevelIsAtEndOfStream { if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)length { DWORD ret; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (_readPipe[0] == NULL) |
︙ | ︙ | |||
346 347 348 349 350 351 352 | if (ret == 0) _atEndOfStream = true; return ret; } | | < | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | if (ret == 0) _atEndOfStream = true; return ret; } - (size_t)lowlevelWriteBuffer: (const void *)buffer length: (size_t)length { DWORD bytesWritten; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; if (_writePipe[1] == NULL) |
︙ | ︙ | |||
389 390 391 392 393 394 395 | { if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; [self closeForWriting]; CloseHandle(_readPipe[0]); | | | | | | | | | | | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | { if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; [self closeForWriting]; CloseHandle(_readPipe[0]); if (_handle != INVALID_HANDLE_VALUE) { TerminateProcess(_handle, 0); CloseHandle(_handle); } _handle = INVALID_HANDLE_VALUE; _readPipe[0] = NULL; [super close]; } - (int)waitForTermination { if (_readPipe[0] == NULL) @throw [OFNotOpenException exceptionWithObject: self]; if (_handle != INVALID_HANDLE_VALUE) { DWORD exitCode; WaitForSingleObject(_handle, INFINITE); if (GetExitCodeProcess(_handle, &exitCode)) _status = exitCode; else _status = GetLastError(); CloseHandle(_handle); _handle = INVALID_HANDLE_VALUE; } return _status; } @end |
Renamed and modified src/platform/windows/tlskey.m [bdf0c15028] to src/platform/Windows/OFTLSKey.m [3701d3663b].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFTLSKey.h" int OFTLSKeyNew(OFTLSKey *key) { *key = TlsAlloc(); if (*key == TLS_OUT_OF_INDEXES) return EAGAIN; return 0; } int OFTLSKeyFree(OFTLSKey key) { return (TlsFree(key) ? 0 : EINVAL); } |
Modified src/platform/libfat/OFString+PathAdditions.m from [420e4f330e] to [2f244634b3].
︙ | ︙ | |||
149 150 151 152 153 154 155 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." | | | | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | { void *pool = objc_autoreleasePoolPush(); OFString *ret, *fileName; size_t pos; fileName = self.lastPathComponent; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return @""; } ret = [fileName substringFromIndex: pos + 1]; [ret retain]; |
︙ | ︙ | |||
219 220 221 222 223 224 225 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." | | | | 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | return [[self copy] autorelease]; pool = objc_autoreleasePoolPush(); components = [[self.pathComponents mutableCopy] autorelease]; fileName = components.lastObject; pos = [fileName rangeOfString: @"." options: OFStringSearchBackwards].location; if (pos == OFNotFound || pos == 0) { objc_autoreleasePoolPop(pool); return [[self copy] autorelease]; } fileName = [fileName substringToIndex: pos]; [components replaceObjectAtIndex: components.count - 1 withObject: fileName]; |
︙ | ︙ | |||
277 278 279 280 281 282 283 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: | | | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | done = false; break; } if ([component isEqual: @".."] && parent != nil && ![parent isEqual: @".."]) { [array removeObjectsInRange: OFRangeMake(i - 1, 2)]; done = false; break; } } } |
︙ | ︙ |
Renamed and modified src/atomic_osatomic.h [0fe4f3a992] to src/platform/macOS/OFAtomic.h [52d5cd31b9].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include <libkern/OSAtomic.h> static OF_INLINE int | | | | | | | | | | | | | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include <libkern/OSAtomic.h> static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { return OSAtomicAdd32(i, p); } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { return OSAtomicAdd32(i, p); } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { #ifdef __LP64__ return (void *)OSAtomicAdd64(i, (int64_t *)p); #else return (void *)OSAtomicAdd32(i, (int32_t *)p); #endif } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { return OSAtomicAdd32(-i, p); } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { return OSAtomicAdd32(-i, p); } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { #ifdef __LP64__ return (void *)OSAtomicAdd64(-i, (int64_t *)p); #else return (void *)OSAtomicAdd32(-i, (int32_t *)p); #endif } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { return OSAtomicIncrement32(p); } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { return OSAtomicIncrement32(p); } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { return OSAtomicDecrement32(p); } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { return OSAtomicDecrement32(p); } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { return OSAtomicOr32(i, p); } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { return OSAtomicOr32(i, p); } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { return OSAtomicAnd32(i, p); } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { return OSAtomicAnd32(i, p); } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { return OSAtomicXor32(i, p); } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { return OSAtomicXor32(i, p); } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { return OSAtomicCompareAndSwapInt(o, n, p); } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { return OSAtomicCompareAndSwap32(o, n, p); } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { return OSAtomicCompareAndSwapPtr(o, n, p); } static OF_INLINE void OFMemoryBarrier(void) { OSMemoryBarrier(); } static OF_INLINE void OFAcquireMemoryBarrier(void) { OSMemoryBarrier(); } static OF_INLINE void OFReleaseMemoryBarrier(void) { OSMemoryBarrier(); } |
Renamed and modified src/atomic_x86.h [3d60327fd6] to src/platform/x86/OFAtomic.h [b0f56d0157].
︙ | ︙ | |||
12 13 14 15 16 17 18 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ OF_ASSUME_NONNULL_BEGIN static OF_INLINE int | | | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ OF_ASSUME_NONNULL_BEGIN static OF_INLINE int OFAtomicIntAdd(volatile int *_Nonnull p, int i) { if (sizeof(int) == 4) __asm__ __volatile__ ( "lock\n\t" "xaddl %0, %2\n\t" "addl %1, %0" : "+&r"(i) |
︙ | ︙ | |||
39 40 41 42 43 44 45 | else abort(); return i; } static OF_INLINE int32_t | | | | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | else abort(); return i; } static OF_INLINE int32_t OFAtomicInt32Add(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "lock\n\t" "xaddl %0, %2\n\t" "addl %1, %0" : "+&r"(i) : "r"(i), "m"(*p) ); return i; } static OF_INLINE void *_Nullable OFAtomicPointerAdd(void *volatile _Nullable *_Nonnull p, intptr_t i) { #if defined(OF_X86_64) __asm__ __volatile__ ( "lock\n\t" "xaddq %0, %2\n\t" "addq %1, %0" : "+&r"(i) |
︙ | ︙ | |||
79 80 81 82 83 84 85 | ); return (void *)i; #endif } static OF_INLINE int | | | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | ); return (void *)i; #endif } static OF_INLINE int OFAtomicIntSubtract(volatile int *_Nonnull p, int i) { if (sizeof(int) == 4) __asm__ __volatile__ ( "negl %0\n\t" "lock\n\t" "xaddl %0, %2\n\t" "subl %1, %0" |
︙ | ︙ | |||
108 109 110 111 112 113 114 | else abort(); return i; } static OF_INLINE int32_t | | | | 108 109 110 111 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 | else abort(); return i; } static OF_INLINE int32_t OFAtomicInt32Subtract(volatile int32_t *_Nonnull p, int32_t i) { __asm__ __volatile__ ( "negl %0\n\t" "lock\n\t" "xaddl %0, %2\n\t" "subl %1, %0" : "+&r"(i) : "r"(i), "m"(*p) ); return i; } static OF_INLINE void *_Nullable OFAtomicPointerSubtract(void *volatile _Nullable *_Nonnull p, intptr_t i) { #if defined(OF_X86_64) __asm__ __volatile__ ( "negq %0\n\t" "lock\n\t" "xaddq %0, %2\n\t" "subq %1, %0" |
︙ | ︙ | |||
151 152 153 154 155 156 157 | ); return (void *)i; #endif } static OF_INLINE int | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | ); return (void *)i; #endif } static OF_INLINE int OFAtomicIntIncrease(volatile int *_Nonnull p) { int i; if (sizeof(int) == 4) __asm__ __volatile__ ( "xorl %0, %0\n\t" "incl %0\n\t" |
︙ | ︙ | |||
184 185 186 187 188 189 190 | else abort(); return i; } static OF_INLINE int32_t | | | | 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | else abort(); return i; } static OF_INLINE int32_t OFAtomicInt32Increase(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "xorl %0, %0\n\t" "incl %0\n\t" "lock\n\t" "xaddl %0, %1\n\t" "incl %0" : "=&r"(i) : "m"(*p) ); return i; } static OF_INLINE int OFAtomicIntDecrease(volatile int *_Nonnull p) { int i; if (sizeof(int) == 4) __asm__ __volatile__ ( "xorl %0, %0\n\t" "decl %0\n\t" |
︙ | ︙ | |||
235 236 237 238 239 240 241 | else abort(); return i; } static OF_INLINE int32_t | | | | 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | else abort(); return i; } static OF_INLINE int32_t OFAtomicInt32Decrease(volatile int32_t *_Nonnull p) { int32_t i; __asm__ __volatile__ ( "xorl %0, %0\n\t" "decl %0\n\t" "lock\n\t" "xaddl %0, %1\n\t" "decl %0" : "=&r"(i) : "m"(*p) ); return i; } static OF_INLINE unsigned int OFAtomicIntOr(volatile unsigned int *_Nonnull p, unsigned int i) { if (sizeof(int) == 4) __asm__ __volatile__ ( "0:\n\t" "movl %2, %0\n\t" "movl %0, %%eax\n\t" "orl %1, %0\n\t" |
︙ | ︙ | |||
290 291 292 293 294 295 296 | else abort(); return i; } static OF_INLINE uint32_t | | | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | else abort(); return i; } static OF_INLINE uint32_t OFAtomicInt32Or(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "movl %2, %0\n\t" "movl %0, %%eax\n\t" "orl %1, %0\n\t" "lock\n\t" "cmpxchg %0, %2\n\t" "jne 0b" : "=&r"(i) : "r"(i), "m"(*p) : "eax", "cc" ); return i; } static OF_INLINE unsigned int OFAtomicIntAnd(volatile unsigned int *_Nonnull p, unsigned int i) { if (sizeof(int) == 4) __asm__ __volatile__ ( "0:\n\t" "movl %2, %0\n\t" "movl %0, %%eax\n\t" "andl %1, %0\n\t" |
︙ | ︙ | |||
346 347 348 349 350 351 352 | else abort(); return i; } static OF_INLINE uint32_t | | | | 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | else abort(); return i; } static OF_INLINE uint32_t OFAtomicInt32And(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "movl %2, %0\n\t" "movl %0, %%eax\n\t" "andl %1, %0\n\t" "lock\n\t" "cmpxchg %0, %2\n\t" "jne 0b" : "=&r"(i) : "r"(i), "m"(*p) : "eax", "cc" ); return i; } static OF_INLINE unsigned int OFAtomicIntXor(volatile unsigned int *_Nonnull p, unsigned int i) { if (sizeof(int) == 4) __asm__ __volatile__ ( "0:\n\t" "movl %2, %0\n\t" "movl %0, %%eax\n\t" "xorl %1, %0\n\t" |
︙ | ︙ | |||
402 403 404 405 406 407 408 | else abort(); return i; } static OF_INLINE uint32_t | | | | | | | | | 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | else abort(); return i; } static OF_INLINE uint32_t OFAtomicInt32Xor(volatile uint32_t *_Nonnull p, uint32_t i) { __asm__ __volatile__ ( "0:\n\t" "movl %2, %0\n\t" "movl %0, %%eax\n\t" "xorl %1, %0\n\t" "lock\n\t" "cmpxchgl %0, %2\n\t" "jne 0b" : "=&r"(i) : "r"(i), "m"(*p) : "eax", "cc" ); return i; } static OF_INLINE bool OFAtomicIntCompareAndSwap(volatile int *_Nonnull p, int o, int n) { int r; __asm__ __volatile__ ( "lock\n\t" "cmpxchg %2, %3\n\t" "sete %b0\n\t" "movzbl %b0, %0" : "=&d"(r), "+a"(o) /* use d instead of r to avoid a gcc bug */ : "r"(n), "m"(*p) : "cc" ); return r; } static OF_INLINE bool OFAtomicInt32CompareAndSwap(volatile int32_t *_Nonnull p, int32_t o, int32_t n) { int r; __asm__ __volatile__ ( "lock\n\t" "cmpxchg %2, %3\n\t" "sete %b0\n\t" "movzbl %b0, %0" : "=&d"(r), "+a"(o) /* use d instead of r to avoid a gcc bug */ : "r"(n), "m"(*p) : "cc" ); return r; } static OF_INLINE bool OFAtomicPointerCompareAndSwap(void *volatile _Nullable *_Nonnull p, void *_Nullable o, void *_Nullable n) { int r; __asm__ __volatile__ ( "lock\n\t" "cmpxchg %2, %3\n\t" "sete %b0\n\t" "movzbl %b0, %0" : "=&d"(r), "+a"(o) /* use d instead of r to avoid a gcc bug */ : "r"(n), "m"(*p) : "cc" ); return r; } static OF_INLINE void OFMemoryBarrier(void) { __asm__ __volatile__ ( "mfence" ::: "memory" ); } static OF_INLINE void OFAcquireMemoryBarrier(void) { __asm__ __volatile__ ("" ::: "memory"); } static OF_INLINE void OFReleaseMemoryBarrier(void) { __asm__ __volatile__ ("" ::: "memory"); } OF_ASSUME_NONNULL_END |
Modified src/runtime/Makefile from [7961a820de] to [6dd30f7bce].
︙ | ︙ | |||
28 29 30 31 32 33 34 | protocol.m \ selector.m \ sparsearray.m \ static-instances.m \ synchronized.m \ tagged-pointer.m \ ${USE_SRCS_THREADS} | | > | | < | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | protocol.m \ selector.m \ sparsearray.m \ static-instances.m \ synchronized.m \ tagged-pointer.m \ ${USE_SRCS_THREADS} SRCS_THREADS = OFOnce.m \ OFPlainMutex.m \ OFTLSKey.m \ threading.m INCLUDES = ObjFWRT.h includesubdir = ObjFWRT OBJS_EXTRA = lookup-asm/lookup-asm.a LIB_OBJS_EXTRA = lookup-asm/lookup-asm.lib.a AMIGA_LIB_OBJS_START = amiga-library.amigalib.o AMIGA_LIB_OBJS_EXTRA = amiga-glue.amigalib.o \ |
︙ | ︙ |
Renamed and modified src/runtime/once.m [d69450279b] to src/runtime/OFOnce.m [faf23e6bb2].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "ObjFWRT.h" #import "private.h" | | | 14 15 16 17 18 19 20 21 | */ #include "config.h" #import "ObjFWRT.h" #import "private.h" #include "../OFOnce.m" |
Renamed and modified src/runtime/mutex.m [061a17e697] to src/runtime/OFPlainMutex.m [c27a6b035d].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "ObjFWRT.h" #import "private.h" | | | 14 15 16 17 18 19 20 21 | */ #include "config.h" #import "ObjFWRT.h" #import "private.h" #include "../OFPlainMutex.m" |
Renamed and modified src/runtime/tlskey.m [f580536fe7] to src/runtime/OFTLSKey.m [408a710b0b].
︙ | ︙ | |||
14 15 16 17 18 19 20 | */ #include "config.h" #import "ObjFWRT.h" #import "private.h" | | | 14 15 16 17 18 19 20 21 | */ #include "config.h" #import "ObjFWRT.h" #import "private.h" #include "../OFTLSKey.m" |
Modified src/runtime/ObjFWRT.h from [1456702210] to [4089c697eb].
︙ | ︙ | |||
142 143 144 145 146 147 148 | typedef id _Nullable (*IMP)(id _Nonnull object, SEL _Nonnull selector, ...); /** * @brief A handler for uncaught exceptions. * * @param exception The exception which was not caught. */ | | | | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | typedef id _Nullable (*IMP)(id _Nonnull object, SEL _Nonnull selector, ...); /** * @brief A handler for uncaught exceptions. * * @param exception The exception which was not caught. */ typedef void (*objc_uncaught_exception_handler)(id _Nullable exception); /** * @brief A handler for mutation during enumeration. * * @param object The object that was mutated during enumeration */ typedef void (*objc_enumeration_mutation_handler)(id _Nonnull object); /** * @brief A struct representing a call to super. */ struct objc_super { /** * @brief The object on which to perform the super call. |
︙ | ︙ | |||
516 517 518 519 520 521 522 | * @return A copy of the attribute value. You need to call `free()` on it when * done. */ extern char *_Nullable property_copyAttributeValue( objc_property_t _Nonnull property, const char *_Nonnull name); /** | | | | | | | | 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | * @return A copy of the attribute value. You need to call `free()` on it when * done. */ extern char *_Nullable property_copyAttributeValue( objc_property_t _Nonnull property, const char *_Nonnull name); /** * @brief Deinitializes the Objective-C runtime. * * This frees all data structures used by the runtime, after which Objective-C * can no longer be used inside the current process. This is only useful for * debugging and tests. */ extern void objc_deinit(void); /** * @brief Sets the handler for uncaught exceptions. * * @param handler The new handler for uncaught exceptions * @return The old handler for uncaught exceptions */ extern _Nullable objc_uncaught_exception_handler objc_setUncaughtExceptionHandler( objc_uncaught_exception_handler _Nullable handler); /** * @brief Sets the forwarding handler for unimplemented methods. * * @param forward The forwarding handler for regular methods * @param stretForward The forwarding handler for methods using the struct * return ABI */ extern void objc_setForwardHandler(IMP _Nullable forward, IMP _Nullable stretForward); /** * @brief Sets the handler for mutations during enumeration. * * @param handler The handler for mutations during enumeration */ extern void objc_setEnumerationMutationHandler( objc_enumeration_mutation_handler _Nullable handler); /** * @brief Constructs an instance of the specified class in the specified array * of bytes. * * @param class_ The class of which to construct an instance * @param bytes An array of bytes of at least the length of the instance size. |
︙ | ︙ |
Modified src/runtime/amiga-funcarray.inc from [674e168c3f] to [eca72c7d0a].
︙ | ︙ | |||
75 76 77 78 79 80 81 | (CONST_APTR)glue_protocol_getName, (CONST_APTR)glue_protocol_isEqual, (CONST_APTR)glue_protocol_conformsToProtocol, (CONST_APTR)glue_objc_setUncaughtExceptionHandler, (CONST_APTR)glue_objc_setForwardHandler, (CONST_APTR)glue_objc_setEnumerationMutationHandler, (CONST_APTR)glue_objc_constructInstance, | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | (CONST_APTR)glue_protocol_getName, (CONST_APTR)glue_protocol_isEqual, (CONST_APTR)glue_protocol_conformsToProtocol, (CONST_APTR)glue_objc_setUncaughtExceptionHandler, (CONST_APTR)glue_objc_setForwardHandler, (CONST_APTR)glue_objc_setEnumerationMutationHandler, (CONST_APTR)glue_objc_constructInstance, (CONST_APTR)glue_objc_deinit, (CONST_APTR)glue_class_copyIvarList, (CONST_APTR)glue_ivar_getName, (CONST_APTR)glue_ivar_getTypeEncoding, (CONST_APTR)glue_ivar_getOffset, (CONST_APTR)glue_class_copyMethodList, (CONST_APTR)glue_method_getName, (CONST_APTR)glue_method_getTypeEncoding, |
︙ | ︙ |
Modified src/runtime/amiga-glue.h from [51945d63f3] to [2ca426ebf9].
︙ | ︙ | |||
84 85 86 87 88 89 90 | extern IMP _Nullable glue_class_replaceMethod PPC_PARAMS(Class _Nonnull class, SEL _Nonnull selector, IMP _Nonnull implementation, const char *_Nullable typeEncoding); extern Class _Nullable glue_object_getClass PPC_PARAMS(id _Nullable object); extern Class _Nullable glue_object_setClass PPC_PARAMS(id _Nullable object, Class _Nonnull class); extern const char *_Nullable glue_object_getClassName PPC_PARAMS(id _Nullable object); extern const char *_Nonnull glue_protocol_getName PPC_PARAMS(Protocol *_Nonnull protocol); extern bool glue_protocol_isEqual PPC_PARAMS(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2); extern bool glue_protocol_conformsToProtocol PPC_PARAMS(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2); | | | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | extern IMP _Nullable glue_class_replaceMethod PPC_PARAMS(Class _Nonnull class, SEL _Nonnull selector, IMP _Nonnull implementation, const char *_Nullable typeEncoding); extern Class _Nullable glue_object_getClass PPC_PARAMS(id _Nullable object); extern Class _Nullable glue_object_setClass PPC_PARAMS(id _Nullable object, Class _Nonnull class); extern const char *_Nullable glue_object_getClassName PPC_PARAMS(id _Nullable object); extern const char *_Nonnull glue_protocol_getName PPC_PARAMS(Protocol *_Nonnull protocol); extern bool glue_protocol_isEqual PPC_PARAMS(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2); extern bool glue_protocol_conformsToProtocol PPC_PARAMS(Protocol *_Nonnull protocol1, Protocol *_Nonnull protocol2); extern _Nullable objc_uncaught_exception_handler glue_objc_setUncaughtExceptionHandler PPC_PARAMS(objc_uncaught_exception_handler _Nullable handler); extern void glue_objc_setForwardHandler PPC_PARAMS(IMP _Nullable forward, IMP _Nullable stretForward); extern void glue_objc_setEnumerationMutationHandler PPC_PARAMS(objc_enumeration_mutation_handler _Nullable hadler); extern id _Nullable glue_objc_constructInstance PPC_PARAMS(Class _Nullable class, void *_Nullable bytes); extern void glue_objc_deinit(void); extern Ivar _Nullable *_Nullable glue_class_copyIvarList PPC_PARAMS(Class _Nullable class, unsigned int *_Nullable outCount); extern const char *_Nonnull glue_ivar_getName PPC_PARAMS(Ivar _Nonnull ivar); extern const char *_Nonnull glue_ivar_getTypeEncoding PPC_PARAMS(Ivar _Nonnull ivar); extern ptrdiff_t glue_ivar_getOffset PPC_PARAMS(Ivar _Nonnull ivar); extern Method _Nullable *_Nullable glue_class_copyMethodList PPC_PARAMS(Class _Nullable class, unsigned int *_Nullable outCount); extern SEL _Nonnull glue_method_getName PPC_PARAMS(Method _Nonnull method); extern const char *_Nullable glue_method_getTypeEncoding PPC_PARAMS(Method _Nonnull method); |
︙ | ︙ |
Modified src/runtime/amiga-glue.m from [fef86ecf8c] to [7d3bd6cbde].
︙ | ︙ | |||
554 555 556 557 558 559 560 | { M68K_ARG(Protocol *_Nonnull, protocol1, a0) M68K_ARG(Protocol *_Nonnull, protocol2, a1) return protocol_conformsToProtocol(protocol1, protocol2); } | | | | | | | | | 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | { M68K_ARG(Protocol *_Nonnull, protocol1, a0) M68K_ARG(Protocol *_Nonnull, protocol2, a1) return protocol_conformsToProtocol(protocol1, protocol2); } _Nullable objc_uncaught_exception_handler __saveds glue_objc_setUncaughtExceptionHandler PPC_PARAMS(objc_uncaught_exception_handler _Nullable handler) { M68K_ARG(objc_uncaught_exception_handler _Nullable, handler, a0) return objc_setUncaughtExceptionHandler(handler); } void __saveds glue_objc_setForwardHandler PPC_PARAMS(IMP _Nullable forward, IMP _Nullable stretForward) { M68K_ARG(IMP _Nullable, forward, a0) M68K_ARG(IMP _Nullable, stretForward, a1) objc_setForwardHandler(forward, stretForward); } void __saveds glue_objc_setEnumerationMutationHandler PPC_PARAMS(objc_enumeration_mutation_handler _Nullable hadler) { M68K_ARG(objc_enumeration_mutation_handler _Nullable, hadler, a0) objc_setEnumerationMutationHandler(hadler); } id _Nullable __saveds glue_objc_constructInstance PPC_PARAMS(Class _Nullable class, void *_Nullable bytes) { M68K_ARG(Class _Nullable, class, a0) M68K_ARG(void *_Nullable, bytes, a1) return objc_constructInstance(class, bytes); } void __saveds glue_objc_deinit(void) { objc_deinit(); } Ivar _Nullable *_Nullable __saveds glue_class_copyIvarList PPC_PARAMS(Class _Nullable class, unsigned int *_Nullable outCount) { M68K_ARG(Class _Nullable, class, a0) M68K_ARG(unsigned int *_Nullable, outCount, a1) |
︙ | ︙ |
Deleted src/runtime/amigaos3.sfd version [27d28cf09f].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/runtime/arc.m from [eaae2aa32a] to [1147559114].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS | | | | | | 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 | #include "config.h" #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" #endif struct WeakRef { id **locations; size_t count; }; static struct objc_hashtable *hashtable; #ifdef OF_HAVE_THREADS static OFSpinlock spinlock; #endif static uint32_t hash(const void *object) { return (uint32_t)(uintptr_t)object; } static bool equal(const void *object1, const void *object2) { return (object1 == object2); } OF_CONSTRUCTOR() { hashtable = objc_hashtable_new(hash, equal, 2); #ifdef OF_HAVE_THREADS if (OFSpinlockNew(&spinlock) != 0) OBJC_ERROR("Failed to create spinlock!"); #endif } id objc_retain(id object) { |
︙ | ︙ | |||
113 114 115 116 117 118 119 | return value; } id objc_storeWeak(id *object, id value) { | | | | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | return value; } id objc_storeWeak(id *object, id value) { struct WeakRef *old; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*object != nil && (old = objc_hashtable_get(hashtable, *object)) != NULL) { for (size_t i = 0; i < old->count; i++) { if (old->locations[i] == object) { |
︙ | ︙ | |||
151 152 153 154 155 156 157 | break; } } } if (value != nil && class_respondsToSelector(object_getClass(value), @selector(allowsWeakReference)) && [value allowsWeakReference]) { | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | break; } } } if (value != nil && class_respondsToSelector(object_getClass(value), @selector(allowsWeakReference)) && [value allowsWeakReference]) { struct WeakRef *ref = objc_hashtable_get(hashtable, value); if (ref == NULL) { if ((ref = calloc(1, sizeof(*ref))) == NULL) OBJC_ERROR("Not enough memory to allocate weak " "reference!"); objc_hashtable_set(hashtable, value, ref); |
︙ | ︙ | |||
173 174 175 176 177 178 179 | ref->locations[ref->count++] = object; } else value = nil; *object = value; #ifdef OF_HAVE_THREADS | | | | | | 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | ref->locations[ref->count++] = object; } else value = nil; *object = value; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif return value; } id objc_loadWeakRetained(id *object) { id value = nil; struct WeakRef *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*object != nil && (ref = objc_hashtable_get(hashtable, *object)) != NULL) value = *object; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif if (class_respondsToSelector(object_getClass(value), @selector(retainWeakReference)) && [value retainWeakReference]) return value; |
︙ | ︙ | |||
235 236 237 238 239 240 241 | { objc_release(objc_initWeak(dest, objc_loadWeakRetained(src))); } void objc_moveWeak(id *dest, id *src) { | | | | | | | | | 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | { objc_release(objc_initWeak(dest, objc_loadWeakRetained(src))); } void objc_moveWeak(id *dest, id *src) { struct WeakRef *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if (*src != nil && (ref = objc_hashtable_get(hashtable, *src)) != NULL) { for (size_t i = 0; i < ref->count; i++) { if (ref->locations[i] == src) { ref->locations[i] = dest; break; } } } *dest = *src; *src = nil; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } void objc_zeroWeakReferences(id value) { struct WeakRef *ref; #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&spinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif if ((ref = objc_hashtable_get(hashtable, value)) != NULL) { for (size_t i = 0; i < ref->count; i++) *ref->locations[i] = nil; objc_hashtable_delete(hashtable, value); free(ref->locations); free(ref); } #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } |
Modified src/runtime/autorelease.m from [cddc441815] to [c90ec8958a].
︙ | ︙ | |||
23 24 25 26 27 28 29 | # import "private.h" #else # import <objc/runtime.h> #endif #import "macros.h" #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) | | | | < | > | | | | | | | > | > | | | < | > | | > | > | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | # import "private.h" #else # import <objc/runtime.h> #endif #import "macros.h" #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) # import "OFTLSKey.h" #endif #ifndef OF_OBJFW_RUNTIME @interface DummyObject - (void)release; @end #endif #if defined(OF_HAVE_COMPILER_TLS) static thread_local id *objects = NULL; static thread_local uintptr_t count = 0; static thread_local uintptr_t size = 0; #elif defined(OF_HAVE_THREADS) static OFTLSKey objectsKey, countKey, sizeKey; #else static id *objects = NULL; static uintptr_t count = 0; static uintptr_t size = 0; #endif #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OF_CONSTRUCTOR() { if (OFTLSKeyNew(&objectsKey) != 0 || OFTLSKeyNew(&countKey) != 0 || OFTLSKeyNew(&sizeKey) != 0) OBJC_ERROR("Failed to create TLS keys!"); } #endif void * objc_autoreleasePoolPush() { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey); #endif return (void *)count; } void objc_autoreleasePoolPop(void *pool) { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) id *objects = OFTLSKeyGet(objectsKey); uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey); #endif uintptr_t idx = (uintptr_t)pool; bool freeMem = false; if (idx == (uintptr_t)-1) { idx++; freeMem = true; } for (uintptr_t i = idx; i < count; i++) { [objects[i] release]; #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) objects = OFTLSKeyGet(objectsKey); count = (uintptr_t)OFTLSKeyGet(countKey); #endif } count = idx; if (freeMem) { free(objects); objects = NULL; #if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS) size = 0; #else if (OFTLSKeySet(objectsKey, objects) != 0 || OFTLSKeySet(sizeKey, (void *)0) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif } #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) if (OFTLSKeySet(countKey, (void *)count) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif } id _objc_rootAutorelease(id object) { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) id *objects = OFTLSKeyGet(objectsKey); uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey); uintptr_t size = (uintptr_t)OFTLSKeyGet(sizeKey); #endif if (count >= size) { if (size == 0) size = 16; else size *= 2; if ((objects = realloc(objects, size * sizeof(id))) == NULL) OBJC_ERROR("Failed to resize autorelease pool!"); #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) if (OFTLSKeySet(objectsKey, objects) != 0 || OFTLSKeySet(sizeKey, (void *)size) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif } objects[count++] = object; #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) if (OFTLSKeySet(countKey, (void *)count) != 0) OBJC_ERROR("Failed to set TLS key!"); #endif return object; } |
Modified src/runtime/category.m from [e672c2edf4] to [5b97638d56].
︙ | ︙ | |||
28 29 30 31 32 33 34 | registerSelectors(struct objc_category *category) { struct objc_method_list *iter; unsigned int i; for (iter = category->instanceMethods; iter != NULL; iter = iter->next) for (i = 0; i < iter->count; i++) | | | | | | 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 | registerSelectors(struct objc_category *category) { struct objc_method_list *iter; unsigned int i; for (iter = category->instanceMethods; iter != NULL; iter = iter->next) for (i = 0; i < iter->count; i++) objc_registerSelector(&iter->methods[i].selector); for (iter = category->classMethods; iter != NULL; iter = iter->next) for (i = 0; i < iter->count; i++) objc_registerSelector(&iter->methods[i].selector); } static void registerCategory(struct objc_category *category) { struct objc_category **categories; Class class = objc_classnameToClass(category->className, false); if (categoriesMap == NULL) categoriesMap = objc_hashtable_new( objc_string_hash, objc_string_equal, 2); categories = (struct objc_category **)objc_hashtable_get( categoriesMap, category->className); if (categories != NULL) { struct objc_category **newCategories; size_t i; |
︙ | ︙ | |||
66 67 68 69 70 71 72 | newCategories[i] = category; newCategories[i + 1] = NULL; objc_hashtable_set(categoriesMap, category->className, newCategories); if (class != Nil && class->info & OBJC_CLASS_INFO_SETUP) { | | | | | | | | | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | newCategories[i] = category; newCategories[i + 1] = NULL; objc_hashtable_set(categoriesMap, category->className, newCategories); if (class != Nil && class->info & OBJC_CLASS_INFO_SETUP) { objc_updateDTable(class); objc_updateDTable(class->isa); } return; } if ((categories = malloc(2 * sizeof(*categories))) == NULL) OBJC_ERROR("Not enough memory for category %s of class %s!\n", category->categoryName, category->className); categories[0] = category; categories[1] = NULL; objc_hashtable_set(categoriesMap, category->className, categories); if (class != Nil && class->info & OBJC_CLASS_INFO_SETUP) { objc_updateDTable(class); objc_updateDTable(class->isa); } } void objc_registerAllCategories(struct objc_symtab *symtab) { struct objc_category **categories = (struct objc_category **)symtab->defs + symtab->classDefsCount; for (size_t i = 0; i < symtab->categoryDefsCount; i++) { registerSelectors(categories[i]); registerCategory(categories[i]); } } struct objc_category ** objc_categoriesForClass(Class class) { if (categoriesMap == NULL) return NULL; return (struct objc_category **)objc_hashtable_get(categoriesMap, class->name); } void objc_unregisterAllCategories(void) { if (categoriesMap == NULL) return; for (uint32_t i = 0; i < categoriesMap->size; i++) if (categoriesMap->data[i] != NULL) free((void *)categoriesMap->data[i]->object); objc_hashtable_free(categoriesMap); categoriesMap = NULL; } |
Modified src/runtime/class.m from [8c93de1488] to [8556b52111].
︙ | ︙ | |||
32 33 34 35 36 37 38 | static struct objc_sparsearray *fastPath = NULL; static void registerClass(Class class) { if (classes == NULL) classes = objc_hashtable_new( | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | static struct objc_sparsearray *fastPath = NULL; static void registerClass(Class class) { if (classes == NULL) classes = objc_hashtable_new( objc_string_hash, objc_string_equal, 2); objc_hashtable_set(classes, class->name, class); if (emptyDTable == NULL) emptyDTable = objc_dtable_new(); class->dTable = emptyDTable; class->isa->dTable = emptyDTable; if (strcmp(class->name, "Protocol") != 0) classesCount++; } bool class_registerAlias_np(Class class, const char *name) { objc_globalMutex_lock(); if (classes == NULL) { objc_globalMutex_unlock(); return NO; } objc_hashtable_set(classes, name, (Class)((uintptr_t)class | 1)); objc_globalMutex_unlock(); return YES; } static void registerSelectors(Class class) { struct objc_method_list *iter; unsigned int i; for (iter = class->methodList; iter != NULL; iter = iter->next) for (i = 0; i < iter->count; i++) objc_registerSelector(&iter->methods[i].selector); } Class objc_classnameToClass(const char *name, bool cache) { Class class; if (classes == NULL) return Nil; /* |
︙ | ︙ | |||
111 112 113 114 115 116 117 | if (cache && fastPath != NULL) { class = objc_sparsearray_get(fastPath, (uintptr_t)name); if (class != Nil) return class; } | | | | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | if (cache && fastPath != NULL) { class = objc_sparsearray_get(fastPath, (uintptr_t)name); if (class != Nil) return class; } objc_globalMutex_lock(); class = (Class)((uintptr_t)objc_hashtable_get(classes, name) & ~1); if (cache && fastPath == NULL && --lookupsUntilFastPath == 0) fastPath = objc_sparsearray_new(sizeof(uintptr_t)); if (cache && fastPath != NULL) objc_sparsearray_set(fastPath, (uintptr_t)name, class); objc_globalMutex_unlock(); return class; } static void callSelector(Class class, SEL selector) { |
︙ | ︙ | |||
176 177 178 179 180 181 182 | callSelector(class, loadSel); class->info |= OBJC_CLASS_INFO_LOADED; } void | | | | | | | | | | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | callSelector(class, loadSel); class->info |= OBJC_CLASS_INFO_LOADED; } void objc_updateDTable(Class class) { struct objc_category **categories; if (!(class->info & OBJC_CLASS_INFO_DTABLE)) return; if (class->dTable == emptyDTable) class->dTable = objc_dtable_new(); if (class->superclass != Nil) objc_dtable_copy(class->dTable, class->superclass->dTable); for (struct objc_method_list *methodList = class->methodList; methodList != NULL; methodList = methodList->next) for (unsigned int i = 0; i < methodList->count; i++) objc_dtable_set(class->dTable, (uint32_t)methodList->methods[i].selector.UID, methodList->methods[i].implementation); if ((categories = objc_categoriesForClass(class)) != NULL) { for (unsigned int i = 0; categories[i] != NULL; i++) { struct objc_method_list *methodList = (class->info & OBJC_CLASS_INFO_CLASS ? categories[i]->instanceMethods : categories[i]->classMethods); for (; methodList != NULL; methodList = methodList->next) for (unsigned int j = 0; j < methodList->count; j++) objc_dtable_set(class->dTable, (uint32_t)methodList->methods[j] .selector.UID, methodList->methods[j] .implementation); } } if (class->subclassList != NULL) for (Class *iter = class->subclassList; *iter != NULL; iter++) objc_updateDTable(*iter); } static void addSubclass(Class class) { size_t i; |
︙ | ︙ | |||
278 279 280 281 282 283 284 | } } else for (unsigned int i = 0; i < class->ivars->count; i++) *class->ivarOffsets[i] = class->ivars->ivars[i].offset; } static void | | | | | 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | } } else for (unsigned int i = 0; i < class->ivars->count; i++) *class->ivarOffsets[i] = class->ivars->ivars[i].offset; } static void setUpClass(Class class) { const char *superclassName; if (class->info & OBJC_CLASS_INFO_SETUP) return; superclassName = (const char *)class->superclass; if (superclassName != NULL) { Class super = objc_classnameToClass(superclassName, false); Class rootClass; if (super == Nil) return; setUpClass(super); if (!(super->info & OBJC_CLASS_INFO_SETUP)) return; /* * GCC sets class->isa->isa to the name of the root class, * while Clang just sets it to Nil. Therefore always calculate |
︙ | ︙ | |||
347 348 349 350 351 352 353 | */ if (class->info & OBJC_CLASS_INFO_INITIALIZED) return; class->info |= OBJC_CLASS_INFO_DTABLE; class->isa->info |= OBJC_CLASS_INFO_DTABLE; | | | | 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | */ if (class->info & OBJC_CLASS_INFO_INITIALIZED) return; class->info |= OBJC_CLASS_INFO_DTABLE; class->isa->info |= OBJC_CLASS_INFO_DTABLE; objc_updateDTable(class); objc_updateDTable(class->isa); /* * Set it first to prevent calling it recursively due to message sends * in the initialize method */ class->info |= OBJC_CLASS_INFO_INITIALIZED; class->isa->info |= OBJC_CLASS_INFO_INITIALIZED; |
︙ | ︙ | |||
371 372 373 374 375 376 377 | objc_msg_lookup(class, initializeSel); initialize(class, initializeSel); } } void | | | | | | | | | 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | objc_msg_lookup(class, initializeSel); initialize(class, initializeSel); } } void objc_initializeClass(Class class) { if (class->info & OBJC_CLASS_INFO_INITIALIZED) return; objc_globalMutex_lock(); /* * It's possible that two threads try to initialize a class at the same * time. Make sure that the thread which held the lock did not already * initialize it. */ if (class->info & OBJC_CLASS_INFO_INITIALIZED) { objc_globalMutex_unlock(); return; } setUpClass(class); if (!(class->info & OBJC_CLASS_INFO_SETUP)) { objc_globalMutex_unlock(); return; } initializeClass(class); objc_globalMutex_unlock(); } static void processLoadQueue() { for (size_t i = 0; i < loadQueueCount; i++) { setUpClass(loadQueue[i]); if (loadQueue[i]->info & OBJC_CLASS_INFO_SETUP) { callLoad(loadQueue[i]); loadQueueCount--; if (loadQueueCount == 0) { |
︙ | ︙ | |||
429 430 431 432 433 434 435 | if (loadQueue == NULL) OBJC_ERROR("Not enough memory for load queue!"); } } } void | | | | 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | if (loadQueue == NULL) OBJC_ERROR("Not enough memory for load queue!"); } } } void objc_registerAllClasses(struct objc_symtab *symtab) { for (uint16_t i = 0; i < symtab->classDefsCount; i++) { Class class = (Class)symtab->defs[i]; registerClass(class); registerSelectors(class); registerSelectors(class->isa); } for (uint16_t i = 0; i < symtab->classDefsCount; i++) { Class class = (Class)symtab->defs[i]; if (hasLoad(class)) { setUpClass(class); if (class->info & OBJC_CLASS_INFO_SETUP) callLoad(class); else { loadQueue = realloc(loadQueue, sizeof(Class) * (loadQueueCount + 1)); |
︙ | ︙ | |||
470 471 472 473 474 475 476 | Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes) { struct objc_class *class, *metaclass; Class iter, rootclass = Nil; | < < < | > > > > > > | | | | | | | 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | Class objc_allocateClassPair(Class superclass, const char *name, size_t extraBytes) { struct objc_class *class, *metaclass; Class iter, rootclass = Nil; if ((class = calloc(1, sizeof(*class))) == NULL || (metaclass = calloc(1, sizeof(*class))) == NULL) OBJC_ERROR("Not enough memory to allocate class pair for class " "%s!", name); class->isa = metaclass; class->superclass = superclass; class->name = name; class->info = OBJC_CLASS_INFO_CLASS; class->instanceSize = (superclass != Nil ? superclass->instanceSize : 0); if (extraBytes > LONG_MAX || LONG_MAX - class->instanceSize < (long)extraBytes) OBJC_ERROR("extraBytes too large!"); class->instanceSize += (long)extraBytes; for (iter = superclass; iter != Nil; iter = iter->superclass) rootclass = iter; metaclass->isa = (rootclass != Nil ? rootclass->isa : class); metaclass->superclass = (superclass != Nil ? superclass->isa : Nil); metaclass->name = name; metaclass->info = OBJC_CLASS_INFO_CLASS; metaclass->instanceSize = (superclass != Nil ? superclass->isa->instanceSize : 0) + (long)extraBytes; return class; } void objc_registerClassPair(Class class) { objc_globalMutex_lock(); registerClass(class); if (class->superclass != Nil) { addSubclass(class); addSubclass(class->isa); } class->info |= OBJC_CLASS_INFO_SETUP; class->isa->info |= OBJC_CLASS_INFO_SETUP; if (hasLoad(class)) callLoad(class); else class->info |= OBJC_CLASS_INFO_LOADED; processLoadQueue(); objc_globalMutex_unlock(); } Class objc_lookUpClass(const char *name) { Class class; if ((class = objc_classnameToClass(name, true)) == NULL) return Nil; if (class->info & OBJC_CLASS_INFO_SETUP) return class; objc_globalMutex_lock(); setUpClass(class); objc_globalMutex_unlock(); if (!(class->info & OBJC_CLASS_INFO_SETUP)) return Nil; return class; } |
︙ | ︙ | |||
579 580 581 582 583 584 585 | return objc_getRequiredClass(name); } unsigned int objc_getClassList(Class *buffer, unsigned int count) { unsigned int j; | | | | | | > | | 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 | return objc_getRequiredClass(name); } unsigned int objc_getClassList(Class *buffer, unsigned int count) { unsigned int j; objc_globalMutex_lock(); if (buffer == NULL) return classesCount; if (classesCount < count) count = classesCount; j = 0; for (uint32_t i = 0; i < classes->size; i++) { void *class; if (j >= count) { objc_globalMutex_unlock(); return j; } if (classes->data[i] == NULL) continue; if (strcmp(classes->data[i]->key, "Protocol") == 0) continue; class = (Class)classes->data[i]->object; if (class == Nil || (uintptr_t)class & 1) continue; buffer[j++] = class; } objc_globalMutex_unlock(); return j; } Class * objc_copyClassList(unsigned int *length) { Class *ret; unsigned int count; objc_globalMutex_lock(); if ((ret = malloc((classesCount + 1) * sizeof(Class))) == NULL) OBJC_ERROR("Failed to allocate memory for class list!"); count = objc_getClassList(ret, classesCount); if (count != classesCount) OBJC_ERROR("Fatal internal inconsistency!"); ret[count] = Nil; if (length != NULL) *length = count; objc_globalMutex_unlock(); return ret; } bool class_isMetaClass(Class class) { |
︙ | ︙ | |||
722 723 724 725 726 727 728 | } static struct objc_method * getMethod(Class class, SEL selector) { struct objc_category **categories; | | | 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 | } static struct objc_method * getMethod(Class class, SEL selector) { struct objc_category **categories; if ((categories = objc_categoriesForClass(class)) != NULL) { for (; *categories != NULL; categories++) { struct objc_method_list *methodList = (class->info & OBJC_CLASS_INFO_METACLASS ? (*categories)->classMethods : (*categories)->instanceMethods); for (; methodList != NULL; |
︙ | ︙ | |||
756 757 758 759 760 761 762 | static void addMethod(Class class, SEL selector, IMP implementation, const char *typeEncoding) { struct objc_method_list *methodList; | | | | | | | | | | | | 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 | static void addMethod(Class class, SEL selector, IMP implementation, const char *typeEncoding) { struct objc_method_list *methodList; /* FIXME: We need a way to free this at objc_deinit() */ if ((methodList = malloc(sizeof(*methodList))) == NULL) OBJC_ERROR("Not enough memory to replace method!"); methodList->next = class->methodList; methodList->count = 1; methodList->methods[0].selector.UID = selector->UID; methodList->methods[0].selector.typeEncoding = typeEncoding; methodList->methods[0].implementation = implementation; class->methodList = methodList; objc_updateDTable(class); } Method class_getInstanceMethod(Class class, SEL selector) { Method method; Class superclass; if (class == Nil) return NULL; objc_globalMutex_lock(); if ((method = getMethod(class, selector)) != NULL) { objc_globalMutex_unlock(); return method; } superclass = class->superclass; objc_globalMutex_unlock(); if (superclass != Nil) return class_getInstanceMethod(superclass, selector); return NULL; } bool class_addMethod(Class class, SEL selector, IMP implementation, const char *typeEncoding) { bool ret; objc_globalMutex_lock(); if (getMethod(class, selector) == NULL) { addMethod(class, selector, implementation, typeEncoding); ret = true; } else ret = false; objc_globalMutex_unlock(); return ret; } IMP class_replaceMethod(Class class, SEL selector, IMP implementation, const char *typeEncoding) { struct objc_method *method; IMP oldImplementation; objc_globalMutex_lock(); if ((method = getMethod(class, selector)) != NULL) { oldImplementation = method->implementation; method->implementation = implementation; objc_updateDTable(class); } else { oldImplementation = NULL; addMethod(class, selector, implementation, typeEncoding); } objc_globalMutex_unlock(); return oldImplementation; } Class object_getClass(id object_) { |
︙ | ︙ | |||
910 911 912 913 914 915 916 | } if (class->subclassList != NULL) { free(class->subclassList); class->subclassList = NULL; } | | | | | > > | > > | | | | > | 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 | } if (class->subclassList != NULL) { free(class->subclassList); class->subclassList = NULL; } if (class->dTable != NULL && class->dTable != emptyDTable) objc_dtable_free(class->dTable); class->dTable = NULL; if ((class->info & OBJC_CLASS_INFO_SETUP) && class->superclass != Nil) class->superclass = (Class)class->superclass->name; class->info &= ~OBJC_CLASS_INFO_SETUP; } void objc_unregisterClass(Class class) { static SEL unloadSel = NULL; objc_globalMutex_lock(); if (unloadSel == NULL) unloadSel = sel_registerName("unload"); while (class->subclassList != NULL && class->subclassList[0] != Nil) objc_unregisterClass(class->subclassList[0]); if (class->info & OBJC_CLASS_INFO_LOADED) callSelector(class, unloadSel); objc_hashtable_delete(classes, class->name); if (strcmp(class_getName(class), "Protocol") != 0) classesCount--; unregisterClass(class); unregisterClass(class->isa); objc_globalMutex_unlock(); } void objc_unregisterAllClasses(void) { if (classes == NULL) return; for (uint32_t i = 0; i < classes->size; i++) { if (classes->data[i] != NULL && classes->data[i] != &objc_deletedBucket) { void *class = (Class)classes->data[i]->object; if (class == Nil || (uintptr_t)class & 1) continue; objc_unregisterClass(class); /* * The table might have been resized, so go back to the * start again. * * Due to the i++ in the for loop, we need to set it to * UINT32_MAX so that it will get increased at the end * of the loop and thus become 0. */ i = UINT32_MAX; } } if (classesCount != 0) OBJC_ERROR("Fatal internal inconsistency!"); if (emptyDTable != NULL) { objc_dtable_free(emptyDTable); emptyDTable = NULL; } objc_sparsearray_free(fastPath); fastPath = NULL; objc_hashtable_free(classes); classes = NULL; } |
Modified src/runtime/dtable.m from [d61b5652b8] to [fe23892d25].
︙ | ︙ | |||
26 27 28 29 30 31 32 | static struct objc_dtable_level3 *emptyLevel3 = NULL; #endif static void init(void) { if ((emptyLevel2 = malloc(sizeof(*emptyLevel2))) == NULL) | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | static struct objc_dtable_level3 *emptyLevel3 = NULL; #endif static void init(void) { if ((emptyLevel2 = malloc(sizeof(*emptyLevel2))) == NULL) OBJC_ERROR("Not enough memory to allocate dispatch table!"); #ifdef OF_SELUID24 if ((emptyLevel3 = malloc(sizeof(*emptyLevel3))) == NULL) OBJC_ERROR("Not enough memory to allocate dispatch table!"); #endif #ifdef OF_SELUID24 for (uint_fast16_t i = 0; i < 256; i++) { emptyLevel2->buckets[i] = emptyLevel3; emptyLevel3->buckets[i] = (IMP)0; } #else for (uint_fast16_t i = 0; i < 256; i++) emptyLevel2->buckets[i] = (IMP)0; #endif } struct objc_dtable * objc_dtable_new(void) { struct objc_dtable *dTable; #ifdef OF_SELUID24 if (emptyLevel2 == NULL || emptyLevel3 == NULL) init(); #else if (emptyLevel2 == NULL) init(); #endif if ((dTable = malloc(sizeof(*dTable))) == NULL) OBJC_ERROR("Not enough memory to allocate dispatch table!"); for (uint_fast16_t i = 0; i < 256; i++) dTable->buckets[i] = emptyLevel2; return dTable; } void objc_dtable_copy(struct objc_dtable *dest, struct objc_dtable *src) { for (uint_fast16_t i = 0; i < 256; i++) { if (src->buckets[i] == emptyLevel2) |
︙ | ︙ | |||
109 110 111 112 113 114 115 | objc_dtable_set(dest, idx, implementation); } #endif } } void | | | | > | | | > | | | | | | | | | | 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | objc_dtable_set(dest, idx, implementation); } #endif } } void objc_dtable_set(struct objc_dtable *dTable, uint32_t idx, IMP implementation) { #ifdef OF_SELUID24 uint8_t i = idx >> 16; uint8_t j = idx >> 8; uint8_t k = idx; #else uint8_t i = idx >> 8; uint8_t j = idx; #endif if (dTable->buckets[i] == emptyLevel2) { struct objc_dtable_level2 *level2 = malloc(sizeof(*level2)); if (level2 == NULL) OBJC_ERROR("Not enough memory to insert into " "dispatch table!"); for (uint_fast16_t l = 0; l < 256; l++) #ifdef OF_SELUID24 level2->buckets[l] = emptyLevel3; #else level2->buckets[l] = (IMP)0; #endif dTable->buckets[i] = level2; } #ifdef OF_SELUID24 if (dTable->buckets[i]->buckets[j] == emptyLevel3) { struct objc_dtable_level3 *level3 = malloc(sizeof(*level3)); if (level3 == NULL) OBJC_ERROR("Not enough memory to insert into " "dispatch table!"); for (uint_fast16_t l = 0; l < 256; l++) level3->buckets[l] = (IMP)0; dTable->buckets[i]->buckets[j] = level3; } dTable->buckets[i]->buckets[j]->buckets[k] = implementation; #else dTable->buckets[i]->buckets[j] = implementation; #endif } void objc_dtable_free(struct objc_dtable *dTable) { for (uint_fast16_t i = 0; i < 256; i++) { if (dTable->buckets[i] == emptyLevel2) continue; #ifdef OF_SELUID24 for (uint_fast16_t j = 0; j < 256; j++) if (dTable->buckets[i]->buckets[j] != emptyLevel3) free(dTable->buckets[i]->buckets[j]); #endif free(dTable->buckets[i]); } free(dTable); } void objc_dtable_cleanup(void) { if (emptyLevel2 != NULL) free(emptyLevel2); |
︙ | ︙ |
Modified src/runtime/exception.m from [5b9f454f5d] to [b58329f870].
︙ | ︙ | |||
22 23 24 25 26 27 28 | #include <string.h> #import "ObjFWRT.h" #import "private.h" #import "macros.h" #ifdef OF_HAVE_THREADS | | | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <string.h> #import "ObjFWRT.h" #import "private.h" #import "macros.h" #ifdef OF_HAVE_THREADS # include "OFPlainMutex.h" #endif #ifdef HAVE_SEH_EXCEPTIONS # include <windows.h> #endif #if defined(HAVE_DWARF_EXCEPTIONS) |
︙ | ︙ | |||
65 66 67 68 69 70 71 | # define CALL_PERSONALITY(func) func(state, ex, ctx) #endif #define GNUCOBJC_EXCEPTION_CLASS UINT64_C(0x474E55434F424A43) /* GNUCOBJC */ #define GNUCCXX0_EXCEPTION_CLASS UINT64_C(0x474E5543432B2B00) /* GNUCC++\0 */ #define CLNGCXX0_EXCEPTION_CLASS UINT64_C(0x434C4E47432B2B00) /* CLNGC++\0 */ | | > | | | | > > | | | | | | | | | | | | | | | | | > > | | > | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | # define CALL_PERSONALITY(func) func(state, ex, ctx) #endif #define GNUCOBJC_EXCEPTION_CLASS UINT64_C(0x474E55434F424A43) /* GNUCOBJC */ #define GNUCCXX0_EXCEPTION_CLASS UINT64_C(0x474E5543432B2B00) /* GNUCC++\0 */ #define CLNGCXX0_EXCEPTION_CLASS UINT64_C(0x434C4E47432B2B00) /* CLNGC++\0 */ #define numEmergencyExceptions 4 enum { _UA_SEARCH_PHASE = 0x01, _UA_CLEANUP_PHASE = 0x02, _UA_HANDLER_FRAME = 0x04, _UA_FORCE_UNWIND = 0x08 }; enum { DW_EH_PE_absptr = 0x00, DW_EH_PE_uleb128 = 0x01, DW_EH_PE_udata2 = 0x02, DW_EH_PE_udata4 = 0x03, DW_EH_PE_udata8 = 0x04, DW_EH_PE_signed = 0x08, DW_EH_PE_sleb128 = (DW_EH_PE_signed | DW_EH_PE_uleb128), DW_EH_PE_sdata2 = (DW_EH_PE_signed | DW_EH_PE_udata2), DW_EH_PE_sdata4 = (DW_EH_PE_signed | DW_EH_PE_udata4), DW_EH_PE_sdata8 = (DW_EH_PE_signed | DW_EH_PE_udata8), DW_EH_PE_pcrel = 0x10, DW_EH_PE_textrel = 0x20, DW_EH_PE_datarel = 0x30, DW_EH_PE_funcrel = 0x40, DW_EH_PE_aligned = 0x50, DW_EH_PE_indirect = 0x80, DW_EH_PE_omit = 0xFF }; enum { CLEANUP_FOUND = 0x01, HANDLER_FOUND = 0x02 }; struct _Unwind_Context; typedef enum { _URC_OK = 0, _URC_FATAL_PHASE1_ERROR = 3, _URC_END_OF_STACK = 5, |
︙ | ︙ | |||
154 155 156 157 158 159 160 | id object; #ifndef HAVE_ARM_EHABI_EXCEPTIONS uintptr_t landingpad; intptr_t filter; #endif }; | | | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | id object; #ifndef HAVE_ARM_EHABI_EXCEPTIONS uintptr_t landingpad; intptr_t filter; #endif }; struct LSDA { uintptr_t regionStart, landingpadsStart; uint8_t typesTableEnc; const uint8_t *typesTable; uintptr_t typesTableBase; uint8_t callsitesEnc; const uint8_t *callsites, *actionTable; }; |
︙ | ︙ | |||
235 236 237 238 239 240 241 | #ifdef HAVE_SEH_EXCEPTIONS extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT, PDISPATCHER_CONTEXT, _Unwind_Reason_Code (*)(int, int, uint64_t, struct _Unwind_Exception *, struct _Unwind_Context *)); #endif | | | | | | | 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | #ifdef HAVE_SEH_EXCEPTIONS extern EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD, void *, PCONTEXT, PDISPATCHER_CONTEXT, _Unwind_Reason_Code (*)(int, int, uint64_t, struct _Unwind_Exception *, struct _Unwind_Context *)); #endif static objc_uncaught_exception_handler uncaughtExceptionHandler; static struct objc_exception emergencyExceptions[numEmergencyExceptions]; #ifdef OF_HAVE_THREADS static OFSpinlock emergencyExceptionsSpinlock; OF_CONSTRUCTOR() { if (OFSpinlockNew(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to create spinlock!"); } #endif static uint64_t readULEB128(const uint8_t **ptr) { uint64_t value = 0; |
︙ | ︙ | |||
334 335 336 337 338 339 340 | static uint64_t readValue(uint8_t enc, const uint8_t **ptr) { uint64_t value; if (enc == DW_EH_PE_aligned) { const uintptr_t *aligned = (const uintptr_t *) | | | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | static uint64_t readValue(uint8_t enc, const uint8_t **ptr) { uint64_t value; if (enc == DW_EH_PE_aligned) { const uintptr_t *aligned = (const uintptr_t *) OFRoundUpToPowerOf2(sizeof(void *), (uintptr_t)*ptr); *ptr = (const uint8_t *)(aligned + 1); return *aligned; } #define READ(type) \ |
︙ | ︙ | |||
395 396 397 398 399 400 401 | value = *(uintptr_t *)(uintptr_t)value; return value; } #endif static void | | | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | value = *(uintptr_t *)(uintptr_t)value; return value; } #endif static void readLSDA(struct _Unwind_Context *ctx, const uint8_t *ptr, struct LSDA *LSDA) { uint8_t landingpadsStartEnc; uintptr_t callsitesSize; LSDA->regionStart = _Unwind_GetRegionStart(ctx); LSDA->landingpadsStart = LSDA->regionStart; LSDA->typesTable = NULL; |
︙ | ︙ | |||
423 424 425 426 427 428 429 | callsitesSize = (uintptr_t)readULEB128(&ptr); LSDA->callsites = ptr; LSDA->actionTable = LSDA->callsites + callsitesSize; } static bool | | | 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | callsitesSize = (uintptr_t)readULEB128(&ptr); LSDA->callsites = ptr; LSDA->actionTable = LSDA->callsites + callsitesSize; } static bool findCallsite(struct _Unwind_Context *ctx, struct LSDA *LSDA, uintptr_t *landingpad, const uint8_t **actionRecords) { uintptr_t IP = _Unwind_GetIP(ctx); const uint8_t *ptr = LSDA->callsites; *landingpad = 0; *actionRecords = NULL; |
︙ | ︙ | |||
500 501 502 503 504 505 506 | if (iter == class) return true; return false; } static uint8_t | | | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | if (iter == class) return true; return false; } static uint8_t findActionRecord(const uint8_t *actionRecords, struct LSDA *LSDA, int actions, bool foreign, struct objc_exception *e, intptr_t *filterPtr) { const uint8_t *ptr; intptr_t filter, displacement; do { ptr = actionRecords; |
︙ | ︙ | |||
596 597 598 599 600 601 602 | } _Unwind_SetGR(ctx, 12, (uintptr_t)ex); #endif struct objc_exception *e = (struct objc_exception *)ex; bool foreign = (exClass != GNUCOBJC_EXCEPTION_CLASS); const uint8_t *LSDAAddr, *actionRecords; | | | 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | } _Unwind_SetGR(ctx, 12, (uintptr_t)ex); #endif struct objc_exception *e = (struct objc_exception *)ex; bool foreign = (exClass != GNUCOBJC_EXCEPTION_CLASS); const uint8_t *LSDAAddr, *actionRecords; struct LSDA LSDA; uintptr_t landingpad = 0; uint8_t found = 0; intptr_t filter = 0; if (foreign) { switch (exClass) { #ifdef CXX_PERSONALITY |
︙ | ︙ | |||
707 708 709 710 711 712 713 | } static void emergencyExceptionCleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) { #ifdef OF_HAVE_THREADS | | | | | | | | | | | | | | 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | } static void emergencyExceptionCleanup(_Unwind_Reason_Code reason, struct _Unwind_Exception *ex) { #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif ex->class = 0; #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif } void objc_exception_throw(id object) { struct objc_exception *e = calloc(1, sizeof(*e)); bool emergency = false; if (e == NULL) { #ifdef OF_HAVE_THREADS if (OFSpinlockLock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif for (uint_fast8_t i = 0; i < numEmergencyExceptions; i++) { if (emergencyExceptions[i].exception.class == 0) { e = &emergencyExceptions[i]; e->exception.class = GNUCOBJC_EXCEPTION_CLASS; emergency = true; break; } } #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&emergencyExceptionsSpinlock) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif } if (e == NULL) OBJC_ERROR("Not enough memory to allocate exception!"); e->exception.class = GNUCOBJC_EXCEPTION_CLASS; e->exception.cleanup = (emergency ? emergencyExceptionCleanup : cleanup); e->object = object; _Unwind_RaiseException(&e->exception); if (uncaughtExceptionHandler != NULL) uncaughtExceptionHandler(object); OBJC_ERROR("_Unwind_RaiseException() returned!"); } objc_uncaught_exception_handler objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler handler) { objc_uncaught_exception_handler old = uncaughtExceptionHandler; uncaughtExceptionHandler = handler; return old; } #ifdef HAVE_SEH_EXCEPTIONS typedef EXCEPTION_DISPOSITION (*seh_personality_fn)(PEXCEPTION_RECORD, void *, |
︙ | ︙ |
Modified src/runtime/hashtable.m from [4ff03c1700] to [ad954a7a5c].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #include <stdio.h> #include <stdlib.h> #include <string.h> #import "ObjFWRT.h" #import "private.h" | | | | | 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 | #include <stdio.h> #include <stdlib.h> #include <string.h> #import "ObjFWRT.h" #import "private.h" struct objc_hashtable_bucket objc_deletedBucket; uint32_t objc_string_hash(const void *str_) { const char *str = str_; uint32_t hash = 0; while (*str != 0) { hash += *str; hash += (hash << 10); hash ^= (hash >> 6); str++; } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; } bool objc_string_equal(const void *ptr1, const void *ptr2) { return (strcmp(ptr1, ptr2) == 0); } struct objc_hashtable * objc_hashtable_new(uint32_t (*hash)(const void *), bool (*equal)(const void *, const void *), uint32_t size) |
︙ | ︙ | |||
99 100 101 102 103 104 105 | return; if ((newData = calloc(newSize, sizeof(*newData))) == NULL) OBJC_ERROR("Not enough memory to resize hash table!"); for (uint32_t i = 0; i < table->size; i++) { if (table->data[i] != NULL && | | | | | | 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | return; if ((newData = calloc(newSize, sizeof(*newData))) == NULL) OBJC_ERROR("Not enough memory to resize hash table!"); for (uint32_t i = 0; i < table->size; i++) { if (table->data[i] != NULL && table->data[i] != &objc_deletedBucket) { uint32_t j, last; last = newSize; for (j = table->data[i]->hash & (newSize - 1); j < last && newData[j] != NULL; j++); if (j >= last) { last = table->data[i]->hash & (newSize - 1); for (j = 0; j < last && newData[j] != NULL; j++); } if (j >= last) OBJC_ERROR("No free bucket in hash table!"); newData[j] = table->data[i]; } } free(table->data); table->data = newData; table->size = newSize; } static inline bool indexForKey(struct objc_hashtable *table, const void *key, uint32_t *idx) { uint32_t i, hash; hash = table->hash(key) & (table->size - 1); for (i = hash; i < table->size && table->data[i] != NULL; i++) { if (table->data[i] == &objc_deletedBucket) continue; if (table->equal(table->data[i]->key, key)) { *idx = i; return true; } } if (i < table->size) return false; for (i = 0; i < hash && table->data[i] != NULL; i++) { if (table->data[i] == &objc_deletedBucket) continue; if (table->equal(table->data[i]->key, key)) { *idx = i; return true; } } |
︙ | ︙ | |||
177 178 179 180 181 182 183 | resize(table, table->count + 1); hash = table->hash(key); last = table->size; for (i = hash & (table->size - 1); i < last && table->data[i] != NULL && | | | | | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | resize(table, table->count + 1); hash = table->hash(key); last = table->size; for (i = hash & (table->size - 1); i < last && table->data[i] != NULL && table->data[i] != &objc_deletedBucket; i++); if (i >= last) { last = hash & (table->size - 1); for (i = 0; i < last && table->data[i] != NULL && table->data[i] != &objc_deletedBucket; i++); } if (i >= last) OBJC_ERROR("No free bucket in hash table!"); if ((bucket = malloc(sizeof(*bucket))) == NULL) OBJC_ERROR("Not enough memory to allocate hash table bucket!"); bucket->key = key; bucket->hash = hash; bucket->object = object; |
︙ | ︙ | |||
220 221 222 223 224 225 226 | { uint32_t idx; if (!indexForKey(table, key, &idx)) return; free(table->data[idx]); | | | | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | { uint32_t idx; if (!indexForKey(table, key, &idx)) return; free(table->data[idx]); table->data[idx] = &objc_deletedBucket; table->count--; resize(table, table->count); } void objc_hashtable_free(struct objc_hashtable *table) { for (uint32_t i = 0; i < table->size; i++) if (table->data[i] != NULL && table->data[i] != &objc_deletedBucket) free(table->data[i]); free(table->data); free(table); } |
Modified src/runtime/init.m from [b626330f56] to [930fe22400].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #import "ObjFWRT.h" #import "private.h" void __objc_exec_class(struct objc_module *module) { | | | | | | | | | | | | | | | 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 | #import "ObjFWRT.h" #import "private.h" void __objc_exec_class(struct objc_module *module) { objc_globalMutex_lock(); objc_registerAllSelectors(module->symtab); objc_registerAllClasses(module->symtab); objc_registerAllCategories(module->symtab); objc_initStaticInstances(module->symtab); objc_globalMutex_unlock(); } void objc_deinit(void) { objc_globalMutex_lock(); objc_unregisterAllCategories(); objc_unregisterAllClasses(); objc_unregisterAllSelectors(); objc_forgetPendingStaticInstances(); objc_dtable_cleanup(); objc_globalMutex_unlock(); } |
Modified src/runtime/instance.m from [c5fcd18398] to [3d0ab38eff].
︙ | ︙ | |||
77 78 79 80 81 82 83 | Class class; void (*last)(id, SEL) = NULL; if (object == nil) return NULL; #ifdef OF_OBJFW_RUNTIME | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | Class class; void (*last)(id, SEL) = NULL; if (object == nil) return NULL; #ifdef OF_OBJFW_RUNTIME objc_zeroWeakReferences(object); #endif if (destructSelector == NULL) destructSelector = sel_registerName(".cxx_destruct"); for (class = object_getClass(object); class != Nil; class = class_getSuperclass(class)) { |
︙ | ︙ |
Modified src/runtime/ivar.m from [3e8ec570e1] to [5caeed37fa].
︙ | ︙ | |||
27 28 29 30 31 32 33 | if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } | | | | | | 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 61 62 63 | if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } objc_globalMutex_lock(); count = (class->ivars != NULL ? class->ivars->count : 0); if (count == 0) { if (outCount != NULL) *outCount = 0; objc_globalMutex_unlock(); return NULL; } if ((ivars = malloc((count + 1) * sizeof(Ivar))) == NULL) OBJC_ERROR("Not enough memory to copy ivars!"); for (unsigned int i = 0; i < count; i++) ivars[i] = &class->ivars->ivars[i]; ivars[count] = NULL; if (outCount != NULL) *outCount = count; objc_globalMutex_unlock(); return ivars; } const char * ivar_getName(Ivar ivar) { |
︙ | ︙ |
Modified src/runtime/library.xml from [99fa55d924] to [f6565586a9].
︙ | ︙ | |||
229 230 231 232 233 234 235 | <argument name='protocol2' type='Protocol *_Nonnull' m68k-reg='a1'/> </function> <function name='protocol_conformsToProtocol' return-type='bool'> <argument name='protocol1' type='Protocol *_Nonnull' m68k-reg='a0'/> <argument name='protocol2' type='Protocol *_Nonnull' m68k-reg='a1'/> </function> <function name='objc_setUncaughtExceptionHandler' | | | | | | 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | <argument name='protocol2' type='Protocol *_Nonnull' m68k-reg='a1'/> </function> <function name='protocol_conformsToProtocol' return-type='bool'> <argument name='protocol1' type='Protocol *_Nonnull' m68k-reg='a0'/> <argument name='protocol2' type='Protocol *_Nonnull' m68k-reg='a1'/> </function> <function name='objc_setUncaughtExceptionHandler' return-type='_Nullable objc_uncaught_exception_handler'> <argument name='handler' type='objc_uncaught_exception_handler _Nullable' m68k-reg='a0'/> </function> <function name='objc_setForwardHandler'> <argument name='forward' type='IMP _Nullable' m68k-reg='a0'/> <argument name='stretForward' type='IMP _Nullable' m68k-reg='a1'/> </function> <function name='objc_setEnumerationMutationHandler'> <argument name='hadler' type='objc_enumeration_mutation_handler _Nullable' m68k-reg='a0'/> </function> <function name='objc_constructInstance' return-type='id _Nullable'> <argument name='class' type='Class _Nullable' m68k-reg='a0'/> <argument name='bytes' type='void *_Nullable' m68k-reg='a1'/> </function> <function name='objc_deinit'/> <function name='class_copyIvarList' return-type='Ivar _Nullable *_Nullable'> <argument name='class' type='Class _Nullable' m68k-reg='a0'/> <argument name='outCount' type='unsigned int *_Nullable' m68k-reg='a1'/> </function> <function name='ivar_getName' return-type='const char *_Nonnull'> <argument name='ivar' type='Ivar _Nonnull' m68k-reg='a0'/> </function> |
︙ | ︙ |
Modified src/runtime/linklib/linklib.m from [e1e21b28b9] to [9056a4e93e].
︙ | ︙ | |||
1040 1041 1042 1043 1044 1045 1046 | :: "r"(ObjFWRTBase) : "r12" ); return __extension__ ((bool (*)(Protocol *_Nonnull, Protocol *_Nonnull))*(void **)(((uintptr_t)ObjFWRTBase) - 382))(protocol1, protocol2); #endif } | | | | | | 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | :: "r"(ObjFWRTBase) : "r12" ); return __extension__ ((bool (*)(Protocol *_Nonnull, Protocol *_Nonnull))*(void **)(((uintptr_t)ObjFWRTBase) - 382))(protocol1, protocol2); #endif } _Nullable objc_uncaught_exception_handler objc_setUncaughtExceptionHandler(objc_uncaught_exception_handler _Nullable handler) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWRTBase; (void)a6; return ((_Nullable objc_uncaught_exception_handler (*)(objc_uncaught_exception_handler _Nullable __asm__("a0")))(((uintptr_t)ObjFWRTBase) - 390))(handler); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWRTBase) : "r12" ); return __extension__ ((_Nullable objc_uncaught_exception_handler (*)(objc_uncaught_exception_handler _Nullable))*(void **)(((uintptr_t)ObjFWRTBase) - 388))(handler); #endif } void objc_setForwardHandler(IMP _Nullable forward, IMP _Nullable stretForward) { #if defined(OF_AMIGAOS_M68K) |
︙ | ︙ | |||
1075 1076 1077 1078 1079 1080 1081 | ); __extension__ ((void (*)(IMP _Nullable, IMP _Nullable))*(void **)(((uintptr_t)ObjFWRTBase) - 394))(forward, stretForward); #endif } void | | | | | 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 | ); __extension__ ((void (*)(IMP _Nullable, IMP _Nullable))*(void **)(((uintptr_t)ObjFWRTBase) - 394))(forward, stretForward); #endif } void objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler _Nullable hadler) { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWRTBase; (void)a6; ((void (*)(objc_enumeration_mutation_handler _Nullable __asm__("a0")))(((uintptr_t)ObjFWRTBase) - 402))(hadler); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( "mr %%r12, %0" :: "r"(ObjFWRTBase) : "r12" ); __extension__ ((void (*)(objc_enumeration_mutation_handler _Nullable))*(void **)(((uintptr_t)ObjFWRTBase) - 400))(hadler); #endif } id _Nullable objc_constructInstance(Class _Nullable class, void *_Nullable bytes) { #if defined(OF_AMIGAOS_M68K) |
︙ | ︙ | |||
1109 1110 1111 1112 1113 1114 1115 | ); return __extension__ ((id _Nullable (*)(Class _Nullable, void *_Nullable))*(void **)(((uintptr_t)ObjFWRTBase) - 406))(class, bytes); #endif } void | | | 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 | ); return __extension__ ((id _Nullable (*)(Class _Nullable, void *_Nullable))*(void **)(((uintptr_t)ObjFWRTBase) - 406))(class, bytes); #endif } void objc_deinit() { #if defined(OF_AMIGAOS_M68K) register struct Library *a6 __asm__("a6") = ObjFWRTBase; (void)a6; ((void (*)())(((uintptr_t)ObjFWRTBase) - 414))(); #elif defined(OF_MORPHOS) __asm__ __volatile__ ( |
︙ | ︙ |
Modified src/runtime/lookup-asm/lookup-asm-arm-elf.S from [7443d47cf7] to [40d58a6394].
︙ | ︙ | |||
19 20 21 22 23 24 25 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: cmp r0, #0 beq returnNilMethod tst r0, #1 bne .LtaggedPointer_\name ldr r2, [r0, #0] ldr r2, [r2, #32] .Lmain_\name: #ifndef OF_BIG_ENDIAN # ifdef OF_SELUID24 |
︙ | ︙ | |||
52 53 54 55 56 57 58 | ldrb r3, [r1, #2] ldr r2, [r2, r3, lsl #2] ldrb r3, [r1, #3] ldr r2, [r2, r3, lsl #2] #endif cmp r2, #0 | | | | | | | | | | | | | | | | | | | | 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | ldrb r3, [r1, #2] ldr r2, [r2, r3, lsl #2] ldrb r3, [r1, #3] ldr r2, [r2, r3, lsl #2] #endif cmp r2, #0 beq \notFound(PLT) mov r0, r2 bx lr .LtaggedPointer_\name: ldr r2, .Lgot$indirect_.LtaggedPointer_\name add r2, pc, r2 ldr r3, .Lgot$indirect_.LtaggedPointer_\name+4 ldr r3, [r2, r3] ldr r3, [r3] eor r0, r0, r3 and r0, r0, #0xE lsl r0, r0, #1 ldr r3, .Lgot$indirect_.LtaggedPointer_\name+8 ldr r3, [r2, r3] ldr r2, [r3, r0] ldr r2, [r2, #32] b .Lmain_\name .type \name, %function .size \name, .-\name .Lgot$indirect_.LtaggedPointer_\name: .long _GLOBAL_OFFSET_TABLE_-(.LtaggedPointer_\name+12) .long objc_taggedPointerSecret(GOT) .long objc_taggedPointerClasses(GOT) .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mov r2, r0 ldr r0, [r0, #0] cmp r0, #0 beq returnNilMethod ldr r2, [r2, #4] ldr r2, [r2, #32] b .Lmain_\lookup .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: adr r0, nilMethod bx lr nilMethod: mov r0, #0 bx lr #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-arm64-elf.S from [7551faefd3] to [77601b6969].
︙ | ︙ | |||
19 20 21 22 23 24 25 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: cbz x0, returnNilMethod tst x0, #1 b.ne .LtaggedPointer_\name ldr x2, [x0] ldr x2, [x2, #64] .Lmain_\name: #ifdef OF_SELUID24 ldrb w3, [x1, #2] ldr x2, [x2, x3, lsl #3] #endif ldrb w3, [x1, #1] ldr x2, [x2, x3, lsl #3] ldrb w3, [x1] ldr x2, [x2, x3, lsl #3] cbz x2, \notFound mov x0, x2 ret .LtaggedPointer_\name: adrp x2, :got:objc_taggedPointerSecret ldr x2, [x2, #:got_lo12:objc_taggedPointerSecret] ldr x2, [x2] eor x0, x0, x2 and x0, x0, #0xE lsl x0, x0, #2 adrp x2, :got:objc_taggedPointerClasses ldr x2, [x2, #:got_lo12:objc_taggedPointerClasses] ldr x2, [x2, x0] ldr x2, [x2, #64] b .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mov x2, x0 ldr x0, [x0] cbz x0, returnNilMethod ldr x2, [x2, #8] ldr x2, [x2, #64] b .Lmain_\lookup .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: adr x0, nilMethod ret nilMethod: mov x0, #0 ret #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-mips-elf.S from [b2c0fd7a36] to [16aa30af7f].
︙ | ︙ | |||
19 20 21 22 23 24 25 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: beqz $a0, 0f andi $t0, $a0, 1 bnez $t0, .LtaggedPointer_\name lw $t0, 0($a0) lw $t0, 32($t0) .Lmain_\name: #ifdef OF_BIG_ENDIAN # ifdef OF_SELUID24 |
︙ | ︙ | |||
62 63 64 65 66 67 68 | lw $t0, 0($t0) addu $t0, $t0, $t3 lw $t0, 0($t0) #ifdef OF_PIC beqz $t0, 1f #else | | | | | | | | | | | | | | | | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | lw $t0, 0($t0) addu $t0, $t0, $t3 lw $t0, 0($t0) #ifdef OF_PIC beqz $t0, 1f #else beqz $t0, \notFound #endif move $v0, $t0 jr $ra 0: #ifdef OF_PIC addiu $v0, $t9, nilMethod-\name #else la $v0, nilMethod #endif jr $ra #ifdef OF_PIC 1: lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 addiu $gp, $gp, 1b-\name lw $t9, %call16(\notFound)($gp) jr $t9 #endif .LtaggedPointer_\name: #ifdef OF_PIC 0: lui $gp, %hi(_gp_disp) addiu $gp, $gp, %lo(_gp_disp) addu $gp, $gp, $t9 addiu $gp, $gp, 0b-\name lw $t0, %got(objc_taggedPointerSecret)($gp) #else la $t0, objc_taggedPointerSecret #endif lw $t0, 0($t0) xor $t0, $a0, $t0 and $t0, $t0, 0xE sll $t0, $t0, 1 #ifdef OF_PIC lw $t1, %got(objc_taggedPointerClasses)($gp) #else la $t1, objc_taggedPointerClasses #endif addu $t0, $t1, $t0 ld $t0, ($t0) ld $t0, 32($t0) b .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: move $t0, $a0 lw $a0, 0($a0) beqz $a0, 0f lw $t0, 4($t0) lw $t0, 32($t0) addiu $t9, $t9, \lookup-\name b .Lmain_\lookup 0: #ifdef OF_PIC addiu $v0, $t9, nilMethod-\name #else la $v0, nilMethod #endif jr $ra .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret nilMethod: move $v0, $zero jr $ra #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-mips64-n64-elf.S from [34f3dd7a14] to [6719050384].
︙ | ︙ | |||
19 20 21 22 23 24 25 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: beqz $a0, 0f andi $t0, $a0, 1 bnez $t0, .LtaggedPointer_\name ld $t0, ($a0) ld $t0, 64($t0) .Lmain_\name: #ifdef OF_BIG_ENDIAN # ifdef OF_SELUID24 |
︙ | ︙ | |||
68 69 70 71 72 73 74 | move $v0, $t0 jr $ra 0: lui $v0, %hi(%neg(%gp_rel(\name))) daddiu $v0, $v0, %lo(%neg(%gp_rel(\name))) daddu $v0, $v0, $t9 | | | | | | | | | | | | | | 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | move $v0, $t0 jr $ra 0: lui $v0, %hi(%neg(%gp_rel(\name))) daddiu $v0, $v0, %lo(%neg(%gp_rel(\name))) daddu $v0, $v0, $t9 ld $v0, %got_disp(nilMethod)($v0) jr $ra 1: lui $t0, %hi(%neg(%gp_rel(\name))) daddiu $t0, $t0, %lo(%neg(%gp_rel(\name))) daddu $t0, $t0, $t9 ld $t9, %got_disp(\notFound)($t0) jr $t9 .LtaggedPointer_\name: lui $t0, %hi(%neg(%gp_rel(\name))) daddiu $t0, $t0, %lo(%neg(%gp_rel(\name))) daddu $t0, $t0, $t9 ld $t1, %got_disp(objc_taggedPointerSecret)($t0) ld $t1, 0($t1) xor $t1, $a0, $t1 and $t1, $t1, 0xE dsll $t1, $t1, 2 ld $t0, %got_disp(objc_taggedPointerClasses)($t0) daddu $t0, $t0, $t1 ld $t0, ($t0) ld $t0, 64($t0) b .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: move $t0, $a0 ld $a0, ($a0) beqz $a0, 0f ld $t0, 8($t0) ld $t0, 64($t0) daddiu $t9, $t9, \lookup-\name b .Lmain_\lookup 0: lui $v0, %hi(%neg(%gp_rel(\name))) daddiu $v0, $v0, %lo(%neg(%gp_rel(\name))) daddu $v0, $v0, $t9 ld $v0, %got_disp(nilMethod)($v0) jr $ra .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret nilMethod: move $v0, $zero jr $ra #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-powerpc-elf.S from [e20fe0b40d] to [7227a38be1].
︙ | ︙ | |||
19 20 21 22 23 24 25 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: cmpwi %r3, 0 beq- returnNilMethod andi. %r0, %r3, 1 bne- .LtaggedPointer_\name lwz %r5, 0(%r3) lwz %r5, 32(%r5) .Lmain_\name: lwz %r8, 0(%r4) #ifdef OF_SELUID24 |
︙ | ︙ | |||
63 64 65 66 67 68 69 | bl 0f 0: mflr %r30 addis %r30, %r30, .Lbiased_got2-0b@ha addi %r30, %r30, .Lbiased_got2-0b@l | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 | bl 0f 0: mflr %r30 addis %r30, %r30, .Lbiased_got2-0b@ha addi %r30, %r30, .Lbiased_got2-0b@l lwz %r0, .Lgot_\notFound-.Lbiased_got2(%r30) mtctr %r0 lwz %r30, 8(%r1) lwz %r0, 20(%r1) addi %r1, %r1, 16 mtlr %r0 bctr #else b \notFound #endif .LtaggedPointer_\name: #if defined(OF_PIC) mflr %r7 bl 0f 0: mflr %r6 mtlr %r7 addis %r6, %r6, .Lbiased_got2-0b@ha addi %r6, %r6, .Lbiased_got2-0b@l lwz %r5, .Lgot_objc_taggedPointerSecret-.Lbiased_got2(%r6) lwz %r5, 0(%r5) #elif defined(OF_BASEREL) addis %r5, %r13, objc_taggedPointerSecret@drel@ha lwz %r5, objc_taggedPointerSecret@drel@l(%r5) #else lis %r5, objc_taggedPointerSecret@ha lwz %r5, objc_taggedPointerSecret@l(%r5) #endif xor %r5, %r3, %r5 rlwinm %r5, %r5, 1, 0x1C #if defined(OF_PIC) lwz %r6, .Lgot_objc_taggedPointerClasses-.Lbiased_got2(%r6) #elif defined(OF_BASEREL) addis %r6, %r13, objc_taggedPointerClasses@drel@ha addi %r6, %r6, objc_taggedPointerClasses@drel@l #else lis %r6, objc_taggedPointerClasses@ha addi %r6, %r6, objc_taggedPointerClasses@l #endif lwzx %r5, %r6, %r5 lwz %r5, 32(%r5) b .Lmain_\name .type \name, @function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mr %r5, %r3 lwz %r3, 0(%r3) cmpwi %r3, 0 beq- returnNilMethod lwz %r5, 4(%r5) lwz %r5, 32(%r5) b .Lmain_\lookup .type \name, @function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: mflr %r0 bl getPC mtlr %r0 0: addi %r3, %r3, nilMethod-0b blr nilMethod: li %r3, 0 blr getPC: mflr %r3 blr #ifdef OF_PIC .section .got2, "aw" .Lbiased_got2 = .+0x8000 .Lgot_objc_methodNotFound: .long objc_methodNotFound .Lgot_objc_methodNotFound_stret: .long objc_methodNotFound_stret .Lgot_objc_taggedPointerSecret: .long objc_taggedPointerSecret .Lgot_objc_taggedPointerClasses: .long objc_taggedPointerClasses #endif #ifdef OF_LINUX .section .note.GNU-stack, "", @progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-sparc-elf.S from [97ba2c63db] to [c6e8c65e49].
︙ | ︙ | |||
19 20 21 22 23 24 25 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: tst %o0 bz returnNilMethod btst 1, %o0 bnz .LtaggedPointer_\name nop ld [%o0], %o2 ld [%o2 + 32], %o2 .Lmain_\name: #ifdef OF_SELUID24 |
︙ | ︙ | |||
58 59 60 61 62 63 64 | nop retl mov %o2, %o0 0: mov %o7, %g1 | | | | | | | | | | | | | | | | | | | | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | nop retl mov %o2, %o0 0: mov %o7, %g1 call \notFound mov %g1, %o7 .LtaggedPointer_\name: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o3 call 0f or %o3, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o3 0: add %o7, %o3, %o3 mov %g1, %o7 #endif sethi %hi(objc_taggedPointerSecret), %o2 or %o2, %lo(objc_taggedPointerSecret), %o2 #ifdef OF_PIC ld [%o3 + %o2], %o2 #endif ld [%o2], %o2 xor %o0, %o2, %o0 and %o0, 0xE, %o0 sll %o0, 1, %o0 sethi %hi(objc_taggedPointerClasses), %o2 or %o2, %lo(objc_taggedPointerClasses), %o2 #ifdef OF_PIC ld [%o3 + %o2], %o2 #endif ld [%o2 + %o0], %o2 ba .Lmain_\name ld [%o2 + 32], %o2 .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mov %o0, %o2 ld [%o0], %o0 cmp %o0, 0 be returnNilMethod nop ld [%o2 + 4], %o2 ba .Lmain_\lookup ld [%o2 + 32], %o2 .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o1 call 0f add %o1, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o1 0: add %o7, %o1, %o1 sethi %hi(nilMethod), %o0 or %o0, %lo(nilMethod), %o0 jmpl %g1 + 8, %g0 ld [%o1 + %o0], %o0 #else sethi %hi(nilMethod), %o0 retl or %o0, %lo(nilMethod), %o0 #endif nilMethod: retl clr %o0 #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-sparc64-elf.S from [f2aa28d73c] to [ddfe4e7ce8].
︙ | ︙ | |||
19 20 21 22 23 24 25 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text | | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: brz,pn %o0, returnNilMethod and %o0, 1, %o2 brnz,pn %o2, .LtaggedPointer_\name nop ldx [%o0], %o2 ldx [%o2 + 64], %o2 .Lmain_\name: #ifdef OF_SELUID24 |
︙ | ︙ | |||
56 57 58 59 60 61 62 | nop retl mov %o2, %o0 0: mov %o7, %g1 | | | | | | | | | | | | | | | | | | | | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | nop retl mov %o2, %o0 0: mov %o7, %g1 call \notFound mov %g1, %o7 .LtaggedPointer_\name: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o3 call 0f or %o3, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o3 0: add %o7, %o3, %o3 mov %g1, %o7 #endif sethi %hi(objc_taggedPointerSecret), %o2 or %o2, %lo(objc_taggedPointerSecret), %o2 #ifdef OF_PIC ldx [%o3 + %o2], %o2 #endif ldx [%o2], %o2 xor %o0, %o2, %o0 and %o0, 0xE, %o0 sll %o0, 2, %o0 sethi %hi(objc_taggedPointerClasses), %o2 or %o2, %lo(objc_taggedPointerClasses), %o2 #ifdef OF_PIC ldx [%o3 + %o2], %o2 #endif ldx [%o2 + %o0], %o2 ba .Lmain_\name ldx [%o2 + 64], %o2 .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: mov %o0, %o2 ldx [%o0], %o0 brz,pn %o0, returnNilMethod nop ldx [%o2 + 8], %o2 ba .Lmain_\lookup ldx [%o2 + 64], %o2 .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: #ifdef OF_PIC mov %o7, %g1 sethi %hi(_GLOBAL_OFFSET_TABLE_ - 4), %o1 call 0f or %o1, %lo(_GLOBAL_OFFSET_TABLE_ + 4), %o1 0: add %o7, %o1, %o1 sethi %hi(nilMethod), %o0 or %o0, %lo(nilMethod), %o0 jmpl %g1 + 8, %g0 ldx [%o1 + %o0], %o0 #else sethi %hi(nilMethod), %o0 retl or %o0, %lo(nilMethod), %o0 #endif nilMethod: retl clr %o0 #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-x86-elf.S from [d0b7459651] to [584c3797d2].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | < | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | * file. */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: movl 4(%esp), %edx testl %edx, %edx jz returnNilMethod testb $1, %dl jnz .LtaggedPointer_\name movl (%edx), %edx movl 32(%edx), %edx .Lmain_\name: movl 8(%esp), %eax #ifdef OF_SELUID24 movzbl 2(%eax), %ecx movl (%edx,%ecx,4), %edx #endif movzbl 1(%eax), %ecx movl (%edx,%ecx,4), %edx movzbl (%eax), %ecx movl (%edx,%ecx,4), %eax testl %eax, %eax jz 0f ret 0: call getEIP addl $_GLOBAL_OFFSET_TABLE_, %eax lea \notFound@GOTOFF(%eax), %eax jmp *%eax .LtaggedPointer_\name: call getEIP addl $_GLOBAL_OFFSET_TABLE_, %eax leal objc_taggedPointerSecret@GOTOFF(%eax), %ecx xorl (%ecx), %edx andb $0xE, %dl movzbl %dl, %edx leal objc_taggedPointerClasses@GOTOFF(%eax), %eax movl (%eax,%edx,2), %edx movl 32(%edx), %edx jmp .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: movl 4(%esp), %edx movl (%edx), %eax testl %eax, %eax jz returnNilMethod movl %eax, 4(%esp) mov 4(%edx), %edx mov 32(%edx), %edx jmp .Lmain_\lookup .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: call getEIP addl $_GLOBAL_OFFSET_TABLE_, %eax leal nilMethod@GOTOFF(%eax), %eax ret nilMethod: xorl %eax, %eax ret getEIP: movl (%esp), %eax ret #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-x86-win32.S from [a72d0d3be2] to [82a8f4610f].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | | | | | | | | | | | | | | | | | | | | | | | | > > > > > | < | | | | | | | | > > > > | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _objc_msg_lookup .globl _objc_msg_lookup_stret .globl _objc_msg_lookup_super .globl _objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: movl 4(%esp), %edx testl %edx, %edx jz returnNilMethod testb $1, %dl jnz .LtaggedPointer_\name movl (%edx), %edx movl 32(%edx), %edx .Lmain_\name: movl 8(%esp), %eax #ifdef OF_SELUID24 movzbl 2(%eax), %ecx movl (%edx,%ecx,4), %edx #endif movzbl 1(%eax), %ecx movl (%edx,%ecx,4), %edx movzbl (%eax), %ecx movl (%edx,%ecx,4), %eax testl %eax, %eax jz \notFound ret .LtaggedPointer_\name: xorl _objc_taggedPointerSecret, %edx andb $0xE, %dl movzbl %dl, %edx movl _objc_taggedPointerClasses(,%edx,2), %edx movl 32(%edx), %edx jmp .Lmain_\name .def \name .scl 2 .type 32 .endef .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: movl 4(%esp), %edx movl (%edx), %eax test %eax, %eax jz returnNilMethod movl %eax, 4(%esp) movl 4(%edx), %edx movl 32(%edx), %edx jmp .Lmain_\lookup .def \name .scl 2 .type 32 .endef .endm GENERATE_LOOKUP _objc_msg_lookup _objc_methodNotFound GENERATE_LOOKUP _objc_msg_lookup_stret _objc_methodNotFound_stret GENERATE_LOOKUP_SUPER _objc_msg_lookup_super _objc_msg_lookup GENERATE_LOOKUP_SUPER _objc_msg_lookup_super_stret _objc_msg_lookup_stret returnNilMethod: movl $nilMethod, %eax ret nilMethod: xorl %eax, %eax ret |
Modified src/runtime/lookup-asm/lookup-asm-x86_64-elf.S from [70f37dd9e8] to [a4b34307ef].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #include "platform.h" | < < | | | | | | | | | | | | | | | | | | | > | | | < | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | * file. */ #include "config.h" #include "platform.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: testq %rdi, %rdi jz returnNilMethod testb $1, %dil jnz .LtaggedPointer_\name movq (%rdi), %r8 movq 64(%r8), %r8 .Lmain_\name: movq (%rsi), %rax movzbl %ah, %ecx movzbl %al, %edx #ifdef OF_SELUID24 shrl $16, %eax movq (%r8,%rax,8), %r8 #endif movq (%r8,%rcx,8), %r8 movq (%r8,%rdx,8), %rax testq %rax, %rax jz \notFound@PLT ret .LtaggedPointer_\name: movq objc_taggedPointerSecret@GOTPCREL(%rip), %rax xorq (%rax), %rdi andb $0xE, %dil movzbl %dil, %r8d movq objc_taggedPointerClasses@GOTPCREL(%rip), %rax movq (%rax,%r8,4), %r8 movq 64(%r8), %r8 jmp .Lmain_\name .type \name, %function .size \name, .-\name .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: movq %rdi, %r8 movq (%rdi), %rdi testq %rdi, %rdi jz returnNilMethod movq 8(%r8), %r8 movq 64(%r8), %r8 jmp .Lmain_\lookup .type \name, %function .size \name, .-\name .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: leaq nilMethod(%rip), %rax ret nilMethod: xorq %rax, %rax ret #ifdef OF_LINUX .section .note.GNU-stack, "", %progbits #endif |
Modified src/runtime/lookup-asm/lookup-asm-x86_64-macho.S from [0df35756bb] to [75f4b5e2f7].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl _objc_msg_lookup .globl _objc_msg_lookup_stret .globl _objc_msg_lookup_super .globl _objc_msg_lookup_super_stret .section __TEXT, __text, regular, pure_instructions .macro GENERATE_LOOKUP $0: testq %rdi, %rdi jz returnNilMethod testb $$1, %dil jnz LtaggedPointer_$0 movq (%rdi), %r8 movq 64(%r8), %r8 Lmain_$0: movq (%rsi), %rax movzbl %ah, %ecx movzbl %al, %edx #ifdef OF_SELUID24 shrl $$16, %eax movq (%r8,%rax,8), %r8 #endif movq (%r8,%rcx,8), %r8 movq (%r8,%rdx,8), %rax testq %rax, %rax jz $1 ret LtaggedPointer_$0: movq _objc_taggedPointerSecret@GOTPCREL(%rip), %rax xorq (%rax), %rdi andb $$0xE, %dil movzbl %dil, %r8d movq _objc_taggedPointerClasses@GOTPCREL(%rip), %rax movq (%rax,%r8,4), %r8 movq 64(%r8), %r8 jmp Lmain_$0 .endmacro .macro GENERATE_LOOKUP_SUPER $0: movq %rdi, %r8 movq (%rdi), %rdi testq %rdi, %rdi jz returnNilMethod movq 8(%r8), %r8 movq 64(%r8), %r8 jmp Lmain_$1 .endmacro GENERATE_LOOKUP _objc_msg_lookup, _objc_methodNotFound GENERATE_LOOKUP _objc_msg_lookup_stret, _objc_methodNotFound_stret GENERATE_LOOKUP_SUPER _objc_msg_lookup_super, _objc_msg_lookup GENERATE_LOOKUP_SUPER _objc_msg_lookup_super_stret, _objc_msg_lookup_stret returnNilMethod: leaq nilMethod(%rip), %rax ret nilMethod: xorq %rax, %rax ret |
Modified src/runtime/lookup-asm/lookup-asm-x86_64-win64.S from [bcecb9f17a] to [bc3f6ee83e].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" | < < | | | | | | | | | | | | | | | | | | | | | | | | | | > | | > > > > | < < | < > > > | | | > > > > | | | | | | | | | 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" .globl objc_msg_lookup .globl objc_msg_lookup_stret .globl objc_msg_lookup_super .globl objc_msg_lookup_super_stret .section .text .macro GENERATE_LOOKUP name notFound \name: testq %rcx, %rcx jz returnNilMethod testb $1, %cl jnz .LtaggedPointer_\name movq (%rcx), %r8 movq 56(%r8), %r8 .Lmain_\name: movq %rcx, %r10 movq %rdx, %r11 movq (%rdx), %rax movzbl %ah, %ecx movzbl %al, %edx #ifdef OF_SELUID24 shrl $16, %eax movq (%r8,%rax,8), %r8 #endif movq (%r8,%rcx,8), %r8 movq (%r8,%rdx,8), %rax testq %rax, %rax jz 0f ret 0: movq %r10, %rcx movq %r11, %rdx jmp \notFound .LtaggedPointer_\name: xorq objc_taggedPointerSecret(%rip), %rcx andb $0xE, %cl movzbl %cl, %r8d leaq objc_taggedPointerClasses(%rip), %rax movq (%rax,%r8,4), %r8 movq 56(%r8), %r8 jmp .Lmain_\name .def \name .scl 2 .type 32 .endef .endm .macro GENERATE_LOOKUP_SUPER name lookup \name: movq %rcx, %r8 movq (%rcx), %rcx testq %rcx, %rcx jz returnNilMethod movq 8(%r8), %r8 movq 56(%r8), %r8 jmp .Lmain_\lookup .def \name .scl 2 .type 32 .endef .endm GENERATE_LOOKUP objc_msg_lookup objc_methodNotFound GENERATE_LOOKUP objc_msg_lookup_stret objc_methodNotFound_stret GENERATE_LOOKUP_SUPER objc_msg_lookup_super objc_msg_lookup GENERATE_LOOKUP_SUPER objc_msg_lookup_super_stret objc_msg_lookup_stret returnNilMethod: leaq nilMethod(%rip), %rax ret nilMethod: xorq %rax, %rax ret |
Modified src/runtime/lookup.m from [041b8ab433] to [7e08e68b8b].
︙ | ︙ | |||
37 38 39 40 41 42 43 | bool isClass = object_getClass(object)->info & OBJC_CLASS_INFO_METACLASS; if (!(object_getClass(object)->info & OBJC_CLASS_INFO_INITIALIZED)) { Class class = (isClass ? (Class)object : object_getClass(object)); | | | > | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | bool isClass = object_getClass(object)->info & OBJC_CLASS_INFO_METACLASS; if (!(object_getClass(object)->info & OBJC_CLASS_INFO_INITIALIZED)) { Class class = (isClass ? (Class)object : object_getClass(object)); objc_initializeClass(class); if (!(class->info & OBJC_CLASS_INFO_SETUP)) OBJC_ERROR("Could not dispatch message %s for " "incomplete class %s!", sel_getName(selector), class_getName(class)); /* * We don't need to handle the case that super was called. * The reason for this is that a call to super is not possible * before a message to the class has been sent and it thus has * been initialized together with its superclasses. */ |
︙ | ︙ | |||
93 94 95 96 97 98 99 | OBJC_ERROR("Selector %c[%s] is not implemented for class %s!", (isClass ? '+' : '-'), sel_getName(selector), object_getClassName(object)); } IMP | | | | | 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | OBJC_ERROR("Selector %c[%s] is not implemented for class %s!", (isClass ? '+' : '-'), sel_getName(selector), object_getClassName(object)); } IMP objc_methodNotFound(id object, SEL selector) { return commonMethodNotFound(object, selector, objc_msg_lookup, forwardHandler); } IMP objc_methodNotFound_stret(id object, SEL selector) { return commonMethodNotFound(object, selector, objc_msg_lookup_stret, stretForwardHandler); } void objc_setForwardHandler(IMP forward, IMP stretForward) { forwardHandler = forward; stretForwardHandler = stretForward; } bool class_respondsToSelector(Class class, SEL selector) { if (class == Nil) return false; return (objc_dtable_get(class->dTable, (uint32_t)selector->UID) != (IMP)0); } #ifndef OF_ASM_LOOKUP static id nilMethod(id self, SEL _cmd) { |
︙ | ︙ |
Modified src/runtime/method.m from [a0fa699892] to [4ccd14f099].
︙ | ︙ | |||
28 29 30 31 32 33 34 | if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } | | | > | > > | | 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 61 62 63 64 65 66 67 68 69 70 71 72 | if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } objc_globalMutex_lock(); count = 0; for (iter = class->methodList; iter != NULL; iter = iter->next) count += iter->count; if (count == 0) { if (outCount != NULL) *outCount = 0; objc_globalMutex_unlock(); return NULL; } if ((methods = malloc((count + 1) * sizeof(Method))) == NULL) OBJC_ERROR("Not enough memory to copy methods"); i = 0; for (iter = class->methodList; iter != NULL; iter = iter->next) for (unsigned int j = 0; j < iter->count; j++) methods[i++] = &iter->methods[j]; if (i != count) OBJC_ERROR("Fatal internal inconsistency!"); methods[count] = NULL; if (outCount != NULL) *outCount = count; objc_globalMutex_unlock(); return methods; } SEL method_getName(Method method) { |
︙ | ︙ |
Modified src/runtime/misc.m from [0e07d705d4] to [45165f1a7f].
︙ | ︙ | |||
33 34 35 36 37 38 39 | # define __NOLIBBASE__ # define Class IntuitionClass # include <proto/intuition.h> # undef Class # undef __NOLIBBASE__ #endif | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # define __NOLIBBASE__ # define Class IntuitionClass # include <proto/intuition.h> # undef Class # undef __NOLIBBASE__ #endif static objc_enumeration_mutation_handler enumerationMutationHandler = NULL; void objc_enumerationMutation(id object) { if (enumerationMutationHandler != NULL) enumerationMutationHandler(object); else OBJC_ERROR("Object was mutated during enumeration!"); } void objc_setEnumerationMutationHandler(objc_enumeration_mutation_handler handler) { enumerationMutationHandler = handler; } void objc_error(const char *title, const char *format, ...) { #if defined(OF_WINDOWS) || defined(OF_AMIGAOS) # define messageLen 512 char message[messageLen]; int status; va_list args; va_start(args, format); status = vsnprintf(message, messageLen, format, args); if (status <= 0 || status >= messageLen) message[0] = '\0'; va_end(args); # undef BUF_LEN #endif #if defined(OF_WINDOWS) fprintf(stderr, "[%s] %s\n", title, message); |
︙ | ︙ | |||
127 128 129 130 131 132 133 | va_end(args); abort(); #endif OF_UNREACHABLE } | > > > > > > > > > > > > > > | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | va_end(args); abort(); #endif OF_UNREACHABLE } char * objc_strdup(const char *string) { char *copy; size_t length = strlen(string); if ((copy = (char *)malloc(length + 1)) == NULL) return NULL; memcpy(copy, string, length + 1); return copy; } |
Deleted src/runtime/morphos-clib.h version [750cbb9d7c].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/runtime/morphos.fd version [4a176c28f2].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified src/runtime/private.h from [0007b0cada] to [133858e63f].
︙ | ︙ | |||
36 37 38 39 40 41 42 | Class _Nullable superclass; const char *_Nonnull name; unsigned long version; unsigned long info; long instanceSize; struct objc_ivar_list *_Nullable ivars; struct objc_method_list *_Nullable methodList; | | | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | Class _Nullable superclass; const char *_Nonnull name; unsigned long version; unsigned long info; long instanceSize; struct objc_ivar_list *_Nullable ivars; struct objc_method_list *_Nullable methodList; struct objc_dtable *_Nonnull dTable; Class _Nullable *_Nullable subclassList; void *_Nullable siblingClass; struct objc_protocol_list *_Nullable protocols; void *_Nullable GCObjectType; unsigned long ABIVersion; int32_t *_Nonnull *_Nullable ivarOffsets; struct objc_property_list *_Nullable propertyList; |
︙ | ︙ | |||
197 198 199 200 201 202 203 | struct objc_hashtable_bucket *_Nonnull *_Nullable data; }; struct objc_sparsearray { struct objc_sparsearray_data { void *_Nullable next[256]; } *_Nonnull data; | | | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | struct objc_hashtable_bucket *_Nonnull *_Nullable data; }; struct objc_sparsearray { struct objc_sparsearray_data { void *_Nullable next[256]; } *_Nonnull data; uint8_t levels; }; struct objc_dtable { struct objc_dtable_level2 { #ifdef OF_SELUID24 struct objc_dtable_level3 { IMP _Nullable buckets[256]; |
︙ | ︙ | |||
277 278 279 280 281 282 283 | __gnu_objc_personality_sj0(version, actions, *exClass, ex, ctx) # else # define __gnu_objc_personality(version, actions, exClass, ex, ctx) \ __gnu_objc_personality_v0(version, actions, *exClass, ex, ctx) # endif #endif | | | | | | | | | | | | | | | | | | | | | | | | | > | 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | __gnu_objc_personality_sj0(version, actions, *exClass, ex, ctx) # else # define __gnu_objc_personality(version, actions, exClass, ex, ctx) \ __gnu_objc_personality_v0(version, actions, *exClass, ex, ctx) # endif #endif extern void objc_registerAllCategories(struct objc_symtab *_Nonnull); extern struct objc_category *_Nullable *_Nullable objc_categoriesForClass(Class _Nonnull); extern void objc_unregisterAllCategories(void); extern void objc_initializeClass(Class _Nonnull); extern void objc_updateDTable(Class _Nonnull); extern void objc_registerAllClasses(struct objc_symtab *_Nonnull); extern Class _Nullable objc_classnameToClass(const char *_Nonnull, bool); extern void objc_unregisterClass(Class _Nonnull); extern void objc_unregisterAllClasses(void); extern uint32_t objc_string_hash(const void *_Nonnull); extern bool objc_string_equal(const void *_Nonnull, const void *_Nonnull); extern struct objc_hashtable *_Nonnull objc_hashtable_new( objc_hashtable_hash_func, objc_hashtable_equal_func, uint32_t); extern struct objc_hashtable_bucket objc_deletedBucket; extern void objc_hashtable_set(struct objc_hashtable *_Nonnull, const void *_Nonnull, const void *_Nonnull); extern void *_Nullable objc_hashtable_get(struct objc_hashtable *_Nonnull, const void *_Nonnull); extern void objc_hashtable_delete(struct objc_hashtable *_Nonnull, const void *_Nonnull); extern void objc_hashtable_free(struct objc_hashtable *_Nonnull); extern void objc_registerSelector(struct objc_selector *_Nonnull); extern void objc_registerAllSelectors(struct objc_symtab *_Nonnull); extern void objc_unregisterAllSelectors(void); extern struct objc_sparsearray *_Nonnull objc_sparsearray_new(uint8_t); extern void *_Nullable objc_sparsearray_get(struct objc_sparsearray *_Nonnull, uintptr_t); extern void objc_sparsearray_set(struct objc_sparsearray *_Nonnull, uintptr_t, void *_Nullable); extern void objc_sparsearray_free(struct objc_sparsearray *_Nonnull); extern struct objc_dtable *_Nonnull objc_dtable_new(void); extern void objc_dtable_copy(struct objc_dtable *_Nonnull, struct objc_dtable *_Nonnull); extern void objc_dtable_set(struct objc_dtable *_Nonnull, uint32_t, IMP _Nullable); extern void objc_dtable_free(struct objc_dtable *_Nonnull); extern void objc_dtable_cleanup(void); extern void objc_initStaticInstances(struct objc_symtab *_Nonnull); extern void objc_forgetPendingStaticInstances(void); extern void objc_zeroWeakReferences(id _Nonnull); extern Class _Nullable object_getTaggedPointerClass(id _Nonnull); #ifdef OF_HAVE_THREADS extern void objc_globalMutex_lock(void); extern void objc_globalMutex_unlock(void); extern void objc_globalMutex_free(void); #else # define objc_globalMutex_lock() # define objc_globalMutex_unlock() # define objc_globalMutex_free() #endif extern char *_Nullable objc_strdup(const char *_Nonnull string); static inline IMP _Nullable objc_dtable_get(const struct objc_dtable *_Nonnull dtable, uint32_t idx) { #ifdef OF_SELUID24 uint8_t i = idx >> 16; uint8_t j = idx >> 8; |
︙ | ︙ |
Modified src/runtime/property.m from [9cb9ad8e02] to [6e20bc37ae].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #include <string.h> #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS | | | > | > | > > > | | | | | > | > | | > | > | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #include <string.h> #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" # define numSpinlocks 8 /* needs to be a power of 2 */ static OFSpinlock spinlocks[numSpinlocks]; static OF_INLINE size_t spinlockSlot(const void *ptr) { return ((size_t)((uintptr_t)ptr >> 4) & (numSpinlocks - 1)); } #endif #ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { for (size_t i = 0; i < numSpinlocks; i++) if (OFSpinlockNew(&spinlocks[i]) != 0) OBJC_ERROR("Failed to create spinlocks!"); } #endif id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic) { if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(ptr); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); @try { return [[*ptr retain] autorelease]; } @finally { if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); } #else return [[*ptr retain] autorelease]; #endif } return *(id *)(void *)((char *)self + offset); } void objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, bool atomic, signed char copy) { if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(ptr); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); @try { #endif id old = *ptr; switch (copy) { case 0: *ptr = [value retain]; break; case 2: *ptr = [value mutableCopy]; break; default: *ptr = [value copy]; } [old release]; #ifdef OF_HAVE_THREADS } @finally { if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); } #endif return; } id *ptr = (id *)(void *)((char *)self + offset); |
︙ | ︙ | |||
113 114 115 116 117 118 119 | /* The following methods are only required for GCC >= 4.6 */ void objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS | | | > | > | | > | > | 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 163 164 165 166 167 | /* The following methods are only required for GCC >= 4.6 */ void objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(src); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif return; } memcpy(dest, src, size); } void objc_setPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS size_t slot = spinlockSlot(src); if (OFSpinlockLock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to lock spinlock!"); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS if (OFSpinlockUnlock(&spinlocks[slot]) != 0) OBJC_ERROR("Failed to unlock spinlock!"); #endif return; } memcpy(dest, src, size); } |
︙ | ︙ | |||
163 164 165 166 167 168 169 | if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } | | | > | > > | | 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | if (class == Nil) { if (outCount != NULL) *outCount = 0; return NULL; } objc_globalMutex_lock(); count = 0; if (class->info & OBJC_CLASS_INFO_NEW_ABI) for (iter = class->propertyList; iter != NULL; iter = iter->next) count += iter->count; if (count == 0) { if (outCount != NULL) *outCount = 0; objc_globalMutex_unlock(); return NULL; } properties = malloc((count + 1) * sizeof(objc_property_t)); if (properties == NULL) OBJC_ERROR("Not enough memory to copy properties"); i = 0; for (iter = class->propertyList; iter != NULL; iter = iter->next) for (unsigned int j = 0; j < iter->count; j++) properties[i++] = &iter->properties[j]; if (i != count) OBJC_ERROR("Fatal internal inconsistency!"); properties[count] = NULL; if (outCount != NULL) *outCount = count; objc_globalMutex_unlock(); return properties; } const char * property_getName(objc_property_t property) { |
︙ | ︙ | |||
215 216 217 218 219 220 221 | bool nullIsError = false; if (strlen(name) != 1) return NULL; switch (*name) { case 'T': | | | | | 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | bool nullIsError = false; if (strlen(name) != 1) return NULL; switch (*name) { case 'T': ret = objc_strdup(property->getter.typeEncoding); nullIsError = true; break; case 'G': if (property->attributes & OBJC_PROPERTY_GETTER) { ret = objc_strdup(property->getter.name); nullIsError = true; } break; case 'S': if (property->attributes & OBJC_PROPERTY_SETTER) { ret = objc_strdup(property->setter.name); nullIsError = true; } break; #define BOOL_CASE(name, field, flag) \ case name: \ if (property->field & flag) { \ ret = calloc(1, 1); \ |
︙ | ︙ | |||
249 250 251 252 253 254 255 | BOOL_CASE('D', extendedAttributes, OBJC_PROPERTY_DYNAMIC) BOOL_CASE('W', extendedAttributes, OBJC_PROPERTY_WEAK) #undef BOOL_CASE } if (nullIsError && ret == NULL) OBJC_ERROR("Not enough memory to copy property attribute " | | | 265 266 267 268 269 270 271 272 273 274 275 | BOOL_CASE('D', extendedAttributes, OBJC_PROPERTY_DYNAMIC) BOOL_CASE('W', extendedAttributes, OBJC_PROPERTY_WEAK) #undef BOOL_CASE } if (nullIsError && ret == NULL) OBJC_ERROR("Not enough memory to copy property attribute " "value!"); return ret; } |
Modified src/runtime/protocol.m from [7bac61bcb9] to [375dff745f].
︙ | ︙ | |||
63 64 65 66 67 68 69 | for (struct objc_protocol_list *protocolList = class->protocols; protocolList != NULL; protocolList = protocolList->next) for (long i = 0; i < protocolList->count; i++) if (protocol_conformsToProtocol(protocolList->list[i], protocol)) return true; | | | | | | | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | for (struct objc_protocol_list *protocolList = class->protocols; protocolList != NULL; protocolList = protocolList->next) for (long i = 0; i < protocolList->count; i++) if (protocol_conformsToProtocol(protocolList->list[i], protocol)) return true; objc_globalMutex_lock(); if ((categories = objc_categoriesForClass(class)) == NULL) { objc_globalMutex_unlock(); return false; } for (long i = 0; categories[i] != NULL; i++) { for (struct objc_protocol_list *protocolList = categories[i]->protocols; protocolList != NULL; protocolList = protocolList->next) { for (long j = 0; j < protocolList->count; j++) { if (protocol_conformsToProtocol( protocolList->list[j], protocol)) { objc_globalMutex_unlock(); return true; } } } } objc_globalMutex_unlock(); return false; } |
Modified src/runtime/selector.m from [1d967febe8] to [595eb87101].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "ObjFWRT.h" #import "private.h" #import "macros.h" #ifdef OF_SELUID24 | | | | | | | | | | | | < < | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #import "ObjFWRT.h" #import "private.h" #import "macros.h" #ifdef OF_SELUID24 static const uint32_t maxSel = 0xFFFFFF; static const uint8_t selLevels = 3; #else static const uint32_t maxSel = 0xFFFF; static const uint8_t selLevels = 2; #endif static struct objc_hashtable *selectors = NULL; static uint32_t selectorsCount = 0; static struct objc_sparsearray *selectorNames = NULL; static void **freeList = NULL; static size_t freeListCount = 0; void objc_registerSelector(struct objc_selector *selector) { SEL existingSelector; const char *name; if (selectorsCount > maxSel) OBJC_ERROR("Out of selector slots!"); if (selectors == NULL) selectors = objc_hashtable_new( objc_string_hash, objc_string_equal, 2); else if ((existingSelector = objc_hashtable_get(selectors, (const char *)selector->UID)) != NULL) { selector->UID = existingSelector->UID; return; } if (selectorNames == NULL) selectorNames = objc_sparsearray_new(selLevels); name = (const char *)selector->UID; selector->UID = selectorsCount++; objc_hashtable_set(selectors, name, selector); objc_sparsearray_set(selectorNames, (uint32_t)selector->UID, (void *)name); } SEL sel_registerName(const char *name) { struct objc_selector *selector; objc_globalMutex_lock(); if (selectors != NULL && (selector = objc_hashtable_get(selectors, name)) != NULL) { objc_globalMutex_unlock(); return (SEL)selector; } if ((selector = malloc(sizeof(*selector))) == NULL || (selector->UID = (uintptr_t)objc_strdup(name)) == 0) OBJC_ERROR("Not enough memory to allocate selector!"); selector->typeEncoding = NULL; if ((freeList = realloc(freeList, sizeof(void *) * (freeListCount + 2))) == NULL) OBJC_ERROR("Not enough memory to allocate selector!"); freeList[freeListCount++] = selector; freeList[freeListCount++] = (char *)selector->UID; objc_registerSelector(selector); objc_globalMutex_unlock(); return (SEL)selector; } void objc_registerAllSelectors(struct objc_symtab *symtab) { struct objc_selector *selector; if (symtab->selectorRefs == NULL) return; for (selector = symtab->selectorRefs; selector->UID != 0; selector++) objc_registerSelector(selector); } const char * sel_getName(SEL selector) { const char *ret; objc_globalMutex_lock(); ret = objc_sparsearray_get(selectorNames, (uint32_t)selector->UID); objc_globalMutex_unlock(); return ret; } bool sel_isEqual(SEL selector1, SEL selector2) { return (selector1->UID == selector2->UID); } void objc_unregisterAllSelectors(void) { objc_hashtable_free(selectors); objc_sparsearray_free(selectorNames); if (freeList != NULL) { for (size_t i = 0; i < freeListCount; i++) free(freeList[i]); |
︙ | ︙ |
Modified src/runtime/sparsearray.m from [dc25cc4021] to [0600278cf2].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #include <stdio.h> #include <stdlib.h> #import "ObjFWRT.h" #import "private.h" struct objc_sparsearray * | | | < < | | | | | | | 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 61 62 63 64 65 66 67 68 69 | #include <stdio.h> #include <stdlib.h> #import "ObjFWRT.h" #import "private.h" struct objc_sparsearray * objc_sparsearray_new(uint8_t levels) { struct objc_sparsearray *sparsearray; if ((sparsearray = calloc(1, sizeof(*sparsearray))) == NULL || (sparsearray->data = calloc(1, sizeof(*sparsearray->data))) == NULL) OBJC_ERROR("Failed to allocate memory for sparse array!"); sparsearray->levels = levels; return sparsearray; } void * objc_sparsearray_get(struct objc_sparsearray *sparsearray, uintptr_t idx) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->levels - 1; i++) { uintptr_t j = (idx >> ((sparsearray->levels - i - 1) * 8)) & 0xFF; if ((iter = iter->next[j]) == NULL) return NULL; } return iter->next[idx & 0xFF]; } void objc_sparsearray_set(struct objc_sparsearray *sparsearray, uintptr_t idx, void *value) { struct objc_sparsearray_data *iter = sparsearray->data; for (uint8_t i = 0; i < sparsearray->levels - 1; i++) { uintptr_t j = (idx >> ((sparsearray->levels - i - 1) * 8)) & 0xFF; if (iter->next[j] == NULL) if ((iter->next[j] = calloc(1, sizeof(struct objc_sparsearray_data))) == NULL) OBJC_ERROR("Failed to allocate memory for " "sparse array!"); |
︙ | ︙ | |||
86 87 88 89 90 91 92 | free(data); } void objc_sparsearray_free(struct objc_sparsearray *sparsearray) { | | | 84 85 86 87 88 89 90 91 92 93 | free(data); } void objc_sparsearray_free(struct objc_sparsearray *sparsearray) { freeSparsearrayData(sparsearray->data, sparsearray->levels); free(sparsearray); } |
Modified src/runtime/static-instances.m from [9308a0dd6f] to [5b5e1b3d9a].
︙ | ︙ | |||
21 22 23 24 25 26 27 | #import "ObjFWRT.h" #import "private.h" static struct objc_static_instances **staticInstancesList = NULL; static size_t staticInstancesCount = 0; void | | | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #import "ObjFWRT.h" #import "private.h" static struct objc_static_instances **staticInstancesList = NULL; static size_t staticInstancesCount = 0; void objc_initStaticInstances(struct objc_symtab *symtab) { struct objc_static_instances **staticInstances; /* Check if the class for a static instance became available */ for (size_t i = 0; i < staticInstancesCount; i++) { Class class = objc_lookUpClass( staticInstancesList[i]->className); |
︙ | ︙ | |||
91 92 93 94 95 96 97 | staticInstancesList[staticInstancesCount++] = *staticInstances; } } } void | | | 91 92 93 94 95 96 97 98 99 100 101 102 103 | staticInstancesList[staticInstancesCount++] = *staticInstances; } } } void objc_forgetPendingStaticInstances() { free(staticInstancesList); staticInstancesList = NULL; staticInstancesCount = 0; } |
Modified src/runtime/synchronized.m from [fe8bbba7b5] to [4edf9604c8].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #include <stdio.h> #include <stdlib.h> #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | #include <stdio.h> #include <stdlib.h> #import "ObjFWRT.h" #import "private.h" #ifdef OF_HAVE_THREADS # import "OFPlainMutex.h" static struct Lock { id object; int count; OFPlainRecursiveMutex rmutex; struct Lock *next; } *locks = NULL; static OFPlainMutex mutex; OF_CONSTRUCTOR() { if (OFPlainMutexNew(&mutex) != 0) OBJC_ERROR("Failed to create mutex!"); } #endif int objc_sync_enter(id object) { if (object == nil) return 0; #ifdef OF_HAVE_THREADS struct Lock *lock; if (OFPlainMutexLock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); /* Look if we already have a lock */ for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) continue; lock->count++; if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (OFPlainRecursiveMutexLock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); return 0; } /* Create a new lock */ if ((lock = malloc(sizeof(*lock))) == NULL) OBJC_ERROR("Failed to allocate memory for mutex!"); if (OFPlainRecursiveMutexNew(&lock->rmutex) != 0) OBJC_ERROR("Failed to create mutex!"); lock->object = object; lock->count = 1; lock->next = locks; locks = lock; if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (OFPlainRecursiveMutexLock(&lock->rmutex) != 0) OBJC_ERROR("Failed to lock mutex!"); #endif return 0; } int objc_sync_exit(id object) { if (object == nil) return 0; #ifdef OF_HAVE_THREADS struct Lock *lock, *last = NULL; if (OFPlainMutexLock(&mutex) != 0) OBJC_ERROR("Failed to lock mutex!"); for (lock = locks; lock != NULL; lock = lock->next) { if (lock->object != object) { last = lock; continue; } if (OFPlainRecursiveMutexUnlock(&lock->rmutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); if (--lock->count == 0) { if (OFPlainRecursiveMutexFree(&lock->rmutex) != 0) OBJC_ERROR("Failed to destroy mutex!"); if (last != NULL) last->next = lock->next; if (locks == lock) locks = lock->next; free(lock); } if (OFPlainMutexUnlock(&mutex) != 0) OBJC_ERROR("Failed to unlock mutex!"); return 0; } OBJC_ERROR("objc_sync_exit() was called for an unlocked object!"); #else return 0; #endif } |
Modified src/runtime/tagged-pointer.m from [a6a4aa7d0f] to [84026d482b].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #import "ObjFWRT.h" #import "private.h" | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | * file. */ #import "ObjFWRT.h" #import "private.h" #define numTaggedPointerBits 4 #define maxNumTaggedPointerClasses (1 << (numTaggedPointerBits - 1)) Class objc_taggedPointerClasses[maxNumTaggedPointerClasses]; static int taggedPointerClassesCount; uintptr_t objc_taggedPointerSecret; void objc_setTaggedPointerSecret(uintptr_t secret) { objc_taggedPointerSecret = secret & ~(uintptr_t)1; } int objc_registerTaggedPointerClass(Class class) { int i; objc_globalMutex_lock(); if (taggedPointerClassesCount == maxNumTaggedPointerClasses) { objc_globalMutex_unlock(); return -1; } i = taggedPointerClassesCount++; objc_taggedPointerClasses[i] = class; objc_globalMutex_unlock(); return i; } bool object_isTaggedPointer(id object) { uintptr_t pointer = (uintptr_t)object; return pointer & 1; } Class object_getTaggedPointerClass(id object) { uintptr_t pointer = (uintptr_t)object ^ objc_taggedPointerSecret; pointer &= (1 << numTaggedPointerBits) - 1; pointer >>= 1; if (pointer >= maxNumTaggedPointerClasses) return Nil; return objc_taggedPointerClasses[pointer]; } uintptr_t object_getTaggedPointerValue(id object) { uintptr_t pointer = (uintptr_t)object ^ objc_taggedPointerSecret; pointer >>= numTaggedPointerBits; return pointer; } id objc_createTaggedPointer(int class, uintptr_t value) { uintptr_t pointer; if (class < 0 || class >= maxNumTaggedPointerClasses) return nil; if (value > (UINTPTR_MAX >> numTaggedPointerBits)) return nil; pointer = (class << 1) | 1; pointer |= (value << numTaggedPointerBits); return (id)(pointer ^ objc_taggedPointerSecret); } |
Modified src/runtime/threading.m from [13c9aec71c] to [9fcf574ba3].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #include <stdio.h> #include <stdlib.h> #import "ObjFWRT.h" #import "private.h" | > | | | | | | | | | | | 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 | #include "config.h" #include <stdio.h> #include <stdlib.h> #import "ObjFWRT.h" #import "private.h" #import "OFOnce.h" #import "OFPlainMutex.h" static OFPlainRecursiveMutex globalMutex; static void init(void) { if (OFPlainRecursiveMutexNew(&globalMutex) != 0) OBJC_ERROR("Failed to create global mutex!"); } void objc_globalMutex_lock(void) { static OFOnceControl onceControl = OFOnceControlInitValue; OFOnce(&onceControl, init); if (OFPlainRecursiveMutexLock(&globalMutex) != 0) OBJC_ERROR("Failed to lock global mutex!"); } void objc_globalMutex_unlock(void) { if (OFPlainRecursiveMutexUnlock(&globalMutex) != 0) OBJC_ERROR("Failed to unlock global mutex!"); } |
Modified src/unicode.h from [2ed16f1d09] to [fff23a1772].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFString.h" | | | | | | | | | | | | | | | | | | 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFString.h" #define OFUnicodeUppercaseTableSize 0x1EA #define OFUnicodeLowercaseTableSize 0x1EA #define OFUnicodeTitlecaseTableSize 0x1EA #define OFUnicodeCaseFoldingTableSize 0x1EA #define OFUnicodeDecompositionTableSize 0x2FB #define OFUnicodeDecompositionCompatTableSize 0x2FB #ifdef __cplusplus extern "C" { #endif extern const OFUnichar *const _Nonnull OFUnicodeUppercaseTable[OFUnicodeUppercaseTableSize]; extern const OFUnichar *const _Nonnull OFUnicodeLowercaseTable[OFUnicodeLowercaseTableSize]; extern const OFUnichar *const _Nonnull OFUnicodeTitlecaseTable[OFUnicodeTitlecaseTableSize]; extern const OFUnichar *const _Nonnull OFUnicodeCaseFoldingTable[OFUnicodeCaseFoldingTableSize]; extern const char *const _Nullable *const _Nonnull OFUnicodeDecompositionTable[OFUnicodeDecompositionTableSize]; extern const char *const _Nullable *const _Nonnull OFUnicodeDecompositionCompatTable[OFUnicodeDecompositionCompatTableSize]; #ifdef __cplusplus } #endif |
Modified src/unicode.m from [bb9481f3ae] to [a6f5c61cf3].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "OFString.h" | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * file. */ #include "config.h" #import "OFString.h" static const OFUnichar emptyPage[0x100] = { 0 }; static const char *emptyDecompositionPage[0x100] = { NULL }; static const OFUnichar uppercasePage0[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
51 52 53 54 55 56 57 | 0, 0, 0, 0, 0, 0, 0, 0, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 0, 216, 217, 218, 219, 220, 221, 222, 376, }; | | | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | 0, 0, 0, 0, 0, 0, 0, 0, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 0, 216, 217, 218, 219, 220, 221, 222, 376, }; static const OFUnichar uppercasePage1[0x100] = { 0, 256, 0, 258, 0, 260, 0, 262, 0, 264, 0, 266, 0, 268, 0, 270, 0, 272, 0, 274, 0, 276, 0, 278, 0, 280, 0, 282, 0, 284, 0, 286, 0, 288, 0, 290, 0, 292, 0, 294, 0, 296, 0, 298, 0, 300, 0, 302, 0, 73, 0, 306, 0, 308, 0, 310, |
︙ | ︙ | |||
86 87 88 89 90 91 92 | 471, 0, 473, 0, 475, 398, 0, 478, 0, 480, 0, 482, 0, 484, 0, 486, 0, 488, 0, 490, 0, 492, 0, 494, 0, 0, 497, 497, 0, 500, 0, 0, 0, 504, 0, 506, 0, 508, 0, 510, }; | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | 471, 0, 473, 0, 475, 398, 0, 478, 0, 480, 0, 482, 0, 484, 0, 486, 0, 488, 0, 490, 0, 492, 0, 494, 0, 0, 497, 497, 0, 500, 0, 0, 0, 504, 0, 506, 0, 508, 0, 510, }; static const OFUnichar uppercasePage2[0x100] = { 0, 512, 0, 514, 0, 516, 0, 518, 0, 520, 0, 522, 0, 524, 0, 526, 0, 528, 0, 530, 0, 532, 0, 534, 0, 536, 0, 538, 0, 540, 0, 542, 0, 0, 0, 546, 0, 548, 0, 550, 0, 552, 0, 554, 0, 556, 0, 558, 0, 560, 0, 562, 0, 0, 0, 0, |
︙ | ︙ | |||
121 122 123 124 125 126 127 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage3[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
156 157 158 159 160 161 162 | 0, 984, 0, 986, 0, 988, 0, 990, 0, 992, 0, 994, 0, 996, 0, 998, 0, 1000, 0, 1002, 0, 1004, 0, 1006, 922, 929, 1017, 895, 0, 917, 0, 0, 1015, 0, 0, 1018, 0, 0, 0, 0, }; | | | 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | 0, 984, 0, 986, 0, 988, 0, 990, 0, 992, 0, 994, 0, 996, 0, 998, 0, 1000, 0, 1002, 0, 1004, 0, 1006, 922, 929, 1017, 895, 0, 917, 0, 0, 1015, 0, 0, 1018, 0, 0, 0, 0, }; static const OFUnichar uppercasePage4[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, |
︙ | ︙ | |||
191 192 193 194 195 196 197 | 0, 1240, 0, 1242, 0, 1244, 0, 1246, 0, 1248, 0, 1250, 0, 1252, 0, 1254, 0, 1256, 0, 1258, 0, 1260, 0, 1262, 0, 1264, 0, 1266, 0, 1268, 0, 1270, 0, 1272, 0, 1274, 0, 1276, 0, 1278, }; | | | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | 0, 1240, 0, 1242, 0, 1244, 0, 1246, 0, 1248, 0, 1250, 0, 1252, 0, 1254, 0, 1256, 0, 1258, 0, 1260, 0, 1262, 0, 1264, 0, 1266, 0, 1268, 0, 1270, 0, 1272, 0, 1274, 0, 1276, 0, 1278, }; static const OFUnichar uppercasePage5[0x100] = { 0, 1280, 0, 1282, 0, 1284, 0, 1286, 0, 1288, 0, 1290, 0, 1292, 0, 1294, 0, 1296, 0, 1298, 0, 1300, 0, 1302, 0, 1304, 0, 1306, 0, 1308, 0, 1310, 0, 1312, 0, 1314, 0, 1316, 0, 1318, 0, 1320, 0, 1322, 0, 1324, 0, 1326, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
226 227 228 229 230 231 232 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage16[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
261 262 263 264 265 266 267 | 7320, 7321, 7322, 7323, 7324, 7325, 7326, 7327, 7328, 7329, 7330, 7331, 7332, 7333, 7334, 7335, 7336, 7337, 7338, 7339, 7340, 7341, 7342, 7343, 7344, 7345, 7346, 7347, 7348, 7349, 7350, 7351, 7352, 7353, 7354, 0, 0, 7357, 7358, 7359, }; | | | 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | 7320, 7321, 7322, 7323, 7324, 7325, 7326, 7327, 7328, 7329, 7330, 7331, 7332, 7333, 7334, 7335, 7336, 7337, 7338, 7339, 7340, 7341, 7342, 7343, 7344, 7345, 7346, 7347, 7348, 7349, 7350, 7351, 7352, 7353, 7354, 0, 0, 7357, 7358, 7359, }; static const OFUnichar uppercasePage19[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
296 297 298 299 300 301 302 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5104, 5105, 5106, 5107, 5108, 5109, 0, 0, }; | | | 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5104, 5105, 5106, 5107, 5108, 5109, 0, 0, }; static const OFUnichar uppercasePage28[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
331 332 333 334 335 336 337 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage29[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
366 367 368 369 370 371 372 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage30[0x100] = { 0, 7680, 0, 7682, 0, 7684, 0, 7686, 0, 7688, 0, 7690, 0, 7692, 0, 7694, 0, 7696, 0, 7698, 0, 7700, 0, 7702, 0, 7704, 0, 7706, 0, 7708, 0, 7710, 0, 7712, 0, 7714, 0, 7716, 0, 7718, 0, 7720, 0, 7722, 0, 7724, 0, 7726, 0, 7728, 0, 7730, 0, 7732, 0, 7734, |
︙ | ︙ | |||
401 402 403 404 405 406 407 | 0, 7896, 0, 7898, 0, 7900, 0, 7902, 0, 7904, 0, 7906, 0, 7908, 0, 7910, 0, 7912, 0, 7914, 0, 7916, 0, 7918, 0, 7920, 0, 7922, 0, 7924, 0, 7926, 0, 7928, 0, 7930, 0, 7932, 0, 7934, }; | | | 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | 0, 7896, 0, 7898, 0, 7900, 0, 7902, 0, 7904, 0, 7906, 0, 7908, 0, 7910, 0, 7912, 0, 7914, 0, 7916, 0, 7918, 0, 7920, 0, 7922, 0, 7924, 0, 7926, 0, 7928, 0, 7930, 0, 7932, 0, 7934, }; static const OFUnichar uppercasePage31[0x100] = { 7944, 7945, 7946, 7947, 7948, 7949, 7950, 7951, 0, 0, 0, 0, 0, 0, 0, 0, 7960, 7961, 7962, 7963, 7964, 7965, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7976, 7977, 7978, 7979, 7980, 7981, 7982, 7983, 0, 0, 0, 0, 0, 0, 0, 0, 7992, 7993, 7994, 7995, 7996, 7997, 7998, 7999, |
︙ | ︙ | |||
436 437 438 439 440 441 442 | 0, 0, 0, 0, 0, 0, 0, 0, 8168, 8169, 0, 0, 0, 8172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8188, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | 0, 0, 0, 0, 0, 0, 0, 0, 8168, 8169, 0, 0, 0, 8172, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8188, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage33[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
471 472 473 474 475 476 477 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage36[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
506 507 508 509 510 511 512 | 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414, 9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | 9406, 9407, 9408, 9409, 9410, 9411, 9412, 9413, 9414, 9415, 9416, 9417, 9418, 9419, 9420, 9421, 9422, 9423, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage44[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11264, 11265, 11266, 11267, 11268, 11269, 11270, 11271, |
︙ | ︙ | |||
541 542 543 544 545 546 547 | 0, 11480, 0, 11482, 0, 11484, 0, 11486, 0, 11488, 0, 11490, 0, 0, 0, 0, 0, 0, 0, 0, 11499, 0, 11501, 0, 0, 0, 0, 11506, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | 0, 11480, 0, 11482, 0, 11484, 0, 11486, 0, 11488, 0, 11490, 0, 0, 0, 0, 0, 0, 0, 0, 11499, 0, 11501, 0, 0, 0, 0, 11506, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage45[0x100] = { 4256, 4257, 4258, 4259, 4260, 4261, 4262, 4263, 4264, 4265, 4266, 4267, 4268, 4269, 4270, 4271, 4272, 4273, 4274, 4275, 4276, 4277, 4278, 4279, 4280, 4281, 4282, 4283, 4284, 4285, 4286, 4287, 4288, 4289, 4290, 4291, 4292, 4293, 0, 4295, 0, 0, 0, 0, 0, 4301, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
576 577 578 579 580 581 582 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage166[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
611 612 613 614 615 616 617 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage167[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42786, 0, 42788, 0, 42790, 0, 42792, 0, 42794, 0, 42796, 0, 42798, 0, 0, 0, 42802, 0, 42804, 0, 42806, |
︙ | ︙ | |||
646 647 648 649 650 651 652 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42997, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42997, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage171[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
681 682 683 684 685 686 687 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage255[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
716 717 718 719 720 721 722 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage260[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66560, 66561, 66562, 66563, 66564, 66565, 66566, 66567, 66568, 66569, 66570, 66571, 66572, 66573, 66574, 66575, |
︙ | ︙ | |||
751 752 753 754 755 756 757 | 66736, 66737, 66738, 66739, 66740, 66741, 66742, 66743, 66744, 66745, 66746, 66747, 66748, 66749, 66750, 66751, 66752, 66753, 66754, 66755, 66756, 66757, 66758, 66759, 66760, 66761, 66762, 66763, 66764, 66765, 66766, 66767, 66768, 66769, 66770, 66771, 0, 0, 0, 0, }; | | | 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | 66736, 66737, 66738, 66739, 66740, 66741, 66742, 66743, 66744, 66745, 66746, 66747, 66748, 66749, 66750, 66751, 66752, 66753, 66754, 66755, 66756, 66757, 66758, 66759, 66760, 66761, 66762, 66763, 66764, 66765, 66766, 66767, 66768, 66769, 66770, 66771, 0, 0, 0, 0, }; static const OFUnichar uppercasePage268[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
786 787 788 789 790 791 792 | 68760, 68761, 68762, 68763, 68764, 68765, 68766, 68767, 68768, 68769, 68770, 68771, 68772, 68773, 68774, 68775, 68776, 68777, 68778, 68779, 68780, 68781, 68782, 68783, 68784, 68785, 68786, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | 68760, 68761, 68762, 68763, 68764, 68765, 68766, 68767, 68768, 68769, 68770, 68771, 68772, 68773, 68774, 68775, 68776, 68777, 68778, 68779, 68780, 68781, 68782, 68783, 68784, 68785, 68786, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage280[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
821 822 823 824 825 826 827 | 71864, 71865, 71866, 71867, 71868, 71869, 71870, 71871, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 | 71864, 71865, 71866, 71867, 71868, 71869, 71870, 71871, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage366[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
856 857 858 859 860 861 862 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar uppercasePage489[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 125184, 125185, 125186, 125187, 125188, 125189, 125190, 125191, 125192, 125193, 125194, 125195, 125196, 125197, 125198, 125199, 125200, 125201, 125202, 125203, 125204, 125205, |
︙ | ︙ | |||
891 892 893 894 895 896 897 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage0[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
926 927 928 929 930 931 932 | 248, 249, 250, 251, 252, 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | 248, 249, 250, 251, 252, 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage1[0x100] = { 257, 0, 259, 0, 261, 0, 263, 0, 265, 0, 267, 0, 269, 0, 271, 0, 273, 0, 275, 0, 277, 0, 279, 0, 281, 0, 283, 0, 285, 0, 287, 0, 289, 0, 291, 0, 293, 0, 295, 0, 297, 0, 299, 0, 301, 0, 303, 0, 105, 0, 307, 0, 309, 0, 311, 0, |
︙ | ︙ | |||
961 962 963 964 965 966 967 | 0, 474, 0, 476, 0, 0, 479, 0, 481, 0, 483, 0, 485, 0, 487, 0, 489, 0, 491, 0, 493, 0, 495, 0, 0, 499, 499, 0, 501, 0, 405, 447, 505, 0, 507, 0, 509, 0, 511, 0, }; | | | 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 | 0, 474, 0, 476, 0, 0, 479, 0, 481, 0, 483, 0, 485, 0, 487, 0, 489, 0, 491, 0, 493, 0, 495, 0, 0, 499, 499, 0, 501, 0, 405, 447, 505, 0, 507, 0, 509, 0, 511, 0, }; static const OFUnichar lowercasePage2[0x100] = { 513, 0, 515, 0, 517, 0, 519, 0, 521, 0, 523, 0, 525, 0, 527, 0, 529, 0, 531, 0, 533, 0, 535, 0, 537, 0, 539, 0, 541, 0, 543, 0, 414, 0, 547, 0, 549, 0, 551, 0, 553, 0, 555, 0, 557, 0, 559, 0, 561, 0, 563, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
996 997 998 999 1000 1001 1002 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage3[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1031 1032 1033 1034 1035 1036 1037 | 985, 0, 987, 0, 989, 0, 991, 0, 993, 0, 995, 0, 997, 0, 999, 0, 1001, 0, 1003, 0, 1005, 0, 1007, 0, 0, 0, 0, 0, 952, 0, 0, 1016, 0, 1010, 1019, 0, 0, 891, 892, 893, }; | | | 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 | 985, 0, 987, 0, 989, 0, 991, 0, 993, 0, 995, 0, 997, 0, 999, 0, 1001, 0, 1003, 0, 1005, 0, 1007, 0, 0, 0, 0, 0, 952, 0, 0, 1016, 0, 1010, 1019, 0, 0, 891, 892, 893, }; static const OFUnichar lowercasePage4[0x100] = { 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1066 1067 1068 1069 1070 1071 1072 | 1241, 0, 1243, 0, 1245, 0, 1247, 0, 1249, 0, 1251, 0, 1253, 0, 1255, 0, 1257, 0, 1259, 0, 1261, 0, 1263, 0, 1265, 0, 1267, 0, 1269, 0, 1271, 0, 1273, 0, 1275, 0, 1277, 0, 1279, 0, }; | | | 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 | 1241, 0, 1243, 0, 1245, 0, 1247, 0, 1249, 0, 1251, 0, 1253, 0, 1255, 0, 1257, 0, 1259, 0, 1261, 0, 1263, 0, 1265, 0, 1267, 0, 1269, 0, 1271, 0, 1273, 0, 1275, 0, 1277, 0, 1279, 0, }; static const OFUnichar lowercasePage5[0x100] = { 1281, 0, 1283, 0, 1285, 0, 1287, 0, 1289, 0, 1291, 0, 1293, 0, 1295, 0, 1297, 0, 1299, 0, 1301, 0, 1303, 0, 1305, 0, 1307, 0, 1309, 0, 1311, 0, 1313, 0, 1315, 0, 1317, 0, 1319, 0, 1321, 0, 1323, 0, 1325, 0, 1327, 0, 0, 1377, 1378, 1379, 1380, 1381, 1382, 1383, |
︙ | ︙ | |||
1101 1102 1103 1104 1105 1106 1107 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage16[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1136 1137 1138 1139 1140 1141 1142 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage19[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1171 1172 1173 1174 1175 1176 1177 | 43944, 43945, 43946, 43947, 43948, 43949, 43950, 43951, 43952, 43953, 43954, 43955, 43956, 43957, 43958, 43959, 43960, 43961, 43962, 43963, 43964, 43965, 43966, 43967, 5112, 5113, 5114, 5115, 5116, 5117, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 | 43944, 43945, 43946, 43947, 43948, 43949, 43950, 43951, 43952, 43953, 43954, 43955, 43956, 43957, 43958, 43959, 43960, 43961, 43962, 43963, 43964, 43965, 43966, 43967, 5112, 5113, 5114, 5115, 5116, 5117, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage28[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1206 1207 1208 1209 1210 1211 1212 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage30[0x100] = { 7681, 0, 7683, 0, 7685, 0, 7687, 0, 7689, 0, 7691, 0, 7693, 0, 7695, 0, 7697, 0, 7699, 0, 7701, 0, 7703, 0, 7705, 0, 7707, 0, 7709, 0, 7711, 0, 7713, 0, 7715, 0, 7717, 0, 7719, 0, 7721, 0, 7723, 0, 7725, 0, 7727, 0, 7729, 0, 7731, 0, 7733, 0, 7735, 0, |
︙ | ︙ | |||
1241 1242 1243 1244 1245 1246 1247 | 7897, 0, 7899, 0, 7901, 0, 7903, 0, 7905, 0, 7907, 0, 7909, 0, 7911, 0, 7913, 0, 7915, 0, 7917, 0, 7919, 0, 7921, 0, 7923, 0, 7925, 0, 7927, 0, 7929, 0, 7931, 0, 7933, 0, 7935, 0, }; | | | 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | 7897, 0, 7899, 0, 7901, 0, 7903, 0, 7905, 0, 7907, 0, 7909, 0, 7911, 0, 7913, 0, 7915, 0, 7917, 0, 7919, 0, 7921, 0, 7923, 0, 7925, 0, 7927, 0, 7929, 0, 7931, 0, 7933, 0, 7935, 0, }; static const OFUnichar lowercasePage31[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943, 0, 0, 0, 0, 0, 0, 0, 0, 7952, 7953, 7954, 7955, 7956, 7957, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7968, 7969, 7970, 7971, 7972, 7973, 7974, 7975, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1276 1277 1278 1279 1280 1281 1282 | 8144, 8145, 8054, 8055, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8160, 8161, 8058, 8059, 8165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8056, 8057, 8060, 8061, 8179, 0, 0, 0, }; | | | 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 | 8144, 8145, 8054, 8055, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8160, 8161, 8058, 8059, 8165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8056, 8057, 8060, 8061, 8179, 0, 0, 0, }; static const OFUnichar lowercasePage33[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 969, 0, 0, 0, 107, 229, 0, 0, 0, 0, 0, 0, 8526, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1311 1312 1313 1314 1315 1316 1317 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage36[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1346 1347 1348 1349 1350 1351 1352 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage44[0x100] = { 11312, 11313, 11314, 11315, 11316, 11317, 11318, 11319, 11320, 11321, 11322, 11323, 11324, 11325, 11326, 11327, 11328, 11329, 11330, 11331, 11332, 11333, 11334, 11335, 11336, 11337, 11338, 11339, 11340, 11341, 11342, 11343, 11344, 11345, 11346, 11347, 11348, 11349, 11350, 11351, 11352, 11353, 11354, 11355, 11356, 11357, 11358, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1381 1382 1383 1384 1385 1386 1387 | 11481, 0, 11483, 0, 11485, 0, 11487, 0, 11489, 0, 11491, 0, 0, 0, 0, 0, 0, 0, 0, 11500, 0, 11502, 0, 0, 0, 0, 11507, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 | 11481, 0, 11483, 0, 11485, 0, 11487, 0, 11489, 0, 11491, 0, 0, 0, 0, 0, 0, 0, 0, 11500, 0, 11502, 0, 0, 0, 0, 11507, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage166[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1416 1417 1418 1419 1420 1421 1422 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage167[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42787, 0, 42789, 0, 42791, 0, 42793, 0, 42795, 0, 42797, 0, 42799, 0, 0, 0, 42803, 0, 42805, 0, 42807, 0, |
︙ | ︙ | |||
1451 1452 1453 1454 1455 1456 1457 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42998, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42998, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage255[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65345, 65346, 65347, 65348, 65349, 65350, 65351, 65352, 65353, 65354, 65355, 65356, 65357, 65358, 65359, 65360, 65361, 65362, 65363, 65364, 65365, 65366, 65367, |
︙ | ︙ | |||
1486 1487 1488 1489 1490 1491 1492 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage260[0x100] = { 66600, 66601, 66602, 66603, 66604, 66605, 66606, 66607, 66608, 66609, 66610, 66611, 66612, 66613, 66614, 66615, 66616, 66617, 66618, 66619, 66620, 66621, 66622, 66623, 66624, 66625, 66626, 66627, 66628, 66629, 66630, 66631, 66632, 66633, 66634, 66635, 66636, 66637, 66638, 66639, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1521 1522 1523 1524 1525 1526 1527 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage268[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1556 1557 1558 1559 1560 1561 1562 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage280[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1591 1592 1593 1594 1595 1596 1597 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage366[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1626 1627 1628 1629 1630 1631 1632 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar lowercasePage489[0x100] = { 125218, 125219, 125220, 125221, 125222, 125223, 125224, 125225, 125226, 125227, 125228, 125229, 125230, 125231, 125232, 125233, 125234, 125235, 125236, 125237, 125238, 125239, 125240, 125241, 125242, 125243, 125244, 125245, 125246, 125247, 125248, 125249, 125250, 125251, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1661 1662 1663 1664 1665 1666 1667 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar titlecasePage1[0x100] = { 0, 256, 0, 258, 0, 260, 0, 262, 0, 264, 0, 266, 0, 268, 0, 270, 0, 272, 0, 274, 0, 276, 0, 278, 0, 280, 0, 282, 0, 284, 0, 286, 0, 288, 0, 290, 0, 292, 0, 294, 0, 296, 0, 298, 0, 300, 0, 302, 0, 73, 0, 306, 0, 308, 0, 310, |
︙ | ︙ | |||
1696 1697 1698 1699 1700 1701 1702 | 471, 0, 473, 0, 475, 398, 0, 478, 0, 480, 0, 482, 0, 484, 0, 486, 0, 488, 0, 490, 0, 492, 0, 494, 0, 498, 498, 498, 0, 500, 0, 0, 0, 504, 0, 506, 0, 508, 0, 510, }; | | | 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 | 471, 0, 473, 0, 475, 398, 0, 478, 0, 480, 0, 482, 0, 484, 0, 486, 0, 488, 0, 490, 0, 492, 0, 494, 0, 498, 498, 498, 0, 500, 0, 0, 0, 504, 0, 506, 0, 508, 0, 510, }; static const OFUnichar titlecasePage16[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1731 1732 1733 1734 1735 1736 1737 | 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 0, 0, 4349, 4350, 4351, }; | | | 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 | 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 0, 0, 4349, 4350, 4351, }; static const OFUnichar caseFoldingPage0[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1766 1767 1768 1769 1770 1771 1772 | 248, 249, 250, 251, 252, 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 | 248, 249, 250, 251, 252, 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar caseFoldingPage1[0x100] = { 257, 0, 259, 0, 261, 0, 263, 0, 265, 0, 267, 0, 269, 0, 271, 0, 273, 0, 275, 0, 277, 0, 279, 0, 281, 0, 283, 0, 285, 0, 287, 0, 289, 0, 291, 0, 293, 0, 295, 0, 297, 0, 299, 0, 301, 0, 303, 0, 0, 0, 307, 0, 309, 0, 311, 0, |
︙ | ︙ | |||
1801 1802 1803 1804 1805 1806 1807 | 0, 474, 0, 476, 0, 0, 479, 0, 481, 0, 483, 0, 485, 0, 487, 0, 489, 0, 491, 0, 493, 0, 495, 0, 0, 499, 499, 0, 501, 0, 405, 447, 505, 0, 507, 0, 509, 0, 511, 0, }; | | | 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 | 0, 474, 0, 476, 0, 0, 479, 0, 481, 0, 483, 0, 485, 0, 487, 0, 489, 0, 491, 0, 493, 0, 495, 0, 0, 499, 499, 0, 501, 0, 405, 447, 505, 0, 507, 0, 509, 0, 511, 0, }; static const OFUnichar caseFoldingPage3[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1836 1837 1838 1839 1840 1841 1842 | 985, 0, 987, 0, 989, 0, 991, 0, 993, 0, 995, 0, 997, 0, 999, 0, 1001, 0, 1003, 0, 1005, 0, 1007, 0, 954, 961, 0, 0, 952, 949, 0, 1016, 0, 1010, 1019, 0, 0, 891, 892, 893, }; | | | 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 | 985, 0, 987, 0, 989, 0, 991, 0, 993, 0, 995, 0, 997, 0, 999, 0, 1001, 0, 1003, 0, 1005, 0, 1007, 0, 954, 961, 0, 0, 952, 949, 0, 1016, 0, 1010, 1019, 0, 0, 891, 892, 893, }; static const OFUnichar caseFoldingPage19[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1871 1872 1873 1874 1875 1876 1877 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5104, 5105, 5106, 5107, 5108, 5109, 0, 0, }; | | | 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5104, 5105, 5106, 5107, 5108, 5109, 0, 0, }; static const OFUnichar caseFoldingPage28[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1906 1907 1908 1909 1910 1911 1912 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; | | | 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; static const OFUnichar caseFoldingPage30[0x100] = { 7681, 0, 7683, 0, 7685, 0, 7687, 0, 7689, 0, 7691, 0, 7693, 0, 7695, 0, 7697, 0, 7699, 0, 7701, 0, 7703, 0, 7705, 0, 7707, 0, 7709, 0, 7711, 0, 7713, 0, 7715, 0, 7717, 0, 7719, 0, 7721, 0, 7723, 0, 7725, 0, 7727, 0, 7729, 0, 7731, 0, 7733, 0, 7735, 0, |
︙ | ︙ | |||
1941 1942 1943 1944 1945 1946 1947 | 7897, 0, 7899, 0, 7901, 0, 7903, 0, 7905, 0, 7907, 0, 7909, 0, 7911, 0, 7913, 0, 7915, 0, 7917, 0, 7919, 0, 7921, 0, 7923, 0, 7925, 0, 7927, 0, 7929, 0, 7931, 0, 7933, 0, 7935, 0, }; | | | 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 | 7897, 0, 7899, 0, 7901, 0, 7903, 0, 7905, 0, 7907, 0, 7909, 0, 7911, 0, 7913, 0, 7915, 0, 7917, 0, 7919, 0, 7921, 0, 7923, 0, 7925, 0, 7927, 0, 7929, 0, 7931, 0, 7933, 0, 7935, 0, }; static const OFUnichar caseFoldingPage31[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943, 0, 0, 0, 0, 0, 0, 0, 0, 7952, 7953, 7954, 7955, 7956, 7957, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7968, 7969, 7970, 7971, 7972, 7973, 7974, 7975, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
1976 1977 1978 1979 1980 1981 1982 | 8144, 8145, 8054, 8055, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8160, 8161, 8058, 8059, 8165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8056, 8057, 8060, 8061, 8179, 0, 0, 0, }; | | | 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 | 8144, 8145, 8054, 8055, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8160, 8161, 8058, 8059, 8165, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8056, 8057, 8060, 8061, 8179, 0, 0, 0, }; static const OFUnichar caseFoldingPage171[0x100] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
︙ | ︙ | |||
12360 12361 12362 12363 12364 12365 12366 | "\x36", "\x37", "\x38", "\x39", NULL, NULL, NULL, NULL, NULL, NULL, }; | | | 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 | "\x36", "\x37", "\x38", "\x39", NULL, NULL, NULL, NULL, NULL, NULL, }; const OFUnichar *const OFUnicodeUppercaseTable[0x1EA] = { uppercasePage0, uppercasePage1, uppercasePage2, uppercasePage3, uppercasePage4, uppercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage16, emptyPage, emptyPage, uppercasePage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, |
︙ | ︙ | |||
12486 12487 12488 12489 12490 12491 12492 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage489 }; | | | 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 12499 12500 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage489 }; const OFUnichar *const OFUnicodeLowercaseTable[0x1EA] = { lowercasePage0, lowercasePage1, lowercasePage2, lowercasePage3, lowercasePage4, lowercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage16, emptyPage, emptyPage, lowercasePage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, |
︙ | ︙ | |||
12612 12613 12614 12615 12616 12617 12618 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage489 }; | | | 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage489 }; const OFUnichar *const OFUnicodeTitlecaseTable[0x1EA] = { uppercasePage0, titlecasePage1, uppercasePage2, uppercasePage3, uppercasePage4, uppercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, titlecasePage16, emptyPage, emptyPage, uppercasePage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, |
︙ | ︙ | |||
12738 12739 12740 12741 12742 12743 12744 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage489 }; | | | | | | | | 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, uppercasePage489 }; const OFUnichar *const OFUnicodeCaseFoldingTable[0x1EA] = { caseFoldingPage0, caseFoldingPage1, lowercasePage2, caseFoldingPage3, lowercasePage4, lowercasePage5, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage16, emptyPage, emptyPage, caseFoldingPage19, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, caseFoldingPage28, emptyPage, caseFoldingPage30, caseFoldingPage31, emptyPage, lowercasePage33, emptyPage, emptyPage, lowercasePage36, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage44, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, |
︙ | ︙ | |||
12796 12797 12798 12799 12800 12801 12802 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage166, lowercasePage167, emptyPage, emptyPage, emptyPage, | | | 12796 12797 12798 12799 12800 12801 12802 12803 12804 12805 12806 12807 12808 12809 12810 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage166, lowercasePage167, emptyPage, emptyPage, emptyPage, caseFoldingPage171, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, |
︙ | ︙ | |||
12905 12906 12907 12908 12909 12910 12911 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage489 }; | | | 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 | emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, emptyPage, lowercasePage489 }; const char *const *OFUnicodeDecompositionTable[0x2FB] = { decompositionPage0, decompositionPage1, decompositionPage2, decompositionPage3, decompositionPage4, emptyDecompositionPage, decompositionPage6, emptyDecompositionPage, emptyDecompositionPage, decompositionPage9, decompositionPage10, decompositionPage11, decompositionPage12, decompositionPage13, emptyDecompositionPage, decompositionPage15, decompositionPage16, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, |
︙ | ︙ | |||
13163 13164 13165 13166 13167 13168 13169 | emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, decompositionPage760, decompositionPage761, decompositionPage762 }; | | | 13163 13164 13165 13166 13167 13168 13169 13170 13171 13172 13173 13174 13175 13176 13177 | emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, decompositionPage760, decompositionPage761, decompositionPage762 }; const char *const *OFUnicodeDecompositionCompatTable[0x2FB] = { decompCompatPage0, decompCompatPage1, decompCompatPage2, decompCompatPage3, decompositionPage4, decompCompatPage5, decompCompatPage6, emptyDecompositionPage, emptyDecompositionPage, decompositionPage9, decompositionPage10, decompositionPage11, decompCompatPage12, decompCompatPage13, decompCompatPage14, decompCompatPage15, decompCompatPage16, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, emptyDecompositionPage, |
︙ | ︙ |
Modified tests/ForwardingTests.m from [469bc2e23f] to [4df4ada152].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" #define FORMAT @"%@ %@ %@ %@ %@ %@ %@ %@ %@ %g %g %g %g %g %g %g %g %g" #define ARGS @"a", @"b", @"c", @"d", @"e", @"f", @"g", @"h", @"i", \ 1.5, 2.25, 3.125, 4.0625, 5.03125, 6.5, 7.25, 8.0, 9.0 #define RESULT @"a b c d e f g h i 1.5 2.25 3.125 4.0625 5.03125 6.5 7.25 8 9" static OFString *const module = @"Forwarding"; static size_t forwardingsCount = 0; static bool success = false; static id target = nil; struct StretTest { char buffer[1024]; }; @interface ForwardingTest: OFObject @end @interface ForwardingTest (Test) + (void)test; - (void)test; - (uint32_t)forwardingTargetTest: (intptr_t)a0 : (intptr_t)a1 : (double)a2 : (double)a3; - (OFString *)forwardingTargetVarArgTest: (OFConstantString *)format, ...; - (long double)forwardingTargetFPRetTest; - (struct StretTest)forwardingTargetStRetTest; - (void)forwardingTargetNilTest; - (void)forwardingTargetSelfTest; - (struct StretTest)forwardingTargetNilStRetTest; - (struct StretTest)forwardingTargetSelfStRetTest; @end @interface ForwardingTarget: OFObject @end static void test(id self, SEL _cmd) { success = true; } @implementation ForwardingTest + (bool)resolveClassMethod: (SEL)selector { forwardingsCount++; if (sel_isEqual(selector, @selector(test))) { class_replaceMethod(object_getClass(self), @selector(test), (IMP)test, "v#:"); return YES; } return NO; } + (bool)resolveInstanceMethod: (SEL)selector { forwardingsCount++; if (sel_isEqual(selector, @selector(test))) { class_replaceMethod(self, @selector(test), (IMP)test, "v@:"); return YES; } return NO; |
︙ | ︙ | |||
123 124 125 126 127 128 129 | @implementation ForwardingTarget - (uint32_t)forwardingTargetTest: (intptr_t)a0 : (intptr_t)a1 : (double)a2 : (double)a3 { | | | | | | | | | | | | > | | | > | | | | | > | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | @implementation ForwardingTarget - (uint32_t)forwardingTargetTest: (intptr_t)a0 : (intptr_t)a1 : (double)a2 : (double)a3 { OFEnsure(self == target); if (a0 != (intptr_t)0xDEADBEEF) return 0; if (a1 != -1) return 0; if (a2 != 1.25) return 0; if (a3 != 2.75) return 0; return 0x12345678; } - (OFString *)forwardingTargetVarArgTest: (OFConstantString *)format, ... { va_list args; OFString *ret; OFEnsure(self == target); va_start(args, format); ret = [[[OFString alloc] initWithFormat: format arguments: args] autorelease]; va_end(args); return ret; } - (long double)forwardingTargetFPRetTest { OFEnsure(self == target); return 12345678.00006103515625; } - (struct StretTest)forwardingTargetStRetTest { struct StretTest ret = { { 0 } }; OFEnsure(self == target); memcpy(ret.buffer, "abcdefghijklmnopqrstuvwxyz", 27); return ret; } @end @implementation TestsAppDelegate (ForwardingTests) - (void)forwardingTests { void *pool = objc_autoreleasePoolPush(); TEST(@"Forwarding a message and adding a class method", R([ForwardingTest test]) && success && R([ForwardingTest test]) && forwardingsCount == 1); ForwardingTest *testObject = [[[ForwardingTest alloc] init] autorelease]; success = false; forwardingsCount = 0; TEST(@"Forwarding a message and adding an instance method", R([testObject test]) && success && R([testObject test]) && forwardingsCount == 1); #ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR target = [[[ForwardingTarget alloc] init] autorelease]; TEST(@"-[forwardingTargetForSelector:]", [testObject forwardingTargetTest: 0xDEADBEEF : -1 : 1.25 : 2.75] == 0x12345678) TEST(@"-[forwardingTargetForSelector:] variable arguments", [[testObject forwardingTargetVarArgTest: FORMAT, ARGS] isEqual: RESULT]) /* * Don't try fpret on Win64 if we don't have stret forwarding, as * long double is handled as a struct there. */ # if !defined(OF_WINDOWS) || !defined(OF_X86_64) || \ defined(OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET) TEST(@"-[forwardingTargetForSelector:] fp return", [testObject forwardingTargetFPRetTest] == 12345678.00006103515625) # endif # ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET TEST(@"-[forwardingTargetForSelector:] struct return", !memcmp([testObject forwardingTargetStRetTest].buffer, "abcdefghijklmnopqrstuvwxyz", 27)) # endif EXPECT_EXCEPTION(@"-[forwardingTargetForSelector:] nil target", OFNotImplementedException, [testObject forwardingTargetNilTest]) EXPECT_EXCEPTION(@"-[forwardingTargetForSelector:] self target", OFNotImplementedException, [testObject forwardingTargetSelfTest]) # ifdef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET EXPECT_EXCEPTION(@"-[forwardingTargetForSelector:] nil target + " @"stret", OFNotImplementedException, [testObject forwardingTargetNilStRetTest]) EXPECT_EXCEPTION(@"-[forwardingTargetForSelector:] self target + " @"stret", OFNotImplementedException, [testObject forwardingTargetSelfStRetTest]) # endif #endif objc_autoreleasePoolPop(pool); } @end |
Modified tests/Makefile from [6a6c363390] to [c2c3a7e8c9].
1 2 3 4 5 6 7 8 9 10 11 12 13 | include ../extra.mk SUBDIRS = ${TESTPLUGIN} CLEAN = EBOOT.PBP \ boot.dol \ ${PROG_NOINST}.arm9 \ ${PROG_NOINST}.nds DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ | < < > > < < < | | | | < | > | | | > | | > | > | > | 1 2 3 4 5 6 7 8 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | include ../extra.mk SUBDIRS = ${TESTPLUGIN} CLEAN = EBOOT.PBP \ boot.dol \ ${PROG_NOINST}.arm9 \ ${PROG_NOINST}.nds DISTCLEAN = Info.plist PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = ForwardingTests.m \ OFArrayTests.m \ ${OF_BLOCK_TESTS_M} \ OFCharacterSetTests.m \ OFDataTests.m \ OFDateTests.m \ OFDictionaryTests.m \ OFInvocationTests.m \ OFJSONTests.m \ OFListTests.m \ OFLocaleTests.m \ OFMethodSignatureTests.m \ OFNumberTests.m \ OFObjectTests.m \ OFPBKDF2Tests.m \ OFPropertyListTests.m \ OFScryptTests.m \ OFSetTests.m \ OFStreamTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFURLTests.m \ OFValueTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ RuntimeTests.m \ ${RUNTIME_ARC_TESTS_M} \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_THREADS} \ ${USE_SRCS_WINDOWS} SRCS_FILES = OFHMACTests.m \ OFINIFileTests.m \ OFMD5HashTests.m \ OFRIPEMD160HashTests.m \ OFSerializationTests.m \ OFSHA1HashTests.m \ OFSHA224HashTests.m \ OFSHA256HashTests.m \ OFSHA384HashTests.m \ OFSHA512HashTests.m SRCS_IPX = OFIPXSocketTests.m \ OFSPXSocketTests.m \ OFSPXStreamSocketTests.m SRCS_PLUGINS = OFPluginTests.m SRCS_SOCKETS = OFDNSResolverTests.m \ ${OF_HTTP_CLIENT_TESTS_M} \ OFHTTPCookieTests.m \ OFHTTPCookieManagerTests.m \ OFKernelEventObserverTests.m \ OFSocketTests.m \ OFTCPSocketTests.m \ OFUDPSocketTests.m \ ${USE_SRCS_IPX} SRCS_THREADS = OFThreadTests.m SRCS_WINDOWS = OFWindowsRegistryKeyTests.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test include ../buildsys.mk post-all: ${RUN_TESTS} .PHONY: run run-on-ios run-on-android run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib rm -f ${OBJFWRT_AMIGA_LIB} if test -f ../src/libobjfw.so; then \ ${LN_S} ../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../src/libobjfw.dylib; then \ ${LN_S} ../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../src/runtime/libobjfwrt.so; then \ ${LN_S} ../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi if test -f ../src/runtime/${OBJFWRT_AMIGA_LIB}; then \ ${LN_S} ../src/runtime/${OBJFWRT_AMIGA_LIB} \ ${OBJFWRT_AMIGA_LIB}; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_FRAMEWORK_PATH=../src:../src/runtime$${DYLD_FRAMEWORK_PATH+:}$$DYLD_FRAMEWORK_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ASAN_OPTIONS=allocator_may_return_null=1 \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT run-on-ios: all if [ -z "${IOS_HOST}" ]; then \ echo "Please set IOS_HOST to the hostname of your iOS host!"; \ exit 1; \ |
︙ | ︙ |
Deleted tests/OFASN1DERParsingTests.m version [70f5ebfaac].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted tests/OFASN1DERRepresentationTests.m version [2719fd4ef9].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified tests/OFArrayTests.m from [2e6d46311e] to [0c4712974c].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *module; static OFString *const cArray[] = { @"Foo", @"Bar", @"Baz" }; @interface SimpleArray: OFArray { |
︙ | ︙ | |||
47 48 49 50 51 52 53 | [self release]; @throw e; } return self; } | | < | < | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)object arguments: (va_list)arguments { self = [super init]; @try { _array = [[OFMutableArray alloc] initWithObject: object arguments: arguments]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithObjects: (id const *)objects count: (size_t)count { self = [super init]; @try { _array = [[OFMutableArray alloc] initWithObjects: objects count: count]; } @catch (id e) { |
︙ | ︙ | |||
104 105 106 107 108 109 110 | @implementation SimpleMutableArray + (void)initialize { if (self == [SimpleMutableArray class]) [self inheritMethodsFromClass: [SimpleArray class]]; } | | < | < | < | < | | | | > | | < | | | > | | | | > | > | | | | | | | | | | | | | | | | | | | < | | | | | | | | | < | | | | > | > | | > > | | | > | | | | < < > > > | | | > | | | | | | | | | | | | | | | > | | | | > | | | < | | | | | | < | | < | < | < | | | | | | | | | | | > | | | | | | | | | | | | | > | | | | | | | | | > | | | | | | | | > | | | | | | | | 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | @implementation SimpleMutableArray + (void)initialize { if (self == [SimpleMutableArray class]) [self inheritMethodsFromClass: [SimpleArray class]]; } - (void)insertObject: (id)object atIndex: (size_t)idx { [_array insertObject: object atIndex: idx]; } - (void)replaceObjectAtIndex: (size_t)idx withObject: (id)object { [_array replaceObjectAtIndex: idx withObject: object]; } - (void)removeObjectAtIndex: (size_t)idx { [_array removeObjectAtIndex: idx]; } @end @implementation TestsAppDelegate (OFArrayTests) - (void)arrayTestsWithClass: (Class)arrayClass mutableClass: (Class)mutableArrayClass { void *pool = objc_autoreleasePoolPush(); OFArray *array1, *array2; OFMutableArray *mutableArray1, *mutableArray2; OFEnumerator *enumerator; id object; bool ok; size_t i; TEST(@"+[array]", (mutableArray1 = [mutableArrayClass array])) TEST(@"+[arrayWithObjects:]", (array1 = [arrayClass arrayWithObjects: @"Foo", @"Bar", @"Baz", nil])) TEST(@"+[arrayWithObjects:count:]", (array2 = [arrayClass arrayWithObjects: cArray count: 3]) && [array2 isEqual: array1]) TEST(@"-[description]", [array1.description isEqual: @"(\n\tFoo,\n\tBar,\n\tBaz\n)"]) TEST(@"-[addObject:]", R([mutableArray1 addObject: cArray[0]]) && R([mutableArray1 addObject: cArray[2]])) TEST(@"-[insertObject:atIndex:]", R([mutableArray1 insertObject: cArray[1] atIndex: 1])) TEST(@"-[count]", mutableArray1.count == 3 && array1.count == 3 && array2.count == 3) TEST(@"-[isEqual:]", [mutableArray1 isEqual: array1] && [array1 isEqual: array2]) TEST(@"-[objectAtIndex:]", [[mutableArray1 objectAtIndex: 0] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 1] isEqual: cArray[1]] && [[mutableArray1 objectAtIndex: 2] isEqual: cArray[2]] && [[array1 objectAtIndex: 0] isEqual: cArray[0]] && [[array1 objectAtIndex: 1] isEqual: cArray[1]] && [[array1 objectAtIndex: 2] isEqual: cArray[2]] && [[array2 objectAtIndex: 0] isEqual: cArray[0]] && [[array2 objectAtIndex: 1] isEqual: cArray[1]] && [[array2 objectAtIndex: 2] isEqual: cArray[2]]) TEST(@"-[containsObject:]", [array1 containsObject: cArray[1]] && ![array1 containsObject: @"nonexistent"]) TEST(@"-[containsObjectIdenticalTo:]", [array1 containsObjectIdenticalTo: cArray[1]] && ![array1 containsObjectIdenticalTo: [OFString stringWithString: cArray[1]]]) TEST(@"-[indexOfObject:]", [array1 indexOfObject: cArray[1]] == 1) TEST(@"-[indexOfObjectIdenticalTo:]", [array2 indexOfObjectIdenticalTo: cArray[1]] == 1) TEST(@"-[objectsInRange:]", [[array1 objectsInRange: OFRangeMake(1, 2)] isEqual: [arrayClass arrayWithObjects: cArray[1], cArray[2], nil]]) TEST(@"-[replaceObject:withObject:]", R([mutableArray1 replaceObject: cArray[1] withObject: cArray[0]]) && [[mutableArray1 objectAtIndex: 0] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 1] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 2] isEqual: cArray[2]]) TEST(@"-[replaceObject:identicalTo:]", R([mutableArray1 replaceObjectIdenticalTo: cArray[0] withObject: cArray[1]]) && [[mutableArray1 objectAtIndex: 0] isEqual: cArray[1]] && [[mutableArray1 objectAtIndex: 1] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 2] isEqual: cArray[2]]) TEST(@"-[replaceObjectAtIndex:withObject:]", R([mutableArray1 replaceObjectAtIndex: 0 withObject: cArray[0]]) && [[mutableArray1 objectAtIndex: 0] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 1] isEqual: cArray[0]] && [[mutableArray1 objectAtIndex: 2] isEqual: cArray[2]]) TEST(@"-[removeObject:]", R([mutableArray1 removeObject: cArray[0]]) && mutableArray1.count == 2) TEST(@"-[removeObjectIdenticalTo:]", R([mutableArray1 removeObjectIdenticalTo: cArray[2]]) && mutableArray1.count == 1) mutableArray2 = [[array1 mutableCopy] autorelease]; TEST(@"-[removeObjectAtIndex:]", R([mutableArray2 removeObjectAtIndex: 1]) && mutableArray2.count == 2 && [[mutableArray2 objectAtIndex: 1] isEqual: cArray[2]]) mutableArray2 = [[array1 mutableCopy] autorelease]; TEST(@"-[removeObjectsInRange:]", R([mutableArray2 removeObjectsInRange: OFRangeMake(0, 2)]) && mutableArray2.count == 1 && [[mutableArray2 objectAtIndex: 0] isEqual: cArray[2]]) mutableArray2 = [[array1 mutableCopy] autorelease]; [mutableArray2 addObject: @"qux"]; [mutableArray2 addObject: @"last"]; TEST(@"-[reverse]", R([mutableArray2 reverse]) && [mutableArray2 isEqual: [arrayClass arrayWithObjects: @"last", @"qux", @"Baz", @"Bar", @"Foo", nil]]) mutableArray2 = [[array1 mutableCopy] autorelease]; [mutableArray2 addObject: @"qux"]; [mutableArray2 addObject: @"last"]; TEST(@"-[reversedArray]", [[mutableArray2 reversedArray] isEqual: [arrayClass arrayWithObjects: @"last", @"qux", @"Baz", @"Bar", @"Foo", nil]]) mutableArray2 = [[array1 mutableCopy] autorelease]; [mutableArray2 addObject: @"0"]; [mutableArray2 addObject: @"z"]; TEST(@"-[sortedArray]", [[mutableArray2 sortedArray] isEqual: [arrayClass arrayWithObjects: @"0", @"Bar", @"Baz", @"Foo", @"z", nil]] && [[mutableArray2 sortedArrayUsingSelector: @selector(compare:) options: OFArraySortDescending] isEqual: [arrayClass arrayWithObjects: @"z", @"Foo", @"Baz", @"Bar", @"0", nil]]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [array1 objectAtIndex: array1.count]) EXPECT_EXCEPTION(@"Detect out of range in -[removeObjectsInRange:]", OFOutOfRangeException, [mutableArray1 removeObjectsInRange: OFRangeMake(0, mutableArray1.count + 1)]) TEST(@"-[componentsJoinedByString:]", (array2 = [arrayClass arrayWithObjects: @"", @"a", @"b", @"c", nil]) && [[array2 componentsJoinedByString: @" "] isEqual: @" a b c"] && (array2 = [arrayClass arrayWithObject: @"foo"]) && [[array2 componentsJoinedByString: @" "] isEqual: @"foo"]) TEST(@"-[componentsJoinedByString:options]", (array2 = [arrayClass arrayWithObjects: @"", @"foo", @"", @"", @"bar", @"", nil]) && [[array2 componentsJoinedByString: @" " options: OFArraySkipEmptyComponents] isEqual: @"foo bar"]) mutableArray1 = [[array1 mutableCopy] autorelease]; ok = true; i = 0; TEST(@"-[objectEnumerator]", (enumerator = [mutableArray1 objectEnumerator])) while ((object = [enumerator nextObject]) != nil) { if (![object isEqual: cArray[i]]) ok = false; [mutableArray1 replaceObjectAtIndex: i withObject: @""]; i++; } if (mutableArray1.count != i) ok = false; TEST(@"OFEnumerator's -[nextObject]", ok) [mutableArray1 removeObjectAtIndex: 0]; EXPECT_EXCEPTION(@"Detection of mutation during enumeration", OFEnumerationMutationException, [enumerator nextObject]) mutableArray1 = [[array1 mutableCopy] autorelease]; ok = true; i = 0; for (OFString *string in mutableArray1) { if (![string isEqual: cArray[i]]) ok = false; [mutableArray1 replaceObjectAtIndex: i withObject: @""]; i++; } if (mutableArray1.count != i) ok = false; TEST(@"Fast Enumeration", ok) [mutableArray1 replaceObjectAtIndex: 0 withObject: cArray[0]]; [mutableArray1 replaceObjectAtIndex: 1 withObject: cArray[1]]; [mutableArray1 replaceObjectAtIndex: 2 withObject: cArray[2]]; ok = false; i = 0; @try { for (OFString *string in mutableArray1) { (void)string; if (i == 0) [mutableArray1 addObject: @""]; i++; } } @catch (OFEnumerationMutationException *e) { ok = true; } TEST(@"Detection of mutation during Fast Enumeration", ok) [mutableArray1 removeLastObject]; #ifdef OF_HAVE_BLOCKS { __block bool blockOK = true; __block size_t count = 0; OFArray *compareArray = array1; OFMutableArray *mutableArray3; mutableArray1 = [[array1 mutableCopy] autorelease]; [mutableArray1 enumerateObjectsUsingBlock: ^ (id object_, size_t idx, bool *stop) { count++; if (![object_ isEqual: [compareArray objectAtIndex: idx]]) blockOK = false; }]; if (count != compareArray.count) blockOK = false; TEST(@"Enumeration using blocks", blockOK) blockOK = false; mutableArray3 = mutableArray1; @try { [mutableArray3 enumerateObjectsUsingBlock: ^ (id object_, size_t idx, bool *stop) { [mutableArray3 removeObjectAtIndex: idx]; }]; } @catch (OFEnumerationMutationException *e) { blockOK = true; } @catch (OFOutOfRangeException *e) { /* * Out of bounds access due to enumeration not being * detected. */ } TEST(@"Detection of mutation during enumeration using blocks", blockOK) } TEST(@"-[replaceObjectsUsingBlock:]", R([mutableArray1 replaceObjectsUsingBlock: ^ id (id object_, size_t idx) { switch (idx) { case 0: return @"foo"; case 1: return @"bar"; } return nil; }]) && [mutableArray1.description isEqual: @"(\n\tfoo,\n\tbar\n)"]) TEST(@"-[mappedArrayUsingBlock:]", [[mutableArray1 mappedArrayUsingBlock: ^ id (id object_, size_t idx) { switch (idx) { case 0: return @"foobar"; case 1: return @"qux"; } return nil; }].description isEqual: @"(\n\tfoobar,\n\tqux\n)"]) TEST(@"-[filteredArrayUsingBlock:]", [[mutableArray1 filteredArrayUsingBlock: ^ bool (id object_, size_t idx) { return [object_ isEqual: @"foo"]; }].description isEqual: @"(\n\tfoo\n)"]) TEST(@"-[foldUsingBlock:]", [[arrayClass arrayWithObjects: [OFMutableString string], @"foo", @"bar", @"baz", nil] foldUsingBlock: ^ id (id left, id right) { [left appendString: right]; return left; }]) #endif TEST(@"-[valueForKey:]", [[[arrayClass arrayWithObjects: @"foo", @"bar", @"quxqux", nil] valueForKey: @"length"] isEqual: [arrayClass arrayWithObjects: [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 3], [OFNumber numberWithInt: 6], nil]] && [[[arrayClass arrayWithObjects: @"1", @"2", nil] valueForKey: @"@count"] isEqual: [OFNumber numberWithInt: 2]]) mutableArray1 = [mutableArrayClass arrayWithObjects: [OFMutableURL URLWithString: @"http://foo.bar/"], [OFMutableURL URLWithString: @"http://bar.qux/"], [OFMutableURL URLWithString: @"http://qux.quxqux/"], nil]; TEST(@"-[setValue:forKey:]", R([mutableArray1 setValue: [OFNumber numberWithShort: 1234] forKey: @"port"]) && [mutableArray1 isEqual: [arrayClass arrayWithObjects: [OFURL URLWithString: @"http://foo.bar:1234/"], [OFURL URLWithString: @"http://bar.qux:1234/"], [OFURL URLWithString: @"http://qux.quxqux:1234/"], nil]]) objc_autoreleasePoolPop(pool); } |
︙ | ︙ |
Modified tests/OFBlockTests.m from [dc2e6666e8] to [52123616f6].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | | | | > | > > | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFBlock"; #if defined(OF_OBJFW_RUNTIME) extern struct objc_class _NSConcreteStackBlock; extern struct objc_class _NSConcreteGlobalBlock; extern struct objc_class _NSConcreteMallocBlock; #elif defined(OF_APPLE_RUNTIME) extern void *_NSConcreteStackBlock; extern void *_NSConcreteGlobalBlock; extern void *_NSConcreteMallocBlock; #endif static void (^globalBlock)(void) = ^ {}; static int (^returnStackBlock(void))(void) { __block int i = 42; return [Block_copy(^ int { return ++i; }) autorelease]; } static double forwardTest(void) { __block double d; void (^block)(void) = Block_copy(^ { d = 5; }); block(); Block_release(block); return d; } @implementation TestsAppDelegate (OFBlockTests) - (void)blockTests { void *pool = objc_autoreleasePoolPush(); __block int x; void (^stackBlock)(void) = ^ { x = 0; }; void (^mallocBlock)(void); int (^voidBlock)(void); TEST(@"Class of stack block", (Class)&_NSConcreteStackBlock == objc_getClass("OFStackBlock") && [stackBlock isKindOfClass: [OFBlock class]]) #if !defined(OF_WINDOWS) || !defined(__clang__) || !defined(OF_NO_SHARED) /* * Causes a linker error on Windows with Clang when compiling as a * static library. This is a bug in Clang. */ TEST(@"Class of global block", (Class)&_NSConcreteGlobalBlock == objc_getClass("OFGlobalBlock") && [globalBlock isKindOfClass: [OFBlock class]]) #endif TEST(@"Class of a malloc block", (Class)&_NSConcreteMallocBlock == objc_getClass("OFMallocBlock")) TEST(@"Copying a stack block", (mallocBlock = [[stackBlock copy] autorelease]) && [mallocBlock class] == objc_getClass("OFMallocBlock") && [mallocBlock isKindOfClass: [OFBlock class]]) TEST(@"Copying a stack block and referencing its variable", forwardTest() == 5) TEST(@"Copying a stack block and using its copied variable", (voidBlock = returnStackBlock()) && voidBlock() == 43 && voidBlock() == 44 && voidBlock() == 45) TEST(@"Copying a global block", (id)globalBlock == [[globalBlock copy] autorelease]) #ifndef __clang_analyzer__ TEST(@"Copying a malloc block", (id)mallocBlock == [mallocBlock copy] && [mallocBlock retainCount] == 2) #endif TEST(@"Autorelease a stack block", R([stackBlock autorelease])) TEST(@"Autorelease a global block", R([globalBlock autorelease])) #ifndef __clang_analyzer__ TEST(@"Autorelease a malloc block", R([mallocBlock autorelease])) #endif objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFCharacterSetTests.m from [7038831ad1] to [11fed19a2c].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #import "TestsAppDelegate.h" #import "OFCharacterSet.h" #import "OFBitSetCharacterSet.h" #import "OFRangeCharacterSet.h" | | | | | | | | | | | | | > | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | #import "TestsAppDelegate.h" #import "OFCharacterSet.h" #import "OFBitSetCharacterSet.h" #import "OFRangeCharacterSet.h" static OFString *module; @interface SimpleCharacterSet: OFCharacterSet @end @implementation SimpleCharacterSet - (bool)characterIsMember: (OFUnichar)character { return (character % 2 == 0); } @end @implementation TestsAppDelegate (OFCharacterSetTests) - (void)characterSetTests { void *pool = objc_autoreleasePoolPush(); OFCharacterSet *characterSet, *invertedCharacterSet; bool ok; module = @"OFCharacterSet"; characterSet = [[[SimpleCharacterSet alloc] init] autorelease]; ok = true; for (OFUnichar c = 0; c < 65536; c++) { if (c % 2 == 0) { if (![characterSet characterIsMember: c]) ok = false; } else if ([characterSet characterIsMember: c]) ok = false; } TEST(@"-[characterIsMember:]", ok); module = @"OFBitSetCharacterSet"; TEST(@"+[characterSetWithCharactersInString:]", (characterSet = [OFCharacterSet characterSetWithCharactersInString: @"0123456789"]) && [characterSet isKindOfClass: [OFBitSetCharacterSet class]]) ok = true; for (OFUnichar c = 0; c < 65536; c++) { if (c >= '0' && c <= '9') { if (![characterSet characterIsMember: c]) ok = false; } else if ([characterSet characterIsMember: c]) ok = false; } TEST(@"-[characterIsMember:]", ok); module = @"OFRangeCharacterSet"; TEST(@"+[characterSetWithRange:]", (characterSet = [OFCharacterSet characterSetWithRange: OFRangeMake('0', 10)]) && [characterSet isKindOfClass: [OFRangeCharacterSet class]]) ok = true; for (OFUnichar c = 0; c < 65536; c++) { if (c >= '0' && c <= '9') { if (![characterSet characterIsMember: c]) ok = false; } else if ([characterSet characterIsMember: c]) ok = false; } TEST(@"-[characterIsMember:]", ok); ok = true; invertedCharacterSet = characterSet.invertedSet; for (OFUnichar c = 0; c < 65536; c++) { if (c >= '0' && c <= '9') { if ([invertedCharacterSet characterIsMember: c]) ok = false; } else if (![invertedCharacterSet characterIsMember: c]) ok = false; } TEST(@"-[invertedSet]", ok); TEST(@"Inverting -[invertedSet] returns original set", invertedCharacterSet.invertedSet == characterSet) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFDNSResolverTests.m from [0af53b3697] to [1d2ed3ff32].
︙ | ︙ | |||
20 21 22 23 24 25 26 | @implementation TestsAppDelegate (OFDNSResolverTests) - (void)DNSResolverTests { void *pool = objc_autoreleasePoolPush(); OFDNSResolver *resolver = [OFDNSResolver resolver]; OFMutableString *staticHosts = [OFMutableString string]; | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 | @implementation TestsAppDelegate (OFDNSResolverTests) - (void)DNSResolverTests { void *pool = objc_autoreleasePoolPush(); OFDNSResolver *resolver = [OFDNSResolver resolver]; OFMutableString *staticHosts = [OFMutableString string]; [OFStdOut setForegroundColor: [OFColor lime]]; for (OFString *host in resolver.staticHosts) { OFString *IPs; if (staticHosts.length > 0) [staticHosts appendString: @"; "]; IPs = [[resolver.staticHosts objectForKey: host] componentsJoinedByString: @", "]; [staticHosts appendFormat: @"%@=(%@)", host, IPs]; } [OFStdOut writeFormat: @"[OFDNSResolver] Static hosts: %@\n", staticHosts]; [OFStdOut writeFormat: @"[OFDNSResolver] Name servers: %@\n", [resolver.nameServers componentsJoinedByString: @", "]]; [OFStdOut writeFormat: @"[OFDNSResolver] Local domain: %@\n", resolver.localDomain]; [OFStdOut writeFormat: @"[OFDNSResolver] Search domains: %@\n", [resolver.searchDomains componentsJoinedByString: @", "]]; [OFStdOut writeFormat: @"[OFDNSResolver] Timeout: %lf\n", resolver.timeout]; [OFStdOut writeFormat: @"[OFDNSResolver] Max attempts: %u\n", resolver.maxAttempts]; [OFStdOut writeFormat: @"[OFDNSResolver] Min number of dots in absolute name: %u\n", resolver.minNumberOfDotsInAbsoluteName]; [OFStdOut writeFormat: @"[OFDNSResolver] Uses TCP: %u\n", resolver.usesTCP]; [OFStdOut writeFormat: @"[OFDNSResolver] Config reload interval: %lf\n", resolver.configReloadInterval]; objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFDataTests.m from [0d3eb2fad7] to [def38bc628].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | < | | | | | | | | | | | | | | | | | | | | | | | | < | < | | < | > | | | | < | | | > > | | > > | > > | | | | | > | > | | | | | < < < < | < | > | | | | | > | > > | | | | | | > | | | | | > | | | | | | < < | | | | < < | | < | > | > > > | | | > | > > | | > > | | > > | | > > | | > > > | | | | < | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFData"; @implementation TestsAppDelegate (OFDataTests) - (void)dataTests { void *pool = objc_autoreleasePoolPush(); OFMutableData *mutableData; OFData *data; void *raw[2]; OFRange range; TEST(@"+[dataWithItemSize:]", (mutableData = [OFMutableData dataWithItemSize: 4096])) raw[0] = OFAllocMemory(1, 4096); raw[1] = OFAllocMemory(1, 4096); memset(raw[0], 0xFF, 4096); memset(raw[1], 0x42, 4096); TEST(@"-[addItem:]", R([mutableData addItem: raw[0]]) && R([mutableData addItem: raw[1]])) TEST(@"-[itemAtIndex:]", memcmp([mutableData itemAtIndex: 0], raw[0], 4096) == 0 && memcmp([mutableData itemAtIndex: 1], raw[1], 4096) == 0) TEST(@"-[lastItem]", memcmp(mutableData.lastItem, raw[1], 4096) == 0) TEST(@"-[count]", mutableData.count == 2) TEST(@"-[isEqual:]", (data = [OFData dataWithItems: mutableData.items count: mutableData.count itemSize: mutableData.itemSize]) && [data isEqual: mutableData] && R([mutableData removeLastItem]) && ![mutableData isEqual: data]) TEST(@"-[mutableCopy]", (mutableData = [[data mutableCopy] autorelease]) && [mutableData isEqual: data]) TEST(@"-[compare]", [mutableData compare: data] == 0 && R([mutableData removeLastItem]) && [data compare: mutableData] == OFOrderedDescending && [mutableData compare: data] == OFOrderedAscending && [[OFData dataWithItems: "aa" count: 2] compare: [OFData dataWithItems: "z" count: 1]] == OFOrderedAscending) TEST(@"-[hash]", data.hash == 0x634A529F) mutableData = [OFMutableData dataWithItems: "abcdef" count: 6]; TEST(@"-[removeLastItem]", R([mutableData removeLastItem]) && mutableData.count == 5 && memcmp(mutableData.items, "abcde", 5) == 0) TEST(@"-[removeItemsInRange:]", R([mutableData removeItemsInRange: OFRangeMake(1, 2)]) && mutableData.count == 3 && memcmp(mutableData.items, "ade", 3) == 0) TEST(@"-[insertItems:atIndex:count:]", R([mutableData insertItems: "bc" atIndex: 1 count: 2]) && mutableData.count == 5 && memcmp(mutableData.items, "abcde", 5) == 0) data = [OFData dataWithItems: "aaabaccdacaabb" count: 7 itemSize: 2]; range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: 0 range: OFRangeMake(0, 7)]; TEST(@"-[rangeOfData:options:range:] #1", range.location == 0 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: OFDataSearchBackwards range: OFRangeMake(0, 7)]; TEST(@"-[rangeOfData:options:range:] #2", range.location == 5 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "ac" count: 1 itemSize: 2] options: 0 range: OFRangeMake(0, 7)]; TEST(@"-[rangeOfData:options:range:] #3", range.location == 2 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "aabb" count: 2 itemSize: 2] options: 0 range: OFRangeMake(0, 7)]; TEST(@"-[rangeOfData:options:range:] #4", range.location == 5 && range.length == 2) TEST(@"-[rangeOfData:options:range:] #5", R(range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: 0 range: OFRangeMake(1, 6)]) && range.location == 5 && range.length == 1) range = [data rangeOfData: [OFData dataWithItems: "aa" count: 1 itemSize: 2] options: OFDataSearchBackwards range: OFRangeMake(0, 5)]; TEST(@"-[rangeOfData:options:range:] #6", range.location == 0 && range.length == 1) EXPECT_EXCEPTION( @"-[rangeOfData:options:range:] failing on different itemSize", OFInvalidArgumentException, [data rangeOfData: [OFData dataWithItems: "aaa" count: 1 itemSize: 3] options: 0 range: OFRangeMake(0, 1)]) EXPECT_EXCEPTION( @"-[rangeOfData:options:range:] failing on out of range", OFOutOfRangeException, [data rangeOfData: [OFData dataWithItems: "" count: 0 itemSize: 2] options: 0 range: OFRangeMake(8, 1)]) TEST(@"-[subdataWithRange:]", [[data subdataWithRange: OFRangeMake(2, 4)] isEqual: [OFData dataWithItems: "accdacaa" count: 4 itemSize: 2]] && [[mutableData subdataWithRange: OFRangeMake(2, 3)] isEqual: [OFData dataWithItems: "cde" count: 3]]) EXPECT_EXCEPTION(@"-[subdataWithRange:] failing on out of range #1", OFOutOfRangeException, [data subdataWithRange: OFRangeMake(7, 1)]) EXPECT_EXCEPTION(@"-[subdataWithRange:] failing on out of range #2", OFOutOfRangeException, [mutableData subdataWithRange: OFRangeMake(6, 1)]) TEST(@"-[stringByMD5Hashing]", [mutableData.stringByMD5Hashing isEqual: @"ab56b4d92b40713acc5af89985d4b786"]) TEST(@"-[stringByRIPEMD160Hashing]", [mutableData.stringByRIPEMD160Hashing isEqual: @"973398b6e6c6cfa6b5e6a5173f195ce3274bf828"]) TEST(@"-[stringBySHA1Hashing]", [mutableData.stringBySHA1Hashing isEqual: @"03de6c570bfe24bfc328ccd7ca46b76eadaf4334"]) TEST(@"-[stringBySHA224Hashing]", [mutableData.stringBySHA224Hashing isEqual: @"bdd03d560993e675516ba5a50638b6531ac2ac3d5847c61916cfced6" ]) TEST(@"-[stringBySHA256Hashing]", [mutableData.stringBySHA256Hashing isEqual: @"36bbe50ed96841d10443bcb670d6554f0a34b761be67ec9c4a8ad2c0" @"c44ca42c"]) TEST(@"-[stringBySHA384Hashing]", [mutableData.stringBySHA384Hashing isEqual: @"4c525cbeac729eaf4b4665815bc5db0c84fe6300068a727cf74e2813" @"521565abc0ec57a37ee4d8be89d097c0d2ad52f0"]) TEST(@"-[stringBySHA512Hashing]", [mutableData.stringBySHA512Hashing isEqual: @"878ae65a92e86cac011a570d4c30a7eaec442b85ce8eca0c2952b5e3" @"cc0628c2e79d889ad4d5c7c626986d452dd86374b6ffaa7cd8b67665" @"bef2289a5c70b0a1"]) TEST(@"-[stringByBase64Encoding]", [mutableData.stringByBase64Encoding isEqual: @"YWJjZGU="]) TEST(@"+[dataWithBase64EncodedString:]", memcmp([[OFData dataWithBase64EncodedString: @"YWJjZGU="] items], "abcde", 5) == 0) TEST(@"Building strings", (mutableData = [OFMutableData dataWithItems: "Hello!" count: 6]) && R([mutableData addItem: ""]) && strcmp(mutableData.items, "Hello!") == 0) EXPECT_EXCEPTION(@"Detect out of range in -[itemAtIndex:]", OFOutOfRangeException, [mutableData itemAtIndex: mutableData.count]) EXPECT_EXCEPTION(@"Detect out of range in -[addItems:count:]", OFOutOfRangeException, [mutableData addItems: raw[0] count: SIZE_MAX]) EXPECT_EXCEPTION(@"Detect out of range in -[removeItemsInRange:]", OFOutOfRangeException, [mutableData removeItemsInRange: OFRangeMake(mutableData.count, 1)]) OFFreeMemory(raw[0]); OFFreeMemory(raw[1]); objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFDateTests.m from [02539a3684] to [7e834c33fc].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <time.h> #import "TestsAppDelegate.h" | | | | | | | | | | 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 | #include "config.h" #include <time.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFDate"; @implementation TestsAppDelegate (OFDateTests) - (void)dateTests { void *pool = objc_autoreleasePoolPush(); OFDate *date1, *date2; struct tm tm; int16_t tz; const char *dstr = "Wed, 09 Jun 2021 +0200x"; TEST(@"OFStrPTime()", OFStrPTime(dstr, "%a, %d %b %Y %z", &tm, &tz) == dstr + 22 && tm.tm_wday == 3 && tm.tm_mday == 9 && tm.tm_mon == 5 && tm.tm_year == 2021 - 1900 && tz == 2 * 60) TEST(@"+[dateWithTimeIntervalSince1970:]", (date1 = [OFDate dateWithTimeIntervalSince1970: 0])) TEST(@"-[dateByAddingTimeInterval:]", (date2 = [date1 dateByAddingTimeInterval: 3600 * 25 + 5.000002])) TEST(@"-[description]", [date1.description isEqual: @"1970-01-01T00:00:00Z"] && [date2.description isEqual: @"1970-01-02T01:00:05Z"]) TEST(@"+[dateWithDateString:format:]", [[[OFDate dateWithDateString: @"2000-06-20T12:34:56+0200" format: @"%Y-%m-%dT%H:%M:%S%z"] description] isEqual: @"2000-06-20T10:34:56Z"]); EXPECT_EXCEPTION(@"Detection of unparsed in " |
︙ | ︙ | |||
73 74 75 76 77 78 79 | EXPECT_EXCEPTION(@"Detection of unparsed in " @"+[dateWithLocalDateString:format:] #2", OFInvalidFormatException, [OFDate dateWithLocalDateString: @"2000-06-20T12:34:56+0200x" format: @"%Y-%m-%dT%H:%M:%S%z"]) TEST(@"-[isEqual:]", | | | | | | > | | | | > | | | | | | 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | EXPECT_EXCEPTION(@"Detection of unparsed in " @"+[dateWithLocalDateString:format:] #2", OFInvalidFormatException, [OFDate dateWithLocalDateString: @"2000-06-20T12:34:56+0200x" format: @"%Y-%m-%dT%H:%M:%S%z"]) TEST(@"-[isEqual:]", [date1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0]] && ![date1 isEqual: [OFDate dateWithTimeIntervalSince1970: 0.0000001]]) TEST(@"-[compare:]", [date1 compare: date2] == OFOrderedAscending) TEST(@"-[second]", date1.second == 0 && date2.second == 5) TEST(@"-[microsecond]", date1.microsecond == 0 && date2.microsecond == 2) TEST(@"-[minute]", date1.minute == 0 && date2.minute == 0) TEST(@"-[hour]", date1.hour == 0 && date2.hour == 1) TEST(@"-[dayOfMonth]", date1.dayOfMonth == 1 && date2.dayOfMonth == 2) TEST(@"-[monthOfYear]", date1.monthOfYear == 1 && date2.monthOfYear == 1) TEST(@"-[year]", date1.year == 1970 && date2.year == 1970) TEST(@"-[dayOfWeek]", date1.dayOfWeek == 4 && date2.dayOfWeek == 5) TEST(@"-[dayOfYear]", date1.dayOfYear == 1 && date2.dayOfYear == 2) TEST(@"-[earlierDate:]", [[date1 earlierDate: date2] isEqual: date1]) TEST(@"-[laterDate:]", [[date1 laterDate: date2] isEqual: date2]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFDictionaryTests.m from [403fe91187] to [545415a78a].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *module; static OFString *keys[] = { @"key1", @"key2" }; static OFString *values[] = { @"value1", @"value2" |
︙ | ︙ | |||
51 52 53 54 55 56 57 | [self release]; @throw e; } return self; } | | < | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | [self release]; @throw e; } return self; } - (instancetype)initWithKey: (id)key arguments: (va_list)arguments { self = [super init]; @try { _dictionary = [[OFMutableDictionary alloc] initWithKey: key arguments: arguments]; |
︙ | ︙ | |||
101 102 103 104 105 106 107 | - (id)objectForKey: (id)key { return [_dictionary objectForKey: key]; } - (size_t)count { | | | < | < | | | < | < | | | | | | < | | | | | | | | | | | | | < | | | | < | < | | | | | | < | | | | | | | | | | > | | | | | | | | | 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | - (id)objectForKey: (id)key { return [_dictionary objectForKey: key]; } - (size_t)count { return _dictionary.count; } - (OFEnumerator *)keyEnumerator { return [_dictionary keyEnumerator]; } @end @implementation SimpleMutableDictionary + (void)initialize { if (self == [SimpleMutableDictionary class]) [self inheritMethodsFromClass: [SimpleDictionary class]]; } - (void)setObject: (id)object forKey: (id)key { bool existed = ([_dictionary objectForKey: key] == nil); [_dictionary setObject: object forKey: key]; if (existed) _mutations++; } - (void)removeObjectForKey: (id)key { bool existed = ([_dictionary objectForKey: key] == nil); [_dictionary removeObjectForKey: key]; if (existed) _mutations++; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { int ret = [super countByEnumeratingWithState: state objects: objects count: count]; state->mutationsPtr = &_mutations; return ret; } @end @implementation TestsAppDelegate (OFDictionaryTests) - (void)dictionaryTestsWithClass: (Class)dictionaryClass mutableClass: (Class)mutableDictionaryClass { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *mutableDict = [mutableDictionaryClass dictionary]; OFDictionary *dict; OFEnumerator *keyEnumerator, *objectEnumerator; OFArray *keysArray, *valuesArray; [mutableDict setObject: values[0] forKey: keys[0]]; [mutableDict setValue: values[1] forKey: keys[1]]; TEST(@"-[objectForKey:]", [[mutableDict objectForKey: keys[0]] isEqual: values[0]] && [[mutableDict objectForKey: keys[1]] isEqual: values[1]] && [mutableDict objectForKey: @"key3"] == nil) TEST(@"-[valueForKey:]", [[mutableDict valueForKey: keys[0]] isEqual: values[0]] && [[mutableDict valueForKey: @"@count"] isEqual: [OFNumber numberWithInt: 2]]) EXPECT_EXCEPTION(@"Catching -[setValue:forKey:] on immutable " @"dictionary", OFUndefinedKeyException, [[dictionaryClass dictionary] setValue: @"x" forKey: @"x"]) TEST(@"-[containsObject:]", [mutableDict containsObject: values[0]] && ![mutableDict containsObject: @"nonexistent"]) TEST(@"-[containsObjectIdenticalTo:]", [mutableDict containsObjectIdenticalTo: values[0]] && ![mutableDict containsObjectIdenticalTo: [OFString stringWithString: values[0]]]) TEST(@"-[description]", [[mutableDict description] isEqual: @"{\n\tkey1 = value1;\n\tkey2 = value2;\n}"]) TEST(@"-[allKeys]", [[mutableDict allKeys] isEqual: [OFArray arrayWithObjects: keys[0], keys[1], nil]]) TEST(@"-[allObjects]", [[mutableDict allObjects] isEqual: [OFArray arrayWithObjects: values[0], values[1], nil]]) TEST(@"-[keyEnumerator]", (keyEnumerator = [mutableDict keyEnumerator])) TEST(@"-[objectEnumerator]", (objectEnumerator = [mutableDict objectEnumerator])) TEST(@"OFEnumerator's -[nextObject]", [[keyEnumerator nextObject] isEqual: keys[0]] && [[objectEnumerator nextObject] isEqual: values[0]] && [[keyEnumerator nextObject] isEqual: keys[1]] && [[objectEnumerator nextObject] isEqual: values[1]] && [keyEnumerator nextObject] == nil && [objectEnumerator nextObject] == nil) [mutableDict removeObjectForKey: keys[0]]; EXPECT_EXCEPTION(@"Detection of mutation during enumeration", OFEnumerationMutationException, [keyEnumerator nextObject]); [mutableDict setObject: values[0] forKey: keys[0]]; size_t i = 0; bool ok = true; for (OFString *key in mutableDict) { if (i > 1 || ![key isEqual: keys[i]]) { ok = false; break; } [mutableDict setObject: [mutableDict objectForKey: key] forKey: key]; i++; } TEST(@"Fast Enumeration", ok) ok = false; @try { for (OFString *key in mutableDict) { (void)key; [mutableDict setObject: @"" forKey: @""]; } } @catch (OFEnumerationMutationException *e) { ok = true; } TEST(@"Detection of mutation during Fast Enumeration", ok) [mutableDict removeObjectForKey: @""]; TEST(@"-[stringByURLEncoding]", [[[OFDictionary dictionaryWithKeysAndObjects: @"foo", @"bar", @"q&x", @"q=x", nil] stringByURLEncoding] isEqual: @"q%26x=q%3Dx&foo=bar"]) #ifdef OF_HAVE_BLOCKS { __block size_t j = 0; __block bool blockOk = true; [mutableDict enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { if (j > 1 || ![key isEqual: keys[j]]) { blockOk = false; *stop = true; return; } [mutableDict setObject: [mutableDict objectForKey: key] forKey: key]; j++; }]; TEST(@"Enumeration using blocks", blockOk) blockOk = false; @try { [mutableDict enumerateKeysAndObjectsUsingBlock: ^ (id key, id object, bool *stop) { [mutableDict setObject: @"" forKey: @""]; }]; } @catch (OFEnumerationMutationException *e) { blockOk = true; } TEST(@"Detection of mutation during enumeration using blocks", blockOk) [mutableDict removeObjectForKey: @""]; } TEST(@"-[replaceObjectsUsingBlock:]", R([mutableDict replaceObjectsUsingBlock: ^ id (id key, id object) { if ([key isEqual: keys[0]]) return @"value_1"; if ([key isEqual: keys[1]]) return @"value_2"; return nil; }]) && [[mutableDict objectForKey: keys[0]] isEqual: @"value_1"] && [[mutableDict objectForKey: keys[1]] isEqual: @"value_2"]) TEST(@"-[mappedDictionaryUsingBlock:]", [[[mutableDict mappedDictionaryUsingBlock: ^ id (id key, id object) { if ([key isEqual: keys[0]]) return @"val1"; if ([key isEqual: keys[1]]) return @"val2"; return nil; }] description] isEqual: @"{\n\tkey1 = val1;\n\tkey2 = val2;\n}"]) TEST(@"-[filteredDictionaryUsingBlock:]", [[[mutableDict filteredDictionaryUsingBlock: ^ bool (id key, id object) { return [key isEqual: keys[0]]; }] description] isEqual: @"{\n\tkey1 = value_1;\n}"]) #endif TEST(@"-[count]", mutableDict.count == 2) TEST(@"+[dictionaryWithKeysAndObjects:]", (dict = [dictionaryClass dictionaryWithKeysAndObjects: @"foo", @"bar", @"baz", @"qux", nil]) && [[dict objectForKey: @"foo"] isEqual: @"bar"] && [[dict objectForKey: @"baz"] isEqual: @"qux"]) |
︙ | ︙ | |||
353 354 355 356 357 358 359 | TEST(@"-[copy]", (dict = [[dict copy] autorelease]) && [[dict objectForKey: keys[0]] isEqual: values[0]] && [[dict objectForKey: keys[1]] isEqual: values[1]]) TEST(@"-[mutableCopy]", | | | | | | < | | | < | | | | < | | | | < | | 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | TEST(@"-[copy]", (dict = [[dict copy] autorelease]) && [[dict objectForKey: keys[0]] isEqual: values[0]] && [[dict objectForKey: keys[1]] isEqual: values[1]]) TEST(@"-[mutableCopy]", (mutableDict = [[dict mutableCopy] autorelease]) && mutableDict.count == dict.count && [[mutableDict objectForKey: keys[0]] isEqual: values[0]] && [[mutableDict objectForKey: keys[1]] isEqual: values[1]] && R([mutableDict setObject: @"value3" forKey: @"key3"]) && [[mutableDict objectForKey: @"key3"] isEqual: @"value3"] && [[mutableDict objectForKey: keys[0]] isEqual: values[0]] && R([mutableDict setObject: @"foo" forKey: keys[0]]) && [[mutableDict objectForKey: keys[0]] isEqual: @"foo"]) TEST(@"-[removeObjectForKey:]", R([mutableDict removeObjectForKey: keys[0]]) && [mutableDict objectForKey: keys[0]] == nil) [mutableDict setObject: @"foo" forKey: keys[0]]; TEST(@"-[isEqual:]", ![mutableDict isEqual: dict] && R([mutableDict removeObjectForKey: @"key3"]) && ![mutableDict isEqual: dict] && R([mutableDict setObject: values[0] forKey: keys[0]]) && [mutableDict isEqual: dict]) objc_autoreleasePoolPop(pool); } - (void)dictionaryTests { module = @"OFDictionary"; |
︙ | ︙ |
Modified tests/OFHMACTests.m from [25a2a29ceb] to [f54d111cd0].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | | | | | | < | | | | | | | | | | | | | | | | | < | < | < | < | < | < | | | < | < | < | < | < | < | < | | | | | | < | < | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFHMAC"; static const uint8_t key[] = "yM9h8K6IWnJRvxC/0F8XRWG7RnACDBz8wqK2tbXrYVLoKC3vPLeJikyJSM47tVHc" "DlXHww9zULAC2sJUlm2Kg1z4oz2aXY3Y1PQSB4VkC/m0DQ7hCI6cAg4TWnKdzWTy" "cvYGX+Y6HWeDY79/PGSd8fNItme6I8w4HDBqU7BP2sum3jbePJqoiSnhcyJZQTeZ" "jw0ZXoyrfHgOYD2M+NsTDaGpLblFtQ7n5CczjKtafG40PkEwx1dcrd46U9i3GyTK"; static const size_t keyLength = sizeof(key); static const uint8_t MD5Digest[] = "\xCC\x1F\xEF\x09\x29\xA3\x25\x1A\x06\xA9\x83\x99\xF9\xBC\x8F\x42"; static const uint8_t SHA1Digest[] = "\x94\xB9\x0A\x6F\xFB\xA7\x13\x6A\x75\x55" "\xD5\x7F\x5D\xB7\xF4\xCA\xEB\x4A\xDE\xBF"; static const uint8_t RIPEMD160Digest[] = "\x2C\xE1\xED\x41\xC6\xF3\x51\xA8\x04\xD2" "\xC3\x9B\x08\x33\x3B\xD5\xC9\x00\x39\x50"; static const uint8_t SHA256Digest[] = "\xFB\x8C\xDA\x88\xB3\x81\x32\x16\xD7\xD8\x62\xD4\xA6\x26\x9D\x77" "\x01\x99\x62\x65\x29\x02\x41\xE6\xEF\xA1\x02\x31\xA8\x9D\x77\x5D"; static const uint8_t SHA384Digest[] = "\x2F\x4A\x47\xAE\x13\x8E\x96\x52\xF1\x8F\x05\xFD\x65\xCD\x9A\x97" "\x93\x2F\xC9\x02\xD6\xC6\xAB\x2E\x15\x76\xC0\xA7\xA0\x05\xF4\xEF" "\x14\x52\x33\x4B\x9C\x5F\xD8\x07\x4E\x98\xAE\x97\x46\x29\x24\xB4"; static const uint8_t SHA512Digest[] = "\xF5\x8C\x3F\x9C\xA2\x2F\x0A\xF3\x26\xD8\xC0\x7E\x20\x63\x88\x61" "\xC9\xE1\x1F\xD7\xC7\xE5\x59\x33\xD5\x2F\xAF\x56\x1C\x94\xC8\xA4" "\x61\xB3\xF9\x1A\xE3\x09\x43\xA6\x5B\x85\xB1\x50\x5B\xCB\x1A\x2E" "\xB7\xE8\x87\xC1\x73\x19\x63\xF6\xA2\x91\x8D\x7E\x2E\xCC\xEC\x99"; @implementation TestsAppDelegate (OFHMACTests) - (void)HMACTests { void *pool = objc_autoreleasePoolPush(); OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; OFHMAC *HMACMD5, *HMACSHA1, *HMACRMD160; OFHMAC *HMACSHA256, *HMACSHA384, *HMACSHA512; TEST(@"+[HMACWithHashClass:] with MD5", (HMACMD5 = [OFHMAC HMACWithHashClass: [OFMD5Hash class] allowsSwappableMemory: true])) TEST(@"+[HMACWithHashClass:] with SHA-1", (HMACSHA1 = [OFHMAC HMACWithHashClass: [OFSHA1Hash class] allowsSwappableMemory: true])) TEST(@"+[HMACWithHashClass:] with RIPEMD-160", (HMACRMD160 = [OFHMAC HMACWithHashClass: [OFRIPEMD160Hash class] allowsSwappableMemory: true])) TEST(@"+[HMACWithHashClass:] with SHA-256", (HMACSHA256 = [OFHMAC HMACWithHashClass: [OFSHA256Hash class] allowsSwappableMemory: true])) TEST(@"+[HMACWithHashClass:] with SHA-384", (HMACSHA384 = [OFHMAC HMACWithHashClass: [OFSHA384Hash class] allowsSwappableMemory: true])) TEST(@"+[HMACWithHashClass:] with SHA-512", (HMACSHA512 = [OFHMAC HMACWithHashClass: [OFSHA512Hash class] allowsSwappableMemory: true])) EXPECT_EXCEPTION(@"Detection of missing key", OFInvalidArgumentException, [HMACMD5 updateWithBuffer: "" length: 0]) TEST(@"-[setKey:length:] with MD5", R([HMACMD5 setKey: key length: keyLength])) TEST(@"-[setKey:length:] with SHA-1", R([HMACSHA1 setKey: key length: keyLength])) TEST(@"-[setKey:length:] with RIPEMD-160", R([HMACRMD160 setKey: key length: keyLength])) TEST(@"-[setKey:length:] with SHA-256", R([HMACSHA256 setKey: key length: keyLength])) TEST(@"-[setKey:length:] with SHA-384", R([HMACSHA384 setKey: key length: keyLength])) TEST(@"-[setKey:length:] with SHA-512", R([HMACSHA512 setKey: key length: keyLength])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [HMACMD5 updateWithBuffer: buffer length: length]; [HMACSHA1 updateWithBuffer: buffer length: length]; [HMACRMD160 updateWithBuffer: buffer length: length]; [HMACSHA256 updateWithBuffer: buffer length: length]; [HMACSHA384 updateWithBuffer: buffer length: length]; [HMACSHA512 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[digest] with MD5", memcmp(HMACMD5.digest, MD5Digest, HMACMD5.digestSize) == 0) TEST(@"-[digest] with SHA-1", memcmp(HMACSHA1.digest, SHA1Digest, HMACSHA1.digestSize) == 0) TEST(@"-[digest] with RIPEMD-160", memcmp(HMACRMD160.digest, RIPEMD160Digest, HMACRMD160.digestSize) == 0) TEST(@"-[digest] with SHA-256", memcmp(HMACSHA256.digest, SHA256Digest, HMACSHA256.digestSize) == 0) TEST(@"-[digest] with SHA-384", memcmp(HMACSHA384.digest, SHA384Digest, HMACSHA384.digestSize) == 0) TEST(@"-[digest] with SHA-512", memcmp(HMACSHA512.digest, SHA512Digest, HMACSHA512.digestSize) == 0) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFHTTPClientTests.m from [18ee20c625] to [1197c752e1].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #include <inttypes.h> #include <string.h> #import "TestsAppDelegate.h" | | | | | < | | | < < | < < | < < | | < | | < | < | < | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include "config.h" #include <inttypes.h> #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFHTTPClient"; static OFCondition *condition; static OFHTTPResponse *response = nil; @interface TestsAppDelegate (HTTPClientTests) <OFHTTPClientDelegate> @end @interface HTTPClientTestsServer: OFThread { @public uint16_t _port; } @end @implementation HTTPClientTestsServer - (id)main { OFTCPSocket *listener, *client; char buffer[5]; [condition lock]; listener = [OFTCPSocket socket]; _port = [listener bindToHost: @"127.0.0.1" port: 0]; [listener listen]; [condition signal]; [condition unlock]; client = [listener accept]; OFEnsure([[client readLine] isEqual: @"GET /foo HTTP/1.1"]); OFEnsure([[client readLine] hasPrefix: @"User-Agent:"]); OFEnsure([[client readLine] isEqual: @"Content-Length: 5"]); OFEnsure([[client readLine] isEqual: @"Content-Type: application/x-www-form-urlencoded; charset=UTF-8"]); if (![[client readLine] isEqual: [OFString stringWithFormat: @"Host: 127.0.0.1:%" @PRIu16, _port]]) OFEnsure(0); OFEnsure([[client readLine] isEqual: @""]); [client readIntoBuffer: buffer exactLength: 5]; OFEnsure(memcmp(buffer, "Hello", 5) == 0); [client writeString: @"HTTP/1.0 200 OK\r\n" @"cONTeNT-lENgTH: 7\r\n" @"\r\n" @"foo\n" @"bar"]; [client close]; |
︙ | ︙ | |||
97 98 99 100 101 102 103 | } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response_ exception: (id)exception { | | | | | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response_ exception: (id)exception { OFEnsure(exception == nil); response = [response_ retain]; [[OFRunLoop mainRunLoop] stop]; } - (void)HTTPClientTests { void *pool = objc_autoreleasePoolPush(); HTTPClientTestsServer *server; OFURL *URL; OFHTTPClient *client; OFHTTPRequest *request; OFData *data; condition = [OFCondition condition]; [condition lock]; server = [[[HTTPClientTestsServer alloc] init] autorelease]; server.supportsSockets = true; [server start]; [condition wait]; [condition unlock]; URL = [OFURL URLWithString: [OFString stringWithFormat: @"http://127.0.0.1:%" @PRIu16 "/foo", server->_port]]; TEST(@"-[asyncPerformRequest:]", (client = [OFHTTPClient client]) && (client.delegate = self) && |
︙ | ︙ |
Modified tests/OFHTTPCookieManagerTests.m from [c178740871] to [d8c3ff9fea].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFHTTPCookieManager"; @implementation TestsAppDelegate (OFHTTPCookieManagerTests) - (void)HTTPCookieManagerTests { void *pool = objc_autoreleasePoolPush(); OFHTTPCookieManager *manager = [OFHTTPCookieManager manager]; OFURL *URL1, *URL2, *URL3, *URL4; OFHTTPCookie *cookie1, *cookie2, *cookie3, *cookie4, *cookie5; URL1 = [OFURL URLWithString: @"http://nil.im/foo"]; URL2 = [OFURL URLWithString: @"https://nil.im/foo/bar"]; URL3 = [OFURL URLWithString: @"https://test.nil.im/foo/bar"]; URL4 = [OFURL URLWithString: @"http://webkeks.org/foo/bar"]; cookie1 = [OFHTTPCookie cookieWithName: @"test" value: @"1" domain: @"nil.im"]; TEST(@"-[addCookie:forURL:] #1", R([manager addCookie: cookie1 forURL: URL1])) TEST(@"-[cookiesForURL:] #1", [[manager cookiesForURL: URL1] isEqual: [OFArray arrayWithObject: cookie1]]) cookie2 = [OFHTTPCookie cookieWithName: @"test" value: @"2" domain: @"webkeks.org"]; TEST(@"-[addCookie:forURL:] #2", R([manager addCookie: cookie2 forURL: URL1])) TEST(@"-[cookiesForURL:] #2", [[manager cookiesForURL: URL1] isEqual: [OFArray arrayWithObject: cookie1]] && [[manager cookiesForURL: URL4] isEqual: [OFArray array]]) cookie3 = [OFHTTPCookie cookieWithName: @"test" value: @"3" domain: @"nil.im"]; cookie3.secure = true; TEST(@"-[addCookie:forURL:] #3", R([manager addCookie: cookie3 forURL: URL2])) TEST(@"-[cookiesForURL:] #3", [[manager cookiesForURL: URL2] isEqual: [OFArray arrayWithObject: cookie3]] && [[manager cookiesForURL: URL1] isEqual: [OFArray array]]) cookie3.expires = [OFDate dateWithTimeIntervalSinceNow: -1]; cookie4 = [OFHTTPCookie cookieWithName: @"test" value: @"4" domain: @"nil.im"]; cookie4.domain = @".nil.im"; TEST(@"-[addCookie:forURL:] #4", R([manager addCookie: cookie4 forURL: URL2])) TEST(@"-[cookiesForURL:] #4", [[manager cookiesForURL: URL2] isEqual: [OFArray arrayWithObject: cookie4]] && [[manager cookiesForURL: URL3] isEqual: [OFArray arrayWithObject: cookie4]]) cookie5 = [OFHTTPCookie cookieWithName: @"bar" value: @"5" domain: @"test.nil.im"]; TEST(@"-[addCookie:forURL:] #5", R([manager addCookie: cookie5 forURL: URL1])) TEST(@"-[cookiesForURL:] #5", [[manager cookiesForURL: URL1] isEqual: [OFArray arrayWithObject: cookie4]] && [[manager cookiesForURL: URL3] isEqual: [OFArray arrayWithObjects: cookie4, cookie5, nil]]) TEST(@"-[purgeExpiredCookies]", [manager.cookies isEqual: [OFArray arrayWithObjects: cookie3, cookie4, cookie5, nil]] && R([manager purgeExpiredCookies]) && [manager.cookies isEqual: [OFArray arrayWithObjects: cookie4, cookie5, nil]]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFHTTPCookieTests.m from [ea70ec9f7e] to [3f137e64cb].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFHTTPCookie"; @implementation TestsAppDelegate (OFHTTPCookieTests) - (void)HTTPCookieTests { void *pool = objc_autoreleasePoolPush(); OFURL *URL = [OFURL URLWithString: @"http://nil.im"]; OFHTTPCookie *cookie1, *cookie2; OFArray OF_GENERIC(OFHTTPCookie *) *cookies; cookie1 = [OFHTTPCookie cookieWithName: @"foo" value: @"bar" domain: @"nil.im"]; TEST(@"+[cookiesWithResponseHeaderFields:forURL:] #1", [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary dictionaryWithObject: @"foo=bar" forKey: @"Set-Cookie"] forURL: URL] isEqual: [OFArray arrayWithObject: cookie1]]) cookie2 = [OFHTTPCookie cookieWithName: @"qux" value: @"cookie" domain: @"nil.im"]; TEST(@"+[cookiesWithResponseHeaderFields:forURL:] #2", [[OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary dictionaryWithObject: @"foo=bar,qux=cookie" forKey: @"Set-Cookie"] forURL: URL] isEqual: [OFArray arrayWithObjects: cookie1, cookie2, nil]]) cookie1.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890]; cookie2.expires = [OFDate dateWithTimeIntervalSince1970: 1234567890]; cookie1.path = @"/x"; cookie2.domain = @"webkeks.org"; cookie2.path = @"/objfw"; cookie2.secure = true; cookie2.HTTPOnly = true; [cookie2.extensions addObject: @"foo"]; [cookie2.extensions addObject: @"bar"]; TEST(@"+[cookiesWithResponseHeaderFields:forURL:] #3", [(cookies = [OFHTTPCookie cookiesWithResponseHeaderFields: [OFDictionary dictionaryWithObject: @"foo=bar; Expires=Fri, 13 Feb 2009 23:31:30 GMT; Path=/x," @"qux=cookie; Expires=Fri, 13 Feb 2009 23:31:30 GMT; " @"Domain=webkeks.org; Path=/objfw; Secure; HTTPOnly; foo; bar" forKey: @"Set-Cookie"] forURL: URL]) isEqual: [OFArray arrayWithObjects: cookie1, cookie2, nil]]) TEST(@"+[requestHeaderFieldsWithCookies:]", [[OFHTTPCookie requestHeaderFieldsWithCookies: cookies] isEqual: [OFDictionary dictionaryWithObject: @"foo=bar; qux=cookie" forKey: @"Cookie"]]) objc_autoreleasePoolPop(pool); |
︙ | ︙ |
Modified tests/OFINIFileTests.m from [cacad5286a] to [c77a7c32e4].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *module; @implementation TestsAppDelegate (OFINIFileTests) - (void)INIFileTests { void *pool = objc_autoreleasePoolPush(); OFString *output = @"[tests]\r\n" @"foo=baz\r\n" |
︙ | ︙ | |||
45 46 47 48 49 50 51 52 53 54 | @"double=0.75\r\n"; OFINIFile *file; OFINICategory *tests, *foobar, *types; OFArray *array; #ifndef OF_NINTENDO_DS OFString *writePath; #endif TEST(@"+[fileWithPath:encoding:]", (file = [OFINIFile fileWithPath: @"testfile.ini" | > > | | < | < | < | < | | | | < | < | < | | | < | | | | | | | | | | | 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | @"double=0.75\r\n"; OFINIFile *file; OFINICategory *tests, *foobar, *types; OFArray *array; #ifndef OF_NINTENDO_DS OFString *writePath; #endif module = @"OFINIFile"; TEST(@"+[fileWithPath:encoding:]", (file = [OFINIFile fileWithPath: @"testfile.ini" encoding: OFStringEncodingCodepage437])) tests = [file categoryForName: @"tests"]; foobar = [file categoryForName: @"foobar"]; types = [file categoryForName: @"types"]; TEST(@"-[categoryForName:]", tests != nil && foobar != nil && types != nil) module = @"OFINICategory"; TEST(@"-[stringForKey:]", [[tests stringForKey: @"foo"] isEqual: @"bar"] && [[foobar stringForKey: @"quxquxqux"] isEqual: @"hello\"wörld"]) TEST(@"-[setString:forKey:]", R([tests setString: @"baz" forKey: @"foo"]) && R([tests setString: @"new" forKey: @"new"]) && R([foobar setString: @"a\fb" forKey: @"qux3"])) TEST(@"-[longLongForKey:defaultValue:]", [types longLongForKey: @"integer" defaultValue: 2] == 0x20) TEST(@"-[setLongLong:forKey:]", R([types setLongLong: 0x10 forKey: @"integer"])) TEST(@"-[boolForKey:defaultValue:]", [types boolForKey: @"bool" defaultValue: false] == true) TEST(@"-[setBool:forKey:]", R([types setBool: false forKey: @"bool"])) TEST(@"-[floatForKey:defaultValue:]", [types floatForKey: @"float" defaultValue: 1] == 0.5f) TEST(@"-[setFloat:forKey:]", R([types setFloat: 0.25f forKey: @"float"])) TEST(@"-[doubleForKey:defaultValue:]", [types doubleForKey: @"double" defaultValue: 3] == 0.25) TEST(@"-[setDouble:forKey:]", R([types setDouble: 0.75 forKey: @"double"])) array = [OFArray arrayWithObjects: @"1", @"2", nil]; TEST(@"-[stringArrayForKey:]", [[types stringArrayForKey: @"array1"] isEqual: array] && [[types stringArrayForKey: @"array2"] isEqual: array] && [[types stringArrayForKey: @"array3"] isEqual: [OFArray array]]) array = [OFArray arrayWithObjects: @"foo", @"bar", nil]; TEST(@"-[setStringArray:forKey:]", R([types setStringArray: array forKey: @"array1"])) TEST(@"-[removeValueForKey:]", R([foobar removeValueForKey: @"quxqux "]) && R([types removeValueForKey: @"array2"])) module = @"OFINIFile"; /* FIXME: Find a way to write files on Nintendo DS */ #ifndef OF_NINTENDO_DS # ifndef OF_IOS writePath = @"tmpfile.ini"; # else writePath = [OFString pathWithComponents: [OFArray arrayWithObjects: [[OFApplication environment] objectForKey: @"HOME"], @"tmp", @"tmpfile.ini", nil]]; # endif TEST(@"-[writeToFile:encoding:]", R([file writeToFile: writePath encoding: OFStringEncodingCodepage437]) && [[OFString stringWithContentsOfFile: writePath encoding: OFStringEncodingCodepage437] isEqual: output]) [[OFFileManager defaultManager] removeItemAtPath: writePath]; #else (void)output; #endif objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFIPXSocketTests.m from [9fbe112566] to [a26f3af451].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <errno.h> #import "TestsAppDelegate.h" | | | | < | | | | | | | < < | < < | | < | 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 61 62 63 64 65 66 67 68 69 70 | #include "config.h" #include <errno.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFIPXSocket"; @implementation TestsAppDelegate (OFIPXSocketTests) - (void)IPXSocketTests { void *pool = objc_autoreleasePoolPush(); OFIPXSocket *sock; OFSocketAddress address1, address2; char buffer[5]; TEST(@"+[socket]", (sock = [OFIPXSocket socket])) @try { TEST(@"-[bindToPort:packetType:]", R(address1 = [sock bindToPort: 0 packetType: 0])) } @catch (OFBindFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFIPXSocket] -[bindToPort:packetType:]: " @"IPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFIPXSocket] -[bindToPort:packetType:]: " @"IPX not configured, skipping tests"]; break; default: @throw e; } objc_autoreleasePoolPop(pool); return; } TEST(@"-[sendBuffer:length:receiver:]", R([sock sendBuffer: "Hello" length: 5 receiver: &address1])) TEST(@"-[receiveIntoBuffer:length:sender:]", [sock receiveIntoBuffer: buffer length: 5 sender: &address2] == 5 && memcmp(buffer, "Hello", 5) == 0 && OFSocketAddressEqual(&address1, &address2) && OFSocketAddressHash(&address1) == OFSocketAddressHash(&address2)) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFInvocationTests.m from [78de2aee0d] to [a2e3d6960f].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__) # include <complex.h> #endif #import "TestsAppDelegate.h" | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | 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 | #if defined(HAVE_COMPLEX_H) && !defined(__STDC_NO_COMPLEX__) # include <complex.h> #endif #import "TestsAppDelegate.h" static OFString *const module = @"OFInvocation"; struct TestStruct { unsigned char c; unsigned int i; }; @implementation TestsAppDelegate (OFInvocationTests) - (struct TestStruct)invocationTestMethod1: (unsigned char)c : (unsigned int)i : (struct TestStruct *)ptr : (struct TestStruct)st { return st; } - (void)invocationTests { void *pool = objc_autoreleasePoolPush(); SEL selector = @selector(invocationTestMethod1::::); OFMethodSignature *sig = [self methodSignatureForSelector: selector]; OFInvocation *invocation; struct TestStruct st, st2, *stp = &st, *stp2; unsigned const char c = 0xAA; unsigned char c2; const unsigned int i = 0x55555555; unsigned int i2; memset(&st, '\xFF', sizeof(st)); st.c = 0x55; |
︙ | ︙ | |||
279 280 281 282 283 284 285 | TEST(@"-[setReturnValue]", R([invocation setReturnValue: &st])) TEST(@"-[getReturnValue]", R([invocation getReturnValue: &st2]) && memcmp(&st, &st2, sizeof(st)) == 0) memset(&st2, '\0', sizeof(st2)); | | < < | < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < | < < < < < < < < | < < | < | < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | < < < < | < < < < < < < < < < < < < < < | < < | < < < < < < < < < < | < < < < < < < < | < < < < | < < < < < < < < < | | < | < < < < < < < < < < < < < < < < < < < < | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | TEST(@"-[setReturnValue]", R([invocation setReturnValue: &st])) TEST(@"-[getReturnValue]", R([invocation getReturnValue: &st2]) && memcmp(&st, &st2, sizeof(st)) == 0) memset(&st2, '\0', sizeof(st2)); TEST(@"-[setArgument:atIndex:] #1", R([invocation setArgument: &c atIndex: 2])) TEST(@"-[setArgument:atIndex:] #2", R([invocation setArgument: &i atIndex: 3])) TEST(@"-[setArgument:atIndex:] #3", R([invocation setArgument: &stp atIndex: 4])) TEST(@"-[setArgument:atIndex:] #4", R([invocation setArgument: &st atIndex: 5])) TEST(@"-[getArgument:atIndex:] #1", R([invocation getArgument: &c2 atIndex: 2]) && c == c2) TEST(@"-[getArgument:atIndex:] #2", R([invocation getArgument: &i2 atIndex: 3]) && i == i2) TEST(@"-[getArgument:atIndex:] #3", R([invocation getArgument: &stp2 atIndex: 4]) && stp == stp2) TEST(@"-[getArgument:atIndex:] #4", R([invocation getArgument: &st2 atIndex: 5]) && memcmp(&st, &st2, sizeof(st)) == 0) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFJSONTests.m from [1509791c9a] to [4a647fbb7e].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | > | > | | > | | | | > | | 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 61 62 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFJSON"; @implementation TestsAppDelegate (JSONTests) - (void)JSONTests { void *pool = objc_autoreleasePoolPush(); OFString *string = @"{\"foo\"\t:'b\\na\\r', \"x\":/*foo*/ [.5\r,0xF," @"null//bar\n,\"foo\",false]}"; OFDictionary *dict = [OFDictionary dictionaryWithKeysAndObjects: @"foo", @"b\na\r", @"x", [OFArray arrayWithObjects: [OFNumber numberWithFloat: .5f], [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: false], nil], nil]; TEST(@"-[objectByParsingJSON] #1", [string.objectByParsingJSON isEqual: dict]) TEST(@"-[JSONRepresentation]", [[dict JSONRepresentation] isEqual: @"{\"x\":[0.5,15,null,\"foo\",false],\"foo\":\"b\\na\\r\"}"]) TEST(@"OFJSONRepresentationOptionPretty", [[dict JSONRepresentationWithOptions: OFJSONRepresentationOptionPretty] isEqual: @"{\n\t\"x\": [\n\t\t0.5,\n\t\t15,\n\t\tnull,\n\t\t" @"\"foo\",\n\t\tfalse\n\t],\n\t\"foo\": \"b\\na\\r\"\n}"]) TEST(@"OFJSONRepresentationOptionJSON5", [[dict JSONRepresentationWithOptions: OFJSONRepresentationOptionJSON5] isEqual: @"{x:[0.5,15,null,\"foo\",false],foo:\"b\\\na\\r\"}"]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #2", OFInvalidJSONException, [@"{" objectByParsingJSON]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #3", OFInvalidJSONException, [@"]" objectByParsingJSON]) EXPECT_EXCEPTION(@"-[objectByParsingJSON] #4", OFInvalidJSONException, [@"bar" objectByParsingJSON]) |
︙ | ︙ |
Modified tests/OFKernelEventObserverTests.m from [24325e2282] to [f4ab45b387].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif #import "TestsAppDelegate.h" | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #endif #ifdef HAVE_SELECT # import "OFSelectKernelEventObserver.h" #endif #import "TestsAppDelegate.h" static const size_t numExpectedEvents = 3; static OFString *module; @interface ObserverTest: OFObject <OFKernelEventObserverDelegate> { @public TestsAppDelegate *_testsAppDelegate; |
︙ | ︙ | |||
54 55 56 57 58 59 60 | @try { uint16_t port; _testsAppDelegate = testsAppDelegate; _server = [[OFTCPSocket alloc] init]; | | < | < < | < | 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | @try { uint16_t port; _testsAppDelegate = testsAppDelegate; _server = [[OFTCPSocket alloc] init]; port = [_server bindToHost: @"127.0.0.1" port: 0]; [_server listen]; _client = [[OFTCPSocket alloc] init]; [_client connectToHost: @"127.0.0.1" port: port]; [_client writeBuffer: "0" length: 1]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
90 91 92 93 94 95 96 | OFDate *deadline; bool deadlineExceeded = false; [_testsAppDelegate outputTesting: @"-[observe] with listening socket" inModule: module]; deadline = [OFDate dateWithTimeIntervalSinceNow: 1]; | | | | | 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | OFDate *deadline; bool deadlineExceeded = false; [_testsAppDelegate outputTesting: @"-[observe] with listening socket" inModule: module]; deadline = [OFDate dateWithTimeIntervalSinceNow: 1]; while (_events < numExpectedEvents) { if (deadline.timeIntervalSinceNow < 0) { deadlineExceeded = true; break; } [_observer observeForTimeInterval: 0.01]; } if (!deadlineExceeded) [_testsAppDelegate outputSuccess: @"-[observe] not exceeding deadline" inModule: module]; else { [_testsAppDelegate outputFailure: @"-[observe] not exceeding deadline" inModule: module]; _fails++; } if (_events == numExpectedEvents) [_testsAppDelegate outputSuccess: @"-[observe] handling all events" inModule: module]; else { [_testsAppDelegate outputFailure: @"-[observe] handling all events" inModule: module]; _fails++; } } - (void)objectIsReadyForReading: (id)object { char buffer; switch (_events++) { case 0: if (object == _server) [_testsAppDelegate outputSuccess: @"-[observe] with listening socket" inModule: module]; |
︙ | ︙ | |||
149 150 151 152 153 154 155 | [_testsAppDelegate outputTesting: @"-[observe] with data ready to read" inModule: module]; break; case 1: if (object == _accepted && | | | | < | | 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | [_testsAppDelegate outputTesting: @"-[observe] with data ready to read" inModule: module]; break; case 1: if (object == _accepted && [object readIntoBuffer: &buffer length: 1] == 1 && buffer == '0') [_testsAppDelegate outputSuccess: @"-[observe] with data ready to read" inModule: module]; else { [_testsAppDelegate outputFailure: @"-[observe] with data ready to read" inModule: module]; _fails++; } [_client close]; [_testsAppDelegate outputTesting: @"-[observe] with closed connection" inModule: module]; break; case 2: if (object == _accepted && [object readIntoBuffer: &buffer length: 1] == 0) [_testsAppDelegate outputSuccess: @"-[observe] with closed connection" inModule: module]; else { [_testsAppDelegate outputFailure: @"-[observe] with closed connection" inModule: module]; _fails++; } break; default: OFEnsure(0); } } @end @implementation TestsAppDelegate (OFKernelEventObserverTests) - (void)kernelEventObserverTestsWithClass: (Class)class { |
︙ | ︙ |
Modified tests/OFListTests.m from [6f825fa0b7] to [890c1e2652].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | > | | | | > | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFList"; static OFString *strings[] = { @"Foo", @"Bar", @"Baz" }; @implementation TestsAppDelegate (OFListTests) - (void)listTests { void *pool = objc_autoreleasePoolPush(); OFList *list; OFEnumerator *enumerator; OFListItem iter; OFString *object; size_t i; bool ok; TEST(@"+[list]", (list = [OFList list])) TEST(@"-[appendObject:]", [list appendObject: strings[0]] && [list appendObject: strings[1]] && [list appendObject: strings[2]]) TEST(@"-[firstListItem]", [OFListItemObject(list.firstListItem) isEqual: strings[0]]) TEST(@"OFListItemNext()", [OFListItemObject(OFListItemNext(list.firstListItem)) isEqual: strings[1]]) TEST(@"-[lastListItem]", [OFListItemObject(list.lastListItem) isEqual: strings[2]]) TEST(@"OFListItemPrevious()", [OFListItemObject(OFListItemPrevious(list.lastListItem)) isEqual: strings[1]]) TEST(@"-[removeListItem:]", R([list removeListItem: list.lastListItem]) && [list.lastObject isEqual: strings[1]] && R([list removeListItem: list.firstListItem]) && [list.firstObject isEqual: list.lastObject]) TEST(@"-[insertObject:beforeListItem:]", [list insertObject: strings[0] beforeListItem: list.lastListItem] && [OFListItemObject(OFListItemPrevious(list.lastListItem)) isEqual: strings[0]]) TEST(@"-[insertObject:afterListItem:]", [list insertObject: strings[2] afterListItem: OFListItemNext(list.firstListItem)] && [list.lastObject isEqual: strings[2]]) TEST(@"-[count]", list.count == 3) TEST(@"-[containsObject:]", [list containsObject: strings[1]] && ![list containsObject: @"nonexistent"]) TEST(@"-[containsObjectIdenticalTo:]", [list containsObjectIdenticalTo: strings[1]] && ![list containsObjectIdenticalTo: [OFString stringWithString: strings[1]]]) TEST(@"-[copy]", (list = [[list copy] autorelease]) && [list.firstObject isEqual: strings[0]] && [OFListItemObject(OFListItemNext(list.firstListItem)) isEqual: strings[1]] && [list.lastObject isEqual: strings[2]]) TEST(@"-[isEqual:]", [list isEqual: [[list copy] autorelease]]) TEST(@"-[description]", [list.description isEqual: @"[\n\tFoo,\n\tBar,\n\tBaz\n]"]) TEST(@"-[objectEnumerator]", (enumerator = [list objectEnumerator])) iter = list.firstListItem; i = 0; ok = true; while ((object = [enumerator nextObject]) != nil) { if (![object isEqual: OFListItemObject(iter)]) ok = false; iter = OFListItemNext(iter); i++; } if (list.count != i) ok = false; TEST(@"OFEnumerator's -[nextObject]", ok); [list removeListItem: list.firstListItem]; EXPECT_EXCEPTION(@"Detection of mutation during enumeration", OFEnumerationMutationException, [enumerator nextObject]) [list prependObject: strings[0]]; iter = list.firstListItem; i = 0; ok = true; for (OFString *object_ in list) { if (![object_ isEqual: OFListItemObject(iter)]) ok = false; iter = OFListItemNext(iter); i++; } if (list.count != i) ok = false; TEST(@"Fast Enumeration", ok) ok = false; @try { for (OFString *object_ in list) { (void)object_; [list removeListItem: list.lastListItem]; } } @catch (OFEnumerationMutationException *e) { ok = true; } TEST(@"Detection of mutation during Fast Enumeration", ok) |
︙ | ︙ |
Modified tests/OFLocaleTests.m from [2b5c756cd6] to [16fe524ac5].
︙ | ︙ | |||
18 19 20 21 22 23 24 | #import "TestsAppDelegate.h" @implementation TestsAppDelegate (OFLocaleTests) - (void)localeTests { void *pool = objc_autoreleasePoolPush(); | | | | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #import "TestsAppDelegate.h" @implementation TestsAppDelegate (OFLocaleTests) - (void)localeTests { void *pool = objc_autoreleasePoolPush(); [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeFormat: @"[OFLocale] Language: %@\n", [OFLocale language]]; [OFStdOut writeFormat: @"[OFLocale] Territory: %@\n", [OFLocale territory]]; [OFStdOut writeFormat: @"[OFLocale] Encoding: %@\n", OFStringEncodingName([OFLocale encoding])]; [OFStdOut writeFormat: @"[OFLocale] Decimal point: %@\n", [OFLocale decimalPoint]]; objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFMD5HashTests.m from [7ba538ae71] to [e16a55e7a6].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | | < | | | | | < | < | | | | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFMD5Hash"; const uint8_t testFileMD5[16] = "\x00\x8B\x9D\x1B\x58\xDF\xF8\xFE\xEE\xF3\xAE\x8D\xBB\x68\x2D\x38"; @implementation TestsAppDelegate (OFMD5HashTests) - (void)MD5HashTests { void *pool = objc_autoreleasePoolPush(); OFMD5Hash *MD5, *MD5Copy; OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (MD5 = [OFMD5Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [MD5 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (MD5Copy = [[MD5 copy] autorelease])) TEST(@"-[digest]", memcmp(MD5.digest, testFileMD5, 16) == 0 && memcmp(MD5Copy.digest, testFileMD5, 16) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, [MD5 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFMethodSignatureTests.m from [465deaed93] to [ebd654aa45].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) # include <complex.h> #endif #import "TestsAppDelegate.h" | | | | | | | | | | > | | | | | > | | | | | | > | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) # include <complex.h> #endif #import "TestsAppDelegate.h" static OFString *const module = @"OFMethodSignature"; struct Test1Struct { char c; int i; char d; }; struct Test2Struct { char c; struct { short s; int i; } st; union { char c; int i; } u; double d; }; #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) struct Test3Struct { char c; complex double cd; }; #endif union Test3Union { char c; int i; double d; }; union Test4Union { char c; struct { short x, y; } st; int i; union { float f; double d; } u; }; @implementation TestsAppDelegate (OFMethodSignatureTests) - (void)methodSignatureTests { void *pool = objc_autoreleasePoolPush(); OFMethodSignature *methodSignature; TEST(@"-[signatureWithObjCTypes:] #1", (methodSignature = [OFMethodSignature signatureWithObjCTypes: "i28@0:8S16*20"]) && methodSignature.numberOfArguments == 4 && strcmp(methodSignature.methodReturnType, "i") == 0 && strcmp([methodSignature argumentTypeAtIndex: 0], "@") == 0 && strcmp([methodSignature argumentTypeAtIndex: 1], ":") == 0 && strcmp([methodSignature argumentTypeAtIndex: 2], "S") == 0 && strcmp([methodSignature argumentTypeAtIndex: 3], "*") == 0 && methodSignature.frameLength == 28 && [methodSignature argumentOffsetAtIndex: 0] == 0 && [methodSignature argumentOffsetAtIndex: 1] == 8 && [methodSignature argumentOffsetAtIndex: 2] == 16 && [methodSignature argumentOffsetAtIndex: 3] == 20) TEST(@"-[signatureWithObjCTypes:] #2", (methodSignature = [OFMethodSignature signatureWithObjCTypes: "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}24@0:8" "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}16"]) && methodSignature.numberOfArguments == 3 && strcmp(methodSignature.methodReturnType, "{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}") == 0 && strcmp([methodSignature argumentTypeAtIndex: 0], "@") == 0 && strcmp([methodSignature argumentTypeAtIndex: 1], ":") == 0 && strcmp([methodSignature argumentTypeAtIndex: 2], "^{s0=csi(u1={s2=iii{s3=(u4=ic^v*)}})}") == 0 && methodSignature.frameLength == 24 && [methodSignature argumentOffsetAtIndex: 0] == 0 && [methodSignature argumentOffsetAtIndex: 1] == 8 && [methodSignature argumentOffsetAtIndex: 2] == 16) EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #3", OFInvalidFormatException, [OFMethodSignature signatureWithObjCTypes: "{ii"]) EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #4", OFInvalidFormatException, [OFMethodSignature signatureWithObjCTypes: ""]) EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #5", OFInvalidFormatException, [OFMethodSignature signatureWithObjCTypes: "0"]) EXPECT_EXCEPTION(@"-[signatureWithObjCTypes:] #6", OFInvalidFormatException, [OFMethodSignature signatureWithObjCTypes: "{{}0"]) TEST(@"OFSizeOfTypeEncoding() #1", OFSizeOfTypeEncoding(@encode(struct Test1Struct)) == sizeof(struct Test1Struct)) TEST(@"OFSizeOfTypeEncoding() #2", OFSizeOfTypeEncoding(@encode(struct Test2Struct)) == sizeof(struct Test2Struct)) #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ OF_GCC_VERSION >= 402 TEST(@"OFSizeOfTypeEncoding() #3", OFSizeOfTypeEncoding(@encode(struct Test3Struct)) == sizeof(struct Test3Struct)) #endif TEST(@"OFSizeOfTypeEncoding() #4", OFSizeOfTypeEncoding(@encode(union Test3Union)) == sizeof(union Test3Union)) TEST(@"OFSizeOfTypeEncoding() #5", OFSizeOfTypeEncoding(@encode(union Test4Union)) == sizeof(union Test4Union)) TEST(@"OFSizeOfTypeEncoding() #6", OFSizeOfTypeEncoding(@encode(struct Test1Struct [5])) == sizeof(struct Test1Struct [5])) TEST(@"OFAlignmentOfTypeEncoding() #1", OFAlignmentOfTypeEncoding(@encode(struct Test1Struct)) == OF_ALIGNOF(struct Test1Struct)) TEST(@"OFAlignmentOfTypeEncoding() #2", OFAlignmentOfTypeEncoding(@encode(struct Test2Struct)) == OF_ALIGNOF(struct Test2Struct)) #if !defined(__STDC_NO_COMPLEX__) && defined(HAVE_COMPLEX_H) && \ OF_GCC_VERSION >= 402 TEST(@"OFAlignmentOfTypeEncoding() #3", OFAlignmentOfTypeEncoding(@encode(struct Test3Struct)) == OF_ALIGNOF(struct Test3Struct)) #endif TEST(@"OFAlignmentOfTypeEncoding() #4", OFAlignmentOfTypeEncoding(@encode(union Test3Union)) == OF_ALIGNOF(union Test3Union)) TEST(@"OFAlignmentOfTypeEncoding() #5", OFAlignmentOfTypeEncoding(@encode(union Test4Union)) == OF_ALIGNOF(union Test4Union)) TEST(@"OFAlignmentOfTypeEncoding() #6", OFAlignmentOfTypeEncoding(@encode(struct Test1Struct [5])) == OF_ALIGNOF(struct Test1Struct [5])) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFNumberTests.m from [92564f033d] to [c0de3f5f8b].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFNumber"; @implementation TestsAppDelegate (OFNumberTests) - (void)numberTests { void *pool = objc_autoreleasePoolPush(); OFNumber *number; TEST(@"+[numberWithLongLong:]", (number = [OFNumber numberWithLongLong: 123456789])) TEST(@"-[isEqual:]", [number isEqual: [OFNumber numberWithLong: 123456789]]) TEST(@"-[hash]", number.hash == 0x82D8BC42) TEST(@"-[charValue]", number.charValue == 21) TEST(@"-[doubleValue]", number.doubleValue == 123456789.L) TEST(@"signed char minimum & maximum unmodified", (number = [OFNumber numberWithChar: SCHAR_MIN]) && number.charValue == SCHAR_MIN && (number = [OFNumber numberWithChar: SCHAR_MAX]) && number.charValue == SCHAR_MAX) TEST(@"short minimum & maximum unmodified", (number = [OFNumber numberWithShort: SHRT_MIN]) && number.shortValue == SHRT_MIN && (number = [OFNumber numberWithShort: SHRT_MAX]) && number.shortValue == SHRT_MAX) TEST(@"int minimum & maximum unmodified", (number = [OFNumber numberWithInt: INT_MIN]) && number.intValue == INT_MIN && (number = [OFNumber numberWithInt: INT_MAX]) && number.intValue == INT_MAX) TEST(@"long minimum & maximum unmodified", (number = [OFNumber numberWithLong: LONG_MIN]) && number.longValue == LONG_MIN && (number = [OFNumber numberWithLong: LONG_MAX]) && number.longValue == LONG_MAX) TEST(@"long long minimum & maximum unmodified", (number = [OFNumber numberWithLongLong: LLONG_MIN]) && number.longLongValue == LLONG_MIN && (number = [OFNumber numberWithLongLong: LLONG_MAX]) && number.longLongValue == LLONG_MAX) TEST(@"unsigned char maximum unmodified", (number = [OFNumber numberWithUnsignedChar: UCHAR_MAX]) && number.unsignedCharValue == UCHAR_MAX) TEST(@"unsigned short maximum unmodified", (number = [OFNumber numberWithUnsignedShort: USHRT_MAX]) && number.unsignedShortValue == USHRT_MAX) TEST(@"unsigned int maximum unmodified", (number = [OFNumber numberWithUnsignedInt: UINT_MAX]) && number.unsignedIntValue == UINT_MAX) TEST(@"unsigned long maximum unmodified", (number = [OFNumber numberWithUnsignedLong: ULONG_MAX]) && number.unsignedLongValue == ULONG_MAX) TEST(@"unsigned long long maximum unmodified", (number = [OFNumber numberWithUnsignedLongLong: ULLONG_MAX]) && number.unsignedLongLongValue == ULLONG_MAX) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFObjectTests.m from [87d14c79b3] to [84ff5d698c].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #if (defined(OF_DRAGONFLYBSD) && defined(__LP64__)) || defined(OF_NINTENDO_3DS) # define TOO_BIG (SIZE_MAX / 3) #else # define TOO_BIG (SIZE_MAX - 128) #endif | | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #if (defined(OF_DRAGONFLYBSD) && defined(__LP64__)) || defined(OF_NINTENDO_3DS) # define TOO_BIG (SIZE_MAX / 3) #else # define TOO_BIG (SIZE_MAX - 128) #endif static OFString *const module = @"OFObject"; @interface MyObject: OFObject { id _objectValue; Class _classValue; bool _boolValue; char _charValue; short _shortValue; int _intValue; |
︙ | ︙ | |||
57 58 59 60 61 62 63 | @property (nonatomic) unsigned int unsignedIntValue; @property (nonatomic) unsigned long unsignedLongValue; @property (nonatomic) unsigned long long unsignedLongLongValue; @property (nonatomic) float floatValue; @property (nonatomic) double doubleValue; @end | | | 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | @property (nonatomic) unsigned int unsignedIntValue; @property (nonatomic) unsigned long unsignedLongValue; @property (nonatomic) unsigned long long unsignedLongLongValue; @property (nonatomic) float floatValue; @property (nonatomic) double doubleValue; @end @implementation MyObject @synthesize objectValue = _objectValue, classValue = _classValue; @synthesize boolValue = _boolValue, charValue = _charValue; @synthesize shortValue = _shortValue, intValue = _intValue; @synthesize longValue = _longValue, longLongValue = _longLongValue; @synthesize unsignedCharValue = _unsignedCharValue; @synthesize unsignedShortValue = _unsignedShortValue; @synthesize unsignedIntValue = _unsignedIntValue; |
︙ | ︙ | |||
81 82 83 84 85 86 87 | } @end @implementation TestsAppDelegate (OFObjectTests) - (void)objectTests { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | | | < | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | > | > | | > | | | | | | | | | | | | | 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | } @end @implementation TestsAppDelegate (OFObjectTests) - (void)objectTests { void *pool = objc_autoreleasePoolPush(); OFObject *object; MyObject *myObject; TEST(@"+[description]", [[OFObject description] isEqual: @"OFObject"] && [[MyObject description] isEqual: @"MyObject"]) object = [[[OFObject alloc] init] autorelease]; myObject = [[[MyObject alloc] init] autorelease]; TEST(@"-[description]", [object.description isEqual: @"<OFObject>"] && [myObject.description isEqual: @"<MyObject>"]) myObject.objectValue = @"Hello"; myObject.classValue = myObject.class; TEST(@"-[valueForKey:]", [[myObject valueForKey: @"objectValue"] isEqual: @"Hello"] && [[myObject valueForKey: @"classValue"] isEqual: myObject.class] && [[myObject valueForKey: @"class"] isEqual: myObject.class]) EXPECT_EXCEPTION(@"-[valueForKey:] with undefined key", OFUndefinedKeyException, [myObject valueForKey: @"undefined"]) TEST(@"-[setValue:forKey:]", R([myObject setValue: @"World" forKey: @"objectValue"]) && R([myObject setValue: [OFObject class] forKey: @"classValue"]) && [myObject.objectValue isEqual: @"World"] && [myObject.classValue isEqual: [OFObject class]]) EXPECT_EXCEPTION(@"-[setValue:forKey:] with undefined key", OFUndefinedKeyException, [myObject setValue: @"x" forKey: @"undefined"]) myObject.boolValue = 1; myObject.charValue = 2; myObject.shortValue = 3; myObject.intValue = 4; myObject.longValue = 5; myObject.longLongValue = 6; myObject.unsignedCharValue = 7; myObject.unsignedShortValue = 8; myObject.unsignedIntValue = 9; myObject.unsignedLongValue = 10; myObject.unsignedLongLongValue = 11; myObject.floatValue = 12; myObject.doubleValue = 13; TEST(@"Auto-wrapping of -[valueForKey:]", [[myObject valueForKey: @"boolValue"] isEqual: [OFNumber numberWithBool: 1]] && [[myObject valueForKey: @"charValue"] isEqual: [OFNumber numberWithChar: 2]] && [[myObject valueForKey: @"shortValue"] isEqual: [OFNumber numberWithShort: 3]] && [[myObject valueForKey: @"intValue"] isEqual: [OFNumber numberWithInt: 4]] && [[myObject valueForKey: @"longValue"] isEqual: [OFNumber numberWithLong: 5]] && [[myObject valueForKey: @"longLongValue"] isEqual: [OFNumber numberWithLongLong: 6]] && [[myObject valueForKey: @"unsignedCharValue"] isEqual: [OFNumber numberWithUnsignedChar: 7]] && [[myObject valueForKey: @"unsignedShortValue"] isEqual: [OFNumber numberWithUnsignedShort: 8]] && [[myObject valueForKey: @"unsignedIntValue"] isEqual: [OFNumber numberWithUnsignedInt: 9]] && [[myObject valueForKey: @"unsignedLongValue"] isEqual: [OFNumber numberWithUnsignedLong: 10]] && [[myObject valueForKey: @"unsignedLongLongValue"] isEqual: [OFNumber numberWithUnsignedLongLong: 11]] && [[myObject valueForKey: @"floatValue"] isEqual: [OFNumber numberWithFloat: 12]] && [[myObject valueForKey: @"doubleValue"] isEqual: [OFNumber numberWithDouble: 13]]) TEST(@"Auto-wrapping of -[setValue:forKey:]", R([myObject setValue: [OFNumber numberWithBool: 0] forKey: @"boolValue"]) && R([myObject setValue: [OFNumber numberWithChar: 10] forKey: @"charValue"]) && R([myObject setValue: [OFNumber numberWithShort: 20] forKey: @"shortValue"]) && R([myObject setValue: [OFNumber numberWithInt: 30] forKey: @"intValue"]) && R([myObject setValue: [OFNumber numberWithLong: 40] forKey: @"longValue"]) && R([myObject setValue: [OFNumber numberWithLongLong: 50] forKey: @"longLongValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedChar: 60] forKey: @"unsignedCharValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedShort: 70] forKey: @"unsignedShortValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedInt: 80] forKey: @"unsignedIntValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedLong: 90] forKey: @"unsignedLongValue"]) && R([myObject setValue: [OFNumber numberWithUnsignedLongLong: 100] forKey: @"unsignedLongLongValue"]) && R([myObject setValue: [OFNumber numberWithFloat: 110] forKey: @"floatValue"]) && R([myObject setValue: [OFNumber numberWithDouble: 120] forKey: @"doubleValue"]) && myObject.isBoolValue == 0 && myObject.charValue == 10 && myObject.shortValue == 20 && myObject.intValue == 30 && myObject.longValue == 40 && myObject.longLongValue == 50 && myObject.unsignedCharValue == 60 && myObject.unsignedShortValue == 70 && myObject.unsignedIntValue == 80 && myObject.unsignedLongValue == 90 && myObject.unsignedLongLongValue == 100 && myObject.floatValue == 110 && myObject.doubleValue == 120) EXPECT_EXCEPTION(@"Catch -[setValue:forKey:] with nil key for scalar", OFInvalidArgumentException, [myObject setValue: (id _Nonnull)nil forKey: @"intValue"]) TEST(@"-[valueForKeyPath:]", (myObject = [[[MyObject alloc] init] autorelease]) && (myObject.objectValue = [[[MyObject alloc] init] autorelease]) && R([myObject.objectValue setObjectValue: [[[MyObject alloc] init] autorelease]]) && R([[myObject.objectValue objectValue] setDoubleValue: 0.5]) && [[myObject valueForKeyPath: @"objectValue.objectValue.doubleValue"] doubleValue] == 0.5) TEST(@"[-setValue:forKeyPath:]", R([myObject setValue: [OFNumber numberWithDouble: 0.75] forKeyPath: @"objectValue.objectValue.doubleValue"]) && [[myObject.objectValue objectValue] doubleValue] == 0.75) objc_autoreleasePoolPop(pool); } @end |
Renamed and modified tests/PBKDF2Tests.m [ed81571c9c] to tests/OFPBKDF2Tests.m [650e1671f9].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFPBKDF2"; @implementation TestsAppDelegate (OFPBKDF2Tests) - (void)PBKDF2Tests { void *pool = objc_autoreleasePoolPush(); OFHMAC *HMAC = [OFHMAC HMACWithHashClass: [OFSHA1Hash class] allowsSwappableMemory: true]; unsigned char key[25]; /* Test vectors from RFC 6070 */ TEST(@"PBKDF2-SHA1, 1 iteration", R(OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 1, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true })) && memcmp(key, "\x0C\x60\xC8\x0F\x96\x1F\x0E\x71\xF3\xA9\xB5" "\x24\xAF\x60\x12\x06\x2F\xE0\x37\xA6", 20) == 0) TEST(@"PBKDF2-SHA1, 2 iterations", R(OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 2, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true })) && memcmp(key, "\xEA\x6C\x01\x4D\xC7\x2D\x6F\x8C\xCD\x1E\xD9" "\x2A\xCE\x1D\x41\xF0\xD8\xDE\x89\x57", 20) == 0) TEST(@"PBKDF2-SHA1, 4096 iterations", R(OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 4096, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true })) && memcmp(key, "\x4B\x00\x79\x01\xB7\x65\x48\x9A\xBE\xAD\x49" "\xD9\x26\xF7\x21\xD0\x65\xA4\x29\xC1", 20) == 0) /* This test takes too long, even on a fast machine. */ #if 0 TEST(@"PBKDF2-SHA1, 16777216 iterations", R(OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 16777216, .salt = (unsigned char *)"salt", .saltLength = 4, .password = "password", .passwordLength = 8, .key = key, .keyLength = 20, .allowsSwappableMemory = true })) && memcmp(key, "\xEE\xFE\x3D\x61\xCD\x4D\xA4\xE4\xE9\x94\x5B" "\x3D\x6B\xA2\x15\x8C\x26\x34\xE9\x84", 20) == 0) #endif TEST(@"PBKDF2-SHA1, 4096 iterations, key > 1 block", R(OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 4096, .salt = (unsigned char *)"saltSALTsaltSALTsalt" "SALTsaltSALTsalt", .saltLength = 36, .password = "passwordPASSWORDpassword", .passwordLength = 24, .key = key, .keyLength = 25, .allowsSwappableMemory = true })) && memcmp(key, "\x3D\x2E\xEC\x4F\xE4\x1C\x84\x9B\x80\xC8\xD8\x36\x62" "\xC0\xE4\x4A\x8B\x29\x1A\x96\x4C\xF2\xF0\x70\x38", 25) == 0) TEST(@"PBKDF2-SHA1, 4096 iterations, key < 1 block", R(OFPBKDF2((OFPBKDF2Parameters){ .HMAC = HMAC, .iterations = 4096, .salt = (unsigned char *)"sa\0lt", .saltLength = 5, .password = "pass\0word", .passwordLength = 9, .key = key, |
︙ | ︙ |
Modified tests/OFPluginTests.m from [5d4c7a32e2] to [4801b7fe9e].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #import "TestsAppDelegate.h" #import "plugin/TestPlugin.h" #ifndef OF_IOS | | | | | | | 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 | #include "config.h" #import "TestsAppDelegate.h" #import "plugin/TestPlugin.h" #ifndef OF_IOS static OFString *const pluginPath = @"plugin/TestPlugin"; #else static OFString *const pluginPath = @"PlugIns/TestPlugin"; #endif static OFString *const module = @"OFPlugin"; @implementation TestsAppDelegate (OFPluginTests) - (void)pluginTests { void *pool = objc_autoreleasePoolPush(); TestPlugin *plugin; TEST(@"+[pluginWithPath:]", (plugin = [OFPlugin pluginWithPath: pluginPath])) TEST(@"TestPlugin's -[test:]", [plugin test: 1234] == 2468) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFPropertyListTests.m from [b2a840a564] to [9ca2969379].
︙ | ︙ | |||
21 22 23 24 25 26 27 | @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \ @"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " \ @"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" \ @"<plist version=\"1.0\">\n" \ x @"\n" \ @"</plist>" | | | | | | 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 | @"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" \ @"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" " \ @"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" \ @"<plist version=\"1.0\">\n" \ x @"\n" \ @"</plist>" static OFString *const module = @"OFPropertyList"; static OFString *const PLIST1 = PLIST(@"<string>Hello</string>"); static OFString *const PLIST2 = PLIST( @"<array>" @" <string>Hello</string>" @" <data>V29ybGQh</data>" @" <date>2018-03-14T12:34:56Z</date>" @" <true/>" @" <false/>" @" <real>12.25</real>" @" <integer>-10</integer>" @"</array>"); static OFString *const PLIST3 = PLIST( @"<dict>" @" <key>array</key>" @" <array>" @" <string>Hello</string>" @" <data>V29ybGQh</data>" @" <date>2018-03-14T12:34:56Z</date>" @" <true/>" |
︙ | ︙ | |||
55 56 57 58 59 60 61 | @implementation TestsAppDelegate (OFPLISTParser) - (void)propertyListTests { void *pool = objc_autoreleasePoolPush(); OFArray *array = [OFArray arrayWithObjects: @"Hello", | | < | 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | @implementation TestsAppDelegate (OFPLISTParser) - (void)propertyListTests { void *pool = objc_autoreleasePoolPush(); OFArray *array = [OFArray arrayWithObjects: @"Hello", [OFData dataWithItems: "World!" count: 6], [OFDate dateWithTimeIntervalSince1970: 1521030896], [OFNumber numberWithBool: true], [OFNumber numberWithBool: false], [OFNumber numberWithFloat: 12.25f], [OFNumber numberWithInt: -10], nil]; |
︙ | ︙ |
Modified tests/OFRIPEMD160HashTests.m from [35f25635b9] to [00f15b1edb].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | < | < | | | | < | < | | | | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFRIPEMD160Hash"; const uint8_t testFileRIPEMD160[20] = "\x46\x02\x97\xF5\x85\xDF\xB9\x21\x00\xC8\xF9\x87\xC6\xEC\x84\x0D\xCE" "\xE6\x08\x8B"; @implementation TestsAppDelegate (OFRIPEMD160HashTests) - (void)RIPEMD160HashTests { void *pool = objc_autoreleasePoolPush(); OFRIPEMD160Hash *RIPEMD160, *RIPEMD160Copy; OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (RIPEMD160 = [OFRIPEMD160Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [RIPEMD160 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (RIPEMD160Copy = [[RIPEMD160 copy] autorelease])) TEST(@"-[digest]", memcmp(RIPEMD160.digest, testFileRIPEMD160, 20) == 0 && memcmp(RIPEMD160Copy.digest, testFileRIPEMD160, 20) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length]", OFHashAlreadyCalculatedException, [RIPEMD160 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Deleted tests/OFSCTPSocketTests.m version [5eb12e5159].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Modified tests/OFSHA1HashTests.m from [178723d8a9] to [4f485b9d65].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | < | | | | | < | < | | | | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFSHA1Hash"; const uint8_t testFileSHA1[20] = "\xC9\x9A\xB8\x7E\x1E\xC8\xEC\x65\xD5\xEB\xE4\x2E\x0D\xA6\x80\x96\xF5" "\x94\xE7\x17"; @implementation TestsAppDelegate (SHA1HashTests) - (void)SHA1HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA1Hash *SHA1, *SHA1Copy; OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA1 = [OFSHA1Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [SHA1 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA1Copy = [[SHA1 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA1.digest, testFileSHA1, 20) == 0 && memcmp(SHA1Copy.digest, testFileSHA1, 20) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA1 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA224HashTests.m from [b5e3284a33] to [d949087e30].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | < | | | | | < | < | | | | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFSHA224Hash"; const uint8_t testFileSHA224[28] = "\x27\x69\xD8\x04\x2D\x0F\xCA\x84\x6C\xF1\x62\x44\xBA\x0C\xBD\x46\x64" "\x5F\x4F\x20\x02\x4D\x15\xED\x1C\x61\x1F\xF7"; @implementation TestsAppDelegate (SHA224HashTests) - (void)SHA224HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA224Hash *SHA224, *SHA224Copy; OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA224 = [OFSHA224Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [SHA224 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA224Copy = [[SHA224 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA224.digest, testFileSHA224, 28) == 0 && memcmp(SHA224Copy.digest, testFileSHA224, 28) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA224 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA256HashTests.m from [301369bd01] to [f90460efa2].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | < | | | | | < | < | | | | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFSHA256Hash"; const uint8_t testFileSHA256[32] = "\x1A\x02\xD6\x46\xF5\xA6\xBA\xAA\xFF\x7F\xD5\x87\xBA\xC3\xF6\xC6\xB5" "\x67\x93\x8F\x0F\x44\x90\xB8\xF5\x35\x89\xF0\x5A\x23\x7F\x69"; @implementation TestsAppDelegate (SHA256HashTests) - (void)SHA256HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA256Hash *SHA256, *SHA256Copy; OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA256 = [OFSHA256Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[64]; size_t length = [file readIntoBuffer: buffer length: 64]; [SHA256 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA256Copy = [[SHA256 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA256.digest, testFileSHA256, 32) == 0 && memcmp(SHA256Copy.digest, testFileSHA256, 32) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA256 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA384HashTests.m from [dc27edd55b] to [7fee81f984].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | < | | | | | < | < | | | | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFSHA384Hash"; const uint8_t testFileSHA384[48] = "\x7E\xDE\x62\xE2\x10\xA5\x1E\x18\x8A\x11\x7F\x78\xD7\xC7\x55\xB6\x43" "\x94\x1B\xD2\x78\x5C\xCF\xF3\x8A\xB8\x98\x22\xC7\x0E\xFE\xF1\xEC\x53" "\xE9\x1A\xB3\x51\x70\x8C\x1F\x3F\x56\x12\x44\x01\x91\x54"; @implementation TestsAppDelegate (SHA384HashTests) - (void)SHA384HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA384Hash *SHA384, *SHA384Copy; OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA384 = [OFSHA384Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[128]; size_t length = [file readIntoBuffer: buffer length: 128]; [SHA384 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA384Copy = [[SHA384 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA384.digest, testFileSHA384, 48) == 0 && memcmp(SHA384Copy.digest, testFileSHA384, 48) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA384 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSHA512HashTests.m from [d42fcd68e6] to [b65f0f5008].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | < | | | | | < | < | | | | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFSHA512Hash"; const uint8_t testFileSHA512[64] = "\x8F\x36\x6E\x3C\x19\x4B\xBB\xC7\x82\xAA\xCD\x7D\x55\xA2\xD3\x29\x29" "\x97\x6A\x3F\xEB\x9B\xB2\xCB\x75\xC9\xEC\xC8\x10\x07\xD6\x07\x31\x4A" "\xB1\x30\x97\x82\x58\xA5\x1F\x71\x42\xE6\x56\x07\x99\x57\xB2\xB8\x3B" "\xA1\x8A\x41\x64\x33\x69\x21\x8C\x2A\x44\x6D\xF2\xA0"; @implementation TestsAppDelegate (SHA512HashTests) - (void)SHA512HashTests { void *pool = objc_autoreleasePoolPush(); OFSHA512Hash *SHA512, *SHA512Copy; OFFile *file = [OFFile fileWithPath: @"testfile.bin" mode: @"r"]; TEST(@"+[hashWithAllowsSwappableMemory:]", (SHA512 = [OFSHA512Hash hashWithAllowsSwappableMemory: true])) while (!file.atEndOfStream) { char buffer[128]; size_t length = [file readIntoBuffer: buffer length: 128]; [SHA512 updateWithBuffer: buffer length: length]; } [file close]; TEST(@"-[copy]", (SHA512Copy = [[SHA512 copy] autorelease])) TEST(@"-[digest]", memcmp(SHA512.digest, testFileSHA512, 64) == 0 && memcmp(SHA512Copy.digest, testFileSHA512, 64) == 0) EXPECT_EXCEPTION(@"Detect invalid call of " @"-[updateWithBuffer:length:]", OFHashAlreadyCalculatedException, [SHA512 updateWithBuffer: "" length: 1]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSPXSocketTests.m from [ea2a79212c] to [1c45b38ca1].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <errno.h> #import "TestsAppDelegate.h" | | | | | | | | | | | | | | | | | | | < < | < | < | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | #include "config.h" #include <errno.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFSPXSocket"; @interface SPXSocketDelegate: OFObject <OFSPXSocketDelegate> { @public OFSequencedPacketSocket *_expectedServerSocket; OFSPXSocket *_expectedClientSocket; unsigned char _expectedNode[IPX_NODE_LEN]; uint32_t _expectedNetwork; uint16_t _expectedPort; bool _accepted; bool _connected; } @end @implementation SPXSocketDelegate - (bool)socket: (OFSequencedPacketSocket *)sock didAcceptSocket: (OFSequencedPacketSocket *)accepted exception: (id)exception { OFEnsure(!_accepted); _accepted = (sock == _expectedServerSocket && accepted != nil && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; return false; } - (void)socket: (OFSPXSocket *)sock didConnectToNode: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && network == _expectedNetwork && port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end @implementation TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests { void *pool = objc_autoreleasePoolPush(); OFSPXSocket *sockClient, *sockServer, *sockAccepted;; OFSocketAddress address1; const OFSocketAddress *address2; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; uint16_t port; char buffer[5]; SPXSocketDelegate *delegate; TEST(@"+[socket]", (sockClient = [OFSPXSocket socket]) && (sockServer = [OFSPXSocket socket])) @try { TEST(@"-[bindToPort:]", R(address1 = [sockServer bindToPort: 0])) } @catch (OFBindFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXSocket] -[bindToPort:]: " @"IPX unsupported, skipping tests"]; break; case ESOCKTNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXSocket] -[bindToPort:]: " @"SPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXSocket] -[bindToPort:]: " @"IPX not configured, skipping tests"]; break; default: @throw e; } objc_autoreleasePoolPop(pool); return; } OFSocketAddressIPXNode(&address1, node); network = OFSocketAddressIPXNetwork(&address1); port = OFSocketAddressPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNode:network:port:]", R([sockClient connectToNode: node network: network port: port])) TEST(@"-[accept]", (sockAccepted = [sockServer accept])) TEST(@"-[sendBuffer:length:]", R([sockAccepted sendBuffer: "Hello" length: 5])) TEST(@"-[receiveIntoBuffer:length:]", [sockClient receiveIntoBuffer: buffer length: 5] == 5 && memcmp(buffer, "Hello", 5) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && R(OFSocketAddressIPXNode(address2, node2)) && memcmp(node, node2, IPX_NODE_LEN) == 0 && OFSocketAddressIPXNetwork(address2) == network) delegate = [[[SPXSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXSocket socket]; delegate->_expectedServerSocket = sockServer; sockServer.delegate = delegate; sockClient = [OFSPXSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; address1 = [sockServer bindToPort: 0]; [sockServer listen]; [sockServer asyncAccept]; OFSocketAddressIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&address1); delegate->_expectedPort = port = OFSocketAddressPort(&address1); @try { [sockClient asyncConnectToNode: node network: network port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; TEST(@"-[asyncAccept] & -[asyncConnectToNode:network:port:]", delegate->_accepted && delegate->_connected) } @catch (OFObserveFailedException *e) { switch (e.errNo) { case ENOTSOCK: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXSocket] -[asyncAccept] & " @"-[asyncConnectToNode:network:port:]: select() " @"not supported for SPX, skipping test"]; break; default: @throw e; } } objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSPXStreamSocketTests.m from [b2fe1b33a9] to [0326ef9bb8].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <errno.h> #import "TestsAppDelegate.h" | | | | | | | | | | | | | | | | | | | < < | < | < | < | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #include "config.h" #include <errno.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFSPXStreamSocket"; @interface SPXStreamSocketDelegate: OFObject <OFSPXStreamSocketDelegate> { @public OFStreamSocket *_expectedServerSocket; OFSPXStreamSocket *_expectedClientSocket; unsigned char _expectedNode[IPX_NODE_LEN]; uint32_t _expectedNetwork; uint16_t _expectedPort; bool _accepted; bool _connected; } @end @implementation SPXStreamSocketDelegate - (bool)socket: (OFStreamSocket *)sock didAcceptSocket: (OFStreamSocket *)accepted exception: (id)exception { OFEnsure(!_accepted); _accepted = (sock == _expectedServerSocket && accepted != nil && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; return false; } - (void)socket: (OFSPXStreamSocket *)sock didConnectToNode: (unsigned char [IPX_NODE_LEN])node network: (uint32_t)network port: (uint16_t)port exception: (id)exception { OFEnsure(!_connected); _connected = (sock == _expectedClientSocket && memcmp(node, _expectedNode, IPX_NODE_LEN) == 0 && network == _expectedNetwork && port == _expectedPort && exception == nil); if (_accepted && _connected) [[OFRunLoop mainRunLoop] stop]; } @end @implementation TestsAppDelegate (OFSPXStreamSocketTests) - (void)SPXStreamSocketTests { void *pool = objc_autoreleasePoolPush(); OFSPXStreamSocket *sockClient, *sockServer, *sockAccepted;; OFSocketAddress address1; const OFSocketAddress *address2; unsigned char node[IPX_NODE_LEN], node2[IPX_NODE_LEN]; uint32_t network; uint16_t port; char buffer[5]; SPXStreamSocketDelegate *delegate; TEST(@"+[socket]", (sockClient = [OFSPXStreamSocket socket]) && (sockServer = [OFSPXStreamSocket socket])) @try { TEST(@"-[bindToPort:]", R(address1 = [sockServer bindToPort: 0])) } @catch (OFBindFailedException *e) { switch (e.errNo) { case EAFNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[bindToPort:]: " @"IPX unsupported, skipping tests"]; break; case ESOCKTNOSUPPORT: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[bindToPort:]: " @"SPX unsupported, skipping tests"]; break; case EADDRNOTAVAIL: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[bindToPort:]: " @"IPX not configured, skipping tests"]; break; default: @throw e; } objc_autoreleasePoolPop(pool); return; } OFSocketAddressIPXNode(&address1, node); network = OFSocketAddressIPXNetwork(&address1); port = OFSocketAddressPort(&address1); TEST(@"-[listen]", R([sockServer listen])) TEST(@"-[connectToNode:network:port:]", R([sockClient connectToNode: node network: network port: port])) TEST(@"-[accept]", (sockAccepted = [sockServer accept])) /* Test reassembly (this would not work with OFSPXSocket) */ TEST(@"-[writeBuffer:length:]", R([sockAccepted writeBuffer: "Hello" length: 5])) TEST(@"-[readIntoBuffer:length:]", [sockClient readIntoBuffer: buffer length: 2] == 2 && memcmp(buffer, "He", 2) == 0 && [sockClient readIntoBuffer: buffer length: 3] == 3 && memcmp(buffer, "llo", 3) == 0) TEST(@"-[remoteAddress]", (address2 = sockAccepted.remoteAddress) && R(OFSocketAddressIPXNode(address2, node2)) && memcmp(node, node2, IPX_NODE_LEN) == 0 && OFSocketAddressIPXNetwork(address2) == network) delegate = [[[SPXStreamSocketDelegate alloc] init] autorelease]; sockServer = [OFSPXStreamSocket socket]; delegate->_expectedServerSocket = sockServer; sockServer.delegate = delegate; sockClient = [OFSPXStreamSocket socket]; delegate->_expectedClientSocket = sockClient; sockClient.delegate = delegate; address1 = [sockServer bindToPort: 0]; [sockServer listen]; [sockServer asyncAccept]; OFSocketAddressIPXNode(&address1, node); memcpy(delegate->_expectedNode, node, IPX_NODE_LEN); delegate->_expectedNetwork = network = OFSocketAddressIPXNetwork(&address1); delegate->_expectedPort = port = OFSocketAddressPort(&address1); @try { [sockClient asyncConnectToNode: node network: network port: port]; [[OFRunLoop mainRunLoop] runUntilDate: [OFDate dateWithTimeIntervalSinceNow: 2]]; TEST(@"-[asyncAccept] & -[asyncConnectToNode:network:port:]", delegate->_accepted && delegate->_connected) } @catch (OFObserveFailedException *e) { switch (e.errNo) { case ENOTSOCK: [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeLine: @"\r[OFSPXStreamSocket] -[asyncAccept] & " @"-[asyncConnectToNode:network:port:]: select() " @"not supported for SPX, skipping test"]; break; default: @throw e; } } objc_autoreleasePoolPop(pool); } @end |
Renamed and modified tests/ScryptTests.m [c3d319d11a] to tests/OFScryptTests.m [2e44374c3f].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFScrypt"; /* Test vectors form RFC 7914 */ static const unsigned char salsa20Input[64] = { 0x7E, 0x87, 0x9A, 0x21, 0x4F, 0x3E, 0xC9, 0x86, 0x7C, 0xA9, 0x40, 0xE6, 0x41, 0x71, 0x8F, 0x26, 0xBA, 0xEE, 0x55, 0x5B, 0x8C, 0x61, 0xC1, 0xB5, 0x0D, 0xF8, 0x46, 0x11, 0x6D, 0xCD, 0x3B, 0x1D, 0xEE, 0x24, 0xF3, 0x19, 0xDF, 0x9B, 0x3D, 0x85, 0x14, 0x12, 0x1E, 0x4B, 0x5A, 0xC5, 0xAA, 0x32, 0x76, 0x02, 0x1D, 0x29, 0x09, 0xC7, 0x48, 0x29, 0xED, 0xEB, 0xC6, 0x8D, |
︙ | ︙ | |||
126 127 128 129 130 131 132 | 0xAB, 0xE5, 0xEE, 0x98, 0x20, 0xAD, 0xAA, 0x47, 0x8E, 0x56, 0xFD, 0x8F, 0x4B, 0xA5, 0xD0, 0x9F, 0xFA, 0x1C, 0x6D, 0x92, 0x7C, 0x40, 0xF4, 0xC3, 0x37, 0x30, 0x40, 0x49, 0xE8, 0xA9, 0x52, 0xFB, 0xCB, 0xF4, 0x5C, 0x6F, 0xA7, 0x7A, 0x41, 0xA4 }; #endif | | | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | 0xAB, 0xE5, 0xEE, 0x98, 0x20, 0xAD, 0xAA, 0x47, 0x8E, 0x56, 0xFD, 0x8F, 0x4B, 0xA5, 0xD0, 0x9F, 0xFA, 0x1C, 0x6D, 0x92, 0x7C, 0x40, 0xF4, 0xC3, 0x37, 0x30, 0x40, 0x49, 0xE8, 0xA9, 0x52, 0xFB, 0xCB, 0xF4, 0x5C, 0x6F, 0xA7, 0x7A, 0x41, 0xA4 }; #endif @implementation TestsAppDelegate (OFScryptTests) - (void)scryptTests { void *pool = objc_autoreleasePoolPush(); uint32_t salsa20Buffer[16]; uint32_t blockMixBuffer[32]; uint32_t ROMixBuffer[32], ROMixTmp[17 * 32]; unsigned char output[64]; TEST(@"Salsa20/8 Core", R(memcpy(salsa20Buffer, salsa20Input, 64)) && R(OFSalsa20_8Core(salsa20Buffer)) && memcmp(salsa20Buffer, salsa20Output, 64) == 0) TEST(@"Block mix", R(OFScryptBlockMix(blockMixBuffer, blockMixInput.u32, 1)) && memcmp(blockMixBuffer, blockMixOutput, 128) == 0) TEST(@"ROMix", R(memcpy(ROMixBuffer, ROMixInput, 128)) && R(OFScryptROMix(ROMixBuffer, 1, 16, ROMixTmp)) && memcmp(ROMixBuffer, ROMixOutput, 128) == 0) TEST(@"scrypt test vector #1", R(OFScrypt((OFScryptParameters){ .blockSize = 1, .costFactor = 16, .parallelization = 1, .salt = (unsigned char *)"", .saltLength = 0, .password = "", .passwordLength = 0, .key = output, .keyLength = 64, .allowsSwappableMemory = true })) && memcmp(output, testVector1, 64) == 0) TEST(@"scrypt test vector #2", R(OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1024, .parallelization = 16, .salt = (unsigned char *)"NaCl", .saltLength = 4, .password = "password", .passwordLength = 8, .key = output, .keyLength = 64, .allowsSwappableMemory = true })) && memcmp(output, testVector2, 64) == 0) TEST(@"scrypt test vector #3", R(OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 16384, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14, .password = "pleaseletmein", .passwordLength = 13, .key = output, .keyLength = 64, .allowsSwappableMemory = true })) && memcmp(output, testVector3, 64) == 0) /* The forth test vector is too expensive to include it in the tests. */ #if 0 TEST(@"scrypt test vector #4", R(OFScrypt((OFScryptParameters){ .blockSize = 8, .costFactor = 1048576, .parallelization = 1, .salt = (unsigned char *)"SodiumChloride", .saltLength = 14, .password = "pleaseletmein", .passwordLength = 13, |
︙ | ︙ |
Modified tests/OFSerializationTests.m from [123b41888a] to [c0ded8afa9].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | < | < | | | | > | | | < | < | | > | 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 61 62 63 64 65 66 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFSerialization"; @implementation TestsAppDelegate (OFSerializationTests) - (void)serializationTests { void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *dict = [OFMutableDictionary dictionary]; OFMutableArray *array = [OFMutableArray array]; OFList *list = [OFList list]; OFData *data; OFString *string; [array addObject: @"Qu\"xbar\ntest"]; [array addObject: [OFNumber numberWithInt: 1234]]; [array addObject: [OFNumber numberWithDouble: 1234.5678]]; [array addObject: [OFMutableString stringWithString: @"asd"]]; [array addObject: [OFDate dateWithTimeIntervalSince1970: 1234.5678]]; [dict setObject: @"Hello" forKey: array]; [dict setObject: @"B\"la" forKey: @"Blub"]; [list appendObject: @"Hello"]; [list appendObject: @"Wo\rld!\nHow are you?"]; [list appendObject: [OFURL URLWithString: @"https://objfw.nil.im/"]]; [list appendObject: [OFXMLElement elementWithXMLString: @"<x><y/><![CDATA[<]]></x>"]]; [list appendObject: [OFSet setWithObjects: @"foo", @"foo", @"bar", nil]]; [list appendObject: [OFCountedSet setWithObjects: @"foo", @"foo", @"bar", nil]]; [dict setObject: @"list" forKey: list]; data = [OFData dataWithItems: "0123456789:;<ABCDEFGHJIKLMNOPQRSTUVWXYZ" count: 39]; [dict setObject: @"data" forKey: data]; TEST(@"-[stringBySerializing]", (string = dict.stringBySerializing) && [string isEqual: [OFString stringWithContentsOfFile: @"serialization.xml"]]) TEST(@"-[objectByDeserializing]", [string.objectByDeserializing isEqual: dict]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFSetTests.m from [ac52690eae] to [d85d2c2bce].
︙ | ︙ | |||
17 18 19 20 21 22 23 | #import "TestsAppDelegate.h" #import "OFSet.h" #import "OFMapTableSet.h" #import "OFMutableMapTableSet.h" | | | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #import "TestsAppDelegate.h" #import "OFSet.h" #import "OFMapTableSet.h" #import "OFMutableMapTableSet.h" static OFString *module; @interface SimpleSet: OFSet { OFMutableSet *_set; } @end |
︙ | ︙ | |||
75 76 77 78 79 80 81 | [self release]; @throw e; } return self; } | | < | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | [self release]; @throw e; } return self; } - (instancetype)initWithObject: (id)firstObject arguments: (va_list)arguments { self = [super init]; @try { _set = [[OFMutableSet alloc] initWithObject: firstObject arguments: arguments]; } @catch (id e) { |
︙ | ︙ | |||
141 142 143 144 145 146 147 | [_set removeObject: object]; if (existed) _mutations++; } | | | < | 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | [_set removeObject: object]; if (existed) _mutations++; } - (int)countByEnumeratingWithState: (OFFastEnumerationState *)state objects: (id *)objects count: (int)count { int ret = [_set countByEnumeratingWithState: state objects: objects count: count]; state->mutationsPtr = &_mutations; return ret; } @end @implementation TestsAppDelegate (OFSetTests) - (void)setTestsWithClass: (Class)setClass mutableClass: (Class)mutableSetClass { void *pool = objc_autoreleasePoolPush(); OFSet *set1, *set2; OFMutableSet *mutableSet; bool ok; size_t i; |
︙ | ︙ |
Renamed and modified tests/SocketTests.m [a3c28758aa] to tests/OFSocketTests.m [bd6253505c].
︙ | ︙ | |||
48 49 50 51 52 53 54 | a.sockaddr.in6.sin6_addr.s6_addr[10] = a5 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[11] = a5 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[12] = a6 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[13] = a6 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[14] = a7 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[15] = a7 & 0xFF; | | | | < | | | | < | | < | | < | | < | | < | | < | > > | < | | | | | | | | | | | < | | < | | < | | < | | < | | < | | < | | < | | < | | > | | | < | < | < | | < | | < | | < | | < | | < < | < | | < | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | a.sockaddr.in6.sin6_addr.s6_addr[10] = a5 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[11] = a5 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[12] = a6 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[13] = a6 & 0xFF; \ a.sockaddr.in6.sin6_addr.s6_addr[14] = a7 >> 8; \ a.sockaddr.in6.sin6_addr.s6_addr[15] = a7 & 0xFF; static OFString *const module = @"OFSocket"; @implementation TestsAppDelegate (OFSocketTests) - (void)socketTests { void *pool = objc_autoreleasePoolPush(); OFSocketAddress addr; TEST(@"Parsing an IPv4", R(addr = OFSocketAddressParseIP(@"127.0.0.1", 1234)) && OFFromBigEndian32(addr.sockaddr.in.sin_addr.s_addr) == 0x7F000001 && OFFromBigEndian16(addr.sockaddr.in.sin_port) == 1234) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #1", OFInvalidFormatException, OFSocketAddressParseIP(@"127.0.0.0.1", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #2", OFInvalidFormatException, OFSocketAddressParseIP(@"127.0.0.256", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #3", OFInvalidFormatException, OFSocketAddressParseIP(@"127.0.0. 1", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #4", OFInvalidFormatException, OFSocketAddressParseIP(@" 127.0.0.1", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #5", OFInvalidFormatException, OFSocketAddressParseIP(@"127.0.a.1", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv4 #6", OFInvalidFormatException, OFSocketAddressParseIP(@"127.0..1", 1234)) TEST(@"Port of an IPv4 address", OFSocketAddressPort(&addr) == 1234) TEST(@"Converting an IPv4 to a string", [OFSocketAddressString(&addr) isEqual: @"127.0.0.1"]) TEST(@"Parsing an IPv6 #1", R(addr = OFSocketAddressParseIP( @"1122:3344:5566:7788:99aa:bbCc:ddee:ff00", 1234)) && COMPARE_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #2", R(addr = OFSocketAddressParseIP(@"::", 1234)) && COMPARE_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #3", R(addr = OFSocketAddressParseIP(@"aaAa::bBbb", 1234)) && COMPARE_V6(addr, 0xAAAA, 0, 0, 0, 0, 0, 0, 0xBBBB) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #4", R(addr = OFSocketAddressParseIP(@"aaAa::", 1234)) && COMPARE_V6(addr, 0xAAAA, 0, 0, 0, 0, 0, 0, 0) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) TEST(@"Parsing an IPv6 #5", R(addr = OFSocketAddressParseIP(@"::aaAa", 1234)) && COMPARE_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0xAAAA) && OFFromBigEndian16(addr.sockaddr.in6.sin6_port) == 1234) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #1", OFInvalidFormatException, OFSocketAddressParseIP(@"1:::2", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #2", OFInvalidFormatException, OFSocketAddressParseIP(@"1: ::2", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #3", OFInvalidFormatException, OFSocketAddressParseIP(@"1:: :2", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #4", OFInvalidFormatException, OFSocketAddressParseIP(@"1::2::3", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #5", OFInvalidFormatException, OFSocketAddressParseIP(@"10000::1", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #6", OFInvalidFormatException, OFSocketAddressParseIP(@"::10000", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #7", OFInvalidFormatException, OFSocketAddressParseIP(@"::1::", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #8", OFInvalidFormatException, OFSocketAddressParseIP(@"1:2:3:4:5:6:7:", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #9", OFInvalidFormatException, OFSocketAddressParseIP(@"1:2:3:4:5:6:7::", 1234)) EXPECT_EXCEPTION(@"Refusing invalid IPv6 #10", OFInvalidFormatException, OFSocketAddressParseIP(@"1:2", 1234)) TEST(@"Port of an IPv6 address", OFSocketAddressPort(&addr) == 1234) SET_V6(addr, 0, 0, 0, 0, 0, 0, 0, 0) TEST(@"Converting an IPv6 to a string #1", [OFSocketAddressString(&addr) isEqual: @"::"]) SET_V6(addr, 0, 0, 0, 0, 0, 0, 0, 1) TEST(@"Converting an IPv6 to a string #2", [OFSocketAddressString(&addr) isEqual: @"::1"]) SET_V6(addr, 1, 0, 0, 0, 0, 0, 0, 0) TEST(@"Converting an IPv6 to a string #3", [OFSocketAddressString(&addr) isEqual: @"1::"]) SET_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #4", [OFSocketAddressString(&addr) isEqual: @"1122:3344:5566:7788:99aa:bbcc:ddee:ff00"]) SET_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0) TEST(@"Converting an IPv6 to a string #5", [OFSocketAddressString(&addr) isEqual: @"1122:3344:5566:7788:99aa:bbcc:ddee:0"]) SET_V6(addr, 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) TEST(@"Converting an IPv6 to a string #6", [OFSocketAddressString(&addr) isEqual: @"1122:3344:5566:7788:99aa:bbcc::"]) SET_V6(addr, 0, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #7", [OFSocketAddressString(&addr) isEqual: @"0:3344:5566:7788:99aa:bbcc:ddee:ff00"]) SET_V6(addr, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #8", [OFSocketAddressString(&addr) isEqual: @"::5566:7788:99aa:bbcc:ddee:ff00"]) SET_V6(addr, 0, 0, 0x5566, 0, 0, 0, 0xDDEE, 0xFF00) TEST(@"Converting an IPv6 to a string #9", [OFSocketAddressString(&addr) isEqual: @"0:0:5566::ddee:ff00"]) SET_V6(addr, 0, 0, 0x5566, 0x7788, 0x99AA, 0xBBCC, 0, 0) TEST(@"Converting an IPv6 to a string #10", [OFSocketAddressString(&addr) isEqual: @"::5566:7788:99aa:bbcc:0:0"]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFStreamTests.m from [fdf2fcbee2] to [7f38bebd95].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | < | 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 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFStream"; @interface StreamTest: OFStream { int state; } @end @implementation StreamTest - (bool)lowlevelIsAtEndOfStream { return (state > 1); } - (size_t)lowlevelReadIntoBuffer: (void *)buffer length: (size_t)size { size_t pageSize = [OFSystemInfo pageSize]; switch (state) { case 0: if (size < 1) return 0; |
︙ | ︙ | |||
61 62 63 64 65 66 67 | @end @implementation TestsAppDelegate (OFStreamTests) - (void)streamTests { void *pool = objc_autoreleasePoolPush(); size_t pageSize = [OFSystemInfo pageSize]; | | | | | | | | | | | | 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | @end @implementation TestsAppDelegate (OFStreamTests) - (void)streamTests { void *pool = objc_autoreleasePoolPush(); size_t pageSize = [OFSystemInfo pageSize]; StreamTest *test = [[[StreamTest alloc] init] autorelease]; OFString *string; char *cString; cString = OFAllocMemory(pageSize - 2, 1); memset(cString, 'X', pageSize - 3); cString[pageSize - 3] = '\0'; TEST(@"-[readLine]", [[test readLine] isEqual: @"foo"] && (string = [test readLine]).length == pageSize - 3 && !strcmp(string.UTF8String, cString)) OFFreeMemory(cString); objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFStringTests.m from [72c5e8bd18] to [33be156318].
︙ | ︙ | |||
25 26 27 28 29 30 31 | #import "OFMutableUTF8String.h" #import "OFUTF8String.h" #ifndef INFINITY # define INFINITY __builtin_inf() #endif | | | | | | | | 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 "OFMutableUTF8String.h" #import "OFUTF8String.h" #ifndef INFINITY # define INFINITY __builtin_inf() #endif static OFString *module; static OFString *const whitespace[] = { @" \r \t\n\t \tasd \t \t\t\r\n", @" \t\t \t\t \t \t" }; static const OFUnichar unicharString[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0x1F03A, 0 }; static const OFUnichar swappedUnicharString[] = { 0xFFFE0000, 0x66000000, 0xF6000000, 0xF6000000, 0x62000000, 0xE4000000, 0x72000000, 0x3AF00100, 0 }; static const OFChar16 char16String[] = { 0xFEFF, 'f', 0xF6, 0xF6, 'b', 0xE4, 'r', 0xD83C, 0xDC3A, 0 }; static const OFChar16 swappedChar16String[] = { 0xFFFE, 0x6600, 0xF600, 0xF600, 0x6200, 0xE400, 0x7200, 0x3CD8, 0x3ADC, 0 }; @interface SimpleString: OFString { OFMutableString *_string; |
︙ | ︙ | |||
87 88 89 90 91 92 93 | @throw e; } return self; } - (instancetype)initWithCString: (const char *)cString | | | | | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | @throw e; } return self; } - (instancetype)initWithCString: (const char *)cString encoding: (OFStringEncoding)encoding length: (size_t)length { self = [super init]; @try { _string = [[OFMutableString alloc] initWithCString: cString encoding: encoding length: length]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF16String: (const OFChar16 *)UTF16String length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF16String: UTF16String length: length byteOrder: byteOrder]; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithUTF32String: (const OFChar32 *)UTF32String length: (size_t)length byteOrder: (OFByteOrder)byteOrder { self = [super init]; @try { _string = [[OFMutableString alloc] initWithUTF32String: UTF32String length: length |
︙ | ︙ | |||
165 166 167 168 169 170 171 | - (void)dealloc { [_string release]; [super dealloc]; } | | | | < | 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | - (void)dealloc { [_string release]; [super dealloc]; } - (OFUnichar)characterAtIndex: (size_t)idx { return [_string characterAtIndex: idx]; } - (size_t)length { return _string.length; } @end @implementation SimpleMutableString + (void)initialize { if (self == [SimpleMutableString class]) [self inheritMethodsFromClass: [SimpleString class]]; } - (void)replaceCharactersInRange: (OFRange)range withString: (OFString *)string { [_string replaceCharactersInRange: range withString: string]; } @end @interface EntityHandler: OFObject <OFStringXMLUnescapingDelegate> @end @implementation EntityHandler |
︙ | ︙ | |||
210 211 212 213 214 215 216 | @end @implementation TestsAppDelegate (OFStringTests) - (void)stringTestsWithClass: (Class)stringClass mutableClass: (Class)mutableStringClass { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | > | > > | | | | | | | > | | | | | > | | | | | | | | | | | | | | | | | > | > | | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | > | | | | | | | | | < < > | | | | | | < | | | | | | | | | | | | | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 | @end @implementation TestsAppDelegate (OFStringTests) - (void)stringTestsWithClass: (Class)stringClass mutableClass: (Class)mutableStringClass { void *pool = objc_autoreleasePoolPush(); OFMutableString *mutableString1, *mutableString2, *mutableString3; OFString *string; OFArray *array; size_t i; const OFUnichar *characters; const uint16_t *UTF16Characters; OFCharacterSet *characterSet; EntityHandler *entityHandler; #ifdef OF_HAVE_BLOCKS __block int j; __block bool ok; #endif #define C(s) ((OFString *)[stringClass stringWithString: s]) mutableString1 = [mutableStringClass stringWithString: @"täs€"]; mutableString2 = [mutableStringClass string]; mutableString3 = [[mutableString1 copy] autorelease]; TEST(@"-[isEqual:]", [mutableString1 isEqual: mutableString3] && ![mutableString1 isEqual: [[[OFObject alloc] init] autorelease]]) TEST(@"-[compare:]", [mutableString1 compare: mutableString3] == OFOrderedSame && [mutableString1 compare: @""] != OFOrderedSame && [C(@"") compare: @"a"] == OFOrderedAscending && [C(@"a") compare: @"b"] == OFOrderedAscending && [C(@"cd") compare: @"bc"] == OFOrderedDescending && [C(@"ä") compare: @"ö"] == OFOrderedAscending && [C(@"€") compare: @"ß"] == OFOrderedDescending && [C(@"aa") compare: @"z"] == OFOrderedAscending) #ifdef OF_HAVE_UNICODE_TABLES TEST(@"-[caseInsensitiveCompare:]", [C(@"a") caseInsensitiveCompare: @"A"] == OFOrderedSame && [C(@"Ä") caseInsensitiveCompare: @"ä"] == OFOrderedSame && [C(@"я") caseInsensitiveCompare: @"Я"] == OFOrderedSame && [C(@"€") caseInsensitiveCompare: @"ß"] == OFOrderedDescending && [C(@"ß") caseInsensitiveCompare: @"→"] == OFOrderedAscending && [C(@"AA") caseInsensitiveCompare: @"z"] == OFOrderedAscending && [[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare: [stringClass stringWithUTF8String: "AbD"]] == [C(@"abc") compare: @"abd"]) #else TEST(@"-[caseInsensitiveCompare:]", [C(@"a") caseInsensitiveCompare: @"A"] == OFOrderedSame && [C(@"AA") caseInsensitiveCompare: @"z"] == OFOrderedAscending && [[stringClass stringWithUTF8String: "ABC"] caseInsensitiveCompare: [stringClass stringWithUTF8String: "AbD"]] == [C(@"abc") compare: @"abd"]) #endif TEST(@"-[hash] is the same if -[isEqual:] is true", mutableString1.hash == mutableString3.hash) TEST(@"-[description]", [mutableString1.description isEqual: mutableString1]) TEST(@"-[appendString:] and -[appendUTF8String:]", R([mutableString2 appendUTF8String: "1𝄞"]) && R([mutableString2 appendString: @"3"]) && R([mutableString1 appendString: mutableString2]) && [mutableString1 isEqual: @"täs€1𝄞3"]) TEST(@"-[appendCharacters:length:]", R([mutableString2 appendCharacters: unicharString + 6 length: 2]) && [mutableString2 isEqual: @"1𝄞3r🀺"]) TEST(@"-[length]", mutableString1.length == 7) TEST(@"-[UTF8StringLength]", mutableString1.UTF8StringLength == 13) TEST(@"-[hash]", mutableString1.hash == 0x705583C0) TEST(@"-[characterAtIndex:]", [mutableString1 characterAtIndex: 0] == 't' && [mutableString1 characterAtIndex: 1] == 0xE4 && [mutableString1 characterAtIndex: 3] == 0x20AC && [mutableString1 characterAtIndex: 5] == 0x1D11E) EXPECT_EXCEPTION(@"Detect out of range in -[characterAtIndex:]", OFOutOfRangeException, [mutableString1 characterAtIndex: 7]) TEST(@"-[reverse]", R([mutableString1 reverse]) && [mutableString1 isEqual: @"3𝄞1€sät"]) mutableString2 = [mutableStringClass stringWithString: @"abc"]; #ifdef OF_HAVE_UNICODE_TABLES TEST(@"-[uppercase]", R([mutableString1 uppercase]) && [mutableString1 isEqual: @"3𝄞1€SÄT"] && R([mutableString2 uppercase]) && [mutableString2 isEqual: @"ABC"]) TEST(@"-[lowercase]", R([mutableString1 lowercase]) && [mutableString1 isEqual: @"3𝄞1€sät"] && R([mutableString2 lowercase]) && [mutableString2 isEqual: @"abc"]) TEST(@"-[uppercaseString]", [[mutableString1 uppercaseString] isEqual: @"3𝄞1€SÄT"]) TEST(@"-[lowercaseString]", R([mutableString1 uppercase]) && [[mutableString1 lowercaseString] isEqual: @"3𝄞1€sät"]) TEST(@"-[capitalizedString]", [C(@"džbla tdžst TDŽST").capitalizedString isEqual: @"Džbla Tdžst Tdžst"]) #else TEST(@"-[uppercase]", R([mutableString1 uppercase]) && [mutableString1 isEqual: @"3𝄞1€SäT"] && R([mutableString2 uppercase]) && [mutableString2 isEqual: @"ABC"]) TEST(@"-[lowercase]", R([mutableString1 lowercase]) && [mutableString1 isEqual: @"3𝄞1€sät"] && R([mutableString2 lowercase]) && [mutableString2 isEqual: @"abc"]) TEST(@"-[uppercaseString]", [mutableString1.uppercaseString isEqual: @"3𝄞1€SäT"]) TEST(@"-[lowercaseString]", R([mutableString1 uppercase]) && [mutableString1.lowercaseString isEqual: @"3𝄞1€sät"]) TEST(@"-[capitalizedString]", [C(@"džbla tdžst TDŽST").capitalizedString isEqual: @"džbla Tdžst TDŽst"]) #endif TEST(@"+[stringWithUTF8String:length:]", (mutableString1 = [mutableStringClass stringWithUTF8String: "\xEF\xBB\xBF" "foobar" length: 6]) && [mutableString1 isEqual: @"foo"]) TEST(@"+[stringWithUTF16String:]", (string = [stringClass stringWithUTF16String: char16String]) && [string isEqual: @"fööbär🀺"] && (string = [stringClass stringWithUTF16String: swappedChar16String]) && [string isEqual: @"fööbär🀺"]) TEST(@"+[stringWithUTF32String:]", (string = [stringClass stringWithUTF32String: unicharString]) && [string isEqual: @"fööbär🀺"] && (string = [stringClass stringWithUTF32String: swappedUnicharString]) && [string isEqual: @"fööbär🀺"]) #ifdef OF_HAVE_FILES TEST(@"+[stringWithContentsOfFile:encoding]", (string = [stringClass stringWithContentsOfFile: @"testfile.txt" encoding: OFStringEncodingISO8859_1]) && [string isEqual: @"testäöü"]) TEST(@"+[stringWithContentsOfURL:encoding]", (string = [stringClass stringWithContentsOfURL: [OFURL fileURLWithPath: @"testfile.txt"] encoding: OFStringEncodingISO8859_1]) && [string isEqual: @"testäöü"]) #endif TEST(@"-[appendUTFString:length:]", R([mutableString1 appendUTF8String: "\xEF\xBB\xBF" "barqux" length: 6]) && [mutableString1 isEqual: @"foobar"]) EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #1", OFInvalidEncodingException, [stringClass stringWithUTF8String: "\xE0\x80"]) EXPECT_EXCEPTION(@"Detection of invalid UTF-8 encoding #2", OFInvalidEncodingException, [stringClass stringWithUTF8String: "\xF0\x80\x80\xC0"]) TEST(@"Conversion of ISO 8859-1 to Unicode", [[stringClass stringWithCString: "\xE4\xF6\xFC" encoding: OFStringEncodingISO8859_1] isEqual: @"äöü"]) #ifdef HAVE_ISO_8859_15 TEST(@"Conversion of ISO 8859-15 to Unicode", [[stringClass stringWithCString: "\xA4\xA6\xA8\xB4\xB8\xBC\xBD\xBE" encoding: OFStringEncodingISO8859_15] isEqual: @"€ŠšŽžŒœŸ"]) #endif #ifdef HAVE_WINDOWS_1252 TEST(@"Conversion of Windows 1252 to Unicode", [[stringClass stringWithCString: "\x80\x82\x83\x84\x85\x86\x87\x88" "\x89\x8A\x8B\x8C\x8E\x91\x92\x93" "\x94\x95\x96\x97\x98\x99\x9A\x9B" "\x9C\x9E\x9F" encoding: OFStringEncodingWindows1252] isEqual: @"€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ"]) #endif #ifdef HAVE_CODEPAGE_437 TEST(@"Conversion of Codepage 437 to Unicode", [[stringClass stringWithCString: "\xB0\xB1\xB2\xDB" encoding: OFStringEncodingCodepage437] isEqual: @"░▒▓█"]) #endif TEST(@"Conversion of Unicode to ASCII #1", !strcmp([C(@"This is a test") cStringWithEncoding: OFStringEncodingASCII], "This is a test")) EXPECT_EXCEPTION(@"Conversion of Unicode to ASCII #2", OFInvalidEncodingException, [C(@"This is a tést") cStringWithEncoding: OFStringEncodingASCII]) TEST(@"Conversion of Unicode to ISO-8859-1 #1", !strcmp([C(@"This is ä test") cStringWithEncoding: OFStringEncodingISO8859_1], "This is \xE4 test")) EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-1 #2", OFInvalidEncodingException, [C(@"This is ä t€st") cStringWithEncoding: OFStringEncodingISO8859_1]) #ifdef HAVE_ISO_8859_15 TEST(@"Conversion of Unicode to ISO-8859-15 #1", !strcmp([C(@"This is ä t€st") cStringWithEncoding: OFStringEncodingISO8859_15], "This is \xE4 t\xA4st")) EXPECT_EXCEPTION(@"Conversion of Unicode to ISO-8859-15 #2", OFInvalidEncodingException, [C(@"This is ä t€st…") cStringWithEncoding: OFStringEncodingISO8859_15]) #endif #ifdef HAVE_WINDOWS_1252 TEST(@"Conversion of Unicode to Windows-1252 #1", !strcmp([C(@"This is ä t€st…") cStringWithEncoding: OFStringEncodingWindows1252], "This is \xE4 t\x80st\x85")) EXPECT_EXCEPTION(@"Conversion of Unicode to Windows-1252 #2", OFInvalidEncodingException, [C(@"This is ä t€st…‼") cStringWithEncoding: OFStringEncodingWindows1252]) #endif #ifdef HAVE_CODEPAGE_437 TEST(@"Conversion of Unicode to Codepage 437 #1", !strcmp([C(@"Tést strîng ░▒▓") cStringWithEncoding: OFStringEncodingCodepage437], "T\x82st str\x8Cng \xB0\xB1\xB2")) EXPECT_EXCEPTION(@"Conversion of Unicode to Codepage 437 #2", OFInvalidEncodingException, [C(@"T€st strîng ░▒▓") cStringWithEncoding: OFStringEncodingCodepage437]) #endif TEST(@"Lossy conversion of Unicode to ASCII", !strcmp([C(@"This is a tést") lossyCStringWithEncoding: OFStringEncodingASCII], "This is a t?st")) TEST(@"Lossy conversion of Unicode to ISO-8859-1", !strcmp([C(@"This is ä t€st") lossyCStringWithEncoding: OFStringEncodingISO8859_1], "This is \xE4 t?st")) #ifdef HAVE_ISO_8859_15 TEST(@"Lossy conversion of Unicode to ISO-8859-15", !strcmp([C(@"This is ä t€st…") lossyCStringWithEncoding: OFStringEncodingISO8859_15], "This is \xE4 t\xA4st?")) #endif #ifdef HAVE_WINDOWS_1252 TEST(@"Lossy conversion of Unicode to Windows-1252", !strcmp([C(@"This is ä t€st…‼") lossyCStringWithEncoding: OFStringEncodingWindows1252], "This is \xE4 t\x80st\x85?")) #endif #ifdef HAVE_CODEPAGE_437 TEST(@"Lossy conversion of Unicode to Codepage 437", !strcmp([C(@"T€st strîng ░▒▓") lossyCStringWithEncoding: OFStringEncodingCodepage437], "T?st str\x8Cng \xB0\xB1\xB2")) #endif TEST(@"+[stringWithFormat:]", [(mutableString1 = [mutableStringClass stringWithFormat: @"%@:%d", @"test", 123]) isEqual: @"test:123"]) TEST(@"-[appendFormat:]", R(([mutableString1 appendFormat: @"%02X", 15])) && [mutableString1 isEqual: @"test:1230F"]) TEST(@"-[rangeOfString:]", [C(@"𝄞öö") rangeOfString: @"öö"].location == 1 && [C(@"𝄞öö") rangeOfString: @"ö"].location == 1 && [C(@"𝄞öö") rangeOfString: @"𝄞"].location == 0 && [C(@"𝄞öö") rangeOfString: @"x"].location == OFNotFound && [C(@"𝄞öö") rangeOfString: @"öö" options: OFStringSearchBackwards].location == 1 && [C(@"𝄞öö") rangeOfString: @"ö" options: OFStringSearchBackwards].location == 2 && [C(@"𝄞öö") rangeOfString: @"𝄞" options: OFStringSearchBackwards].location == 0 && [C(@"𝄞öö") rangeOfString: @"x" options: OFStringSearchBackwards].location == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[rangeOfString:options:range:]", OFOutOfRangeException, [C(@"𝄞öö") rangeOfString: @"ö" options: 0 range: OFRangeMake(3, 1)]) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"cđ"]; TEST(@"-[indexOfCharacterFromSet:]", [C(@"abcđabcđe") indexOfCharacterFromSet: characterSet] == 2 && [C(@"abcđabcđë") indexOfCharacterFromSet: characterSet options: OFStringSearchBackwards] == 7 && [C(@"abcđabcđë") indexOfCharacterFromSet: characterSet options: 0 range: OFRangeMake(4, 4)] == 6 && [C(@"abcđabcđëf") indexOfCharacterFromSet: characterSet options: 0 range: OFRangeMake(8, 2)] == OFNotFound) EXPECT_EXCEPTION( @"Detect out of range in -[indexOfCharacterFromSet:options:range:]", OFOutOfRangeException, [C(@"𝄞öö") indexOfCharacterFromSet: characterSet options: 0 range: OFRangeMake(3, 1)]) TEST(@"-[substringWithRange:]", [[C(@"𝄞öö") substringWithRange: OFRangeMake(1, 1)] isEqual: @"ö"] && [[C(@"𝄞öö") substringWithRange: OFRangeMake(3, 0)] isEqual: @""]) EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #1", OFOutOfRangeException, [C(@"𝄞öö") substringWithRange: OFRangeMake(2, 2)]) EXPECT_EXCEPTION(@"Detect out of range in -[substringWithRange:] #2", OFOutOfRangeException, [C(@"𝄞öö") substringWithRange: OFRangeMake(4, 0)]) TEST(@"-[stringByAppendingString:]", [[C(@"foo") stringByAppendingString: @"bar"] isEqual: @"foobar"]) TEST(@"-[stringByPrependingString:]", [[C(@"foo") stringByPrependingString: @"bar"] isEqual: @"barfoo"]) |
︙ | ︙ | |||
563 564 565 566 567 568 569 | !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # else TEST(@"-[isAbsolutePath]", C(@"/foo").absolutePath && C(@"/foo/bar").absolutePath && !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # endif | | | | | | | | | | | > | > | | | | | | | | | | | | | | | | | > | | | | | | | | | | | | | | | | | | | | | | | 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # else TEST(@"-[isAbsolutePath]", C(@"/foo").absolutePath && C(@"/foo/bar").absolutePath && !C(@"foo/bar").absolutePath && !C(@"foo").absolutePath) # endif mutableString1 = [mutableStringClass stringWithString: @"foo"]; # if defined(OF_WINDOWS) || defined(OF_MSDOS) [mutableString1 appendString: @"\\"]; # else [mutableString1 appendString: @"/"]; # endif [mutableString1 appendString: @"bar"]; mutableString2 = [mutableStringClass stringWithString: mutableString1]; # if defined(OF_WINDOWS) || defined(OF_MSDOS) [mutableString2 appendString: @"\\"]; # else [mutableString2 appendString: @"/"]; # endif string = [stringClass stringWithString: mutableString2]; [mutableString2 appendString: @"baz"]; TEST(@"-[stringByAppendingPathComponent:]", [[mutableString1 stringByAppendingPathComponent: @"baz"] isEqual: mutableString2] && [[string stringByAppendingPathComponent: @"baz"] isEqual: mutableString2]) #endif TEST(@"-[hasPrefix:]", [C(@"foobar") hasPrefix: @"foo"] && ![C(@"foobar") hasPrefix: @"foobar0"]) TEST(@"-[hasSuffix:]", [C(@"foobar") hasSuffix: @"bar"] && ![C(@"foobar") hasSuffix: @"foobar0"]) i = 0; TEST(@"-[componentsSeparatedByString:]", (array = [C(@"fooXXbarXXXXbazXXXX") componentsSeparatedByString: @"XX"]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"baz"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && array.count == i && (array = [C(@"foo") componentsSeparatedByString: @""]) && [[array objectAtIndex: 0] isEqual: @"foo"] && array.count == 1) i = 0; TEST(@"-[componentsSeparatedByString:options:]", (array = [C(@"fooXXbarXXXXbazXXXX") componentsSeparatedByString: @"XX" options: OFStringSkipEmptyComponents]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @"baz"] && array.count == i) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"XYZ"]; i = 0; TEST(@"-[componentsSeparatedByCharactersInSet:]", (array = [C(@"fooXYbarXYZXbazXYXZx") componentsSeparatedByCharactersInSet: characterSet]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"baz"] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @""] && [[array objectAtIndex: i++] isEqual: @"x"] && array.count == i) i = 0; TEST(@"-[componentsSeparatedByCharactersInSet:options:]", (array = [C(@"fooXYbarXYZXbazXYXZ") componentsSeparatedByCharactersInSet: characterSet options: OFStringSkipEmptyComponents]) && [[array objectAtIndex: i++] isEqual: @"foo"] && [[array objectAtIndex: i++] isEqual: @"bar"] && [[array objectAtIndex: i++] isEqual: @"baz"] && array.count == i) #ifdef OF_HAVE_FILES # if defined(OF_WINDOWS) TEST(@"+[pathWithComponents:]", [[stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil]] isEqual: @"foo\\bar\\baz"] && [[stringClass pathWithComponents: [OFArray arrayWithObjects: |
︙ | ︙ | |||
746 747 748 749 750 751 752 | [[stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", nil]] isEqual: @"foo"]) # endif # if defined(OF_WINDOWS) TEST(@"-[pathComponents]", /* c:/tmp */ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | [[stringClass pathWithComponents: [OFArray arrayWithObjects: @"foo", nil]] isEqual: @"foo"]) # endif # if defined(OF_WINDOWS) TEST(@"-[pathComponents]", /* c:/tmp */ (array = C(@"c:/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\tmp\ */ (array = C(@"c:\\tmp\\").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\ */ (array = C(@"c:\\").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && /* c:/ */ (array = C(@"c:/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:/"] && /* c: */ (array = C(@"c:").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:"] && /* foo\bar */ (array = C(@"foo\\bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo\bar/baz/ */ (array = C(@"foo\\bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo\/ */ (array = C(@"foo\\/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && /* \\foo\bar */ (array = C(@"\\\\foo\\bar").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"\\\\"] && [[array objectAtIndex: 1] isEqual: @"foo"] && [[array objectAtIndex: 2] isEqual: @"bar"] && C(@"").pathComponents.count == 0) # elif defined(OF_MSDOS) TEST(@"-[pathComponents]", /* c:/tmp */ (array = C(@"c:/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\tmp\ */ (array = C(@"c:\\tmp\\").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* c:\ */ (array = C(@"c:\\").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:\\"] && /* c:/ */ (array = C(@"c:/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:/"] && /* c: */ (array = C(@"c:").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"c:"] && /* foo\bar */ (array = C(@"foo\\bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo\bar/baz/ */ (array = C(@"foo\\bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo\/ */ (array = C(@"foo\\/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && C(@"").pathComponents.count == 0) # elif defined(OF_AMIGAOS) TEST(@"-[pathComponents]", /* dh0:tmp */ (array = C(@"dh0:tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"dh0:"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* dh0:tmp/ */ (array = C(@"dh0:tmp/").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"dh0:"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* dh0: */ (array = C(@"dh0:/").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"dh0:"] && [[array objectAtIndex: 1] isEqual: @"/"] && /* foo/bar */ (array = C(@"foo/bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo/bar/baz/ */ (array = C(@"foo/bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo// */ (array = C(@"foo//").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"/"] && C(@"").pathComponents.count == 0) # elif defined(OF_NINTENDO_3DS) || defined(OF_WII) TEST(@"-[pathComponents]", /* sdmc:/tmp */ (array = C(@"sdmc:/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"sdmc:"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* sdmc:/ */ (array = C(@"sdmc:/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"sdmc:"] && /* foo/bar */ (array = C(@"foo/bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo/bar/baz/ */ (array = C(@"foo/bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo// */ (array = C(@"foo//").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && C(@"").pathComponents.count == 0) # else TEST(@"-[pathComponents]", /* /tmp */ (array = C(@"/tmp").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* /tmp/ */ (array = C(@"/tmp/").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"/"] && [[array objectAtIndex: 1] isEqual: @"tmp"] && /* / */ (array = C(@"/").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"/"] && /* foo/bar */ (array = C(@"foo/bar").pathComponents) && array.count == 2 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && /* foo/bar/baz/ */ (array = C(@"foo/bar/baz/").pathComponents) && array.count == 3 && [[array objectAtIndex: 0] isEqual: @"foo"] && [[array objectAtIndex: 1] isEqual: @"bar"] && [[array objectAtIndex: 2] isEqual: @"baz"] && /* foo// */ (array = C(@"foo//").pathComponents) && array.count == 1 && [[array objectAtIndex: 0] isEqual: @"foo"] && C(@"").pathComponents.count == 0) # endif # if defined(OF_WINDOWS) TEST(@"-[lastPathComponent]", [C(@"c:/tmp").lastPathComponent isEqual: @"tmp"] && [C(@"c:\\tmp\\").lastPathComponent isEqual: @"tmp"] && |
︙ | ︙ | |||
1183 1184 1185 1186 1187 1188 1189 | EXPECT_EXCEPTION(@"Detect out of range in -[unsignedLongLongValue]", OFOutOfRangeException, [C(@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF") unsignedLongLongValueWithBase: 16]) | | | | | | > | | | | > | > | | | | > | | > | | | < | > | | | | | | | | | > > | | > | | < | > | | < | | < | | < | | < | > | | | | | > | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | > | | | > | | > > | | | > | | > > | | > > | | > | | | | 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 | EXPECT_EXCEPTION(@"Detect out of range in -[unsignedLongLongValue]", OFOutOfRangeException, [C(@"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF" @"0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF") unsignedLongLongValueWithBase: 16]) TEST(@"-[characters]", (characters = C(@"fööbär🀺").characters) && !memcmp(characters, unicharString + 1, sizeof(unicharString) - 8)) #ifdef OF_BIG_ENDIAN # define swappedByteOrder OFByteOrderLittleEndian #else # define swappedByteOrder OFByteOrderBigEndian #endif TEST(@"-[UTF16String]", (UTF16Characters = C(@"fööbär🀺").UTF16String) && !memcmp(UTF16Characters, char16String + 1, OFUTF16StringLength(char16String) * 2) && (UTF16Characters = [C(@"fööbär🀺") UTF16StringWithByteOrder: swappedByteOrder]) && !memcmp(UTF16Characters, swappedChar16String + 1, OFUTF16StringLength(swappedChar16String) * 2)) TEST(@"-[UTF16StringLength]", C(@"fööbär🀺").UTF16StringLength == 8) TEST(@"-[UTF32String]", (characters = C(@"fööbär🀺").UTF32String) && !memcmp(characters, unicharString + 1, OFUTF32StringLength(unicharString) * 4) && (characters = [C(@"fööbär🀺") UTF32StringWithByteOrder: swappedByteOrder]) && !memcmp(characters, swappedUnicharString + 1, OFUTF32StringLength(swappedUnicharString) * 4)) #undef swappedByteOrder TEST(@"-[stringByMD5Hashing]", [C(@"asdfoobar").stringByMD5Hashing isEqual: @"184dce2ec49b5422c7cfd8728864db4c"]) TEST(@"-[stringByRIPEMD160Hashing]", [C(@"asdfoobar").stringByRIPEMD160Hashing isEqual: @"021d773b0fac06eb6755ca6aa58a580c980f7f13"]) TEST(@"-[stringBySHA1Hashing]", [C(@"asdfoobar").stringBySHA1Hashing isEqual: @"f5f81ac0a8b5cbfdc4585ec1ad32e7b3a12b9b49"]) TEST(@"-[stringBySHA224Hashing]", [C(@"asdfoobar").stringBySHA224Hashing isEqual: @"5a06822dcbd5a874f67d062b80b9d8a9cb9b5b303960b9da9290c192" ]) TEST(@"-[stringBySHA256Hashing]", [C(@"asdfoobar").stringBySHA256Hashing isEqual: @"28e65b1dcd7f6ce2ea6277b15f87b913628b5500bf7913a2bbf4cedc" @"fa1215f6"]) TEST(@"-[stringBySHA384Hashing]", [C(@"asdfoobar").stringBySHA384Hashing isEqual: @"73286da882ffddca2f45e005cfa6b44f3fc65bfb26db1d087ded2f9c" @"279e5addf8be854044bca0cece073fce28eec7d9"]) TEST(@"-[stringBySHA512Hashing]", [C(@"asdfoobar").stringBySHA512Hashing isEqual: @"0464c427da158b02161bb44a3090bbfc594611ef6a53603640454b56" @"412a9247c3579a329e53a5dc74676b106755e3394f9454a2d4227324" @"2615d32f80437d61"]) characterSet = [OFCharacterSet characterSetWithCharactersInString: @"abfo'_~$🍏"]; TEST(@"-[stringByURLEncodingWithAllowedCharacters:]", [[C(@"foo\"ba'_~$]🍏🍌") stringByURLEncodingWithAllowedCharacters: characterSet] isEqual: @"foo%22ba'_~$%5D🍏%F0%9F%8D%8C"]) TEST(@"-[stringByURLDecoding]", [C(@"foo%20bar%22+%24%F0%9F%8D%8C").stringByURLDecoding isEqual: @"foo bar\"+$🍌"]) TEST(@"-[insertString:atIndex:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 insertString: @"äöü" atIndex: 3]) && [mutableString1 isEqual: @"𝄞ööäöüöbä€"]) EXPECT_EXCEPTION(@"Detect invalid format in -[stringByURLDecoding] " @"#1", OFInvalidFormatException, [C(@"foo%xbar") stringByURLDecoding]) EXPECT_EXCEPTION(@"Detect invalid encoding in -[stringByURLDecoding] " @"#2", OFInvalidEncodingException, [C(@"foo%FFbar") stringByURLDecoding]) TEST(@"-[setCharacter:atIndex:]", (mutableString1 = [mutableStringClass stringWithString: @"abäde"]) && R([mutableString1 setCharacter: 0xF6 atIndex: 2]) && [mutableString1 isEqual: @"aböde"] && R([mutableString1 setCharacter: 'c' atIndex: 2]) && [mutableString1 isEqual: @"abcde"] && R([mutableString1 setCharacter: 0x20AC atIndex: 3]) && [mutableString1 isEqual: @"abc€e"] && R([mutableString1 setCharacter: 'x' atIndex: 1]) && [mutableString1 isEqual: @"axc€e"]) TEST(@"-[deleteCharactersInRange:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 deleteCharactersInRange: OFRangeMake(1, 3)]) && [mutableString1 isEqual: @"𝄞bä€"] && R([mutableString1 deleteCharactersInRange: OFRangeMake(0, 4)]) && [mutableString1 isEqual: @""]) TEST(@"-[replaceCharactersInRange:withString:]", (mutableString1 = [mutableStringClass stringWithString: @"𝄞öööbä€"]) && R([mutableString1 replaceCharactersInRange: OFRangeMake(1, 3) withString: @"äöüß"]) && [mutableString1 isEqual: @"𝄞äöüßbä€"] && R([mutableString1 replaceCharactersInRange: OFRangeMake(4, 2) withString: @"b"]) && [mutableString1 isEqual: @"𝄞äöübä€"] && R([mutableString1 replaceCharactersInRange: OFRangeMake(0, 7) withString: @""]) && [mutableString1 isEqual: @""]) EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #1", OFOutOfRangeException, { mutableString1 = [mutableStringClass stringWithString: @"𝄞öö"]; [mutableString1 deleteCharactersInRange: OFRangeMake(2, 2)]; }) EXPECT_EXCEPTION(@"Detect OoR in -[deleteCharactersInRange:] #2", OFOutOfRangeException, [mutableString1 deleteCharactersInRange: OFRangeMake(4, 0)]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[replaceCharactersInRange:withString:] #1", OFOutOfRangeException, [mutableString1 replaceCharactersInRange: OFRangeMake(2, 2) withString: @""]) EXPECT_EXCEPTION(@"Detect OoR in " @"-[replaceCharactersInRange:withString:] #2", OFOutOfRangeException, [mutableString1 replaceCharactersInRange: OFRangeMake(4, 0) withString: @""]) TEST(@"-[replaceOccurrencesOfString:withString:]", (mutableString1 = [mutableStringClass stringWithString: @"asd fo asd fofo asd"]) && R([mutableString1 replaceOccurrencesOfString: @"fo" withString: @"foo"]) && [mutableString1 isEqual: @"asd foo asd foofoo asd"] && (mutableString1 = [mutableStringClass stringWithString: @"XX"]) && R([mutableString1 replaceOccurrencesOfString: @"X" withString: @"XX"]) && [mutableString1 isEqual: @"XXXX"]) TEST(@"-[replaceOccurrencesOfString:withString:options:range:]", (mutableString1 = [mutableStringClass stringWithString: @"foofoobarfoobarfoo"]) && R([mutableString1 replaceOccurrencesOfString: @"oo" withString: @"óò" options: 0 range: OFRangeMake(2, 15)]) && [mutableString1 isEqual: @"foofóòbarfóòbarfoo"]) TEST(@"-[deleteLeadingWhitespaces]", (mutableString1 = [mutableStringClass stringWithString: whitespace[0]]) && R([mutableString1 deleteLeadingWhitespaces]) && [mutableString1 isEqual: @"asd \t \t\t\r\n"] && (mutableString1 = [mutableStringClass stringWithString: whitespace[1]]) && R([mutableString1 deleteLeadingWhitespaces]) && [mutableString1 isEqual: @""]) TEST(@"-[deleteTrailingWhitespaces]", (mutableString1 = [mutableStringClass stringWithString: whitespace[0]]) && R([mutableString1 deleteTrailingWhitespaces]) && [mutableString1 isEqual: @" \r \t\n\t \tasd"] && (mutableString1 = [mutableStringClass stringWithString: whitespace[1]]) && R([mutableString1 deleteTrailingWhitespaces]) && [mutableString1 isEqual: @""]) TEST(@"-[deleteEnclosingWhitespaces]", (mutableString1 = [mutableStringClass stringWithString: whitespace[0]]) && R([mutableString1 deleteEnclosingWhitespaces]) && [mutableString1 isEqual: @"asd"] && (mutableString1 = [mutableStringClass stringWithString: whitespace[1]]) && R([mutableString1 deleteEnclosingWhitespaces]) && [mutableString1 isEqual: @""]) #ifdef OF_HAVE_UNICODE_TABLES TEST(@"-[decomposedStringWithCanonicalMapping]", [C(@"H\xC3\xA4llj\xC3\xB6").decomposedStringWithCanonicalMapping isEqual: @"H\x61\xCC\x88llj\x6F\xCC\x88"]); TEST(@"-[decomposedStringWithCompatibilityMapping]", [C(@"H\xC3\xA4llj\xC3\xB6").decomposedStringWithCompatibilityMapping isEqual: @"H\x61\xCC\x88llj\x6F\xCC\x88"]); #endif TEST(@"-[stringByXMLEscaping]", (string = C(@"<hello> &world'\"!&").stringByXMLEscaping) && [string isEqual: @"<hello> &world'"!&"]) TEST(@"-[stringByXMLUnescaping]", [string.stringByXMLUnescaping isEqual: @"<hello> &world'\"!&"] && [C(@"y").stringByXMLUnescaping isEqual: @"y"] && [C(@"ä").stringByXMLUnescaping isEqual: @"ä"] && [C(@"€").stringByXMLUnescaping isEqual: @"€"] && [C(@"𝄞").stringByXMLUnescaping isEqual: @"𝄞"]) EXPECT_EXCEPTION(@"Detect unknown entities in -[stringByXMLUnescaping]", OFUnknownXMLEntityException, [C(@"&foo;") stringByXMLUnescaping]) |
︙ | ︙ | |||
1387 1388 1389 1390 1391 1392 1393 | EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#4", OFInvalidFormatException, [C(@"&#g;") stringByXMLUnescaping]) EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#5", OFInvalidFormatException, [C(@"&#xg;") stringByXMLUnescaping]) TEST(@"-[stringByXMLUnescapingWithDelegate:]", | | | | | 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 | EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#4", OFInvalidFormatException, [C(@"&#g;") stringByXMLUnescaping]) EXPECT_EXCEPTION(@"Detect invalid entities in -[stringByXMLUnescaping] " @"#5", OFInvalidFormatException, [C(@"&#xg;") stringByXMLUnescaping]) TEST(@"-[stringByXMLUnescapingWithDelegate:]", (entityHandler = [[[EntityHandler alloc] init] autorelease]) && [[C(@"x&foo;y") stringByXMLUnescapingWithDelegate: entityHandler] isEqual: @"xbary"]) #ifdef OF_HAVE_BLOCKS TEST(@"-[stringByXMLUnescapingWithBlock:]", [[C(@"x&foo;y") stringByXMLUnescapingWithBlock: ^ OFString *(OFString *str, OFString *entity) { if ([entity isEqual: @"foo"]) return @"bar"; return nil; }] isEqual: @"xbary"]) j = 0; |
︙ | ︙ |
Modified tests/OFSystemInfoTests.m from [c560db3946] to [23b6100c57].
︙ | ︙ | |||
21 22 23 24 25 26 27 | - (void)systemInfoTests { void *pool = objc_autoreleasePoolPush(); #ifdef OF_HAVE_FILES OFString *userConfigPath, *userDataPath; #endif | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | - (void)systemInfoTests { void *pool = objc_autoreleasePoolPush(); #ifdef OF_HAVE_FILES OFString *userConfigPath, *userDataPath; #endif [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut writeFormat: @"[OFSystemInfo] Page size: %zd\n", [OFSystemInfo pageSize]]; [OFStdOut writeFormat: @"[OFSystemInfo] Number of CPUs: %zd\n", [OFSystemInfo numberOfCPUs]]; [OFStdOut writeFormat: @"[OFSystemInfo] ObjFW version: %@\n", [OFSystemInfo ObjFWVersion]]; [OFStdOut writeFormat: @"[OFSystemInfo] ObjFW version major: %u\n", [OFSystemInfo ObjFWVersionMajor]]; [OFStdOut writeFormat: @"[OFSystemInfo] ObjFW version minor: %u\n", [OFSystemInfo ObjFWVersionMinor]]; [OFStdOut writeFormat: @"[OFSystemInfo] Operating system name: %@\n", [OFSystemInfo operatingSystemName]]; [OFStdOut writeFormat: @"[OFSystemInfo] Operating system version: %@\n", [OFSystemInfo operatingSystemVersion]]; #ifdef OF_HAVE_FILES @try { userConfigPath = [OFSystemInfo userConfigPath]; } @catch (OFNotImplementedException *e) { userConfigPath = @"Not implemented"; } [OFStdOut writeFormat: @"[OFSystemInfo] User config path: %@\n", userConfigPath]; @try { userDataPath = [OFSystemInfo userDataPath]; } @catch (OFNotImplementedException *e) { userDataPath = @"Not implemented"; } [OFStdOut writeFormat: @"[OFSystemInfo] User data path: %@\n", userDataPath]; #endif [OFStdOut writeFormat: @"[OFSystemInfo] CPU vendor: %@\n", [OFSystemInfo CPUVendor]]; [OFStdOut writeFormat: @"[OFSystemInfo] CPU model: %@\n", [OFSystemInfo CPUModel]]; #if defined(OF_X86_64) || defined(OF_X86) [OFStdOut writeFormat: @"[OFSystemInfo] Supports MMX: %d\n", [OFSystemInfo supportsMMX]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE: %d\n", [OFSystemInfo supportsSSE]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE2: %d\n", [OFSystemInfo supportsSSE2]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE3: %d\n", [OFSystemInfo supportsSSE3]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports SSSE3: %d\n", [OFSystemInfo supportsSSSE3]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE4.1: %d\n", [OFSystemInfo supportsSSE41]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports SSE4.2: %d\n", [OFSystemInfo supportsSSE42]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports AVX: %d\n", [OFSystemInfo supportsAVX]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports AVX2: %d\n", [OFSystemInfo supportsAVX2]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports AES-NI: %d\n", [OFSystemInfo supportsAESNI]]; [OFStdOut writeFormat: @"[OFSystemInfo] Supports SHA extensions: %d\n", [OFSystemInfo supportsSHAExtensions]]; #endif #ifdef OF_POWERPC [OFStdOut writeFormat: @"[OFSystemInfo] Supports AltiVec: %d\n", [OFSystemInfo supportsAltiVec]]; #endif objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFTCPSocketTests.m from [9caf5227b3] to [e9219b696c].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | < | < | | | | | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFTCPSocket"; @implementation TestsAppDelegate (OFTCPSocketTests) - (void)TCPSocketTests { void *pool = objc_autoreleasePoolPush(); OFTCPSocket *server, *client = nil, *accepted; uint16_t port; char buffer[6]; TEST(@"+[socket]", (server = [OFTCPSocket socket]) && (client = [OFTCPSocket socket])) TEST(@"-[bindToHost:port:]", (port = [server bindToHost: @"127.0.0.1" port: 0])) TEST(@"-[listen]", R([server listen])) TEST(@"-[connectToHost:port:]", R([client connectToHost: @"127.0.0.1" port: port])) TEST(@"-[accept]", (accepted = [server accept])) TEST(@"-[remoteAddress]", [OFSocketAddressString(accepted.remoteAddress) isEqual: @"127.0.0.1"]) TEST(@"-[writeString:]", [client writeString: @"Hello!"]) TEST(@"-[readIntoBuffer:length:]", [accepted readIntoBuffer: buffer length: 6] && !memcmp(buffer, "Hello!", 6)) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFThreadTests.m from [7689fdb7c9] to [6e125a20af].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | > | | < | | | | | | 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 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFThread"; @interface TestThread: OFThread @end @implementation TestThread - (id)main { [[OFThread threadDictionary] setObject: @"bar" forKey: @"foo"]; OFEnsure([[[OFThread threadDictionary] objectForKey: @"foo"] isEqual: @"bar"]); return @"success"; } @end @implementation TestsAppDelegate (OFThreadTests) - (void)threadTests { void *pool = objc_autoreleasePoolPush(); TestThread *thread; TEST(@"+[thread]", (thread = [TestThread thread])) TEST(@"-[start]", R([thread start])) TEST(@"-[join]", [[thread join] isEqual: @"success"]) TEST(@"-[threadDictionary]", [[OFThread threadDictionary] objectForKey: @"foo"] == nil) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFUDPSocketTests.m from [874d662a72] to [6d7b4e4936].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | < | < | | < < | < < < | > | | | | | | | | 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 61 62 63 64 65 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFUDPSocket"; @implementation TestsAppDelegate (OFUDPSocketTests) - (void)UDPSocketTests { void *pool = objc_autoreleasePoolPush(); OFUDPSocket *sock; uint16_t port1; OFSocketAddress addr1, addr2, addr3; char buf[6]; TEST(@"+[socket]", (sock = [OFUDPSocket socket])) TEST(@"-[bindToHost:port:]", (port1 = [sock bindToHost: @"127.0.0.1" port: 0])) addr1 = OFSocketAddressParseIP(@"127.0.0.1", port1); TEST(@"-[sendBuffer:length:receiver:]", R([sock sendBuffer: "Hello" length: 6 receiver: &addr1])) TEST(@"-[receiveIntoBuffer:length:sender:]", [sock receiveIntoBuffer: buf length: 6 sender: &addr2] == 6 && !memcmp(buf, "Hello", 6) && [OFSocketAddressString(&addr2) isEqual: @"127.0.0.1"] && OFSocketAddressPort(&addr2) == port1) addr3 = OFSocketAddressParseIP(@"127.0.0.1", port1 + 1); /* * TODO: Move those tests elsewhere as soon as the DNS resolving part * is no longer in OFUDPSocket. */ TEST(@"OFSocketAddressEqual()", OFSocketAddressEqual(&addr1, &addr2) && !OFSocketAddressEqual(&addr1, &addr3)) TEST(@"OFSocketAddressHash()", OFSocketAddressHash(&addr1) == OFSocketAddressHash(&addr2) && OFSocketAddressHash(&addr1) != OFSocketAddressHash(&addr3)) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFURLTests.m from [409cce205c] to [641ece2b4e].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | | 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 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFURL"; static OFString *URLString = @"ht%3atp://us%3Aer:p%40w@ho%3Ast:1234/" @"pa%3Fth?que%23ry=1&f%26oo=b%3dar#frag%23ment"; @implementation TestsAppDelegate (OFURLTests) - (void)URLTests { void *pool = objc_autoreleasePoolPush(); OFURL *URL1, *URL2, *URL3, *URL4, *URL5, *URL6, *URL7; OFMutableURL *mutableURL; TEST(@"+[URLWithString:]", R(URL1 = [OFURL URLWithString: URLString]) && R(URL2 = [OFURL URLWithString: @"http://foo:80"]) && R(URL3 = [OFURL URLWithString: @"http://bar/"]) && R(URL4 = [OFURL URLWithString: @"file:///etc/passwd"]) && R(URL5 = [OFURL URLWithString: @"http://foo/bar/qux/foo%2fbar"]) && R(URL6 = [OFURL URLWithString: @"https://[12:34::56:abcd]/"]) && R(URL7 = [OFURL URLWithString: @"https://[12:34::56:abcd]:234/"])) EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #1", OFInvalidFormatException, [OFURL URLWithString: @"ht,tp://foo"]) EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #2", OFInvalidFormatException, |
︙ | ︙ | |||
66 67 68 69 70 71 72 | [OFURL URLWithString: @"https://[f]:/"]) EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #8", OFInvalidFormatException, [OFURL URLWithString: @"https://[f]:f/"]) TEST(@"+[URLWithString:relativeToURL:]", | | < | | | < | < | < | < | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | [OFURL URLWithString: @"https://[f]:/"]) EXPECT_EXCEPTION(@"+[URLWithString:] fails with invalid characters #8", OFInvalidFormatException, [OFURL URLWithString: @"https://[f]:f/"]) TEST(@"+[URLWithString:relativeToURL:]", [[[OFURL URLWithString: @"/foo" relativeToURL: URL1] string] isEqual: @"ht%3atp://us%3Aer:p%40w@ho%3Ast:1234/foo"] && [[[OFURL URLWithString: @"foo/bar?q" relativeToURL: [OFURL URLWithString: @"http://h/qux/quux"]] string] isEqual: @"http://h/qux/foo/bar?q"] && [[[OFURL URLWithString: @"foo/bar" relativeToURL: [OFURL URLWithString: @"http://h/qux/?x"]] string] isEqual: @"http://h/qux/foo/bar"] && [[[OFURL URLWithString: @"http://foo/?q" relativeToURL: URL1] string] isEqual: @"http://foo/?q"] && [[[OFURL URLWithString: @"foo" relativeToURL: [OFURL URLWithString: @"http://foo/bar"]] string] isEqual: @"http://foo/foo"] && [[[OFURL URLWithString: @"foo" relativeToURL: [OFURL URLWithString: @"http://foo"]] string] isEqual: @"http://foo/foo"]) EXPECT_EXCEPTION( @"+[URLWithString:relativeToURL:] fails with invalid characters #1", OFInvalidFormatException, [OFURL URLWithString: @"`" relativeToURL: URL1]) EXPECT_EXCEPTION( @"+[URLWithString:relativeToURL:] fails with invalid characters #2", OFInvalidFormatException, [OFURL URLWithString: @"/`" relativeToURL: URL1]) EXPECT_EXCEPTION( @"+[URLWithString:relativeToURL:] fails with invalid characters #3", OFInvalidFormatException, [OFURL URLWithString: @"?`" relativeToURL: URL1]) EXPECT_EXCEPTION( @"+[URLWithString:relativeToURL:] fails with invalid characters #4", OFInvalidFormatException, [OFURL URLWithString: @"#`" relativeToURL: URL1]) #ifdef OF_HAVE_FILES TEST(@"+[fileURLWithPath:]", [[[OFURL fileURLWithPath: @"testfile.txt"] fileSystemRepresentation] isEqual: [[OFFileManager defaultManager].currentDirectoryPath stringByAppendingPathComponent: @"testfile.txt"]]) |
︙ | ︙ | |||
136 137 138 139 140 141 142 | [tmp.host isEqual: @"test"] && [tmp.path isEqual: @"/"] && [tmp.string isEqual: @"file://test/"] && [tmp.fileSystemRepresentation isEqual: @"\\\\test"]) # endif #endif TEST(@"-[string]", | | | | | | | | | | | | | > | | | | | | | | | | | | | > | | > | > | | | | | | | | > | > | > | | > | > > | | > | | | | | | > | | > | | | | | | > | | | | | | | | < | < | < | < | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | [tmp.host isEqual: @"test"] && [tmp.path isEqual: @"/"] && [tmp.string isEqual: @"file://test/"] && [tmp.fileSystemRepresentation isEqual: @"\\\\test"]) # endif #endif TEST(@"-[string]", [URL1.string isEqual: URLString] && [URL2.string isEqual: @"http://foo:80"] && [URL3.string isEqual: @"http://bar/"] && [URL4.string isEqual: @"file:///etc/passwd"]) TEST(@"-[scheme]", [URL1.scheme isEqual: @"ht:tp"] && [URL4.scheme isEqual: @"file"]) TEST(@"-[user]", [URL1.user isEqual: @"us:er"] && URL4.user == nil) TEST(@"-[password]", [URL1.password isEqual: @"p@w"] && URL4.password == nil) TEST(@"-[host]", [URL1.host isEqual: @"ho:st"] && [URL6.host isEqual: @"12:34::56:abcd"] && [URL7.host isEqual: @"12:34::56:abcd"]) TEST(@"-[port]", URL1.port.unsignedShortValue == 1234 && [URL4 port] == nil && URL7.port.unsignedShortValue == 234) TEST(@"-[path]", [URL1.path isEqual: @"/pa?th"] && [URL4.path isEqual: @"/etc/passwd"]) TEST(@"-[pathComponents]", [URL1.pathComponents isEqual: [OFArray arrayWithObjects: @"/", @"pa?th", nil]] && [URL4.pathComponents isEqual: [OFArray arrayWithObjects: @"/", @"etc", @"passwd", nil]] && [URL5.pathComponents isEqual: [OFArray arrayWithObjects: @"/", @"bar", @"qux", @"foo/bar", nil]]) TEST(@"-[lastPathComponent]", [[[OFURL URLWithString: @"http://host/foo//bar/baz"] lastPathComponent] isEqual: @"baz"] && [[[OFURL URLWithString: @"http://host/foo//bar/baz/"] lastPathComponent] isEqual: @"baz"] && [[[OFURL URLWithString: @"http://host/foo/"] lastPathComponent] isEqual: @"foo"] && [[[OFURL URLWithString: @"http://host/"] lastPathComponent] isEqual: @"/"] && [URL5.lastPathComponent isEqual: @"foo/bar"]) TEST(@"-[query]", [URL1.query isEqual: @"que#ry=1&f&oo=b=ar"] && URL4.query == nil) TEST(@"-[queryDictionary]", [URL1.queryDictionary isEqual: [OFDictionary dictionaryWithKeysAndObjects: @"que#ry", @"1", @"f&oo", @"b=ar", nil]]); TEST(@"-[fragment]", [URL1.fragment isEqual: @"frag#ment"] && URL4.fragment == nil) TEST(@"-[copy]", R(URL4 = [[URL1 copy] autorelease])) TEST(@"-[isEqual:]", [URL1 isEqual: URL4] && ![URL2 isEqual: URL3] && [[OFURL URLWithString: @"HTTP://bar/"] isEqual: URL3]) TEST(@"-[hash:]", URL1.hash == URL4.hash && URL2.hash != URL3.hash) EXPECT_EXCEPTION(@"Detection of invalid format", OFInvalidFormatException, [OFURL URLWithString: @"http"]) mutableURL = [OFMutableURL URL]; TEST(@"-[setScheme:]", (mutableURL.scheme = @"ht:tp") && [mutableURL.URLEncodedScheme isEqual: @"ht%3Atp"]) TEST(@"-[setURLEncodedScheme:]", (mutableURL.URLEncodedScheme = @"ht%3Atp") && [mutableURL.scheme isEqual: @"ht:tp"]) EXPECT_EXCEPTION( @"-[setURLEncodedScheme:] with invalid characters fails", OFInvalidFormatException, mutableURL.URLEncodedScheme = @"~") TEST(@"-[setHost:]", (mutableURL.host = @"ho:st") && [mutableURL.URLEncodedHost isEqual: @"ho%3Ast"] && (mutableURL.host = @"12:34:ab") && [mutableURL.URLEncodedHost isEqual: @"[12:34:ab]"] && (mutableURL.host = @"12:34:aB") && [mutableURL.URLEncodedHost isEqual: @"[12:34:aB]"] && (mutableURL.host = @"12:34:g") && [mutableURL.URLEncodedHost isEqual: @"12%3A34%3Ag"]) TEST(@"-[setURLEncodedHost:]", (mutableURL.URLEncodedHost = @"ho%3Ast") && [mutableURL.host isEqual: @"ho:st"] && (mutableURL.URLEncodedHost = @"[12:34]") && [mutableURL.host isEqual: @"12:34"] && (mutableURL.URLEncodedHost = @"[12::ab]") && [mutableURL.host isEqual: @"12::ab"]) EXPECT_EXCEPTION(@"-[setURLEncodedHost:] with invalid characters fails" " #1", OFInvalidFormatException, mutableURL.URLEncodedHost = @"/") EXPECT_EXCEPTION(@"-[setURLEncodedHost:] with invalid characters fails" " #2", OFInvalidFormatException, mutableURL.URLEncodedHost = @"[12:34") EXPECT_EXCEPTION(@"-[setURLEncodedHost:] with invalid characters fails" " #3", OFInvalidFormatException, mutableURL.URLEncodedHost = @"[a::g]") TEST(@"-[setUser:]", (mutableURL.user = @"us:er") && [mutableURL.URLEncodedUser isEqual: @"us%3Aer"]) TEST(@"-[setURLEncodedUser:]", (mutableURL.URLEncodedUser = @"us%3Aer") && [mutableURL.user isEqual: @"us:er"]) EXPECT_EXCEPTION(@"-[setURLEncodedUser:] with invalid characters fails", OFInvalidFormatException, mutableURL.URLEncodedHost = @"/") TEST(@"-[setPassword:]", (mutableURL.password = @"pass:word") && [mutableURL.URLEncodedPassword isEqual: @"pass%3Aword"]) TEST(@"-[setURLEncodedPassword:]", (mutableURL.URLEncodedPassword = @"pass%3Aword") && [mutableURL.password isEqual: @"pass:word"]) EXPECT_EXCEPTION( @"-[setURLEncodedPassword:] with invalid characters fails", OFInvalidFormatException, mutableURL.URLEncodedPassword = @"/") TEST(@"-[setPath:]", (mutableURL.path = @"pa/th@?") && [mutableURL.URLEncodedPath isEqual: @"pa/th@%3F"]) TEST(@"-[setURLEncodedPath:]", (mutableURL.URLEncodedPath = @"pa/th@%3F") && [mutableURL.path isEqual: @"pa/th@?"]) EXPECT_EXCEPTION(@"-[setURLEncodedPath:] with invalid characters fails", OFInvalidFormatException, mutableURL.URLEncodedPath = @"?") TEST(@"-[setQuery:]", (mutableURL.query = @"que/ry?#") && [mutableURL.URLEncodedQuery isEqual: @"que/ry?%23"]) TEST(@"-[setURLEncodedQuery:]", (mutableURL.URLEncodedQuery = @"que/ry?%23") && [mutableURL.query isEqual: @"que/ry?#"]) EXPECT_EXCEPTION( @"-[setURLEncodedQuery:] with invalid characters fails", OFInvalidFormatException, mutableURL.URLEncodedQuery = @"`") TEST(@"-[setQueryDictionary:]", (mutableURL.queryDictionary = [OFDictionary dictionaryWithKeysAndObjects: @"foo&bar", @"baz=qux", @"f=oobar", @"b&azqux", nil]) && [mutableURL.URLEncodedQuery isEqual: @"foo%26bar=baz%3Dqux&f%3Doobar=b%26azqux"]) TEST(@"-[setFragment:]", (mutableURL.fragment = @"frag/ment?#") && [mutableURL.URLEncodedFragment isEqual: @"frag/ment?%23"]) TEST(@"-[setURLEncodedFragment:]", (mutableURL.URLEncodedFragment = @"frag/ment?%23") && [mutableURL.fragment isEqual: @"frag/ment?#"]) EXPECT_EXCEPTION( @"-[setURLEncodedFragment:] with invalid characters fails", OFInvalidFormatException, mutableURL.URLEncodedFragment = @"`") TEST(@"-[URLByAppendingPathComponent:isDirectory:]", [[[OFURL URLWithString: @"file:///foo/bar"] URLByAppendingPathComponent: @"qux" isDirectory: false] isEqual: [OFURL URLWithString: @"file:///foo/bar/qux"]] && [[[OFURL URLWithString: @"file:///foo/bar/"] URLByAppendingPathComponent: @"qux" isDirectory: false] isEqual: [OFURL URLWithString: @"file:///foo/bar/qux"]] && [[[OFURL URLWithString: @"file:///foo/bar/"] URLByAppendingPathComponent: @"qu?x" isDirectory: false] isEqual: [OFURL URLWithString: @"file:///foo/bar/qu%3Fx"]] && [[[OFURL URLWithString: @"file:///foo/bar/"] URLByAppendingPathComponent: @"qu?x" isDirectory: true] isEqual: [OFURL URLWithString: @"file:///foo/bar/qu%3Fx/"]]) TEST(@"-[URLByStandardizingPath]", [[[OFURL URLWithString: @"http://foo/bar/.."] URLByStandardizingPath] isEqual: [OFURL URLWithString: @"http://foo/"]] && [[[OFURL URLWithString: @"http://foo/bar/%2E%2E/../qux/"] |
︙ | ︙ |
Modified tests/OFValueTests.m from [eefd2c428a] to [f0ec7ac363].
︙ | ︙ | |||
15 16 17 18 19 20 21 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" | | | | | | < | | | < | | < | 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 | #include "config.h" #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFValue"; @implementation TestsAppDelegate (OFValueTests) - (void)valueTests { void *pool = objc_autoreleasePoolPush(); OFRange range = OFRangeMake(1, 64), range2; OFPoint point = OFPointMake(1.5f, 3.0f), point2; OFSize size = OFSizeMake(4.5f, 5.0f), size2; OFRect rect = OFRectMake(1.5f, 3.0f, 4.5f, 6.0f), rect2; OFValue *value; void *pointer = &value; TEST(@"+[valueWithBytes:objCType:]", (value = [OFValue valueWithBytes: &range objCType: @encode(OFRange)])) TEST(@"-[objCType]", strcmp(value.objCType, @encode(OFRange)) == 0) TEST(@"-[getValue:size:]", R([value getValue: &range2 size: sizeof(OFRange)]) && OFRangeEqual(range2, range)) EXPECT_EXCEPTION(@"-[getValue:size:] with wrong size throws", OFOutOfRangeException, [value getValue: &range size: sizeof(OFRange) - 1]) TEST(@"+[valueWithPointer:]", (value = [OFValue valueWithPointer: pointer])) TEST(@"-[pointerValue]", value.pointerValue == pointer && [[OFValue valueWithBytes: &pointer |
︙ | ︙ | |||
75 76 77 78 79 80 81 | [[OFValue valueWithBytes: "a" objCType: @encode(char)] nonretainedObjectValue]) TEST(@"+[valueWithRange:]", (value = [OFValue valueWithRange: range])) TEST(@"-[rangeValue]", | | | | | < | | | | | < | | | | | | | | | | | | < | | | | | | | | | | | | < | | | < | | | | < | < | < | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 | [[OFValue valueWithBytes: "a" objCType: @encode(char)] nonretainedObjectValue]) TEST(@"+[valueWithRange:]", (value = [OFValue valueWithRange: range])) TEST(@"-[rangeValue]", OFRangeEqual(value.rangeValue, range) && (value = [OFValue valueWithBytes: &range objCType: @encode(OFRange)]) && OFRangeEqual(value.rangeValue, range)) TEST(@"-[getValue:size:] for OFRangeValue", (value = [OFValue valueWithRange: range]) && R([value getValue: &range2 size: sizeof(range2)]) && OFRangeEqual(range2, range)) EXPECT_EXCEPTION(@"-[rangeValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] rangeValue]) TEST(@"+[valueWithPoint:]", (value = [OFValue valueWithPoint: point])) TEST(@"-[pointValue]", OFPointEqual(value.pointValue, point) && (value = [OFValue valueWithBytes: &point objCType: @encode(OFPoint)]) && OFPointEqual(value.pointValue, point)) TEST(@"-[getValue:size:] for OFPointValue", (value = [OFValue valueWithPoint: point]) && R([value getValue: &point2 size: sizeof(point2)]) && OFPointEqual(point2, point)) EXPECT_EXCEPTION(@"-[pointValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] pointValue]) TEST(@"+[valueWithSize:]", (value = [OFValue valueWithSize: size])) TEST(@"-[sizeValue]", OFSizeEqual(value.sizeValue, size) && (value = [OFValue valueWithBytes: &size objCType: @encode(OFSize)]) && OFSizeEqual(value.sizeValue, size)) TEST(@"-[getValue:size:] for OFSizeValue", (value = [OFValue valueWithSize: size]) && R([value getValue: &size2 size: sizeof(size2)]) && OFSizeEqual(size2, size)) EXPECT_EXCEPTION(@"-[sizeValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] sizeValue]) TEST(@"+[valueWithRect:]", (value = [OFValue valueWithRect: rect])) TEST(@"-[rectValue]", OFRectEqual(value.rectValue, rect) && (value = [OFValue valueWithBytes: &rect objCType: @encode(OFRect)]) && OFRectEqual(value.rectValue, rect)) TEST(@"-[getValue:size:] for OFRectValue", (value = [OFValue valueWithRect: rect]) && R([value getValue: &rect2 size: sizeof(rect2)]) && OFRectEqual(rect2, rect)) EXPECT_EXCEPTION(@"-[rectValue] with wrong size throws", OFOutOfRangeException, [[OFValue valueWithBytes: "a" objCType: @encode(char)] rectValue]) TEST(@"-[isEqual:]", [[OFValue valueWithRect: rect] isEqual: [OFValue valueWithBytes: &rect objCType: @encode(OFRect)]] && ![[OFValue valueWithBytes: "a" objCType: @encode(signed char)] isEqual: [OFValue valueWithBytes: "a" objCType: @encode(unsigned char)]] && ![[OFValue valueWithBytes: "a" objCType: @encode(char)] isEqual: [OFValue valueWithBytes: "b" objCType: @encode(char)]]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFWindowsRegistryKeyTests.m from [c468a7e06f] to [b3eba3a2d6].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | < | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFWindowsRegistryKey"; @implementation TestsAppDelegate (OFWindowsRegistryKeyTests) - (void)windowsRegistryKeyTests { void *pool = objc_autoreleasePoolPush(); OFData *data = [OFData dataWithItems: "abcdef" count: 6]; OFWindowsRegistryKey *softwareKey, *objFWKey; DWORD type; TEST(@"+[OFWindowsRegistryKey classesRootKey]", [OFWindowsRegistryKey classesRootKey]) TEST(@"+[OFWindowsRegistryKey currentConfigKey]", [OFWindowsRegistryKey currentConfigKey]) |
︙ | ︙ | |||
48 49 50 51 52 53 54 | openSubkeyAtPath: @"Software" securityAndAccessRights: KEY_ALL_ACCESS]) && [[OFWindowsRegistryKey currentUserKey] openSubkeyAtPath: @"nonexistent" securityAndAccessRights: KEY_ALL_ACCESS] == nil) TEST(@"-[createSubkeyAtPath:securityAndAccessRights:]", | | | | < < | < | | | < | | | | | | | 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | openSubkeyAtPath: @"Software" securityAndAccessRights: KEY_ALL_ACCESS]) && [[OFWindowsRegistryKey currentUserKey] openSubkeyAtPath: @"nonexistent" securityAndAccessRights: KEY_ALL_ACCESS] == nil) TEST(@"-[createSubkeyAtPath:securityAndAccessRights:]", (objFWKey = [softwareKey createSubkeyAtPath: @"ObjFW" securityAndAccessRights: KEY_ALL_ACCESS])) TEST(@"-[setData:forValueNamed:type:]", R([objFWKey setData: data forValueNamed: @"data" type: REG_BINARY])) TEST(@"-[dataForValueNamed:subkeyPath:flags:type:]", [[objFWKey dataForValueNamed: @"data" type: &type] isEqual: data] && type == REG_BINARY) TEST(@"-[setString:forValueNamed:type:]", R([objFWKey setString: @"foobar" forValueNamed: @"string"]) && R([objFWKey setString: @"%PATH%;foo" forValueNamed: @"expand" type: REG_EXPAND_SZ])) TEST(@"-[stringForValue:subkeyPath:]", [[objFWKey stringForValueNamed: @"string"] isEqual: @"foobar"] && [[objFWKey stringForValueNamed: @"expand" type: &type] isEqual: @"%PATH%;foo"] && type == REG_EXPAND_SZ) TEST(@"-[deleteValueNamed:]", R([objFWKey deleteValueNamed: @"data"])) TEST(@"-[deleteSubkeyAtPath:]", R([softwareKey deleteSubkeyAtPath: @"ObjFW"])) objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFXMLElementBuilderTests.m from [e70986486c] to [1ae510b9c5].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | | | | | | | | | 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 61 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"OFXMLElementBuilder"; static OFXMLNode *nodes[2]; static size_t i = 0; @implementation TestsAppDelegate (OFXMLElementBuilderTests) - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildElement: (OFXMLElement *)element { OFEnsure(i == 0); nodes[i++] = [element retain]; } - (void)elementBuilder: (OFXMLElementBuilder *)builder didBuildParentlessNode: (OFXMLNode *)node { OFEnsure(i == 1); nodes[i++] = [node retain]; } - (void)XMLElementBuilderTests { void *pool = objc_autoreleasePoolPush(); OFXMLParser *parser = [OFXMLParser parser]; OFXMLElementBuilder *builder = [OFXMLElementBuilder builder]; OFString *string = @"<foo>bar<![CDATA[f<oo]]>baz<qux/>" " <qux xmlns:qux='urn:qux'><?asd?><qux:bar/><x qux:y='z'/></qux>" "</foo>"; parser.delegate = builder; builder.delegate = self; TEST(@"Building elements from parsed XML", R([parser parseString: string]) && nodes[0] != nil && [nodes[0].XMLString isEqual: string] && R([parser parseString: @"<!--foo-->"]) && nodes[1] != nil && [nodes[1].XMLString isEqual: @"<!--foo-->"] && i == 2) [nodes[0] release]; [nodes[1] release]; objc_autoreleasePoolPop(pool); } |
︙ | ︙ |
Modified tests/OFXMLNodeTests.m from [8eafe93c0b] to [3a041e8eb3].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | | > > | | | | | | | | < | | | | | | < | | | | | | < | | | | | | | | | < | | < < | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *module; @implementation TestsAppDelegate (OFXMLNodeTests) - (void)XMLNodeTests { void *pool = objc_autoreleasePoolPush(); id node1, node2, node3, node4; OFArray *array; module = @"OFXMLNode"; TEST(@"+[elementWithName:]", (node1 = [OFXMLElement elementWithName: @"foo"]) && [[node1 XMLString] isEqual: @"<foo/>"]) TEST(@"+[elementWithName:stringValue:]", (node2 = [OFXMLElement elementWithName: @"foo" stringValue: @"b&ar"]) && [[node2 XMLString] isEqual: @"<foo>b&ar</foo>"]) TEST(@"+[elementWithName:namespace:]", (node3 = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]) && R([node3 addAttributeWithName: @"test" stringValue: @"test"]) && R([node3 setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]) && [[node3 XMLString] isEqual: @"<objfw-test:foo test='test'/>"] && (node4 = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]) && R([node4 addAttributeWithName: @"test" stringValue: @"test"]) && [[node4 XMLString] isEqual: @"<foo xmlns='urn:objfw:test' test='test'/>"]) TEST(@"+[elementWithName:namespace:stringValue:]", (node4 = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"x"]) && R([node4 setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]) && [[node4 XMLString] isEqual: @"<objfw-test:foo>x</objfw-test:foo>"]) TEST(@"+[charactersWithString:]", (node4 = [OFXMLCharacters charactersWithString: @"<foo>"]) && [[node4 XMLString] isEqual: @"<foo>"]) TEST(@"+[CDATAWithString:]", (node4 = [OFXMLCDATA CDATAWithString: @"<foo>"]) && [[node4 XMLString] isEqual: @"<![CDATA[<foo>]]>"]); TEST(@"+[commentWithText:]", (node4 = [OFXMLComment commentWithText: @" comment "]) && [[node4 XMLString] isEqual: @"<!-- comment -->"]) module = @"OFXMLElement"; TEST(@"-[addAttributeWithName:stringValue:]", R([node1 addAttributeWithName: @"foo" stringValue: @"b&ar"]) && [[node1 XMLString] isEqual: @"<foo foo='b&ar'/>"] && R([node2 addAttributeWithName: @"foo" stringValue: @"b&ar"]) && [[node2 XMLString] isEqual: @"<foo foo='b&ar'>b&ar</foo>"]) TEST(@"-[setPrefix:forNamespace:]", R([node2 setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"])) TEST(@"-[addAttributeWithName:namespace:stringValue:]", R([node2 addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"bar"]) && R([node2 addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"ignored"]) && [[node2 XMLString] isEqual: @"<foo foo='b&ar' objfw-test:foo='bar'>b&ar</foo>"]) TEST(@"-[removeAttributeForName:namespace:]", R([node2 removeAttributeForName: @"foo"]) && [[node2 XMLString] isEqual: @"<foo objfw-test:foo='bar'>b&ar</foo>"] && R([node2 removeAttributeForName: @"foo" namespace: @"urn:objfw:test"]) && [[node2 XMLString] isEqual: @"<foo>b&ar</foo>"]) TEST(@"-[addChild:]", R([node1 addChild: [OFXMLElement elementWithName: @"bar"]]) && [[node1 XMLString] isEqual: @"<foo foo='b&ar'><bar/></foo>"] && R([node3 addChild: [OFXMLElement elementWithName: @"bar" namespace: @"urn:objfw:test"]]) && [[node3 XMLString] isEqual: @"<objfw-test:foo test='test'><objfw-test:bar/></objfw-test:foo>"]) TEST(@"+[elementWithXMLString:] and -[stringValue]", [[[OFXMLElement elementWithXMLString: @"<?xml version='1.0' encoding='UTF-8'?>\r\n<x>foo<![CDATA[bar]]>" @"<y>b<!-- fooo -->az</y>qux</x>"] stringValue] isEqual: @"foobarbazqux"]) TEST(@"-[elementsForName:namespace:]", (array = [node3 elementsForName: @"bar" namespace: @"urn:objfw:test"]) && array.count == 1 && [[array.firstObject XMLString] isEqual: @"<bar xmlns='urn:objfw:test'/>"]) TEST(@"-[isEqual:]", [[OFXMLElement elementWithXMLString: @"<foo bar='asd'/>"] isEqual: [OFXMLElement elementWithXMLString: @"<foo bar='asd'></foo>"]] && [[OFXMLElement elementWithXMLString: @"<x><y/></x>"] isEqual: [OFXMLElement elementWithXMLString: @"<x><y></y></x>"]]) |
︙ | ︙ |
Modified tests/OFXMLParserTests.m from [faffb42f7b] to [3eb25f939e].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #include "config.h" #include <stdlib.h> #include <string.h> #import "TestsAppDelegate.h" | | | | | | | | | | | | | | > > | | > | > | | > | > | > | | > | | > | > | > | > | > | > | > | > | | > | > | > | > | > | > | > | | > > | | > | > | > | > | | > | > | | > | > | > | > | > | > | > | > | > | > | | | | > | | | | | | | | | | < | | < | | | < | | | | | | | < | < | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | #include "config.h" #include <stdlib.h> #include <string.h> #import "TestsAppDelegate.h" static OFString *const module = @"OFXMLParser"; static int i = 0; enum EventType { eventTypeProcessingInstruction, eventTypeTagOpen, eventTypeTagClose, eventTypeString, eventTypeCDATA, eventTypeComment }; @implementation TestsAppDelegate (OFXMLParser) - (void)parser: (OFXMLParser *)parser didCreateEvent: (enum EventType)type name: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attrs string: (OFString *)string { OFString *message; i++; message = [OFString stringWithFormat: @"Parsing part #%d", i]; switch (i) { case 1: TEST(message, type == eventTypeProcessingInstruction && [name isEqual: @"xml"] && [string isEqual: @"version='1.0'"]) break; case 2: TEST(message, type == eventTypeProcessingInstruction && [name isEqual: @"p?i"] && string == nil) break; case 3: TEST(message, type == eventTypeTagOpen && [name isEqual: @"root"] && prefix == nil && namespace == nil && attrs.count == 0) break; case 4: TEST(message, type == eventTypeString && [string isEqual: @"\n\n "]) break; case 5: TEST(message, type == eventTypeCDATA && [string isEqual: @"f<]]]oo]"] && parser.lineNumber == 3) break; case 6: TEST(message, type == eventTypeTagOpen && [name isEqual: @"bar"] && prefix == nil && namespace == nil && attrs == nil) break; case 7: TEST(message, type == eventTypeTagClose && [name isEqual: @"bar"] && prefix == nil && namespace == nil && attrs == nil) break; case 8: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 9: TEST(message, type == eventTypeTagOpen && [name isEqual: @"foobar"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:foobar"] && attrs.count == 1 && /* xmlns attr */ [[[attrs objectAtIndex: 0] name] isEqual: @"xmlns"] && [[attrs objectAtIndex: 0] namespace] == nil && [[[attrs objectAtIndex: 0] stringValue] isEqual: @"urn:objfw:test:foobar"]) break; case 10: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 11: TEST(message, type == eventTypeTagOpen && [name isEqual: @"qux"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:foobar"] && attrs.count == 1 && /* xmlns:foo attr */ [[[attrs objectAtIndex: 0] name] isEqual: @"foo"] && [[[attrs objectAtIndex: 0] namespace] isEqual: @"http://www.w3.org/2000/xmlns/"] && [[[attrs objectAtIndex: 0] stringValue] isEqual: @"urn:objfw:test:foo"]) break; case 12: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 13: TEST(message, type == eventTypeTagOpen && [name isEqual: @"bla"] && [prefix isEqual: @"foo"] && [namespace isEqual: @"urn:objfw:test:foo"] && attrs.count == 2 && /* foo:bla attr */ [[[attrs objectAtIndex: 0] name] isEqual: @"bla"] && [[[attrs objectAtIndex: 0] namespace] isEqual: @"urn:objfw:test:foo"] && [[[attrs objectAtIndex: 0] stringValue] isEqual: @"bla"] && /* blafoo attr */ [[[attrs objectAtIndex: 1] name] isEqual: @"blafoo"] && [[attrs objectAtIndex: 1] namespace] == nil && [[[attrs objectAtIndex: 1] stringValue] isEqual: @"foo"]) break; case 14: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 15: TEST(message, type == eventTypeTagOpen && [name isEqual: @"blup"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:foobar"] && attrs.count == 2 && /* foo:qux attr */ [[[attrs objectAtIndex: 0] name] isEqual: @"qux"] && [[[attrs objectAtIndex: 0] namespace] isEqual: @"urn:objfw:test:foo"] && [[[attrs objectAtIndex: 0] stringValue] isEqual: @"asd"] && /* quxqux attr */ [[[attrs objectAtIndex: 1] name] isEqual: @"quxqux"] && [[attrs objectAtIndex: 1] namespace] == nil && [[[attrs objectAtIndex: 1] stringValue] isEqual: @"test"]) break; case 16: TEST(message, type == eventTypeTagClose && [name isEqual: @"blup"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:foobar"]) break; case 17: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 18: TEST(message, type == eventTypeTagOpen && [name isEqual: @"bla"] && [prefix isEqual: @"bla"] && [namespace isEqual: @"urn:objfw:test:bla"] && attrs.count == 3 && /* xmlns:bla attr */ [[[attrs objectAtIndex: 0] name] isEqual: @"bla"] && [[[attrs objectAtIndex: 0] namespace] isEqual: @"http://www.w3.org/2000/xmlns/"] && [[[attrs objectAtIndex: 0] stringValue] isEqual: @"urn:objfw:test:bla"] && /* qux attr */ [[[attrs objectAtIndex: 1] name] isEqual: @"qux"] && [[attrs objectAtIndex: 1] namespace] == nil && [[[attrs objectAtIndex: 1] stringValue] isEqual: @"qux"] && /* bla:foo attr */ [[[attrs objectAtIndex: 2] name] isEqual: @"foo"] && [[[attrs objectAtIndex: 2] namespace] isEqual: @"urn:objfw:test:bla"] && [[[attrs objectAtIndex: 2] stringValue] isEqual: @"blafoo"]) break; case 19: TEST(message, type == eventTypeTagClose && [name isEqual: @"bla"] && [prefix isEqual: @"bla"] && [namespace isEqual: @"urn:objfw:test:bla"]) break; case 20: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 21: TEST(message, type == eventTypeTagOpen && [name isEqual: @"abc"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:abc"] && attrs.count == 3 && /* xmlns attr */ [[[attrs objectAtIndex: 0] name] isEqual: @"xmlns"] && [[attrs objectAtIndex: 0] namespace] == nil && [[[attrs objectAtIndex: 0] stringValue] isEqual: @"urn:objfw:test:abc"] && /* abc attr */ [[[attrs objectAtIndex: 1] name] isEqual: @"abc"] && [[attrs objectAtIndex: 1] namespace] == nil && [[[attrs objectAtIndex: 1] stringValue] isEqual: @"abc"] && /* foo:abc attr */ [[[attrs objectAtIndex: 2] name] isEqual: @"abc"] && [[[attrs objectAtIndex: 2] namespace] isEqual: @"urn:objfw:test:foo"] && [[[attrs objectAtIndex: 2] stringValue] isEqual: @"abc"]) break; case 22: TEST(message, type == eventTypeTagClose && [name isEqual: @"abc"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:abc"]) break; case 23: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 24: TEST(message, type == eventTypeTagClose && [name isEqual: @"bla"] && [prefix isEqual: @"foo"] && [namespace isEqual: @"urn:objfw:test:foo"]) break; case 25: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 26: TEST(message, type == eventTypeComment && [string isEqual: @" commänt "]) break; case 27: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 28: TEST(message, type == eventTypeTagClose && [name isEqual: @"qux"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:foobar"]) break; case 29: TEST(message, type == eventTypeString && [string isEqual: @"\n "]) break; case 30: TEST(message, type == eventTypeTagClose && [name isEqual: @"foobar"] && prefix == nil && [namespace isEqual: @"urn:objfw:test:foobar"]) break; case 31: TEST(message, type == eventTypeString && [string isEqual: @"\n"]) break; case 32: TEST(message, type == eventTypeTagClose && [name isEqual: @"root"] && prefix == nil && namespace == nil); break; } } - (void)parser: (OFXMLParser *)parser foundProcessingInstructionWithTarget: (OFString *)target data: (OFString *)data { [self parser: parser didCreateEvent: eventTypeProcessingInstruction name: target prefix: nil namespace: nil attributes: nil string: data]; } - (void)parser: (OFXMLParser *)parser didStartElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace attributes: (OFArray *)attrs { [self parser: parser didCreateEvent: eventTypeTagOpen name: name prefix: prefix namespace: namespace attributes: attrs string: nil]; } - (void)parser: (OFXMLParser *)parser didEndElement: (OFString *)name prefix: (OFString *)prefix namespace: (OFString *)namespace { [self parser: parser didCreateEvent: eventTypeTagClose name: name prefix: prefix namespace: namespace attributes: nil string: nil]; } - (void)parser: (OFXMLParser *)parser foundCharacters: (OFString *)string { [self parser: parser didCreateEvent: eventTypeString name: nil prefix: nil namespace: nil attributes: nil string: string]; } - (void)parser: (OFXMLParser *)parser foundCDATA: (OFString *)CDATA { [self parser: parser didCreateEvent: eventTypeCDATA name: nil prefix: nil namespace: nil attributes: nil string: CDATA]; } - (void)parser: (OFXMLParser *)parser foundComment: (OFString *)comment { [self parser: parser didCreateEvent: eventTypeComment name: nil prefix: nil namespace: nil attributes: nil string: comment]; } - (OFString *)parser: (OFXMLParser *)parser foundUnknownEntityNamed: (OFString *)entity { if ([entity isEqual: @"foo"]) return @"foobar"; return nil; } - (void)XMLParserTests { void *pool = objc_autoreleasePoolPush(); const char *string = "\xEF\xBB\xBF<?xml version='1.0'?><?p?i?>" "<!DOCTYPE foo><root>\r\r" " <![CDATA[f<]]]oo]]]><bar/>\n" " <foobar xmlns='urn:objfw:test:foobar'>\r\n" " <qux xmlns:foo='urn:objfw:test:foo'>\n" " <foo:bla foo:bla = 'bla' blafoo='foo'>\n" " <blup foo:qux='asd' quxqux='test'/>\n" " <bla:bla\r\rxmlns:bla\r=\t\"urn:objfw:test:bla\" qux='qux'\r\n" " bla:foo='blafoo'/>\n" " <abc xmlns='urn:objfw:test:abc' abc='abc' foo:abc='abc'/>\n" " </foo:bla>\n" " <!-- commänt -->\n" " </qux>\n" " </foobar>\n" "</root>"; OFXMLParser *parser; size_t j, length; TEST(@"+[parser]", (parser = [OFXMLParser parser])) TEST(@"-[setDelegate:]", (parser.delegate = self)) /* Simulate a stream where we only get chunks */ length = strlen(string); for (j = 0; j < length; j+= 2) { if (parser.hasFinishedParsing) abort(); if (j + 2 > length) [parser parseBuffer: string + j length: 1]; else [parser parseBuffer: string + j length: 2]; } TEST(@"Checking if everything was parsed", i == 32 && parser.lineNumber == 18) TEST(@"-[hasFinishedParsing]", parser.hasFinishedParsing) TEST(@"Parsing whitespaces after the document", R([parser parseString: @" \t\r\n "])) TEST(@"Parsing comments after the document", R([parser parseString: @" \t<!-- foo -->\r<!--bar-->\n "])) EXPECT_EXCEPTION(@"Detection of junk after the document #1", OFMalformedXMLException, [parser parseString: @"a"]) EXPECT_EXCEPTION(@"Detection of junk after the document #2", OFMalformedXMLException, [parser parseString: @"<!["]) parser = [OFXMLParser parser]; EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #1", OFMalformedXMLException, [parser parseString: @"<?xml version='2.0'?>"]) parser = [OFXMLParser parser]; EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #2", OFInvalidEncodingException, [parser parseString: @"<?xml encoding='UTF-7'?>"]) parser = [OFXMLParser parser]; EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #3", OFMalformedXMLException, [parser parseString: @"<x><?xml?></x>"]) objc_autoreleasePoolPop(pool); } @end |
Modified tests/RuntimeARCTests.m from [17d2d82f60] to [b48c97e0ac].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"Runtime (ARC)"; @interface RuntimeARCTest: OFObject @end @implementation RuntimeARCTest - (instancetype)init { |
︙ | ︙ |
Modified tests/RuntimeTests.m from [60799e33cc] to [20a13fa2e0].
︙ | ︙ | |||
13 14 15 16 17 18 19 | * file. */ #include "config.h" #import "TestsAppDelegate.h" | | | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | * file. */ #include "config.h" #import "TestsAppDelegate.h" static OFString *const module = @"Runtime"; @interface OFObject (SuperTest) - (id)superTest; @end @interface RuntimeTest: OFObject { |
︙ | ︙ | |||
59 60 61 62 63 64 65 | } @end @implementation TestsAppDelegate (RuntimeTests) - (void)runtimeTests { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | > | | > | | | | 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | } @end @implementation TestsAppDelegate (RuntimeTests) - (void)runtimeTests { void *pool = objc_autoreleasePoolPush(); RuntimeTest *test = [[[RuntimeTest alloc] init] autorelease]; OFString *string, *foo; #ifdef OF_OBJFW_RUNTIME int classID; uintmax_t value; id object; #endif EXPECT_EXCEPTION(@"Calling a non-existent method via super", OFNotImplementedException, [test superTest]) TEST(@"Calling a method via a super with self == nil", [test nilSuperTest] == nil) string = [OFMutableString stringWithString: @"foo"]; foo = @"foo"; test.foo = string; TEST(@"copy, nonatomic properties", [test.foo isEqual: foo] && test.foo != foo && test.foo.retainCount == 1) test.bar = string; TEST(@"retain, atomic properties", test.bar == string && string.retainCount == 3) #ifdef OF_OBJFW_RUNTIME if (sizeof(uintptr_t) == 8) value = 0xDEADBEEFDEADBEF; else if (sizeof(uintptr_t) == 4) value = 0xDEADBEF; else abort(); TEST(@"Tagged pointers", objc_registerTaggedPointerClass([OFString class]) != -1 && (classID = objc_registerTaggedPointerClass([OFNumber class])) != -1 && (object = objc_createTaggedPointer(classID, (uintptr_t)value)) && object_getClass(object) == [OFNumber class] && [object class] == [OFNumber class] && object_getTaggedPointerValue(object) == value && objc_createTaggedPointer(classID, UINTPTR_MAX >> 4) != nil && objc_createTaggedPointer(classID, (UINTPTR_MAX >> 4) + 1) == nil) #endif objc_autoreleasePoolPop(pool); } @end |
Modified tests/TestsAppDelegate.h from [df50ba0832] to [36680e2682].
︙ | ︙ | |||
11 12 13 14 15 16 17 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "ObjFW.h" | | | | < | | | < | | < | | | | | | | < | | | | | | | | | < | | < | | | < | < | < < < < < < < < < | 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 55 56 57 58 59 60 61 62 63 64 65 66 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "ObjFW.h" #define TEST(test, ...) \ { \ [self outputTesting: test inModule: module]; \ \ if (__VA_ARGS__) \ [self outputSuccess: test inModule: module]; \ else { \ [self outputFailure: test inModule: module]; \ _fails++; \ } \ } #define EXPECT_EXCEPTION(test, exception, code) \ { \ bool caught = false; \ \ [self outputTesting: test inModule: module]; \ \ @try { \ code; \ } @catch (exception *e) { \ caught = true; \ } \ \ if (caught) \ [self outputSuccess: test inModule: module]; \ else { \ [self outputFailure: test inModule: module]; \ _fails++; \ } \ } #define R(...) (__VA_ARGS__, 1) @class OFString; @interface TestsAppDelegate: OFObject <OFApplicationDelegate> { int _fails; } - (void)outputTesting: (OFString *)test inModule: (OFString *)module; - (void)outputSuccess: (OFString *)test inModule: (OFString *)module; - (void)outputFailure: (OFString *)test inModule: (OFString *)module; @end @interface TestsAppDelegate (OFArrayTests) - (void)arrayTests; @end @interface TestsAppDelegate (OFBlockTests) |
︙ | ︙ | |||
159 160 161 162 163 164 165 166 167 168 169 170 171 172 | @interface TestsAppDelegate (OFNumberTests) - (void)numberTests; @end @interface TestsAppDelegate (OFObjectTests) - (void)objectTests; @end @interface TestsAppDelegate (OFPropertyListTests) - (void)propertyListTests; @end @interface TestsAppDelegate (OFPluginTests) - (void)pluginTests; | > > > > | 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | @interface TestsAppDelegate (OFNumberTests) - (void)numberTests; @end @interface TestsAppDelegate (OFObjectTests) - (void)objectTests; @end @interface TestsAppDelegate (OFPBKDF2Tests) - (void)PBKDF2Tests; @end @interface TestsAppDelegate (OFPropertyListTests) - (void)propertyListTests; @end @interface TestsAppDelegate (OFPluginTests) - (void)pluginTests; |
︙ | ︙ | |||
180 181 182 183 184 185 186 | - (void)runtimeARCTests; @end @interface TestsAppDelegate (OFRIPEMD160HashTests) - (void)RIPEMD160HashTests; @end | | | 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | - (void)runtimeARCTests; @end @interface TestsAppDelegate (OFRIPEMD160HashTests) - (void)RIPEMD160HashTests; @end @interface TestsAppDelegate (OFScryptTests) - (void)scryptTests; @end @interface TestsAppDelegate (OFSHA1HashTests) - (void)SHA1HashTests; @end |
︙ | ︙ | |||
204 205 206 207 208 209 210 | - (void)SHA384HashTests; @end @interface TestsAppDelegate (OFSHA512HashTests) - (void)SHA512HashTests; @end | < < < < | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | - (void)SHA384HashTests; @end @interface TestsAppDelegate (OFSHA512HashTests) - (void)SHA512HashTests; @end @interface TestsAppDelegate (OFSPXSocketTests) - (void)SPXSocketTests; @end @interface TestsAppDelegate (OFSPXStreamSocketTests) - (void)SPXStreamSocketTests; @end |
︙ | ︙ | |||
231 232 233 234 235 236 237 238 239 240 241 242 243 244 | @interface TestsAppDelegate (OFSystemInfoTests) - (void)systemInfoTests; @end @interface TestsAppDelegate (OFHMACTests) - (void)HMACTests; @end @interface TestsAppDelegate (OFStreamTests) - (void)streamTests; @end @interface TestsAppDelegate (OFStringTests) - (void)stringTests; | > > > > | 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | @interface TestsAppDelegate (OFSystemInfoTests) - (void)systemInfoTests; @end @interface TestsAppDelegate (OFHMACTests) - (void)HMACTests; @end @interface TestsAppDelegate (OFSocketTests) - (void)socketTests; @end @interface TestsAppDelegate (OFStreamTests) - (void)streamTests; @end @interface TestsAppDelegate (OFStringTests) - (void)stringTests; |
︙ | ︙ | |||
276 277 278 279 280 281 282 | - (void)XMLNodeTests; @end @interface TestsAppDelegate (OFXMLParserTests) <OFXMLParserDelegate, OFXMLElementBuilderDelegate> - (void)XMLParserTests; @end | < < < < < < < < | 263 264 265 266 267 268 269 | - (void)XMLNodeTests; @end @interface TestsAppDelegate (OFXMLParserTests) <OFXMLParserDelegate, OFXMLElementBuilderDelegate> - (void)XMLParserTests; @end |
Modified tests/TestsAppDelegate.m from [0065cae80a] to [2b8f245976].
︙ | ︙ | |||
46 47 48 49 50 51 52 53 54 55 | #ifdef OF_NINTENDO_3DS /* Newer versions of libctru started using id as a parameter name. */ # define id id_3ds # include <3ds.h> # undef id #endif #ifdef OF_PSP static int | > > > > > > | | | | | > > > | > | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | #ifdef OF_NINTENDO_3DS /* Newer versions of libctru started using id as a parameter name. */ # define id id_3ds # include <3ds.h> # undef id #endif #ifdef OF_AMIGAOS extern unsigned long *OFHashSeedRef(void); #else extern unsigned long OFHashSeed; #endif #ifdef OF_PSP static int exitCallback(int arg1, int arg2, void *arg) { sceKernelExitGame(); return 0; } static int threadCallback(SceSize args, void *argp) { sceKernelRegisterExitCallback( sceKernelCreateCallback("Exit Callback", exitCallback, NULL)); sceKernelSleepThreadCB(); return 0; } #endif int main(int argc, char *argv[]) { #ifdef OF_PSP int tid; #endif #if defined(OF_OBJFW_RUNTIME) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) /* * This does not work on Win32 if ObjFW is built as a DLL. * * On AmigaOS, some destructors need to be able to send messages. * Calling objc_deinit() via atexit() would result in the runtime being * destructed before for the destructors ran. */ atexit(objc_deinit); #endif /* We need deterministic hashes for tests */ #ifdef OF_AMIGAOS *OFHashSeedRef() = 0; #else OFHashSeed = 0; #endif #ifdef OF_WII GXRModeObj *rmode; void *xfb; VIDEO_Init(); WPAD_Init(); |
︙ | ︙ | |||
116 117 118 119 120 121 122 | #ifdef OF_PSP pspDebugScreenInit(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); | | | | | | | | | | | | < | | < | | | | | < | | | | | | < | | | | | | | | | | | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | #ifdef OF_PSP pspDebugScreenInit(); sceCtrlSetSamplingCycle(0); sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL); if ((tid = sceKernelCreateThread("update_thread", threadCallback, 0x11, 0xFA0, 0, 0)) >= 0) sceKernelStartThread(tid, 0, 0); #endif #ifdef OF_NINTENDO_DS consoleDemoInit(); #endif #ifdef OF_NINTENDO_3DS gfxInitDefault(); atexit(gfxExit); consoleInit(GFX_TOP, NULL); #endif #if defined(OF_WII) || defined(OF_PSP) || defined(OF_NINTENDO_DS) || \ defined(OF_NINTENDO_3DS) @try { return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]); } @catch (id e) { OFString *string = [OFString stringWithFormat: @"\nRuntime error: Unhandled exception:\n%@\n", e]; OFString *backtrace = [OFString stringWithFormat: @"\nBacktrace:\n %@\n\n", [[e backtrace] componentsJoinedByString: @"\n "]]; [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut writeString: string]; [OFStdOut writeString: backtrace]; # if defined(OF_WII) [OFStdOut reset]; [OFStdOut writeString: @"Press home button to exit!"]; for (;;) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) [OFApplication terminateWithStatus: 1]; VIDEO_WaitVSync(); } # elif defined(OF_PSP) sceKernelSleepThreadCB(); # elif defined(OF_NINTENDO_DS) [OFStdOut reset]; [OFStdOut writeString: @"Press start button to exit!"]; for (;;) { swiWaitForVBlank(); scanKeys(); if (keysDown() & KEY_START) [OFApplication terminateWithStatus: 1]; } # elif defined(OF_NINTENDO_3DS) [OFStdOut reset]; [OFStdOut writeString: @"Press start button to exit!"]; for (;;) { hidScanInput(); if (hidKeysDown() & KEY_START) [OFApplication terminateWithStatus: 1]; gspWaitForVBlank(); } # else abort(); # endif } #else return OFApplicationMain(&argc, &argv, [[TestsAppDelegate alloc] init]); #endif } @implementation TestsAppDelegate - (void)outputTesting: (OFString *)test inModule: (OFString *)module { if (OFStdOut.hasTerminal) { [OFStdOut setForegroundColor: [OFColor yellow]]; [OFStdOut writeFormat: @"[%@] %@: testing...", module, test]; } else [OFStdOut writeFormat: @"[%@] %@: ", module, test]; } - (void)outputSuccess: (OFString *)test inModule: (OFString *)module { if (OFStdOut.hasTerminal) { [OFStdOut setForegroundColor: [OFColor lime]]; [OFStdOut eraseLine]; [OFStdOut writeFormat: @"\r[%@] %@: ok\n", module, test]; } else [OFStdOut writeLine: @"ok"]; } - (void)outputFailure: (OFString *)test inModule: (OFString *)module { if (OFStdOut.hasTerminal) { [OFStdOut setForegroundColor: [OFColor red]]; [OFStdOut eraseLine]; [OFStdOut writeFormat: @"\r[%@] %@: failed\n", module, test]; #ifdef OF_WII [OFStdOut reset]; [OFStdOut writeLine: @"Press A to continue!"]; for (;;) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) return; VIDEO_WaitVSync(); } #endif #ifdef OF_PSP [OFStdOut reset]; [OFStdOut writeLine: @"Press X to continue!"]; for (;;) { SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); if (pad.Buttons & PSP_CTRL_CROSS) { for (;;) { sceCtrlReadBufferPositive(&pad, 1); if (!(pad.Buttons & PSP_CTRL_CROSS)) return; } } } #endif #ifdef OF_NINTENDO_DS [OFStdOut reset]; [OFStdOut writeString: @"Press A to continue!"]; for (;;) { swiWaitForVBlank(); scanKeys(); if (keysDown() & KEY_A) break; } #endif #ifdef OF_NINTENDO_3DS [OFStdOut reset]; [OFStdOut writeString: @"Press A to continue!"]; for (;;) { hidScanInput(); if (hidKeysDown() & KEY_A) break; gspWaitForVBlank(); } #endif [OFStdOut writeString: @"\r"]; [OFStdOut reset]; [OFStdOut eraseLine]; } else [OFStdOut writeLine: @"failed"]; } - (void)applicationDidFinishLaunching { #if defined(OF_IOS) && defined(OF_HAVE_FILES) CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); UInt8 resourcesPath[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, true, resourcesPath, PATH_MAX)) { [OFStdErr writeString: @"Failed to locate resources!\n"]; [OFApplication terminateWithStatus: 1]; } [[OFFileManager defaultManager] changeCurrentDirectoryPath: [OFString stringWithUTF8String: (const char *)resourcesPath]]; #endif #if defined(OF_WII) && defined(OF_HAVE_FILES) |
︙ | ︙ | |||
348 349 350 351 352 353 354 | #if defined(OF_HAVE_FILES) && defined(HAVE_CODEPAGE_437) [self INIFileTests]; #endif #ifdef OF_HAVE_SOCKETS [self socketTests]; [self TCPSocketTests]; [self UDPSocketTests]; | < < < | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | #if defined(OF_HAVE_FILES) && defined(HAVE_CODEPAGE_437) [self INIFileTests]; #endif #ifdef OF_HAVE_SOCKETS [self socketTests]; [self TCPSocketTests]; [self UDPSocketTests]; # ifdef OF_HAVE_IPX [self IPXSocketTests]; [self SPXSocketTests]; [self SPXStreamSocketTests]; # endif [self kernelEventObserverTests]; #endif |
︙ | ︙ | |||
377 378 379 380 381 382 383 | [self XMLNodeTests]; [self XMLElementBuilderTests]; #ifdef OF_HAVE_FILES [self serializationTests]; #endif [self JSONTests]; [self propertyListTests]; | < < | | | | | | | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | [self XMLNodeTests]; [self XMLElementBuilderTests]; #ifdef OF_HAVE_FILES [self serializationTests]; #endif [self JSONTests]; [self propertyListTests]; #if defined(OF_HAVE_PLUGINS) [self pluginTests]; #endif #ifdef OF_WINDOWS [self windowsRegistryKeyTests]; #endif #ifdef OF_HAVE_SOCKETS [self DNSResolverTests]; #endif [self systemInfoTests]; [self localeTests]; [OFStdOut reset]; #if defined(OF_IOS) [OFStdOut writeFormat: @"%d tests failed!", _fails]; [OFApplication terminateWithStatus: _fails]; #elif defined(OF_WII) [OFStdOut writeString: @"Press home button to exit!"]; for (;;) { WPAD_ScanPads(); if (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME) [OFApplication terminateWithStatus: _fails]; VIDEO_WaitVSync(); } #elif defined(OF_PSP) [OFStdOut writeFormat: @"%d tests failed!", _fails]; sceKernelSleepThreadCB(); #elif defined(OF_NINTENDO_DS) [OFStdOut writeString: @"Press start button to exit!"]; for (;;) { swiWaitForVBlank(); scanKeys(); if (keysDown() & KEY_START) [OFApplication terminateWithStatus: _fails]; } #elif defined(OF_NINTENDO_3DS) [OFStdOut writeString: @"Press start button to exit!"]; for (;;) { hidScanInput(); if (hidKeysDown() & KEY_START) [OFApplication terminateWithStatus: _fails]; |
︙ | ︙ |
Modified tests/objc_sync/Makefile from [050b215f54] to [7453b53ff1].
1 2 3 4 5 6 7 8 9 10 11 12 13 | include ../../extra.mk PROG_NOINST = objc_sync${PROG_SUFFIX} SRCS = test.m include ../../buildsys.mk post-all: ${RUN_TESTS} .PHONY: run run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} | | > | | | > | | > | > | > | 1 2 3 4 5 6 7 8 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | include ../../extra.mk PROG_NOINST = objc_sync${PROG_SUFFIX} SRCS = test.m include ../../buildsys.mk post-all: ${RUN_TESTS} .PHONY: run run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib rm -f ${OBJFWRT_AMIGA_LIB} if test -f ../../src/libobjfw.so; then \ ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../../src/libobjfw.dylib; then \ ${LN_S} ../../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/libobjfwrt.so; then \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/${OBJFWRT_AMIGA_LIB}; then \ ${LN_S} ../../src/runtime/${OBJFWRT_AMIGA_LIB} \ ${OBJFWRT_AMIGA_LIB}; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT CPPFLAGS += -I../../src -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} |
Modified tests/plugin/TestPlugin.m from [01c39da93f] to [37c0de4e88].
︙ | ︙ | |||
24 25 26 27 28 29 30 | { Class class = objc_getClass("TestPlugin"); if (class == Nil) /* * musl has broken dlclose(): Instead of calling the destructor * on dlclose(), they call it on exit(). This of course means | | | | | | 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 | { Class class = objc_getClass("TestPlugin"); if (class == Nil) /* * musl has broken dlclose(): Instead of calling the destructor * on dlclose(), they call it on exit(). This of course means * that our tests might have already called objc_deinit() and * the class is already gone. */ return; objc_unregisterClass(class); } #endif @implementation TestPlugin - (int)test: (int)num { return num * 2; } @end id OFPluginInit(void) { return [[[TestPlugin alloc] init] autorelease]; } |
Modified tests/terminal/Makefile from [58c564f0ae] to [c978643dd3].
1 2 3 4 5 6 7 8 9 10 11 12 13 | include ../../extra.mk PROG_NOINST = terminal_tests${PROG_SUFFIX} SRCS = TerminalTests.m include ../../buildsys.mk post-all: ${RUN_TESTS} .PHONY: run run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} | | > | | | > | | > | > | > | 1 2 3 4 5 6 7 8 9 10 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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | include ../../extra.mk PROG_NOINST = terminal_tests${PROG_SUFFIX} SRCS = TerminalTests.m include ../../buildsys.mk post-all: ${RUN_TESTS} .PHONY: run run: rm -f libobjfw.so.${OBJFW_LIB_MAJOR} rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} rm -f objfw${OBJFW_LIB_MAJOR}.dll libobjfw.${OBJFW_LIB_MAJOR}.dylib rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR} rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib rm -f ${OBJFWRT_AMIGA_LIB} if test -f ../../src/libobjfw.so; then \ ${LN_S} ../../src/libobjfw.so libobjfw.so.${OBJFW_LIB_MAJOR}; \ ${LN_S} ../../src/libobjfw.so \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ elif test -f ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/libobjfw.so.${OBJFW_LIB_MAJOR_MINOR} \ libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/objfw${OBJFW_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/objfw${OBJFW_LIB_MAJOR}.dll \ objfw${OBJFW_LIB_MAJOR}.dll; \ fi if test -f ../../src/libobjfw.dylib; then \ ${LN_S} ../../src/libobjfw.dylib \ libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/libobjfwrt.so; then \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ ${LN_S} ../../src/runtime/libobjfwrt.so \ libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ elif test -f ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; then \ ${LN_S} ../../src/runtime/libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR} libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ fi if test -f ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll; then \ ${LN_S} ../../src/runtime/objfwrt${OBJFWRT_LIB_MAJOR}.dll \ objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ fi if test -f ../../src/runtime/libobjfwrt.dylib; then \ ${LN_S} ../../src/runtime/libobjfwrt.dylib \ libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ fi if test -f ../../src/runtime/${OBJFWRT_AMIGA_LIB}; then \ ${LN_S} ../../src/runtime/${OBJFWRT_AMIGA_LIB} \ ${OBJFWRT_AMIGA_LIB}; \ fi LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ LIBRARY_PATH=.$${LIBRARY_PATH+:}$$LIBRARY_PATH \ ${WRAPPER} ./${PROG_NOINST}; EXIT=$$?; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR}; \ rm -f libobjfw.so.${OBJFW_LIB_MAJOR_MINOR}; \ rm -f objfw${OBJFW_LIB_MAJOR}.dll; \ rm -f libobjfw.${OBJFW_LIB_MAJOR}.dylib; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR}; \ rm -f libobjfwrt.so.${OBJFWRT_LIB_MAJOR_MINOR}; \ rm -f objfwrt${OBJFWRT_LIB_MAJOR}.dll; \ rm -f libobjfwrt.${OBJFWRT_LIB_MAJOR}.dylib; \ exit $$EXIT CPPFLAGS += -I../../src -I../../src/exceptions -I../../src/runtime -I../.. LIBS := -L../../src -lobjfw -L../../src/runtime ${RUNTIME_LIBS} ${LIBS} LD = ${OBJC} |
Modified tests/terminal/TerminalTests.m from [cd3ec05bca] to [edc6e4e174].
︙ | ︙ | |||
34 35 36 37 38 39 40 | [OFColor maroon], [OFColor red], [OFColor purple], [OFColor fuchsia], [OFColor green], [OFColor lime], [OFColor olive], [OFColor yellow], [OFColor navy], [OFColor blue], [OFColor teal], [OFColor aqua], nil]; size_t i; OFEnumerator OF_GENERIC(OFColor *) *reverseEnumerator; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | [OFColor maroon], [OFColor red], [OFColor purple], [OFColor fuchsia], [OFColor green], [OFColor lime], [OFColor olive], [OFColor yellow], [OFColor navy], [OFColor blue], [OFColor teal], [OFColor aqua], nil]; size_t i; OFEnumerator OF_GENERIC(OFColor *) *reverseEnumerator; [OFStdOut writeFormat: @"%dx%d\n", OFStdOut.columns, OFStdOut.rows]; i = 0; for (OFColor *color in colors) { [OFStdOut setForegroundColor: color]; [OFStdOut writeFormat: @"%zx", i++]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; i = 0; for (OFColor *color in colors) { [OFStdOut setBackgroundColor: color]; [OFStdOut writeFormat: @"%zx", i++]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; i = 0; reverseEnumerator = [colors.reversedArray objectEnumerator]; for (OFColor *color in colors) { [OFStdOut setForegroundColor: color]; [OFStdOut setBackgroundColor: [reverseEnumerator nextObject]]; [OFStdOut writeFormat: @"%zx", i++]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; for (i = 0; i < colors.count * 2; i++) { if (i % 2) [OFStdOut setBackgroundColor: [colors objectAtIndex: ((i / 2) + 2) % colors.count]]; else [OFStdOut setForegroundColor: [colors objectAtIndex: i / 2]]; [OFStdOut writeFormat: @"%zx", i / 2]; } [OFStdOut reset]; [OFStdOut writeLine: @"R"]; [OFStdOut writeLine: @"Press return"]; [OFStdIn readLine]; [OFStdOut setBackgroundColor: [OFColor green]]; [OFStdOut writeString: @"Hello!"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut eraseLine]; [OFStdOut writeString: @"World!"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut clear]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setCursorPosition: OFPointMake(5, 3)]; [OFStdOut writeString: @"Text at (5, 3)"]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFPointMake(-2, 0)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFPointMake(2, 0)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFPointMake(0, -2)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFPointMake(0, 2)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFPointMake(1, 1)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setRelativeCursorPosition: OFPointMake(-1, -1)]; [OFThread sleepForTimeInterval: 2]; [OFStdOut setCursorColumn: 2]; [OFThread sleepForTimeInterval: 2]; [OFStdOut reset]; [OFApplication terminate]; } @end |
Modified utils/Makefile from [82be3d0820] to [521b7f89ce].
1 2 3 4 5 6 | include ../extra.mk SUBDIRS += ${OFARC} \ ${OFDNS} \ ${OFHASH} \ ${OFHTTP} \ | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 | include ../extra.mk SUBDIRS += ${OFARC} \ ${OFDNS} \ ${OFHASH} \ ${OFHTTP} \ completions include ../buildsys.mk DISTCLEAN = objfw-config install-extra: objfw-config objfw-compile objfw-new |
︙ | ︙ |
Modified utils/ofarc/Archive.h from [2900eb7128] to [c76a3f3daa].
︙ | ︙ | |||
16 17 18 19 20 21 22 | #import "OFObject.h" #import "OFFile.h" #import "OFArray.h" @protocol Archive <OFObject> + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode | | | | 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #import "OFObject.h" #import "OFFile.h" #import "OFArray.h" @protocol Archive <OFObject> + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding; - (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding; - (void)listFiles; - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files; - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files; @optional - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files; @end |
Modified utils/ofarc/GZIPArchive.m from [a9786ac1f4] to [5f3f952774].
︙ | ︙ | |||
26 27 28 29 30 31 32 | static OFArc *app; static void setPermissions(OFString *destination, OFString *source) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFFileManager *fileManager = [OFFileManager defaultManager]; | | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | static OFArc *app; static void setPermissions(OFString *destination, OFString *source) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFFileManager *fileManager = [OFFileManager defaultManager]; OFFileAttributes attributes = [fileManager attributesOfItemAtPath: source]; OFFileAttributeKey key = OFFilePOSIXPermissions; OFFileAttributes destinationAttributes = [OFDictionary dictionaryWithObject: [attributes objectForKey: key] forKey: key]; [fileManager setAttributes: destinationAttributes ofItemAtPath: destination]; #endif } static void setModificationDate(OFString *path, OFGZIPStream *stream) { OFDate *modificationDate = stream.modificationDate; OFFileAttributes attributes; if (modificationDate == nil) return; attributes = [OFDictionary dictionaryWithObject: modificationDate forKey: OFFileModificationDate]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @implementation GZIPArchive + (void)initialize { if (self == [GZIPArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithStream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _stream = [[OFGZIPStream alloc] initWithStream: stream mode: mode]; } @catch (id e) { |
︙ | ︙ | |||
96 97 98 99 100 101 102 | [_stream release]; [super dealloc]; } - (void)listFiles { | | | | | < | < | | | | | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | [_stream release]; [super dealloc]; } - (void)listFiles { [OFStdErr writeLine: OF_LOCALIZED(@"cannot_list_gz", @"Cannot list files of a .gz archive!")]; app->_exitStatus = 1; } - (void)extractFiles: (OFArray OF_GENERIC(OFString *) *)files { OFString *fileName; OFFile *output; if (files.count != 0) { [OFStdErr writeLine: OF_LOCALIZED(@"cannot_extract_specific_file_from_gz", @"Cannot extract a specific file of a .gz archive!")]; app->_exitStatus = 1; return; } fileName = app->_archivePath.lastPathComponent .stringByDeletingPathExtension; if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if (![app shouldExtractFile: fileName outFileName: fileName]) return; output = [OFFile fileWithPath: fileName mode: @"w"]; setPermissions(fileName, app->_archivePath); while (!_stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: _stream toStream: output fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [output close]; setModificationDate(fileName, _stream); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED(@"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files { OFString *fileName = app->_archivePath.lastPathComponent .stringByDeletingPathExtension; if (files.count > 0) { [OFStdErr writeLine: OF_LOCALIZED( @"cannot_print_specific_file_from_gz", @"Cannot print a specific file of a .gz archive!")]; app->_exitStatus = 1; return; } while (!_stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: _stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } } @end |
Modified utils/ofarc/LHAArchive.m from [3021725523] to [051184aa1d].
︙ | ︙ | |||
44 45 46 47 48 49 50 | if (mode == nil) return; mode = [OFNumber numberWithUnsignedShort: mode.unsignedShortValue & 0777]; | | | | | | | | | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | if (mode == nil) return; mode = [OFNumber numberWithUnsignedShort: mode.unsignedShortValue & 0777]; OFFileAttributes attributes = [OFDictionary dictionaryWithObject: mode forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; #endif } static void setModificationDate(OFString *path, OFLHAArchiveEntry *entry) { OFDate *modificationDate = entry.modificationDate; OFFileAttributes attributes; if (modificationDate == nil) { /* * Fall back to the original date if we have no modification * date, as the modification date is a UNIX extension. */ modificationDate = entry.date; if (modificationDate == nil) return; } attributes = [OFDictionary dictionaryWithObject: modificationDate forKey: OFFileModificationDate]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @implementation LHAArchive + (void)initialize { if (self == [LHAArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithStream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [[OFLHAArchive alloc] initWithStream: stream mode: mode]; if (encoding != OFStringEncodingAutodetect) _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ | |||
127 128 129 130 131 132 133 | - (void)listFiles { OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | - (void)listFiles { OFLHAArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *date = [entry.date localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu32, entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu32, entry.uncompressedSize]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", entry.compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc16", @"CRC16: %[crc16]", @"crc16", CRC16)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_date", @"Date: %[date]", @"date", date)]; if (entry.mode != nil) { OFString *modeString = [OFString stringWithFormat: @"%ho", entry.mode.unsignedShortValue]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_mode", @"Mode: %[mode]", @"mode", modeString)]; } if (entry.UID != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_uid", @"UID: %[uid]", @"uid", entry.UID)]; } if (entry.GID != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_gid", @"GID: %[gid]", @"gid", entry.GID)]; } if (entry.owner != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner", @"Owner: %[owner]", @"owner", entry.owner)]; } if (entry.group != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group", @"Group: %[group]", @"group", entry.group)]; } if (app->_outputLevel >= 2) { OFString *headerLevel = [OFString stringWithFormat: @"%" PRIu8, entry.headerLevel]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_header_level", @"Header level: %[level]", @"level", headerLevel)]; if (entry.operatingSystemIdentifier != '\0') { OFString *OSID = [OFString stringWithFormat: @"%c", entry.operatingSystemIdentifier]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_osid", @"Operating system identifier: " "%[osid]", @"osid", OSID)]; } if (entry.modificationDate != nil) { OFString *modificationDate = entry.modificationDate.description; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; } } if (app->_outputLevel >= 3) { OFString *extensions = indent(entry.extensions.description); [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_extensions", @"Extensions: %[extensions]", @"extensions", extensions)]; } } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
288 289 290 291 292 293 294 | if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { | | | | | | < | < | 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if ([fileName hasSuffix: @"/"]) { [fileManager createDirectoryAtPath: outFileName createParents: true]; setPermissions(outFileName, entry); setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } goto outer_loop_end; } directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; |
︙ | ︙ | |||
354 355 356 357 358 359 360 | if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; | | | | | | | | | | | | | | | | | | | | | | 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } if (missing.count > 0) { for (OFString *file in missing) [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFLHAArchiveEntry *entry; if (files_.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { OFString *fileName = entry.fileName; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [files removeObject: fileName]; [stream close]; if (files.count == 0) break; } for (OFString *file in files) { [OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; if (files.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } for (OFString *fileName in files) { void *pool = objc_autoreleasePoolPush(); OFFileAttributes attributes; OFFileAttributeType type; OFMutableLHAArchiveEntry *entry; OFStream *output; if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableLHAArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS entry.mode = [OFNumber numberWithUnsignedLong: attributes.filePOSIXPermissions]; #endif entry.date = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER entry.UID = [OFNumber numberWithUnsignedLong: attributes.fileOwnerAccountID]; entry.GID = [OFNumber numberWithUnsignedLong: attributes.fileGroupOwnerAccountID]; entry.owner = attributes.fileOwnerAccountName; entry.group = attributes.fileGroupOwnerAccountName; #endif if ([type isEqual: OFFileTypeDirectory]) entry.compressionMethod = @"-lhd-"; output = [_archive streamForWritingEntry: entry]; if ([type isEqual: OFFileTypeRegular]) { unsigned long long written = 0; unsigned long long size = attributes.fileSize; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; |
︙ | ︙ | |||
516 517 518 519 520 521 522 | percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; | | | | | | 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 | percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; |
︙ | ︙ |
Modified utils/ofarc/OFArc.h from [535da98fc8] to [f6ae34fcaa].
︙ | ︙ | |||
35 36 37 38 39 40 41 | OFString *_archivePath; int _exitStatus; } - (id <Archive>)openArchiveWithPath: (OFString *)path type: (OFString *)type mode: (char)mode | | | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | OFString *_archivePath; int _exitStatus; } - (id <Archive>)openArchiveWithPath: (OFString *)path type: (OFString *)type mode: (char)mode encoding: (OFStringEncoding)encoding; - (bool)shouldExtractFile: (OFString *)fileName outFileName: (OFString *)outFileName; - (ssize_t)copyBlockFromStream: (OFStream *)input toStream: (OFStream *)output fileName: (OFString *)fileName; - (nullable OFString *)safeLocalPathForPath: (OFString *)path; @end |
︙ | ︙ |
Modified utils/ofarc/OFArc.m from [a6b651554f] to [84fac1d63f].
︙ | ︙ | |||
38 39 40 41 42 43 44 | #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" #import "OFSeekFailedException.h" #import "OFWriteFailedException.h" | | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" #import "OFSeekFailedException.h" #import "OFWriteFailedException.h" #define bufferSize 4096 OF_APPLICATION_DELEGATE(OFArc) static void help(OFStream *stream, bool full, int status) { [stream writeLine: OF_LOCALIZED(@"usage", |
︙ | ︙ | |||
77 78 79 80 81 82 83 | @" -x --extract Extract files")]; } [OFApplication terminateWithStatus: status]; } static void | | | | | | | | | | | | | | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | @" -x --extract Extract files")]; } [OFApplication terminateWithStatus: status]; } static void mutuallyExclusiveError(OFUnichar shortOption1, OFString *longOption1, OFUnichar shortOption2, OFString *longOption2) { OFString *shortOption1Str = [OFString stringWithFormat: @"%C", shortOption1]; OFString *shortOption2Str = [OFString stringWithFormat: @"%C", shortOption2]; [OFStdErr writeLine: OF_LOCALIZED(@"2_options_mutually_exclusive", @"Error: -%[shortopt1] / --%[longopt1] and " @"-%[shortopt2] / --%[longopt2] " @"are mutually exclusive!", @"shortopt1", shortOption1Str, @"longopt1", longOption1, @"shortopt2", shortOption2Str, @"longopt2", longOption2)]; [OFApplication terminateWithStatus: 1]; } static void mutuallyExclusiveError5(OFUnichar shortOption1, OFString *longOption1, OFUnichar shortOption2, OFString *longOption2, OFUnichar shortOption3, OFString *longOption3, OFUnichar shortOption4, OFString *longOption4, OFUnichar shortOption5, OFString *longOption5) { OFString *shortOption1Str = [OFString stringWithFormat: @"%C", shortOption1]; OFString *shortOption2Str = [OFString stringWithFormat: @"%C", shortOption2]; OFString *shortOption3Str = [OFString stringWithFormat: @"%C", shortOption3]; OFString *shortOption4Str = [OFString stringWithFormat: @"%C", shortOption4]; OFString *shortOption5Str = [OFString stringWithFormat: @"%C", shortOption5]; [OFStdErr writeLine: OF_LOCALIZED(@"5_options_mutually_exclusive", @"Error: -%[shortopt1] / --%[longopt1], " @"-%[shortopt2] / --%[longopt2], -%[shortopt3] / --%[longopt3], " @"-%[shortopt4] / --%[longopt4] and\n" @" -%[shortopt5] / --%[longopt5] are mutually exclusive!", @"shortopt1", shortOption1Str, @"longopt1", longOption1, @"shortopt2", shortOption2Str, @"longopt2", longOption2, @"shortopt3", shortOption3Str, @"longopt3", longOption3, @"shortopt4", shortOption4Str, @"longopt4", longOption4, @"shortopt5", shortOption5Str, @"longopt5", longOption5)]; [OFApplication terminateWithStatus: 1]; } static void writingNotSupported(OFString *type) { [OFStdErr writeLine: OF_LOCALIZED( @"writing_not_supported", @"Writing archives of type %[type] is not (yet) supported!", @"type", type)]; } @implementation OFArc - (void)applicationDidFinishLaunching { OFString *outputDir, *encodingString, *type; const OFOptionsParserOption options[] = { { 'a', @"append", 0, NULL, NULL }, { 'c', @"create", 0, NULL, NULL }, { 'C', @"directory", 1, NULL, &outputDir }, { 'E', @"encoding", 1, NULL, &encodingString }, { 'f', @"force", 0, NULL, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'l', @"list", 0, NULL, NULL }, { 'n', @"no-clobber", 0, NULL, NULL }, { 'p', @"print", 0, NULL, NULL }, { 'q', @"quiet", 0, NULL, NULL }, { 't', @"type", 1, NULL, &type }, { 'v', @"verbose", 0, NULL, NULL }, { 'x', @"extract", 0, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFUnichar option, mode = '\0'; OFStringEncoding encoding = OFStringEncodingAutodetect; OFOptionsParser *optionsParser; OFArray OF_GENERIC(OFString *) *remainingArguments, *files; id <Archive> archive; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsWritingFiles = true; sandbox.allowsCreatingFiles = true; sandbox.allowsChangingFileAttributes = true; sandbox.allowsUserDatabaseReading = true; /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; #else [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofarc/lang"]; #endif |
︙ | ︙ | |||
234 235 236 237 238 239 240 | 'l', @"list", 'p', @"print", 'x', @"extract"); mode = option; break; case 'h': | | | | | | | | | | | | < | | | | | | | | | < | | > > > > | < | | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | 'l', @"list", 'p', @"print", 'x', @"extract"); mode = option; break; case 'h': help(OFStdOut, true, 0); break; case '=': [OFStdErr writeLine: OF_LOCALIZED( @"option_takes_no_argument", @"%[prog]: Option --%[opt] takes no argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; [OFApplication terminateWithStatus: 1]; break; case ':': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"long_option_requires_argument", @"%[prog]: Option --%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"option_requires_argument", @"%[prog]: Option -%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } @try { if (encodingString != nil) encoding = OFStringEncodingParseName(encodingString); } @catch (OFInvalidArgumentException *e) { [OFStdErr writeLine: OF_LOCALIZED( @"invalid_encoding", @"%[prog]: Invalid encoding: %[encoding]", @"prog", [OFApplication programName], @"encoding", encodingString)]; [OFApplication terminateWithStatus: 1]; } remainingArguments = optionsParser.remainingArguments; switch (mode) { case 'a': case 'c': if (remainingArguments.count < 1) help(OFStdErr, false, 1); files = [remainingArguments objectsInRange: OFRangeMake(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX if (![remainingArguments.firstObject isEqual: @"-"]) [sandbox unveilPath: remainingArguments.firstObject permissions: (mode == 'a' ? @"rwc" : @"wc")]; for (OFString *path in files) [sandbox unveilPath: path permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif archive = [self openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; [archive addFiles: files]; break; case 'l': if (remainingArguments.count != 1) help(OFStdErr, false, 1); #ifdef OF_HAVE_SANDBOX if (![remainingArguments.firstObject isEqual: @"-"]) [sandbox unveilPath: remainingArguments.firstObject permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif archive = [self openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; [archive listFiles]; break; case 'p': if (remainingArguments.count < 1) help(OFStdErr, false, 1); #ifdef OF_HAVE_SANDBOX if (![remainingArguments.firstObject isEqual: @"-"]) [sandbox unveilPath: remainingArguments.firstObject permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif files = [remainingArguments objectsInRange: OFRangeMake(1, remainingArguments.count - 1)]; archive = [self openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; [archive printFiles: files]; break; case 'x': if (remainingArguments.count < 1) help(OFStdErr, false, 1); files = [remainingArguments objectsInRange: OFRangeMake(1, remainingArguments.count - 1)]; #ifdef OF_HAVE_SANDBOX if (![remainingArguments.firstObject isEqual: @"-"]) [sandbox unveilPath: remainingArguments.firstObject permissions: @"r"]; if (files.count > 0) for (OFString *path in files) [sandbox unveilPath: path permissions: @"wc"]; else { OFString *path = outputDir; if (path == nil) path = [[OFFileManager defaultManager] currentDirectoryPath]; /* We need 'r' to change the directory to it. */ [sandbox unveilPath: path permissions: @"rwc"]; } sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif archive = [self openArchiveWithPath: remainingArguments.firstObject type: type mode: mode encoding: encoding]; |
︙ | ︙ | |||
431 432 433 434 435 436 437 | @try { [archive extractFiles: files]; } @catch (OFCreateDirectoryFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; | | | | | | | | 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | @try { [archive extractFiles: files]; } @catch (OFCreateDirectoryFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_create_directory", @"Failed to create directory %[dir]: %[error]", @"dir", e.URL.fileSystemRepresentation, @"error", error)]; _exitStatus = 1; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", e.path, @"error", error)]; _exitStatus = 1; } break; default: help(OFStdErr, true, 1); break; } [OFApplication terminateWithStatus: _exitStatus]; } - (id <Archive>)openArchiveWithPath: (OFString *)path type: (OFString *)type mode: (char)mode encoding: (OFStringEncoding)encoding { OFString *modeString, *fileModeString; OFStream *file = nil; id <Archive> archive = nil; [_archivePath release]; _archivePath = [path copy]; |
︙ | ︙ | |||
496 497 498 499 500 501 502 | @throw [OFInvalidArgumentException exception]; } if ([path isEqual: @"-"]) { switch (mode) { case 'a': case 'c': | | | | < | | | 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 | @throw [OFInvalidArgumentException exception]; } if ([path isEqual: @"-"]) { switch (mode) { case 'a': case 'c': file = OFStdOut; break; case 'l': case 'p': case 'x': file = OFStdIn; break; default: @throw [OFInvalidArgumentException exception]; } } else { @try { file = [OFFile fileWithPath: path mode: fileModeString]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", e.path, @"error", error)]; [OFApplication terminateWithStatus: 1]; } } |
︙ | ︙ | |||
564 565 566 567 568 569 570 | mode: modeString encoding: encoding]; } else if ([type isEqual: @"zip"]) archive = [ZIPArchive archiveWithStream: file mode: modeString encoding: encoding]; else { | | | | | | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | mode: modeString encoding: encoding]; } else if ([type isEqual: @"zip"]) archive = [ZIPArchive archiveWithStream: file mode: modeString encoding: encoding]; else { [OFStdErr writeLine: OF_LOCALIZED( @"unknown_archive_type", @"Unknown archive type: %[type]", @"type", type)]; goto error; } } @catch (OFNotImplementedException *e) { if ((mode == 'a' || mode == 'c') && sel_isEqual(e.selector, @selector(initWithStream:mode:))) { writingNotSupported(type); goto error; } @throw e; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", path, @"error", error)]; goto error; } @catch (OFSeekFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_seek_in_file", @"Failed to seek in file %[file]: %[error]", @"file", path, @"error", error)]; goto error; } @catch (OFInvalidFormatException *e) { [OFStdErr writeLine: OF_LOCALIZED( @"file_is_not_a_valid_archive", @"File %[file] is not a valid archive!", @"file", path)]; goto error; } if ((mode == 'a' || mode == 'c') && |
︙ | ︙ | |||
631 632 633 634 635 636 637 | if (_overwrite == 1 || ![[OFFileManager defaultManager] fileExistsAtPath: outFileName]) return true; if (_overwrite == -1) { if (_outputLevel >= 0) { | | | | | | | | | | | | < | | | < | | | 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 | if (_overwrite == 1 || ![[OFFileManager defaultManager] fileExistsAtPath: outFileName]) return true; if (_overwrite == -1) { if (_outputLevel >= 0) { [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED(@"file_skipped", @"skipped")]; } return false; } do { [OFStdErr writeString: @"\r"]; [OFStdErr writeString: OF_LOCALIZED(@"ask_overwrite", @"Overwrite %[file]? [ynAN?]", @"file", fileName)]; [OFStdErr writeString: @" "]; line = [OFStdIn readLine]; if ([line isEqual: @"?"]) [OFStdErr writeLine: OF_LOCALIZED( @"ask_overwrite_help", @" y: yes\n" @" n: no\n" @" A: always\n" @" N: never")]; } while (![line isEqual: @"y"] && ![line isEqual: @"n"] && ![line isEqual: @"N"] && ![line isEqual: @"A"]); if ([line isEqual: @"A"]) _overwrite = 1; else if ([line isEqual: @"N"]) _overwrite = -1; if ([line isEqual: @"n"] || [line isEqual: @"N"]) { if (_outputLevel >= 0) [OFStdOut writeLine: OF_LOCALIZED(@"skipping_file", @"Skipping %[file]...", @"file", fileName)]; return false; } if (_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; return true; } - (ssize_t)copyBlockFromStream: (OFStream *)input toStream: (OFStream *)output fileName: (OFString *)fileName { char buffer[bufferSize]; size_t length; @try { length = [input readIntoBuffer: buffer length: bufferSize]; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdOut writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_read_file", @"Failed to read file %[file]: %[error]", @"file", fileName, @"error", error)]; return -1; } @try { [output writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdOut writeString: @"\r"]; [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_write_file", @"Failed to write file %[file]: %[error]", @"file", fileName, @"error", error)]; return -1; } return length; |
︙ | ︙ |
Modified utils/ofarc/TarArchive.m from [5f80d4f8b1] to [a19def56d5].
︙ | ︙ | |||
30 31 32 33 34 35 36 | static OFArc *app; static void setPermissions(OFString *path, OFTarArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFNumber *mode = [OFNumber numberWithUnsignedShort: entry.mode & 0777]; | | | | | | | | | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | static OFArc *app; static void setPermissions(OFString *path, OFTarArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS OFNumber *mode = [OFNumber numberWithUnsignedShort: entry.mode & 0777]; OFFileAttributes attributes = [OFDictionary dictionaryWithObject: mode forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; #endif } static void setModificationDate(OFString *path, OFTarArchiveEntry *entry) { OFDate *modificationDate = entry.modificationDate; OFFileAttributes attributes; if (modificationDate == nil) return; attributes = [OFDictionary dictionaryWithObject: modificationDate forKey: OFFileModificationDate]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @implementation TarArchive + (void)initialize { if (self == [TarArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithStream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [[OFTarArchive alloc] initWithStream: stream mode: mode]; if (encoding != OFStringEncodingAutodetect) _archive.encoding = encoding; } @catch (id e) { [self release]; @throw e; } return self; |
︙ | ︙ | |||
105 106 107 108 109 110 111 | - (void)listFiles { OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | - (void)listFiles { OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *date = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *size = [OFString stringWithFormat: @"%" PRIu64, entry.size]; OFString *mode = [OFString stringWithFormat: @"%06o", entry.mode]; OFString *UID = [OFString stringWithFormat: @"%u", entry.UID]; OFString *GID = [OFString stringWithFormat: @"%u", entry.GID]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_size", @"[" @" 'Size: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", size)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_mode", @"Mode: %[mode]", @"mode", mode)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_uid", @"UID: %[uid]", @"uid", UID)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_gid", @"GID: %[gid]", @"gid", GID)]; if (entry.owner != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_owner", @"Owner: %[owner]", @"owner", entry.owner)]; } if (entry.group != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_group", @"Group: %[group]", @"group", entry.group)]; } [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", date)]; } if (app->_outputLevel >= 2) { [OFStdOut writeString: @"\t"]; switch (entry.type) { case OFTarArchiveEntryTypeFile: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_normal", @"Type: Normal file")]; break; case OFTarArchiveEntryTypeLink: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_hardlink", @"Type: Hard link")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_link_target", @"Target file name: %[target]", @"target", entry.targetFileName)]; break; case OFTarArchiveEntryTypeSymlink: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_symlink", @"Type: Symbolic link")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_link_target", @"Target file name: %[target]", @"target", entry.targetFileName)]; break; case OFTarArchiveEntryTypeCharacterDevice: { OFString *majorString = [OFString stringWithFormat: @"%d", entry.deviceMajor]; OFString *minorString = [OFString stringWithFormat: @"%d", entry.deviceMinor]; [OFStdOut writeLine: OF_LOCALIZED( @"list_type_character_device", @"Type: Character device")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_major", @"Device major: %[major]", @"major", majorString)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_minor", @"Device minor: %[minor]", @"minor", minorString)]; break; } case OFTarArchiveEntryTypeBlockDevice: { OFString *majorString = [OFString stringWithFormat: @"%d", entry.deviceMajor]; OFString *minorString = [OFString stringWithFormat: @"%d", entry.deviceMinor]; [OFStdOut writeLine: OF_LOCALIZED( @"list_type_block_device", @"Type: Block device")]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_major", @"Device major: %[major]", @"major", majorString)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_device_minor", @"Device minor: %[minor]", @"minor", minorString)]; break; } case OFTarArchiveEntryTypeDirectory: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_directory", @"Type: Directory")]; break; case OFTarArchiveEntryTypeFIFO: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_fifo", @"Type: FIFO")]; break; case OFTarArchiveEntryTypeContiguousFile: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_contiguous_file", @"Type: Contiguous file")]; break; default: [OFStdOut writeLine: OF_LOCALIZED( @"list_type_unknown", @"Type: Unknown")]; break; } } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
273 274 275 276 277 278 279 | OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; | | | | | | | | | | | | < | < | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | OFMutableSet OF_GENERIC(OFString *) *missing = [OFMutableSet setWithArray: files]; OFTarArchiveEntry *entry; while ((entry = [_archive nextEntry]) != nil) { void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFTarArchiveEntryType type = entry.type; OFString *outFileName, *directory; OFFile *output; OFStream *stream; uint64_t written = 0, size = entry.size; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; if (type != OFTarArchiveEntryTypeFile && type != OFTarArchiveEntryTypeDirectory) { if (app->_outputLevel >= 0) [OFStdOut writeLine: OF_LOCALIZED( @"skipping_file", @"Skipping %[file]...", @"file", fileName)]; continue; } [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if (type == OFTarArchiveEntryTypeDirectory || (type == OFTarArchiveEntryTypeFile && [fileName hasSuffix: @"/"])) { [fileManager createDirectoryAtPath: outFileName createParents: true]; setPermissions(outFileName, entry); setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } goto outer_loop_end; } directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingCurrentEntry]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; |
︙ | ︙ | |||
365 366 367 368 369 370 371 | if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; | | | | | | | | | | | | | | | | | | | | | | | | | 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 | if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } if (missing.count > 0) { for (OFString *file in missing) [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files_ { OFMutableSet *files; OFTarArchiveEntry *entry; if (files_.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } files = [OFMutableSet setWithArray: files_]; while ((entry = [_archive nextEntry]) != nil) { OFString *fileName = entry.fileName; OFStream *stream; if (![files containsObject: fileName]) continue; stream = [_archive streamForReadingCurrentEntry]; while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: fileName]; if (length < 0) { app->_exitStatus = 1; return; } } [files removeObject: fileName]; [stream close]; if (files.count == 0) break; } for (OFString *file in files) { [OFStdErr writeLine: OF_LOCALIZED(@"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; if (files.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } for (OFString *fileName in files) { void *pool = objc_autoreleasePoolPush(); OFFileAttributes attributes; OFFileAttributeType type; OFMutableTarArchiveEntry *entry; OFStream *output; if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; attributes = [fileManager attributesOfItemAtPath: fileName]; type = attributes.fileType; entry = [OFMutableTarArchiveEntry entryWithFileName: fileName]; #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS entry.mode = attributes.filePOSIXPermissions; #endif entry.size = attributes.fileSize; entry.modificationDate = attributes.fileModificationDate; #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER entry.UID = attributes.fileOwnerAccountID; entry.GID = attributes.fileGroupOwnerAccountID; entry.owner = attributes.fileOwnerAccountName; entry.group = attributes.fileGroupOwnerAccountName; #endif if ([type isEqual: OFFileTypeRegular]) entry.type = OFTarArchiveEntryTypeFile; else if ([type isEqual: OFFileTypeDirectory]) { entry.type = OFTarArchiveEntryTypeDirectory; entry.size = 0; } else if ([type isEqual: OFFileTypeSymbolicLink]) { entry.type = OFTarArchiveEntryTypeSymlink; entry.targetFileName = attributes.fileSymbolicLinkDestination; entry.size = 0; } [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; if (entry.type == OFTarArchiveEntryTypeFile) { uint64_t written = 0, size = entry.size; int8_t percent = -1, newPercent; OFFile *input = [OFFile fileWithPath: fileName mode: @"r"]; while (!input.atEndOfStream) { |
︙ | ︙ | |||
535 536 537 538 539 540 541 | percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; | | | | | | 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; |
︙ | ︙ |
Modified utils/ofarc/ZIPArchive.m from [c58060c45a] to [6b1b9a0f7a].
︙ | ︙ | |||
37 38 39 40 41 42 43 | static OFArc *app; static void setPermissions(OFString *path, OFZIPArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS if ((entry.versionMadeBy >> 8) == | | < < | | | | | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | static OFArc *app; static void setPermissions(OFString *path, OFZIPArchiveEntry *entry) { #ifdef OF_FILE_MANAGER_SUPPORTS_PERMISSIONS if ((entry.versionMadeBy >> 8) == OFZIPArchiveEntryAttributeCompatibilityUNIX) { OFNumber *mode = [OFNumber numberWithUnsignedShort: (entry.versionSpecificAttributes >> 16) & 0777]; OFFileAttributes attributes = [OFDictionary dictionaryWithObject: mode forKey: OFFilePOSIXPermissions]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } #endif } static void setModificationDate(OFString *path, OFZIPArchiveEntry *entry) { OFDate *modificationDate = entry.modificationDate; OFFileAttributes attributes; if (modificationDate == nil) return; attributes = [OFDictionary dictionaryWithObject: modificationDate forKey: OFFileModificationDate]; [[OFFileManager defaultManager] setAttributes: attributes ofItemAtPath: path]; } @implementation ZIPArchive + (void)initialize { if (self == [ZIPArchive class]) app = (OFArc *)[OFApplication sharedApplication].delegate; } + (instancetype)archiveWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { return [[[self alloc] initWithStream: stream mode: mode encoding: encoding] autorelease]; } - (instancetype)initWithStream: (OF_KINDOF(OFStream *))stream mode: (OFString *)mode encoding: (OFStringEncoding)encoding { self = [super init]; @try { _archive = [[OFZIPArchive alloc] initWithStream: stream mode: mode]; } @catch (id e) { |
︙ | ︙ | |||
113 114 115 116 117 118 119 | } - (void)listFiles { for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); | | | | | | | | | | | | | > > | | | | | | | < | | | | | | | | | 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | } - (void)listFiles { for (OFZIPArchiveEntry *entry in _archive.entries) { void *pool = objc_autoreleasePoolPush(); [OFStdOut writeLine: entry.fileName]; if (app->_outputLevel >= 1) { OFString *compressedSize = [OFString stringWithFormat: @"%" PRIu64, entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: @"%" PRIu64, entry.uncompressedSize]; OFString *compressionMethod = OFZIPArchiveEntryCompressionMethodName( entry.compressionMethod); OFString *CRC32 = [OFString stringWithFormat: @"%08" PRIX32, entry.CRC32]; OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compressed_size", @"[" @" 'Compressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", compressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_uncompressed_size", @"[" @" 'Uncompressed: '," @" [" @" {'size == 1': '1 byte'}," @" {'': '%[size] bytes'}" @" ]" @"]".objectByParsingJSON, @"size", uncompressedSize)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_compression_method", @"Compression method: %[method]", @"method", compressionMethod)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED(@"list_crc32", @"CRC32: %[crc32]", @"crc32", CRC32)]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_modification_date", @"Modification date: %[date]", @"date", modificationDate)]; if (app->_outputLevel >= 2) { uint16_t versionMadeBy = entry.versionMadeBy; OFZIPArchiveEntryAttributeCompatibility UNIX = OFZIPArchiveEntryAttributeCompatibilityUNIX; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_version_made_by", @"Version made by: %[version]", @"version", OFZIPArchiveEntryVersionToString( versionMadeBy))]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_min_version_needed", @"Minimum version needed: %[version]", @"version", OFZIPArchiveEntryVersionToString( entry.minVersionNeeded))]; if ((versionMadeBy >> 8) == UNIX) { uint32_t mode = entry .versionSpecificAttributes >> 16; OFString *modeString = [OFString stringWithFormat: @"%06o", mode]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_mode", @"Mode: %[mode]", @"mode", modeString)]; } } if (app->_outputLevel >= 3) { OFString *GPBF = [OFString stringWithFormat: @"%04" PRIx16, entry.generalPurposeBitFlag]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_general_purpose_bit_flag", @"General purpose bit flag: %[gpbf]", @"gpbf", GPBF)]; if (entry.extraField != nil) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_extra_field", @"Extra field: %[extra]", @"extra", entry.extraField.description)]; } } if (entry.fileComment.length > 0) { [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @"list_comment", @"Comment: %[comment]", @"comment", entry.fileComment)]; } } objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
255 256 257 258 259 260 261 | if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { | | | | | | < | < | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | if (!all && ![files containsObject: fileName]) continue; [missing removeObject: fileName]; outFileName = [app safeLocalPathForPath: fileName]; if (outFileName == nil) { [OFStdErr writeLine: OF_LOCALIZED( @"refusing_to_extract_file", @"Refusing to extract %[file]!", @"file", fileName)]; app->_exitStatus = 1; goto outer_loop_end; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"extracting_file", @"Extracting %[file]...", @"file", fileName)]; if ([fileName hasSuffix: @"/"]) { [fileManager createDirectoryAtPath: outFileName createParents: true]; setPermissions(outFileName, entry); setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } goto outer_loop_end; } directory = outFileName.stringByDeletingLastPathComponent; if (![fileManager directoryExistsAtPath: directory]) [fileManager createDirectoryAtPath: directory createParents: true]; if (![app shouldExtractFile: fileName outFileName: outFileName]) goto outer_loop_end; stream = [_archive streamForReadingFile: fileName]; output = [OFFile fileWithPath: outFileName mode: @"w"]; setPermissions(outFileName, entry); while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: output fileName: fileName]; |
︙ | ︙ | |||
321 322 323 324 325 326 327 | if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; | | | | | | | | | | | | | | | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | if (app->_outputLevel >= 0 && percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"extracting_file_percent", @"Extracting %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } [output close]; setModificationDate(outFileName, entry); if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"extracting_file_done", @"Extracting %[file]... done", @"file", fileName)]; } outer_loop_end: objc_autoreleasePoolPop(pool); } if (missing.count > 0) { for (OFString *file in missing) [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", file)]; app->_exitStatus = 1; } } - (void)printFiles: (OFArray OF_GENERIC(OFString *) *)files { OFStream *stream; if (files.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"print_no_file_specified", @"Need one or more files to print!")]; app->_exitStatus = 1; return; } for (OFString *path in files) { @try { stream = [_archive streamForReadingFile: path]; } @catch (OFOpenItemFailedException *e) { if (e.errNo == ENOENT) { [OFStdErr writeLine: OF_LOCALIZED( @"file_not_in_archive", @"File %[file] is not in the archive!", @"file", e.path)]; app->_exitStatus = 1; continue; } @throw e; } while (!stream.atEndOfStream) { ssize_t length = [app copyBlockFromStream: stream toStream: OFStdOut fileName: path]; if (length < 0) { app->_exitStatus = 1; return; } } [stream close]; } } - (void)addFiles: (OFArray OF_GENERIC(OFString *) *)files { OFFileManager *fileManager = [OFFileManager defaultManager]; if (files.count < 1) { [OFStdErr writeLine: OF_LOCALIZED(@"add_no_file_specified", @"Need one or more files to add!")]; app->_exitStatus = 1; return; } for (OFString *localFileName in files) { void *pool = objc_autoreleasePoolPush(); OFArray OF_GENERIC (OFString *) *components; OFString *fileName; OFFileAttributes attributes; bool isDirectory = false; OFMutableZIPArchiveEntry *entry; unsigned long long size; OFStream *output; components = localFileName.pathComponents; fileName = [components componentsJoinedByString: @"/"]; attributes = [fileManager attributesOfItemAtPath: localFileName]; if ([attributes.fileType isEqual: OFFileTypeDirectory]) { isDirectory = true; fileName = [fileName stringByAppendingString: @"/"]; } if (app->_outputLevel >= 0) [OFStdOut writeString: OF_LOCALIZED(@"adding_file", @"Adding %[file]...", @"file", fileName)]; entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName]; size = (isDirectory ? 0 : attributes.fileSize); if (size > INT64_MAX) @throw [OFOutOfRangeException exception]; entry.compressedSize = (int64_t)size; entry.uncompressedSize = (int64_t)size; entry.compressionMethod = OFZIPArchiveEntryCompressionMethodNone; entry.modificationDate = attributes.fileModificationDate; [entry makeImmutable]; output = [_archive streamForWritingEntry: entry]; if (!isDirectory) { |
︙ | ︙ | |||
482 483 484 485 486 487 488 | percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; | | | | | | 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 | percent != newPercent) { OFString *percentString; percent = newPercent; percentString = [OFString stringWithFormat: @"%3u", percent]; [OFStdOut writeString: @"\r"]; [OFStdOut writeString: OF_LOCALIZED( @"adding_file_percent", @"Adding %[file]... %[percent]%", @"file", fileName, @"percent", percentString)]; } } } if (app->_outputLevel >= 0) { [OFStdOut writeString: @"\r"]; [OFStdOut writeLine: OF_LOCALIZED( @"adding_file_done", @"Adding %[file]... done", @"file", fileName)]; } [output close]; |
︙ | ︙ |
Modified utils/ofdns/OFDNS.m from [bf05d8854e] to [bf91a28ab8].
︙ | ︙ | |||
31 32 33 34 35 36 37 | @end OF_APPLICATION_DELEGATE(OFDNS) static void help(OFStream *stream, bool full, int status) { | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | @end OF_APPLICATION_DELEGATE(OFDNS) static void help(OFStream *stream, bool full, int status) { [OFStdErr writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] -[chst] domain1 [domain2 ...]", @"prog", [OFApplication programName])]; if (full) { [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", |
︙ | ︙ | |||
63 64 65 66 67 68 69 | didPerformQuery: (OFDNSQuery *)query response: (OFDNSResponse *)response exception: (id)exception { _inFlight--; if (exception == nil) | | | | | | | | | | | | | | < | | | < | 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | didPerformQuery: (OFDNSQuery *)query response: (OFDNSResponse *)response exception: (id)exception { _inFlight--; if (exception == nil) [OFStdOut writeFormat: @"%@\n", response]; else { [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_resolve", @"Failed to resolve: %[exception]", @"exception", exception)]; _errors++; } if (_inFlight == 0) [OFApplication terminateWithStatus: _errors]; } - (void)applicationDidFinishLaunching { OFString *DNSClassString, *server; const OFOptionsParserOption options[] = { { 'c', @"class", 1, NULL, &DNSClassString }, { 'h', @"help", 0, NULL, NULL }, { 's', @"server", 1, NULL, &server }, { 't', @"type", 1, NULL, NULL }, { '\0', nil, 0, NULL, NULL } }; OFMutableArray OF_GENERIC(OFString *) *recordTypes; OFOptionsParser *optionsParser; OFUnichar option; OFArray OF_GENERIC(OFString *) *remainingArguments; OFDNSResolver *resolver; OFDNSClass DNSClass; #ifdef OF_HAVE_FILES # ifndef OF_AMIGAOS [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; # else [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofdns/lang"]; # endif #endif #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [[OFSandbox alloc] init]; @try { sandbox.allowsStdIO = true; sandbox.allowsDNS = true; [OFApplication of_activateSandbox: sandbox]; } @finally { [sandbox release]; } #endif recordTypes = [OFMutableArray array]; optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 't': [recordTypes addObject: optionsParser.argument]; break; case 'h': help(OFStdOut, true, 0); break; case ':': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"long_option_required_argument", @"%[prog]: Option --%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"option_requires_argument", @"%[prog]: Option -%[opt] requires an " @"argument", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED( @"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%C", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED( @"Unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } remainingArguments = optionsParser.remainingArguments; if (remainingArguments.count < 1) help(OFStdErr, false, 1); resolver = [OFDNSResolver resolver]; DNSClass = (DNSClassString != nil ? OFDNSClassParseName(DNSClassString) : OFDNSClassIN); if (recordTypes.count == 0) [recordTypes addObject: @"ALL"]; if (server != nil) { resolver.configReloadInterval = 0; resolver.nameServers = [OFArray arrayWithObject: server]; } for (OFString *domainName in remainingArguments) { for (OFString *recordTypeString in recordTypes) { OFDNSRecordType recordType = OFDNSRecordTypeParseName(recordTypeString); OFDNSQuery *query = [OFDNSQuery queryWithDomainName: domainName DNSClass: DNSClass recordType: recordType]; _inFlight++; [resolver asyncPerformQuery: query delegate: self]; } } } @end |
Modified utils/ofhash/OFHash.m from [aa03d9ef76] to [976db374f8].
︙ | ︙ | |||
38 39 40 41 42 43 44 | @end OF_APPLICATION_DELEGATE(OFHash) static void help(void) { | | | | | | | | | | | < | < | | | < | < | < | < | < | | | < | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | @end OF_APPLICATION_DELEGATE(OFHash) static void help(void) { [OFStdErr writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] [--md5|--ripemd160|--sha1|--sha224|--sha256|" @"--sha384|--sha512] file1 [file2 ...]", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } static void printHash(OFString *algo, OFString *path, id <OFCryptographicHash> hash) { const unsigned char *digest = hash.digest; size_t digestSize = hash.digestSize; [OFStdOut writeFormat: @"%@ ", algo]; for (size_t i = 0; i < digestSize; i++) [OFStdOut writeFormat: @"%02x", digest[i]]; [OFStdOut writeFormat: @" %@\n", path]; } @implementation OFHash - (void)applicationDidFinishLaunching { int exitStatus = 0; bool calculateMD5, calculateRIPEMD160, calculateSHA1, calculateSHA224; bool calculateSHA256, calculateSHA384, calculateSHA512; const OFOptionsParserOption options[] = { { '\0', @"md5", 0, &calculateMD5, NULL }, { '\0', @"ripemd160", 0, &calculateRIPEMD160, NULL }, { '\0', @"sha1", 0, &calculateSHA1, NULL }, { '\0', @"sha224", 0, &calculateSHA224, NULL }, { '\0', @"sha256", 0, &calculateSHA256, NULL }, { '\0', @"sha384", 0, &calculateSHA384, NULL }, { '\0', @"sha512", 0, &calculateSHA512, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser = [OFOptionsParser parserWithOptions: options]; OFUnichar option; OFMD5Hash *MD5Hash = nil; OFRIPEMD160Hash *RIPEMD160Hash = nil; OFSHA1Hash *SHA1Hash = nil; OFSHA224Hash *SHA224Hash = nil; OFSHA256Hash *SHA256Hash = nil; OFSHA384Hash *SHA384Hash = nil; OFSHA512Hash *SHA512Hash = nil; #ifndef OF_AMIGAOS [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; #else [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhash/lang"]; #endif while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED(@"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%c", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED(@"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; @try { sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsUserDatabaseReading = true; for (OFString *path in optionsParser.remainingArguments) [sandbox unveilPath: path permissions: @"r"]; [sandbox unveilPath: @LANGUAGE_DIR permissions: @"r"]; [OFApplication of_activateSandbox: sandbox]; } @finally { [sandbox release]; } #endif if (!calculateMD5 && !calculateRIPEMD160 && !calculateSHA1 && !calculateSHA224 && !calculateSHA256 && !calculateSHA384 && !calculateSHA512) help(); if (optionsParser.remainingArguments.count < 1) help(); if (calculateMD5) MD5Hash = [OFMD5Hash hashWithAllowsSwappableMemory: true]; if (calculateRIPEMD160) RIPEMD160Hash = [OFRIPEMD160Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA1) SHA1Hash = [OFSHA1Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA224) SHA224Hash = [OFSHA224Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA256) SHA256Hash = [OFSHA256Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA384) SHA384Hash = [OFSHA384Hash hashWithAllowsSwappableMemory: true]; if (calculateSHA512) SHA512Hash = [OFSHA512Hash hashWithAllowsSwappableMemory: true]; for (OFString *path in optionsParser.remainingArguments) { void *pool = objc_autoreleasePoolPush(); OFStream *file; if ([path isEqual: @"-"]) file = OFStdIn; else { @try { file = [OFFile fileWithPath: path mode: @"r"]; } @catch (OFOpenItemFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_open_file", @"Failed to open file %[file]: %[error]", @"file", e.path, @"error", error)]; exitStatus = 1; goto outer_loop_end; |
︙ | ︙ | |||
212 213 214 215 216 217 218 | length = [file readIntoBuffer: buffer length: 1024]; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | length = [file readIntoBuffer: buffer length: 1024]; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdErr writeLine: OF_LOCALIZED( @"failed_to_read_file", @"Failed to read %[file]: %[error]", @"file", path, @"error", error)]; exitStatus = 1; goto outer_loop_end; |
︙ | ︙ |
Modified utils/ofhttp/Makefile from [196747b7c1] to [717e0862da].
︙ | ︙ | |||
12 13 14 15 16 17 18 | ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ | | > > | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ${PROG}: ${LIBOBJFW_DEP_LVL2} ${LIBOBJFWRT_DEP_LVL2} CPPFLAGS += -I../../src \ -I../../src/runtime \ -I../../src/exceptions \ -I../.. \ -DLANGUAGE_DIR='"${datadir}/ofhttp/lang"' \ -DLIB_PREFIX='"${LIB_PREFIX}"' \ -DLIB_SUFFIX='"${LIB_SUFFIX}"' LIBS := -L../../src -L../../src/linklib ${OBJFW_LIBS} \ -L../../src/runtime -L../../src/runtime/linklib ${RUNTIME_LIBS} \ ${LIBS} LD = ${OBJC} LDFLAGS += ${LDFLAGS_RPATH} |
Modified utils/ofhttp/OFHTTP.m from [9525086526] to [cd70aeb710].
︙ | ︙ | |||
62 63 64 65 66 67 68 | size_t _URLIndex; int _errorCode; OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectFileNameRequest; bool _detectedFileName, _quiet, _verbose, _insecure, _ignoreStatus; bool _useUnicode; OFStream *_body; | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | size_t _URLIndex; int _errorCode; OFString *_outputPath, *_currentFileName; bool _continue, _force, _detectFileName, _detectFileNameRequest; bool _detectedFileName, _quiet, _verbose, _insecure, _ignoreStatus; bool _useUnicode; OFStream *_body; OFHTTPRequestMethod _method; OFMutableDictionary *_clientHeaders; OFHTTPClient *_HTTPClient; char *_buffer; OFStream *_output; unsigned long long _received, _length, _resumedFrom; ProgressBar *_progressBar; } - (void)downloadNextURL; @end OF_APPLICATION_DELEGATE(OFHTTP) static void help(OFStream *stream, bool full, int status) { [OFStdErr writeLine: OF_LOCALIZED(@"usage", @"Usage: %[prog] -[cehHmoOPqv] url1 [url2 ...]", @"prog", [OFApplication programName])]; if (full) { [stream writeString: @"\n"]; [stream writeLine: OF_LOCALIZED(@"full_usage", |
︙ | ︙ | |||
128 129 130 131 132 133 134 | static OFString * fileNameFromContentDisposition(OFString *contentDisposition) { void *pool; const char *UTF8String; size_t UTF8StringLength; enum { | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | static OFString * fileNameFromContentDisposition(OFString *contentDisposition) { void *pool; const char *UTF8String; size_t UTF8StringLength; enum { stateDispositionType, stateDispositionTypeSemicolon, stateDispositionParamNameSkipSpace, stateDispositionParamName, stateDispositionParamValue, stateDispositionParamQuoted, stateDispositionParamUnquoted, stateDispositionExpectSemicolon } state; size_t last; OFString *type = nil, *paramName = nil, *paramValue; OFMutableDictionary *params; OFString *fileName; if (contentDisposition == nil) return nil; pool = objc_autoreleasePoolPush(); UTF8String = contentDisposition.UTF8String; UTF8StringLength = contentDisposition.UTF8StringLength; state = stateDispositionType; params = [OFMutableDictionary dictionary]; last = 0; for (size_t i = 0; i < UTF8StringLength; i++) { switch (state) { case stateDispositionType: if (UTF8String[i] == ';' || UTF8String[i] == ' ') { type = [OFString stringWithUTF8String: UTF8String length: i]; state = (UTF8String[i] == ';' ? stateDispositionParamNameSkipSpace : stateDispositionTypeSemicolon); last = i + 1; } break; case stateDispositionTypeSemicolon: if (UTF8String[i] == ';') { state = stateDispositionParamNameSkipSpace; last = i + 1; } else if (UTF8String[i] != ' ') { objc_autoreleasePoolPop(pool); return nil; } break; case stateDispositionParamNameSkipSpace: if (UTF8String[i] != ' ') { state = stateDispositionParamName; last = i; i--; } break; case stateDispositionParamName: if (UTF8String[i] == '=') { paramName = [OFString stringWithUTF8String: UTF8String + last length: i - last]; state = stateDispositionParamValue; } break; case stateDispositionParamValue: if (UTF8String[i] == '"') { state = stateDispositionParamQuoted; last = i + 1; } else { state = stateDispositionParamUnquoted; last = i; i--; } break; case stateDispositionParamQuoted: if (UTF8String[i] == '"') { paramValue = [OFString stringWithUTF8String: UTF8String + last length: i - last]; [params setObject: paramValue forKey: paramName.lowercaseString]; state = stateDispositionExpectSemicolon; } break; case stateDispositionParamUnquoted: if (UTF8String[i] <= 31 || UTF8String[i] >= 127) return nil; switch (UTF8String[i]) { case ' ': case '"': case '(': case ')': case ',': case '/': case ':': case '<': case '=': case '>': case '?': case '@': case '[': case '\\': case ']': case '{': case '}': return nil; case ';': paramValue = [OFString stringWithUTF8String: UTF8String + last length: i - last]; [params setObject: paramValue forKey: paramName.lowercaseString]; state = stateDispositionParamNameSkipSpace; break; } break; case stateDispositionExpectSemicolon: if (UTF8String[i] == ';') { state = stateDispositionParamNameSkipSpace; last = i + 1; } else if (UTF8String[i] != ' ') { objc_autoreleasePoolPop(pool); return nil; } break; } } if (state == stateDispositionParamUnquoted) { paramValue = [OFString stringWithUTF8String: UTF8String + last length: UTF8StringLength - last]; [params setObject: paramValue forKey: paramName.lowercaseString]; } else if (state != stateDispositionExpectSemicolon) { objc_autoreleasePoolPop(pool); return nil; } if (![type isEqual: @"attachment"] || (fileName = [params objectForKey: @"filename"]) == nil) { objc_autoreleasePoolPop(pool); |
︙ | ︙ | |||
281 282 283 284 285 286 287 | #ifdef OF_HAVE_PLUGINS + (void)initialize { if (self != [OFHTTP class]) return; /* Opportunistically try loading ObjOpenSSL and ignore any errors. */ | | | | | | | < | | < | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | #ifdef OF_HAVE_PLUGINS + (void)initialize { if (self != [OFHTTP class]) return; /* Opportunistically try loading ObjOpenSSL and ignore any errors. */ OFDLOpen(@LIB_PREFIX @"objopenssl" @LIB_SUFFIX, OFDLOpenFlagLazy); } #endif - (instancetype)init { self = [super init]; @try { _method = OFHTTPRequestMethodGet; _clientHeaders = [[OFMutableDictionary alloc] initWithObject: @"OFHTTP" forKey: @"User-Agent"]; _HTTPClient = [[OFHTTPClient alloc] init]; _HTTPClient.delegate = self; _buffer = OFAllocMemory(1, [OFSystemInfo pageSize]); } @catch (id e) { [self release]; @throw e; } return self; } - (void)addHeader: (OFString *)header { size_t pos = [header rangeOfString: @":"].location; OFString *name, *value; if (pos == OFNotFound) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_header", @"%[prog]: Headers must to be in format name:value!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } name = [header substringToIndex: pos] .stringByDeletingEnclosingWhitespaces; value = [header substringFromIndex: pos + 1] .stringByDeletingEnclosingWhitespaces; [_clientHeaders setObject: value forKey: name]; } - (void)setBody: (OFString *)path { OFString *contentLength = nil; [_body release]; _body = nil; if ([path isEqual: @"-"]) _body = [OFStdIn copy]; else { _body = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { unsigned long long fileSize = [[OFFileManager defaultManager] attributesOfItemAtPath: path].fileSize; contentLength = |
︙ | ︙ | |||
368 369 370 371 372 373 374 | - (void)setMethod: (OFString *)method { void *pool = objc_autoreleasePoolPush(); method = method.uppercaseString; @try { | | | | | | | | | | | | | | | > | > > > | | > | < | | | | | | | < < < | < | < | < | | | 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | - (void)setMethod: (OFString *)method { void *pool = objc_autoreleasePoolPush(); method = method.uppercaseString; @try { _method = OFHTTPRequestMethodParseName(method); } @catch (OFInvalidArgumentException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_method", @"%[prog]: Invalid request method %[method]!", @"prog", [OFApplication programName], @"method", method)]; [OFApplication terminateWithStatus: 1]; } objc_autoreleasePoolPop(pool); } - (void)setProxy: (OFString *)proxy { @try { size_t pos = [proxy rangeOfString: @":" options: OFStringSearchBackwards].location; OFString *host; unsigned long long port; if (pos == OFNotFound) @throw [OFInvalidFormatException exception]; host = [proxy substringToIndex: pos]; port = [proxy substringFromIndex: pos + 1] .unsignedLongLongValue; if (port > UINT16_MAX) @throw [OFOutOfRangeException exception]; [OFTCPSocket setSOCKS5Host: host]; [OFTCPSocket setSOCKS5Port: (uint16_t)port]; } @catch (OFInvalidFormatException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_input_proxy", @"%[prog]: Proxy must to be in format host:port!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } } - (void)applicationDidFinishLaunching { OFString *outputPath; const OFOptionsParserOption options[] = { { 'b', @"body", 1, NULL, NULL }, { 'c', @"continue", 0, &_continue, NULL }, { 'f', @"force", 0, &_force, NULL }, { 'h', @"help", 0, NULL, NULL }, { 'H', @"header", 1, NULL, NULL }, { 'm', @"method", 1, NULL, NULL }, { 'o', @"output", 1, NULL, &outputPath }, { 'O', @"detect-filename", 0, &_detectFileName, NULL }, { 'P', @"socks5-proxy", 1, NULL, NULL }, { 'q', @"quiet", 0, &_quiet, NULL }, { 'v', @"verbose", 0, &_verbose, NULL }, { '\0', @"insecure", 0, &_insecure, NULL }, { '\0', @"ignore-status", 0, &_ignoreStatus, NULL }, { '\0', nil, 0, NULL, NULL } }; OFOptionsParser *optionsParser; OFUnichar option; #ifdef OF_HAVE_SANDBOX OFSandbox *sandbox = [OFSandbox sandbox]; sandbox.allowsStdIO = true; sandbox.allowsReadingFiles = true; sandbox.allowsWritingFiles = true; sandbox.allowsCreatingFiles = true; sandbox.allowsIPSockets = true; sandbox.allowsDNS = true; sandbox.allowsUserDatabaseReading = true; sandbox.allowsTTY = true; /* Dropped after parsing options */ sandbox.allowsUnveil = true; [OFApplication of_activateSandbox: sandbox]; #endif #ifndef OF_AMIGAOS [OFLocale addLanguageDirectory: @LANGUAGE_DIR]; #else [OFLocale addLanguageDirectory: @"PROGDIR:/share/ofhttp/lang"]; #endif optionsParser = [OFOptionsParser parserWithOptions: options]; while ((option = [optionsParser nextOption]) != '\0') { switch (option) { case 'b': [self setBody: optionsParser.argument]; break; case 'h': help(OFStdOut, true, 0); break; case 'H': [self addHeader: optionsParser.argument]; break; case 'm': [self setMethod: optionsParser.argument]; break; case 'P': [self setProxy: optionsParser.argument]; break; case ':': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED(@"long_argument_missing", @"%[prog]: Argument for option --%[opt] " @"missing" @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%c", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED(@"argument_missing", @"%[prog]: Argument for option -%[opt] " @"missing", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; case '=': [OFStdErr writeLine: OF_LOCALIZED(@"option_takes_no_argument", @"%[prog]: Option --%[opt] takes no argument", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; [OFApplication terminateWithStatus: 1]; break; case '?': if (optionsParser.lastLongOption != nil) [OFStdErr writeLine: OF_LOCALIZED(@"unknown_long_option", @"%[prog]: Unknown option: --%[opt]", @"prog", [OFApplication programName], @"opt", optionsParser.lastLongOption)]; else { OFString *optStr = [OFString stringWithFormat: @"%c", optionsParser.lastOption]; [OFStdErr writeLine: OF_LOCALIZED(@"unknown_option", @"%[prog]: Unknown option: -%[opt]", @"prog", [OFApplication programName], @"opt", optStr)]; } [OFApplication terminateWithStatus: 1]; break; } } #ifdef OF_HAVE_SANDBOX if (outputPath != nil) [sandbox unveilPath: outputPath permissions: (_continue ? @"rwc" : @"wc")]; else [sandbox unveilPath: [[OFFileManager defaultManager] currentDirectoryPath] permissions: (_continue ? @"rwc" : @"wc")]; /* In case we use ObjOpenSSL for https later */ [sandbox unveilPath: @"/etc/ssl" permissions: @"r"]; sandbox.allowsUnveil = false; [OFApplication of_activateSandbox: sandbox]; #endif _outputPath = [outputPath copy]; _URLs = [optionsParser.remainingArguments copy]; if (_URLs.count < 1) help(OFStdErr, false, 1); if (_quiet && _verbose) { [OFStdErr writeLine: OF_LOCALIZED(@"quiet_xor_verbose", @"%[prog]: -q / --quiet and -v / --verbose are mutually " @"exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_outputPath != nil && _detectFileName) { [OFStdErr writeLine: OF_LOCALIZED( @"output_xor_detect_filename", @"%[prog]: -o / --output and -O / --detect-filename are " @"mutually exclusive!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_outputPath != nil && _URLs.count > 1) { [OFStdErr writeLine: OF_LOCALIZED(@"output_only_with_one_url", @"%[prog]: Cannot use -o / --output when more than one URL " @"has been specified!", @"prog", [OFApplication programName])]; [OFApplication terminateWithStatus: 1]; } if (_insecure) _HTTPClient.allowsInsecureRedirects = true; _useUnicode = ([OFLocale encoding] == OFStringEncodingUTF8); [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } - (void)client: (OFHTTPClient *)client didCreateSocket: (OFTCPSocket *)sock request: (OFHTTPRequest *)request { if (_insecure && [sock respondsToSelector: @selector(setVerifiesCertificates:)]) ((id <OFTLSSocket>)sock).verifiesCertificates = false; } - (void)client: (OFHTTPClient *)client wantsRequestBody: (OFStream *)body request: (OFHTTPRequest *)request { /* TODO: Do asynchronously and print status */ while (!_body.atEndOfStream) { char buffer[4096]; size_t length = [_body readIntoBuffer: buffer length: 4096]; [body writeBuffer: buffer length: length]; } } - (bool)client: (OFHTTPClient *)client shouldFollowRedirect: (OFURL *)URL statusCode: (short)statusCode request: (OFHTTPRequest *)request response: (OFHTTPResponse *)response { if (_verbose) { void *pool = objc_autoreleasePoolPush(); OFDictionary OF_GENERIC(OFString *, OFString *) *headers = response.headers; OFEnumerator *keyEnumerator = [headers keyEnumerator]; OFEnumerator *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [OFStdOut writeFormat: @" %@: %@\n", key, object]; objc_autoreleasePoolPop(pool); } if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"☇ %@", URL.string]; else [OFStdOut writeFormat: @"< %@", URL.string]; } _length = 0; return true; } |
︙ | ︙ | |||
651 652 653 654 655 656 657 | [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; if (!_quiet) { | | | | < < | < > | | | 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; if (!_quiet) { [OFStdOut writeString: @"\n "]; [OFStdOut writeLine: OF_LOCALIZED(@"download_error", @"Error!")]; } URL = [_URLs objectAtIndex: _URLIndex - 1]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_exception", @"%[prog]: Failed to download <%[url]>!\n" @" %[exception]", @"prog", [OFApplication programName], @"url", URL, @"exception", exception)]; _errorCode = 1; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; return false; } [_output writeBuffer: buffer length: length]; _received += length; [_progressBar setReceived: _received]; if (response.atEndOfStream) { [_progressBar stop]; [_progressBar draw]; [_progressBar release]; _progressBar = nil; if (!_quiet) { [OFStdOut writeString: @"\n "]; [OFStdOut writeLine: OF_LOCALIZED(@"download_done", @"Done!")]; } [self performSelector: @selector(downloadNextURL) afterDelay: 0]; return false; } |
︙ | ︙ | |||
712 713 714 715 716 717 718 | if (!_quiet) { OFString *lengthString = [headers objectForKey: @"Content-Length"]; OFString *type = [headers objectForKey: @"Content-Type"]; if (_useUnicode) | | | | 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | if (!_quiet) { OFString *lengthString = [headers objectForKey: @"Content-Length"]; OFString *type = [headers objectForKey: @"Content-Type"]; if (_useUnicode) [OFStdOut writeFormat: @" ➜ %hd\n", statusCode]; else [OFStdOut writeFormat: @" -> %hd\n", statusCode]; if (type == nil) type = OF_LOCALIZED(@"type_unknown", @"unknown"); if (lengthString != nil) { _length = lengthString.unsignedLongLongValue; |
︙ | ︙ | |||
768 769 770 771 772 773 774 | OFEnumerator OF_GENERIC(OFString *) *keyEnumerator = [headers keyEnumerator]; OFEnumerator OF_GENERIC(OFString *) *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; if (statusCode / 100 == 2 && _currentFileName != nil) { | | | | | | | | | | | | | | | | | | | | | | < | | | | | | 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 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 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 | OFEnumerator OF_GENERIC(OFString *) *keyEnumerator = [headers keyEnumerator]; OFEnumerator OF_GENERIC(OFString *) *objectEnumerator = [headers objectEnumerator]; OFString *key, *object; if (statusCode / 100 == 2 && _currentFileName != nil) { [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED( @"info_name_unaligned", @"Name: %[name]", @"name", _currentFileName)]; } while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [OFStdOut writeFormat: @" %@: %@\n", key, object]; objc_autoreleasePoolPop(pool); } else if (statusCode / 100 == 2 && !_detectFileNameRequest) { [OFStdOut writeString: @" "]; if (_currentFileName != nil) [OFStdOut writeLine: OF_LOCALIZED(@"info_name", @"Name: %[name]", @"name", _currentFileName)]; [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED(@"info_type", @"Type: %[type]", @"type", type)]; [OFStdOut writeString: @" "]; [OFStdOut writeLine: OF_LOCALIZED(@"info_size", @"Size: %[size]", @"size", lengthString)]; } } } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response exception: (id)exception { if (exception != nil) { if ([exception isKindOfClass: [OFResolveHostFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"download_resolve_host_failed", @"%[prog]: Failed to download <%[url]>!\n" @" Failed to resolve host: %[exception]", @"prog", [OFApplication programName], @"url", request.URL.string, @"exception", exception)]; } else if ([exception isKindOfClass: [OFConnectionFailedException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"download_failed_connection_failed", @"%[prog]: Failed to download <%[url]>!\n" @" Connection failed: %[exception]", @"prog", [OFApplication programName], @"url", request.URL.string, @"exception", exception)]; } else if ([exception isKindOfClass: [OFInvalidServerReplyException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_invalid_server_reply", @"%[prog]: Failed to download <%[url]>!\n" @" Invalid server reply!", @"prog", [OFApplication programName], @"url", request.URL.string)]; } else if ([exception isKindOfClass: [OFUnsupportedProtocolException class]]) { if (!_quiet) [OFStdOut writeString: @"\n"]; [OFStdErr writeLine: OF_LOCALIZED(@"no_ssl_library", @"%[prog]: No TLS library loaded!\n" @" In order to download via https, you need to " @"preload an TLS library for ObjFW\n" @" such as ObjOpenSSL!", @"prog", [OFApplication programName])]; } else if ([exception isKindOfClass: [OFReadOrWriteFailedException class]]) { OFString *error = OF_LOCALIZED( @"download_failed_read_or_write_failed_any", @"Read or write failed"); if (!_quiet) [OFStdOut writeString: @"\n"]; if ([exception isKindOfClass: [OFReadFailedException class]]) error = OF_LOCALIZED( @"download_failed_read_or_write_failed_" @"read", @"Read failed"); else if ([exception isKindOfClass: [OFWriteFailedException class]]) error = OF_LOCALIZED( @"download_failed_read_or_write_failed_" @"write", @"Write failed"); [OFStdErr writeLine: OF_LOCALIZED( @"download_failed_read_or_write_failed", @"%[prog]: Failed to download <%[url]>!\n" @" %[error]: %[exception]", @"prog", [OFApplication programName], @"url", request.URL.string, @"error", error, @"exception", exception)]; } else if ([exception isKindOfClass: [OFHTTPRequestFailedException class]]) { short statusCode; OFString *codeString; if (_ignoreStatus) { exception = nil; goto after_exception_handling; } statusCode = response.statusCode; codeString = [OFString stringWithFormat: @"%hd %@", statusCode, OFHTTPStatusCodeString(statusCode)]; [OFStdErr writeLine: OF_LOCALIZED(@"download_failed", @"%[prog]: Failed to download <%[url]>!\n" @" HTTP status code: %[code]", @"prog", [OFApplication programName], @"url", request.URL.string, @"code", codeString)]; } else @throw exception; _errorCode = 1; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; return; } after_exception_handling: if (_method == OFHTTPRequestMethodHead) goto next; if (_detectFileNameRequest) { _currentFileName = [fileNameFromContentDisposition( [response.headers objectForKey: @"Content-Disposition"]) copy]; _detectedFileName = true; /* Handle this URL on the next -[downloadNextURL] call */ _URLIndex--; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; return; } if ([_outputPath isEqual: @"-"]) _output = [OFStdOut copy]; else { if (!_continue && !_force && [[OFFileManager defaultManager] fileExistsAtPath: _currentFileName]) { [OFStdErr writeLine: OF_LOCALIZED(@"output_already_exists", @"%[prog]: File %[filename] already exists!", @"prog", [OFApplication programName], @"filename", _currentFileName)]; _errorCode = 1; goto next; } @try { OFString *mode = (response.statusCode == 206 ? @"a" : @"w"); _output = [[OFFile alloc] initWithPath: _currentFileName mode: mode]; } @catch (OFOpenItemFailedException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"failed_to_open_output", @"%[prog]: Failed to open file %[filename]: " @"%[exception]", @"prog", [OFApplication programName], @"filename", _currentFileName, @"exception", e)]; |
︙ | ︙ | |||
977 978 979 980 981 982 983 | [_progressBar draw]; } [_currentFileName release]; _currentFileName = nil; response.delegate = self; | | < | < | | | | | | > > > > > > > > | < | | | < | 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | [_progressBar draw]; } [_currentFileName release]; _currentFileName = nil; response.delegate = self; [response asyncReadIntoBuffer: _buffer length: [OFSystemInfo pageSize]]; return; next: [_currentFileName release]; _currentFileName = nil; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } - (void)downloadNextURL { OFString *URLString = nil; OFURL *URL; OFMutableDictionary *clientHeaders; OFHTTPRequest *request; _received = _length = _resumedFrom = 0; if (_output != OFStdOut) [_output release]; _output = nil; if (_URLIndex >= _URLs.count) [OFApplication terminateWithStatus: _errorCode]; @try { URLString = [_URLs objectAtIndex: _URLIndex++]; URL = [OFURL URLWithString: URLString]; } @catch (OFInvalidFormatException *e) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_url", @"%[prog]: Invalid URL: <%[url]>!", @"prog", [OFApplication programName], @"url", URLString)]; _errorCode = 1; goto next; } if (![URL.scheme isEqual: @"http"] && ![URL.scheme isEqual: @"https"]) { [OFStdErr writeLine: OF_LOCALIZED(@"invalid_scheme", @"%[prog]: Invalid scheme: <%[url]>!", @"prog", [OFApplication programName], @"url", URLString)]; _errorCode = 1; goto next; } clientHeaders = [[_clientHeaders mutableCopy] autorelease]; if (_detectFileName && !_detectedFileName) { if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"⠒ %@", URL.string]; else [OFStdOut writeFormat: @"? %@", URL.string]; } request = [OFHTTPRequest requestWithURL: URL]; request.headers = clientHeaders; request.method = OFHTTPRequestMethodHead; _detectFileNameRequest = true; [_HTTPClient asyncPerformRequest: request]; return; } if (!_detectedFileName) { [_currentFileName release]; _currentFileName = nil; } else _detectedFileName = false; if (_currentFileName == nil) _currentFileName = [_outputPath copy]; if (_currentFileName == nil) _currentFileName = [URL.path.lastPathComponent copy]; if ([_currentFileName isEqual: @"/"]) { [_currentFileName release]; _currentFileName = nil; } if (_currentFileName == nil) _currentFileName = @"unnamed"; if (_continue) { @try { unsigned long long size = [[OFFileManager defaultManager] attributesOfItemAtPath: _currentFileName].fileSize; OFString *range; if (size > ULLONG_MAX) @throw [OFOutOfRangeException exception]; _resumedFrom = (unsigned long long)size; range = [OFString stringWithFormat: @"bytes=%jd-", _resumedFrom]; [clientHeaders setObject: range forKey: @"Range"]; } @catch (OFRetrieveItemAttributesFailedException *e) { } } if (!_quiet) { if (_useUnicode) [OFStdOut writeFormat: @"⇣ %@", URL.string]; else [OFStdOut writeFormat: @"< %@", URL.string]; } request = [OFHTTPRequest requestWithURL: URL]; request.headers = clientHeaders; request.method = _method; _detectFileNameRequest = false; [_HTTPClient asyncPerformRequest: request]; return; next: [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } @end |
Modified utils/ofhttp/ProgressBar.m from [3a96d93eb6] to [55b889a4e0].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" #import "OFLocale.h" #import "ProgressBar.h" | > | | < | | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" #import "OFLocale.h" #import "ProgressBar.h" static const float oneKibibyte = 1024; static const float oneMebibyte = 1024 * 1024; static const float oneGibibyte = 1024 * 1024 * 1024; static const OFTimeInterval updateInterval = 0.1; #ifndef HAVE_TRUNCF # define truncf(x) trunc(x) #endif @implementation ProgressBar - (instancetype)initWithLength: (unsigned long long)length |
︙ | ︙ | |||
46 47 48 49 50 51 52 | _useUnicode = useUnicode; _length = length; _resumedFrom = resumedFrom; _startDate = [[OFDate alloc] init]; _lastReceivedDate = [[OFDate alloc] init]; _drawTimer = [[OFTimer | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | _useUnicode = useUnicode; _length = length; _resumedFrom = resumedFrom; _startDate = [[OFDate alloc] init]; _lastReceivedDate = [[OFDate alloc] init]; _drawTimer = [[OFTimer scheduledTimerWithTimeInterval: updateInterval target: self selector: @selector(draw) repeats: true] retain]; _BPSTimer = [[OFTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @selector( |
︙ | ︙ | |||
88 89 90 91 92 93 94 | } - (void)_drawProgress { float bars, percent; int columns, barWidth; | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | } - (void)_drawProgress { float bars, percent; int columns, barWidth; if ((columns = OFStdOut.columns) >= 0) { if (columns > 37) barWidth = columns - 37; else barWidth = 0; } else barWidth = 43; bars = (float)(_resumedFrom + _received) / (float)(_resumedFrom + _length) * barWidth; percent = (float)(_resumedFrom + _received) / (float)(_resumedFrom + _length) * 100; if (_useUnicode) { [OFStdOut writeString: @"\r ▕"]; for (size_t i = 0; i < (size_t)bars; i++) [OFStdOut writeString: @"█"]; if (bars < barWidth) { float rem = bars - truncf(bars); if (rem >= 0.875) [OFStdOut writeString: @"▉"]; else if (rem >= 0.75) [OFStdOut writeString: @"▊"]; else if (rem >= 0.625) [OFStdOut writeString: @"▋"]; else if (rem >= 0.5) [OFStdOut writeString: @"▌"]; else if (rem >= 0.375) [OFStdOut writeString: @"▍"]; else if (rem >= 0.25) [OFStdOut writeString: @"▎"]; else if (rem >= 0.125) [OFStdOut writeString: @"▏"]; else [OFStdOut writeString: @" "]; for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++) [OFStdOut writeString: @" "]; } [OFStdOut writeFormat: @"▏ %,6.2f%% ", percent]; } else { [OFStdOut writeString: @"\r ["]; for (size_t i = 0; i < (size_t)bars; i++) [OFStdOut writeString: @"#"]; if (bars < barWidth) { float rem = bars - truncf(bars); if (rem >= 0.75) [OFStdOut writeString: @"O"]; else if (rem >= 0.5) [OFStdOut writeString: @"o"]; else if (rem >= 0.25) [OFStdOut writeString: @"."]; else [OFStdOut writeString: @" "]; for (size_t i = 0; i < barWidth - (size_t)bars - 1; i++) [OFStdOut writeString: @" "]; } [OFStdOut writeFormat: @"] %,6.2f%% ", percent]; } if (percent == 100) { double timeInterval = -_startDate.timeIntervalSinceNow; _BPS = (float)_received / (float)timeInterval; _ETA = timeInterval; } if (isinf(_ETA)) [OFStdOut writeString: @"--:--:-- "]; else if (_ETA >= 99 * 3600) { OFString *num = [OFString stringWithFormat: @"%,4.2f", _ETA / (24 * 3600)]; [OFStdOut writeString: OF_LOCALIZED(@"eta_days", @"%[num] d ", @"num", num)]; } else [OFStdOut writeFormat: @"%2u:%02u:%02u ", (uint8_t)(_ETA / 3600), (uint8_t)(_ETA / 60) % 60, (uint8_t)_ETA % 60]; if (_BPS >= oneGibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gibs", @"%[num] GiB/s", @"num", num)]; } else if (_BPS >= oneMebibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mibs", @"%[num] MiB/s", @"num", num)]; } else if (_BPS >= oneKibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kibs", @"%[num] KiB/s", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS]; [OFStdOut writeString: OF_LOCALIZED(@"progress_bps", @"%[num] B/s ", @"num", num)]; } } - (void)_drawReceived { [OFStdOut writeString: @"\r "]; if (_resumedFrom + _received >= oneGibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", (float)(_resumedFrom + _received) / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gib", @"%[num] GiB", @"num", num)]; } else if (_resumedFrom + _received >= oneMebibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", (float)(_resumedFrom + _received) / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mib", @"%[num] MiB", @"num", num)]; } else if (_resumedFrom + _received >= oneKibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", (float)(_resumedFrom + _received) / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kib", @"%[num] KiB", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%jd", _resumedFrom + _received]; [OFStdOut writeString: OF_LOCALIZED(@"progress_bytes", @"[" @" [" @" {'num == 1': '1 byte '}," @" {'': '%[num] bytes'}" @" ]" @"]".objectByParsingJSON, @"num", num)]; } [OFStdOut writeString: @" "]; if (_stopped) _BPS = (float)_received / -(float)_startDate.timeIntervalSinceNow; if (_BPS >= oneGibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gibs", @"%[num] GiB/s", @"num", num)]; } else if (_BPS >= oneMebibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mibs", @"%[num] MiB/s", @"num", num)]; } else if (_BPS >= oneKibibyte) { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kibs", @"%[num] KiB/s", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @"%,7.2f", _BPS]; [OFStdOut writeString: OF_LOCALIZED(@"progress_bps", @"%[num] B/s ", @"num", num)]; } } - (void)draw { |
︙ | ︙ |
Deleted utils/ofsock/Makefile version [3ea451369d].
|
| < < < < < < < < < < < < < < < < < < < < |
Deleted utils/ofsock/OFSock.m version [913104ae86].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |