kirisky
2017-7-26 09:02:28

@kirisky has joined the channel


leif
2017-7-26 15:36:03

@mflatt So for what its worth, treeting the va_list like a pointer seems to cause erratic behavior.


leif
2017-7-26 15:36:30

I mean, the bug could be somewhere else, and I’m seeing if I can reduce it down.


leif
2017-7-26 15:36:33

But…a.


leif
2017-7-26 15:36:34

ya*


mflatt
2017-7-26 15:38:00

@leif What platform are you on?


mflatt
2017-7-26 15:40:16

Nevermind – I see that sizeof(va_list) is 24 bytes on Mac OS, so it must vary more than I thought, and I must have mangled my experiment before


mflatt
2017-7-26 15:45:35

Thinking about it more, a portable solution seems hopeless without va_list support in libffi, because the specific representation of a va_list can affect the way that it’s passed in registers or on the stack. The only idea I have is to define _va_list in ffi/unsafe based on the result of (system-library-subpath #f) – so it would work only for platforms where we’ve specifically tracked down and hard-coded the representation.


leif
2017-7-26 16:23:24

@mflatt ya, that sounds about right.


leif
2017-7-26 16:23:31

Also I’m on OS X.


leif
2017-7-26 16:24:30

I’ll look at the system V ABI specs, if they are at least consistent among different instruction sets we probably do have a chance


leif
2017-7-26 16:37:24

Looking at the c99 spec, it requires that va_list be a type.


leif
2017-7-26 16:38:04

And if that is the case, it seems like if we make a _va-list type, while we won’t be able to do anything with it in Racket code, it could be passed to C code.


leif
2017-7-26 16:38:34

(I’m looking at section 7.15 of the latest draft of the c99 spec.)


leif
2017-7-26 16:38:45

(As I don’t have a copy of the actual release.)


soegaard2
2017-7-26 18:42:17

@leif Supporting va_list seems painful. Just found the section “Variable Length Arguments” in the SWIG manual. It has the subtitle “The horror. The horror.”


soegaard2
2017-7-26 18:42:24

leif
2017-7-26 18:49:45

@soegaard2 Not trying support varargs…That would be really hard. :confused:


leif
2017-7-26 18:49:49

Just va_list.


leif
2017-7-26 18:49:58

Which is doable, as its just another value.


leif
2017-7-26 18:50:28

As long as it stays an opaque value to Racket, that is fine.


leif
2017-7-26 18:50:54

Trying to mimick va_arg, va_first, etc. or the ... protocol, that sounds scary.


leif
2017-7-26 18:51:11

At least based on what I’ve ascertained at the moment.


soegaard2
2017-7-26 18:52:16

Iam clearly conflating those. Aren’t va_list used to deal with variable arguments?


leif
2017-7-26 18:54:38

You are correct.


leif
2017-7-26 18:54:50

va_list however, can also be passed to another function as a type.


leif
2017-7-26 18:55:06

This is used if you, say, want to make a helper function.


soegaard2
2017-7-26 18:56:47

Ok. So va_list is also useful in other situations.


leif
2017-7-26 18:57:15
int myfunc(const char *str, ...) {
    va_list ag;
    va_start(ag);
    helper(ag);
    va_end(ag);
}

int helper(va_list ag) {
    ...
    va_arg(ag);
    ...
}

leif
2017-7-26 18:57:21

Yup


leif
2017-7-26 18:57:27

in this case, I want to write helper


leif
2017-7-26 18:57:30

In particular…


leif
2017-7-26 18:57:43

I want to write helper that just passes the va_list to another (C) function.


leif
2017-7-26 18:57:49

Because I’m hooking up two libraries.


leif
2017-7-26 18:57:53

Through Racket….


leif
2017-7-26 18:58:50

Of course, this still isn’t enough to duplicate va_copy, as that’s macro. To do that, we would need to make scheme_va_copy, or something like that.


leif
2017-7-26 18:58:54

Which does nothing but call the macro.


leif
2017-7-26 19:01:25

Of course, if we do that, it would make sense to do that for va_arg as well.


leif
2017-7-26 19:01:56

We couldn’t do va_start and va_end though, because that would require supporting vaargs, and ..., which, as you rightly pointed out, is terrifying.


leif
2017-7-26 19:02:12

At least, what it looks like anyway. Perhaps I’m wrong.


soegaard2
2017-7-26 19:11:10

Thanks for the example.


leif
2017-7-26 19:16:46

Any time. :slightly_smiling_face:


leif
2017-7-26 19:51:51

@mflatt worksp/librktio/… vs librktio/… these two directories seem pretty similar. Is one of them deprecated?


mflatt
2017-7-26 19:53:48

There should be a “rktio” directory with the rktio implementation and a “worksp/librktio” directory with MSVC projects


mflatt
2017-7-26 19:54:05

I’m not seeing multiple “librktio” directories


leif
2017-7-26 19:57:49

err…ya, I mean worksp/rktio. That makes sense that one is for windows. Thanks.


leif
2017-7-26 20:02:58

@mflatt oh wait, no


leif
2017-7-26 20:03:05

I do see a worksp/librktio.


leif
2017-7-26 20:03:22

racket/racket/src/worksp/librktio


mflatt
2017-7-26 20:03:51

Just to be sure: there should only be one “rktio” and one “librktio” directory; the “librktio” directory should be in “worksp”, and the “rktio” directory should not be in “worksp”


leif
2017-7-26 20:03:53

Although that one does look like a visual studio project.


leif
2017-7-26 20:04:21

Ah, okay.


leif
2017-7-26 20:04:30

That is correct.


leif
2017-7-26 20:11:45

So, since windows has src/worksp/libffi, does that mean it doesn’t use src/foreign?


leif
2017-7-26 20:12:23

OH….


leif
2017-7-26 20:12:40

src/worksp/libffi probably is in pace of src/foreign/libffi.


mflatt
2017-7-26 20:19:44

The foreign.c part of src/foreign is included directly in libracket, while src/worksp/libffi is the project for src/foreign/libffi


leif
2017-7-26 20:24:44

Okay


leif
2017-7-26 20:25:10

Also, I realized, adding a primitive for va_list is silly, since per the spec, its just an (undefined) struct type.


leif
2017-7-26 20:26:32

So it would make a lot more sense to just add a function to the core that calls sizeof (which I suspect already exists), and then define _va-list in racket.


mflatt
2017-7-26 20:31:07

@leif Is even sizeof(va_list) useful, since the calling convention can depend on more than the size? For example, long and double are often passed differently – though I’ll grant that va_list is unlikely to be represented as a double. I still think it’s best to use (system-library-subpath #f) and hardwire a representation in ffi/unsafe for various known results.


leif
2017-7-26 20:34:46

Ah, fair.


leif
2017-7-26 20:47:15

@mflatt Actually, no. Since va_list is NOT a primitive in C (per the spec), it’ll be handled just like any other struct will.


leif
2017-7-26 20:47:40

(Like, the size and field order of the struct is undefined, but the fact that it is a struct is.)


leif
2017-7-26 20:48:26

“The type declared is va_list which is an object type suitable for holding information needed by the macros va_start, va_arg, va_end, and va_copy”


mflatt
2017-7-26 20:50:02

“object type” => “struct”?


mflatt
2017-7-26 20:50:53

Even so, I thought the way a struct is passed could depend on its content beyond just its size, but I forget these details


leif
2017-7-26 20:53:34

That is how I interpret it. Although I admit I didn’t make the spec so I’m not 100% sure.


mflatt
2017-7-26 20:54:37

Ok. FWIW, I don’t think “object” means “struct” in the C standard


leif
2017-7-26 20:55:17

Also ya, it certainly is true that structs are passed differently based on what is in them.


leif
2017-7-26 20:55:23

Hmm…okay.


leif
2017-7-26 20:55:39

I’ll see if I can find an answer to that. Thanks. :slightly_smiling_face:


leif
2017-7-26 21:18:40

@mflatt “object: region of data storage in the execution environment, the contents of which can represent values”


leif
2017-7-26 21:18:48

So I guess it could be a primitive.


leif
2017-7-26 21:19:00

Just not a macro.