Skip to content

Commit

Permalink
Remove Python 2 support and simplify
Browse files Browse the repository at this point in the history
It's time to stop pretending this is anymore compatible to version 2
by using macros to hide the fact that on 3 objects are bytes and not
string.

Removing the support for version 2 makes things clearer.

Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou authored and ingydotnet committed Sep 23, 2021
1 parent fecae10 commit a31a4fb
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 255 deletions.
17 changes: 1 addition & 16 deletions yaml/_yaml.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@

#include <yaml.h>

#if PY_MAJOR_VERSION < 3

#define PyUnicode_FromString(s) PyUnicode_DecodeUTF8((s), strlen(s), "strict")

#else

// really puzzling, but, not being a string is required
#undef PyString_CheckExact
#define PyString_CheckExact PyBytes_CheckExact
#define PyString_AS_STRING PyBytes_AS_STRING
#define PyString_GET_SIZE PyBytes_GET_SIZE
#define PyString_FromStringAndSize PyBytes_FromStringAndSize

#endif

#define PyUnicode_FromYamlString(s) PyUnicode_FromString((const char *)(void *)(s))
#define PyString_AS_Yaml_STRING(s) ((yaml_char_t *)PyString_AS_STRING(s))
#define PyBytes_AS_Yaml_STRING(s) ((yaml_char_t *)PyBytes_AS_STRING(s))

#ifdef _MSC_VER /* MS Visual C++ 6.0 */
#if _MSC_VER == 1200
Expand Down
8 changes: 5 additions & 3 deletions yaml/_yaml.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ cdef extern from "_yaml.h":
int PyString_CheckExact(object o)
int PyUnicode_CheckExact(object o)
char *PyString_AS_STRING(object o)
int PyString_GET_SIZE(object o)
object PyString_FromStringAndSize(char *v, int l)
object PyUnicode_FromString(char *u)
object PyUnicode_DecodeUTF8(char *u, int s, char *e)
object PyUnicode_AsUTF8String(object o)
Expand All @@ -17,7 +15,11 @@ cdef extern from "_yaml.h":
ctypedef unsigned char yaml_char_t

object PyUnicode_FromYamlString(void *u)
yaml_char_t *PyString_AS_Yaml_STRING(object o)
yaml_char_t *PyBytes_AS_Yaml_STRING(object o)
const char *PyBytes_AS_STRING(object o)
int PyBytes_CheckExact(object o)
int PyBytes_GET_SIZE(object o)
object PyBytes_FromStringAndSize(char *v, int l)

ctypedef enum:
SIZEOF_VOID_P
Expand Down
Loading

0 comments on commit a31a4fb

Please sign in to comment.