Skip to content

Commit fa9f690

Browse files
author
James William Pye
committed
Add postgresql.lib to packages(release) and re-org optimized.c and buffer.c
Re-organize the optimized module into a collection of C files managed by optimized/module.c #include directives. This will provide better organization of optimizations for the protocol package.
1 parent c549073 commit fa9f690

4 files changed

Lines changed: 58 additions & 81 deletions

File tree

postgresql/protocol/buffer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
This is an abstraction module that provides the working buffer implementation.
77
If a C compiler is not available on the system that built the package, the slower
88
`postgresql.protocol.pbuffer` module can be used in
9-
`postgresql.protocol.cbuffer`'s absence.
9+
`postgresql.protocol.optimized.buffer`'s absence.
1010
1111
This provides a convenient place to import the necessary module without
1212
concerning the local code with the details.
1313
"""
1414
try:
15-
from postgresql.protocol.cbuffer import *
15+
from .optimized import pq_message_stream
1616
except ImportError:
17-
from postgresql.protocol.pbuffer import *
17+
from .pbuffer import pq_message_stream
Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@
77
*
88
* PQ messages normally take the form {type, (size), data}
99
*/
10-
#include <stdint.h>
11-
#ifdef WIN32
12-
#include <winsock.h>
13-
#else
14-
#include <sys/types.h>
15-
#include <netinet/in.h>
16-
#endif
17-
#include <Python.h>
18-
#include <structmember.h>
19-
20-
static PyObject *message_types = NULL;
21-
2210
struct p_list
2311
{
2412
PyObject *data; /* PyString pushed onto the buffer */
@@ -532,7 +520,7 @@ static PyMethodDef p_methods[] = {
532520

533521
PyTypeObject pq_message_stream_Type = {
534522
PyVarObject_HEAD_INIT(NULL, 0)
535-
"postgresql.protocol.cbuffer.pq_message_stream", /* tp_name */
523+
"postgresql.protocol.optimized.pq_message_stream", /* tp_name */
536524
sizeof(struct p_buffer), /* tp_basicsize */
537525
0, /* tp_itemsize */
538526
p_dealloc, /* tp_dealloc */
@@ -573,65 +561,6 @@ PyTypeObject pq_message_stream_Type = {
573561
p_new, /* tp_new */
574562
NULL, /* tp_free */
575563
};
576-
577-
static struct PyModuleDef cbuffermodule = {
578-
PyModuleDef_HEAD_INIT,
579-
"cbuffer",/* name of module */
580-
NULL, /* module documentation, may be NULL */
581-
-1, /* size of per-interpreter state of the module,
582-
or -1 if the module keeps state in global variables. */
583-
NULL,
584-
};
585-
586-
PyMODINIT_FUNC
587-
PyInit_cbuffer(void)
588-
{
589-
PyObject *mod;
590-
PyObject *msgtypes;
591-
PyObject *fromlist, *fromstr;
592-
593-
mod = PyModule_Create(&cbuffermodule);
594-
if (mod == NULL)
595-
return(NULL);
596-
597-
if (PyType_Ready(&pq_message_stream_Type) < 0)
598-
goto cleanup;
599-
600-
if (PyModule_AddObject(mod, "pq_message_stream",
601-
(PyObject *) &pq_message_stream_Type) < 0)
602-
goto cleanup;
603-
604-
/*
605-
* Get the message_types tuple to type "instantiation".
606-
*/
607-
fromlist = PyList_New(1);
608-
fromstr = PyUnicode_FromString("message_types");
609-
PyList_SetItem(fromlist, 0, fromstr);
610-
msgtypes = PyImport_ImportModuleLevel(
611-
"message_types",
612-
PyModule_GetDict(mod),
613-
PyModule_GetDict(mod),
614-
fromlist, 1
615-
);
616-
Py_DECREF(fromlist);
617-
if (msgtypes == NULL)
618-
goto cleanup;
619-
message_types = PyObject_GetAttrString(msgtypes, "message_types");
620-
Py_DECREF(msgtypes);
621-
622-
if (!PyObject_IsInstance(message_types, (PyObject *) (&PyTuple_Type)))
623-
{
624-
PyErr_SetString(PyExc_RuntimeError,
625-
"local protocol.message_types.message_types is not a tuple object");
626-
goto cleanup;
627-
}
628-
629-
return(mod);
630-
631-
cleanup:
632-
Py_DECREF(mod);
633-
return(NULL);
634-
}
635564
/*
636565
* vim: ts=3:sw=3:noet:
637566
*/
Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515
#include <Python.h>
1616
#include <structmember.h>
1717

18+
/*
19+
* buffer.c needs the message_types object from protocol.message_types.
20+
*/
21+
static PyObject *message_types = NULL;
22+
23+
#include "buffer.c"
24+
25+
1826
static PyObject *
1927
parse_tuple_message(PyObject *self, PyObject *args)
2028
{
@@ -349,7 +357,50 @@ static struct PyModuleDef optimized_module = {
349357
PyMODINIT_FUNC
350358
PyInit_optimized(void)
351359
{
352-
return(PyModule_Create(&optimized_module));
360+
PyObject *mod;
361+
PyObject *msgtypes;
362+
PyObject *fromlist, *fromstr;
363+
364+
mod = PyModule_Create(&optimized_module);
365+
if (mod == NULL)
366+
return(NULL);
367+
368+
if (PyType_Ready(&pq_message_stream_Type) < 0)
369+
goto cleanup;
370+
371+
if (PyModule_AddObject(mod, "pq_message_stream",
372+
(PyObject *) &pq_message_stream_Type) < 0)
373+
goto cleanup;
374+
375+
/*
376+
* Get the message_types tuple to type "instantiation".
377+
*/
378+
fromlist = PyList_New(1);
379+
fromstr = PyUnicode_FromString("message_types");
380+
PyList_SetItem(fromlist, 0, fromstr);
381+
msgtypes = PyImport_ImportModuleLevel(
382+
"message_types",
383+
PyModule_GetDict(mod),
384+
PyModule_GetDict(mod),
385+
fromlist, 1
386+
);
387+
Py_DECREF(fromlist);
388+
if (msgtypes == NULL)
389+
goto cleanup;
390+
message_types = PyObject_GetAttrString(msgtypes, "message_types");
391+
Py_DECREF(msgtypes);
392+
393+
if (!PyObject_IsInstance(message_types, (PyObject *) (&PyTuple_Type)))
394+
{
395+
PyErr_SetString(PyExc_RuntimeError,
396+
"local protocol.message_types.message_types is not a tuple object");
397+
goto cleanup;
398+
}
399+
400+
return(mod);
401+
cleanup:
402+
Py_DECREF(mod);
403+
return(NULL);
353404
}
354405
/*
355406
* vim: ts=3:sw=3:noet:

postgresql/release/distutils.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
subpackages = [
8787
'bin',
8888
'encodings',
89+
'lib',
8990
'protocol',
9091
'driver',
9192
'test',
@@ -96,12 +97,8 @@
9697
'resolved',
9798
]
9899
extensions_data = {
99-
'protocol.cbuffer' : {
100-
'sources' : [os.path.join('protocol', 'buffer.c')],
101-
'libraries' : (sys.platform == 'win32' and ['ws2_32'] or []),
102-
},
103100
'protocol.optimized' : {
104-
'sources' : [os.path.join('protocol', 'optimized.c')],
101+
'sources' : [os.path.join('protocol', 'optimized', 'module.c')],
105102
'libraries' : (sys.platform == 'win32' and ['ws2_32'] or []),
106103
},
107104
'python.optimized' : {

0 commit comments

Comments
 (0)