Jump to content

C++ proposition


Jief_Machak
 Share

823 posts in this topic

Recommended Posts

No... The cbuild.bat script worked perfectly fine before, I wrote it and used it since like 2012. At some point though, someone else changed it to hard code paths that just needed to be defined in the environment like edk2 requires, but also does a bunch of stupid non-sense and it has been broken since then. I have several times tried to fix it back and then after a while it will be changed back to incorrect. So I gave up. I still have to edit the script because of the hard codes, I don't have my stuff there, and I already have those defined, so why overwrite them? Should not even set them because you get an error about each one not being set, the error it gives otherwise is a lot harder to figure out it is wrong path. I did not include any paths with a space, also definitely know that you need to write ^( and ^) if you want parentheses to work in a command....

 

EDIT: Also, I think that the call keywords were removed, which actually is what causes that problem. Batch scripts should call other batch scripts.

Edited by apianti
Link to comment
Share on other sites

By the way. The "printf" version embedded in XString use %s for ascii (utf8) and %ls for wide string. Currently, we have %a and %s.

The good point of switching to the usual, is that the compiler checks the argument when you give a litteral as format, which is really nice.

Each time we use XStringW.SPrintf(), we have to remember to use %s instead of %a and %ls instead of %s. But again, if we forgot, the compiler will tell us ! :-)

 

Link to comment
Share on other sites

I see you're working on an Image object ! Good.

 

May I advise to avoid non-const reference parameter ? For example "void XImage::Compose(XImage& LowImage, XImage& TopImage, int PosX, int PosY, bool Lowest)" should probably be "void XImage::Compose(const XImage& LowImage, const XImage& TopImage, int PosX, int PosY, bool Lowest)".

In case you need to modify an object you got from a parameter, use a pointer.

So why is that ? Reason is simple, when you'll write code that call this method, for example "img.Compose(low, top, x, y)", you won't expect Compose to be able to change the content of low and top. But if you had to write this "img.Compose(&low, &top, x, y)" you know straight away that low and top are out parameter (or in/out).

 

As a rule of thumb : never ever use non-const reference as parameter. It's confusing when you write code that calls it.

Link to comment
Share on other sites

Yes, I will use const for IN parameters.

 

Next step will be create 

class XRefitEntry;

class XLoaderEntry: XRefitEntry;

 

We also should avoid global variable.

All variables and structures must be defined in main procedure and be transmitted to other functions through arguments.

A proposition for Code Style: use TWo capital letter in the name of class.

 

I know this is huge work... 

For those who want to compile fresh Clover I want to say there is nothing new in functionality up to some time. Use release.

Link to comment
Share on other sites

I agree with globals. They are quickly a mess.

 

Also, what we can do is  :

A "setting/setup/conf" object. This "settings" object might the only global. Then every one will ask that object when a setting is needed. This setting will take care of reading config.plist as well as discovering the OEM path, list all plist present in the kext folder, etc. 

Link to comment
Share on other sites

You have to pass a "const XImage&", not a "const XImage"

For class name, I realise that the X in front come from a time where there was name conflict. I just added an X for eXtended, although it wasn't really an extension but a rewriting.

We can easily decide to remove the X. String, Array, Image would work too. A while ago, Microsoft used C as a class name prefix. Cocoa use NS.

Maybe we should use C (CString, CArray, CImage) which means Class but also CLover :-). Or use just X as it is...

Link to comment
Share on other sites

"error: passing 'const XImage' as 'this' argument discards qualifiers" so it should be that you're trying to call a method that is not declare const.

To declare a const method, just add const after. Ex void XIMage::toto() const { bla bla };

When you are in a const method, compiler will prevent you to modify yourself, which enforce the const mechanism. 

I love the const mechanism because it forces us to use a better design. Could be seems as annoying at first, but so good to be guaranteed that an object you send to a method won't be modified. 

Edited by Jief_Machak
Link to comment
Share on other sites

So XArray<T> will be replacement for std::vector<T>?

 

Thanks for XImage revision. I will continue the work this way.

 

Old Clover sources came from refit long needed to be clean.

Link to comment
Share on other sites

Yes, XArray is my version of vector. I was working with a C++ that had no STL (that was some time ago :-). I just felt the need to replace C std array by something that checks index and free me for handle allocation and reallocation, to catch the 2 biggest problems : accessing unallocated memory and memory leaks !

 

Link to comment
Share on other sites

11 hours ago, Jief_Machak said:

I agree with globals. They are quickly a mess.

 

Also, what we can do is  :

A "setting/setup/conf" object. This "settings" object might the only global. Then every one will ask that object when a setting is needed. This setting will take care of reading config.plist as well as discovering the OEM path, list all plist present in the kext folder, etc. 

In theory there must be

class CApplication;

containing all settings/config etc.

Then main program 

CApplication CloverGUI;

CloverGUI.Run();

Function GetUserSettings() will be a member of the class and so on.

Some more investigation required.

I don't know yet how to call default destructors before calling boot.efi. Something like CloverGUI.Finish(); after OnExitBootServices.

 

Do we have emit(signal)?

Link to comment
Share on other sites

Hang between

DBG ("stringlength = %d\n", device_inject_stringlength);

and

MsgLog ("CurrentMode: Width=%d Height=%d\n", UGAWidth, UGAHeight);

There are many FreePool(ptr) which may hang if ptr is not valid pointer.

It was working before C++. Where is the influence?

Link to comment
Share on other sites

i'm finished latest clover build.

but i'm always getting black screen after enter mac disk.

i'm using buildme with xcode8 option and xcode 11 beta.

is it right? in last official release(https://github.com/CloverHackyColor/CloverBootloader/releases), there is no problem.

 

Edited by Sherlocks
  • Confused 1
  • Sad 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...