Error out/ignore duplicate #includes

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

Error out/ignore duplicate #includes

Postby Major Cooke » Tue Jan 15, 2019 4:53 pm

One thing I found out is, apparently the engine doesn't check for duplicate #includes when used with ZScript and DECORATE. Thus it tries to register certain classes more than once as a result.

If feasible, I suggest either ignoring duplicates or erroring out if they share a file that's already been read, or outright skipping it. Either or works for me. I round-aboutly discovered this by accidentally forgetting to remove one include, since there is one which points to another included file that points to the file already.
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846

Re: Error out/ignore duplicate #includes

Postby fakemai » Sat Jan 19, 2019 10:52 pm

I'd like to second this since it means you can't just mix Episodic EX and Immerse without commenting the following out in one of them. (RESCINDED: It doesn't seem like those helper scripts can be split off into its own file but that's ugly anyway).
Code: Select allExpand view
// #include "scripts/zk-core/token.zsc"
// #include "scripts/zk-core/tokenizer.zsc"
// #include "scripts/zk-core/stream_base.zsc"
// #include "scripts/zk-core/stream_lump.zsc"
// #include "scripts/zk-core/stream_string.zsc"
User avatar
fakemai
 
Joined: 12 Feb 2018
Location: Australia

Re: Error out/ignore duplicate #includes

Postby _mental_ » Sun Jan 20, 2019 3:11 am

Please define duplicate. Does it mean the same file by its full path, by its file name, by its short name (8 characters without extension), or by its content?

fakemai wrote:you can't just mix Episodic EX and Immerse without commenting the following out in one of them.

The problem with these mods is placing almost identical files under different locations.
In theory, de-duplication by name could solve already defined class errors in this case.
However, file contents are not exactly the same, so loading order may break things anyway.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Error out/ignore duplicate #includes

Postby Rachael » Sun Jan 20, 2019 3:41 am

I think a far better system would be a #pragma once type thing specified inside the #included file. Blankly allowing a file to be included multiple times, I think, will encourage messiness and that may be something the author does not always intend. However, forcing the author to consciously override this behavior will mean they did so intentionally, not by accident.
User avatar
Rachael
Webmaster
 
Joined: 13 Jan 2004
Discord: Rachael#3767
Twitch ID: madamerachelle
Github ID: madame-rachelle

Re: Error out/ignore duplicate #includes

Postby Gez » Sun Jan 20, 2019 4:33 am

An automatic "#pragma once" for all files. It would make sense since I don't think zscript is going to ever feature macro redefinition tricks that would justify including a same source file twice and getting different results the second time (like what ZDoom does with namedef.h to generate both an array of string constants and an enum of string identifiers while making sure both are always kept in sync).
Gez
 
 
 
Joined: 06 Jul 2007

Re: Error out/ignore duplicate #includes

Postby _mental_ » Sun Jan 20, 2019 4:41 am

Gez wrote:An automatic "#pragma once" for all files.

I was thinking about the same. Files would be distinguished by their full paths, or technically, by their lump indices.
Although, it won't fix the problem with two mods having the same file with different full paths.
_mental_
 
 
 
Joined: 07 Aug 2011

Re: Error out/ignore duplicate #includes

Postby Graf Zahl » Sun Jan 20, 2019 4:47 am

There's one problem here: Constants are implicitly namespaced to avoid name clashes of mods with engine extensions and code generation depends on the script version. So the second one can actually depend on different values.
This is also what currently stalls opening up 'extends' to user mods. Just reading all as one compile unit would be easy, but it's a bit trickier than that. Different compile units can have different versions and different constants and lumping everything together will create conflicts.

So sorry, there is no way to do this safely. If mods conflict they cannot be used together. Also what _mental_ said, another issue is that if both mods use the same file names but different content the lump manager's file matching rules will only see the second instance which creates a completely different set of problems.

I think that erroring out if the same file gets included twice is the only viable option.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany

Re: Error out/ignore duplicate #includes

Postby fakemai » Sun Jan 20, 2019 5:16 am

Well even if this is a no I'll just post my attempt to make all 3 fit together in case it's helpful. Conflicting files from the main 2 mods were commented out, and I moved the ones from Immerse (plus a couple extra dependencies) into a separate mod. It at least loads, and briefly testing it doesn't seem to crash. Load order compat, episodicex (1.1.0), immerse (1.0.4)

Drat, too big. https://mega.nz/#!MNs2RaJR!B_EYfN8Ec396 ... QOHzvExxXc
User avatar
fakemai
 
Joined: 12 Feb 2018
Location: Australia

Re: Error out/ignore duplicate #includes

Postby Gez » Sun Jan 20, 2019 5:54 am

Graf Zahl wrote:Also what _mental_ said, another issue is that if both mods use the same file names but different content the lump manager's file matching rules will only see the second instance which creates a completely different set of problems.

I won't surprise you if I tell you this has been used deliberately to create patches for mods. Specifically the example I've seen was overriding some of (what else?) Brutal Doom's lumps this way.
Gez
 
 
 
Joined: 06 Jul 2007

Re: Error out/ignore duplicate #includes

Postby Major Cooke » Sun Jan 20, 2019 1:20 pm

To be clear, in the base Decorate.txt I have:

Code: Select allExpand view
#include "Decorate/Include.txt"
#include "Decorate/Weapons/Include.txt"


And inside Decorate/Include.txt:
Code: Select allExpand view
#include "Decorate/Weapons/Include.txt"


That was the accident I had.
So that wound up generating warnings of duplicate actors and renaming them.
I never intended to do that, and because D4D has a gameinfo loading screen it was obscured.

(No, D4D doesn't have any remaining decorate. I'm just making adjustments for another mod's compatibility.)

Mainly, I'm only asking this for files within the current archive of scanning. I.e. if it's inside D4D.pk3 and it finds an include to a file twice in the SAME package, it should error out. That's what I was going for.
User avatar
Major Cooke
The road to Hell is paved in the carrion she leaves behind.
 
Joined: 28 Jan 2007
Discord: Major Cooke#0846


Return to Feature Suggestions

Who is online

Users browsing this forum: MetroidJunkie and 2 guests