Skip to content

Commit

Permalink
Fix warning errors of the libyaml binding
Browse files Browse the repository at this point in the history
Make the build work without any warnings.
The cython and C yaml types were differing in definition and that's
no good.

Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou authored and ingydotnet committed Sep 23, 2021
1 parent b3d2d67 commit 82db283
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 63 deletions.
5 changes: 5 additions & 0 deletions yaml/_yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

#else

#ifndef PyString_CheckExact
#define PyString_CheckExact PyBytes_CheckExact
#endif
#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))

#ifdef _MSC_VER /* MS Visual C++ 6.0 */
#if _MSC_VER == 1200

Expand Down
25 changes: 15 additions & 10 deletions yaml/_yaml.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cdef extern from "_yaml.h":

void malloc(int l)
void memcpy(char *d, char *s, int l)
void memcpy(void *d, void *s, int l)

This comment has been minimized.

Copy link
@MatzeB

MatzeB Aug 15, 2022

FWIW: the C99 standard says:

  • 7.20.3.3: ... void *malloc(size_t size); ...
  • 7.21.6.3: ... size_t strlen(const char *s); ...
  • 7.21.1.1: ... void *memcpy(void * restrict s1, const void * restrict s2, size_t n); ...

Regardless, can't you just do from libc.string cimport memcpy etc. and use the definitions shipping with Cython (see https://github.com/cython/cython/tree/master/Cython/Includes/libc) instead of defining your own versions here?

int strlen(char *s)
int PyString_CheckExact(object o)
int PyUnicode_CheckExact(object o)
Expand All @@ -14,6 +14,11 @@ cdef extern from "_yaml.h":
object PyUnicode_AsUTF8String(object o)
int PY_MAJOR_VERSION

ctypedef unsigned char yaml_char_t

object PyUnicode_FromYamlString(void *u)
yaml_char_t *PyString_AS_Yaml_STRING(object o)

ctypedef enum:
SIZEOF_VOID_P
ctypedef enum yaml_encoding_t:
Expand Down Expand Up @@ -85,10 +90,10 @@ cdef extern from "_yaml.h":
YAML_MAPPING_START_EVENT
YAML_MAPPING_END_EVENT

ctypedef int yaml_read_handler_t(void *data, char *buffer,
ctypedef int yaml_read_handler_t(void *data, unsigned char *buffer,
size_t size, size_t *size_read) except 0

ctypedef int yaml_write_handler_t(void *data, char *buffer,
ctypedef int yaml_write_handler_t(void *data, unsigned char *buffer,
size_t size) except 0

ctypedef struct yaml_mark_t:
Expand All @@ -99,8 +104,8 @@ cdef extern from "_yaml.h":
int major
int minor
ctypedef struct yaml_tag_directive_t:
char *handle
char *prefix
yaml_char_t *handle
yaml_char_t *prefix

ctypedef struct _yaml_token_stream_start_data_t:
yaml_encoding_t encoding
Expand Down Expand Up @@ -208,23 +213,23 @@ cdef extern from "_yaml.h":
int implicit)
int yaml_document_end_event_initialize(yaml_event_t *event,
int implicit)
int yaml_alias_event_initialize(yaml_event_t *event, char *anchor)
int yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor)
int yaml_scalar_event_initialize(yaml_event_t *event,
char *anchor, char *tag, char *value, size_t length,
yaml_char_t *anchor, yaml_char_t *tag, yaml_char_t *value, int length,
int plain_implicit, int quoted_implicit,
yaml_scalar_style_t style)
int yaml_sequence_start_event_initialize(yaml_event_t *event,
char *anchor, char *tag, int implicit, yaml_sequence_style_t style)
yaml_char_t *anchor, yaml_char_t *tag, int implicit, yaml_sequence_style_t style)
int yaml_sequence_end_event_initialize(yaml_event_t *event)
int yaml_mapping_start_event_initialize(yaml_event_t *event,
char *anchor, char *tag, int implicit, yaml_mapping_style_t style)
yaml_char_t *anchor, yaml_char_t *tag, int implicit, yaml_mapping_style_t style)
int yaml_mapping_end_event_initialize(yaml_event_t *event)
void yaml_event_delete(yaml_event_t *event)

int yaml_parser_initialize(yaml_parser_t *parser)
void yaml_parser_delete(yaml_parser_t *parser)
void yaml_parser_set_input_string(yaml_parser_t *parser,
char *input, size_t size)
const unsigned char *input, size_t size)
void yaml_parser_set_input(yaml_parser_t *parser,
yaml_read_handler_t *handler, void *data)
void yaml_parser_set_encoding(yaml_parser_t *parser,
Expand Down
Loading

0 comments on commit 82db283

Please sign in to comment.