Using ZZipLib with SDL? (Compiling SDL_rwops_zzip.c) - windows

This question is a bit specific, but here goes: I'd like to use ZZipLib with SDL. (http://zziplib.sourceforge.net/) ZZipLib comes with a file called SDL_rwops_zzip.c that is specifically intended to make it easy to plug into SDL's file calls. And I have in fact done this without trouble on the Mac.
The problem is on Windows it won't compile. The code in question is from SDL_rwops_zzip.c:
#define SDL_RWOPS_ZZIP_DATA(_context) \
((_context)->hidden.unknown.data1)
#define SDL_RWOPS_ZZIP_FILE(_context) (ZZIP_FILE*) \
((_context)->hidden.unknown.data1)
static int _zzip_seek(SDL_RWops *context, int offset, int whence) // line 30
{
return zzip_seek(SDL_RWOPS_ZZIP_FILE(context), offset, whence);
}
The errors I get are:
SDL_rwops_zzip.c(31): warning C4028: formal parameter 1 different from declaration
SDL_rwops_zzip.c(31): warning C4028: formal parameter 3 different from declaration
SDL_rwops_zzip.c(31): warning C4029: declared formal parameter list different from definition
SDL_rwops_zzip.c(31): error C2491: '_read' : definition of dllimport function not allowed
This Stack Overflow post gives some info on that error:
definition of dllimport function not allowed
but I really don't understand what to do to resolve this error in this particular situation.

I solved the problem by recompiling zziplib using a built-from-scratch Visual Studio 10 Project (the upgraded visual studio 7 project did not produce a working library or .dll), and then by commenting out these lines in conf.h:
# if !__STDC__
# ifndef _zzip_lseek
# define _zzip_lseek _lseek
# endif
# ifndef _zzip_read
# define _zzip_read _read
# endif
# ifndef _zzip_write
# define _zzip_write _write
# endif
# if 0
# ifndef _zzip_stat
# define _zzip_stat _stat
# endif
# endif
# endif // !__STDC__
#endif
and this:
# ifndef _zzip_lseek
# define _zzip_lseek lseek
# endif
# ifndef _zzip_read
# define _zzip_read read
# endif
# ifndef _zzip_write
# define _zzip_write write
# endif

Related

How to query GCC warnings for C++?

