xfer to odin
authorScott Wood <scott@buserror.net>
Wed, 4 Jul 2007 01:23:22 +0000 (20:23 -0500)
committerScott Wood <scott@buserror.net>
Wed, 4 Jul 2007 01:23:22 +0000 (20:23 -0500)
doc/orb/exceptions [new file with mode: 0644]
idlcomp/languages/c++/Makefile
idlcomp/languages/c++/interface-caller.cc
idlcomp/languages/c++/marshall.cc [new file with mode: 0644]
idlcomp/languages/c++/server.cc
idlcomp/vtable-sample.h
include/c++/orb.h
lib/c++/orb.cc

diff --git a/doc/orb/exceptions b/doc/orb/exceptions
new file mode 100644 (file)
index 0000000..99f5b60
--- /dev/null
@@ -0,0 +1,4 @@
+Exceptions are encoded as a 32-bit objlist length (in IDs), followed
+by the objlist, followed by padding if necessary to be aligned on a
+64-bit boundary, followed by the exception vstruct (encoded as when
+invoking a method).
index e7c666b92e6cd91b6448397de53f12a45ee3facc..0bd489c8d83b22f66351a04cd4c1ab48e421cc34 100644 (file)
@@ -1,5 +1,5 @@
 DIR := languages/c++/
 DIRS += $(DIR)
 
-RAW_CXXFILES := main interface-caller server
+RAW_CXXFILES := main interface-caller server marshall
 BUILDCXXFILES += $(RAW_CXXFILES:%=$(DIR)%)
index 7f8d393aa20b5528527531e038d183dcc3e97e24..4d17670e0c62ebd7f38eb5350d672f6f2c85a94a 100644 (file)
@@ -283,7 +283,7 @@ void CPPFile::output_downcast(Interface *iface, Interface *super)
             << indent << "\treinterpret_cast< ::System::_i_Object *>(oldptr._ptr);\n"
             << indent << "return " << name << "(reinterpret_cast< "
             << iname << " *>\n"
-            << indent << "\t(::System::RunTime::downcast(_llptr, " 
+            << indent << "\t(::System::RunTime::downcast(_llptr, "
             << name << "_ns::_guid.l)));\n";
        
        indent.indent_level--;
diff --git a/idlcomp/languages/c++/marshall.cc b/idlcomp/languages/c++/marshall.cc
new file mode 100644 (file)
index 0000000..1e0c87a
--- /dev/null
@@ -0,0 +1,16 @@
+// C++ Marshalling
+//
+// This software is copyright (c) 2007 Scott Wood <scott@buserror.net>.
+// 
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors or contributors be held liable for any damages
+// arising from the use of this software.
+// 
+// Permission is hereby granted to everyone, free of charge, to use, copy,
+// modify, prepare derivative works of, publish, distribute, perform,
+// sublicense, and/or sell copies of the Software, provided that the above
+// copyright notice and disclaimer of warranty be included in all copies or
+// substantial portions of this software.
+
+#include "c++.h"
+
index 35a213555376515b250f76ff72ed689e404ba216..f773e6f604d30f98017e5ff8a04ee88b53e15186 100644 (file)
@@ -291,8 +291,8 @@ void cpp_output_iface_table_entry(Interface *super, void *arg)
        ctx.f << ctx.indent;
        cpp_output_name(ctx.f, super);
        
-       ctx.f << "_ns::_guid.l,\n"
-             << ctx.indent 
+       ctx.f << "_ns::_info,\n"
+             << ctx.indent
              << (ctx.cla->concrete_iface->super_to_chain(super) - ctx.chain) *
                 target->pointer_size << '\n';
 
index db3fd34809248020e7e73d871db1bc90a8a48e1b..a62633cfe6cca7452031422f2d64ca00b09077a1 100644 (file)
@@ -1,7 +1,7 @@
 #include <orb.h>
 
 struct IFaceTable {
-       unsigned char *guid;
+       const IFaceInfo *info;
        ptrdiff_t offset;
 };
 
index 23f0b72571ad07e544855e6d7c26748c2ccb456e..30c4157728e083e885d37188f1fa56ed88f5425e 100644 (file)
@@ -4,6 +4,10 @@
 #include <stdint.h>
 #include <stddef.h>
 #include <string.h>
+#include <limits.h>
+
+#include <lowlevel/barriers.h>
+#include <lowlevel/bitops.h>
 
 namespace System {
        struct _i_Object;
@@ -125,6 +129,71 @@ namespace System {
                                return new_arr;
                        }
                };
+               
+               template<typename T>
+               struct GrowableArray : public MutableArray<T> {
+                       using MutableArray<T>::ptr;
+                       using MutableArray<T>::count;
+                       size_t bufsize;
+                       
+                       GrowableArray()
+                       {
+                               bufsize = 0;
+                       }
+                       
+                       GrowableArray(NullArray na) : MutableArray<T>(na)
+                       {
+                               bufsize = 0;
+                       }
+                       
+                       GrowableArray(T *PTR, size_t COUNT) : MutableArray<T>(PTR, COUNT)
+                       {
+                               bufsize = COUNT;
+                       }
+                       
+                       GrowableArray(T *PTR, size_t COUNT, size_t BUFSIZE) :
+                       MutableArray<T>(PTR, COUNT)
+                       {
+                               bufsize = BUFSIZE;
+                       }
+                       
+                       GrowableArray(MutableArray<T> &ma) : MutableArray<T>(ma)
+                       {
+                               bufsize = count;
+                       }
+                       
+                       void grow(size_t newsize)
+                       {
+                               if (newsize <= bufsize)
+                                       return;
+                               
+                               T *oldptr = ptr;
+                               T *newptr = new(orbmm) T[newsize];
+                               memcpy(newptr, ptr, count * sizeof(T));
+                               ptr = newptr;
+                               ll_smp_membar_store_after_store();
+                               bufsize = newsize;
+                               // FIXME: Should release imply membar?
+                               ll_smp_membar_any_after_store();
+                               orbmm->release(oldptr);
+                       }
+                       
+                       // Caller must sync against all writers.
+                       void append(T *newptr, size_t len, size_t max = ULONG_MAX)
+                       {
+                               if (count + len < count)
+                                       throw ArrayException();
+                               
+                               if (count + len > max)
+                                       throw ArrayException();
+                               
+                               if (count + len > bufsize)
+                                       grow(ll_get_order_round_up(count + len));
+                               
+                               memcpy(ptr + count, newptr, len * sizeof(T));
+                               count += len;
+                       }
+               };
 
                template<typename T> struct Array {
                        const T *ptr;
@@ -239,8 +308,10 @@ namespace System {
                        return ret;
                }
                
+               struct IFaceInfo;
+
                struct IFaceTable {
-                       const unsigned long *const guid;
+                       const IFaceInfo *info;
                        const ptrdiff_t offset;
                };
                
@@ -322,7 +393,19 @@ namespace System {
                        Segment0 seg0;
                        InvokeMethod invoke;
                };
-       
+
+               struct IFaceInfo {
+                       static const uint8_t *guid;
+                       int (*marshall)(GrowableArray<uint8_t> &buf,
+                                       GrowableArray<ID> &objlist,
+                                       ParamInfoBlock::Segment *segs,
+                                       int nsegs);
+                       void (*unmarshall)(Array<uint8_t> buf,
+                                          Array<ID> objlist,
+                                          ParamInfoBlock::Segment *segs,
+                                          int nsegs);
+               };
+               
                namespace Priv {
                        // Return the caller's PC.  It'd be nice if GCC had a builtin for
                        // the current PC, so that a simple relocation could be used rather
@@ -355,6 +438,7 @@ inline void *operator new[](size_t len, ::System::RunTime::ORBMM *orbmm,
        return orbmm->alloc(len, refs);
 }
 
+// FIXME: This isn't safe on anything with a descructor.
 inline void operator delete(void *ptr, ::System::RunTime::ORBMM *orbmm,
                             int refs = 1)
 {
index 852919b6b8d8b50ba3be521473fc9423a090f8b4..31f5cf3cfba2a82d824c8ae55f32c8bf5e8ab7fc 100644 (file)
@@ -30,15 +30,15 @@ namespace RunTime {
                // behaves.
                
                while (true) {
-                       if (tbl->guid[0] == new_guid_first &&
-                           tbl->guid[1] == new_guid[1] &&
+                       if (tbl->info->guid[0] == new_guid_first &&
+                           tbl->info->guid[1] == new_guid[1] &&
                            (sizeof(long) == 8 ||
-                            (tbl->guid[2] == new_guid[2] &&
-                             tbl->guid[3] == new_guid[3])))
+                            (tbl->info->guid[2] == new_guid[2] &&
+                             tbl->info->guid[3] == new_guid[3])))
                                break;                          
 
                        tbl++;
-                       if (__builtin_expect(!tbl->guid, 0))
+                       if (__builtin_expect(!tbl->info->guid, 0))
                                return 0;
                }