Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary OFConstString implementation and support for @"" literals.
- Loading branch information
Showing
11 changed files
with
285 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# =========================================================================== | ||
# http://autoconf-archive.cryp.to/ax_check_compiler_flags.html | ||
# =========================================================================== | ||
# | ||
# SYNOPSIS | ||
# | ||
# AX_CHECK_COMPILER_FLAGS(FLAGS, [ACTION-SUCCESS], [ACTION-FAILURE]) | ||
# | ||
# DESCRIPTION | ||
# | ||
# Check whether the given compiler FLAGS work with the current language's | ||
# compiler, or whether they give an error. (Warnings, however, are | ||
# ignored.) | ||
# | ||
# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on | ||
# success/failure. | ||
# | ||
# LAST MODIFICATION | ||
# | ||
# 2008-04-12 | ||
# | ||
# COPYLEFT | ||
# | ||
# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu> | ||
# Copyright (c) 2008 Matteo Frigo | ||
# | ||
# This program is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or (at your | ||
# option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
# Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# As a special exception, the respective Autoconf Macro's copyright owner | ||
# gives unlimited permission to copy, distribute and modify the configure | ||
# scripts that are the output of Autoconf when processing the Macro. You | ||
# need not follow the terms of the GNU General Public License when using | ||
# or distributing such scripts, even though portions of the text of the | ||
# Macro appear in them. The GNU General Public License (GPL) does govern | ||
# all other use of the material that constitutes the Autoconf Macro. | ||
# | ||
# This special exception to the GPL applies to versions of the Autoconf | ||
# Macro released by the Autoconf Macro Archive. When you make and | ||
# distribute a modified version of the Autoconf Macro, you may extend this | ||
# special exception to the GPL to apply to your modified version as well. | ||
|
||
AC_DEFUN([AX_CHECK_COMPILER_FLAGS], | ||
[AC_PREREQ(2.59) dnl for _AC_LANG_PREFIX | ||
AC_MSG_CHECKING([whether _AC_LANG compiler accepts $1]) | ||
dnl Some hackery here since AC_CACHE_VAL can't handle a non-literal varname: | ||
AS_LITERAL_IF([$1], | ||
[AC_CACHE_VAL(AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1), [ | ||
ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS | ||
_AC_LANG_PREFIX[]FLAGS="$1" | ||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], | ||
AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes, | ||
AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no) | ||
_AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS])], | ||
[ax_save_FLAGS=$[]_AC_LANG_PREFIX[]FLAGS | ||
_AC_LANG_PREFIX[]FLAGS="$1" | ||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], | ||
eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=yes, | ||
eval AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1)=no) | ||
_AC_LANG_PREFIX[]FLAGS=$ax_save_FLAGS]) | ||
eval ax_check_compiler_flags=$AS_TR_SH(ax_cv_[]_AC_LANG_ABBREV[]_flags_$1) | ||
AC_MSG_RESULT($ax_check_compiler_flags) | ||
if test "x$ax_check_compiler_flags" = xyes; then | ||
m4_default([$2], :) | ||
else | ||
m4_default([$3], :) | ||
fi | ||
])dnl AX_CHECK_COMPILER_FLAGS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2008 - 2009 | ||
* Jonathan Schleifer <js@webkeks.org> | ||
* | ||
* All rights reserved. | ||
* | ||
* This file is part of libobjfw. It may be distributed under the terms of the | ||
* Q Public License 1.0, which can be found in the file LICENSE included in | ||
* the packaging of this file. | ||
*/ | ||
|
||
#import "OFObject.h" | ||
|
||
#if !defined(__objc_INCLUDE_GNU) && !defined(OFCONSTSTRING_M) | ||
/* | ||
* This way, projects using libobjfw don't need -Wno-deprecated-declarations on | ||
* OS X 10.5. | ||
*/ | ||
extern void _OFConstStringClassReference; | ||
#endif | ||
|
||
/** | ||
* A class for storing static strings using the @"" literal. | ||
*/ | ||
@interface OFConstString: Object <OFHashable, OFRetainRelease> | ||
{ | ||
char *string; | ||
size_t length; | ||
} | ||
|
||
/** | ||
* \return The OFString as a C string | ||
*/ | ||
- (const char*)cString; | ||
|
||
/** | ||
* \return The length of the OFString | ||
*/ | ||
- (size_t)length; | ||
|
||
/** | ||
* Compares the OFString to another object. | ||
* | ||
* \param obj An object to compare with | ||
* \return An integer which is the result of the comparison, see for example | ||
* strcmp | ||
*/ | ||
- (int)compare: (id)obj; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2008 - 2009 | ||
* Jonathan Schleifer <js@webkeks.org> | ||
* | ||
* All rights reserved. | ||
* | ||
* This file is part of libobjfw. It may be distributed under the terms of the | ||
* Q Public License 1.0, which can be found in the file LICENSE included in | ||
* the packaging of this file. | ||
*/ | ||
|
||
#import "config.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#define OFCONSTSTRING_M | ||
#import "OFConstString.h" | ||
#import "OFString.h" | ||
#import "OFExceptions.h" | ||
#import "OFMacros.h" | ||
|
||
#ifndef __objc_INCLUDE_GNU | ||
struct objc_class _OFConstStringClassReference; | ||
#endif | ||
|
||
@implementation OFConstString | ||
#ifndef __objc_INCLUDE_GNU | ||
+ (void)load | ||
{ | ||
Class cls = objc_getClass("OFConstString"); | ||
memcpy(&_OFConstStringClassReference, cls, | ||
sizeof(_OFConstStringClassReference)); | ||
objc_addClass(&_OFConstStringClassReference); | ||
} | ||
#endif | ||
|
||
- (BOOL)isKindOf: (Class)c | ||
{ | ||
if (c == [OFConstString class]) | ||
return YES; | ||
return NO; | ||
} | ||
|
||
- (const char*)cString | ||
{ | ||
return string; | ||
} | ||
|
||
- (size_t)length | ||
{ | ||
return length; | ||
} | ||
|
||
- (BOOL)isEqual: (id)obj | ||
{ | ||
if (![obj isKindOf: [OFString class]] && | ||
![obj isKindOf: [OFConstString class]]) | ||
return NO; | ||
if (strcmp(string, [obj cString])) | ||
return NO; | ||
|
||
return YES; | ||
} | ||
|
||
- (int)compare: (id)obj | ||
{ | ||
if (![obj isKindOf: [OFString class]] && | ||
![obj isKindOf: [OFConstString class]]) | ||
@throw [OFInvalidArgumentException newWithClass: [self class]]; | ||
|
||
return strcmp(string, [obj cString]); | ||
} | ||
|
||
- (uint32_t)hash | ||
{ | ||
uint32_t hash; | ||
size_t i; | ||
|
||
OF_HASH_INIT(hash); | ||
for (i = 0; i < length; i++) | ||
OF_HASH_ADD(hash, string[i]); | ||
OF_HASH_FINALIZE(hash); | ||
|
||
return hash; | ||
} | ||
|
||
- retain | ||
{ | ||
return self; | ||
} | ||
|
||
- (void)release | ||
{ | ||
} | ||
|
||
- (size_t)retainCount | ||
{ | ||
return 1; | ||
} | ||
|
||
- autorelease | ||
{ | ||
return self; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.