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

Expanded utility of define-c-struct #620

Merged
merged 7 commits into from
Aug 1, 2022
Merged

Expanded utility of define-c-struct #620

merged 7 commits into from
Aug 1, 2022

Conversation

patternspandemic
Copy link
Contributor

@patternspandemic patternspandemic commented May 28, 2021

Additions to resolve issues as explained in #614.

The new form of the define-c-struct macro adds two optional positional arguments:

;; . . .
;; compatible-tags => list of symbols representing additional C type declarations compatible with struct
;;    This is usually the name of a typedef alias, when it differs from the C struct tag.
;; as-typedef => set to #t when defining an anonymous typdef'd struct
;;    In this case, `struct` should be the name of the typedef alias.
(define-macro (define-c-struct struct #!optional (members '()) release-function compatible-tags as-typedef)

The procedure's interface could be made nicer with named optionals if backward compatibility is not a priority, otherwise specifying #f for release-function and compatible-tags will occur often when dealing with typedef'd structs.

Specifying a list of compatible tags allows for type compatibility when a struct is aliased by a typedef of a different name:

; For when the typedef alias name differs from the struct tag:
(c-declare "
typedef struct pnt {
  int x;
  int y;
} pnt_t;
")

; Include the compatible tag for specifying type compatibility
(define-c-struct pnt
  ((x . int) (y . int)) #f (pnt_t))

Specifying #t for as-typedef makes the macro operate on the typedef alias rather than struct type. This allows for the use of define-c-struct on typedef'd anonymous structs:

; For when the typedef aliases an anonymous struct
(c-declare "
typedef struct {
  int x;
  int y;
} pnt_t;
")

; Flag the macro to work on the alias type rather than a struct type
(define-c-struct pnt_t
  ((x . int) (y . int)) #f #f #t)

@patternspandemic patternspandemic changed the title Expanded utillty of define c struct Expanded utillty of define-c-struct May 28, 2021
@fare fare changed the title Expanded utillty of define-c-struct Expanded utility of define-c-struct Jun 3, 2021
@fare
Copy link
Collaborator

fare commented Jun 3, 2021

Looks good to me, modulo improving comments and documentation.

Copy link
Collaborator

@fare fare left a comment

Choose a reason for hiding this comment

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

Looks excellent to me!

@patternspandemic
Copy link
Contributor Author

Just have to make changes to the Guide and I'll remove draft status for review.

@patternspandemic
Copy link
Contributor Author

Nearly there.. Kind of a brain dump. Misspellings and errors likely. Going to refine the Sample.

@patternspandemic patternspandemic marked this pull request as ready for review June 13, 2021 02:48
Copy link
Collaborator

@vyzo vyzo left a comment

Choose a reason for hiding this comment

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

This is excellent, i am going to merge it.

@patternspandemic sorry for the obscene delay, it fell though the cracks.

@vyzo vyzo merged commit 1eb0573 into mighty-gerbils:master Aug 1, 2022
@patternspandemic patternspandemic deleted the define-c-struct branch August 1, 2022 22:24
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.

3 participants