Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Classes/LevelDB.mm
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ - (id) initWithPath:(NSString *)path andName:(NSString *)name {
- (id) initWithPath:(NSString *)path name:(NSString *)name andOptions:(LevelDBOptions)opts {
self = [super init];
if (self) {
_name = name;
_path = path;
_name = [name retain];
_path = [path retain];

leveldb::Options options;

Expand Down Expand Up @@ -664,6 +664,8 @@ - (BOOL) closed {
}
- (void) dealloc {
[self close];
[_name release];
[_path release];
[super dealloc];
}

Expand Down
7 changes: 7 additions & 0 deletions Classes/include/Objective_LevelDB/Common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Common.h
// Forwarding header so that both #import <Objective_LevelDB/Common.h> and
// quoted imports keep working when built with Swift Package Manager.
//

#import "../../Common.h"
7 changes: 7 additions & 0 deletions Classes/include/Objective_LevelDB/LDBSnapshot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// LDBSnapshot.h
// Forwarding header so that both #import <Objective_LevelDB/LDBSnapshot.h> and
// quoted imports keep working when built with Swift Package Manager.
//

#import "../../LDBSnapshot.h"
7 changes: 7 additions & 0 deletions Classes/include/Objective_LevelDB/LDBWriteBatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// LDBWriteBatch.h
// Forwarding header so that both #import <Objective_LevelDB/LDBWriteBatch.h> and
// quoted imports keep working when built with Swift Package Manager.
//

#import "../../LDBWriteBatch.h"
7 changes: 7 additions & 0 deletions Classes/include/Objective_LevelDB/LevelDB.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// LevelDB.h
// Forwarding header so that both #import <Objective_LevelDB/LevelDB.h> and
// quoted imports keep working when built with Swift Package Manager.
//

#import "../../LevelDB.h"
16 changes: 16 additions & 0 deletions Classes/include/Objective_LevelDB/Objective-LevelDB-umbrella.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif

#import "Common.h"
#import "LDBSnapshot.h"
#import "LDBWriteBatch.h"
#import "LevelDB.h"
71 changes: 71 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Objective-LevelDB",
platforms: [
.iOS(.v15)
],
products: [
.library(
name: "Objective-LevelDB",
targets: ["Objective_LevelDB"]
)
],
targets: [
// Google's leveldb, vendored from https://github.com/firebase/leveldb
// (tag CocoaPods-1.22.5) — the same source tree the `leveldb-library`
// CocoaPods pod is built from. Tests, benchmarks and Windows-specific
// files are not vendored. The target is deliberately NOT named
// `leveldb` to avoid a target-name collision with firebase/leveldb
// when both end up in the same dependency graph.
.target(
name: "LevelDBLibrary",
path: "vendor/leveldb",
exclude: [
"LICENSE",
"AUTHORS"
],
sources: [
"db/",
"port/",
"table/",
"util/",
"include/"
],
resources: [.process("Resources/PrivacyInfo.xcprivacy")],
publicHeadersPath: "include",
cSettings: [
.define("LEVELDB_IS_BIG_ENDIAN", to: "0"),
.define("LEVELDB_PLATFORM_POSIX", to: "1"),
.define("HAVE_FULLFSYNC", to: "1"),
.headerSearchPath("./"),
.headerSearchPath("include/")
],
linkerSettings: [
.linkedLibrary("c++")
]
),
// The Objective-C(++) wrapper. The target/module is named
// `Objective_LevelDB` to match the module name CocoaPods generated
// for the `Objective-LevelDB` pod, so existing imports such as
// #import <Objective_LevelDB/LevelDB.h> keep working unchanged.
// The wrapper sources are verbatim MRC (requires_arc = false in the
// podspec), so ARC is disabled via -fno-objc-arc. This is an unsafe
// flag: SwiftPM refuses it for packages consumed by version, so this
// package must be consumed by revision/branch (Tuist handles this
// fine; same pattern as appunite/protobuf).
.target(
name: "Objective_LevelDB",
dependencies: ["LevelDBLibrary"],
path: "Classes",
publicHeadersPath: "include",
cSettings: [
.unsafeFlags(["-fno-objc-arc"])
]
)
],
cxxLanguageStandard: .gnucxx14
)
12 changes: 12 additions & 0 deletions vendor/leveldb/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Names should be added to this file like so:
# Name or Organization <email address>

Google Inc.

# Initial version authors:
Jeffrey Dean <jeff@google.com>
Sanjay Ghemawat <sanjay@google.com>

# Partial list of contributors:
Kevin Regan <kevin.d.regan@gmail.com>
Johan Bilien <jobi@litl.com>
27 changes: 27 additions & 0 deletions vendor/leveldb/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright (c) 2011 The LevelDB Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 changes: 26 additions & 0 deletions vendor/leveldb/Resources/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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">
<dict>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyTrackingDomains</key>
<array>
</array>
<key>NSPrivacyCollectedDataTypes</key>
<array>
</array>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
</array>
</dict>
</array>
</dict>
</plist>

79 changes: 79 additions & 0 deletions vendor/leveldb/db/builder.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "db/builder.h"

#include "db/dbformat.h"
#include "db/filename.h"
#include "db/table_cache.h"
#include "db/version_edit.h"
#include "leveldb/db.h"
#include "leveldb/env.h"
#include "leveldb/iterator.h"

namespace leveldb {

Status BuildTable(const std::string& dbname, Env* env, const Options& options,
TableCache* table_cache, Iterator* iter, FileMetaData* meta) {
Status s;
meta->file_size = 0;
iter->SeekToFirst();

std::string fname = TableFileName(dbname, meta->number);
if (iter->Valid()) {
WritableFile* file;
s = env->NewWritableFile(fname, &file);
if (!s.ok()) {
return s;
}

TableBuilder* builder = new TableBuilder(options, file);
meta->smallest.DecodeFrom(iter->key());
for (; iter->Valid(); iter->Next()) {
Slice key = iter->key();
meta->largest.DecodeFrom(key);
builder->Add(key, iter->value());
}

// Finish and check for builder errors
s = builder->Finish();
if (s.ok()) {
meta->file_size = builder->FileSize();
assert(meta->file_size > 0);
}
delete builder;

// Finish and check for file errors
if (s.ok()) {
s = file->Sync();
}
if (s.ok()) {
s = file->Close();
}
delete file;
file = nullptr;

if (s.ok()) {
// Verify that the table is usable
Iterator* it = table_cache->NewIterator(ReadOptions(), meta->number,
meta->file_size);
s = it->status();
delete it;
}
}

// Check for input iterator errors
if (!iter->status().ok()) {
s = iter->status();
}

if (s.ok() && meta->file_size > 0) {
// Keep it
} else {
env->RemoveFile(fname);
}
return s;
}

} // namespace leveldb
30 changes: 30 additions & 0 deletions vendor/leveldb/db/builder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#ifndef STORAGE_LEVELDB_DB_BUILDER_H_
#define STORAGE_LEVELDB_DB_BUILDER_H_

#include "leveldb/status.h"

namespace leveldb {

struct Options;
struct FileMetaData;

class Env;
class Iterator;
class TableCache;
class VersionEdit;

// Build a Table file from the contents of *iter. The generated file
// will be named according to meta->number. On success, the rest of
// *meta will be filled with metadata about the generated table.
// If no data is present in *iter, meta->file_size will be set to
// zero, and no Table file will be produced.
Status BuildTable(const std::string& dbname, Env* env, const Options& options,
TableCache* table_cache, Iterator* iter, FileMetaData* meta);

} // namespace leveldb

#endif // STORAGE_LEVELDB_DB_BUILDER_H_
Loading