Lurker News

Comments (218) 56 threads

Earlier comments
badsectoracula2 replies#
I get the first one but what is the issue with the second one? It looks like a fairly standard dynamic array with separate size and capacity.
jacquesm1 reply#
Missing null pointer check on return, leaks memory because it overwrites the original pointer.
badsectoracula2 replies#
I didn't notice that, but TBH is this a realistic concern? Is there an actual platform nowadays where realloc (and malloc, for that matter) ever fails, at least outside (small) embedded environments? I've being using realloc for decades and the only time i had to worry about it failing was in DOS.

Nowadays it feels like worrying about realloc failing is similar to worrying about fclose failing.

Continue this thread — 2 replies

cyberax#
No null pointer check, and the fact that you have to manually rewrite it every time.
gwbas1c4 replies#
I don't understand the example. Does it even compile?

It's been a long time since I've used C, so maybe it's using some syntax that I'm unaware of?
IE: What defines "home" that is referenced as an argument to the "appRoute" function, and then passed to the "get" function to set up the "/home" route? Is "home" defined in lavandula.h, or is this really pseudocode?

diath#
It's a macro:

    #define appRoute(name) HttpResponse name(AppContext ctx)
ashtonjamesd2 replies#
Hi, sorry maybe I should've added a comment for that.

The 'appRoute' is a macro that expands to a function signature.
The macro is: '#define appRoute(name) HttpResponse name(AppContext ctx)' and the parameter I passed as 'home' is expanded into the function name. The reason is because all controller function signatures are the same, so just writing 'appRoute' allows the developer to save time writing endpoints!
It is a tradeoff between readability and development speed. And one of the ideas behind the framework is succint and minimal code.

gwbas1c#
So it creates a function called "home", and that is what you pass to get?

Makes sense, thanks!

nodesocket#
Thanks for explaining. I was also a bit confused at a first where the home variable being passed into get() was coming from.
hofrogs#
"appRoute(home)" is a macro that expands to a function called "home":

    #define appRoute(name) HttpResponse name(AppContext ctx)
rnhmjoj#
If I can guess, I would say `appRoute` is a macro that defines a struct called `home` with that handler being assigned to some field as a function pointer.
BiraIgnacio#
Great work, thanks for this!
defraudbah#
github is giving me 503, the project is too good for mS

Thanks for sharing, this looks amazing

Load more comments