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

Support gr objects in flint_printf #2226

Merged
merged 3 commits into from
Feb 1, 2025

Conversation

fredrik-johansson
Copy link
Collaborator

@fredrik-johansson fredrik-johansson commented Jan 31, 2025

Support %{gr_ctx}, %{gr}, %{gr*}, %{gr_poly} and %{gr_mat}.

To make this possible we add error handling to the internal gr_stream methods and have gr_stream_t record the number of written characters so that we can extract this for the return value of flint_printf.

With this it should be possible to get rid of the ad-hoc generics in generic_files/io.c and instead just wrap gr; mainly we just need to consolidate the printing styles first.

BTW am I reading the code wrong or is the error handling in flint_printf actually broken? It doesn't seem to actually check if a subroutine call returns a negative length (indicating error), it just appends it to he total length.

@fredrik-johansson
Copy link
Collaborator Author

I don't understand why clang doesn't like this. It seems to misread the passed length for the gr*. It works if I set slong len = va_arg(vlist, int);, but it doesn't work with slong even if I cast GR_VEC_LEN to slong in test code... but the other vector tests do work? I'm very confused.

@albinahlback
Copy link
Collaborator

BTW am I reading the code wrong or is the error handling in flint_printf actually broken? It doesn't seem to actually check if a subroutine call returns a negative length (indicating error), it just appends it to he total length.

It doesn't have error handling, it assumes that the correct type is used and that the objects have valid representations.

@albinahlback
Copy link
Collaborator

I don't understand why clang doesn't like this. It seems to misread the passed length for the gr*. It works if I set slong len = va_arg(vlist, int);, but it doesn't work with slong even if I cast GR_VEC_LEN to slong in test code... but the other vector tests do work? I'm very confused.

Seems to be OS-specific since macOS passes.

gr_mat_write(gr_stream_t out, const gr_mat_t mat, gr_ctx_t ctx)
{
return _gr_mat_write(out, mat, 1, ctx);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does your editor not end files with a newline?

src/test/t-io.c Outdated
Comment on lines 605 to 619
gr_ctx_t xgr_ctx;
gr_ctx_init_fmpzi(xgr_ctx);
gr_ptr xgr = gr_heap_init(xgr_ctx);
gr_ptr xgr_vec = gr_heap_init_vec(GR_VEC_LEN, xgr_ctx);
gr_poly_t xgr_poly;
gr_mat_t xgr_mat;
GR_IGNORE(gr_set_ui(xgr, 5, xgr_ctx));
GR_IGNORE(gr_set_ui(GR_ENTRY(xgr_vec, 0, xgr_ctx->sizeof_elem), 1, xgr_ctx));
GR_IGNORE(gr_set_ui(GR_ENTRY(xgr_vec, 1, xgr_ctx->sizeof_elem), 2, xgr_ctx));
GR_IGNORE(gr_set_str(GR_ENTRY(xgr_vec, 2, xgr_ctx->sizeof_elem), "I", xgr_ctx));
gr_poly_init(xgr_poly, xgr_ctx);
GR_IGNORE(gr_poly_set_coeff_si(xgr_poly, 1, -1, xgr_ctx));
gr_mat_init(xgr_mat, 1, 2, xgr_ctx);
GR_IGNORE(gr_set_ui(gr_mat_entry_ptr(xgr_mat, 0, 0, xgr_ctx), 4, xgr_ctx));
GR_IGNORE(gr_set_ui(gr_mat_entry_ptr(xgr_mat, 0, 1, xgr_ctx), 3, xgr_ctx));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Before any merging, please initialize, set and clear as done with all other variables.

@fredrik-johansson
Copy link
Collaborator Author

BTW am I reading the code wrong or is the error handling in flint_printf actually broken? It doesn't seem to actually check if a subroutine call returns a negative length (indicating error), it just appends it to he total length.

It doesn't have error handling, it assumes that the correct type is used and that the objects have valid representations.

I mean error handling for the case where IO fails, eg because you've run out of disk space.

@fredrik-johansson fredrik-johansson merged commit a71fd14 into flintlib:main Feb 1, 2025
12 checks passed
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.

2 participants