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

Allocation improvements #32

Merged
merged 21 commits into from
Mar 24, 2018
Merged

Allocation improvements #32

merged 21 commits into from
Mar 24, 2018

Conversation

isaachier
Copy link
Contributor

No description provided.

@coveralls
Copy link

coveralls commented Mar 19, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 8e4b419 on isaachier:vla-fix into e545cf3 on uber:master.

Copy link
Collaborator

@dfellis dfellis left a comment

Choose a reason for hiding this comment

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

Not opposed to the PR or its intended changes, but there are other concerns mixed in with it and the changes to generateBaseCellNeighbors.c are simply incorrect.

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see any code in here using string.h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

memset for all of these comments.

@@ -30,13 +30,15 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. printf is in stdio, I don't see why string was included.

@@ -25,22 +25,22 @@

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this.

@@ -237,18 +226,19 @@ void generate() {

printf("const int baseCellNeighbors[NUM_BASE_CELLS][7] = {\n");
for (int i = 0; i < NUM_BASE_CELLS; i++) {
char* neighborStrings[7] = {0, 0, 0, 0, 0, 0, 0};
printf("{");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please undo the changes you made here. This approach will print garbage around the INVALID_BASE_CELL printout, instead of only printing that message when reaching that condition, so it will not generate the base cell neighbors code correctly, anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I'm very confused. The difference between the old code and this is the removal of the generateBaseCellOutput, which simply formatted strings that are printed here. Instead, I used identical code here to write the digits/macro directly to stdout.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dfellis Could you paste the output you are seeing or expecting? I ran this branch and got the same output as before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My mistake on the reading of his changes. I did not run his branch.

@@ -22,6 +22,7 @@
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this.

@isaachier isaachier mentioned this pull request Mar 19, 2018
@@ -90,9 +91,8 @@ int H3_EXPORT(maxKringSize)(int k) {
*/
void H3_EXPORT(kRing)(H3Index origin, int k, H3Index* out) {
int maxIdx = H3_EXPORT(maxKringSize)(k);
int* distances = calloc(maxIdx, sizeof(int));
int distances[maxIdx];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was a little concerned this does not initialize distances. It might be that distances cannot be used before initializing. Not sure if you want to add a memset here for clarity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Was almost certain I followed them all with a memset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

numRemainingHexes = compactableCount;
}
// Final cleanup
free(remainingHexes);
free(hashSetArray);
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this line is no longer reached in tests, perhaps because of the change around line 276. Could you change to preserve 100% coverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Will push fix for that now.

@@ -237,18 +226,19 @@ void generate() {

printf("const int baseCellNeighbors[NUM_BASE_CELLS][7] = {\n");
for (int i = 0; i < NUM_BASE_CELLS; i++) {
char* neighborStrings[7] = {0, 0, 0, 0, 0, 0, 0};
printf("{");
Copy link
Collaborator

Choose a reason for hiding this comment

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

@dfellis Could you paste the output you are seeing or expecting? I ran this branch and got the same output as before.

@@ -741,7 +742,8 @@ void H3_EXPORT(polyfill)(const GeoPolygon* geoPolygon, int res, H3Index* out) {
// This first part is identical to the maxPolyfillSize above.

// Get the bounding boxes for the polygon and any holes
BBox* bboxes = calloc(sizeof(BBox), geoPolygon->numHoles + 1);
BBox bboxes[geoPolygon->numHoles + 1];
memset(bboxes, 0, sizeof(BBox));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a mistake. Let me fix now.

@@ -741,7 +742,8 @@ void H3_EXPORT(polyfill)(const GeoPolygon* geoPolygon, int res, H3Index* out) {
// This first part is identical to the maxPolyfillSize above.

// Get the bounding boxes for the polygon and any holes
BBox* bboxes = calloc(sizeof(BBox), geoPolygon->numHoles + 1);
BBox bboxes[geoPolygon->numHoles + 1];
memset(bboxes, 0, sizeof(bboxes));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@isaachier
Copy link
Contributor Author

Think I addressed all the comments.

@isaacbrodsky
Copy link
Collaborator

I tested this on MSVC (Visual Studio 2017) and it seems it does not support variable length arrays. I would prefer the repo is limited to the subset of C99/C11 that MSVC supports to maximize how broadly it can be used.

Copy link
Collaborator

@nrabinowitz nrabinowitz left a comment

Choose a reason for hiding this comment

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

One note, probably ignorable, otherwise LGTM.

currentCoord = currentLoop->first;
while (currentCoord != NULL) {
bool skip = true;
for (LinkedGeoPolygon *currentPolygon = polygon, *nextPolygon;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I believe our style in this project is LinkedGeoPolygon* currentPolygon, can we use that here? Or would that require LinkedGeoPolygon* currentPolygon, LinkedGeoPolygon* nextPolygon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the pointer alignment? Ya it's a problem. clang-format isn't even fixing it. The only alternative is LinkedGeoPolygon* nextPolygon; followed by for (LinkedGeoPolygon* currentPolygon = ...). I once answered a question about this on StackOverflow here: https://stackoverflow.com/a/16490876/1930331.

Copy link
Collaborator

@isaacbrodsky isaacbrodsky left a comment

Choose a reason for hiding this comment

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

*Requested change is discussing what features of C we want to require.

@@ -0,0 +1,21 @@
if(__check_alloca)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please include the license header in all source files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

@@ -0,0 +1,44 @@
#ifndef STACKALLOC_H
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please also include a @file/@brief comment describing the purpose of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea

neighborStrings[0], neighborStrings[1], neighborStrings[2],
neighborStrings[3], neighborStrings[4], neighborStrings[5],
neighborStrings[6], i,
printf("}, /* base cell %d%s */\n", i,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the formatting of the comments changes, could you rerun generateBaseCellNeighbors and update baseCells.c?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing.

@isaacbrodsky
Copy link
Collaborator

I successfully built and tested this on MSVC :) - #34 will make that automated.

@isaachier
Copy link
Contributor Author

Luckily even MSVC has the alloca function. It's a bit ugly but this should definitely allow some form of VLA on all popular platforms.

reentrant_gmtime(&tmStruct, &rawTime);
const char licenseFormat[] =
"/*\n"
" * Copyright 2016-%d Uber Technologies, Inc.\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a lot of work just to automatically format the date. I don't think the parts of the baseCells.c file unrelated to the baseCellNeighbors/baseCellNeighbor60CCWRots should be generated. (Those two were the only parts of the file that were generated from this - maybe those two could be split off to their own, generated file.)

Could you revert this change, and we can revisit it in another issue or PR?

Copy link
Contributor

@jogly jogly left a comment

Choose a reason for hiding this comment

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

lgtm

@isaacbrodsky isaacbrodsky merged commit f87862a into uber:master Mar 24, 2018
@isaachier isaachier deleted the vla-fix branch August 5, 2018 22:49
mrdvt92 pushed a commit to mrdvt92/h3 that referenced this pull request Jun 19, 2022
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.

6 participants