Skip to content

Commit 462fee9

Browse files
author
Patrick Thomson
committed
Added more dumping routines, made sure it worked on Mac OS X 10.6, turned on -Werror.
1 parent 5280f11 commit 462fee9

File tree

8 files changed

+90
-19
lines changed

8 files changed

+90
-19
lines changed

YAMLKit.xcodeproj/project.pbxproj

+15-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
72C6DBDA1007D396008D7A84 /* libyaml.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72C6DBD91007D396008D7A84 /* libyaml.dylib */; };
1011
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
1112
8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */; };
1213
CD1DE6870F0960D3006FDAB3 /* YAMLKit.h in Headers */ = {isa = PBXBuildFile; fileRef = CD1DE6860F0960D3006FDAB3 /* YAMLKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -15,7 +16,6 @@
1516
CD312F630F09A0E50004C345 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CD312F620F09A0E50004C345 /* SenTestingKit.framework */; };
1617
CD312F930F09A1A00004C345 /* TestHighLevelAccess.m in Sources */ = {isa = PBXBuildFile; fileRef = CD69C2420F098A540011BAB6 /* TestHighLevelAccess.m */; };
1718
CD4669530F0A98330047C2BF /* verysimple.yaml in Resources */ = {isa = PBXBuildFile; fileRef = CD4669520F0A98330047C2BF /* verysimple.yaml */; };
18-
CD4669600F0A99130047C2BF /* libyaml.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CD46695F0F0A99130047C2BF /* libyaml.dylib */; };
1919
CD4669650F0A996A0047C2BF /* TestParsing.m in Sources */ = {isa = PBXBuildFile; fileRef = CD69C23A0F098A2F0011BAB6 /* TestParsing.m */; };
2020
CD46698D0F0A9A040047C2BF /* YAMLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* YAMLKit.framework */; };
2121
CD69C2200F097CEE0011BAB6 /* YKEmitter.h in Headers */ = {isa = PBXBuildFile; fileRef = CD69C21E0F097CEE0011BAB6 /* YKEmitter.h */; };
@@ -42,14 +42,14 @@
4242
089C1667FE841158C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
4343
1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
4444
32DBCF5E0370ADEE00C91783 /* YAMLKit_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YAMLKit_Prefix.pch; sourceTree = "<group>"; };
45+
72C6DBD91007D396008D7A84 /* libyaml.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libyaml.dylib; path = /usr/local/lib/libyaml.dylib; sourceTree = "<absolute>"; };
4546
8DC2EF5A0486A6940098B216 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4647
8DC2EF5B0486A6940098B216 /* YAMLKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = YAMLKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4748
CD1DE6860F0960D3006FDAB3 /* YAMLKit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YAMLKit.h; sourceTree = "<group>"; };
4849
CD2913040F0E85930003FE76 /* YKConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YKConstants.h; sourceTree = "<group>"; };
4950
CD312F560F09A0A40004C345 /* Run Tests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Run Tests.octest"; sourceTree = BUILT_PRODUCTS_DIR; };
5051
CD312F620F09A0E50004C345 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; };
5152
CD4669520F0A98330047C2BF /* verysimple.yaml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = verysimple.yaml; sourceTree = "<group>"; };
52-
CD46695F0F0A99130047C2BF /* libyaml.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libyaml.dylib; path = /usr/local/lib/libyaml.dylib; sourceTree = "<absolute>"; };
5353
CD69C21E0F097CEE0011BAB6 /* YKEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YKEmitter.h; sourceTree = "<group>"; };
5454
CD69C21F0F097CEE0011BAB6 /* YKEmitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YKEmitter.m; sourceTree = "<group>"; };
5555
CD69C2330F0983A90011BAB6 /* YKParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YKParser.h; sourceTree = "<group>"; };
@@ -72,7 +72,7 @@
7272
buildActionMask = 2147483647;
7373
files = (
7474
8DC2EF570486A6940098B216 /* Cocoa.framework in Frameworks */,
75-
CD4669600F0A99130047C2BF /* libyaml.dylib in Frameworks */,
75+
72C6DBDA1007D396008D7A84 /* libyaml.dylib in Frameworks */,
7676
);
7777
runOnlyForDeploymentPostprocessing = 0;
7878
};
@@ -148,9 +148,9 @@
148148
1058C7B0FEA5585E11CA2CBB /* Linked Frameworks */ = {
149149
isa = PBXGroup;
150150
children = (
151-
CD46695F0F0A99130047C2BF /* libyaml.dylib */,
152151
CD312F620F09A0E50004C345 /* SenTestingKit.framework */,
153152
1058C7B1FEA5585E11CA2CBB /* Cocoa.framework */,
153+
72C6DBD91007D396008D7A84 /* libyaml.dylib */,
154154
);
155155
name = "Linked Frameworks";
156156
sourceTree = "<group>";
@@ -353,6 +353,7 @@
353353
isa = XCBuildConfiguration;
354354
buildSettings = {
355355
ALWAYS_SEARCH_USER_PATHS = NO;
356+
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
356357
COPY_PHASE_STRIP = NO;
357358
DYLIB_COMPATIBILITY_VERSION = 1;
358359
DYLIB_CURRENT_VERSION = 1;
@@ -363,6 +364,8 @@
363364
GCC_OPTIMIZATION_LEVEL = 0;
364365
GCC_PRECOMPILE_PREFIX_HEADER = YES;
365366
GCC_PREFIX_HEADER = YAMLKit_Prefix.pch;
367+
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
368+
GCC_WARN_PEDANTIC = NO;
366369
INFOPLIST_FILE = Info.plist;
367370
INSTALL_PATH = "$(HOME)/Library/Frameworks";
368371
PRODUCT_NAME = YAMLKit;
@@ -381,17 +384,20 @@
381384
GCC_MODEL_TUNING = G5;
382385
GCC_PRECOMPILE_PREFIX_HEADER = YES;
383386
GCC_PREFIX_HEADER = YAMLKit_Prefix.pch;
387+
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
388+
GCC_WARN_PEDANTIC = NO;
384389
INFOPLIST_FILE = Info.plist;
385390
INSTALL_PATH = "$(HOME)/Library/Frameworks";
386391
PRODUCT_NAME = YAMLKit;
392+
SDKROOT = macosx10.6;
387393
WRAPPER_EXTENSION = framework;
388394
};
389395
name = Release;
390396
};
391397
1DEB91B208733DA50010E9CD /* Debug */ = {
392398
isa = XCBuildConfiguration;
393399
buildSettings = {
394-
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
400+
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
395401
GCC_C_LANGUAGE_STANDARD = c99;
396402
GCC_ENABLE_OBJC_GC = supported;
397403
GCC_OPTIMIZATION_LEVEL = 0;
@@ -403,15 +409,15 @@
403409
LIBRARY_SEARCH_PATHS = /usr/local/lib/;
404410
ONLY_ACTIVE_ARCH = YES;
405411
PREBINDING = NO;
406-
SDKROOT = macosx10.5;
412+
SDKROOT = macosx10.6;
407413
WARNING_CFLAGS = "-Wall";
408414
};
409415
name = Debug;
410416
};
411417
1DEB91B308733DA50010E9CD /* Release */ = {
412418
isa = XCBuildConfiguration;
413419
buildSettings = {
414-
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
420+
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
415421
GCC_C_LANGUAGE_STANDARD = c99;
416422
GCC_ENABLE_OBJC_GC = supported;
417423
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
@@ -420,8 +426,9 @@
420426
GCC_WARN_UNUSED_VARIABLE = YES;
421427
HEADER_SEARCH_PATHS = /usr/local/include/;
422428
LIBRARY_SEARCH_PATHS = /usr/local/lib/;
429+
ONLY_ACTIVE_ARCH = YES;
423430
PREBINDING = NO;
424-
SDKROOT = macosx10.5;
431+
SDKROOT = macosx10.6;
425432
WARNING_CFLAGS = "-Wall";
426433
};
427434
name = Release;

src/YAMLKit.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515

1616
}
1717

