Ignore:
Timestamp:
Mar 19, 2014, 11:11:30 AM (11 years ago)
Author:
dmik
Message:

python: Update vendor to 2.7.6.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/vendor/current/Modules/fmmodule.c

    r2 r388  
    1212
    1313typedef struct {
    14         PyObject_HEAD
    15         fmfonthandle fh_fh;
     14    PyObject_HEAD
     15    fmfonthandle fh_fh;
    1616} fhobject;
    1717
    1818static PyTypeObject Fhtype;
    1919
    20 #define is_fhobject(v)          ((v)->ob_type == &Fhtype)
     20#define is_fhobject(v)          ((v)->ob_type == &Fhtype)
    2121
    2222static PyObject *
    2323newfhobject(fmfonthandle fh)
    2424{
    25         fhobject *fhp;
    26         if (fh == NULL) {
    27                 PyErr_SetString(PyExc_RuntimeError,
    28                                 "error creating new font handle");
    29                 return NULL;
    30         }
    31         fhp = PyObject_New(fhobject, &Fhtype);
    32         if (fhp == NULL)
    33                 return NULL;
    34         fhp->fh_fh = fh;
    35         return (PyObject *)fhp;
     25    fhobject *fhp;
     26    if (fh == NULL) {
     27        PyErr_SetString(PyExc_RuntimeError,
     28                        "error creating new font handle");
     29        return NULL;
     30    }
     31    fhp = PyObject_New(fhobject, &Fhtype);
     32    if (fhp == NULL)
     33        return NULL;
     34    fhp->fh_fh = fh;
     35    return (PyObject *)fhp;
    3636}
    3737
     
    4141fh_scalefont(fhobject *self, PyObject *args)
    4242{
    43         double size;
    44         if (!PyArg_ParseTuple(args, "d", &size))
    45                 return NULL;
    46         return newfhobject(fmscalefont(self->fh_fh, size));
     43    double size;
     44    if (!PyArg_ParseTuple(args, "d", &size))
     45        return NULL;
     46    return newfhobject(fmscalefont(self->fh_fh, size));
    4747}
    4848
     
    5252fh_setfont(fhobject *self)
    5353{
    54         fmsetfont(self->fh_fh);
    55         Py_INCREF(Py_None);
    56         return Py_None;
     54    fmsetfont(self->fh_fh);
     55    Py_INCREF(Py_None);
     56    return Py_None;
    5757}
    5858
     
    6060fh_getfontname(fhobject *self)
    6161{
    62         char fontname[256];
    63         int len;
    64         len = fmgetfontname(self->fh_fh, sizeof fontname, fontname);
    65         if (len < 0) {
    66                 PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname");
    67                 return NULL;
    68         }
    69         return PyString_FromStringAndSize(fontname, len);
     62    char fontname[256];
     63    int len;
     64    len = fmgetfontname(self->fh_fh, sizeof fontname, fontname);
     65    if (len < 0) {
     66        PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontname");
     67        return NULL;
     68    }
     69    return PyString_FromStringAndSize(fontname, len);
    7070}
    7171
     
    7373fh_getcomment(fhobject *self)
    7474{
    75         char comment[256];
    76         int len;
    77         len = fmgetcomment(self->fh_fh, sizeof comment, comment);
    78         if (len < 0) {
    79                 PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment");
    80                 return NULL;
    81         }
    82         return PyString_FromStringAndSize(comment, len);
     75    char comment[256];
     76    int len;
     77    len = fmgetcomment(self->fh_fh, sizeof comment, comment);
     78    if (len < 0) {
     79        PyErr_SetString(PyExc_RuntimeError, "error in fmgetcomment");
     80        return NULL;
     81    }
     82    return PyString_FromStringAndSize(comment, len);
    8383}
    8484
     
    8686fh_getfontinfo(fhobject *self)
    8787{
    88         fmfontinfo info;
    89         if (fmgetfontinfo(self->fh_fh, &info) < 0) {
    90                 PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontinfo");
    91                 return NULL;
    92         }
    93         return Py_BuildValue("(llllllll)",
    94                              info.printermatched,
    95                              info.fixed_width,
    96                              info.xorig,
    97                              info.yorig,
    98                              info.xsize,
    99                              info.ysize,
    100                              info.height,
    101                              info.nglyphs);
     88    fmfontinfo info;
     89    if (fmgetfontinfo(self->fh_fh, &info) < 0) {
     90        PyErr_SetString(PyExc_RuntimeError, "error in fmgetfontinfo");
     91        return NULL;
     92    }
     93    return Py_BuildValue("(llllllll)",
     94                         info.printermatched,
     95                         info.fixed_width,
     96                         info.xorig,
     97                         info.yorig,
     98                         info.xsize,
     99                         info.ysize,
     100                         info.height,
     101                         info.nglyphs);
    102102}
    103103
     
    112112fh_getstrwidth(fhobject *self, PyObject *args)
    113113{
    114         char *str;
    115         if (!PyArg_ParseTuple(args, "s", &str))
    116                 return NULL;
    117         return PyInt_FromLong(fmgetstrwidth(self->fh_fh, str));
     114    char *str;
     115    if (!PyArg_ParseTuple(args, "s", &str))
     116        return NULL;
     117    return PyInt_FromLong(fmgetstrwidth(self->fh_fh, str));
    118118}
    119119
    120120static PyMethodDef fh_methods[] = {
    121         {"scalefont",   (PyCFunction)fh_scalefont,   METH_VARARGS},
    122         {"setfont",     (PyCFunction)fh_setfont,     METH_NOARGS},
    123         {"getfontname", (PyCFunction)fh_getfontname, METH_NOARGS},
    124         {"getcomment",  (PyCFunction)fh_getcomment,  METH_NOARGS},
    125         {"getfontinfo", (PyCFunction)fh_getfontinfo, METH_NOARGS},
     121    {"scalefont",       (PyCFunction)fh_scalefont,   METH_VARARGS},
     122    {"setfont",         (PyCFunction)fh_setfont,     METH_NOARGS},
     123    {"getfontname",     (PyCFunction)fh_getfontname, METH_NOARGS},
     124    {"getcomment",      (PyCFunction)fh_getcomment,  METH_NOARGS},
     125    {"getfontinfo",     (PyCFunction)fh_getfontinfo, METH_NOARGS},
    126126#if 0
    127         {"getwholemetrics",     (PyCFunction)fh_getwholemetrics, METH_VARARGS},
     127    {"getwholemetrics",         (PyCFunction)fh_getwholemetrics, METH_VARARGS},
    128128#endif
    129         {"getstrwidth", (PyCFunction)fh_getstrwidth, METH_VARARGS},
    130         {NULL,          NULL}           /* sentinel */
     129    {"getstrwidth",     (PyCFunction)fh_getstrwidth, METH_VARARGS},
     130    {NULL,              NULL}           /* sentinel */
    131131};
    132132
     
    134134fh_getattr(fhobject *fhp, char *name)
    135135{
    136         return Py_FindMethod(fh_methods, (PyObject *)fhp, name);
     136    return Py_FindMethod(fh_methods, (PyObject *)fhp, name);
    137137}
    138138
     
    140140fh_dealloc(fhobject *fhp)
    141141{
    142         fmfreefont(fhp->fh_fh);
    143         PyObject_Del(fhp);
     142    fmfreefont(fhp->fh_fh);
     143    PyObject_Del(fhp);
    144144}
    145145
    146146static PyTypeObject Fhtype = {
    147         PyObject_HEAD_INIT(&PyType_Type)
    148         0,                              /*ob_size*/
    149         "fm.font handle",               /*tp_name*/
    150         sizeof(fhobject),               /*tp_size*/
    151         0,                              /*tp_itemsize*/
    152         /* methods */
    153         (destructor)fh_dealloc,         /*tp_dealloc*/
    154         0,                              /*tp_print*/
    155         (getattrfunc)fh_getattr,        /*tp_getattr*/
    156         0,                              /*tp_setattr*/
    157         0,                              /*tp_compare*/
    158         0,                              /*tp_repr*/
     147    PyObject_HEAD_INIT(&PyType_Type)
     148    0,                                  /*ob_size*/
     149    "fm.font handle",                   /*tp_name*/
     150    sizeof(fhobject),                   /*tp_size*/
     151    0,                                  /*tp_itemsize*/
     152    /* methods */
     153    (destructor)fh_dealloc,             /*tp_dealloc*/
     154    0,                                  /*tp_print*/
     155    (getattrfunc)fh_getattr,            /*tp_getattr*/
     156    0,                                  /*tp_setattr*/
     157    0,                                  /*tp_compare*/
     158    0,                                  /*tp_repr*/
    159159};
    160160
     
    165165fm_init(PyObject *self)
    166166{
    167         fminit();
    168         Py_INCREF(Py_None);
    169         return Py_None;
     167    fminit();
     168    Py_INCREF(Py_None);
     169    return Py_None;
    170170}
    171171
     
    173173fm_findfont(PyObject *self, PyObject *args)
    174174{
    175         char *str;
    176         if (!PyArg_ParseTuple(args, "s", &str))
    177                 return NULL;
    178         return newfhobject(fmfindfont(str));
     175    char *str;
     176    if (!PyArg_ParseTuple(args, "s", &str))
     177        return NULL;
     178    return newfhobject(fmfindfont(str));
    179179}
    180180
     
    182182fm_prstr(PyObject *self, PyObject *args)
    183183{
    184         char *str;
    185         if (!PyArg_ParseTuple(args, "s", &str))
    186                 return NULL;
    187         fmprstr(str);
    188         Py_INCREF(Py_None);
    189         return Py_None;
     184    char *str;
     185    if (!PyArg_ParseTuple(args, "s", &str))
     186        return NULL;
     187    fmprstr(str);
     188    Py_INCREF(Py_None);
     189    return Py_None;
    190190}
    191191
     
    197197clientproc(char *fontname)
    198198{
    199         int err;
    200         PyObject *v;
    201         if (fontlist == NULL)
    202                 return;
    203         v = PyString_FromString(fontname);
    204         if (v == NULL)
    205                 err = -1;
    206         else {
    207                 err = PyList_Append(fontlist, v);
    208                 Py_DECREF(v);
    209         }
    210         if (err != 0) {
    211                 Py_DECREF(fontlist);
    212                 fontlist = NULL;
    213         }
     199    int err;
     200    PyObject *v;
     201    if (fontlist == NULL)
     202        return;
     203    v = PyString_FromString(fontname);
     204    if (v == NULL)
     205        err = -1;
     206    else {
     207        err = PyList_Append(fontlist, v);
     208        Py_DECREF(v);
     209    }
     210    if (err != 0) {
     211        Py_DECREF(fontlist);
     212        fontlist = NULL;
     213    }
    214214}
    215215
     
    217217fm_enumerate(PyObject *self)
    218218{
    219         PyObject *res;
    220         fontlist = PyList_New(0);
    221         if (fontlist == NULL)
    222                 return NULL;
    223         fmenumerate(clientproc);
    224         res = fontlist;
    225         fontlist = NULL;
    226         return res;
     219    PyObject *res;
     220    fontlist = PyList_New(0);
     221    if (fontlist == NULL)
     222        return NULL;
     223    fmenumerate(clientproc);
     224    res = fontlist;
     225    fontlist = NULL;
     226    return res;
    227227}
    228228
     
    230230fm_setpath(PyObject *self, PyObject *args)
    231231{
    232         char *str;
    233         if (!PyArg_ParseTuple(args, "s", &str))
    234                 return NULL;
    235         fmsetpath(str);
    236         Py_INCREF(Py_None);
    237         return Py_None;
     232    char *str;
     233    if (!PyArg_ParseTuple(args, "s", &str))
     234        return NULL;
     235    fmsetpath(str);
     236    Py_INCREF(Py_None);
     237    return Py_None;
    238238}
    239239
     
    241241fm_fontpath(PyObject *self)
    242242{
    243         return PyString_FromString(fmfontpath());
     243    return PyString_FromString(fmfontpath());
    244244}
    245245
    246246static PyMethodDef fm_methods[] = {
    247         {"init",        fm_init,      METH_NOARGS},
    248         {"findfont",    fm_findfont,  METH_VARARGS},
    249         {"enumerate",   fm_enumerate, METH_NOARGS},
    250         {"prstr",       fm_prstr,     METH_VARARGS},
    251         {"setpath",     fm_setpath,   METH_VARARGS},
    252         {"fontpath",    fm_fontpath,  METH_NOARGS},
    253         {NULL,          NULL}           /* sentinel */
     247    {"init",            fm_init,      METH_NOARGS},
     248    {"findfont",        fm_findfont,  METH_VARARGS},
     249    {"enumerate",       fm_enumerate, METH_NOARGS},
     250    {"prstr",           fm_prstr,     METH_VARARGS},
     251    {"setpath",         fm_setpath,   METH_VARARGS},
     252    {"fontpath",        fm_fontpath,  METH_NOARGS},
     253    {NULL,              NULL}           /* sentinel */
    254254};
    255255
     
    258258initfm(void)
    259259{
    260    
     260
    261261    if (PyErr_WarnPy3k("the fm module has been removed in "
    262262                       "Python 3.0", 2) < 0)
     263    return;
     264
     265    Py_InitModule("fm", fm_methods);
     266    if (m == NULL)
    263267        return;
    264    
    265         Py_InitModule("fm", fm_methods);
    266         if (m == NULL)
    267                 return;
    268         fminit();
    269 }
     268    fminit();
     269}
Note: See TracChangeset for help on using the changeset viewer.