else
passwd = getpwuid(getuid());
- const char *basedir(apr_psprintf(pool, "%s/.cycript", passwd->pw_dir));
- const char *histfile(apr_psprintf(pool, "%s/history", basedir));
+ const char *basedir(pool.sprintf("%s/.cycript", passwd->pw_dir));
+ const char *histfile(pool.sprintf("%s/history", basedir));
size_t histlines(0);
rl_initialize();
pid = strtoul(arg, &end, 0);
if (arg + size != end) {
// XXX: arg needs to be escaped in some horrendous way of doom
- const char *command(apr_psprintf(pool, "ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", arg));
+ const char *command(pool.sprintf("ps axc|sed -e '/^ *[0-9]/{s/^ *\\([0-9]*\\)\\( *[^ ]*\\)\\{3\\} *-*\\([^ ]*\\)/\\3 \\1/;/^%s /{s/^[^ ]* //;q;};};d'", arg));
if (FILE *pids = popen(command, "r")) {
char value[32];
CYJSError(JSContextRef context, const char *format, ...);
- virtual const char *PoolCString(apr_pool_t *pool) const;
+ virtual const char *PoolCString(CYPool &pool) const;
virtual JSValueRef CastJSValue(JSContextRef context) const;
};
#endif
CYPoolError(const char *format, ...);
CYPoolError(const char *format, va_list args);
- virtual const char *PoolCString(apr_pool_t *pool) const;
+ virtual const char *PoolCString(CYPool &pool) const;
#ifdef CY_EXECUTE
virtual JSValueRef CastJSValue(JSContextRef context) const;
#endif
#include <JavaScriptCore/JSBase.h>
#endif
-#include <apr_pools.h>
#include "Standard.hpp"
+class CYPool;
+
struct CYException {
virtual ~CYException() {
}
- virtual const char *PoolCString(apr_pool_t *pool) const = 0;
+ virtual const char *PoolCString(CYPool &pool) const = 0;
#ifdef CY_EXECUTE
virtual JSValueRef CastJSValue(JSContextRef context) const = 0;
#endif
return CYUTF16String(JSStringGetCharactersPtr(value), JSStringGetLength(value));
}
-CYUTF8String CYPoolUTF8String(apr_pool_t *pool, JSContextRef context, JSStringRef value) {
+CYUTF8String CYPoolUTF8String(CYPool &pool, JSContextRef context, JSStringRef value) {
return CYPoolUTF8String(pool, CYCastUTF16String(value));
}
-const char *CYPoolCString(apr_pool_t *pool, JSContextRef context, JSStringRef value) {
+const char *CYPoolCString(CYPool &pool, JSContextRef context, JSStringRef value) {
CYUTF8String utf8(CYPoolUTF8String(pool, context, value));
_assert(memchr(utf8.data, '\0', utf8.size) == NULL);
return utf8.data;
}
-const char *CYPoolCString(apr_pool_t *pool, JSContextRef context, JSValueRef value) {
+const char *CYPoolCString(CYPool &pool, JSContextRef context, JSValueRef value) {
return JSValueIsNull(context, value) ? NULL : CYPoolCString(pool, context, CYJSString(context, value));
}
/* }}} */
/* Index Offsets {{{ */
-size_t CYGetIndex(apr_pool_t *pool, JSContextRef context, JSStringRef value) {
+size_t CYGetIndex(CYPool &pool, JSContextRef context, JSStringRef value) {
return CYGetIndex(CYPoolUTF8String(pool, context, value));
}
/* }}} */
void CYFinalize(JSObjectRef object) {
CYData *internal(reinterpret_cast<CYData *>(JSObjectGetPrivate(object)));
+ _assert(internal->count_ != _not(unsigned));
if (--internal->count_ == 0)
delete internal;
}
-void Structor_(apr_pool_t *pool, sig::Type *&type) {
+void Structor_(CYPool &pool, sig::Type *&type) {
if (
type->primitive == sig::pointer_P &&
type->data.data.type != NULL &&
Pointer(void *value, JSContextRef context, JSObjectRef owner, size_t length, sig::Type *type) :
CYOwned(value, context, owner),
- type_(new(pool_) Type_privateData(type)),
+ type_(new(*pool_) Type_privateData(type)),
length_(length)
{
}
JSObjectRef CYMakeStruct(JSContextRef context, void *data, sig::Type *type, ffi_type *ffi, JSObjectRef owner) {
Struct_privateData *internal(new Struct_privateData(context, owner));
- apr_pool_t *pool(internal->pool_);
+ CYPool &pool(*internal->pool_);
Type_privateData *typical(new(pool) Type_privateData(type, ffi));
internal->type_ = typical;
internal->value_ = data;
else {
size_t size(typical->GetFFI()->size);
- void *copy(apr_palloc(internal->pool_, size));
+ void *copy((*internal->pool_)(size));
memcpy(copy, data, size);
internal->value_ = copy;
}
static JSValueRef $cyq(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
CYPool pool;
- const char *name(apr_psprintf(pool, "%s%"APR_SIZE_T_FMT"", CYPoolCString(pool, context, arguments[0]), Nonce_++));
+ const char *name(pool.sprintf("%s%"APR_SIZE_T_FMT"", CYPoolCString(pool, context, arguments[0]), Nonce_++));
return CYCastJSValue(context, name);
}
return CYJSUndefined(context);
}
-const char *CYPoolCCYON(apr_pool_t *pool, JSContextRef context, JSValueRef value, JSValueRef *exception) { CYTry {
+const char *CYPoolCCYON(CYPool &pool, JSContextRef context, JSValueRef value, JSValueRef *exception) { CYTry {
switch (JSType type = JSValueGetType(context, value)) {
case kJSTypeUndefined:
return "undefined";
std::ostringstream str;
CYNumerify(str, CYCastDouble(context, value));
std::string value(str.str());
- return apr_pstrmemdup(pool, value.c_str(), value.size());
+ return pool.strmemdup(value.c_str(), value.size());
} break;
case kJSTypeString: {
CYUTF8String string(CYPoolUTF8String(pool, context, CYJSString(context, value)));
CYStringify(str, string.data, string.size);
std::string value(str.str());
- return apr_pstrmemdup(pool, value.c_str(), value.size());
+ return pool.strmemdup(value.c_str(), value.size());
} break;
case kJSTypeObject:
}
} CYCatch(NULL) }
-const char *CYPoolCCYON(apr_pool_t *pool, JSContextRef context, JSValueRef value) {
+const char *CYPoolCCYON(CYPool &pool, JSContextRef context, JSValueRef value) {
JSValueRef exception(NULL);
const char *cyon(CYPoolCCYON(pool, context, value, &exception));
CYThrow(context, exception);
return cyon;
}
-const char *CYPoolCCYON(apr_pool_t *pool, JSContextRef context, JSObjectRef object) {
+const char *CYPoolCCYON(CYPool &pool, JSContextRef context, JSObjectRef object) {
JSValueRef toCYON(CYGetProperty(context, object, toCYON_s));
if (CYIsCallable(context, toCYON)) {
JSValueRef value(CYCallAsFunction(context, (JSObjectRef) toCYON, object, 0, NULL));
JSPropertyNameArrayRelease(names);
std::string string(str.str());
- return apr_pstrmemdup(pool, string.c_str(), string.size());
+ return pool.strmemdup(string.c_str(), string.size());
}
static JSValueRef Array_callAsFunction_toCYON(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
return JSObjectMake(context, Functor_, internal);
}
-static bool CYGetOffset(apr_pool_t *pool, JSContextRef context, JSStringRef value, ssize_t &index) {
+static bool CYGetOffset(CYPool &pool, JSContextRef context, JSStringRef value, ssize_t &index) {
return CYGetOffset(CYPoolCString(pool, context, value), index);
}
}
}
-void CYPoolFFI(apr_pool_t *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) {
+void CYPoolFFI(CYPool *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) {
switch (type->primitive) {
case sig::boolean_P:
*reinterpret_cast<bool *>(data) = JSValueToBoolean(context, value);
break;
case sig::string_P:
- *reinterpret_cast<const char **>(data) = CYPoolCString(pool, context, value);
+ _assert(pool != NULL);
+ *reinterpret_cast<const char **>(data) = CYPoolCString(*pool, context, value);
break;
case sig::struct_P: {
}
}
-static bool Index_(apr_pool_t *pool, JSContextRef context, Struct_privateData *internal, JSStringRef property, ssize_t &index, uint8_t *&base) {
+static bool Index_(CYPool &pool, JSContextRef context, Struct_privateData *internal, JSStringRef property, ssize_t &index, uint8_t *&base) {
Type_privateData *typical(internal->type_);
sig::Type *type(typical->type_);
if (type == NULL)
}
}
-JSValueRef CYCallFunction(apr_pool_t *pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception, sig::Signature *signature, ffi_cif *cif, void (*function)()) { CYTry {
+JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception, sig::Signature *signature, ffi_cif *cif, void (*function)()) { CYTry {
if (setups + count != signature->count - 1)
throw CYJSError(context, "incorrect number of arguments to ffi function");
ffi_type *ffi(cif->arg_types[index]);
// XXX: alignment?
values[index] = new(pool) uint8_t[ffi->size];
- CYPoolFFI(pool, context, element->type, ffi, values[index], arguments[index - setups]);
+ CYPoolFFI(&pool, context, element->type, ffi, values[index], arguments[index - setups]);
}
uint8_t value[cif->rtype->size];
// XXX: alignment?
uint8_t value[ffi->size];
CYPool pool;
- CYPoolFFI(pool, context, type, ffi, value, arguments[0]);
+ CYPoolFFI(&pool, context, type, ffi, value, arguments[0]);
return CYFromFFI(context, type, ffi, value);
} CYCatch(NULL) }
return JSContextGetGlobalObject(context);
}
-const char *CYExecute(apr_pool_t *pool, CYUTF8String code) {
+const char *CYExecute(CYPool &pool, CYUTF8String code) {
JSContextRef context(CYGetJSContext());
JSValueRef exception(NULL), result;
throw CYJSError(context, value);
}
-const char *CYJSError::PoolCString(apr_pool_t *pool) const {
+const char *CYJSError::PoolCString(CYPool &pool) const {
// XXX: this used to be CYPoolCString
return CYPoolCCYON(pool, context_, value_);
}
va_list args;
va_start(args, format);
- const char *message(apr_pvsprintf(pool, format, args));
+ const char *message(pool.vsprintf(format, args));
va_end(args);
value_ = CYCastJSError(context, message);
#include <sys/un.h>
struct CYExecute_ {
- apr_pool_t *pool_;
+ CYPool &pool_;
const char * volatile data_;
};
return NULL;
}
-extern "C" void CYHandleClient(apr_pool_t *pool, int socket) {
+extern "C" void CYHandleClient(CYPool &pool, int socket) {
CYClient *client(new(pool) CYClient(socket));
apr_threadattr_t *attr;
- _aprcall(apr_threadattr_create(&attr, client->pool_));
- _aprcall(apr_thread_create(&client->thread_, attr, &OnClient, client, client->pool_));
+ _aprcall(apr_threadattr_create(&attr, *client->pool_));
+ _aprcall(apr_thread_create(&client->thread_, attr, &OnClient, client, *client->pool_));
}
extern "C" void CYHandleServer(pid_t pid) {
_syscall(connect(socket, reinterpret_cast<sockaddr *>(&address), SUN_LEN(&address)));
- apr_pool_t *pool;
- apr_pool_create(&pool, NULL);
-
- CYHandleClient(pool, socket);
+ // XXX: this leaks memory... really?
+ CYHandleClient(*new CYPool(), socket);
} catch (const CYException &error) {
CYPool pool;
fprintf(stderr, "%s\n", error.PoolCString(pool));
#ifndef CYCRIPT_INTERNAL_HPP
#define CYCRIPT_INTERNAL_HPP
-#include "Pooling.hpp"
+#include <sig/parse.hpp>
+#include <sig/ffi_type.hpp>
#include <JavaScriptCore/JSBase.h>
#include <JavaScriptCore/JSContextRef.h>
#include <JavaScriptCore/JSObjectRef.h>
#include <JavaScriptCore/JSValueRef.h>
-#include <sig/parse.hpp>
-#include <sig/ffi_type.hpp>
+#include "Pooling.hpp"
JSGlobalContextRef CYGetJSContext(JSContextRef context);
-void Structor_(apr_pool_t *pool, sig::Type *&type);
+void Structor_(CYPool &pool, sig::Type *&type);
JSObjectRef CYMakeType(JSContextRef context, const char *type);
JSObjectRef CYMakeType(JSContextRef context, sig::Type *type);
sig::Type *type_;
void Set(sig::Type *type) {
- type_ = new(pool_) sig::Type;
- sig::Copy(pool_, *type_, *type);
+ type_ = new(*pool_) sig::Type;
+ sig::Copy(*pool_, *type_, *type);
}
- Type_privateData(apr_pool_t *pool, const char *type) :
+ Type_privateData(CYPool &pool, const char *type) :
+ CYData(pool),
ffi_(NULL)
{
- _assert(pool != NULL);
- pool_ = pool;
sig::Signature signature;
- sig::Parse(pool_, &signature, type, &Structor_);
+ sig::Parse(*pool_, &signature, type, &Structor_);
type_ = signature.elements[0].type;
}
ffi_(NULL)
{
sig::Signature signature;
- sig::Parse(pool_, &signature, type, &Structor_);
+ sig::Parse(*pool_, &signature, type, &Structor_);
type_ = signature.elements[0].type;
}
}
Type_privateData(sig::Type *type, ffi_type *ffi) {
- ffi_ = new(pool_) ffi_type;
- sig::Copy(pool_, *ffi_, *ffi);
+ ffi_ = new(*pool_) ffi_type;
+ sig::Copy(*pool_, *ffi_, *ffi);
Set(type);
}
ffi_type *GetFFI() {
if (ffi_ == NULL) {
- ffi_ = new(pool_) ffi_type;
+ ffi_ = new(*pool_) ffi_type;
sig::Element element;
element.name = NULL;
signature.count = 1;
ffi_cif cif;
- sig::sig_ffi_cif(pool_, &sig::ObjectiveC, &signature, &cif);
+ sig::sig_ffi_cif(*pool_, &sig::ObjectiveC, &signature, &cif);
*ffi_ = *cif.rtype;
}
Functor(const char *type, void (*value)()) :
CYValue(reinterpret_cast<void *>(value))
{
- sig::Parse(pool_, &signature_, type, &Structor_);
- sig::sig_ffi_cif(pool_, &sig::ObjectiveC, &signature_, &cif_);
+ sig::Parse(*pool_, &signature_, type, &Structor_);
+ sig::sig_ffi_cif(*pool_, &sig::ObjectiveC, &signature_, &cif_);
}
void (*GetValue() const)() {
#include <ffi.h>
#endif
-#include <apr_pools.h>
-
-#include <String.hpp>
+#include "Pooling.hpp"
+#include "String.hpp"
extern JSStringRef Array_s;
extern JSStringRef cy_s;
JSObjectRef CYGetGlobalObject(JSContextRef context);
extern "C" void CYSetupContext(JSGlobalContextRef context);
-const char *CYExecute(apr_pool_t *pool, CYUTF8String code);
+const char *CYExecute(CYPool &pool, CYUTF8String code);
void CYSetArgs(int argc, const char *argv[]);
bool CYCastBool(JSContextRef context, JSValueRef value);
double CYCastDouble(JSContextRef context, JSValueRef value);
-CYUTF8String CYPoolUTF8String(apr_pool_t *pool, JSContextRef context, JSStringRef value);
-const char *CYPoolCString(apr_pool_t *pool, JSContextRef context, JSStringRef value);
+CYUTF8String CYPoolUTF8String(CYPool &pool, JSContextRef context, JSStringRef value);
+const char *CYPoolCString(CYPool &pool, JSContextRef context, JSStringRef value);
JSValueRef CYGetProperty(JSContextRef context, JSObjectRef object, size_t index);
JSValueRef CYGetProperty(JSContextRef context, JSObjectRef object, JSStringRef name);
return reinterpret_cast<Type_>(CYCastPointer_(context, value));
}
-void CYPoolFFI(apr_pool_t *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value);
+void CYPoolFFI(CYPool *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value);
JSValueRef CYFromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, bool initialize = false, JSObjectRef owner = NULL);
-JSValueRef CYCallFunction(apr_pool_t *pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception, sig::Signature *signature, ffi_cif *cif, void (*function)());
+JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception, sig::Signature *signature, ffi_cif *cif, void (*function)());
bool CYIsCallable(JSContextRef context, JSValueRef value);
JSValueRef CYCallAsFunction(JSContextRef context, JSObjectRef function, JSObjectRef _this, size_t count, const JSValueRef arguments[]);
-const char *CYPoolCCYON(apr_pool_t *pool, JSContextRef context, JSObjectRef object);
+const char *CYPoolCCYON(CYPool &pool, JSContextRef context, JSObjectRef object);
struct CYHooks {
void *(*ExecuteStart)(JSContextRef);
void (*Initialize)();
void (*SetupContext)(JSContextRef);
- bool (*PoolFFI)(apr_pool_t *, JSContextRef, sig::Type *, ffi_type *, void *, JSValueRef);
+ bool (*PoolFFI)(CYPool *, JSContextRef, sig::Type *, ffi_type *, void *, JSValueRef);
JSValueRef (*FromFFI)(JSContextRef, sig::Type *, ffi_type *, void *, bool, JSObjectRef);
};
JSValueRef CYArrayGet(JSContextRef context, JSObjectRef array, size_t index);
void CYArrayPush(JSContextRef context, JSObjectRef array, JSValueRef value);
-const char *CYPoolCString(apr_pool_t *pool, JSContextRef context, JSValueRef value);
+const char *CYPoolCString(CYPool &pool, JSContextRef context, JSValueRef value);
JSStringRef CYCopyJSString(const char *value);
JSStringRef CYCopyJSString(JSStringRef value);
#define UCS_2_INTERNAL "UCS-2-INTERNAL"
#endif
-CYUTF8String CYPoolUTF8String(apr_pool_t *pool, CYUTF16String utf16) {
+CYUTF8String CYPoolUTF8String(CYPool &pool, CYUTF16String utf16) {
_assert(pool != NULL);
const char *in(reinterpret_cast<const char *>(utf16.data));
return utf8;
}
-CYUTF16String CYPoolUTF16String(apr_pool_t *pool, CYUTF8String utf8) {
+CYUTF16String CYPoolUTF16String(CYPool &pool, CYUTF8String utf8) {
_assert(pool != NULL);
const char *in(utf8.data);
out << *driver.program_;
std::string code(str.str());
- CYUTF16String utf16(CYPoolUTF16String(remote, CYUTF8String(code.c_str(), code.size())));
+ CYPool pool(remote);
+ CYUTF16String utf16(CYPoolUTF16String(pool, CYUTF8String(code.c_str(), code.size())));
*data = utf16.data;
*size = utf16.size;
}
-static apr_pool_t *Pool_;
-
static bool initialized_;
void CYInitializeStatic() {
else return;
_aprcall(apr_initialize());
- _aprcall(apr_pool_create(&Pool_, NULL));
}
-apr_pool_t *CYGetGlobalPool() {
+CYPool &CYGetGlobalPool() {
CYInitializeStatic();
- return Pool_;
+ static CYPool pool;
+ return pool;
}
void CYThrow(const char *format, ...) {
va_end(args);
}
-const char *CYPoolError::PoolCString(apr_pool_t *pool) const {
- return apr_pstrdup(pool, message_);
+const char *CYPoolError::PoolCString(CYPool &pool) const {
+ return pool.strdup(message_);
}
CYPoolError::CYPoolError(const char *format, ...) {
va_list args;
va_start(args, format);
- message_ = apr_pvsprintf(pool_, format, args);
+ message_ = pool_.vsprintf(format, args);
va_end(args);
}
CYPoolError::CYPoolError(const char *format, va_list args) {
- message_ = apr_pvsprintf(pool_, format, args);
+ message_ = pool_.vsprintf(format, args);
}
depth = (depth + sizeof(uintptr_t) + 1) / sizeof(uintptr_t) * sizeof(uintptr_t);
CYPool pool;
- uint8_t *local(reinterpret_cast<uint8_t *>(apr_palloc(pool, depth)));
+ uint8_t *local(reinterpret_cast<uint8_t *>(pool(depth)));
Baton *baton(reinterpret_cast<Baton *>(local));
baton->__pthread_set_self = &__pthread_set_self;
BLOCK_HAS_SIGNATURE = 1 << 30,
};
-JSValueRef CYSendMessage(apr_pool_t *pool, JSContextRef context, id self, Class super, SEL _cmd, size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception);
+JSValueRef CYSendMessage(CYPool &pool, JSContextRef context, id self, Class super, SEL _cmd, size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception);
/* Objective-C Pool Release {{{ */
apr_status_t CYPoolRelease_(void *data) {
return APR_SUCCESS;
}
-id CYPoolRelease_(apr_pool_t *pool, id object) {
+id CYPoolRelease_(CYPool *pool, id object) {
if (object == nil)
return nil;
else if (pool == NULL)
return [object autorelease];
else {
- apr_pool_cleanup_register(pool, object, &CYPoolRelease_, &apr_pool_cleanup_null);
+ apr_pool_cleanup_register(*pool, object, &CYPoolRelease_, &apr_pool_cleanup_null);
return object;
}
}
template <typename Type_>
-Type_ CYPoolRelease(apr_pool_t *pool, Type_ object) {
+Type_ CYPoolRelease(CYPool *pool, Type_ object) {
return (Type_) CYPoolRelease_(pool, (id) object);
}
/* }}} */
/* Objective-C Strings {{{ */
-const char *CYPoolCString(apr_pool_t *pool, JSContextRef context, NSString *value) {
+const char *CYPoolCString(CYPool &pool, JSContextRef context, NSString *value) {
if (pool == NULL)
return [value UTF8String];
else {
return CYCopyNSString(context, CYJSString(context, value));
}
-NSString *CYCastNSString(apr_pool_t *pool, const CYUTF8String &value) {
+NSString *CYCastNSString(CYPool *pool, const CYUTF8String &value) {
return CYPoolRelease(pool, CYCopyNSString(value));
}
-NSString *CYCastNSString(apr_pool_t *pool, SEL sel) {
+NSString *CYCastNSString(CYPool *pool, SEL sel) {
const char *name(sel_getName(sel));
return CYPoolRelease(pool, CYCopyNSString(CYUTF8String(name, strlen(name))));
}
-NSString *CYCastNSString(apr_pool_t *pool, JSContextRef context, JSStringRef value) {
+NSString *CYCastNSString(CYPool *pool, JSContextRef context, JSStringRef value) {
return CYPoolRelease(pool, CYCopyNSString(context, value));
}
return CYGetIndex(CYCastUTF8String(value));
}
-bool CYGetOffset(apr_pool_t *pool, JSContextRef context, NSString *value, ssize_t &index) {
+bool CYGetOffset(CYPool &pool, JSContextRef context, NSString *value, ssize_t &index) {
return CYGetOffset(CYPoolCString(pool, context, value), index);
}
name = property_getName(property);
const char *attributes(property_getAttributes(property));
- for (char *state, *token(apr_strtok(apr_pstrdup(pool_, attributes), ",", &state)); token != NULL; token = apr_strtok(NULL, ",", &state)) {
+ for (char *state, *token(apr_strtok(pool_.strdup(attributes), ",", &state)); token != NULL; token = apr_strtok(NULL, ",", &state)) {
switch (*token) {
case 'R': readonly = true; break;
case 'C': copy = true; break;
const char *Getter() {
if (getter_ == NULL)
- getter_ = apr_pstrdup(pool_, name);
+ getter_ = pool_.strdup(name);
return getter_;
}
return reinterpret_cast<NSObject *>(literal);
}
-NSObject *CYCastNSObject(apr_pool_t *pool, JSContextRef context, JSObjectRef object) {
+NSObject *CYCastNSObject(CYPool *pool, JSContextRef context, JSObjectRef object) {
if (CYJSValueIsNSObject(context, object)) {
Instance *internal(reinterpret_cast<Instance *>(JSObjectGetPrivate(object)));
return internal->GetValue();
@end
#endif
-id CYNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef value, bool cast) {
+id CYNSObject(CYPool *pool, JSContextRef context, JSValueRef value, bool cast) {
id object;
bool copy;
return [object retain];
}
-NSObject *CYCastNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef value) {
+NSObject *CYCastNSObject(CYPool *pool, JSContextRef context, JSValueRef value) {
return CYNSObject(pool, context, value, true);
}
-NSObject *CYCopyNSObject(apr_pool_t *pool, JSContextRef context, JSValueRef value) {
- return CYNSObject(pool, context, value, false);
+NSObject *CYCopyNSObject(CYPool &pool, JSContextRef context, JSValueRef value) {
+ return CYNSObject(&pool, context, value, false);
}
/* Bridge: NSArray {{{ */
#endif
}
-Class CYCastClass(apr_pool_t *pool, JSContextRef context, JSValueRef value) {
- id self(CYCastNSObject(pool, context, value));
+Class CYCastClass(CYPool &pool, JSContextRef context, JSValueRef value) {
+ id self(CYCastNSObject(&pool, context, value));
if (CYIsClass(self))
return (Class) self;
throw CYJSError(context, "got something that is not a Class");
size_t size(JSPropertyNameArrayGetCount(names));
NSMutableArray *array([NSMutableArray arrayWithCapacity:size]);
for (size_t index(0); index != size; ++index)
- [array addObject:CYCastNSString(pool, context, JSPropertyNameArrayGetNameAtIndex(names, index))];
+ [array addObject:CYCastNSString(&pool, context, JSPropertyNameArrayGetNameAtIndex(names, index))];
return array;
}
ffi_call(cif, function, value, values);
} CYSadCatch() }
-static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) { CYSadTry {
+static bool CYObjectiveC_PoolFFI(CYPool *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) { CYSadTry {
switch (type->primitive) {
// XXX: do something epic about blocks
case sig::block_P:
case sig::object_P:
case sig::typename_P:
+ // XXX: this works for return values, but not for properties and fields
*reinterpret_cast<id *>(data) = CYCastNSObject(pool, context, value);
break;
return false;
}
-static const char *CYPoolTypeEncoding(apr_pool_t *pool, JSContextRef context, SEL sel, objc_method *method) {
+static const char *CYPoolTypeEncoding(CYPool &pool, JSContextRef context, SEL sel, objc_method *method) {
if (method != NULL)
return method_getTypeEncoding(method);
return true;
CYPool pool;
- NSString *name(CYCastNSString(pool, context, property));
+ NSString *name(CYCastNSString(&pool, context, property));
if (CYInternal *internal = [CYInternal get:self])
if ([internal hasProperty:property inContext:context])
return Internal::Make(context, self, object);
CYPool pool;
- NSString *name(CYCastNSString(pool, context, property));
+ NSString *name(CYCastNSString(&pool, context, property));
if (CYInternal *internal = [CYInternal get:self])
if (JSValueRef value = [internal getProperty:property inContext:context])
CYPool pool;
- NSString *name(CYCastNSString(pool, context, property));
- NSObject *data(CYCastNSObject(pool, context, value));
+ NSString *name(CYCastNSString(&pool, context, property));
+ NSObject *data(CYCastNSObject(&pool, context, value));
CYPoolTry {
if ([self cy$setProperty:name to:data])
if (count == 0)
throw CYJSError(context, "incorrect number of arguments to Instance");
CYPool pool;
- id value(CYCastNSObject(pool, context, arguments[0]));
+ id value(CYCastNSObject(&pool, context, arguments[0]));
if (value == nil)
value = [NSNull null];
return CYCastJSValue(context, [value cy$box]);
if (objc_ivar *ivar = object_getInstanceVariable(self, name, NULL)) {
Type_privateData type(pool, ivar_getTypeEncoding(ivar));
- CYPoolFFI(pool, context, type.type_, type.GetFFI(), reinterpret_cast<uint8_t *>(self) + ivar_getOffset(ivar), value);
+ CYPoolFFI(&pool, context, type.type_, type.GetFFI(), reinterpret_cast<uint8_t *>(self) + ivar_getOffset(ivar), value);
return true;
}
static JSValueRef ObjectiveC_Classes_getProperty(JSContextRef context, JSObjectRef object, JSStringRef property, JSValueRef *exception) { CYTry {
CYPool pool;
- NSString *name(CYCastNSString(pool, context, property));
+ NSString *name(CYCastNSString(&pool, context, property));
if (Class _class = NSClassFromString(name))
return CYMakeInstance(context, _class, true);
return NULL;
}
#endif
-JSValueRef CYSendMessage(apr_pool_t *pool, JSContextRef context, id self, Class _class, SEL _cmd, size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception) { CYTry {
+JSValueRef CYSendMessage(CYPool &pool, JSContextRef context, id self, Class _class, SEL _cmd, size_t count, const JSValueRef arguments[], bool initialize, JSValueRef *exception) { CYTry {
const char *type;
if (_class == NULL)
if (uninitialized)
internal->value_ = nil;
} else {
- self = CYCastNSObject(pool, context, arguments[0]);
+ self = CYCastNSObject(&pool, context, arguments[0]);
_class = nil;
uninitialized = false;
}
Message_privateData *internal(reinterpret_cast<Message_privateData *>(JSObjectGetPrivate(object)));
// XXX: handle Instance::Uninitialized?
- id self(CYCastNSObject(pool, context, _this));
+ id self(CYCastNSObject(&pool, context, _this));
void *setup[2];
setup[0] = &self;
if (count != 2)
throw CYJSError(context, "incorrect number of arguments to Super constructor");
CYPool pool;
- id self(CYCastNSObject(pool, context, arguments[0]));
+ id self(CYCastNSObject(&pool, context, arguments[0]));
Class _class(CYCastClass(pool, context, arguments[1]));
return cy::Super::Make(context, self, _class);
} CYCatch(NULL) }
$objc_getAssociatedObject = reinterpret_cast<id (*)(id, void *)>(dlsym(RTLD_DEFAULT, "objc_getAssociatedObject"));
$objc_removeAssociatedObjects = reinterpret_cast<void (*)(id)>(dlsym(RTLD_DEFAULT, "objc_removeAssociatedObjects"));
- apr_pool_t *pool(CYGetGlobalPool());
+ CYPool &pool(CYGetGlobalPool());
Object_type = new(pool) Type_privateData("@");
Selector_type = new(pool) Type_privateData(":");
if (part->value_)
str << ':';
}
- return $S(apr_pstrdup($pool, str.str().c_str()));
+ return $S($pool.strdup(str.str().c_str()));
}
CYExpression *CYSendDirect::Replace(CYContext &context) {
#ifndef CYCRIPT_POOLING_HPP
#define CYCRIPT_POOLING_HPP
+#include <cstdarg>
+#include <cstdlib>
+
#include <apr_pools.h>
#include <apr_strings.h>
#include "Local.hpp"
#include "Standard.hpp"
-#include <cstdlib>
-
-_finline void *operator new(size_t size, apr_pool_t *pool) {
- return apr_palloc(pool, size);
-}
-
-_finline void *operator new [](size_t size, apr_pool_t *pool) {
- return apr_palloc(pool, size);
-}
-
class CYPool {
private:
apr_pool_t *pool_;
_aprcall(apr_pool_create(&pool_, NULL));
}
+ CYPool(apr_pool_t *pool) :
+ pool_(pool)
+ {
+ }
+
~CYPool() {
apr_pool_destroy(pool_);
}
return pool_;
}
- char *operator ()(const char *data) const {
+ void *operator()(size_t size) const {
+ return apr_palloc(pool_, size);
+ }
+
+ char *strdup(const char *data) const {
return apr_pstrdup(pool_, data);
}
- char *operator ()(const char *data, size_t size) const {
+ char *strndup(const char *data, size_t size) const {
return apr_pstrndup(pool_, data, size);
}
+
+ char *strmemdup(const char *data, size_t size) const {
+ return apr_pstrmemdup(pool_, data, size);
+ }
+
+ char *sprintf(const char *format, ...) const {
+ va_list args;
+ va_start(args, format);
+ char *data(vsprintf(format, args));
+ va_end(args);
+ return data;
+ }
+
+ char *vsprintf(const char *format, va_list args) const {
+ return apr_pvsprintf(pool_, format, args);
+ }
};
+_finline void *operator new(size_t size, CYPool &pool) {
+ return pool(size);
+}
+
+_finline void *operator new [](size_t size, CYPool &pool) {
+ return pool(size);
+}
+
struct CYData {
- apr_pool_t *pool_;
+ CYPool *pool_;
unsigned count_;
CYData() :
{
}
+ CYData(CYPool &pool) :
+ pool_(&pool),
+ count_(_not(unsigned))
+ {
+ }
+
virtual ~CYData() {
}
- static void *operator new(size_t size, apr_pool_t *pool) {
- void *data(apr_palloc(pool, size));
- reinterpret_cast<CYData *>(data)->pool_ = pool;
+ static void *operator new(size_t size, CYPool &pool) {
+ void *data(pool(size));
+ reinterpret_cast<CYData *>(data)->pool_ = &pool;
return data;
}
static void *operator new(size_t size) {
- apr_pool_t *pool;
- _aprcall(apr_pool_create(&pool, NULL));
- return operator new(size, pool);
+ return operator new(size, *new CYPool());
}
static void operator delete(void *data) {
- apr_pool_destroy(reinterpret_cast<CYData *>(data)->pool_);
+ delete reinterpret_cast<CYData *>(data)->pool_;
}
};
template <typename Type_>
struct CYPoolAllocator {
- apr_pool_t *pool_;
+ CYPool *pool_;
typedef Type_ value_type;
typedef value_type *pointer;
}
pointer allocate(size_type size, const void *hint = 0) {
- return reinterpret_cast<pointer>(apr_palloc(pool_, size));
+ return reinterpret_cast<pointer>((*pool_)(size));
}
void deallocate(pointer data, size_type size) {
public CYPool
{
private:
- CYLocal<apr_pool_t> local_;
+ CYLocal<CYPool> local_;
public:
CYLocalPool() :
CYPool(),
- local_(operator apr_pool_t *())
+ local_(this)
{
}
};
#define $pool \
- CYLocal<apr_pool_t>::Get()
+ (*CYLocal<CYPool>::Get())
#endif/*CYCRIPT_POOLING_HPP*/
}
CYIdentifier *CYContext::Unique() {
- return $ CYIdentifier(apr_psprintf($pool, "$cy%u", unique_++));
+ return $ CYIdentifier($pool.sprintf("$cy%u", unique_++));
}
CYStatement *CYContinue::Replace(CYContext &context) {
CYString *CYNumber::String(CYContext &context) {
// XXX: there is a precise algorithm for this
- return $S(apr_psprintf($pool, "%.17g", Value()));
+ return $S($pool.sprintf("%.17g", Value()));
}
CYExpression *CYObject::Replace(CYContext &context) {
const char *name;
if (context.options_.verbose_)
- name = apr_psprintf($pool, "$%"APR_SIZE_T_FMT"", offset);
+ name = $pool.sprintf("$%"APR_SIZE_T_FMT"", offset);
else {
char id[8];
id[7] = '\0';
goto id;
}
- name = apr_pstrmemdup($pool, id + position, 7 - position);
+ name = $pool.strmemdup(id + position, 7 - position);
// XXX: at some point, this could become a keyword
}
bool CYIsKey(CYUTF8String value);
bool CYGetOffset(const char *value, ssize_t &index);
-CYUTF8String CYPoolUTF8String(apr_pool_t *pool, CYUTF16String utf16);
-CYUTF16String CYPoolUTF16String(apr_pool_t *pool, CYUTF8String utf8);
+CYUTF8String CYPoolUTF8String(CYPool &pool, CYUTF16String utf16);
+CYUTF16String CYPoolUTF16String(CYPool &pool, CYUTF8String utf8);
#endif/*CYCRIPT_STRING_HPP*/
#ifndef CYCRIPT_HPP
#define CYCRIPT_HPP
-#include <apr_pools.h>
#include <sig/types.hpp>
#include <sstream>
+#include "Pooling.hpp"
#include "String.hpp"
void CYInitializeStatic();
double CYCastDouble(const char *value, size_t size);
double CYCastDouble(const char *value);
-extern "C" void CYHandleClient(apr_pool_t *pool, int socket);
+extern "C" void CYHandleClient(CYPool &pool, int socket);
template <typename Type_>
bool CYRecvAll(int socket, Type_ *data, size_t size) {
return CYSendAll_(socket, reinterpret_cast<const uint8_t *>(data), size);
}
-apr_pool_t *CYGetGlobalPool();
+CYPool &CYGetGlobalPool();
#endif/*CYCRIPT_HPP*/
#define _GNU_SOURCE
#endif
-#include <apr_strings.h>
#include "Pooling.hpp"
#include "sig/parse.hpp"
namespace sig {
-void Copy(apr_pool_t *pool, Element &lhs, Element &rhs) {
- lhs.name = apr_pstrdup(pool, rhs.name);
+void Copy(CYPool &pool, Element &lhs, Element &rhs) {
+ lhs.name = pool.strdup(rhs.name);
if (rhs.type == NULL)
lhs.type = NULL;
else {
lhs.offset = rhs.offset;
}
-void Copy(apr_pool_t *pool, Signature &lhs, Signature &rhs) {
+void Copy(CYPool &pool, Signature &lhs, Signature &rhs) {
size_t count(rhs.count);
lhs.count = count;
lhs.elements = new(pool) Element[count];
Copy(pool, lhs.elements[index], rhs.elements[index]);
}
-void Copy(apr_pool_t *pool, Type &lhs, Type &rhs) {
+void Copy(CYPool &pool, Type &lhs, Type &rhs) {
lhs.primitive = rhs.primitive;
- lhs.name = apr_pstrdup(pool, rhs.name);
+ lhs.name = pool.strdup(rhs.name);
lhs.flags = rhs.flags;
if (sig::IsAggregate(rhs.primitive))
}
}
-void Copy(apr_pool_t *pool, ffi_type &lhs, ffi_type &rhs) {
+void Copy(CYPool &pool, ffi_type &lhs, ffi_type &rhs) {
lhs.size = rhs.size;
lhs.alignment = rhs.alignment;
lhs.type = rhs.type;
namespace sig {
void sig_ffi_types(
- apr_pool_t *pool,
- ffi_type *(*sig_ffi_type)(apr_pool_t *, struct Type *),
+ CYPool &pool,
+ ffi_type *(*sig_ffi_type)(CYPool &, struct Type *),
struct Signature *signature,
ffi_type **types,
size_t skip = 0,
types[index - skip + offset] = (*sig_ffi_type)(pool, signature->elements[index].type);
}
-ffi_type *ObjectiveC(apr_pool_t *pool, struct Type *type) {
+ffi_type *ObjectiveC(CYPool &pool, struct Type *type) {
switch (type->primitive) {
case typename_P: return &ffi_type_pointer;
case array_P: {
// XXX: this is really lame
- ffi_type *aggregate(reinterpret_cast<ffi_type *>(apr_palloc(pool, sizeof(ffi_type))));
+ ffi_type *aggregate(reinterpret_cast<ffi_type *>(pool(sizeof(ffi_type))));
aggregate->size = 0;
aggregate->alignment = 0;
aggregate->type = FFI_TYPE_STRUCT;
ffi_type *element(ObjectiveC(pool, type->data.data.type));
size_t size(type->data.data.size);
- aggregate->elements = reinterpret_cast<ffi_type **>(apr_palloc(pool, (size + 1) * sizeof(ffi_type *)));
+ aggregate->elements = reinterpret_cast<ffi_type **>(pool((size + 1) * sizeof(ffi_type *)));
for (size_t i(0); i != size; ++i)
aggregate->elements[i] = element;
aggregate->elements[size] = NULL;
case void_P: return &ffi_type_void;
case struct_P: {
- ffi_type *aggregate(reinterpret_cast<ffi_type *>(apr_palloc(pool, sizeof(ffi_type))));
+ ffi_type *aggregate(reinterpret_cast<ffi_type *>(pool(sizeof(ffi_type))));
aggregate->size = 0;
aggregate->alignment = 0;
aggregate->type = FFI_TYPE_STRUCT;
- aggregate->elements = reinterpret_cast<ffi_type **>(apr_palloc(pool, (type->data.signature.count + 1) * sizeof(ffi_type *)));
+ aggregate->elements = reinterpret_cast<ffi_type **>(pool((type->data.signature.count + 1) * sizeof(ffi_type *)));
sig_ffi_types(pool, &ObjectiveC, &type->data.signature, aggregate->elements);
aggregate->elements[type->data.signature.count] = NULL;
}
}
-ffi_type *Java(apr_pool_t *pool, struct Type *type) {
+ffi_type *Java(CYPool &pool, struct Type *type) {
switch (type->primitive) {
case typename_P: return &ffi_type_pointer;
case union_P: return &ffi_type_pointer;
}
void sig_ffi_cif(
- apr_pool_t *pool,
- ffi_type *(*sig_ffi_type)(apr_pool_t *, struct Type *),
+ CYPool &pool,
+ ffi_type *(*sig_ffi_type)(CYPool &, struct Type *),
struct Signature *signature,
ffi_cif *cif,
size_t skip,
size_t offset
) {
if (types == NULL)
- types = reinterpret_cast<ffi_type **>(apr_palloc(pool, (signature->count - 1) * sizeof(ffi_type *)));
+ types = reinterpret_cast<ffi_type **>(pool((signature->count - 1) * sizeof(ffi_type *)));
ffi_type *type = (*sig_ffi_type)(pool, signature->elements[0].type);
sig_ffi_types(pool, sig_ffi_type, signature, types, 1 + skip, offset);
ffi_status status = ffi_prep_cif(cif, FFI_DEFAULT_ABI, signature->count - 1 - skip + offset, type, types);
#ifndef SIG_FFI_TYPE_H
#define SIG_FFI_TYPE_H
-#include <apr_pools.h>
-
#ifdef HAVE_FFI_FFI_H
#include <ffi/ffi.h>
#else
#include <ffi.h>
#endif
+#include "Pooling.hpp"
#include "sig/types.hpp"
namespace sig {
-ffi_type *ObjectiveC(apr_pool_t *pool, struct Type *type);
-ffi_type *Java(apr_pool_t *pool, struct Type *type);
+ffi_type *ObjectiveC(CYPool &pool, struct Type *type);
+ffi_type *Java(CYPool &pool, struct Type *type);
void sig_ffi_cif(
- apr_pool_t *pool,
- ffi_type *(*sig_ffi_type)(apr_pool_t *, struct Type *),
+ CYPool &pool,
+ ffi_type *(*sig_ffi_type)(CYPool &, struct Type *),
struct Signature *signature,
ffi_cif *cif,
size_t skip = 0,
size_t offset = 0
);
-void Copy(apr_pool_t *pool, ffi_type &lhs, ffi_type &rhs);
+void Copy(CYPool &pool, ffi_type &lhs, ffi_type &rhs);
}
**/
/* }}} */
-#include <apr_strings.h>
#include "sig/parse.hpp"
#include "Error.hpp"
namespace sig {
-void Parse_(apr_pool_t *pool, struct Signature *signature, const char **name, char eos, Callback callback);
-struct Type *Parse_(apr_pool_t *pool, const char **name, char eos, bool named, Callback callback);
+void Parse_(CYPool &pool, struct Signature *signature, const char **name, char eos, Callback callback);
+struct Type *Parse_(CYPool &pool, const char **name, char eos, bool named, Callback callback);
/* XXX: I really screwed up this time */
-void *prealloc_(apr_pool_t *pool, void *odata, size_t osize, size_t nsize) {
- void *ndata = apr_palloc(pool, nsize);
+void *prealloc_(CYPool &pool, void *odata, size_t osize, size_t nsize) {
+ void *ndata(pool(nsize));
memcpy(ndata, odata, osize);
return ndata;
}
-void Parse_(apr_pool_t *pool, struct Signature *signature, const char **name, char eos, Callback callback) {
+void Parse_(CYPool &pool, struct Signature *signature, const char **name, char eos, Callback callback) {
_assert(*name != NULL);
// XXX: this is just a stupid check :(
element->name = NULL;
else {
const char *quote = strchr(++*name, '"');
- element->name = apr_pstrmemdup(pool, *name, quote - *name);
+ element->name = pool.strmemdup(*name, quote - *name);
*name = quote + 1;
}
}
}
-struct Type *Parse_(apr_pool_t *pool, const char **name, char eos, bool named, Callback callback) {
+Type *Parse_(CYPool &pool, const char **name, char eos, bool named, Callback callback) {
char next = *(*name)++;
if (next == '?')
return NULL;
- struct Type *type = (struct Type *) apr_palloc(pool, sizeof(struct Type));
+ Type *type(new(pool) Type());
_assert(type != NULL);
- memset(type, 0, sizeof(struct Type));
+ memset(type, 0, sizeof(Type));
parse:
switch (next) {
printf("unterminated specific id type {%s}\n", *name - 10);
_assert(false);
} else if (!named || quote[1] == eos || quote[1] == '"') {
- type->name = apr_pstrmemdup(pool, *name + 1, quote - *name - 1);
+ type->name = pool.strmemdup(*name + 1, quote - *name - 1);
*name = quote + 1;
}
}
);
size_t length = *name - begin - 1;
if (strncmp(begin, "?", length) != 0)
- type->name = (char *) apr_pstrmemdup(pool, begin, length);
+ type->name = (char *) pool.strmemdup(begin, length);
else
type->name = NULL;
return type;
}
-void Parse(apr_pool_t *pool, struct Signature *signature, const char *name, Callback callback) {
+void Parse(CYPool &pool, struct Signature *signature, const char *name, Callback callback) {
const char *temp = name;
Parse_(pool, signature, &temp, '\0', callback);
_assert(temp[-1] == '\0');
}
-const char *Unparse(apr_pool_t *pool, struct Signature *signature) {
+const char *Unparse(CYPool &pool, struct Signature *signature) {
const char *value = "";
size_t offset;
return value;
}
-const char *Unparse_(apr_pool_t *pool, struct Type *type) {
+const char *Unparse_(CYPool &pool, struct Type *type) {
switch (type->primitive) {
case typename_P: return "#";
- case union_P: return apr_psprintf(pool, "(%s)", Unparse(pool, &type->data.signature));
+ case union_P: return pool.sprintf("(%s)", Unparse(pool, &type->data.signature));
case string_P: return "*";
case selector_P: return ":";
case block_P: return "@?";
- case object_P: return type->name == NULL ? "@" : apr_psprintf(pool, "@\"%s\"", type->name);
+ case object_P: return type->name == NULL ? "@" : pool.sprintf("@\"%s\"", type->name);
case boolean_P: return "B";
case uchar_P: return "C";
case uint_P: return "I";
case array_P: {
const char *value = Unparse(pool, type->data.data.type);
- return apr_psprintf(pool, "[%"APR_SIZE_T_FMT"%s]", type->data.data.size, value);
+ return pool.sprintf("[%"APR_SIZE_T_FMT"%s]", type->data.data.size, value);
} break;
- case pointer_P: return apr_psprintf(pool, "^%s", type->data.data.type == NULL ? "v" : Unparse(pool, type->data.data.type));
- case bit_P: return apr_psprintf(pool, "b%"APR_SIZE_T_FMT"", type->data.data.size);
+ case pointer_P: return pool.sprintf("^%s", type->data.data.type == NULL ? "v" : Unparse(pool, type->data.data.type));
+ case bit_P: return pool.sprintf("b%"APR_SIZE_T_FMT"", type->data.data.size);
case char_P: return "c";
case double_P: return "d";
case float_P: return "f";
case longlong_P: return "q";
case short_P: return "s";
case void_P: return "v";
- case struct_P: return apr_psprintf(pool, "{%s=%s}", type->name == NULL ? "?" : type->name, Unparse(pool, &type->data.signature));
+ case struct_P: return pool.sprintf("{%s=%s}", type->name == NULL ? "?" : type->name, Unparse(pool, &type->data.signature));
}
_assert(false);
return NULL;
}
-const char *Unparse(apr_pool_t *pool, struct Type *type) {
+const char *Unparse(CYPool &pool, struct Type *type) {
if (type == NULL)
return "?";
#ifndef SIG_PARSE_H
#define SIG_PARSE_H
+#include "Pooling.hpp"
#include "sig/types.hpp"
-#include <apr_pools.h>
-
namespace sig {
-typedef void (*Callback)(apr_pool_t *pool, Type *&type);
-void Parse(apr_pool_t *pool, struct Signature *signature, const char *name, Callback callback);
+typedef void (*Callback)(CYPool &pool, Type *&type);
+void Parse(CYPool &pool, struct Signature *signature, const char *name, Callback callback);
-const char *Unparse(apr_pool_t *pool, struct Signature *signature);
-const char *Unparse(apr_pool_t *pool, struct Type *type);
+const char *Unparse(CYPool &pool, struct Signature *signature);
+const char *Unparse(CYPool &pool, struct Type *type);
-void Copy(apr_pool_t *pool, Type &lhs, Type &rhs);
-void Copy(apr_pool_t *pool, Signature &lhs, Signature &rhs);
-void Copy(apr_pool_t *pool, Type &lhs, Type &rhs);
+void Copy(CYPool &pool, Type &lhs, Type &rhs);
+void Copy(CYPool &pool, Signature &lhs, Signature &rhs);
+void Copy(CYPool &pool, Type &lhs, Type &rhs);
}
#ifndef SIG_TYPES_H
#define SIG_TYPES_H
+#include <cstdlib>
+#include <stdint.h>
+
#include "Standard.hpp"
namespace sig {
};
struct Element {
- char *name;
+ const char *name;
struct Type *type;
size_t offset;
};