# HG changeset patch # User Tero Marttila # Date 1410701198 -10800 # Node ID 67f956b71bdf25604ce5002ceaeddef5b97029c9 # Parent 0260aeca943c2665d2196cee4d4d21177e321edd python/pypngtile: cleanup cython using modern cimports diff -r 0260aeca943c -r 67f956b71bdf python/pypngtile.pxd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/pypngtile.pxd Sun Sep 14 16:26:38 2014 +0300 @@ -0,0 +1,50 @@ +from libc.stdio cimport ( + FILE, +) + +cdef extern from "pngtile.h" : + struct pt_ctx : + pass + + struct pt_image : + pass + + enum pt_open_mode : + PT_OPEN_READ # 0 + PT_OPEN_UPDATE + + enum pt_cache_status : + PT_CACHE_ERROR # -1 + PT_CACHE_FRESH + PT_CACHE_NONE + PT_CACHE_STALE + PT_CACHE_INCOMPAT + + struct pt_image_info : + size_t img_width, img_height, img_bpp + int image_mtime, cache_mtime, cache_version + size_t image_bytes, cache_bytes + size_t cache_blocks + + struct pt_image_params : + int background_color[4] + + struct pt_tile_info : + size_t width, height + size_t x, y + int zoom + + ctypedef pt_image_info* const_image_info_ptr "const struct pt_image_info *" + + ## functions + int pt_image_open (pt_image **image_ptr, pt_ctx *ctx, char *png_path, int cache_mode) nogil + int pt_image_info_ "pt_image_info" (pt_image *image, pt_image_info **info_ptr) nogil + int pt_image_status (pt_image *image) nogil + int pt_image_load (pt_image *image) nogil + int pt_image_update (pt_image *image, pt_image_params *params) nogil + int pt_image_tile_file (pt_image *image, pt_tile_info *info, FILE *out) nogil + int pt_image_tile_mem (pt_image *image, pt_tile_info *info, char **buf_ptr, size_t *len_ptr) nogil + void pt_image_destroy (pt_image *image) nogil + + # error code -> name + char* pt_strerror (int err) diff -r 0260aeca943c -r 67f956b71bdf python/pypngtile.pyx --- a/python/pypngtile.pyx Sun Sep 14 16:08:40 2014 +0300 +++ b/python/pypngtile.pyx Sun Sep 14 16:26:38 2014 +0300 @@ -1,68 +1,25 @@ -cdef extern from "errno.h" : - extern int errno - -cdef extern from "string.h" : - char* strerror (int err) - - void* memset (void *, int, size_t) - void* memcpy (void *, void *, size_t) - -cimport stdio -cimport stdlib -cimport python_string +from libc.errno cimport ( + errno, +) +from libc.string cimport ( + strerror, + memset, + memcpy, +) +from libc.stdio cimport ( + FILE, +) +from libc.stdlib cimport ( + free, +) +from cpython.string cimport ( + PyString_FromStringAndSize, +) +from pypngtile cimport * cdef extern from "Python.h" : int PyFile_Check (object p) - stdio.FILE* PyFile_AsFile (object p) - void PyFile_IncUseCount (object p) - void PyFile_DecUseCount (object p) - -cdef extern from "pngtile.h" : - struct pt_ctx : - pass - - struct pt_image : - pass - - enum pt_open_mode : - PT_OPEN_READ # 0 - PT_OPEN_UPDATE - - enum pt_cache_status : - PT_CACHE_ERROR # -1 - PT_CACHE_FRESH - PT_CACHE_NONE - PT_CACHE_STALE - PT_CACHE_INCOMPAT - - struct pt_image_info : - size_t img_width, img_height, img_bpp - int image_mtime, cache_mtime, cache_version - size_t image_bytes, cache_bytes - size_t cache_blocks - - struct pt_image_params : - int background_color[4] - - struct pt_tile_info : - size_t width, height - size_t x, y - int zoom - - ctypedef pt_image_info* const_image_info_ptr "const struct pt_image_info *" - - ## functions - int pt_image_open (pt_image **image_ptr, pt_ctx *ctx, char *png_path, int cache_mode) nogil - int pt_image_info_ "pt_image_info" (pt_image *image, pt_image_info **info_ptr) nogil - int pt_image_status (pt_image *image) nogil - int pt_image_load (pt_image *image) nogil - int pt_image_update (pt_image *image, pt_image_params *params) nogil - int pt_image_tile_file (pt_image *image, pt_tile_info *info, stdio.FILE *out) nogil - int pt_image_tile_mem (pt_image *image, pt_tile_info *info, char **buf_ptr, size_t *len_ptr) nogil - void pt_image_destroy (pt_image *image) nogil - - # error code -> name - char* pt_strerror (int err) + FILE* PyFile_AsFile (object p) ## constants # Image() @@ -226,10 +183,10 @@ zoom - zoom level: out = 2**(-zoom) * in out - output file - Note that the given file object MUST be a *real* stdio FILE*, not a fake Python object. + Note that the given file object MUST be a *real* FILE*, not a fake Python object. """ - cdef stdio.FILE *outf + cdef FILE *outf cdef pt_tile_info ti cdef int err @@ -292,10 +249,10 @@ raise Error("pt_image_tile_mem", err) # copy buffer as str... - data = python_string.PyString_FromStringAndSize(buf, len) + data = PyString_FromStringAndSize(buf, len) # drop buffer... - stdlib.free(buf) + free(buf) return data