src/pymongo/_cmessagemodule.c
/* add a lastError message on the end of the buffer.
 * returns 0 on failure */
add a lastError message on the end of the buffer.
returns 0 on failure
add a lastError message on the end of the buffer . returns 0 on failure
static int add_last_error(PyObject* self, buffer_t buffer,
                          int request_id, char* ns, int nslen,
                          codec_options_t* options, PyObject* args) {
    struct module_state *state = GETSTATE(self);
    int message_start;
    int document_start;
    int message_length;
    int document_length;
    PyObject* key;
    PyObject* value;
    Py_ssize_t pos = 0;
    PyObject* one;
    char *p = strchr(ns, '.');
    nslen = p ? (int)(p - ns) : nslen;
    message_start = buffer_save_space(buffer, 4);
    if (message_start == -1) {
        PyErr_NoMemory();
        return 0;
    }
    if (!buffer_write_bytes(buffer, (const char*)&request_id, 4) ||
        !buffer_write_bytes(buffer,
                            "\x00\x00\x00\x00"  
                            "\xd4\x07\x00\x00"  
                            "\x00\x00\x00\x00", 
                            12) ||
        !buffer_write_bytes(buffer,
                            ns, nslen) ||       
        !buffer_write_bytes(buffer,
                            ".$cmd\x00"         
                            "\x00\x00\x00\x00"  
                            "\xFF\xFF\xFF\xFF", 
                            14)) {
        return 0;
    }
    document_start = buffer_save_space(buffer, 4);
    if (document_start == -1) {
        PyErr_NoMemory();
        return 0;
    }
    if (!(one = PyLong_FromLong(1)))
        return 0;
    if (!write_pair(state->_cbson, buffer, "getlasterror", 12, one, 0,
                    options, 1)) {
        Py_DECREF(one);
        return 0;
    }
    Py_DECREF(one);
    while (PyDict_Next(args, &pos, &key, &value)) {
        if (!decode_and_write_pair(state->_cbson, buffer, key, value, 0,
                                   options, 0)) {
            return 0;
        }
    }
    if (!buffer_write_bytes(buffer, "\x00", 1)) {
        return 0;
    }
    message_length = buffer_get_position(buffer) - message_start;
    document_length = buffer_get_position(buffer) - document_start;
    memcpy(buffer_get_buffer(buffer) + message_start, &message_length, 4);
    memcpy(buffer_get_buffer(buffer) + document_start, &document_length, 4);
    return 1;
}
static int add_last_error ( PyObject * self , buffer_t buffer , int request_id , char * ns , int nslen , codec_options_t * options , PyObject * args ) { struct module_state * state = GETSTATE ( self ) ; int message_start ; int document_start ; int message_length ; int document_length ; PyObject * key ; PyObject * value ; Py_ssize_t pos = 0 ; PyObject * one ; char * p = strchr ( ns , ' ' ) ; nslen = p ? ( int ) ( p - ns ) : nslen ; message_start = buffer_save_space ( buffer , 4 ) ; if ( message_start == -1 ) { PyErr_NoMemory ( ) ; return 0 ; } if ( ! buffer_write_bytes ( buffer , ( const char * ) & request_id , 4 ) || ! buffer_write_bytes ( buffer , " \x00 \x00 \x00 \x00 " " \xd4 \x07 \x00 \x00 " " \x00 \x00 \x00 \x00 " , 12 ) || ! buffer_write_bytes ( buffer , ns , nslen ) || ! buffer_write_bytes ( buffer , " \x00 " " \x00 \x00 \x00 \x00 " " \xFF \xFF \xFF \xFF " , 14 ) ) { return 0 ; } document_start = buffer_save_space ( buffer , 4 ) ; if ( document_start == -1 ) { PyErr_NoMemory ( ) ; return 0 ; } if ( ! ( one = PyLong_FromLong ( 1 ) ) ) return 0 ; if ( ! write_pair ( state -> _cbson , buffer , " " , 12 , one , 0 , options , 1 ) ) { Py_DECREF ( one ) ; return 0 ; } Py_DECREF ( one ) ; while ( PyDict_Next ( args , & pos , & key , & value ) ) { if ( ! decode_and_write_pair ( state -> _cbson , buffer , key , value , 0 , options , 0 ) ) { return 0 ; } } if ( ! buffer_write_bytes ( buffer , " \x00 " , 1 ) ) { return 0 ; } message_length = buffer_get_position ( buffer ) - message_start ; document_length = buffer_get_position ( buffer ) - document_start ; memcpy ( buffer_get_buffer ( buffer ) + message_start , & message_length , 4 ) ; memcpy ( buffer_get_buffer ( buffer ) + document_start , & document_length , 4 ) ; return 1 ; }
add a lastError message on the end of the buffer.
add a lastError message on the end of the buffer .
/* Length of the database portion of ns. */ /* responseTo */ /* opcode */ /* options */ /* database */ /* collection name */ /* skip */ /* limit (-1) */ /* save space for length */ /* getlasterror: 1 */ /* getlasterror options */ /* EOD */