From 13f574a3808f92c0f2724d0472d7e164b565b626 Mon Sep 17 00:00:00 2001 From: Dag Sverre Seljebotn Date: Wed, 10 Mar 2010 09:07:07 +0100 Subject: [PATCH] Move C standard library pxd files to libc package --HG-- rename : Cython/Includes/stdio.pxd => Cython/Includes/libc/stdio.pxd rename : Cython/Includes/stdlib.pxd => Cython/Includes/libc/stdlib.pxd --- Cython/Includes/libc/__init__.pyx | 1 + Cython/Includes/libc/stdio.pxd | 9 +++++++++ Cython/Includes/libc/stdlib.pxd | 7 +++++++ Cython/Includes/stdio.pxd | 11 ++--------- Cython/Includes/stdlib.pxd | 9 ++------- tests/run/libc_stdlib.pyx | 11 +++++++++++ 6 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 Cython/Includes/libc/__init__.pyx create mode 100644 Cython/Includes/libc/stdio.pxd create mode 100644 Cython/Includes/libc/stdlib.pxd create mode 100644 tests/run/libc_stdlib.pyx diff --git a/Cython/Includes/libc/__init__.pyx b/Cython/Includes/libc/__init__.pyx new file mode 100644 index 00000000..fa81adaf --- /dev/null +++ b/Cython/Includes/libc/__init__.pyx @@ -0,0 +1 @@ +# empty file diff --git a/Cython/Includes/libc/stdio.pxd b/Cython/Includes/libc/stdio.pxd new file mode 100644 index 00000000..cc574105 --- /dev/null +++ b/Cython/Includes/libc/stdio.pxd @@ -0,0 +1,9 @@ +cdef extern from "stdio.h" nogil: + ctypedef struct FILE + int printf(char *format, ...) + int fprintf(FILE *stream, char *format, ...) + int sprintf(char *str, char *format, ...) + FILE *fopen(char *path, char *mode) + int fclose(FILE *strea) + cdef FILE *stdout + int scanf(char *format, ...) diff --git a/Cython/Includes/libc/stdlib.pxd b/Cython/Includes/libc/stdlib.pxd new file mode 100644 index 00000000..40192d13 --- /dev/null +++ b/Cython/Includes/libc/stdlib.pxd @@ -0,0 +1,7 @@ + +cdef extern from "stdlib.h" nogil: + void free(void *ptr) + void *malloc(size_t size) + void *realloc(void *ptr, size_t size) + size_t strlen(char *s) + char *strcpy(char *dest, char *src) diff --git a/Cython/Includes/stdio.pxd b/Cython/Includes/stdio.pxd index cc574105..f4af328d 100644 --- a/Cython/Includes/stdio.pxd +++ b/Cython/Includes/stdio.pxd @@ -1,9 +1,2 @@ -cdef extern from "stdio.h" nogil: - ctypedef struct FILE - int printf(char *format, ...) - int fprintf(FILE *stream, char *format, ...) - int sprintf(char *str, char *format, ...) - FILE *fopen(char *path, char *mode) - int fclose(FILE *strea) - cdef FILE *stdout - int scanf(char *format, ...) +# Present for backwards compatability +from libc.stdio cimport * diff --git a/Cython/Includes/stdlib.pxd b/Cython/Includes/stdlib.pxd index 40192d13..0d2ce8eb 100644 --- a/Cython/Includes/stdlib.pxd +++ b/Cython/Includes/stdlib.pxd @@ -1,7 +1,2 @@ - -cdef extern from "stdlib.h" nogil: - void free(void *ptr) - void *malloc(size_t size) - void *realloc(void *ptr, size_t size) - size_t strlen(char *s) - char *strcpy(char *dest, char *src) +# Present for backwards compatability +from libc.stdlib cimport * diff --git a/tests/run/libc_stdlib.pyx b/tests/run/libc_stdlib.pyx new file mode 100644 index 00000000..ee88ac85 --- /dev/null +++ b/tests/run/libc_stdlib.pyx @@ -0,0 +1,11 @@ +""" +>>> f() +'hello' +""" + +from libc.stdio cimport sprintf + +def f(): + cdef char buf[10] + sprintf(buf, b'hello') + return str((buf).decode('ASCII')) -- 2.26.2