+namespace sig {
+
+void Copy(apr_pool_t *pool, Type &lhs, Type &rhs);
+
+void Copy(apr_pool_t *pool, Element &lhs, Element &rhs) {
+ lhs.name = apr_pstrdup(pool, rhs.name);
+ if (rhs.type == NULL)
+ lhs.type = NULL;
+ else {
+ lhs.type = new(pool) Type;
+ Copy(pool, *lhs.type, *rhs.type);
+ }
+ lhs.offset = rhs.offset;
+}
+
+void Copy(apr_pool_t *pool, Signature &lhs, Signature &rhs) {
+ size_t count(rhs.count);
+ lhs.count = count;
+ lhs.elements = new(pool) Element[count];
+ for (size_t index(0); index != count; ++index)
+ Copy(pool, lhs.elements[index], rhs.elements[index]);
+}
+
+void Copy(apr_pool_t *pool, Type &lhs, Type &rhs) {
+ lhs.primitive = rhs.primitive;
+ lhs.name = apr_pstrdup(pool, rhs.name);
+ lhs.flags = rhs.flags;
+
+ if (sig::IsAggregate(rhs.primitive))
+ Copy(pool, lhs.data.signature, rhs.data.signature);
+ else {
+ if (rhs.data.data.type != NULL) {
+ lhs.data.data.type = new(pool) Type;
+ Copy(pool, *lhs.data.data.type, *rhs.data.data.type);
+ }
+
+ lhs.data.data.size = rhs.data.data.size;
+ }
+}
+
+void Copy(apr_pool_t *pool, ffi_type &lhs, ffi_type &rhs) {
+ lhs.size = rhs.size;
+ lhs.alignment = rhs.alignment;
+ lhs.type = rhs.type;
+ if (rhs.elements == NULL)
+ lhs.elements = NULL;
+ else {
+ size_t count(0);
+ while (rhs.elements[count] != NULL)
+ ++count;
+
+ lhs.elements = new(pool) ffi_type *[count + 1];
+ lhs.elements[count] = NULL;
+
+ for (size_t index(0); index != count; ++index) {
+ // XXX: if these are libffi native then you can just take them
+ ffi_type *ffi(new(pool) ffi_type);
+ lhs.elements[index] = ffi;
+ sig::Copy(pool, *ffi, *rhs.elements[index]);
+ }
+ }
+}
+
+}
+
+struct Type_privateData {
+ sig::Type type_;
+ ffi_type ffi_;
+ //size_t count_;
+
+ Type_privateData(apr_pool_t *pool, sig::Type *type, ffi_type *ffi) {
+ sig::Copy(pool, type_, *type);
+ sig::Copy(pool, ffi_, *ffi);
+
+ /*sig::Element element;
+ element.name = NULL;
+ element.type = type;
+ element.offset = 0;
+
+ sig::Signature signature;
+ signature.elements = &element;
+ signature.count = 1;
+
+ ffi_cif cif;
+ sig::sig_ffi_cif(pool, &sig::ObjectiveC, &signature, &cif);
+ ffi_ = *cif.rtype;*/
+
+ /*if (type_->type != FFI_TYPE_STRUCT)
+ count_ = 0;
+ else {
+ size_t count(0);
+ while (type_->elements[count] != NULL)
+ ++count;
+ count_ = count;
+ }*/
+ }
+};
+
+struct Struct_privateData :
+ Pointer_privateData
+{
+ JSObjectRef owner_;
+ Type_privateData *type_;
+
+ Struct_privateData() {
+ }
+};
+
+struct CStringMapLess :
+ std::binary_function<const char *, const char *, bool>
+{
+ _finline bool operator ()(const char *lhs, const char *rhs) const {
+ return strcmp(lhs, rhs) < 0;
+ }