The perils of ooc arguments

👋 This page was last updated ~14 years ago. Just so you know.

The ooc language is known to be friendly to C libraries, and we have a slew of them covered on GitHub, but one common hurdle is how to correctly declare extern functions.

Argument types

For an ooc function prototype, there are many types of arguments. You can go with regular variable declarations, like so:

something: func (a: Int, b: Int, c: String)

But in this case, a and b have the same type, so you can also use multi-declarations to shorten it a bit:

something: func (a, b: Int, c: String)

In a type declaration (class, cover), you can also use dot-args and assign-args, like so:

Dog: class { age: Int name: String // assign-args init: func (=age, =name) }

and so:

UI: class { level: Level // assign-args and dot args mixed init: func (=level, .input) { this input = input clone() } }

However, for extern functions, we also have the lazy option to only specify the types and not the parameter name, since we have no body and won’t be using it anyway:

cos: extern func (Double) -> Double

It gets ugly

All fancy so far, what’s the problem then? The problem arises for certain extern functions, let’s say you have a function that takes an SdlWindow and an Int:

doStuff: extern func (SdlWindow, a: Int)

This probably doesn’t do what you think. Why? Because it parses as if it took two arguments, SdlWindow and a, both of type Int.

How can we get out of this pickle? We have two options: either go full lazy, or full pedantic, but for the love of Cthulhu, don’t mix styles!

Full lazy:

doStuff: extern func (SdlWindow, Int)

Full pedantic:

doStuff: extern func (window: SdlWindow, a: Int)

It gets uglier

In ooc-sdl2, I just committed a change that has everything to do with what I wrote above. But the workaround geckojsc employed seemed to work. Why?

The workaround was to use Void* instead of SdlWindow as a type, and have prototypes that looked like:

doStuff: extern func (Void*, a: Int)

Here, it works because Void* can’t be a variable name, so it’s parsed as a type and thus there is no ambiguity as to the signature of the function. However, it’s not correct, because it doesn’t use the type we covered from C.

Conclusion

In future versions, we might deprecate the lazy style, or at least throw warnings when there’s an ambiguity. In the meantime, don’t mix styles! And if you have time, go full pedantic. I’m sure future automatic doc generation tools will thank you.

(JavaScript is required to see this. Or maybe my stuff broke)

Did you know I also make videos? Check them out on YouTube!

Here's another article just for you:

Thumbnail for crates.io phishing attempt

crates.io phishing attempt

Earlier this week, an npm supply chain attack.

It’s turn for crates.io, the main public repository for Rust crates (packages).

The phishing e-mail looks like this:

A phishing e-mail: Important: Breach notification regarding crates.io  Hi, BurntSushi! We recently discovered that an unauthorized actor had compromised the crates.io infrastructure and accessed a limited amount of user information. The attacker's access was revoked, and we are currently reviewing our security posture. We are currently drafting a blog post to outline the timeline and the steps we took to mitigate this. In the meantime, we strongly suggest you to rotate your login info by signing in here to our internal SSO, which is a temporary fix to ensure that the attacker cannot modify any packages published by you.
Andrew Gallant on BlueSky

And it leads to a GitHub login page that looks like this:

A fake GitHub sign-in page.
Barre on GitHub

Several maintainers received it — the issue is being discussed on GitHub.

The crates.io team has acknowledged the attack and said they’d see if they can do something about it.