18-
+ (NSString *)dump:(id)object;
19-
+ (id)load:(NSString *)aString;
18+
+ (NSString *)dumpObject:(id)object;
19+
+ (BOOL)dumpObject:(id)object toFile:(NSString *)path;
20+
+ (BOOL)dumpObject:(id)object toURL:(NSURL *)path;
21+
22+
+ (id)loadFromString:(NSString *)aString;
23+
+ (id)loadFromFile:(NSString *)path;
24+
+ (id)loadFromURL:(NSURL *)url;
2025

2126
@end

src/YAMLKit.m

+40-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@implementation YAMLKit
1212

13-
+ (id)load:(NSString *)str
13+
+ (id)loadFromString:(NSString *)str
1414
{
1515
YKParser *p = [[[YKParser alloc] init] autorelease];
1616
[p readString:str];
@@ -22,13 +22,51 @@ + (id)load:(NSString *)str
2222
return result;
2323
}
2424

25-
+ (NSString *)dump:(id)object
25+
+ (id)loadFromFile:(NSString *)path
26+
{
27+
NSString *contents = [NSString stringWithContentsOfFile:path
28+
encoding:NSUTF8StringEncoding
29+
error:NULL];
30+
if(contents == nil) return nil; // if there was an error reading from the file
31+
return [self loadFromString:contents];
32+
}
33+
34+
+ (id)loadFromURL:(NSURL *)url
35+
{
36+
NSString *contents = [NSString stringWithContentsOfURL:url
37+
encoding:NSUTF8StringEncoding
38+
error:NULL];
39+
if(contents == nil) return nil; // if there was an error reading from the URL
40+
return [self loadFromString:contents];
41+
}
42+
43+
+ (NSString *)dumpObject:(id)object
2644
{
2745
YKEmitter *e = [[[YKEmitter alloc] init] autorelease];
2846
[e emitItem:object];
2947
return [e emittedString];
3048
}
3149

