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

Converting C structs issue #26

Open
jarroddavis68 opened this issue Sep 6, 2023 · 3 comments
Open

Converting C structs issue #26

jarroddavis68 opened this issue Sep 6, 2023 · 3 comments

Comments

@jarroddavis68
Copy link
Contributor

If I have a struct such as this:

typedef struct unz_file_info_s
{
    int version;              /* version made by                 2 bytes */
    int version_needed;       /* version needed to extract       2 bytes */
    int flag;                 /* general purpose bit flag        2 bytes */
    int compression_method;   /* compression method              2 bytes */
    int dosDate;              /* last mod file date in Dos fmt   4 bytes */
    int crc;                  /* crc-32                          4 bytes */
    int compressed_size;      /* compressed size                 4 bytes */
    int uncompressed_size;    /* uncompressed size               4 bytes */
    int size_filename;        /* filename length                 2 bytes */
    int size_file_extra;      /* extra field length              2 bytes */
    int size_file_comment;    /* file comment length             2 bytes */

    int disk_num_start;       /* disk number start               2 bytes */
    int internal_fa;          /* internal file attributes        2 bytes */
    int external_fa;          /* external file attributes        4 bytes */

    int tmu_date;
} unz_file_info;

when converted, it will create this and cut off the last two fields?? Do you limit the total number of fields or what is going on with this? How can I fix it?

type
  Punz_file_info_s = ^unz_file_info_s;

  unz_file_info_s = record
    version: Integer;
    version_needed: Integer;
    flag: Integer;
    compression_method: Integer;
    dosDate: Integer;
    crc: Integer;
    compressed_size: Integer;
    uncompressed_size: Integer;
    size_filename: Integer;
    size_file_extra: Integer;
    size_file_comment: Integer;
    disk_num_start: Integer;
    internal_fa: Integer;
  end;

  unz_file_info = unz_file_info_s;
@neslib
Copy link
Owner

neslib commented Sep 8, 2023

I created a simple .h file with just the struct you mentioned above. When I translate this using version 1.4.1 of Chet, I get the following output (as expected):

unit test;
{ This unit is automatically generated by Chet:
  https://github.com/neslib/Chet }

{$MINENUMSIZE 4}

interface

const
  {$IF Defined(WIN32)}
  LIB_TEST = 'Test_win32.dll';
  _PU = '';
  {$ELSE}
    {$MESSAGE Error 'Unsupported platform'}
  {$ENDIF}

type
  // Forward declarations
  Punz_file_info_s = ^unz_file_info_s;

  unz_file_info_s = record
    version: Integer;
    version_needed: Integer;
    flag: Integer;
    compression_method: Integer;
    dosDate: Integer;
    crc: Integer;
    compressed_size: Integer;
    uncompressed_size: Integer;
    size_filename: Integer;
    size_file_extra: Integer;
    size_file_comment: Integer;
    disk_num_start: Integer;
    internal_fa: Integer;
    external_fa: Integer;
    tmu_date: Integer;
  end;

  unz_file_info = unz_file_info_s;

implementation

end.

It correctly translated all the fields in the struct.
Can you create a reproducible scenario, or send me the complete project?

@jarroddavis68
Copy link
Contributor Author

jarroddavis68 commented Sep 8, 2023

Ahh, I think I see what is going on. It would seem the post processing script command CreateDynamicImport(0) is causing the issue. I will look into this. Sorry for the confusion. In my project I had it defined.

@jarroddavis68
Copy link
Contributor Author

Ok, I've identified the source of the problem, until I can issue a PR, if you are using post processing, just replace:
RemoveAllLines('external', 2); with RemoveAllLines('external ', 2); in function TScriptStringList.CreateDynamicImport(aType: Integer): Boolean;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants