makesdna: Give suggestions for fix #110145

Closed
Ray molenkamp wants to merge 1 commits from LazyDodo/blender:tmp_makesdna into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

Give feedback on how many padding bytes are required and where to put
them.


Heads up : The code change is really irrelevant

It's a one liner, it's uncontroversial, it have comfortably landed
without going though the review process. The patch description isn't
very relevant to the problem it fixes but more of a general critique
on the overall state of makesdna. target audience : The Core Module

Background motivation

Someone on chat asked for help , and makesdna was being "unhelpful"
in my opion towards this dev, offering no useful suggestions how to
resolve their problem.

Repro

put an int oh_no_i_broke_things; just before the coba_weight field
in the UesrDef struct and you'll be met with the following "helpful"
information.

Generating dna.c, dna_type_offsets.h, dna_verify.c
CUSTOMBUILD : Align struct error : UserDef coba_weight
CUSTOMBUILD : Align struct error : UserDef walk_navigation
CUSTOMBUILD : Align struct error : UserDef space_data
CUSTOMBUILD : Align struct error : UserDef file_space_data
CUSTOMBUILD : Align struct error : UserDef experimental
CUSTOMBUILD : Align struct error : UserDef runtime
Sizeerror in 32 bit struct: UserDef (add 4 bytes)
Sizeerror in 64 bit struct: UserDef (add 4 bytes)

The check in question

    /* struct alignment */
    if (type >= firststruct) {
      if (sizeof(void *) == 8 && (size_native % 8)) {
        fprintf(stderr, "Align struct error: %s %s\n", types[structtype], cp);
        dna_error = 1;
      }
    }

Oh so little code, so many problems (and this patch will attempt to
fix just one of them, its only goals is to provide a helpful message
to the developer having issues, but feels like makesdna could use some
love)

  • No attempt is made to offer a solution, while one is clearly known,
    kinda mean...

  • Makesdna is generally architecture agnostic, checks are being done
    for both 64 bit and 32 bit. This one is protected by a
    sizeof(void *) == 8 check. Which is a little fishy

  • If you do not know this code very well, (size_native % 8) feels
    like this is about the size of the struct in question. You'd be wrong
    though size_native is the offset in the parent structure where it
    is used. A bit counter intuitive, so even if a dev goes "I don't know
    what this means" and goes to lookup the error in makesdna, they are
    likely to be mislead, kinda mean...

  • And then there's the alignment check itself which isn't inline with
    what is actually required. The only reason this check works, it checks
    for the worst case scenario (8), the actual alignment requirements are
    "The largest native size in any of the sub structures" ie if an
    embedded struct only has int16_t 's in it, there is no need to align
    this to 8 bytes, 2 would have done just fine. We're being kinda
    wasteful here.

Final score for 4 lines of code :

2x kinda mean
1x kinda fishy
1x kinda wasteful

We should be able to do better than this, no?

Future ?

makesdna is old code, we don't like touching it, and it's starting
to show its age a little bit, it's not very maintainable by
anyone except a few core devs that babysat it all its life. If
we have a list of work we know needs to be done, but that no-one
is going to volunteer for a rewrite of makesdna will be our shining
beacon on top of that list.

Give feedback on how many padding bytes are required and where to put them. ---- ## Heads up : The code change is really irrelevant It's a one liner, it's uncontroversial, it have comfortably landed without going though the review process. The patch description isn't very relevant to the problem it fixes but more of a general critique on the overall state of makesdna. target audience : The Core Module ## Background motivation Someone on chat asked for help , and makesdna was being "unhelpful" in my opion towards this dev, offering no useful suggestions how to resolve their problem. ## Repro put an `int oh_no_i_broke_things;` just before the `coba_weight` field in the `UesrDef` struct and you'll be met with the following "helpful" information. ``` Generating dna.c, dna_type_offsets.h, dna_verify.c CUSTOMBUILD : Align struct error : UserDef coba_weight CUSTOMBUILD : Align struct error : UserDef walk_navigation CUSTOMBUILD : Align struct error : UserDef space_data CUSTOMBUILD : Align struct error : UserDef file_space_data CUSTOMBUILD : Align struct error : UserDef experimental CUSTOMBUILD : Align struct error : UserDef runtime Sizeerror in 32 bit struct: UserDef (add 4 bytes) Sizeerror in 64 bit struct: UserDef (add 4 bytes) ``` ## The check in question ``` /* struct alignment */ if (type >= firststruct) { if (sizeof(void *) == 8 && (size_native % 8)) { fprintf(stderr, "Align struct error: %s %s\n", types[structtype], cp); dna_error = 1; } } ``` Oh so little code, so many problems (and this patch will attempt to fix just one of them, its only goals is to provide a helpful message to the developer having issues, but feels like makesdna could use some love) - No attempt is made to offer a solution, while one is clearly known, kinda mean... - Makesdna is generally architecture agnostic, checks are being done for both 64 bit and 32 bit. This one is protected by a `sizeof(void *) == 8` check. Which is a little fishy - If you do not know this code very well, `(size_native % 8)` feels like this is about the size of the struct in question. You'd be wrong though `size_native` is the offset in the parent structure where it is used. A bit counter intuitive, so even if a dev goes "I don't know what this means" and goes to lookup the error in makesdna, they are likely to be mislead, kinda mean... - And then there's the alignment check itself which isn't inline with what is actually required. The only reason this check works, it checks for the worst case scenario (8), the actual alignment requirements are "The largest native size in any of the sub structures" ie if an embedded struct only has `int16_t` 's in it, there is no need to align this to 8 bytes, 2 would have done just fine. We're being kinda wasteful here. Final score for 4 lines of code : 2x kinda mean 1x kinda fishy 1x kinda wasteful We should be able to do better than this, no? ## Future ? makesdna is old code, we don't like touching it, and it's starting to show its age a little bit, it's not very maintainable by anyone except a few core devs that babysat it all its life. If we have a list of work we know needs to be done, but that no-one is going to volunteer for a rewrite of makesdna will be our shining beacon on top of that list.
Ray molenkamp added 1 commit 2023-07-15 20:10:17 +02:00
84ad33425d makesdna: Give suggestions for fix
Give feedback on how many padding bytes are required and where to put
them.

