Skip to content

CABMAN: Remove _WIN32 ifdef's#252

Merged
HeisSpiter merged 2 commits intoreactos:masterfrom
dfbag7:CORE-12645
Jan 27, 2018
Merged

CABMAN: Remove _WIN32 ifdef's#252
HeisSpiter merged 2 commits intoreactos:masterfrom
dfbag7:CORE-12645

Conversation

@dfbag7
Copy link
Copy Markdown
Contributor

@dfbag7 dfbag7 commented Jan 1, 2018

CORE-12645

Purpose

JIRA issue: CORE-12645

Proposed changes

Basically I tried to remove as much as possible _WIN32 ifdef's to make the code easier to maintain. To achieve that, I did the following changes:

  • Created two implementations of CCFDATAStorage class and placed them in CCFDATAStorageUnix.cxx and CCFDATAStorageWindows.cxx. Both implementations use the same definition of the class in cabinet.h header file.
  • Created single ifdef'ed section containing definitions of platform-dependent functions in the beginning of cabinet.h
  • Removed ifdef's in cabinet.cxx and dfp.cxx and make use the new platform-dependent functions defined in cabinet.h.

TODO

I tested the resulting code trying to create Hybrid CD in three environments:

  • RosBE for Windows using MSVC 2017 (compiler version 19.12.25830.2),
  • RosBE for Windows native (GCC v.4.7.2)
  • RowBe for Linux (Debian 8, GCC v.4.9.2)

Then I installed ReactOS from the resulting ISO image into VMWare VM. All worked fine.

There are, however, some ways to further polish the code. In particular, the code that chooses if existing target file should be overwritten when opening file for writing is still contains two ifdef'ed branches.

@HBelusca
Copy link
Copy Markdown
Contributor

HBelusca commented Jan 1, 2018

Hi, please squash your first two commits and fix your author/committer's name!

/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS cabinet manager
* FILE tools/cabman/CCFDATAStorageWindows.cxx
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file name does not correspond to the actual one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comments, I changed headers of the two files I've added.

* PROGRAMMERS:
* NOTES:
* REVISIONS:
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header file does not seem to meet the actual ReactOS Coding Style standard if I am not mistaken. NOTES and REVISIONS are unnecessary. Please refer to this article (File Structure) regarding this.

@learn-more learn-more changed the title Core 12645 CABMAN: Remove _WIN32 ifdef's Jan 1, 2018
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS cabinet manager
* FILE tools/cabman/CCFDATAStorageWindows.cxx
* PURPOSE: CCFDATAStorage class implementation for Windows
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad purpose too

