Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import os
  3.  
  4. from cffi import FFI
  5.  
  6. ffi = FFI()
  7.  
  8. script_dir = os.path.dirname(__file__)
  9.  
  10. person_header = """
  11.    typedef struct {
  12.        wchar_t *p_first_name;
  13.        wchar_t *p_last_name;
  14.        int p_age;
  15.    } person_t;
  16.    /* Creates a new person. Names are strdup(...)'d into the person. */
  17.    person_t *person_create(const wchar_t *first_name, const wchar_t *last_name, int age);
  18.    /* Writes the person's full name into *buf, up to n characters.
  19.     * Returns the number of characters written. */
  20.    int person_get_full_name(person_t *p, wchar_t *buf, size_t n);
  21.    /* Destroys a person, including free()ing their names. */
  22.    void person_destroy(person_t *p);
  23. """
  24.  
  25. ffi.set_source(script_dir + ".ERIC._eric", person_header + """
  26.    #include <stdlib.h>
  27.    #include <string.h>
  28.    #include <wchar.h>
  29.    person_t *person_create(const wchar_t *first_name, const wchar_t *last_name, int age) {
  30.        person_t *p = malloc(sizeof(person_t));
  31.        if (!p)
  32.            return NULL;
  33.        p->p_first_name = wcsdup(first_name);
  34.        p->p_last_name = wcsdup(last_name);
  35.        p->p_age = age;
  36.        return p;
  37.    }
  38.    int person_get_full_name(person_t *p, wchar_t *buf, size_t n) {
  39.        return swprintf(buf, n, L"%S %S", p->p_first_name, p->p_last_name);
  40.    }
  41.    void person_destroy(person_t *p) {
  42.        if (p->p_first_name)
  43.            free(p->p_first_name);
  44.        if (p->p_last_name)
  45.            free(p->p_last_name);
  46.        free(p);
  47.    }
  48. """)
  49.  
  50. ffi.cdef(person_header)
  51.  
  52. if __name__ == "openerp.addons.plustron_clients.ffi":
  53.     ffi.compile(verbose=True, tmpdir='/')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement