Skip to content

Comments

convert list.c to dlist.d#8317

Merged
dlang-bot merged 1 commit intodlang:masterfrom
WalterBright:dlist.d
Jun 17, 2018
Merged

convert list.c to dlist.d#8317
dlang-bot merged 1 commit intodlang:masterfrom
WalterBright:dlist.d

Conversation

@WalterBright
Copy link
Member

Git diff doesn't seem to render diffs when files get renamed. :-(

@WalterBright WalterBright requested a review from MartinNowak as a code owner June 1, 2018 02:59
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#8317"

@WalterBright WalterBright requested a review from wilzbach as a code owner June 1, 2018 02:59
@WalterBright WalterBright force-pushed the dlist.d branch 4 times, most recently from 0d2ee2b to ae61b0e Compare June 1, 2018 05:41
@jacob-carlborg
Copy link
Contributor

jacob-carlborg commented Jun 1, 2018

Git diff doesn't seem to render diffs when files get renamed. :-(

You could do the rename in on commit and the actual changes in a second commit. The it's possible to diff the individual commits, but perhaps not directly on GitHub.

Also, is there a reason to call it dlist instead of list?

while (list_freelist)
{
list_t list = list_next(list_freelist);
list_freelist = list;
Copy link
Contributor

Choose a reason for hiding this comment

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

The C implementation had a call to list_delete here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it does seem to be missing!

}


list_t list_alloc();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this declaration?

Copy link
Member Author

Choose a reason for hiding this comment

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

Leftover from the conversion. Removed.

* Returns:
* pointer to that list entry.
*/

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why you always have a newline between the DDoc and the code. I recommend removing it, but it's not a problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

The newline is the style commonly used. Others have started using the no newline approach. Besides, I try to minimize diffs on initial conversions.

if (list)
{
list.next = *plist;
list.ptr = ptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

C implementation used the list_next and list_ptr wrappers. It seems to be the same functionality, but throughout this file you're sometimes using the wrapper and sometimes not. It makes it a little hard to review and the code is inconsistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

list_next and list_ptr don't work as lvalues in D.

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Not much more I can add besides @JinShil's nice review.



list_t list_new() { return cast(list_t)malloc(LIST.sizeof); }
void list_delete(list_t list) { free(list); }
Copy link
Contributor

Choose a reason for hiding this comment

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

These two functions are never used in the new dlist.d and haven't been used outside of list.c

Copy link
Member Author

Choose a reason for hiding this comment

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

They're both used.

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Let's move finally forward with this!
I'm just unsure about the commented va_end call.

</ClCompile>
<ClCompile Include="..\dmd\tk\vec.c">
<Filter>dmd\tk</Filter>
</ClCompile>
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to move the vec.h header file to the backend, s.t. D code and header files are "in sync".

pe = &list.next;
}
}
//va_end(ap);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for not calling va_end here?
(in C it's called)

Copy link
Member Author

Choose a reason for hiding this comment

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

There was some problem with it being @nogc and nothrow. core.stdc.stdarg apparently needs some additional work.

Copy link
Contributor

Choose a reason for hiding this comment

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

Compiles fine for me -> #8367


alias void function(void*) @nogc nothrow list_free_fp;

enum FPNULL = cast(list_free_fp)null;
Copy link
Member

Choose a reason for hiding this comment

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

You can avoid the cast with enum list_free_fp FPNULL = null. But defining a new symbol here doesn't really buy a lot in comparison to just using null.

Copy link
Member Author

Choose a reason for hiding this comment

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

FPNULL dates from the olden days when function pointers were different from regular pointers due to the wacky DOS memory models. It doesn't make sense any more, as you point out, but changing it here violates the #1 rule of translation.

{
list = list_freelist;
list_freelist = list_next(list);
//mem_setnewfileline(list,file,line);
Copy link
Member

Choose a reason for hiding this comment

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

Keeping this as a comment doesn't really help as all the (conditional) parameter declarations have gone.

struct LIST
{
/* Do not access items in this struct directly, use the */
/* functions designed for that purpose. */
Copy link
Member

Choose a reason for hiding this comment

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

Can you make them private now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Gawd will smite me if I violate the #1 rule of translation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that if I make it private now, then I have to add to this PR all the other files that are modified to make that work. Of course, that will inevitably cause more problems. Such changes need to be separate PRs.

@WalterBright
Copy link
Member Author

Fellas, these are good suggestions but please keep in mind the #1 rule of translating code - do not attempt to refactor, fix, enhance, improve, rename, reorganize, etc. the code. Do as little as possible to get it to work. I have learned this bitter lesson over and over and over.

Copy link
Contributor

@JinShil JinShil left a comment

Choose a reason for hiding this comment

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

do not attempt to refactor, fix, enhance, improve, rename, reorganize, etc. the code

Yeah, let's get this done.

@dlang-bot dlang-bot merged commit 4613464 into dlang:master Jun 17, 2018
@WalterBright WalterBright deleted the dlist.d branch June 17, 2018 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants