leif
2017-7-25 13:29:11

@mflatt Since different architectures implement va_list differently, but still follow a common C interface, would it then be reasonable to add a primitive to internal racket to convert a va_list to a vector? Something like va_list_to_vector() or something like that?


leif
2017-7-25 13:29:22

Then we could add that functionality to the FFI library.


leif
2017-7-25 13:29:45

(Since at the moment it seems like there is no way to handle a va_list in our ffi)


mflatt
2017-7-25 13:33:10

I don’t think va_list_to_vector() would work well, and probably the C interface would need to be followed more closely with something like va_arg(), and it needs to be in the FFI to work right with types. Also, we’d need a new primitive type for va_list itself.


leif
2017-7-25 13:36:14

Sorry, but I couldn’t parse ‘would need to be followed more closely with something like va_arg()‘, could you clarify what you mean by that?


leif
2017-7-25 13:37:49

Ah, I think I know what you are saying.


leif
2017-7-25 13:38:17

Because we wouldn’t know what the types are, it would be hard to grab the resulting types of data out of the vector.


leif
2017-7-25 13:39:43

Adding a (_va-list …) type to our FFI ‘seems’ doable.


mflatt
2017-7-25 13:50:32

It looks like va_list is pointer-sized in practice. So, if you’re trying to call vsnprintf or something like that to format a log message, probably using _pointer will work. Or do you really need access to the individual arguments referenced by the va_list?


leif
2017-7-25 13:51:25

Nah, in this case using vsnprintf should work.


leif
2017-7-25 13:51:48

I have a format string, and I need expand it.


leif
2017-7-25 13:51:55

But that’s about it.


leif
2017-7-25 13:52:02

So I’ll give that a shot, thanks.


leif
2017-7-25 14:17:14

@mflatt Wouldn’t we actually want vasnprintf?


leif
2017-7-25 14:17:30

Since I won’t know how much buffer space I’ll need?


mflatt
2017-7-25 14:18:49

Sounds right


mflatt
2017-7-25 14:19:52

(I don’t know at the variants. I just know to throw in s for “string”, v for va_list, and n at an attempt to be safe.)


leif
2017-7-25 14:25:48

Yup


leif
2017-7-25 14:25:57

I had to read the man page to get it.


leif
2017-7-25 14:26:05

But a is for allocate.


leif
2017-7-25 14:26:16

Which means it will eventually need to be freed.


leif
2017-7-25 14:26:24

But that one is easy enough to do.


leif
2017-7-25 14:27:09

Ideally I would rather use vsnprintf, but there doesn’t seem to be a good api for determining if your buffer was big enough.


leif
2017-7-25 14:27:31

And, as far as I can tell, for stuff like that, most c programmers seem to take a ‘good enough’ approach to this.


leif
2017-7-25 15:23:57

@mflatt If I have a (_ptr o _string) in my FFI call, with the Racket GC collect the output pointer, or will I have to free it by hand?


leif
2017-7-25 15:31:55

Anyway, modulo that possible memory leaked, your suggestion worked. So thanks. :slightly_smiling_face:


mflatt
2017-7-25 15:42:15

(_ptr o _string) allocates GCable memory to receive the _string pointer as well as the string content, so you don’t have to free either. If the called function was returning a char* that needs to be freed, though, then (_ptr o _string) is not a good choice, because you never get to see the returned pointer to free it


leif
2017-7-25 15:49:28

Ah, fair. It has an argument for a char*, which fills the pointer with a char.


leif
2017-7-25 15:50:12

So you’re saying it would be better to just use a _pointer, copy it into a _string`, and then free the _pointer then?


leif
2017-7-25 15:50:20

(As I understand it anyway)


mflatt
2017-7-25 15:51:44

Yes. You can use (_ptr o _pointer), but do the _pointer to _string cast (which will allocate a string) yourself, and then you can free the _pointer value


leif
2017-7-25 15:52:00

Cool, thanks.


leif
2017-7-25 15:52:20

BTW, I have been meaning to ask, do you have any idea how the Racket7 codebase will effect the FFI?


leif
2017-7-25 15:52:33

err…affect*


mflatt
2017-7-25 15:54:23

So far, I think it will mostly work. Finalization will be different, but most finalization patterns will work in both.


leif
2017-7-25 15:55:50

Okay, that’s good. Thanks.


leif
2017-7-25 15:56:09

(I’ve obviously been making heavy use of it. :slightly_smiling_face: )


lexi.lambda
2017-7-25 17:03:08

@mflatt The racket7 progress is exciting, and your detailed transparency is, as always, much appreciated. :slightly_smiling_face:


abmclin
2017-7-25 18:10:42

ditto what Alexis said. The reason Racket-on-Chez-Scheme doesn’t yet work on Windows is simply because Windows specific functions haven’t been implemented yet?


leif
2017-7-25 18:26:31

@mflatt Is there any good way to specify to the Racket FFI that I would like version 6.69.100 and up?)


leif
2017-7-25 18:26:55

Or rather, 6.69.100 and up, up to 7.x, and then its incompatible again.


leif
2017-7-25 18:27:20

It seems like passing in a whole list of strings to ffi-lib would be massively too long.


leif
2017-7-25 18:28:47

I guess I could just do the string processing myself.


leif
2017-7-25 18:43:27

hmm…actually, no that won’t work. Because I have to give it an absolute path in that case. :confused:


mflatt
2017-7-25 19:56:22

@leif I don’t know how to do that generally, whether using the Racket FFI or anything else


leif
2017-7-25 19:57:57

Ya, I ended up just opening it up, and checking the version after the fact.


leif
2017-7-25 19:58:17

I would imagine dlopen has something it does, but that’s more work than I think its worth at the moment.


mflatt
2017-7-25 19:58:42

@abmclin Racket-on-Chez doesn’t yet build on Windows mostly because I haven’t sorted out how a build will work there – not using Unix tools – but also because Windows path parsing is not yet implemented


ben
2017-7-25 22:26:36

has anyone here tried sleeping in Mary Gates Hall at the University of Washington? (@alexknauth do you know anyone to ask?)


zenspider
2017-7-25 22:39:17

heh. I think I did once back in the day. probably wasn’t SUPPOSED to. :slightly_smiling_face:


leif
2017-7-26 02:58:32

@mflatt Hmm…functions like vasprintf don’t seem to be loaded in Racket’s windows build.


leif
2017-7-26 03:00:14

Ah, that specific one is a gnu extension according to SO. oh well. https://stackoverflow.com/questions/40159892/using-asprintf-on-windows