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

Failed at empty_string & print_filter #147

Open
Mercurius-Lee opened this issue Aug 5, 2020 · 15 comments
Open

Failed at empty_string & print_filter #147

Mercurius-Lee opened this issue Aug 5, 2020 · 15 comments

Comments

@Mercurius-Lee
Copy link

I failed to upgrade my confuse 3.2.2 to 3.3 by homebrew.
image

@troglobit
Copy link
Collaborator

Hoping there are some macOS users out there to help debug this. We need at least .log files and someone to run each failing/fauly test manually and in gdb to find the root cause.

@cardre
Copy link

cardre commented Nov 27, 2020

I think empty_string fails I think because of the rewind using the fseek to 0 on the fmemopen file. Maybe just needs to use rewind instead? I didn't have time to verify this though.

The print_filter is crashing/seg fault because the version of macOS being used for this failure doesn't have a fmemopen implementation and its missing the external definition that happens to be at the top of the empty_string test, i.e. copy this to the top of print_filter.c

#ifndef HAVE_FMEMOPEN
extern FILE *fmemopen(void *buf, size_t size, const char *type);
#endif

@sevan
Copy link

sevan commented Nov 19, 2023

For the empty_string test, output is

FILE:1: no such option 'Þ° ^A^Uh<8f>àr¤<90>'
----------------------------------------------
empty_string.c:37: test FAILED:
Failed test: cfg_parse_fp(cfg, f) == CFG_SUCCESS
----------------------------------------------
FAIL empty_string (exit status: 1)

I'm not seeing the issue with print_filter on OS X Tiger 10.4, running the 3.3 test suite.

@sevan
Copy link

sevan commented Feb 1, 2024

@troglobit I can help with this, what would you like to see from gdb for the empty_string test?

@troglobit
Copy link
Collaborator

@troglobit I can help with this, what would you like to see from gdb for the empty_string test?

At least a backtrace, but even better would be if you could debug it back to the root cause. I have no way to take over where you leave it, or even guess what a fix could be.

@sevan
Copy link

sevan commented Feb 1, 2024

FYI the empty_string issue is not exclusive to Darwin. I've recreated it on FreeBSD 13.2 by forcing the use of the fmemopen implementation supplied by libconfigure.
To reproduce, ./configure ac_cv_func_fmemopen=no && make check

FAIL: empty_string
==================

----------------------------------------------
empty_string.c:37: test FAILED:
Failed test: cfg_parse_fp(cfg, f) == CFG_SUCCESS
----------------------------------------------
FAIL empty_string (exit status: 1)

@troglobit
Copy link
Collaborator

Great! Any ideas for a fix or root cause yet?

@sevan
Copy link

sevan commented Feb 2, 2024

Not yet. There's no back trace for empty_string since it's a single function. it's all happening in main() but I can step trough it. Still playing around to find out where it is going wrong. My guess is that one of the functions your fmemopen() implementation call has the issue. There's also a note at the bottom of funopen(3) that "The funopen() function may not be portable to systems other than BSD." and I'm wonder if that's referring to implementation details or just a heads up about availability.

@sevan
Copy link

sevan commented Feb 7, 2024

Ok, I've narrowed it down to the second half of tests/empty_string.c, if I comment out line 35 to 40 so the second part never runs, then the empty string test passes.
Sometime the test-suite.log contains a message with garbage like FILE:2: no such option '^S¼¿ÿó<8f>å'that's fromfail_unless(cfg_parse_fp(cfg2, f) == CFG_SUCCESS);`

@sevan
Copy link

sevan commented Feb 9, 2024

Issue is the fmemopen substitute which is a wrapper for funopen.
The funopen(3) manual on macOS states

The funopen() function associates a stream with up to four ``I/O
functions''.  Either readfn or writefn must be specified; the others can
be given as an appropriately-typed NULL pointer.  These I/O functions
will be used to read, write, seek and close the new stream.

The fmemopen substitute has a single call to funopen with read & writefn both specified. I tried to break it up so based on what operation was specified to fmemopen would be passed to funopen didn't really work and I guess would need to account for seeking as another case?

Not addressing the issue, but replacing the fmemopen call with tempfile allows tests/empty_string to pass.

--- tests/empty_string.c.orig	2024-02-07 00:08:37.000000000 +0000
+++ tests/empty_string.c	2024-02-09 00:14:12.000000000 +0000
@@ -23,7 +23,7 @@
 	cfg = cfg_init(opts, 0);
 	fail_unless(cfg_parse_buf(cfg, "string = ''") == CFG_SUCCESS);
 	fail_unless(strcmp(cfg_getstr(cfg, "string"), "") == 0);
-	f = fmemopen(buf, sizeof(buf), "w+");
+	f = tmpfile();
 	fail_unless(f != NULL);
 	cfg_print(cfg, f);
 	cfg_free(cfg);

Import a working fmemopen implementation from somewhere or don't try to use it if the host doesn't support it?

I ended up here because libftdi has a libconfuse dependency, but luckily they don't use fmemopen & cfg_parse_fp so I can sidestep the issue and put up a warning for anyone installing libconfuse with the intention of using it for other purposes that this is broken on legacy systems which lack support already.

@sevan
Copy link

sevan commented Feb 14, 2024

Or a better approach is to stick with libconfuse 3.0 before fmemopen() usage was introduced.

@troglobit
Copy link
Collaborator

macOS is not an operating system I'm good at, so any help getting a pull request in to fix this problem would be great.

@sevan
Copy link

sevan commented Feb 17, 2024

For sure, are you comfortable with FreeBSD by any chance?

@troglobit
Copy link
Collaborator

For sure, are you comfortable with FreeBSD by any chance?

Sure, the main problem though is finding the time. I'll see if I can find some the coming week.

@sevan
Copy link

sevan commented Feb 18, 2024

I'll cover testing on Darwin if you can get something together, doesn't have to be in the coming week if that's a hassle.

sevan added a commit to sevan/teabrew that referenced this issue Mar 28, 2024
Hold back to v3.0 since 3.1 onwards rely on fmemopen(3) and its
implementation for backwards compatibility with systems that lack it
e.g Tiger doesn't work.
libconfuse/libconfuse#147
sevan added a commit to sevan/teabrew that referenced this issue Mar 28, 2024
Hold back to v3.0 since 3.1 onwards rely on fmemopen(3) and its
implementation for backwards compatibility with systems that lack it
e.g Tiger doesn't work.
libconfuse/libconfuse#147
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

No branches or pull requests

4 participants