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

gogensig: panic: underlying type must not be nil #61

Open
tsingbx opened this issue Dec 18, 2024 · 5 comments
Open

gogensig: panic: underlying type must not be nil #61

tsingbx opened this issue Dec 18, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@tsingbx
Copy link
Contributor

tsingbx commented Dec 18, 2024

llcppgtest gnutls
llcppgtest gnutls-dane
llcppgtest libzstd
llcppgtest openssl

panic: underlying type must not be nil
@luoliwoshang luoliwoshang added the bug Something isn't working label Dec 18, 2024
@luoliwoshang luoliwoshang changed the title panic: underlying type must not be nil gogensig: panic: underlying type must not be nil Dec 20, 2024
@luoliwoshang
Copy link
Contributor

luoliwoshang commented Dec 24, 2024

gnutls

问题是来自于typdef 一个枚举类型导致的panic
但是在转换测试中,并没有引起崩溃,无论是typedef一个匿名的枚举还是具名的枚举 #81

2024/12/24 09:17:55 NewFuncDecl: &{pwritev} is a function of system header file
2024/12/24 09:17:55 SetCurFile: compat.go File in Current Package: true
2024/12/24 09:17:55 NewTypedefDecl: &{gnutls_connection_end_t}
2024/12/24 09:17:55 NewTypedefDecl: &{gnutls_cipher_algorithm}
panic: underlying type must not be nil

goroutine 1 [running]:
go/types.(*Named).SetUnderlying(0x1400816bab0, {0x0, 0x0})
	/Users/zhangzhiyang/golang/go1.20.4/src/go/types/named.go:435 +0xf4
github.com/goplus/gogen.(*TypeDecl).InitType(0x1400fc4b9a0, 0x140000ca540, {0x102c469c0?, 0x1400816bb20?}, {0x0, 0x0, 0x0})
	/Users/zhangzhiyang/go/pkg/mod/github.com/goplus/[email protected]/type_var_and_const.go:114 +0x1b0
typedef enum gnutls_cipher_algorithm {
	GNUTLS_CIPHER_UNKNOWN = 0,
	GNUTLS_CIPHER_NULL = 1,
	GNUTLS_CIPHER_ARCFOUR_128 = 2,
	GNUTLS_CIPHER_3DES_CBC = 3,
	GNUTLS_CIPHER_AES_128_CBC = 4,
	GNUTLS_CIPHER_AES_256_CBC = 5,
	GNUTLS_CIPHER_ARCFOUR_40 = 6,
} gnutls_cipher_algorithm_t;


typedef enum {
	GNUTLS_KX_UNKNOWN = 0,
	GNUTLS_KX_RSA = 1,
	GNUTLS_KX_DHE_DSS = 2,
	GNUTLS_KX_DHE_RSA = 3,
	GNUTLS_KX_ANON_DH = 4,
	GNUTLS_KX_SRP = 5,
	GNUTLS_KX_RSA_EXPORT = 6,
	GNUTLS_KX_SRP_RSA = 7,
	GNUTLS_KX_SRP_DSS = 8,
	GNUTLS_KX_PSK = 9,
	GNUTLS_KX_DHE_PSK = 10,
	GNUTLS_KX_ANON_ECDH = 11,
	GNUTLS_KX_ECDHE_RSA = 12,
	GNUTLS_KX_ECDHE_ECDSA = 13,
	GNUTLS_KX_ECDHE_PSK = 14,
	GNUTLS_KX_RSA_PSK = 15,
	GNUTLS_KX_VKO_GOST_12 = 16
} gnutls_kx_algorithm_t;

llcppg.cfg

{
	"name": "gnutls",
	"cflags": "$(pkg-config --cflags gnutls)",
	"libs": "$(pkg-config --libs gnutls)",
	"include": [
		"gnutls/gnutls.h",
		"gnutls/compat.h"
	],
	"deps": null,
	"trimPrefixes": [],
	"cplusplus": false
}

经过调查,发现是因为在gnutls/gnutls.h的底部,才引入<gnutls/compat.h>,而目前的处理逻辑是,对于一个头文件,先处理其include列表,处理结束后,才会处理本来的头文件,这就导致了gogensig 先处理gnutls/compat.h 的时候,gnutls_cipher_algorithm_t这个类型还没定义

gnutls/gnutls.h

typedef enum gnutls_cipher_algorithm {
	GNUTLS_CIPHER_UNKNOWN = 0,
	GNUTLS_CIPHER_NULL = 1,
} gnutls_cipher_algorithm_t;

#include <gnutls/compat.h>

gnutls/compat.h

typedef gnutls_cipher_algorithm_t gnutls_cipher_algorithm
	_GNUTLS_GCC_ATTR_DEPRECATED;

@luoliwoshang
Copy link
Contributor

