Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Cache parsed types. #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Cache parsed types. #32

wants to merge 1 commit into from

Conversation

Ferada
Copy link
Owner

@Ferada Ferada commented Jul 20, 2019

Instead of recreating them all the time. Might be addressing some of the issues reported in crategus#69. In the long run might be worth more addressing this in CFFI directly.

Instead of recreating them all the time.
@stacksmith
Copy link

Every little bit helps, as far as I am concerned. I get flak when I complain about hundreds of kilobytes wasted - it's not 1990, I know... But all this stuff piles up causing problems at some point. It's like letting your garden get overgrown to the point you have no idea what's behind the thorns. I'll tell you what's there - rats, ticks and occasionally a crazy guy living in a tent who may burn down your house.
Speaking of CFFI, I spent a few hours tracking down the long path from defcfun to something that actually calls a foreign function (in SBCL). I am sad to say I never got to a conclusive end, after disassembling, decompiling and just trying to follow the sources. I know that between cl-cffi-gtk and CFFI there are four (I think) places where objects get cached for various reasons, and I found a few other places that create new objects for no explainable reason. For instance, deep below CFFI,

(SB-ALIEN:EXTERN-ALIEN "gtk_text_buffer_set_text"
(FUNCTION SB-ALIEN:VOID SB-SYS:SYSTEM-AREA-POINTER
   	SB-SYS:SYSTEM-AREA-POINTER SB-ALIEN:INT))
#<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X5020B060 :TYPE (FUNCTION (VALUES)
   SB-SYS:SYSTEM-AREA-POINTER	SB-SYS:SYSTEM-AREA-POINTER	(SB-ALIEN:SIGNED 32) &REST)>

This one is interesting: if you call it a few times you will see that it returns the same SAP, but with a different alien object. There are many places that have so-called type parses hiding deep inside.
i've been working on a cleaner interface to GTK objects, using several layers that are clearly defined, and it seems to be helpful. I had to completely rewrite gtk buffer, iter, mark bindings to work with untyped pointers at the low level, and get lispier and safer with higher levels.
For objects like gtk-text-buffer, which are pretty much static, it makes sense to just get the raw pointer and use it in all the bindings. It does not change, and it needs no translation. I blabbed about iters enough, but it is so lightweight to use them the way God had intended.
I also wrote a ffdb library that is basically a database for a group of related bindings. I have one for buffer, one for iter, etc. It is a repository of all binding information and may be used to instantly generate a set of bindings at any layer - which is great for experimenting, say to make all gtk-text-iters structure pointers etc.
I am also very excited about a layer of bindings that can use a lexical environment. So you can bind a buffer pointer and every binding inside the environment can use it instead of the usual parameter passing. In fact I have a stream-like object binding a buffer, 3 iters and a mark. All the bindings in that environment can use them as parameters, and you have to provide just the missing ones...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants