Giter Club home page Giter Club logo

Comments (4)

starwing avatar starwing commented on August 29, 2024

(btw, I found another warning when use yyjson_inline_api as yyjson_api:

yyjson.c|6296 col 37| warning: pointer 'val_hdr' may be used after 'realloc' [-Wuse-after-free]
||  6296 |         val = val_tmp + (usize)(val - val_hdr); \
||       |                                     ^
yyjson.c|6358 col 5| note: in expansion of macro 'val_incr'
||  6358 |     val_incr();
||       |     ^~~~~~~~
|| In function 'default_realloc',

)

from yyjson.

ibireme avatar ibireme commented on August 29, 2024

The first warning happens because the definition of yyjson_api is changed.

The original code is like this, and it's fine:

extern void foo(void);
static inline void bar(void) {
    foo();
}

But when you #define yyjson_api static, it changes extern to static, causing a warning:

static void foo(void);
static inline void bar(void) {
    foo();
}

The second warning comes from including yyjson.c directly.

In yyjson.c, alc.realloc() is used to call realloc indirectly through a function pointer. Normally, yyjson.c is compiled separately, so there's no warning.

But if you compile yyjson.c with your code in one unit and don't use a custom allocator, GCC will perform constant propagation and inline alc.realloc() to libc's realloc(), which causes the warning.


Could you share more about why you're using the library this way?

from yyjson.

starwing avatar starwing commented on August 29, 2024

I'm just trying to make a single DLL module on windows for Lua, in this way unused functions are stripped from the result binary, and all routes are inlined for better performance and binary size.

The first warning also makes link failure for missing symbols.

It seems that what I needed is something like yyjson_static_api.

The binding code is here:
https://github.com/starwing/luabuild/blob/master/src/lyyjson.c

(Notice that all sources including Lua are amalgamated into one translation unit in one.c)

from yyjson.

ibireme avatar ibireme commented on August 29, 2024

Fixed.

from yyjson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.