luoliwoshang commented Jan 13, 2025

bdw-gc redeclared 的问题也是因为目前gogensig的include处理逻辑为直接根据include决定转换顺序导致的,与gnutls的原因一致https://github.com/goplus/llcppg/issues/61#issuecomment-2560509332,目前的逻辑导致先转换了 cord_pos.h ,而后再转换cord.h,这导致了cord_pos 使用类型CORD时,还并不存在这个类型。

cord_pos.h

struct CORD_pe {
    CORD pe_cord;
    size_t pe_start_pos;
};

cord.h

typedef const char * CORD;
#include "cord_pos.h"

related llcppg.cfg

{
	"name": "bdw_gc",
	"cflags": "$(pkg-config --cflags bdw-gc)",
	"libs": "$(pkg-config --libs bdw-gc)",
	"include": [
		"gc/gc_inline.h",
		"gc_cpp.h",
		"gc/gc_backptr.h",
		"gc/gc_mark.h",
		"gc.h",
		"gc/leak_detector.h",
		"gc/javaxfc.h",
		"gc/gc_cpp.h",
		"gc/gc_disclaim.h",
		"gc/gc_gcj.h",
		"gc/gc_typed.h",
		"gc/gc.h",
		"gc/ec.h",
		"gc/cord.h",
		"gc/gc_pthread_redirects.h",
		"gc/gc_tiny_fl.h",
		"gc/gc_version.h",
		"gc/gc_config_macros.h",
		"gc/gc_allocator.h",
		"gc/cord_pos.h"
	],
	"deps": null,
	"trimPrefixes": [],
	"cplusplus": false
}

@luoliwoshang
Copy link
Contributor

python-3.12-embed 相同的问题,先处理了cpython/object.h,再处理的object.h,导致使用unaryfunc类型时还不存在定义。

object.h

typedef PyObject * (*unaryfunc)(PyObject *);
include "cpython/object.h"

cpython/object.h

typedef struct {
    /* Number implementations must check *both*
       arguments for proper type and implement the necessary conversions
       in the slot functions themselves. */

    binaryfunc nb_add;
    binaryfunc nb_subtract;
    binaryfunc nb_multiply;
    binaryfunc nb_remainder;
    binaryfunc nb_divmod;
    ternaryfunc nb_power;
    unaryfunc nb_negative;
    unaryfunc nb_positive;
}

llcppg.cfg

