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

BUG: Fix test_from_object_array_unicode (test_defchararray.TestBasic)… #7562

Merged
merged 1 commit into from
May 6, 2016

Conversation

tadeu
Copy link

@tadeu tadeu commented Apr 19, 2016

… on Windows debug

"isspace" crashes with an assert on debug when the character is not ASCII, in Windows

@charris
Copy link
Member

charris commented Apr 19, 2016

This isn't actually a TST, that prefix is for official tests in tests directories.

/* defined(_WIN32) below is because MSVC "isspace" crashes with an assert on
debug when the character is not ASCII
*/
#if defined(isspace) || defined(_WIN32)
#undef isspace
#define isspace(c) ((c==' ')||(c=='\t')||(c=='\n')||(c=='\r')||(c=='\v')||(c=='\f'))
Copy link
Member

Choose a reason for hiding this comment

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

Lines < 80 characters.

Copy link
Author

Choose a reason for hiding this comment

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

Lines < 80 characters.

The largest line in the patch have 76 chars.
Or do you mean this line

#define isspace(c) ((c==' ')||(c=='\t')||(c=='\n')||(c=='\r')||(c=='\v')||(c=='\f'))

which was already there?

Copy link
Member

Choose a reason for hiding this comment

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

Yep, might as well fix it.

@tadeu
Copy link
Author

tadeu commented Apr 19, 2016

This isn't actually a TST, that prefix is for official tests in tests directories.

Sorry, I've seem some TST commits with fixes for broken tests and assumed this would be too. What would be the correct prefix here?

@charris
Copy link
Member

charris commented Apr 19, 2016

That would be a simple BUG.

@tadeu tadeu force-pushed the fix-is-space-unicode-windows branch from 07cb18c to 2783fc6 Compare April 19, 2016 19:59
@tadeu tadeu changed the title TST: Fix test_from_object_array_unicode (test_defchararray.TestBasic)… BUG: Fix test_from_object_array_unicode (test_defchararray.TestBasic)… Apr 19, 2016
@tadeu
Copy link
Author

tadeu commented Apr 19, 2016

That would be a simple BUG.

Ok, I've updated it.

@charris
Copy link
Member

charris commented Apr 19, 2016

Hmm, there is a NumPyOS_ascii_isspace in numpyos.{c,h} that does the same thing. I wonder if we should be using that? There are several other uses of isspace that should perhaps be changed.

EDIT: Seems tne standard isspace is locale dependent, but we override is here to be standard C locale.

EDIT2: But isspace is also used for ucs4, which pretty much requires a macro.

@charris
Copy link
Member

charris commented Apr 19, 2016

I'm wondering if we should make the macro definition unconditional? The other option is to use NumPyOS_ascii_isspace but change its signature to take an int instead of char.

@tadeu
Copy link
Author

tadeu commented Apr 20, 2016

Ok, so what do you suggest? Something like this?

NPY_NO_EXPORT int
-NumPyOS_ascii_isspace(char c)
+NumPyOS_ascii_isspace(int c)
{
    return c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t'
                    || c == '\v';
}
-#define isspace(c)  ((c==' ')||(c=='\t')||(c=='\n')||(c=='\r')||(c=='\v')||(c=='\f'))
+#define isspace(c)  NumPyOS_ascii_isspace(c)

Edit: now that I saw your edit. Yes, if it must support ucs4, it better continue as a macro, right? So what should I do, only break down the long line?

@charris
Copy link
Member

charris commented Apr 20, 2016

I think the change to int for the argument takes care of ucs4, I don't think we run on any platforms where int isn't at least four bytes, so type promotion should be automatic. There are only a few uses of isspace in the file, just the two routines, so I'd get rid of the define and use the function directly. The ascii spaces are required for ucs4 in any case.

@charris
Copy link
Member

charris commented Apr 20, 2016

Maybe want to use a cast to int for the (unsigned) ucs4. My machine has 64 bit ints, so no problem, but might be needed for machines with 32 bit ints.

@tadeu
Copy link
Author

tadeu commented Apr 20, 2016

Should I change the other NumPyOS_ascii_* functions too? (e.g., NumPyOS_ascii_isalpha, NumPyOS_ascii_isdigit, etc.)

@tadeu tadeu force-pushed the fix-is-space-unicode-windows branch from 2783fc6 to 8930da7 Compare April 20, 2016 16:26
@tadeu
Copy link
Author

tadeu commented Apr 20, 2016

I've updated the commit

@tadeu tadeu force-pushed the fix-is-space-unicode-windows branch from 8930da7 to c0a41ad Compare April 20, 2016 16:28
@tadeu tadeu force-pushed the fix-is-space-unicode-windows branch from c0a41ad to 2f9a13a Compare April 20, 2016 16:38
@charris
Copy link
Member

charris commented Apr 21, 2016

Isn't numpyos.c being linked into multiarray?

What happened to this comment?

@tadeu
Copy link
Author

tadeu commented Apr 21, 2016

Isn't numpyos.c being linked into multiarray?

What happened to this comment?

Sorry, I deleted it, it was a mistake I made and quickly corrected (was
calling the wrong function) :)

@charris charris merged commit a0a144e into numpy:master May 6, 2016
@charris
Copy link
Member

charris commented May 6, 2016

OK, let's give this a shot. I think it should be harmless (knock, knock). I'm not sure where all the other problems with the debug version come from. There is a special Python2.7 msvc compiler, Microsoft Visual C++ Compiler for Python 2.7 , that should be compatible with Python 2.7. I don't know if that makes a difference. Note also that all python extensions need to be compiled with the same compiler. MSVC 2010 is much later than the official 2.7 compiler, vs2008.

@charris
Copy link
Member

charris commented May 6, 2016

Thanks @tadeu .

@tadeu
Copy link
Author

tadeu commented May 6, 2016

Thanks @charris !
Yes, unfortunately, I'm currently stuck using a version compiled with MSVC 2010 (and this means all other extensions too), because I'm interacting with other C++ code that depends on this compiler.
But if the other debug problems persist, I'll try to see if I can reproduce them with the vs2008 standard version.

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.

None yet

2 participants