Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add templated helper class to promote type-safety #965

Merged
merged 6 commits into from Apr 12, 2019

Conversation

@Headline
Copy link
Member

Headline commented Mar 9, 2019

Along with some type safety checks to ensure everything is kosher, this also technically fixes us relying on UB punning.


bool ret;
g_pAcceptInput->Execute(vstk, &ret);
MemWriter<void*, const char*, CBaseEntity*, CBaseEntity*, decltype(g_Variant_t), int> vstk(pDest, inputname, pActivator, pCaller, g_Variant_t, params[5]);

This comment has been minimized.

Copy link
@Headline

Headline Mar 9, 2019

Author Member

in-case anyone's curious, this decltype(g_Variant_t) should be okay since it's a global char[] (not char*)

	char test[32];
	std::cout << sizeof(test) << std::endl; //32
	std::cout << sizeof(decltype(test)) << std::endl; //32
Copy link
Member

KyleSanderson left a comment

This is nice; but there's a multitude of style defects and I'd like to know why we're calling malloc when we can hopefully use stack storage instead.

public/sm_memwriter.h Outdated Show resolved Hide resolved
extensions/cstrike/util_cstrike.cpp Outdated Show resolved Hide resolved
extensions/cstrike/natives.cpp Show resolved Hide resolved
extensions/cstrike/natives.cpp Show resolved Hide resolved
extensions/cstrike/util_cstrike.cpp Show resolved Hide resolved
public/sm_memwriter.h Outdated Show resolved Hide resolved
public/sm_memwriter.h Outdated Show resolved Hide resolved
public/sm_memwriter.h Outdated Show resolved Hide resolved
public/sm_memwriter.h Outdated Show resolved Hide resolved
@Headline Headline force-pushed the clean-punning branch from fdce7dd to 90544a0 Mar 16, 2019
@Headline Headline requested review from KyleSanderson and dvander Mar 16, 2019
@Headline

This comment has been minimized.

Copy link
Member Author

Headline commented Mar 16, 2019

Things should be a-okay now. Buffer is now statically allocated, renamed it per the suggestion to ArgBuffer, and whitespace stuff should be better. 🎉

@Headline Headline force-pushed the clean-punning branch from a90e7ab to 3338315 Mar 17, 2019
@Headline Headline force-pushed the clean-punning branch from bf2bac2 to a10f53a Mar 17, 2019
Copy link
Member

KyleSanderson left a comment

The style is still wildly inconsistent 😢

Headline added 2 commits Mar 19, 2019
@Headline Headline force-pushed the clean-punning branch from f9fb2ed to 5dd428c Mar 19, 2019
@asherkin

This comment has been minimized.

Copy link
Member

asherkin commented Mar 19, 2019

This is a really nice quality-of-life improvement. Obviously it looks sane and should behave sanely, but has this been tested in-game with any of these calls?

@asherkin asherkin requested a review from KyleSanderson Mar 19, 2019
@Headline

This comment has been minimized.

Copy link
Member Author

Headline commented Mar 19, 2019

@asherkin no, but I’ve ensured through type-punning by hand that the buffer format is okay. I can do game testing as well to ensure

Copy link
Member

KyleSanderson left a comment

Please test in-game to ensure this doesn't break anything. Beyond that fundamentally it's an improvement; thanks for this.

@Headline Headline added Works For Me and removed Needs Testing labels Mar 21, 2019
@Headline

This comment has been minimized.

Copy link
Member Author

Headline commented Mar 21, 2019

Everything seems to function just as before. Ran through CS_GetTranslatedWeaponAlias and made sure

Copy link
Member

asherkin left a comment

@Headline is this waiting on anything else?

@Headline

This comment has been minimized.

Copy link
Member Author

Headline commented Apr 12, 2019

@asherkin nope!

@Headline Headline merged commit e2eac38 into master Apr 12, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Headline Headline deleted the clean-punning branch Apr 12, 2019
@Headline Headline mentioned this pull request May 1, 2019
@asherkin asherkin mentioned this pull request May 14, 2019
5 of 5 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.