Skip to content

Duplicate PyObject typedef generated from CPython 3.11 headers #3689

Open

Description

@dzylikecode

Using CPython 3.11's Python.h as the entry point causes ffigen to generate
two equivalent Dart typedefs:

typedef PyObject = _object;
typedef PyObject$1 = _object;

Environment

ffigen 22.0.0
Dart SDK 3.13.4 (stable), linux_x64
CPython 3.11.16
Clang 14.0.0
Ubuntu 22.04 x86_64

Reproduction

import 'dart:io';

import 'package:ffigen/ffigen.dart';

Future<void> main() {
  final pythonRoot = Directory('/path/to/Python-3.11.16').uri;

  return FfiGenerator(
    output: Output(
      dart: DartOutput(path: Uri.file('bindings.g.dart')),
      style: const DynamicLibraryBindings(),
    ),
    input: Input(
      entryPoints: [pythonRoot.resolve('Include/Python.h')],
      include: (_) => true,
      compilerOptions: [
        '-I',
        pythonRoot.resolve('Include/').toFilePath(),
        '-I',
        pythonRoot.toFilePath(),
        '-include',
        'sys/time.h',
      ],
    ),
    visitors: [
      Visitor(
        typealias: (node) {
          node.isIncluded =
              node.name == 'PyObject' ? .always : .never;
        },
      ),
    ],
  ).generate();
}

The CPython source directory needs a generated pyconfig.h, for example from
running ./configure on Linux.

Actual result

typedef PyObject = _object;
typedef PyObject$1 = _object;

final class _object extends ffi.Opaque {}

Expected result

typedef PyObject = _object;

final class _object extends ffi.Opaque {}

Diagnostic

Printing matching nodes in the typealias visitor shows the same Clang USR
twice:

c:pytypedefs.h@T@PyObject PyObject
c:pytypedefs.h@T@PyObject PyObject

Activity

  1. removed
    needs-triageNeeds triage from the team. Remove this label once triaged.
    on Oct 7, 2026
  2. liamappelbe commented on Oct 7, 2026

    @liamappelbe
    Contributor

    Once I've done a proper audit and clean up of USRs, we should just dedupe everything by USR. #3485

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions