Skip to content

MAINT: Add a PyDataType_ISUNSIZED macro - #9953

Merged
charris merged 1 commit into
numpy:masterfrom
eric-wieser:add-unsized
Nov 5, 2017
Merged

charris merged 1 commit into
numpy:masterfrom
eric-wieser:add-unsized

Conversation

@eric-wieser

Copy link
Copy Markdown
Member

This allows us to change how flexible types with no length are represented in future, to allow zero-size dtypes (#8970).

Perhaps it would be better to just define PyDataType_UNSIZED as zero, rather than having PyDataType_MAKEUNSIZED existing - it implies a level of abstraction that doesn't work, namely that setting dtype->elsize clears the "unsized" flag.

This allows us to change how flexible types with no length are represented in future, to allow zero-size dtypes (numpy#8970).
#define PyDataType_ISOBJECT(obj) PyTypeNum_ISOBJECT(((PyArray_Descr*)(obj))->type_num)
#define PyDataType_HASFIELDS(obj) (((PyArray_Descr *)(obj))->names != NULL)
#define PyDataType_HASSUBARRAY(dtype) ((dtype)->subarray != NULL)
#define PyDataType_ISUNSIZED(dtype) ((dtype)->elsize == 0)

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 one of those cases where (0 == (dtype)->elsize) is a bit safer. Many years ago there was an attempt to subvert linux with a bit of trick code someone slipped into the public branch that replaced a check, something like user == 0, by user = 0. Site shutdown and a months long hunt for the attacker's pathway ensued. That said, I don't think this is worth worrying about, it just reminds me when I see it ;)

@charris

charris commented Nov 4, 2017

Copy link
Copy Markdown
Member

Looks straight forward, so the question becomes, what is the plan for the next step?

@eric-wieser

eric-wieser commented Nov 4, 2017 •

Copy link
Copy Markdown
Member Author

One idea would be to change the definition to the C equivalent of x is np.void or x is np.unicode_ or x is np.bytes_ or (iscustomdtype(x) and x.elsize == 0), which ought to be reasonably backwards compatible (more so that elsize == -1)

@charris

charris commented Nov 5, 2017

Copy link
Copy Markdown
Member

OK, let's get this in. It can't hurt and does set the stage for later mods.

@charris
charris merged commit a2bddfa into numpy:master Nov 5, 2017
@charris

charris commented Nov 5, 2017

Copy link
Copy Markdown
Member

Thanks Eric.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants