Skip to content

Commit 39845eb

Browse files
committed
Use designated initializers, inline entries.
1 parent 6219b4f commit 39845eb

File tree

1 file changed

+124
-168
lines changed

1 file changed

+124
-168
lines changed

src/_macosx.m

Lines changed: 124 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -525,50 +525,49 @@ static CGFloat _get_device_scale(CGContextRef cr)
525525
Py_RETURN_NONE;
526526
}
527527

528-
static PyMethodDef FigureCanvas_methods[] = {
529-
{"draw",
530-
(PyCFunction)FigureCanvas_draw,
531-
METH_NOARGS,
532-
NULL, // docstring inherited.
528+
static PyTypeObject FigureCanvasType = {
529+
PyVarObject_HEAD_INIT(NULL, 0)
530+
.tp_name = "_macosx.FigureCanvas",
531+
.tp_basicsize = sizeof(FigureCanvas),
532+
.tp_dealloc = (destructor)FigureCanvas_dealloc,
533+
.tp_repr = (reprfunc)FigureCanvas_repr,
534+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
535+
.tp_init = (initproc)FigureCanvas_init,
536+
.tp_new = (newfunc)FigureCanvas_new,
537+
.tp_doc = "A FigureCanvas object wraps a Cocoa NSView object.",
538+
.tp_methods = (PyMethodDef[]){
539+
{"draw",
540+
(PyCFunction)FigureCanvas_draw,
541+
METH_NOARGS,
542+
NULL}, // docstring inherited
543+
{"draw_idle",
544+
(PyCFunction)FigureCanvas_draw_idle,
545+
METH_NOARGS,
546+
NULL}, // docstring inherited
547+
{"flush_events",
548+
(PyCFunction)FigureCanvas_flush_events,
549+
METH_NOARGS,
550+
NULL}, // docstring inherited
551+
{"set_rubberband",
552+
(PyCFunction)FigureCanvas_set_rubberband,
553+
METH_VARARGS,
554+
"Specifies a new rubberband rectangle and invalidates it."},
555+
{"remove_rubberband",
556+
(PyCFunction)FigureCanvas_remove_rubberband,
557+
METH_NOARGS,
558+
"Removes the current rubberband rectangle."},
559+
{"start_event_loop",
560+
(PyCFunction)FigureCanvas_start_event_loop,
561+
METH_KEYWORDS | METH_VARARGS,
562+
NULL}, // docstring inherited
563+
{"stop_event_loop",
564+
(PyCFunction)FigureCanvas_stop_event_loop,
565+
METH_NOARGS,
566+
NULL}, // docstring inherited
567+
{} // sentinel
533568
},
534-
{"draw_idle",
535-
(PyCFunction)FigureCanvas_draw_idle,
536-
METH_NOARGS,
537-
NULL, // docstring inherited.
538-
},
539-
{"flush_events",
540-
(PyCFunction)FigureCanvas_flush_events,
541-
METH_NOARGS,
542-
NULL, // docstring inherited.
543-
},
544-
{"set_rubberband",
545-
(PyCFunction)FigureCanvas_set_rubberband,
546-
METH_VARARGS,
547-
"Specifies a new rubberband rectangle and invalidates it."
548-
},
549-
{"remove_rubberband",
550-
(PyCFunction)FigureCanvas_remove_rubberband,
551-
METH_NOARGS,
552-
"Removes the current rubberband rectangle."
553-
},
554-
{"start_event_loop",
555-
(PyCFunction)FigureCanvas_start_event_loop,
556-
METH_KEYWORDS | METH_VARARGS,
557-
NULL, // docstring inherited.
558-
},
559-
{"stop_event_loop",
560-
(PyCFunction)FigureCanvas_stop_event_loop,
561-
METH_NOARGS,
562-
NULL, // docstring inherited.
563-
},
564-
{NULL} /* Sentinel */
565569
};
566570

567-
static char FigureCanvas_doc[] =
568-
"A FigureCanvas object wraps a Cocoa NSView object.\n";
569-
570-
static PyTypeObject FigureCanvasType;
571-
572571
typedef struct {
573572
PyObject_HEAD
574573
Window* window;
@@ -739,42 +738,38 @@ static CGFloat _get_device_scale(CGContextRef cr)
739738
Py_RETURN_NONE;
740739
}
741740

742-
static PyMethodDef FigureManager_methods[] = {
743-
{"show",
744-
(PyCFunction)FigureManager_show,
745-
METH_NOARGS,
746-
NULL, // docstring inherited.
747-
},
748-
{"destroy",
749-
(PyCFunction)FigureManager_destroy,
750-
METH_NOARGS,
751-
NULL, // docstring inherited.
752-
},
753-
{"set_window_title",
754-
(PyCFunction)FigureManager_set_window_title,
755-
METH_VARARGS,
756-
NULL, // docstring inherited.
757-
},
758-
{"get_window_title",
759-
(PyCFunction)FigureManager_get_window_title,
760-
METH_NOARGS,
761-
NULL, // docstring inherited.
741+
static PyTypeObject FigureManagerType = {
742+
PyVarObject_HEAD_INIT(NULL, 0)
743+
.tp_name = "_macosx.FigureManager",
744+
.tp_basicsize = sizeof(FigureManager),
745+
.tp_dealloc = (destructor)FigureManager_dealloc,
746+
.tp_repr = (reprfunc)FigureManager_repr,
747+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
748+
.tp_init = (initproc)FigureManager_init,
749+
.tp_new = (newfunc)FigureManager_new,
750+
.tp_doc = "A FigureManager object wraps a Cocoa NSWindow object.",
751+
.tp_methods = (PyMethodDef[]){ // All docstrings are inherited.
752+
{"show",
753+
(PyCFunction)FigureManager_show,
754+
METH_NOARGS},
755+
{"destroy",
756+
(PyCFunction)FigureManager_destroy,
757+
METH_NOARGS},
758+
{"set_window_title",
759+
(PyCFunction)FigureManager_set_window_title,
760+
METH_VARARGS},
761+
{"get_window_title",
762+
(PyCFunction)FigureManager_get_window_title,
763+
METH_NOARGS},
764+
{"resize",
765+
(PyCFunction)FigureManager_resize,
766+
METH_VARARGS},
767+
{} // sentinel
762768
},
763-
{"resize",
764-
(PyCFunction)FigureManager_resize,
765-
METH_VARARGS,
766-
NULL, // docstring inherited.
767-
},
768-
{NULL} /* Sentinel */
769769
};
770770

771-
static char FigureManager_doc[] =
772-
"A FigureManager object wraps a Cocoa NSWindow object.\n";
773-
774-
static PyTypeObject FigureManagerType;
775-
776-
@interface NavigationToolbar2Handler : NSObject {
777-
PyObject* toolbar;
771+
@interface NavigationToolbar2Handler : NSObject
772+
{ PyObject* toolbar;
778773
NSButton* panbutton;
779774
NSButton* zoombutton;
780775
}
@@ -1013,20 +1008,24 @@ -(void)save_figure:(id)sender { gil_call_method(toolbar, "save_figure"); }
10131008
Py_RETURN_NONE;
10141009
}
10151010

1016-
static PyMethodDef NavigationToolbar2_methods[] = {
1017-
{"set_message",
1018-
(PyCFunction)NavigationToolbar2_set_message,
1019-
METH_VARARGS,
1020-
NULL, // docstring inherited.
1011+
static PyTypeObject NavigationToolbar2Type = {
1012+
PyVarObject_HEAD_INIT(NULL, 0)
1013+
.tp_name = "_macosx.NavigationToolbar2",
1014+
.tp_basicsize = sizeof(NavigationToolbar2),
1015+
.tp_dealloc = (destructor)NavigationToolbar2_dealloc,
1016+
.tp_repr = (reprfunc)NavigationToolbar2_repr,
1017+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1018+
.tp_init = (initproc)NavigationToolbar2_init,
1019+
.tp_new = (newfunc)NavigationToolbar2_new,
1020+
.tp_doc = "NavigationToolbar2",
1021+
.tp_methods = (PyMethodDef[]){ // All docstrings are inherited.
1022+
{"set_message",
1023+
(PyCFunction)NavigationToolbar2_set_message,
1024+
METH_VARARGS},
1025+
{} // sentinel
10211026
},
1022-
{NULL} /* Sentinel */
10231027
};
10241028

1025-
static char NavigationToolbar2_doc[] =
1026-
"NavigationToolbar2\n";
1027-
1028-
static PyTypeObject NavigationToolbar2Type;
1029-
10301029
static PyObject*
10311030
choose_save_file(PyObject* unused, PyObject* args)
10321031
{
@@ -1867,99 +1866,56 @@ static void context_cleanup(const void* info)
18671866
Py_TYPE(self)->tp_free((PyObject*)self);
18681867
}
18691868

1870-
static char Timer_doc[] =
1871-
"A Timer object wraps a CFRunLoopTimerRef and can add it to the event loop.\n";
1872-
1873-
static PyMethodDef Timer_methods[] = {
1874-
{"_timer_start",
1875-
(PyCFunction)Timer__timer_start,
1876-
METH_VARARGS,
1877-
NULL, // docstring inherited.
1869+
static PyTypeObject TimerType = {
1870+
PyVarObject_HEAD_INIT(NULL, 0)
1871+
.tp_name = "_macosx.Timer",
1872+
.tp_basicsize = sizeof(Timer),
1873+
.tp_dealloc = (destructor)Timer_dealloc,
1874+
.tp_repr = (reprfunc)Timer_repr,
1875+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
1876+
.tp_new = (newfunc)Timer_new,
1877+
.tp_doc = "A Timer object wraps a CFRunLoopTimerRef and can add it to the event loop.",
1878+
.tp_methods = (PyMethodDef[]){ // All docstrings are inherited.
1879+
{"_timer_start",
1880+
(PyCFunction)Timer__timer_start,
1881+
METH_VARARGS},
1882+
{"_timer_stop",
1883+
(PyCFunction)Timer__timer_stop,
1884+
METH_NOARGS},
1885+
{} // sentinel
18781886
},
1879-
{"_timer_stop",
1880-
(PyCFunction)Timer__timer_stop,
1881-
METH_NOARGS,
1882-
NULL, // docstring inherited.
1883-
},
1884-
{NULL} /* Sentinel */
1885-
};
1886-
1887-
static PyTypeObject TimerType;
1888-
1889-
static PyMethodDef methods[] = {
1890-
{"event_loop_is_running",
1891-
(PyCFunction)event_loop_is_running,
1892-
METH_NOARGS,
1893-
"Return whether the OSX backend has set up the NSApp main event loop."
1894-
},
1895-
{"show",
1896-
(PyCFunction)show,
1897-
METH_NOARGS,
1898-
"Show all the figures and enter the main loop.\n"
1899-
"\n"
1900-
"This function does not return until all Matplotlib windows are closed,\n"
1901-
"and is normally not needed in interactive sessions."
1902-
},
1903-
{"choose_save_file",
1904-
(PyCFunction)choose_save_file,
1905-
METH_VARARGS,
1906-
"Closes the window."
1907-
},
1908-
{"set_cursor",
1909-
(PyCFunction)set_cursor,
1910-
METH_VARARGS,
1911-
"Sets the active cursor."
1912-
},
1913-
{NULL, NULL, 0, NULL} /* sentinel */
19141887
};
19151888

19161889
static struct PyModuleDef moduledef = {
1917-
PyModuleDef_HEAD_INIT, "_macosx", "Mac OS X native backend", -1, methods
1890+
PyModuleDef_HEAD_INIT, "_macosx", "Mac OS X native backend", -1,
1891+
(PyMethodDef[]){
1892+
{"event_loop_is_running",
1893+
(PyCFunction)event_loop_is_running,
1894+
METH_NOARGS,
1895+
"Return whether the OSX backend has set up the NSApp main event loop."},
1896+
{"show",
1897+
(PyCFunction)show,
1898+
METH_NOARGS,
1899+
"Show all the figures and enter the main loop.\n"
1900+
"\n"
1901+
"This function does not return until all Matplotlib windows are closed,\n"
1902+
"and is normally not needed in interactive sessions."},
1903+
{"choose_save_file",
1904+
(PyCFunction)choose_save_file,
1905+
METH_VARARGS,
1906+
"Closes the window."},
1907+
{"set_cursor",
1908+
(PyCFunction)set_cursor,
1909+
METH_VARARGS,
1910+
"Sets the active cursor."},
1911+
{} /* Sentinel */
1912+
},
19181913
};
19191914

19201915
#pragma GCC visibility push(default)
19211916

19221917
PyObject* PyInit__macosx(void)
19231918
{
1924-
FigureCanvasType.tp_name = "_macosx.FigureCanvas";
1925-
FigureCanvasType.tp_basicsize = sizeof(FigureCanvas);
1926-
FigureCanvasType.tp_dealloc = FigureCanvas_dealloc;
1927-
FigureCanvasType.tp_repr = FigureCanvas_repr;
1928-
FigureCanvasType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1929-
FigureCanvasType.tp_doc = FigureCanvas_doc;
1930-
FigureCanvasType.tp_methods = FigureCanvas_methods;
1931-
FigureCanvasType.tp_init = FigureCanvas_init;
1932-
FigureCanvasType.tp_new = FigureCanvas_new;
1933-
1934-
FigureManagerType.tp_name = "_macosx.FigureManager";
1935-
FigureManagerType.tp_basicsize = sizeof(FigureManager);
1936-
FigureManagerType.tp_dealloc = FigureManager_dealloc;
1937-
FigureManagerType.tp_repr = FigureManager_repr;
1938-
FigureManagerType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1939-
FigureManagerType.tp_doc = FigureManager_doc;
1940-
FigureManagerType.tp_methods = FigureManager_methods;
1941-
FigureManagerType.tp_init = FigureManager_init;
1942-
FigureManagerType.tp_new = FigureManager_new;
1943-
1944-
NavigationToolbar2Type.tp_name = "_macosx.NavigationToolbar2";
1945-
NavigationToolbar2Type.tp_basicsize = sizeof(NavigationToolbar2);
1946-
NavigationToolbar2Type.tp_dealloc = NavigationToolbar2_dealloc;
1947-
NavigationToolbar2Type.tp_repr = NavigationToolbar2_repr;
1948-
NavigationToolbar2Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1949-
NavigationToolbar2Type.tp_doc = NavigationToolbar2_doc;
1950-
NavigationToolbar2Type.tp_methods = NavigationToolbar2_methods;
1951-
NavigationToolbar2Type.tp_init = NavigationToolbar2_init;
1952-
NavigationToolbar2Type.tp_new = NavigationToolbar2_new;
1953-
1954-
TimerType.tp_name = "_macosx.Timer";
1955-
TimerType.tp_basicsize = sizeof(Timer);
1956-
TimerType.tp_dealloc = Timer_dealloc;
1957-
TimerType.tp_repr = Timer_repr;
1958-
TimerType.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
1959-
TimerType.tp_doc = Timer_doc;
1960-
TimerType.tp_methods = Timer_methods;
1961-
TimerType.tp_new = Timer_new;
1962-
19631919
if (PyType_Ready(&FigureCanvasType) < 0
19641920
|| PyType_Ready(&FigureManagerType) < 0
19651921
|| PyType_Ready(&NavigationToolbar2Type) < 0

0 commit comments

Comments
 (0)