[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Lisp object that refers to a C struct

From: Stefan Monnier
Subject: Re: Lisp object that refers to a C struct
Date: Tue, 16 Oct 2012 09:11:25 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux)

>> Otherwise, better define your own type so that its printed
>> representation can be more helpful, indicating what it's used for
> How do I define my own type?

Either by adding one more lisp_misc or one more pseudovector.
For either of them, you need to add the corresponding new tag to their
enumeration (Lisp_Misc_Type or pvec_type).  For lisp_misc you
additionally need to add your entry to the union type (but make sure
the first word has the same structure as the others, starting with
a 16bit type and a 1bit markbit) and make sure the overall size of the
union type is not increased.

Then you need to add the corresponding switch branches in print.c and in

> In particular, what to do with gcmarkbit in Lisp_Misc?

The markbit represents whether or not the object you created was found
by the tracing GC, so just set it like we do for the other types.

The other question is "when should we free the C struct to which this
new lisp_misc points"?  And that depends.  You could have the GC free it
when it finds your lisp_misc can be freed, or you could have instead
a notion of "deleted file-watcher" (like we have for
buffers/windows/...) which is when the underlying C struct has been
freed (but of course, this state needs to be represented, e.g. by
setting the pointer to NULL, which means that you need to be able to
enumerate all the file-watcher objects (or the only one, if you enforce
there can only be one) corresponding to a particular C struct).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]