GithubHelp home page GithubHelp logo

Comments (11)

trolldbois avatar trolldbois commented on July 1, 2024

All 3 issues are due to python version. The code is python 3.8 and later.

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

Thanks for your answer, indeed it works with python 3.8.
I did not find any information concerning this requirement, can you ideally please some info in your home page?
Thanks

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

One more question, once again related to Ubuntu distributions.
I took the basic "t.c"' example found in https://pypi.org/project/ctypeslib2/.

1- launch clang2py on Ubuntu 16.04

~$ clang2py t.c --debug

returns nothing, whereas it should return an output. Is it normal?

2- launch clang2py on Ubuntu 18.04

~$ clang2py t.c --debug

returns the following, which is not the same exact expected output. Is it normal?

# -*- coding: utf-8 -*-
#
# TARGET arch is: []
# WORD_SIZE is: 8
# POINTER_SIZE is: 8
# LONGDOUBLE_SIZE is: 16
#
import ctypes


class AsDictMixin:
    @classmethod
    def as_dict(cls, self):
        result = {}
        if not isinstance(self, AsDictMixin):
            # not a structure, assume it's already a python object
            return self
        if not hasattr(cls, "_fields_"):
            return result
        # sys.version_info >= (3, 5)
        # for (field, *_) in cls._fields_:  # noqa
        for field_tuple in cls._fields_:  # noqa
            field = field_tuple[0]
            if field.startswith('PADDING_'):
                continue
            value = getattr(self, field)
            type_ = type(value)
            if hasattr(value, "_length_") and hasattr(value, "_type_"):
                # array
                if not hasattr(type_, "as_dict"):
                    value = [v for v in value]
                else:
                    type_ = type_._type_
                    value = [type_.as_dict(v) for v in value]
            elif hasattr(value, "contents") and hasattr(value, "_type_"):
                # pointer
                try:
                    if not hasattr(type_, "as_dict"):
                        value = value.contents
                    else:
                        type_ = type_._type_
                        value = type_.as_dict(value.contents)
                except ValueError:
                    # nullptr
                    value = None
            elif isinstance(value, AsDictMixin):
                # other structure
                value = type_.as_dict(value)
            result[field] = value
        return result


class Structure(ctypes.Structure, AsDictMixin):

    def __init__(self, *args, **kwds):
        # We don't want to use positional arguments fill PADDING_* fields

        args = dict(zip(self.__class__._field_names_(), args))
        args.update(kwds)
        super(Structure, self).__init__(**args)

    @classmethod
    def _field_names_(cls):
        if hasattr(cls, '_fields_'):
            return (f[0] for f in cls._fields_ if not f[0].startswith('PADDING'))
        else:
            return ()

    @classmethod
    def get_type(cls, field):
        for f in cls._fields_:
            if f[0] == field:
                return f[1]
        return None

    @classmethod
    def bind(cls, bound_fields):
        fields = {}
        for name, type_ in cls._fields_:
            if hasattr(type_, "restype"):
                if name in bound_fields:
                    if bound_fields[name] is None:
                        fields[name] = type_()
                    else:
                        # use a closure to capture the callback from the loop scope
                        fields[name] = (
                            type_((lambda callback: lambda *args: callback(*args))(
                                bound_fields[name]))
                        )
                    del bound_fields[name]
                else:
                    # default callback implementation (does nothing)
                    try:
                        default_ = type_(0).restype().value
                    except TypeError:
                        default_ = None
                    fields[name] = type_((
                        lambda default_: lambda *args: default_)(default_))
            else:
                # not a callback function, use default initialization
                if name in bound_fields:
                    fields[name] = bound_fields[name]
                    del bound_fields[name]
                else:
                    fields[name] = type_()
        if len(bound_fields) != 0:
            raise ValueError(
                "Cannot bind the following unknown callback(s) {}.{}".format(
                    cls.__name__, bound_fields.keys()
            ))
        return cls(**fields)


class Union(ctypes.Union, AsDictMixin):
    pass





class struct_my_bitfield(Structure):
    pass

struct_my_bitfield._pack_ = 1 # source:False
struct_my_bitfield._fields_ = [
    ('a', ctypes.c_int64, 3),
    ('b', ctypes.c_int64, 4),
    ('c', ctypes.c_int64, 3),
    ('d', ctypes.c_int64, 3),
    ('f', ctypes.c_int64, 2),
    ('PADDING_0', ctypes.c_uint64, 49),
]

__all__ = \
    ['struct_my_bitfield']

Thanks.

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

1- launch clang2py on Ubuntu 16.04

~$ clang2py t.c --debug

returns nothing, whereas it should return an output. Is it normal?

I was able to have an output under Ubuntu 16.04 after installing LLVM 12 :)
I also installed LLVM 13 on Ubuntu 18.04 machine.
Hence, we have the same output on both (the "more complete one than on your doc", see above).


Now : I have DEBUG:cursorhandler:cursor.type:INVALID 'errors' leading to an empty output when parsing all files from a same directory (works with some files from here, but when adding other files I have this issue).

I think I'm not far from the solution, but do you know how could I resolve this issue?
Do you need the complete log, or all H files?

Thank you

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

After some more analysis, it appears that the following #define is making the issue happen (that leads to an empty output, as a reminder) :

void    log_print(const char * module, int options, int severity, const char * color, int output, const char * fmt, ...);
#define log_print_def(fmt, ...)     log_print(NULL, 0, DEBUG_INFO, NULL, LOG_DEF_PRINT, fmt, ##__VA_ARGS__)

For info, in debug logs:

DEBUG:clangparser:/usr/include/dt-sdk/lib_logs.h:158: Found a MACRO_DEFINITION|log_print_def|log_print_def
DEBUG:handler:get_unique_name: name "log_print_def"
DEBUG:utils:MACRO_DEFINITION: displayname:'log_print_def'
DEBUG:handler:get_unique_name: name "log_print_def"
DEBUG:handler:get_unique_name: name "log_print_def"
DEBUG:utils:_literal_handling: displayname:'log_print_def'
DEBUG:cursorhandler:literal has 23 tokens.[ log_print_def ( fmt , ... ) log_print ( NULL , 0 , DEBUG_INFO , NULL , LOG_DEF_PRINT , fmt , ## __VA_ARGS__ ) ]
DEBUG:cursorhandler:cursor.type:INVALID
DEBUG:cursorhandler:token:log_print_def tk.kd: IDENTIFIER tk.cursor.kd:MACRO_DEFINITION cursor.kd:MACRO_DEFINITION

Do you know why this happen?
Thanks again, and I apologize for my previous messages.

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

@trolldbois hello, any idea for this issue with this variadic arguments function ?

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

Hi, still anybody has a clue to avoid this issue?

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

Hello, I would like to know if maintenance is still ongoing on this library, because I still have the issue with #define based on a variadic function? Thanks

from ctypeslib.

trolldbois avatar trolldbois commented on July 1, 2024

@FloSim82 Would you be able to open an issue, just for that, with a simple poc and the specific versions of python, clang and python clang package you are using ?
Does not seem to be a problem in my tests.

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

Thanks for your answer.
For the moment, after cleaning the libs and resintalling from scratch, I don't have any error anymore.
If encountering again the variadic macro issue, I'll report a new bug.

from ctypeslib.

FloSim82 avatar FloSim82 commented on July 1, 2024

Issue #106 has bee n reported for the latest issue, thanks again

from ctypeslib.

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.