----
## Heads up : The code change is really irrelevant

It's a one liner, it's uncontroversial, it have comfortably landed
without going though the review process. The patch description isn't
very relevant to the problem it fixes but more of a general critique
on the overall state of makesdna. target audience : The Core Module

## Background motivation

Someone on chat asked for help , and makesdna was being "unhelpful"
in my opion towards this dev, offering no useful suggestions how to
resolve their problem.

## Repro

put an `int oh_no_i_broke_things;` just before the `coba_weight` field
in the `UesrDef` struct and you'll be met with the following "helpful"
information.

```
Generating dna.c, dna_type_offsets.h, dna_verify.c
CUSTOMBUILD : Align struct error : UserDef coba_weight
CUSTOMBUILD : Align struct error : UserDef walk_navigation
CUSTOMBUILD : Align struct error : UserDef space_data
CUSTOMBUILD : Align struct error : UserDef file_space_data
CUSTOMBUILD : Align struct error : UserDef experimental
CUSTOMBUILD : Align struct error : UserDef runtime
Sizeerror in 32 bit struct: UserDef (add 4 bytes)
Sizeerror in 64 bit struct: UserDef (add 4 bytes)
```

## The check in question

```
    /* struct alignment */
    if (type >= firststruct) {
      if (sizeof(void *) == 8 && (size_native % 8)) {
        fprintf(stderr, "Align struct error: %s %s\n", types[structtype], cp);
        dna_error = 1;
      }
    }
```
Oh so little code, so many problems (and this patch will attempt to
fix just one of them, its only goals is to provide a helpful message
to the developer having issues, but feels like makesdna could use some
love)

- No attempt is made to offer a solution, while one is clearly known,
kinda mean...

- Makesdna is generally architecture agnostic, checks are being done
for both 64 bit and 32 bit. This one is protected by a
`sizeof(void *) == 8` check. Which is a little fishy

- If you do not know this code very well, `(size_native % 8)` feels
like this is about the size of the struct in question. You'd be wrong
though `size_native` is the offset in the parent structure where it
is used. A bit counter intuitive, so even if a dev goes "I don't know
what this means" and goes to lookup the error in makesdna, they are
likely to be mislead, kinda mean...

- And then there's the alignment check itself which isn't inline with
what is actually required. The only reason this check works, it checks
for the worst case scenario (8), the actual alignment requirements are
"The largest native size in any of the sub structures" ie if an
embedded struct only has `int16_t` 's in it, there is no need to align
this to 8 bytes, 2 would have done just fine. We're being kinda
wasteful here.

Final score for 4 lines of code :

2x kinda mean
1x kinda fishy
1x kinda wasteful

We should be able to do better than this, no?

## Future ?

makesdna is old code, we don't like touching it, and it's starting
to show its age a little bit, it's not very maintainable by
anyone except a few core devs that babysat it all its life. If
we have a list of work we know needs to be done, but that no-one
is going to volunteer for a rewrite of makesdna will be our shining
beacon on top of that list.
Ray molenkamp requested review from Campbell Barton 2023-07-15 20:10:49 +02:00
Ray molenkamp requested review from Sergey Sharybin 2023-07-15 20:11:02 +02:00
Sergey Sharybin approved these changes 2023-07-17 09:56:26 +02:00

Interesting how we both sought to fix this at pretty much the same time. My PR is in #110291 and landed, but I agree that this PR is doing the better thing -- it's clearer for the developer who reads the message what to do about it.

Interesting how we both sought to fix this at pretty much the same time. My PR is in #110291 and landed, but I agree that this PR is doing the better thing -- it's clearer for the developer who reads the message what to do about it.
Ray molenkamp closed this pull request 2023-07-25 16:26:11 +02:00

Pull request closed

Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#110145
No description provided.