[cl-cairo2-devel] null pdf surface

Scott Graham scott.clcairo2 at h4ck3r.net
Mon Jan 5 04:41:23 UTC 2009


Ok, thanks. I'll try to dig into it to it a little so I can ask a
coherent cffi question.

For now I've opened "/dev/null" as the file. It's probably less
efficient, but works at least.

scott

On Sun, Jan 4, 2009 at 8:00 PM, Tamas K Papp <tpapp at princeton.edu> wrote:
> On Sun, Jan 04, 2009 at 07:40:40PM -0800, Scott Graham wrote:
>> Hi
>>
>> I want to create a null pdf surface to be used for calculating metrics
>> without writing a file. See:
>>
>> http://cairographics.org/manual/cairo-pdf-surface.html#cairo-pdf-surface-create
>>
>> But, with something like:
>>
>> (defmacro with-pdf-file ((filename width height) &body body)
>>   "Execute the body with context bound to a newly created pdf
>>   file, and close it after executing body."
>>   `(let* ((*context* (create-pdf-context ,filename ,width ,height)))
>>          (unwind-protect (progn , at body)
>>                          (destroy *context*))))
>>
>> (with-pdf-file ((cffi:null-pointer) 500 500)
>>   (move-to 100 100)
>>   (line-to 200 200)
>>   (stroke))
>>
>> I get (a bunch of) errors spit out:
>>
>> WARNING: function returned with status WRITE-ERROR.
>>
>> So I guess it's not working properly. Is there a different way I could
>> try specifying that "NULL" gets passed into the cairo function
>> perhaps? Or is this perhaps just a bug in cairo itself?
>
> Hi Scott,
>
> I am at a conference and I don't have time to investigate this in
> detail at the moment, but I suspect that the error arises from how
> CFFI handles :string types.  When you use a string type, CFFI
> allocates a memory area, and copies the string to that before calling
> the function with the resulting pointer.  My guess is that this chokes
> on NULL.
>
> What I would do is ask on the CFFI list whether there is a clean way
> to pass a NULL pointer to a CFFI function which expects a string
> argument.  If not (which is my guess), then we have to do the
> allocation and conversion manually, and call a function with type
> char*.  See Section 4.8 of the CFFI manual on this issue.
>
> If you have time on your hands and know how to program C, you can
> experiment with the following: write a C function
>
> void test(char* string) {
>  /* open a file with a fixed name, eg /tmp/test, write string into
>  it, close */
>  ...
> }
>
> define this in CFFI with the argument of type :string, and see what is
> written to the file when you call this with cffi:null-pointer.
>
> Anyhow, please ask the smart people who designed CFFI.  If possible,
> please CC me.
>
> Thanks,
>
> Tamas
>




More information about the Cl-cairo2-devel mailing list