FreezePhoenix

 The 2nd Monitor

General discussion about codereview.stackexchange.com - Welcom...
Jul 21, 2023 21:51
> Oh, really? God, I hadn't thought of that! Seriously, any constructive critiques welcome, on what is CLEARLY a coding/learning exercise here. @freezePhoenix no need to provide any more input.
Jul 21, 2023 21:51
https://codereview.stackexchange.com/questions/286174/shared-ptr-implementation-code-first-cut?noredirect=1#comment569685_286174
Not sure, but I feel like this comment was a bit heated?
Jun 30, 2023 19:39
At this point, I wasn't asking how, just remarking on the fact that I didn't know C++ let you do template<template<typename... Args> typename T>
Jun 30, 2023 19:35
Thus, type safety.
Jun 30, 2023 19:32
long somethin() {
    return 1;
}

int main() {
    erased_type<std::function> temp = std::function(somethin);

    auto a = temp.get<long()>();
    std::cout << a() << std::endl; // prints out 1

    auto b = temp.get<double()>();  // throws std::bad_any_cast

    std::cout << b() << std::endl;
}
Jun 30, 2023 19:32
But if you use the erased_type...
Jun 30, 2023 19:30
#include <iostream>

long somethin() {
    return 1;
}

using A = long(*)();
using B = double(*)();

int main() {
    A a = &somethin;

    B b = (B) a;

    std::cout << b() << std::endl;
}
Jun 30, 2023 19:30
Even this emits zero warnings:
Jun 30, 2023 19:27
This emits zero warnings
Jun 30, 2023 19:26
#include <iostream>

void somethin() {
    return;
}

int main() {
    int a = 1;
    void(*A)() = somethin;

    int(*B)() = (int(*)()) A;

    std::cout << B() << std::endl;
}
Jun 30, 2023 19:26
Take into consideration the following code:
Jun 30, 2023 19:25
Because here you can't just do that
Jun 30, 2023 19:24
Well yeah but the compiler also just goes "Mmm yess casting a void function pointer to a non-void function pointer, yes, this is a good idea"
Jun 30, 2023 19:23
Wdym knock out
Jun 30, 2023 19:22
@Vogel612 So you can just assign values to it... like std::any lets you do.
Jun 30, 2023 19:19
@Vogel612 To avoid casting function pointers unsafely
Jun 30, 2023 19:18
template<template<typename... Args> typename T>
struct erased_type {
    private:
        std::any internal;
    public:
        erased_type(): internal() {}
        template<typename... Args>
        erased_type(const T<Args...>& obj): internal(obj) {}
        template<typename... Args>
        erased_type(T<Args...>&& obj): internal(obj) {}
        template<typename... Args>
        erased_type& operator=(const T<Args...>& obj) {
            internal = obj;
            return *this;
        }
Jun 30, 2023 19:18
I did not know that C++ let you do cursed things like this:
Jun 30, 2023 15:48
Using a wrapper of std::any
Jun 30, 2023 15:47
I could try and implement some form of type erasure
Jun 30, 2023 15:38
Well, hm....
Jun 30, 2023 15:30
PathfindArguments::MapPathResult ipc_handler(const PathfindArguments& args) {
	if (args.start_map != args.end_map) {
		pather->mLogger->info("Cross-map pathfinding not supported ({} -> {})", args.start_map, args.end_map);
		return { PathfindArguments::MapPathResult::FAIL };
	} else {
		if (pather->map_to_id.contains(args.start_map)) {

			unsigned int map_id = pather->map_to_id[args.start_map];
			return pather->maps[map_id].path(args.start, args.end);
		}
		return { PathfindArguments::MapPathResult::FAIL };
Jun 30, 2023 15:30
Where
Jun 30, 2023 15:29
ServiceInfo<PathfindArguments, PathfindArguments::MapPathResult>::HANDLER init(ServiceInfo<PathfindArguments, PathfindArguments::MapPathResult>* info) {
	info->destructor = cleanup;
	GameData* data = info->G;
	pather = std::unique_ptr<Pather>(new Pather(data));
	return ipc_handler;
}
Jun 30, 2023 15:29
The .so accepts it like this:
Jun 30, 2023 15:28
template<typename ARGUMENTS, typename RETURN = void>
class ServiceInfo {
	public:

		typedef RETURN (*HANDLER)(const ARGUMENTS&);
		HANDLER child_handler = nullptr;
		GameData* G;
		std::function<void()> destructor;
		~ServiceInfo() {
			if (destructor != nullptr) {
				destructor();
			}
		}
};
Jun 30, 2023 15:27
The main program is loading an init symbol from a .so, and passing it a
Jun 30, 2023 15:27
not quite
Jun 30, 2023 15:27
well
Jun 30, 2023 15:25
@pacmaninbw No the shared library pointer that I am trying to pass is being accessed with dlsym
Jun 30, 2023 01:06
@pacmaninbw Wdym?
Jun 30, 2023 00:00
(C++)
Jun 30, 2023 00:00
Does anyone know how I might transport function pointers through shared library boundaries?
Dec 30, 2020 16:37
@Mast WebAssembly is compiled from C or C++ code
Dec 30, 2020 16:08
You can, but, eh
Dec 30, 2020 16:08
Yeah you're not supposed to directly write in WebAssembly.
Dec 30, 2020 15:34
@Edward Your primary bottleneck with a small simulation will be JS drawing to a canvas. The C++ code isn't gonna be an issue.
Dec 30, 2020 15:33
WebAssembly can call JS code and vice versa
Dec 30, 2020 15:33
The WebAssembly's memory is exposed as an ArrayBuffer
Dec 30, 2020 15:31
Ohhh I currently am not using it at all I just learned it a while back to add it to my toolbelt.

Also because JS is slow as heck, and WebAssembly would allow me to write hot code paths in a faster language. Good for more calculation intense things, because C / WebAssembly has some pretty good optimization, which JS just doesn't have.
Dec 30, 2020 15:29
Like, how do you run it?
Dec 30, 2020 15:29
How am I using it?
Dec 30, 2020 15:26
Obviously, I suggest writing in a text format lol
Dec 30, 2020 15:25
WebAssembly has two formats, a text format and a binary format
Dec 30, 2020 15:22
There's a small issue with that decompiler though, it sticks fn_ in front of every function when it decompiles lol
 

 Coding Projects and Duga Heaven :)

Minesweeper Flags, Zomis' games, PDB, MTG, Cardshifter, and al...
Jun 23, 2023 19:18
Kind of weird cus they never contacted me but /shrug
Jun 23, 2023 19:17
Got the merge approved, apparently
Jun 23, 2023 19:15
There we go