summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Menes/Menes.h1
-rw-r--r--Menes/Pooling.hpp117
-rw-r--r--MobileCydia.mm48
-rw-r--r--makefile1
-rwxr-xr-xsysroot.sh2
5 files changed, 139 insertions, 30 deletions
diff --git a/Menes/Menes.h b/Menes/Menes.h
index 5da16ba..0a421c7 100644
--- a/Menes/Menes.h
+++ b/Menes/Menes.h
@@ -24,6 +24,7 @@
#include "Menes/Function.h"
#include "Menes/ObjectHandle.h"
+#include "Menes/Pooling.hpp"
#include "Menes/invocationWithSelector.h"
#include "Menes/radixSortWithSelector.h"
diff --git a/Menes/Pooling.hpp b/Menes/Pooling.hpp
new file mode 100644
index 0000000..751f397
--- /dev/null
+++ b/Menes/Pooling.hpp
@@ -0,0 +1,117 @@
+/* Cycript - Optimizing JavaScript Compiler/Runtime
+ * Copyright (C) 2009-2014 Jay Freeman (saurik)
+*/
+
+/* GNU Affero General Public License, Version 3 {{{ */
+/*
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero 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 Affero General Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+**/
+/* }}} */
+
+#ifndef Menes_Pooling_HPP
+#define Menes_Pooling_HPP
+
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+
+#include <algorithm>
+
+#include <stdint.h>
+
+class CYPool;
+_finline void *operator new(size_t size, CYPool &pool);
+_finline void *operator new [](size_t size, CYPool &pool);
+
+class CYPool {
+ private:
+ uint8_t *data_;
+ size_t size_;
+
+ struct Cleaner {
+ Cleaner *next_;
+ void (*code_)(void *);
+ void *data_;
+
+ Cleaner(Cleaner *next, void (*code)(void *), void *data) :
+ next_(next),
+ code_(code),
+ data_(data)
+ {
+ }
+ } *cleaner_;
+
+ static _finline size_t align(size_t size) {
+ // XXX: alignment is more complex than this
+ return (size + 7) & ~0x3;
+ }
+
+ template <typename Type_>
+ static void delete_(void *data) {
+ reinterpret_cast<Type_ *>(data)->~Type_();
+ }
+
+ CYPool(const CYPool &);
+
+ public:
+ CYPool() :
+ data_(NULL),
+ size_(0),
+ cleaner_(NULL)
+ {
+ }
+
+ ~CYPool() {
+ for (Cleaner *cleaner(cleaner_); cleaner != NULL; ) {
+ Cleaner *next(cleaner->next_);
+ (*cleaner->code_)(cleaner->data_);
+ cleaner = next;
+ }
+ }
+
+ template <typename Type_>
+ Type_ *malloc(size_t size) {
+ size = align(size);
+
+ if (size > size_) {
+ // XXX: is this an optimal malloc size?
+ size_ = std::max<size_t>(size, size + align(sizeof(Cleaner)));
+ data_ = reinterpret_cast<uint8_t *>(::malloc(size_));
+ atexit(free, data_);
+ _assert(size <= size_);
+ }
+
+ void *data(data_);
+ data_ += size;
+ size_ -= size;
+ return reinterpret_cast<Type_ *>(data);
+ }
+
+ void atexit(void (*code)(void *), void *data = NULL);
+};
+
+_finline void *operator new(size_t size, CYPool &pool) {
+ return pool.malloc<void>(size);
+}
+
+_finline void *operator new [](size_t size, CYPool &pool) {
+ return pool.malloc<void>(size);
+}
+
+_finline void CYPool::atexit(void (*code)(void *), void *data) {
+ cleaner_ = new(*this) Cleaner(cleaner_, code, data);
+}
+
+#endif/*Menes_Pooling_HPP*/
diff --git a/MobileCydia.mm b/MobileCydia.mm
index 0625b35..1968599 100644
--- a/MobileCydia.mm
+++ b/MobileCydia.mm
@@ -83,8 +83,6 @@
#include <apt-pkg/strutl.h>
#include <apt-pkg/tagfile.h>
-#include <apr-1/apr_pools.h>
-
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -580,14 +578,14 @@ class CYString {
cache_ = reinterpret_cast<CFStringRef>(CFRetain(rhs.cache_));
}
- void copy(apr_pool_t *pool) {
- char *temp(reinterpret_cast<char *>(apr_palloc(pool, size_ + 1)));
+ void copy(CYPool *pool) {
+ char *temp(pool->malloc<char>(size_ + 1));
memcpy(temp, data_, size_);
temp[size_] = '\0';
data_ = temp;
}
- void set(apr_pool_t *pool, const char *data, size_t size) {
+ void set(CYPool *pool, const char *data, size_t size) {
if (size == 0)
clear();
else {
@@ -601,11 +599,11 @@ class CYString {
}
}
- _finline void set(apr_pool_t *pool, const char *data) {
+ _finline void set(CYPool *pool, const char *data) {
set(pool, data, data == NULL ? 0 : strlen(data));
}
- _finline void set(apr_pool_t *pool, const std::string &rhs) {
+ _finline void set(CYPool *pool, const std::string &rhs) {
set(pool, rhs.data(), rhs.size());
}
@@ -1118,7 +1116,7 @@ typedef std::map< unsigned long, _H<Source> > SourceMap;
@interface Database : NSObject {
NSZone *zone_;
- apr_pool_t *pool_;
+ CYPool pool_;
unsigned era_;
@@ -1556,7 +1554,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
_transient NSObject<SourceDelegate> *delegate_;
}
-- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool;
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(CYPool *)pool;
- (NSComparisonResult) compareByName:(Source *)source;
@@ -1639,7 +1637,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
return index_;
}
-- (void) setMetaIndex:(metaIndex *)index inPool:(apr_pool_t *)pool {
+- (void) setMetaIndex:(metaIndex *)index inPool:(CYPool *)pool {
trusted_ = index->IsTrusted();
uri_.set(pool, index->GetURI());
@@ -1715,7 +1713,7 @@ static void PackageImport(const void *key, const void *value, void *context) {
authority_ = [url path];
}
-- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(apr_pool_t *)pool {
+- (Source *) initWithMetaIndex:(metaIndex *)index forDatabase:(Database *)database inPool:(CYPool *)pool {
if ((self = [super init]) != nil) {
era_ = [database era];
database_ = database;
@@ -2110,7 +2108,7 @@ struct ParsedPackage {
uint32_t ignored_ : 1;
uint32_t pooled_ : 1;
- apr_pool_t *pool_;
+ CYPool *pool_;
uint32_t rank_;
@@ -2139,8 +2137,8 @@ struct ParsedPackage {
_H<NSMutableArray> tags_;
}
-- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
-+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database;
+- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database;
++ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database;
- (pkgCache::PkgIterator) iterator;
- (void) parse;
@@ -2357,7 +2355,7 @@ struct PackageNameOrdering :
- (void) dealloc {
if (!pooled_)
- apr_pool_destroy(pool_);
+ delete pool_;
if (parsed_ != NULL)
delete parsed_;
[super dealloc];
@@ -2540,11 +2538,11 @@ struct PackageNameOrdering :
_end
} }
-- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
+- (Package *) initWithVersion:(pkgCache::VerIterator)version withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database {
if ((self = [super init]) != nil) {
_profile(Package$initWithVersion)
if (pool == NULL)
- apr_pool_create(&pool_, NULL);
+ pool_ = new CYPool();
else {
pool_ = pool;
pooled_ = true;
@@ -2620,7 +2618,7 @@ struct PackageNameOrdering :
char *transform;
_profile(Package$initWithVersion$Transliterate$apr_palloc)
- transform = static_cast<char *>(apr_palloc(pool_, length));
+ transform = pool_->malloc<char>(length);
_end
_profile(Package$initWithVersion$Transliterate$u_strToUTF8WithSub$transform)
u_strToUTF8WithSub(transform, length, NULL, CollationString_.data(), CollationString_.size(), 0xfffd, NULL, &code);
@@ -2719,7 +2717,7 @@ struct PackageNameOrdering :
_end } return self;
}
-+ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(apr_pool_t *)pool database:(Database *)database {
++ (Package *) packageWithIterator:(pkgCache::PkgIterator)iterator withZone:(NSZone *)zone inPool:(CYPool *)pool database:(Database *)database {
pkgCache::VerIterator version;
_profile(Package$packageWithIterator$GetCandidateVer)
@@ -3520,7 +3518,6 @@ class CydiaLogCleaner :
// XXX: actually implement this thing
_assert(false);
[self releasePackages];
- apr_pool_destroy(pool_);
NSRecycleZone(zone_);
[super dealloc];
}
@@ -3651,7 +3648,6 @@ class CydiaLogCleaner :
lock_ = NULL;
zone_ = NSCreateZone(1024 * 1024, 256 * 1024, NO);
- apr_pool_create(&pool_, NULL);
size_t capacity(MetaFile_->active_);
if (capacity == 0)
@@ -3801,7 +3797,8 @@ class CydiaLogCleaner :
cache_.Close();
- apr_pool_clear(pool_);
+ pool_.~CYPool();
+ new (&pool_) CYPool();
NSRecycleZone(zone_);
zone_ = NSCreateZone(1024 * 1024, 256 * 1024, NO);
@@ -3823,7 +3820,7 @@ class CydiaLogCleaner :
_profile(reloadDataWithInvocation$Source$initWithMetaIndex)
for (pkgSourceList::const_iterator source = list_->begin(); source != list_->end(); ++source) {
- Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:pool_] autorelease]);
+ Source *object([[[Source alloc] initWithMetaIndex:*source forDatabase:self inPool:&pool_] autorelease]);
[sourceList_ addObject:object];
}
_end
@@ -3926,7 +3923,7 @@ class CydiaLogCleaner :
_profile(reloadDataWithInvocation$packageWithIterator)
for (pkgCache::PkgIterator iterator = cache_->PkgBegin(); !iterator.end(); ++iterator)
- if (Package *package = [Package packageWithIterator:iterator withZone:zone_ inPool:pool_ database:self])
+ if (Package *package = [Package packageWithIterator:iterator withZone:zone_ inPool:&pool_ database:self])
//packages.push_back(package);
CFArrayAppendValue(packages_, CFRetain(package));
_end
@@ -10319,9 +10316,6 @@ int main(int argc, char *argv[]) {
CollationStarts_ = [NSArray arrayWithObjects:@"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",@"ʒ",nil];
}
/* }}} */
-
- apr_app_initialize(&argc, const_cast<const char * const **>(&argv), NULL);
-
/* Parse Arguments {{{ */
bool substrate(false);
diff --git a/makefile b/makefile
index 4ca2d6f..fbca76b 100644
--- a/makefile
+++ b/makefile
@@ -42,7 +42,6 @@ libs += -framework SystemConfiguration
libs += -framework WebCore
libs += -framework WebKit
-libs += -lapr-1
libs += -lapt-pkg
libs += -licucore
diff --git a/sysroot.sh b/sysroot.sh
index ec3ee2c..e17d8d9 100755
--- a/sysroot.sh
+++ b/sysroot.sh
@@ -62,8 +62,6 @@ function extract() {
declare -A urls
-urls[apr]=http://apt.saurik.com/debs/apr_1.3.3-4_iphoneos-arm.deb
-urls[apr-lib]=http://apt.saurik.com/debs/apr-lib_1.3.3-2_iphoneos-arm.deb
urls[apt7]=http://apt.saurik.com/debs/apt7_0.7.25.3-7_iphoneos-arm.deb
urls[apt7-lib]=http://apt.saurik.com/debs/apt7-lib_0.7.25.3-12_iphoneos-arm.deb
urls[coreutils]=http://apt.saurik.com/debs/coreutils_7.4-11_iphoneos-arm.deb