{
	"name": "python_3_12_embed",
	"cflags": "$(pkg-config --cflags python-3.12-embed)",
	"libs": "$(pkg-config --libs python-3.12-embed)",
	"include": [
		"internal/pycore_blocks_output_buffer.h",
		"Python.h",
		"objimpl.h",
		"pymem.h",
		"frameobject.h",
		"pyport.h",
		"object.h",
		"pylifecycle.h",
		"ceval.h",
		"warnings.h",
		"tupleobject.h",
		"traceback.h",
		"sysmodule.h",
		"setobject.h",
		"pythonrun.h",
		"pystate.h",
		"descrobject.h",
		"complexobject.h",
		"dictobject.h",
		"pyframe.h",
		"pyerrors.h",
		"compile.h",
		"weakrefobject.h",
		"modsupport.h",
		"methodobject.h",
		"memoryobject.h",
		"longobject.h",
		"listobject.h",
		"interpreteridobject.h",
		"bytesobject.h",
		"internal/pycore_frame.h",
		"bytearrayobject.h",
		"import.h",
		"abstract.h",
		"floatobject.h",
		"fileutils.h",
		"fileobject.h",
		"internal/pycore_genobject.h",
		"internal/pycore_obmalloc.h",
		"internal/pycore_abstract.h",
		"internal/pycore_asdl.h",
		"internal/pycore_ast.h",
		"internal/pycore_ast_state.h",
		"internal/pycore_atexit.h",
		"internal/pycore_atomic.h",
		"internal/pycore_atomic_funcs.h",
		"internal/pycore_bitutils.h",
		"internal/pycore_bytes_methods.h",
		"internal/pycore_bytesobject.h",
		"internal/pycore_call.h",
		"internal/pycore_ceval.h",
		"internal/pycore_ceval_state.h",
		"internal/pycore_code.h",
		"internal/pycore_compile.h",
		"internal/pycore_condvar.h",
		"internal/pycore_context.h",
		"internal/pycore_descrobject.h",
		"internal/pycore_dict.h",
		"internal/pycore_dict_state.h",
		"internal/pycore_dtoa.h",
		"internal/pycore_emscripten_signal.h",
		"internal/pycore_exceptions.h",
		"internal/pycore_faulthandler.h",
		"internal/pycore_fileutils.h",
		"internal/pycore_fileutils_windows.h",
		"internal/pycore_floatobject.h",
		"internal/pycore_flowgraph.h",
		"internal/pycore_format.h",
		"internal/pycore_function.h",
		"internal/pycore_gc.h",
		"internal/pycore_getopt.h",
		"internal/pycore_gil.h",
		"internal/pycore_global_objects.h",
		"internal/pycore_global_objects_fini_generated.h",
		"internal/pycore_global_strings.h",
		"internal/pycore_hamt.h",
		"internal/pycore_hashtable.h",
		"internal/pycore_import.h",
		"internal/pycore_initconfig.h",
		"internal/pycore_instruments.h",
		"internal/pycore_interp.h",
		"internal/pycore_intrinsics.h",
		"internal/pycore_list.h",
		"internal/pycore_long.h",
		"internal/pycore_memoryobject.h",
		"internal/pycore_moduleobject.h",
		"internal/pycore_namespace.h",
		"internal/pycore_object.h",
		"internal/pycore_object_state.h",
		"internal/pycore_obmalloc_init.h",
		"internal/pycore_opcode.h",
		"internal/pycore_opcode_utils.h",
		"internal/pycore_parser.h",
		"internal/pycore_pathconfig.h",
		"internal/pycore_pyarena.h",
		"internal/pycore_pyerrors.h",
		"internal/pycore_pyhash.h",
		"internal/pycore_pylifecycle.h",
		"internal/pycore_pymath.h",
		"internal/pycore_pymem.h",
		"internal/pycore_pymem_init.h",
		"internal/pycore_pystate.h",
		"internal/pycore_pythread.h",
		"internal/pycore_range.h",
		"internal/pycore_runtime.h",
		"internal/pycore_runtime_init.h",
		"internal/pycore_runtime_init_generated.h",
		"internal/pycore_signal.h",
		"internal/pycore_sliceobject.h",
		"internal/pycore_strhex.h",
		"internal/pycore_structseq.h",
		"internal/pycore_symtable.h",
		"internal/pycore_sysmodule.h",
		"internal/pycore_time.h",
		"internal/pycore_token.h",
		"internal/pycore_traceback.h",
		"internal/pycore_tracemalloc.h",
		"internal/pycore_tuple.h",
		"internal/pycore_typeobject.h",
		"internal/pycore_typevarobject.h",
		"internal/pycore_ucnhash.h",
		"internal/pycore_unicodeobject.h",
		"internal/pycore_unicodeobject_generated.h",
		"internal/pycore_unionobject.h",
		"internal/pycore_warnings.h",
		"intrcheck.h",
		"iterobject.h",
		"marshal.h",
		"moduleobject.h",
		"opcode.h",
		"osdefs.h",
		"osmodule.h",
		"patchlevel.h",
		"py_curses.h",
		"pybuffer.h",
		"pycapsule.h",
		"pyconfig.h",
		"pydtrace.h",
		"pydtrace_probes.h",
		"pyexpat.h",
		"pyhash.h",
		"pymacconfig.h",
		"pymacro.h",
		"pymath.h",
		"pystats.h",
		"pystrcmp.h",
		"pystrtod.h",
		"pythread.h",
		"pytypedefs.h",
		"rangeobject.h",
		"sliceobject.h",
		"structmember.h",
		"structseq.h",
		"tracemalloc.h",
		"codecs.h",
		"typeslots.h",
		"unicodeobject.h",
		"boolobject.h",
		"bltinmodule.h"
	],
	"deps": null,
	"trimPrefixes": [],
	"cplusplus": false
}

@luoliwoshang
Copy link
Contributor

luoliwoshang commented Jan 13, 2025

openssl, libssl, libcrypto same question

conf.h

struct conf_st;
struct conf_method_st;
typedef struct conf_method_st CONF_METHOD;
#  include <openssl/conftypes.h>

conftype.h

struct conf_method_st {
    const char *name;
    CONF *(*create) (CONF_METHOD *meth);
    int (*init) (CONF *conf);
    int (*destroy) (CONF *conf);
    int (*destroy_data) (CONF *conf);
    int (*load_bio) (CONF *conf, BIO *bp, long *eline);
    int (*dump) (const CONF *conf, BIO *bp);
    int (*is_number) (const CONF *conf, char c);
    int (*to_int) (const CONF *conf, char c);
    int (*load) (CONF *conf, const char *name, long *eline);
};

struct conf_st {
    CONF_METHOD *meth;
    void *meth_data;
    LHASH_OF(CONF_VALUE) *data;
    int flag_dollarid;
    int flag_abspath;
    char *includedir;
    OSSL_LIB_CTX *libctx;
};

@luoliwoshang
Copy link
Contributor

llcppgtest gnutls
llcppgtest gnutls-dane
llcppgtest libzstd
llcppgtest openssl

panic: underlying type must not be nil

libbzstd 的问题已在latest llcppg 中被修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants