KJ7LNW / xnec2c

Xnec2c is a high-performance multi-threaded electromagnetic simulation package to model antenna near- and far-field radiation patterns for Linux and UNIX operating systems.
https://www.xnec2c.org/
GNU General Public License v3.0
77 stars 16 forks source link

Fix type errors with glib 2.73 #13

Closed df7cb closed 2 years ago

df7cb commented 2 years ago

On Debian unstable, xnec2c fails to compile:

common.h:1453:6: error: conflicting types for 'g_idle_add_once'; have 'void(gboolean (*)(void *), void *)' {aka 'void(int (*)(void *), void *)'}
 1453 | void g_idle_add_once(GSourceFunc function, gpointer data);
      |      ^~~~~~~~~~~~~~~
In file included from /usr/include/glib-2.0/glib/giochannel.h:35,
                 from /usr/include/glib-2.0/glib.h:56,
                 from /usr/include/gtk-3.0/gdk/gdkconfig.h:13,
                 from /usr/include/gtk-3.0/gdk/gdk.h:30,
                 from /usr/include/gtk-3.0/gtk/gtk.h:30,
                 from common.h:35:
/usr/include/glib-2.0/glib/gmain.h:822:10: note: previous declaration of 'g_idle_add_once' with type 'guint(void (*)(void *), void *)' {aka 'unsigned int(void (*)(void *), void *)'}
  822 | guint    g_idle_add_once            (GSourceOnceFunc function,
      |          ^~~~~~~~~~~~~~~

The attached patch fixes the issue here. The net change is:

-void g_idle_add_once(GSourceFunc function, gpointer data);
+guint g_idle_add_once(GSourceOnceFunc function, gpointer data);

-void g_idle_add_once_sync(GSourceFunc function, gpointer data);
+void g_idle_add_once_sync(GSourceOnceFunc function, gpointer data);

Note that I did not verify if that change is backwards compatible with older library versions.

KJ7LNW commented 2 years ago

Hi Christoph,

Thanks for your contribution!

I tried to compile this on my desk (CentOS 7) and I get these errors. Is a typedef for GSourceOnceFunc missing somewhere or is GSourceOnceFunc really a glib type in a newer release? If GSourceOnceFunc is new to glib then configure.ac needs to be updated to handle it being missing on older distributions.

In file included from main.h:23:0,
                 from main.c:20:
common.h:1490:23: error: unknown type name ‘GSourceOnceFunc’
 guint g_idle_add_once(GSourceOnceFunc function, gpointer data);
                       ^
common.h:1491:27: error: unknown type name ‘GSourceOnceFunc’
 void g_idle_add_once_sync(GSourceOnceFunc function, gpointer data);

-Eric

KJ7LNW commented 2 years ago

If GSourceOnceFunc is new to glib then configure.ac needs to be updated to handle it being missing on older distributions.

... or would GSourceFunc instead of GSourceOnceFunc be acceptable?

df7cb commented 2 years ago

It's a typedef in /usr/include/glib-2.0/glib/gmain.h (libglib2.0-dev 2.73.3-3):

/**
 * GSourceFunc:
 * @user_data: data passed to the function, set when the source was
 *     created with one of the above functions
 *
 * Specifies the type of function passed to g_timeout_add(),
 * g_timeout_add_full(), g_idle_add(), and g_idle_add_full().
 *
 * When calling g_source_set_callback(), you may need to cast a function of a
 * different type to this type. Use G_SOURCE_FUNC() to avoid warnings about
 * incompatible function types.
 *
 * Returns: %FALSE if the source should be removed. %G_SOURCE_CONTINUE and
 * %G_SOURCE_REMOVE are more memorable names for the return value.
 */
typedef gboolean (*GSourceFunc)       (gpointer user_data);

/**
 * GSourceOnceFunc:
 * @user_data: data passed to the function, set when the source was
 *   created
 *
 * A source function that is only called once before being removed from the main
 * context automatically.
 *
 * See: g_idle_add_once(), g_timeout_add_once()
 *
 * Since: 2.74
 */
typedef void (* GSourceOnceFunc) (gpointer user_data);

I have not investigated any context, I just wanted xnec2c to compile so we could update the Debian package from 4.3.4 to 4.4.11. With that patch, it seems to work. (Unfortunately I'm still in the pre-beginner phase as a user, so I can't test much more than loading an example file and see if there's any antenna visible on the screen.)

Cc: @hibby

KJ7LNW commented 2 years ago

(Unfortunately I'm still in the pre-beginner phase as a user, so I can't test much more than loading an example file and see if there's any antenna visible on the screen.)

Here are a few hints to get you started:

  1. Start with a simple antenna like 2m_yagi.nec because it will render quickly.
  2. In the main window, select View->Radiation Pattern and View->Frequency Plots
  3. In the Freqplots window, select "Max Gain" and "VSWR" (or whichever you'd like to see).
  4. Click the triangle "Play" button on the freqplots window to render the graph.
  5. Click anywhere in the plot window to select a frequency (green line)
  6. Drag the radiation pattern around and have a look!
  /* See: g_idle_add_once(), g_timeout_add_once()
  *
  * Since: 2.74
  */
 typedef void (* GSourceOnceFunc) (gpointer user_data);

It looks like xnec2c is ahead of its time, unexpectedly predicting the future: last year g_idle_add_once() was implemented in xnec2c, and a year later the Gnome team added that very function.

So this is more complicated than I thought because of the namespace collision. You discovered the namespace issue while fixing the prototype here:

-void g_idle_add_once(GSourceFunc function, gpointer data)
+guint g_idle_add_once(GSourceOnceFunc function, gpointer data)

Actually I'm surprised there wasn't a symbol collision at link time since xnec2c used the same g_idle_add_once() function name as GLIB.

They may be implemented differently, but the only real difference between the two versions in terms of functionality is the return value. There are a couple #ifdef's that you'll need so I'll mock up a branch in github and have you test it.

KJ7LNW commented 2 years ago

@df7cb,

Please test this branch in my repo that is based on your original work: glib-type

If it works in Sid then let me know so I can release xnec2c 4.4.12 with your changes.

Thanks!

-Eric

KJ7LNW commented 2 years ago

Hi @df7cb,

I noticed this github issue mentions glib 2.72 in the title, but I think it only affects 2.73 and later (that is, 2.74 since 2.73 is the dev for 2.74) based on the comment here: https://github.com/GNOME/glib/blob/main/glib/gmain.h#L197

Anyway I think I have the #ifdef's correct, so let me what you get when you build this branch: https://github.com/KJ7LNW/xnec2c/tree/glib-type

-Eric

df7cb commented 2 years ago

Hi Eric @KJ7LNW,

the 2.72 was a typo on my side, sorry. Your glib-type branch compiles fine here.

Thanks for the hits on getting started! Unfortunately, when clicking the play button, a graph with sine-like waves starts drawing, but right before finishing, there's a segfault:

[err] Unable to set the preferred mathlib index to 0 (ignore if first run)
[1749214 BUG:mathlib_lock_intel]    mathlib.c:740: mathlib_lock_intel: Cannot find library for mathlib idx=17
[debug]   Backtrace:
[debug]     0. xnec2c(print_backtrace+0x52) [0x5625f80291e2]
[debug]     1. xnec2c(_xnec2c_printf+0x18f) [0x5625f7fec48f]
[debug]     2. xnec2c(Frequency_Loop+0x2f2) [0x5625f8019142]
[debug]     3. xnec2c(Frequency_Loop_Thread+0x27) [0x5625f80198b7]
[debug]     4. /lib/x86_64-linux-gnu/libc.so.6(+0x87b27) [0x7f3def887b27]

...

[1749215 BUG:set_mathlib_interactive]   mathlib.c:308: set_mathlib_interactive: lib == NULL
[debug]   Backtrace:
[debug]     0. xnec2c(print_backtrace+0x52) [0x5625f80291e2]
[debug]     1. xnec2c(_xnec2c_printf+0x18f) [0x5625f7fec48f]
[debug]     2. xnec2c(Child_Process+0xaf6) [0x5625f8011846]
[debug]     3. xnec2c(main+0x4c1) [0x5625f7fe13a1]
[debug]     4. /lib/x86_64-linux-gnu/libc.so.6(+0x2920a) [0x7f3def82920a]
[debug]     5. /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x7c) [0x7f3def8292bc]

[crit] segmentation fault, exiting

Not sure the backtrace is usable, but there it is: core.txt

For comparison, the plot works with 4.3.4:

xnec2c: warning: existing config file version differs: xnec2c 4.4.11 != xnec2c 4.3.4

Trying ATLAS, Threaded (libtatlas.so.3):
  Unable to open libtatlas.so.3: libtatlas.so.3: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying ATLAS, Serial (libsatlas.so.3):
  Unable to open libsatlas.so.3: libsatlas.so.3: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying OpenBLAS+LAPACKe, Serial (libopenblas.so):
  Unable to open libopenblas.so: libopenblas.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying OpenBLAS+LAPACKe, OpenMP (libopenblaso.so):
  Unable to open libopenblaso.so: libopenblaso.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying OpenBLAS+LAPACKe, pthreads (libopenblasp.so):
  Unable to open libopenblasp.so: libopenblasp.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying OpenBLAS+LAPACKe, Serial (libopenblas_serial.so.0):
  Unable to open libopenblas_serial.so.0: libopenblas_serial.so.0: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying OpenBLAS+LAPACKe, OpenMP (libopenblas_openmp.so.0):
  Unable to open libopenblas_openmp.so.0: libopenblas_openmp.so.0: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying OpenBLAS+LAPACKe, pthreads (libopenblas_pthreads.so.0):
  Unable to open libopenblas_pthreads.so.0: libopenblas_pthreads.so.0: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying Selected LAPACK+BLAS (liblapacke.so.3):
  Unable to open liblapacke.so.3: liblapacke.so.3: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying ATLAS (liblapack_atlas.so.3):
  Unable to open liblapack_atlas.so.3: liblapack_atlas.so.3: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying Intel MKL, Serial (libmkl_rt.so):
  Unable to open libmkl_rt.so: libmkl_rt.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying Intel MKL, TBB Threads (libmkl_rt.so):
  Unable to open libmkl_rt.so: libmkl_rt.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying Intel MKL, Intel Threads (libmkl_rt.so):
  Unable to open libmkl_rt.so: libmkl_rt.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying Intel MKL, GNU Threads (libmkl_rt.so):
  Unable to open libmkl_rt.so: libmkl_rt.so: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
  skipping.

Trying NEC2 Gaussian Elimination ((builtin)):
  loaded ok.
/home/myon/.xnec2c/xnec2c.conf:76: parse error (Structure Projection Center x and y Offset): 0.000000,0.000000 
/home/myon/.xnec2c/xnec2c.conf:78: parse error (Rdpattern Projection Center x and y Offset): 0.000000,0.000000 
Unable to set the preferred mathlib index to 0
/home/myon/.xnec2c/xnec2c.conf:94: Line not parsed: 0
/home/myon/.xnec2c/xnec2c.conf:96: Line not parsed: 0
New_Frequency[1750381]: NEC2 Gaussian Elimination: total time at 140,00 MHz: 0,035277 seconds
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
mathlib_lock_intel: Cannot find library for mathlib idx=17
set_mathlib_interactive: lib == NULL
Frequency_Loop elapsed time: 0,692373 seconds
New_Frequency[1750381]: NEC2 Gaussian Elimination: total time at 150,00 MHz: 0,029148 seconds

(We probably need to add some dependencies to xnec2c.deb to pull in some of these libs.)

KJ7LNW commented 2 years ago

Strange that it is getting mathlib index 17, it is probably a conf parsing issue between 4.3 and 4.4.

Please send me your ~/.xnec2c/xnec2c.conf file so I can test here.

Also, see if this fixes it: mv ~/.xnec2c/xnec2c.conf ~/.xnec2c/xnec2c.conf-broken

KJ7LNW commented 2 years ago

See previous comment too.

Lets also try this to see if we can get a more detailed backtrace with your current config:

make clean
CFLAGS='-g -O0' ./configure && make
gdb ./src/xnec2c -ex 'run <your-args-here-if-any>'
# for example, if you are using 4 CPUs: gdb ./src/xnec2c -ex 'run -j4'

When it core dumps, run this:

gdb> bt f
gdb> thr a a bt f

Regarding mathlib dependencies: See the "Dependencies" and "Technical Details" section in the PACKAGING document, here:

For Debian I've found this to work but it could pull in more than you actually need:

See the comments in the mathlib_t structure atop of mathlib.c:

KJ7LNW commented 2 years ago

I think I was able to reproduce the issue by hacking 17 into the conf for the mathlib selection in xnec2c.conf.

standby, I'll put up a test branch.

KJ7LNW commented 2 years ago

Ok I think this has been fixed in master. The glib-type branch was merged too:

Please test and if it works then I'll roll a new release.

df7cb commented 2 years ago

Thanks for the fixes! I'm currently not at the machine where it crashed (will try that tonight), but it works on the machine here. A new release would be awesome if you think the problems have been dealt with.

Thanks also for the library tips - we'll need to fix that up on the Debian side here, there's currently some unresolvable symbols within the libraries themselves, so I can't test that yet.

df7cb commented 2 years ago

Works on the shack computer now, thanks!

$ xnec2c examples/2m_yagi.nec 
[notice] existing config file version differs: xnec2c 4.3.4 != xnec2c 4.4.11
[warn] Structure Projection Center x and y Offset (locale=C): only matchd 8 of 17 chars, trying another locale: 0,000000,0,000000
[warn] Rdpattern Projection Center x and y Offset (locale=C): only matchd 8 of 17 chars, trying another locale: 0,000000,0,000000
[err] ATLAS, Threaded was not detected: Unable to set the mathlib index to 0
[warn] mathlib_batch_idx out of range, clamping to zero: 0 !< 17 !< 12
[err] ATLAS, Threaded was not detected: Unable to set the mathlib index to 0
[warn] Selected fmhz_save Frequency (locale=C): only matchd 1 of 8 chars, trying another locale: 0,000000
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
[err] set_mathlib_interactive[1755620]: mathlib.available=0, skipping: ATLAS, Threaded
# Xnec2c configuration file
#
# Application Vesrsion
xnec2c 4.3.4
# Current Working Directory
1
# Main Window Size, in pixels
1278,563
# Main Window Position (root x and y)
1281,1036
# Main Window Currents toggle button state
1
# Main Window Charges toggle button state
0
# Main Window Polarization menu total state
1
# Main Window Polarization menu horizontal state
0
# Main Window Polarization menu vertical state
0
# Main Window Polarization menu right hand state
0
# Main Window Polarization menu left hand state
0
# Main Window Frequency loop start state
1
# Main Window Rotate spinbutton state
50
# Main Window Incline spinbutton state
52
# Main Window Zoom spinbutton state
110
# Radiation Pattern Window Size, in pixels
0,0
# Radiation Pattern Window Position (root x and y)
0,0
# Radiation Pattern Window Gain toggle button state
0
# Radiation Pattern Window EH toggle button state
0
# Radiation Pattern Window Menu E-field state
0
# Radiation Pattern Window Menu H-field state
0
# Radiation Pattern Window Menu Poynting vector state
0
# Radiation Pattern Window Zoom spinbutton state
100
# Frequency Plots Window Size, in pixels
1278,973
# Frequency Plots Window Position (root x and y)
1281,41
# Frequency Plots Window Max Gain toggle button state
1
# Frequency Plots Window Gain Direction toggle button state
0
# Frequency Plots Window Viewer Direction Gain toggle button state
0
# Frequency Plots Window VSWR toggle button state
0
# Frequency Plots Window Z-real/Z-imag toggle button state
0
# Frequency Plots Window Z-mag/Z-phase toggle button state
0
# Frequency Plots Window Smith toggle button state
0
# Frequency Plots Window Net Gain checkbutton state
0
# Frequency Plots Window Min/Max checkbutton state
0
# NEC2 Editor Window Size, in pixels
0,0
# NEC2 Editor Window Position (root x and y)
0,0
# Structure Projection Center x and y Offset
0,000000,0,000000
# Rdpattern Projection Center x and y Offset
0,000000,0,000000
# Enable Confirm Quit Dialog
0
# Selected Mathlib
0
# Selected Batch Mathlib
17
# Selected Mathlib Benchmarks
000000000000000
# Selected fmhz_save Frequency
0,000000
# Frequency Plots Show S11 checkbutton state
0
# Frequency Plots Show Clamp VSWR checkbutton state
1
KJ7LNW commented 2 years ago

Glad it works! I just pushed a few new commits to the master branch if you want to test. I'll release 4.4.12 shortly.

KJ7LNW commented 2 years ago

Ok, v4.4.12 is out: https://www.xnec2c.org/#Version

Please give it a try!

df7cb commented 2 years ago

Looks good, thanks! Debian package updated and uploaded.