[Python-Dev] a few strdup() questions... (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Wed Jan 7 20:22:43 CET 2009


MS Windows CE doesn't provide strdup(), so where should I put it? I guess I should just compile in Python/strdup.c, right?

Right.

However, where should I declare it?

I recommend pyport.h.

Also, there is HAVESTRDUP. I would actually expect that #undef HAVESTRDUP would do the trick to at least declare this, but it doesn't. I guess that most modern OS have this so this will probably just be bitrot ... right?

Wrong, I think. The macro is a side effect of AC_REPLACE_FUNCS, which will a) add strdup.c to the list of files to compile, or b) define HAVE_STRDUP.

BTW: there is another implementation (called mystrdup) in Modules/ctypes/ctypestest.c, why not use the one in Python/strdup.c there?

I guess that's historical, from the times when ctypes was still a separate package.

First difference is that I wouldn't accept NULL as valid input, e.g. the glibc implementation doesn't either and GCC even warns you if you call strdup(NULL). Secondly, I would have used memcpy(), since the length is already known and then potentially quicker. Should I write a patch?

Is that really worth it? It works as-is, doesn't it?

Regards, Martin



More information about the Python-Dev mailing list