*/
{
fclose(FileHandle);
FileHandle = tmpfile();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why such a complex implementation?
Why not using ftruncate(fileno(FileHandle), 0); ?
And likely fseek(FileHandle, 0, SEEK_SET); beforehand.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that this is not an optimal implementation, but current task is only to remove _WIN32, so I just left the implementation itself untouched.
Refactoring could be the next step.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK for me then.

LONG size;
fseek(handle, 0, SEEK_END);
size = ftell(handle);
fseek(handle, 0, SEEK_SET);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit skeptical about this... Wouldn't it be better to save current position, query for full size, and restore saved position?
So that, it would be consistent with Win32 behaviour.

Copy link
Copy Markdown
Contributor Author

@dfbag7 dfbag7 Jan 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the call to fseek() in line 113 looks strange. But currently I'm trying to not mix tasks together, so I kept the implementation untouched only removing _WIN32 ifdef's.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

* Copyright 2017 Colin Finck <mail@colinfinck.de>
* Copyright 2018 Dmitry Bagdanov <dimbo_job@mail.ru>
*/
#if !defined(_WIN32)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... this really isn't so much a Unix implementation as it is a standard C library one. Why don't we just delete the Win32 version and use this across the board? (I think that may have been the intent behind the Jira ticket)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that ;)
But then I decided to keep the initial intention to not use standard C library file access functions on Windows...

Copy link
Copy Markdown
Member

@learn-more learn-more Jan 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was indeed to drop the win32 one,
since it looks like the other stuff was written after the win32 one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that will be the next pull request then.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with that approach is that what you propose now is not a natural step between the current version of the code and where we'd probably want it to be. E.g. changing if-CreateFile-else-fopen to fopen is much more straightforward than changing it to OpenFileForReading, and then back to the fopen that was already there before. That just seems like unnecessary code churn.
I'm open to discussion, but right now it seems to me like literally deleting all the stuff in the _WIN32 code path would get us closest to where we want to be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ThFabba, now I'm completely agree with you. That was my misunderstanding that the intention is to not use standard C file access functions on Windows. So I'm going to provide another pull request that uses standard C functions on all platforms.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dfbag7 For reference, if you push commits to the same branch they will end up in this pull request.
If you rewrite this branches history and then force-push you will update this pull request.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, as the intent is totally different from original idea, perhaps should we close that PR for a brand new one? New code, new direction, new PR? :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever the process here is - I'm fine with either updating or creating a new PR - I conclude this is WIP, so I'll add the WIP tag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dfbag7 Can you please make a basic performance evaluation after your changes? I am asking because I have experienced (mainly with STL) that portable code can lead to heavily degrading performance and this tool is already kinda slow, so I wouldn't want it to become even slower.

@tkreuzer tkreuzer added the WIP label Jan 6, 2018
@ColinFinck
Copy link
Copy Markdown
Member

@dfbag7 Thanks for working on this! This tool really needs some love.
While you're converting things to C++ classes/STL, you may also want to save some code by replacing my SEARCH_CRITERIA structure by an std::vector. I added that and some custom linked-list code years ago when I was still lacking STL proficiency..
Apart from that, I'm all for dropping the Win32-only code pathes and using STL for file access (alternatively stdio if that gives a better performance).

@dfbag7
Copy link
Copy Markdown
Contributor Author

dfbag7 commented Jan 12, 2018 via email

@learn-more
Copy link
Copy Markdown
Member

In my experience moving fromg stdio to STL will incur a performance hit.

@ThFabba
Copy link
Copy Markdown
Member

ThFabba commented Jan 12, 2018

I'm guessing it's the processing, not the file I/O that makes cabman slow though?

@dfbag7
Copy link
Copy Markdown
Contributor Author

dfbag7 commented Jan 12, 2018

Yes. I have not done profiling, but almost sure that the I/O does not affect performance as much as zipping (which is actually performed by ZLIB library).

@dfbag7
Copy link
Copy Markdown
Contributor Author

dfbag7 commented Jan 23, 2018

Hi all,
I've added another commit. Can you please review? Now almost all file access and memory management calls to WIN32-specific functions are replaced with standard C library counterparts in both Linux and Windows environments.

Copy link
Copy Markdown
Member

@learn-more learn-more left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @dfbag7, sorry for the late reply.
Overall this is already very good looking, I have added some inline comments about some details.

CCFDATAStorage::CCFDATAStorage()
/*
* FUNCTION: Default constructor
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use per-function comments, please stick to a format that is doxygen compatible, preferrably the one outlined here:
https://reactos.org/wiki/Coding_Style

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole CABMAN project uses that style of function comments, so decided to not change them to maintain consistency.
Now the comments changed to the reactos' standard (only in file CCFDATAStorage.cxx file, though).
Commit fc99634

DPRINT(MID_TRACE, ("ERROR '%i'.\n", errno));
return CAB_STATUS_CANNOT_CREATE;
}
*/
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover comments?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those code was left from initial implementation, and I considered to not remove it...
Removed in commit 753efbe

}
*/

FileCreated = true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove FileCreated alltogether, and just check on FileHandle != NULL ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in commit 753efbe

#define DIR_SEPARATOR_CHAR '\\'
#define DIR_SEPARATOR_STRING "\\"
#define DIR_SEPARATOR_CHAR '\\'
#define DIR_SEPARATOR_STRING "\\"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this indented?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation removed in commit 299cede

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For what it's worth, we seem to have three indentation styles for preprocessor directives in use throughout the codebase:

  1. No indentation at all
  2. Indenting like @dfbag7 did
  3. Indenting the directive but not the hash (e.g. "# define")

I personally prefer the style @dfbag7 used. As our Coding Style guidelines give no rule regarding that, I use it myself in some modules.
However, it's up to you guys what shall be used for cabman in the future.

Copy link
Copy Markdown
Member

@HeisSpiter HeisSpiter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new iteration looks good to me, I approve a squash & merge.
This will open room for improvement in the implementation :-).

@ThFabba
Copy link
Copy Markdown
Member

ThFabba commented Jan 25, 2018

Things look good on a cursory glance, but please make this at least 2 commits when merging. Moving existing code to a different file should always be its own commit, then changes to that code should be a second one.

@dfbag7
Copy link
Copy Markdown
Contributor Author

dfbag7 commented Jan 26, 2018

please make this at least 2 commits when merging.

done in that way - commits 2cd3c7b and d45a562

@ThFabba
Copy link
Copy Markdown
Member

ThFabba commented Jan 27, 2018

Perfect, thank you!

@HeisSpiter HeisSpiter merged commit 991d33c into reactos:master Jan 27, 2018
@sanchaez sanchaez removed the WIP label Jan 27, 2018
@dfbag7 dfbag7 deleted the CORE-12645 branch January 27, 2018 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants