Guest User

Untitled

a guest
Jan 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.13 KB | None | 0 0
  1. diff --git a/src/ffi.h b/src/ffi.h
  2. index fe29e71..770bc73 100644
  3. --- a/src/ffi.h
  4. +++ b/src/ffi.h
  5. @@ -40,49 +40,49 @@ class Pointer : public ObjectWrap {
  6. Pointer(unsigned char *ptr);
  7. ~Pointer();
  8.  
  9. - static void Initialize(Handle<Object> Target);
  10. - static Handle<Object> WrapInstance(Pointer *inst);
  11. - static Handle<Object> WrapPointer(unsigned char *ptr);
  12. + static void Initialize(v8::Handle<Object> Target);
  13. + static v8::Handle<Object> WrapInstance(Pointer *inst);
  14. + static v8::Handle<Object> WrapPointer(unsigned char *ptr);
  15. unsigned char *GetPointer();
  16. void MovePointer(int bytes);
  17. void Alloc(size_t bytes);
  18. void Free();
  19.  
  20. protected:
  21. - static Handle<Value> New(const Arguments& args);
  22. - static Handle<Value> Seek(const Arguments& args);
  23. - static Handle<Value> PutInt8(const Arguments& args);
  24. - static Handle<Value> GetInt8(const Arguments& args);
  25. - static Handle<Value> PutUInt8(const Arguments& args);
  26. - static Handle<Value> GetUInt8(const Arguments& args);
  27. - static Handle<Value> PutInt16(const Arguments& args);
  28. - static Handle<Value> GetInt16(const Arguments& args);
  29. - static Handle<Value> PutUInt16(const Arguments& args);
  30. - static Handle<Value> GetUInt16(const Arguments& args);
  31. - static Handle<Value> PutInt32(const Arguments& args);
  32. - static Handle<Value> GetInt32(const Arguments& args);
  33. - static Handle<Value> PutUInt32(const Arguments& args);
  34. - static Handle<Value> GetUInt32(const Arguments& args);
  35. - static Handle<Value> PutInt64(const Arguments& args);
  36. - static Handle<Value> GetInt64(const Arguments& args);
  37. - static Handle<Value> PutUInt64(const Arguments& args);
  38. - static Handle<Value> GetUInt64(const Arguments& args);
  39. - static Handle<Value> PutFloat(const Arguments& args);
  40. - static Handle<Value> GetFloat(const Arguments& args);
  41. - static Handle<Value> PutDouble(const Arguments& args);
  42. - static Handle<Value> GetDouble(const Arguments& args);
  43. - static Handle<Value> PutPointerMethod(const Arguments& args);
  44. - static Handle<Value> GetPointerMethod(const Arguments& args);
  45. - static Handle<Value> PutCString(const Arguments& args);
  46. - static Handle<Value> GetCString(const Arguments& args);
  47. - static Handle<Value> IsNull(const Arguments& args);
  48. + static v8::Handle<v8::Value> New(const Arguments& args);
  49. + static v8::Handle<v8::Value> Seek(const Arguments& args);
  50. + static v8::Handle<v8::Value> PutInt8(const Arguments& args);
  51. + static v8::Handle<v8::Value> GetInt8(const Arguments& args);
  52. + static v8::Handle<v8::Value> PutUInt8(const Arguments& args);
  53. + static v8::Handle<v8::Value> GetUInt8(const Arguments& args);
  54. + static v8::Handle<v8::Value> PutInt16(const Arguments& args);
  55. + static v8::Handle<v8::Value> GetInt16(const Arguments& args);
  56. + static v8::Handle<v8::Value> PutUInt16(const Arguments& args);
  57. + static v8::Handle<v8::Value> GetUInt16(const Arguments& args);
  58. + static v8::Handle<v8::Value> PutInt32(const Arguments& args);
  59. + static v8::Handle<v8::Value> GetInt32(const Arguments& args);
  60. + static v8::Handle<v8::Value> PutUInt32(const Arguments& args);
  61. + static v8::Handle<v8::Value> GetUInt32(const Arguments& args);
  62. + static v8::Handle<v8::Value> PutInt64(const Arguments& args);
  63. + static v8::Handle<v8::Value> GetInt64(const Arguments& args);
  64. + static v8::Handle<v8::Value> PutUInt64(const Arguments& args);
  65. + static v8::Handle<v8::Value> GetUInt64(const Arguments& args);
  66. + static v8::Handle<v8::Value> PutFloat(const Arguments& args);
  67. + static v8::Handle<v8::Value> GetFloat(const Arguments& args);
  68. + static v8::Handle<v8::Value> PutDouble(const Arguments& args);
  69. + static v8::Handle<v8::Value> GetDouble(const Arguments& args);
  70. + static v8::Handle<v8::Value> PutPointerMethod(const Arguments& args);
  71. + static v8::Handle<v8::Value> GetPointerMethod(const Arguments& args);
  72. + static v8::Handle<v8::Value> PutCString(const Arguments& args);
  73. + static v8::Handle<v8::Value> GetCString(const Arguments& args);
  74. + static v8::Handle<v8::Value> IsNull(const Arguments& args);
  75.  
  76. - static Handle<Value> GetAddress(Local<String> name, const AccessorInfo& info);
  77. - static Handle<Value> GetAllocated(Local<String> name, const AccessorInfo& info);
  78. + static v8::Handle<v8::Value> GetAddress(Local<String> name, const AccessorInfo& info);
  79. + static v8::Handle<v8::Value> GetAllocated(Local<String> name, const AccessorInfo& info);
  80.  
  81. private:
  82. static Persistent<FunctionTemplate> pointer_template;
  83. - static Handle<FunctionTemplate> MakeTemplate();
  84. + static v8::Handle<FunctionTemplate> MakeTemplate();
  85. unsigned char *m_ptr;
  86. unsigned int m_allocated;
  87. };
  88. @@ -98,23 +98,23 @@ public:
  89.  
  90. class FFI : public ObjectWrap {
  91. public:
  92. - static void InitializeStaticFunctions(Handle<Object> Target);
  93. - static void InitializeBindings(Handle<Object> Target);
  94. + static void InitializeStaticFunctions(v8::Handle<Object> Target);
  95. + static void InitializeBindings(v8::Handle<Object> Target);
  96.  
  97. protected:
  98. - static Handle<Value> FFIPrepCif(const Arguments& args);
  99. - static Handle<Value> Strtoul(const Arguments& args);
  100. + static v8::Handle<v8::Value> FFIPrepCif(const Arguments& args);
  101. + static v8::Handle<v8::Value> Strtoul(const Arguments& args);
  102. };
  103.  
  104. class ForeignCaller : public ObjectWrap {
  105. public:
  106. ForeignCaller();
  107. ~ForeignCaller();
  108. - static void Initialize(Handle<Object> Target);
  109. + static void Initialize(v8::Handle<Object> Target);
  110.  
  111. protected:
  112. - static Handle<Value> New(const Arguments& args);
  113. - static Handle<Value> Exec(const Arguments& args);
  114. + static v8::Handle<v8::Value> New(const Arguments& args);
  115. + static v8::Handle<v8::Value> Exec(const Arguments& args);
  116. static int AsyncFFICall(eio_req *req);
  117. static int FinishAsyncFFICall(eio_req *req);
  118.  
  119. @@ -127,28 +127,28 @@ class ForeignCaller : public ObjectWrap {
  120.  
  121. private:
  122. static Persistent<FunctionTemplate> foreign_caller_template;
  123. - static Handle<FunctionTemplate> MakeTemplate();
  124. + static v8::Handle<FunctionTemplate> MakeTemplate();
  125. };
  126.  
  127. class ThreadedCallbackInvokation;
  128.  
  129. class CallbackInfo : public ObjectWrap {
  130. public:
  131. - CallbackInfo(Handle<Function> func, void *closure);
  132. + CallbackInfo(v8::Handle<Function> func, void *closure);
  133. ~CallbackInfo();
  134. - static void Initialize(Handle<Object> Target);
  135. - Handle<Value> GetPointerObject();
  136. + static void Initialize(v8::Handle<Object> Target);
  137. + v8::Handle<v8::Value> GetPointerObject();
  138. static void WatcherCallback(EV_P_ ev_async *w, int revents);
  139.  
  140. protected:
  141. static void DispatchToV8(CallbackInfo *self, void *retval, void **parameters);
  142. - static Handle<Value> New(const Arguments& args);
  143. - static Handle<Value> GetPointer(Local<String> name, const AccessorInfo& info);
  144. + static v8::Handle<v8::Value> New(const Arguments& args);
  145. + static v8::Handle<v8::Value> GetPointer(Local<String> name, const AccessorInfo& info);
  146. static void Invoke(ffi_cif *cif, void *retval, void **parameters, void *user_data);
  147.  
  148. private:
  149. static Persistent<FunctionTemplate> callback_template;
  150. - static Handle<FunctionTemplate> MakeTemplate();
  151. + static v8::Handle<FunctionTemplate> MakeTemplate();
  152.  
  153. static pthread_t g_mainthread;
  154. static pthread_mutex_t g_queue_mutex;
  155. @@ -157,7 +157,7 @@ class CallbackInfo : public ObjectWrap {
  156.  
  157. void *m_closure;
  158. Persistent<Function> m_function;
  159. - Handle<Object> m_this;
  160. + v8::Handle<Object> m_this;
  161. };
  162.  
  163. class ThreadedCallbackInvokation {
  164. diff --git a/src/foreign_caller.cc b/src/foreign_caller.cc
  165. index d54fd57..1c41116 100644
  166. --- a/src/foreign_caller.cc
  167. +++ b/src/foreign_caller.cc
  168. @@ -1,3 +1,4 @@
  169. +#import <Foundation/Foundation.h>
  170. #include "ffi.h"
  171.  
  172. ForeignCaller::ForeignCaller() {
  173. @@ -8,10 +9,10 @@ ForeignCaller::~ForeignCaller() {
  174.  
  175. Persistent<FunctionTemplate> ForeignCaller::foreign_caller_template;
  176.  
  177. -Handle<FunctionTemplate> ForeignCaller::MakeTemplate()
  178. +v8::Handle<FunctionTemplate> ForeignCaller::MakeTemplate()
  179. {
  180. - HandleScope scope;
  181. - Handle<FunctionTemplate> t = FunctionTemplate::New(New);
  182. + v8::HandleScope scope;
  183. + v8::Handle<FunctionTemplate> t = FunctionTemplate::New(New);
  184.  
  185. Local<ObjectTemplate> inst = t->InstanceTemplate();
  186. inst->SetInternalFieldCount(1);
  187. @@ -19,24 +20,24 @@ Handle<FunctionTemplate> ForeignCaller::MakeTemplate()
  188. return scope.Close(t);
  189. }
  190.  
  191. -void ForeignCaller::Initialize(Handle<Object> target)
  192. +void ForeignCaller::Initialize(v8::Handle<Object> target)
  193. {
  194. - HandleScope scope;
  195. + v8::HandleScope scope;
  196.  
  197. if (foreign_caller_template.IsEmpty()) {
  198. foreign_caller_template = Persistent<FunctionTemplate>::New(MakeTemplate());
  199. }
  200.  
  201. - Handle<FunctionTemplate> t = foreign_caller_template;
  202. + v8::Handle<FunctionTemplate> t = foreign_caller_template;
  203.  
  204. NODE_SET_PROTOTYPE_METHOD(t, "exec", Exec);
  205.  
  206. target->Set(String::NewSymbol("ForeignCaller"), t->GetFunction());
  207. }
  208.  
  209. -Handle<Value> ForeignCaller::New(const Arguments& args)
  210. +v8::Handle<Value> ForeignCaller::New(const Arguments& args)
  211. {
  212. - HandleScope scope;
  213. + v8::HandleScope scope;
  214. ForeignCaller *self = new ForeignCaller();
  215.  
  216. if (args.Length() == 5) {
  217. @@ -60,13 +61,13 @@ Handle<Value> ForeignCaller::New(const Arguments& args)
  218. return args.This();
  219. }
  220.  
  221. -Handle<Value> ForeignCaller::Exec(const Arguments& args)
  222. +v8::Handle<Value> ForeignCaller::Exec(const Arguments& args)
  223. {
  224. - HandleScope scope;
  225. + v8::HandleScope scope;
  226. ForeignCaller *self = ObjectWrap::Unwrap<ForeignCaller>(args.This());
  227.  
  228. if (self->m_async) {
  229. - HandleScope scope;
  230. + v8::HandleScope scope;
  231. AsyncCallParams *p = new AsyncCallParams();
  232.  
  233. // cuter way of doing this?
  234. @@ -84,17 +85,21 @@ Handle<Value> ForeignCaller::Exec(const Arguments& args)
  235. p->emitter = Persistent<Object>::New(emitterConstructor->NewInstance());
  236.  
  237. ev_ref(EV_DEFAULT_UC);
  238. - eio_custom(ForeignCaller::AsyncFFICall, EIO_PRI_DEFAULT, ForeignCaller::FinishAsyncFFICall, p);
  239. + //eio_custom(&ForeignCaller::AsyncFFICall, EIO_PRI_DEFAULT, &ForeignCaller::FinishAsyncFFICall, p);
  240.  
  241. return scope.Close(p->emitter);
  242. }
  243. else {
  244. +@try {
  245. ffi_call(
  246. self->m_cif,
  247. self->m_fn,
  248. self->m_res,
  249. self->m_fnargs
  250. );
  251. +} @catch (NSException *ex) {
  252. +return v8::ThrowException(Pointer::WrapPointer((unsigned char *)ex));
  253. +}
  254. }
  255.  
  256. return Undefined();
  257. @@ -128,4 +133,4 @@ int ForeignCaller::FinishAsyncFFICall(eio_req *req)
  258. delete p;
  259.  
  260. return 0;
  261. -}
  262. \ No newline at end of file
  263. +}
  264. diff --git a/wscript b/wscript
  265. index 2072c58..0804974 100644
  266. --- a/wscript
  267. +++ b/wscript
  268. @@ -28,6 +28,10 @@ def configure(conf):
  269. # the off_t size difference between the way node is compiled
  270. # and this will cause the eio_req to be different and crash
  271. # the node-ffi stuff
  272. + conf.env.append_value('CCFLAGS', '-ObjC++')
  273. + conf.env.append_value('CXXFLAGS', '-ObjC++')
  274. + conf.env.append_value('CCFLAGS', '-lobjc')
  275. + conf.env.append_value('CXXFLAGS', '-lobjc')
  276. conf.env.append_value('CCFLAGS', '-D_LARGEFILE_SOURCE')
  277. conf.env.append_value('CXXFLAGS', '-D_LARGEFILE_SOURCE')
  278. conf.env.append_value('CCFLAGS', '-D_FILE_OFFSET_BITS=64')
  279. @@ -40,6 +44,7 @@ def configure(conf):
  280. def build(bld):
  281. obj = bld.new_task_gen('cxx', 'shlib', 'node_addon')
  282. obj.target = 'ffi_bindings'
  283. + obj.frameworks = [ 'Foundation' ]
  284. obj.source = './src/ffi.cc ./src/callback_info.cc ./src/pointer.cc ./src/threaded_callback_invokation.cc ./src/foreign_caller.cc'
  285. obj.uselib = 'FFI DL'
Add Comment
Please, Sign In to add comment