From 42fce70a896a046b201c04a8a4921303acb876aa Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Fri, 28 Oct 2011 18:47:26 -0700 Subject: [PATCH 1/2] Check for the compiled bindings in both places. When node switched it's build system to GYP then the resulting bin will be put in "Release" instead of "build". So check for both places with a little `bindings.js` shim. --- lib/bindings.js | 10 ++++++++++ lib/canvas.js | 2 +- lib/context2d.js | 4 ++-- lib/image.js | 4 ++-- lib/pixelarray.js | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 lib/bindings.js diff --git a/lib/bindings.js b/lib/bindings.js new file mode 100644 index 0000000..bd348e3 --- /dev/null +++ b/lib/bindings.js @@ -0,0 +1,10 @@ +/** + * Compat for changes from node 0.4.x to 0.6.x. + */ +try { + module.exports = require('../build/Release/canvas'); +} catch (e) { try { + module.exports = require('../build/default/canvas'); +} catch (e) { + throw e; +}} diff --git a/lib/canvas.js b/lib/canvas.js index 8f2f07c..d1971ec 100644 --- a/lib/canvas.js +++ b/lib/canvas.js @@ -9,7 +9,7 @@ * Module dependencies. */ -var canvas = require('../build/default/canvas') +var canvas = require('./bindings') , Canvas = canvas.Canvas , Image = canvas.Image , cairoVersion = canvas.cairoVersion diff --git a/lib/context2d.js b/lib/context2d.js index 84c96bb..0202645 100644 --- a/lib/context2d.js +++ b/lib/context2d.js @@ -9,7 +9,7 @@ * Module dependencies. */ -var canvas = require('../build/default/canvas') +var canvas = require('./bindings') , Context2d = canvas.CanvasRenderingContext2d , CanvasGradient = canvas.CanvasGradient , ImageData = canvas.ImageData @@ -320,4 +320,4 @@ Context2d.prototype.createImageData = function(width, height){ width = width.width; } return new ImageData(new PixelArray(width, height)); -}; \ No newline at end of file +}; diff --git a/lib/image.js b/lib/image.js index fa0040a..558472b 100644 --- a/lib/image.js +++ b/lib/image.js @@ -9,7 +9,7 @@ * Module dependencies. */ -var Canvas = require('../build/default/canvas') +var Canvas = require('./bindings') , Image = Canvas.Image; /** @@ -57,4 +57,4 @@ Image.prototype.inspect = function(){ + (this.src ? ' ' + this.src : '') + (this.complete ? ' complete' : '') + ']'; -}; \ No newline at end of file +}; diff --git a/lib/pixelarray.js b/lib/pixelarray.js index 7f191f4..ff10cee 100644 --- a/lib/pixelarray.js +++ b/lib/pixelarray.js @@ -9,7 +9,7 @@ * Module dependencies. */ -var Canvas = require('../build/default/canvas') +var Canvas = require('./bindings') , PixelArray = Canvas.CanvasPixelArray; /** From de520fcece0ada84b6417c229bf5165099d0988c Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Fri, 28 Oct 2011 18:48:48 -0700 Subject: [PATCH 2/2] Try to detect when EIO_custom changed it's signature. Should also be a part of #115 and #120. --- src/Canvas.cc | 6 ++++++ src/Canvas.h | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index d487357..61c158c 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -133,7 +133,11 @@ toBuffer(void *c, const uint8_t *data, unsigned len) { * EIO toBuffer callback. */ +#if NODE_VERSION_AT_LEAST(0, 5, 4) +void +#else int +#endif Canvas::EIO_ToBuffer(eio_req *req) { closure_t *closure = (closure_t *) req->data; @@ -142,7 +146,9 @@ Canvas::EIO_ToBuffer(eio_req *req) { , toBuffer , closure); +#if !NODE_VERSION_AT_LEAST(0, 5, 4) return 0; +#endif } /* diff --git a/src/Canvas.h b/src/Canvas.h index a2c03b1..e1a815a 100644 --- a/src/Canvas.h +++ b/src/Canvas.h @@ -11,6 +11,7 @@ #include #include #include +#include #include using namespace v8; @@ -43,7 +44,13 @@ class Canvas: public node::ObjectWrap { static void SetHeight(Local prop, Local val, const AccessorInfo &info); static Handle StreamPNGSync(const Arguments &args); static Local Error(cairo_status_t status); - static int EIO_ToBuffer(eio_req *req); + static +#if NODE_VERSION_AT_LEAST(0, 5, 4) + void +#else + int +#endif + EIO_ToBuffer(eio_req *req); static int EIO_AfterToBuffer(eio_req *req); inline cairo_surface_t *surface(){ return _surface; } inline uint8_t *data(){ return cairo_image_surface_get_data(_surface); }