GCC allows querying available warning flags specific for C++ language with the syntax:
g++ -Q --help=warning,c++
Adding warning flags to the call includes them in the result:
g++ -Wall -Q --help=warning,c++
However, it seems the call is done from the C point of view and I don't know how to do it from the C++ point of view. If the call includes C++-only warning, like:
g++ -Wnon-virtual-dtor -Q --help=warning,c++
the output contains a message:
cc1: warning: command line option ‘-Wnon-virtual-dtor’ is valid for C++/ObjC++ but not for C
and still shows the warning as disabled:
-Wnon-virtual-dtor [disabled]
Note, that this happens regardless of whether the call is done using g++ or gcc.
The same with C-only -Wbad-function-cast behaves in an expected way:
gcc -Wbad-function-cast -Q --help=warning,c
There is no extra message and reported warning status changes between [disabled] and [enabled]. Again, regardless of whether g++ or gcc is used.
I'm using GCC version 7.3.0. Although the issue seems to apply to many if not all versions. It can be observed through Compiler Explorer.
So, is there a way to do this query with respect to given language?
Yes, your observations are correct.
Probably this is not the intended behavior, and if you care about this feature, then I suggest reporting it upstream.
Note that this works, however:
touch 1.cc
g++ -Wnon-virtual-dtor -Q --help=warning,c++ 1.cc
I.e. if there's an input file with a proper extension, then the correct compiler proper executable is invoked: cc1plus, not cc1. The latter is the default if no input files are present. I did some quick debugging, and here's how that happens:
// gcc.c:
driver::do_spec_on_infiles () const
{
...
for (i = 0; (int) i < n_infiles; i++)
{
...
/* Figure out which compiler from the file's suffix. */
input_file_compiler
= lookup_compiler (infiles[i].name, input_filename_length,
infiles[i].language);
if (input_file_compiler)
{
...
value = do_spec (input_file_compiler->spec);
And input_file_compiler at that point is the C compiler, because
p n_infiles
$9 = 1
(gdb) p infiles[0]
$10 = {name = 0x4cbfb0 "help-dummy", language = 0x4cbfae "c", incompiler = 0x58a920, compiled = false, preprocessed = false}
Here's how the dummy file got created (function process_command in the same file):
if (n_infiles == 0
&& (print_subprocess_help || print_help_list || print_version))
{
/* Create a dummy input file, so that we can pass
the help option on to the various sub-processes. */
add_infile ("help-dummy", "c");
}

error when compiling kernel with some new features

I am trying to compile kernel version 4.1 with some patches (adding some features to the GRO). I come from a hardware background and relatively new to network stack. I wish to know how to solve this problem or at least pointers to understand why it occurs.
This is what I did
# my temp location
mdkir kern
cd kern
# cloned the juggler and linux 4.1 tree
git clone https://github.com/gengyl08/juggler.git
wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.1.tar.gz
tar -xvf linux-4.1.tar.gz
# copied just the essential files that were diffferent
cp juggler/linux-4.1/include/linux/netdevice.h linux-4.1/include/linux/netdevice.h
cp juggler/linux-4.1/include/linux/skbuff.h linux-4.1/include/linux/skbuff.h
cp juggler/linux-4.1/net/core/dev.c linux-4.1/net/core/dev.c
cp juggler/linux-4.1/net/core/net-sysfs.c linux-4.1/net/core/net-sysfs.c
cp juggler/linux-4.1/net/core/skbuff.c linux-4.1/net/core/skbuff.c
cp juggler/linux-4.1/net/ipv4/af_inet.c linux-4.1/net/ipv4/af_inet.c
cp juggler/linux-4.1/net/ipv4/tcp_offload.c linux-4.1/net/ipv4/tcp_offload.c
cd linux-4.1
make menuconfig # generated the default .config file
# building the kernel
time make
When I try to compile them, I get the following error
drivers/net/ethernet/agere/et131x.c: In function ‘nic_send_packet.constprop.43’:
include/linux/compiler.h:412:20: error: call to ‘__compiletime_assert_2439’ declared with attribute error: BUILD_BUG
prefix ## suffix(); \
^
include/linux/compiler.h:417:2: note: in expansion of macro ‘__compiletime_assert’
__compiletime_assert(condition, msg, prefix, suffix)
^
include/linux/compiler.h:429:2: note: in expansion of macro ‘_compiletime_assert’
_compiletime_assert(condition, msg, __compiletime_assert_, __LINE__)
^
include/linux/bug.h:50:37: note: in expansion of macro ‘compiletime_assert’
#define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
^
include/linux/bug.h:74:2: note: in expansion of macro ‘BUILD_BUG_ON_MSG’
BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
^
drivers/net/ethernet/agere/et131x.c:2439:2: note: in expansion of macro ‘BUILD_BUG_ON’
BUILD_BUG_ON(MAX_SKB_FRAGS + 1 > 23);
^
make[4]: *** [drivers/net/ethernet/agere/et131x.o] Error 1
make[3]: *** [drivers/net/ethernet/agere] Error 2
make[2]: *** [drivers/net/ethernet] Error 2
make[1]: *** [drivers/net] Error 2
make: *** [drivers] Error 2
real 22m3.067s
user 21m4.028s
sys 1m6.724s
It looks like MAX_SKB_FRAGS is too big and ethernet driver doesn't like it.
From drivers/net/ethernet/agere/et131x.c:
/* Part of the optimizations of this send routine restrict us to
* sending 24 fragments at a pass. In practice we should never see
* more than 5 fragments.
*/
/* nr_frags should be no more than 18. */
BUILD_BUG_ON(MAX_SKB_FRAGS + 1 > 23);
From the patches you're using:
linux-3.18.5/include/linux/skbuff.h:
#if (65536/PAGE_SIZE + 1) < 16
#define MAX_SKB_FRAGS 16UL
#else
#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 1)
#endif
linux-4.1/include/linux/skbuff.h:
#if (65536/PAGE_SIZE + 1) < 45
#define MAX_SKB_FRAGS 45UL
#else
#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 1)
#endif
Note the difference.
I haven't analyzed this code, but from a very first look I see some inconsistency there.
Replacing 45 back to 16 should do the trick. Of course, there might be a reason why the patch author picked a higher value.

undefined reference to__aeabi_ldivmod when building kernel for arm32

When building one kernel image for arm32 platform, in the final linking, the error is:
arm-eabi-ld -EL -p --no-undefined -X --build-id -o .tmp_vmlinux1 -T obj/KERNEL/arch/arm/kernel/vmlinux.lds arch/arm/kernel/head.o init/built-in.o --start-group usr/built-in.o arch/arm/vfp/built-in.o arch/arm/kernel/built-in.o arch/arm/mm/built-in.o arch/arm/common/built-in.o arch/arm/net/built-in.o arch/arm/crypto/built-in.o arch/arm/mach-sc/built-in.o kernel/built-in.o mm/built-in.o fs/built-in.o ipc/built-in.o security/built-in.o crypto/built-in.o block/built-in.o arch/arm/lib/lib.a lib/lib.a arch/arm/lib/built-in.o lib/built-in.o drivers/built-in.o sound/built-in.o firmware/built-in.o arch/arm/oprofile/built-in.o net/built-in.o --end-group
drivers/built-in.o:
undefined reference to `__aeabi_ldivmod'
make[2]: *** [vmlinux] Error 1
I know the reason is my using 64bit divison for arm32 which 64bit is not supported, and using do_div() can get rid of the __aeabi_ldivmod error. I know __aeabi_ldivmod is defined in the libgcc.a, so I added the following code in my Kernel Makefile:
--- a/Makefile
+++ b/Makefile
## -677,6 +677,7 ##
LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
$(call cc-ldoption, -Wl$(comma)--build-id,))
KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
+LDFLAGS_vmlinux += -L$(MY_LIBPATH) -lgcc
But it still can't work, so can anybody help on my questions:
1) Why the libgcc.a is not linked default in the kernel building?
2) How to link the libgcc.a to fix the link error?
[Update]
OK, I found the following note for -lgcc in OSDev wiki:
-lgcc
You disable the important libgcc library when you pass -nodefaultlibs (implied by -nostdlib). The compiler needs this library for many operations that it cannot do itself or that is more efficient to put into a shared function. You must pass this library near the end of the link line, after all the other object files and libraries, or the linker won't use it and you get strange linker errors.
So I hard coded -L${MYLIB_PATH} -lgcc into into scripts/link-vmlinux.sh:
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
## -55,7 +55,7 ## vmlinux_link()
if [ "${SRCARCH}" != "um" ]; then
${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \
-T ${lds} ${KBUILD_VMLINUX_INIT} \
- --start-group ${KBUILD_VMLINUX_MAIN} --end-group ${1}
+ --start-group ${KBUILD_VMLINUX_MAIN} --end-group ${1} -L${MYLIB_PATH} -lgcc
else
${CC} ${CFLAGS_vmlinux} -o ${2} \
-Wl,-T,${lds} ${KBUILD_VMLINUX_INIT} \
Then the build went without __aeabi_ldivmod error.
While I want to find the better modifying than just harding coding and to know why kernel doesn't link libgcc default.
Don't edit scripts/link-vmlinux.sh, edit only certain Makefiles. For example if you have this error:
drivers/power/reset/msm-poweroff.c:249: undefined reference to `lge_set_restart_reason'
run cscope -R inside top of linux kernel source code directory, then find global definition for lge_set_restart_reason, it finds file definition in include/soc/qcom/lge/lge_handle_panic.h
But lge_handle_panic.h has only definition of lge_set_restart_reason, you need lge_handle_panic.c, which has this function, looking like this:
void lge_set_restart_reason(unsigned int reason)
{
writel_relaxed(reason, RESTART_REASON);
if(use_hardreset) {
qpnp_pon_set_restart_reason(map_imem_reboot_to_pmic(reason));
qpnp_pon_system_pwr_off(PON_POWER_OFF_HARD_RESET);
}
}
so you need to edit drivers/power/reset/Makefile to include lge_handle_panic.o object file:
obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o lge_handle_panic.o
In custom kernels, a lot of functions is enabled by config, what I mean is:
#ifdef CONFIG_LGE_HANDLE_PANIC
static void __iomem *msm_timer0_base;
void __iomem *wdt_timer_get_timer0_base(void)
{
return msm_timer0_base;
}
static void wdt_timer_set_timer0_base(void __iomem * iomem)
{
msm_timer0_base = iomem;
}
#endif
You need enable CONFIG_LGE_HANDLE_PANIC, or any config if you have again this error, or remove "ifdef" and "endif" (I'm not recommending doing this)

Meaning of yywrap() in flex

What does this instructions mean in flex (lex) :
#define yywrap() 1
and this [ \t]+$
i find it in the code below:
(%%
[ \t]+ putchar('_');
[ \t]+%
%%
input "hello world"
output "hello_world"
)
According to The Lex & Yacc Page :
When the scanner receives an end-of-file indication from YY_INPUT, it then checks the yywrap() function. If yywrap() returns false (zero), then it is assumed that the function has gone ahead and set up yyin to point to another input file, and scanning continues. If it returns true (non-zero), then the scanner terminates, returning 0 to its caller. Note that in either case, the start condition remains unchanged; it does not revert to INITIAL.
The #define is used to simplify building the program (so that no -ll linkage option is needed).
Further reading:
What are lex and yacc?
Routines to reprocess input
6. How do Lex and YACC work internally (Lex and YACC primer/HOWTO)

When I really should call refresh function in module curses in Ruby

When I really should call refresh function manually in module Curses in Ruby? I think that it's unclear in the docs.
Thanks in advance.
The refresh method points out to the external function refresh():
static VALUE
curses_refresh(VALUE obj)
{
curses_stdscr();
refresh();
return Qnil;
}
And you can see the documentation of that refresh() method in the curs_refresh manual:
The refresh and wrefresh routines (or wnoutrefresh and doupdate) must
be called to get actual output to the terminal, as other routines mere‐
ly manipulate data structures. The routine wrefresh copies the named
window to the physical terminal screen, taking into account what is al‐
ready there to do optimizations. The refresh routine is the same, us‐
ing stdscr as the default window. Unless leaveok has been enabled, the
physical cursor of the terminal is left at the location of the cursor
for that window.
In modern Linux you can see the declaration of that function or macros in /usr/include/ncurses.h or /usr/include/curses.h. Example:
extern NCURSES_EXPORT(int) refresh (void); /* generated */
#define refresh() wrefresh(stdscr)
And this is the part of Ruby's curses.c that refers to the header files:
#if defined(HAVE_NCURSES_H)
# include <ncurses.h>
#elif defined(HAVE_NCURSES_CURSES_H)
# include <ncurses/curses.h>
#elif defined(HAVE_CURSES_COLR_CURSES_H)
# ifdef HAVE_STDARG_PROTOTYPES
# include <stdarg.h>
# else
# include <varargs.h>
# endif
# include <curses_colr/curses.h>
#else
# include <curses.h>
...
# endif
#endif

Resources