Skip to content

Avoid use of intptr_t as a common underlying type - #175

Open
jengelh wants to merge 1 commit into
libyal:mainfrom
jengelh:master
Open

jengelh wants to merge 1 commit into
libyal:mainfrom
jengelh:master

Conversation

@jengelh

@jengelh jengelh commented Nov 20, 2026

Copy link
Copy Markdown

Doing this change from intptr_t to typedef struct… immediately brings up actual coding errors where wrong parameters are passed.

References: #96

@jengelh

jengelh commented Nov 20, 2026

Copy link
Copy Markdown
Author

These were the errors after just changing the typedefs brought up the errors:

libpff_folder.c: In function 'libpff_folder_get_type':
libpff_folder.c:122:14: error: passing argument 1 of 'libpff_record_entry_get_data_as_utf8_string_size' from incompatible pointer type [-Wincompatible-pointer-types]
  122 |              folder,
      |              ^~~~~~
      |              |
      |              libpff_item_t * {aka struct libpff_internal_item *}
In file included from libpff_folder.c:44:
libpff_record_entry.h:219:29: note: expected 'libpff_record_entry_t *' {aka 'struct libpff_internal_record_entry *'} but argument is of type 'libpff_item_t *' {aka 'struct libpff_internal_item *'}
  219 |      libpff_record_entry_t *record_entry,
      |      ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
libpff_folder.c:152:22: error: passing argument 1 of 'libpff_record_entry_get_data_as_utf8_string' from incompatible pointer type [-Wincompatible-pointer-types]
  152 |                      folder,
      |                      ^~~~~~
      |                      |
      |                      libpff_item_t * {aka struct libpff_internal_item *}
libpff_record_entry.h:225:29: note: expected 'libpff_record_entry_t *' {aka 'struct libpff_internal_record_entry *'} but argument is of type 'libpff_item_t *' {aka 'struct libpff_internal_item *'}
  225 |      libpff_record_entry_t *record_entry,
      |      ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~

Comment thread include/libpff/types.h.in Outdated
typedef intptr_t libpff_name_to_id_map_entry_t;
typedef intptr_t libpff_record_entry_t;
typedef intptr_t libpff_record_set_t;
typedef struct libpff_internal_file libpff_file_t;

@joachimmetz joachimmetz Nov 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not portable unfortunately, internal structs should remain internal to the library. This way they leak into the public API

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Their insides do not leak.

$ cat 1.c
#include <libpff.h>
int main()
{
        libpff_file_t *a = NULL;
        libpff_error_t *err = NULL;
        libpff_file_initialize(&a, &err);
        a->io_handle;
}
$ gcc 1.c -Wall
1.c: In function ‘main’:
1.c:7:10: error: invalid use of incomplete typedef ‘libpff_file_t’ {aka ‘struct libpff_internal_file’}
    7 |         a->io_handle;
      |          ^~

or did you mean something different?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR we discussed this already on #96 (comment) "public structs as proxy pointers, these are not supported by every compiler"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have missed that in 2026.
Then again, also in 2026, which compiler is it that does not support this? At least so I can test...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need to dig it up when time permits, for now the code should stick with the intptr_t proxy pointers.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"No ANSI/ISO-compliant C compiler fails to support a typedef to a forward-declared (incomplete) struct (e.g., typedef struct foo foo_t;). That pattern—an opaque type—is explicitly guaranteed by every C standard since C89. https://stackoverflow.com/questions/3965279/opaque-c-structs-various-ways-to-declare-them" (googlai summary)

@joachimmetz joachimmetz Nov 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that you can argue all you want it will not change my current stance.

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 23.34%. Comparing base (d233208) to head (94d0889).

❗ There is a different number of reports uploaded between BASE (d233208) and HEAD (94d0889). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (d233208) HEAD (94d0889)
3 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #175      +/-   ##
==========================================
- Coverage   28.90%   23.34%   -5.57%     
==========================================
  Files          64       63       -1     
  Lines       21062    20948     -114     
  Branches     5075     5064      -11     
==========================================
- Hits         6088     4890    -1198     
- Misses      13022    14923    +1901     
+ Partials     1952     1135     -817     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jengelh

jengelh commented Nov 21, 2026

Copy link
Copy Markdown
Author

Since the "definition" for libpff_file_t is freely changable, I made it a struct {void*} as originally set out in #96 (comment)

@jengelh

jengelh commented Nov 21, 2026 •

Copy link
Copy Markdown
Author

I just found this in libolecf, which seems to be doing something quite similar, save for being behind an ifdef. Is there a particular reason this is conditional on -DHAVE_DEBUG_OUTPUT? [Edit: found out it's libolecf/libolecf_types.h not not include/libolecf/types.h.in]

#if defined( HAVE_DEBUG_OUTPUT ) && !defined( WINAPI )
typedef struct libolecf_file {}                 libolecf_file_t;
typedef struct libolecf_item {}                 libolecf_item_t;
typedef struct libolecf_property_section {}     libolecf_property_section_t;
typedef struct libolecf_property_set {}         libolecf_property_set_t;
typedef struct libolecf_property_value {}       libolecf_property_value_t;

#else
typedef intptr_t libolecf_file_t;
typedef intptr_t libolecf_item_t;
typedef intptr_t libolecf_property_section_t;
typedef intptr_t libolecf_property_set_t;
typedef intptr_t libolecf_property_value_t;

#endif /* defined( HAVE_DEBUG_OUTPUT ) && !defined( WINAPI ) */

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants