Skip to content

New printing API#132

Closed
hazeled wants to merge 7 commits intolibtcod:mainfrom
hazeled:main
Closed

New printing API#132
hazeled wants to merge 7 commits intolibtcod:mainfrom
hazeled:main

Conversation

@hazeled
Copy link
Contributor

@hazeled hazeled commented Sep 29, 2022

Adds "TCOD_printf", "TCOD_printn", and "TCOD_vprintf" (Along with a PrintParams struct) to console_printing. Also fixes some typos

@codecov
Copy link

codecov bot commented Sep 29, 2022

Codecov Report

Merging #132 (4ebc8af) into main (38110b9) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

❗ Current head 4ebc8af differs from pull request most recent head f137d82. Consider uploading reports for the commit f137d82 to get more accurate results

@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
- Coverage   18.58%   18.55%   -0.04%     
==========================================
  Files         126      126              
  Lines       13540    13562      +22     
==========================================
  Hits         2517     2517              
- Misses      11023    11045      +22     
Impacted Files Coverage Δ
src/libtcod/console_printing.c 36.15% <0.00%> (-0.99%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@HexDecimal HexDecimal left a comment

Choose a reason for hiding this comment

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

I didn't realize how non-obvious it was that everything above the // New UTF-8 parser. line is something to be avoided.

It's very unfortunate that you performed this work on your main branch instead of a separate branch. I can't safely push changes to the PR in this state. You will also be unable to make a 2nd PR until this is fixed.

I don't like the unversioned print functions. They should at least have something such as rgb as in TCOD_printn_rgb and TCOD_PrintParamsRGB to at least define that this version is using the RGB color types.

Tests will need to be added to tests/test_printing.cpp to satisfy Codecov.

If you're ever done working on this PR then it's possible for me to merge this now. I'll have an easier time resolving these issues since I'm more familiar with the library and the issues are relatively small.

TCOD_PUBLIC int TCOD_printn(
TCOD_Console* __restrict console,
TCOD_PrintParams params,
char* strsrc,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is strsrc not const?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This might also be misspelled? I assume it's supposed to be src. It's also wrong for a sized array to come before the parameter which determines it's size. Even though there are functions in the standard which do that, it's a known issue which you should avoid.

TCOD_PrintParams params,
const char* fmt,
va_list args) {
int err = TCOD_console_print_internal(console, params.x, params.y, params.width, params.height, params.flag, params.alignment, TCOD_console_vsprint(fmt, args), true, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

TCOD_console_print_internal is the deprecated EASCII series of functions. No new code should use any internal function other than printn_internal_.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also TCOD_console_vsprint is not as reentrant as it looks, and should be avoided. vprintf_internal_ handles this case.

Comment on lines 1546 to 1549
char* strbuf = malloc(n);
strncpy(strbuf, strsrc, n);
int err = TCOD_console_print_internal(console, params.x, params.y, params.width, params.height, params.flag, params.alignment, strbuf, true, false);
free(strbuf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

printn functions should no do any allocations. The string and size should be passed to printn_internal_.

@hazeled
Copy link
Contributor Author

hazeled commented Sep 29, 2022

Ahh, my bad. I haven't worked on this library in a while. I'll go ahead and fix those issues, thank you for pointing them out

@hazeled
Copy link
Contributor Author

hazeled commented Sep 29, 2022

Also, I somehow didn't realize I was pushing to the main branch of my fork. I can move it to a different fork with a different branch, if you think that'd work best

@HexDecimal
Copy link
Collaborator

Move this to a topic branch and then I'll start pushing changes to that branch. Most of the issues are small and should be easy for me to fix.

@hazeled hazeled closed this Sep 29, 2022
@hazeled hazeled mentioned this pull request Sep 29, 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.

2 participants