50+
+ (BOOL)dumpObject:(id)object toFile:(NSString *)path
51+
{
52+
YKEmitter *e = [[[YKEmitter alloc] init] autorelease];
53+
[e emitItem:object];
54+
return [[e emittedString] writeToFile:path
55+
atomically:YES
56+
encoding:NSUTF8StringEncoding
57+
error:NULL];
58+
}
59+
60+
+ (BOOL)dumpObject:(id)object toURL:(NSURL *)path
61+
{
62+
YKEmitter *e = [[[YKEmitter alloc] init] autorelease];
63+
[e emitItem:object];
64+
return [[e emittedString] writeToURL:path
65+
atomically:YES
66+
encoding:NSUTF8StringEncoding
67+
error:NULL];
68+
}
69+
3270

3371

3472
@end

src/YKConstants.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111

12-
const NSString *YKErrorDomain = @"YKErrorDomain";
12+
NSString *YKErrorDomain = @"YKErrorDomain";
1313
const NSString *YKProblemValueKey = @"YKProblemValue";
1414
const NSString *YKProblemOffsetKey = @"YKProblemOffset";
1515
const NSString *YKProblemIndexKey = @"YKProblemIndex";

src/YKEmitter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
}
1717

1818
- (void)emitItem:(id)item;
19-
- (int)_writeItem:(id)item toDocument:(yaml_document_t *)document;
2019
- (NSString *)emittedString;
2120
- (NSData *)emittedData;
2221

2322
@property(assign) BOOL usesExplicitDelimiters;
2423
@property(assign) NSStringEncoding encoding;
2524

25+
2626
@end

src/YKEmitter.m

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77

88
#import "YKEmitter.h"
99

10-
@implementation YKEmitter
10+
@interface YKEmitter (YKEmitterPrivateMEthods)
11+
12+
- (int)_writeItem:(id)item toDocument:(yaml_document_t *)document;
1113

14+
@end
15+
16+
@implementation YKEmitter
1217

1318
@synthesize usesExplicitDelimiters, encoding;
1419

@@ -22,7 +27,7 @@ - (id)init
2227
// Coincidentally, the order of arguments to CFDataAppendBytes are just right
2328
// such that if I pass the buffer as the data parameter, I can just use
2429
// a pointer to CFDataAppendBytes to tell the emitter to write to the NSMutableData.
25-
yaml_emitter_set_output(&emitter, CFDataAppendBytes, buffer);
30+
yaml_emitter_set_output(&emitter, (yaml_write_handler_t*)CFDataAppendBytes, buffer);
2631
[self setUsesExplicitDelimiters:NO];
2732
}
2833
return self;
@@ -42,7 +47,7 @@ - (void)emitItem:(id)item
4247
yaml_document_delete(&document);
4348
}
4449

45-
- (int)_writeItem:(id)item toDocument:(yaml_document_t *)doc;
50+
- (int)_writeItem:(id)item toDocument:(yaml_document_t *)doc
4651
{
4752
int nodeID = 0;
4853
// #keyEnumerator covers NSMapTable/NSHashTable/NSDictionary

src/YKParser.m

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
#import "YKParser.h"
99
#import "YKConstants.h"
1010

11+
@interface YKParser (YKParserPrivateMethods)
12+
13+
- (id)_interpretObjectFromEvent:(yaml_event_t)event;
14+
- (NSError *)_constructErrorFromParser:(yaml_parser_t *)p;
15+
16+
@end
17+
1118
@implementation YKParser
1219

1320
@synthesize readyToParse;

test/TestHighLevelAccess.m

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@ @implementation TestHighLevelAccess
1212
- (void)testStringDumping
1313
{
1414
NSArray *a = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
15-
NSString *dumped = [YAMLKit dump:a];
15+
NSString *dumped = [YAMLKit dumpObject:a];
1616
STAssertEqualObjects(dumped, @"- one\n- two\n- three\n", @"was not the same when dumped");
1717
}
1818

1919
- (void)testStringLoading
2020
{
2121
NSString *dumped = @"- one\n- two\n- three";
22-
NSArray *a = [YAMLKit load:dumped];
22+
NSArray *a = [YAMLKit loadFromString:dumped];
2323
NSArray *b = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
2424
STAssertEqualObjects(a, b, @"was not the same when loaded");
2525
}
2626

27+
- (void)testFileDumpingAndLoading
28+
{
29+
NSArray *a = [NSArray arrayWithObjects:@"one", @"two", @"three", nil];
30+
NSString *path = @"/tmp/yamlkit_test.yaml";
31+
STAssertTrue([YAMLKit dumpObject:a toFile:path], @"did not dump successfully");
32+
STAssertEqualObjects(a, [YAMLKit loadFromFile:path], @"was not the same when loaded");
33+
}
34+
35+
2736
@end

0 commit comments

Comments
 (0)