Tooling 01 - #302
Conversation
|
@stsp as this a draft you probably didn't get a notification. |
|
Why the script that removes |
|
|
||
| if (termNoComcom) { | ||
| fdloudprintf("Bad or missing Command Interpreter: %s\n", GET_PTR(Shell)); | ||
| fdloudprintf("Bad or missing Command Interpreter: %S\n", Shell); |
There was a problem hiding this comment.
I don't think adding new formats
like 'S' or whatever, is a good idea.
'%P' is enough for additions.
|
I think I must have misunderstood the goal here. I thought the goal was to remove all of the C++isms from the C file so it could look like the C FreeDOS original.
It doesn't, it adds them where necessary in the conversion to C++, just like you did in
Then there's nothing to do, no need for a script, just turn on all the debug ifdefs see what doesn't compile and add
It was used in the FreeDOS kernel for far strings, If I don't have a distinct format specifier and use '%P' for both, how does the converter know whether the intent was to print the pointer address Anyway it looks like I got the wrong idea, an interesting investigation, but ultimately unnecessary. |
True, but not that way.
This is light-years better than just |
|
I had a poke about with clang-tidy, but couldn't see if you can convert files to a new format, it suggested instead that you need to run it as part of the compilation with all the same flags etc. But assuming that can be figured out how would C++ new printing method deal with a FAR char *, how would it know whether you wanted to print the address or the string it pointed to? |
If so - you need to ask AI for
Of course by looking into the format |
|
I just asked Google to transform a pointer 'printf("format %p\n", p) into c++ formatting printing, #include <print>
std::print("format {}\n", static_cast<const void*>(p));or #include <fmt/core.h>
// Automatically handles the void* conversion for any pointer type
fmt::print("format {}\n", fmt::ptr(p));or #include <fmt/printf.h>
// Works without a cast, using your exact original C format string!
fmt::printf("format %p\n", p);do any of those look any good? |
|
Nope. |
|
so I added some test code to try out std formatting. I added a custom formatter to FarPtr // Specialised std::formatter for FarPtr
template<typename T>
struct std::formatter<FarPtr<T>> {
bool print_address = false;
constexpr auto parse(std::format_parse_context& ctx) {
auto it = ctx.begin();
if (it != ctx.end() && *it == 'p') {
print_address = true;
++it;
}
return it;
}
auto format(const FarPtr<T>& obj, std::format_context& ctx) const {
if (print_address)
return std::format_to(ctx.out(), "{:p}", &obj);
else
return std::format_to(ctx.out(), "{:04x}:{:04x}", obj.seg, obj.off);
}
};However when I try to test it with void FAR *ptr = MK_FP(0x0000, 0x0040);
FDLOGSTDPRINT("Default: {0}, Address: {0:p}\n", ptr, ptr);
FDLOGSTDPRINT("Type: {}\n", typeid(ptr).name());The type id is "Pv" a plain void pointer, so my formatter doesn't fire and I just print the address twice. What I am I missing? Is FarPtr the correct thing to have the custom formatter on? |
|
Could you please provide a patch |
|
Okay, it's very rough, will need to tidy a little first. |
|
top two commits here https://github.com/andrewbird/fdpp/tree/printf-03 |
|
Ok, you assumed you can use |
|
I tried this, but I'm getting in a pickle with headers/templates etc. Will have to try later... ajb@calypso:/clients/common/fdpp.git$ git diff
diff --git a/fdpp/thunks.cc b/fdpp/thunks.cc
index fda2aeb4..b91ff7d2 100644
--- a/fdpp/thunks.cc
+++ b/fdpp/thunks.cc
@@ -515,10 +515,6 @@ void RelocHook(UWORD old_seg, UWORD new_seg, UWORD offs, UDWORD len)
uint8_t *start_p = (uint8_t *)so2lin(old_seg, offs);
uint8_t *end_p = (uint8_t *)so2lin(old_seg + (len >> 4), (len & 0xf) + offs);
uint16_t delta = new_seg - old_seg;
- void FAR *tptr = MK_FP(0x0000, 0x0040);
-
- FDLOGSTDPRINT("Default: {0}, Address: {0:p}\n", tptr, tptr);
- FDLOGSTDPRINT("Type: {}\n", typeid(tptr).name());
// fdlogprintf("relocate %hx --> %hx:%hx, %x\n", old_seg, new_seg, offs, len);
FDLOGSTDPRINT("relocate {:04x} --> {:04x}:{:04x}, {:x}\n", old_seg, new_seg, offs, len);
diff --git a/kernel/main.c b/kernel/main.c
index cb5b4d0c..d02c68ba 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -33,6 +33,7 @@
#include "dyndata.h"
#include "dosobj.h"
#include "debug.h"
+#include "../fdpp/stdprint.hpp"
#ifdef VERSION_STRINGS
static const char *mainRcsId =
@@ -78,6 +79,8 @@ ASMREF(struct lol) LoL = __ASMADDR(DATASTART);
struct _bprm bprm;
#define TEXT_SIZE (_InitTextEnd - _HMATextStart)
seg DOS_PSP;
+#define FDPP_PRINT_LOG 0
+#define FDLOGSTDPRINT(format, ...) fdstdprint(FDPP_PRINT_LOG, format, ##__VA_ARGS__)
VOID ASMCFUNC FreeDOSmain(void)
{
@@ -86,6 +89,11 @@ VOID ASMCFUNC FreeDOSmain(void)
UWORD FAR *BootParamVer;
struct _bprm FAR *b;
+ void FAR *tptr = MK_FP(0x0000, 0x0040);
+
+ FDLOGSTDPRINT("Default: {0}, Address: {0:p}\n", tptr, tptr);
+ FDLOGSTDPRINT("Type: {}\n", typeid(tptr).name());
+
#ifdef _MSC_VER
extern FAR prn_dev;
DosDataSeg = (__segment) & DATASTART; |
|
If you scroll upwards a lot, you'll |
yes, that was there. It turned out I had a couple of problems with my formatter I updated my test branch here https://github.com/andrewbird/fdpp/tree/printf-03 And the log it produces So I probably need to move some things around, is including "../fdpp/stdprint.hpp" the right thing to do in each c file? |
No, why do you meed this? |
|
Formatters are already in Initially I had it in |
|
Its certainly not right! |
|
I'm still working on this quietly :) I have a question, what's the reasoning between some files in fdpp directory being .cc and other .cpp? |
|
This means they are written |
|
So the FarPtr object wouldn't be usable in .cpp, but would in fdpp/*.cc? |
|
Or rather |
|
No, exactly the opposite. |
Agreed But what about |
|
No, and why would that be needed?
FAR * is exclusively for freedos code,
which is why I changed the extension
to .cc where its not needed. In thunks.cc
you can use resolve_segoff() and
other helpers that treat fptr as seg/off
struct, rather than something magic.
Воскресенье, 19 июля 2026 г получено от Andrew Bird:
… andrewbird left a comment (dosemu2/fdpp#302)
> .c in kernel/
Agreed
But what about `fdpp/thunks.cc` can we use `FAR *` there?
--
Reply to this email directly or view it on GitHub:
#302 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***
|
Not saying it would, and I'm not trying to be difficult, I just want to understand why |
|
Because its in C and not C++
Воскресенье, 19 июля 2026 г получено от Andrew Bird:
… andrewbird left a comment (dosemu2/fdpp#302)
> No, and why would that be needed?
Not saying it would, and I'm not trying to be difficult, I just want to understand why `fdpp/thunks.cc` was not `fdpp/thunks.cpp`
--
Reply to this email directly or view it on GitHub:
#302 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***
|
|
Cool, got it. So this change (where fdlogstdprint() takes a format string and an Args...) in thunks.cc is desirable or not? - fdlogprintf("purge %p %x\n", ptr, len);
+ fdlogstdprint("purge {:p} {:x}\n", ptr, len); |
|
Not sure its needed, you only |
True, that's how it started, then you introduced me to the idea of variadic type safety :)
I haven't noticed any either. |
So implement it for kernel? |
|
yes, will do. |
So here's a first stab at converting the C source to use std printfs (or the recently reimplemented %P) without any GET_PTR / GET FP32 wrappers, to C++ with the wrappers applied during the build process. The bulk of the python work was AI generated, but I've since worked on it a bit both to make it work in the FDPP environment, and to get to know the code better.
I added a single line change to the makefile easily, but meson had to use an intermediate file (pipes didn't work if you wanted access to variables). Anyway it's functional but the stderr info lines are discarded unless the tool actually exits with error. Obviously I don't know meson at all, I'll continue avoiding it as much as possible, it may be easy to fix I don't know.
The second commit rolls back the changes that would have been necessary to get FreeDOS to work in the new object FAR ptr world of FDPP. This might not be wholly desirable, I don't know, it certainly makes the C code look less cluttered and it was good to test the script.
Unfortunately the build scripts for CI use meson, so you won't see the info in the build log