static int l_graphics_Mesh_setVertexMap(lua_State *state) { l_assertType(state, 1, l_graphics_isMesh); l_graphics_Mesh *mesh = l_graphics_toMesh(state, 1); size_t top = (size_t)lua_gettop(state); if(top == 1) { graphics_Mesh_setVertexMap(&mesh->mesh, 0, 0); return 0; } size_t count; if(top > 2) { ensureBufferSize(sizeof(uint32_t) * (top - 1)); for(int i = 0; i < top - 1; ++i) { ((uint32_t*)moduleData.buffer)[i] = (uint32_t)l_tools_toNumberOrError(state, i + 2) - 1; printf("Index: %d\n", ((uint32_t*)moduleData.buffer)[i]); } count = top - 1; } else { size_t len = (size_t)lua_objlen(state, 2); ensureBufferSize(len * sizeof(uint32_t)); for(int i = 0; i < len; ++i) { lua_rawgeti(state, 2, i+1); ((uint32_t*)moduleData.buffer)[i] = (uint32_t)l_tools_toNumberOrError(state, -1) - 1; } count = len; } graphics_Mesh_setVertexMap(&mesh->mesh, count, (uint32_t*)moduleData.buffer); return 0; }
void ClientMessage::append(const ClientMessage *msg) { // no need to double check if correlation ids match here, // since we make sure that this is guaranteed at the caller that they are matching ! int32_t dataSize = msg->getDataSize(); int32_t existingFrameLen = getFrameLength(); int32_t newFrameLen = existingFrameLen + dataSize; ensureBufferSize(newFrameLen); memcpy(buffer + existingFrameLen, msg->buffer, (size_t) dataSize); setFrameLength(newFrameLen); }
static size_t readVertices(lua_State* state, bool *hasVertexColor, int base) { if(!lua_istable(state, base)) { lua_pushstring(state, "Need table of vertices"); lua_error(state); // does not return return 0; // hint the compiler } size_t count = lua_objlen(state, base); ensureBufferSize(count * sizeof(graphics_Vertex)); *hasVertexColor = false; for(size_t i = 0; i < count; ++i) { lua_rawgeti(state, base, i+1); readVertex(state, ((graphics_Vertex*)moduleData.buffer) + i, hasVertexColor); lua_pop(state, 1); } return count; }
/* * cdb_sync_xlog - process xlog sync */ static void cdb_sync_xlog(void) { uint32 currentBlockOffset; XLogRecPtr writeLoc; elog((Debug_print_qd_mirroring ? LOG : DEBUG5), "QDSYNC: write logid %d seg %d woffset 0x%X, wlen 0x%X", wlogid, wseg, woffset, wlen); if (woffset % XLOG_BLCKSZ != 0) { elog(ERROR,"QDSYNC: not on block boundaries 0x%X", woffset); } if (wlogid != xlogid || wseg != xseg) { elog((Debug_print_qd_mirroring ? LOG : DEBUG5), "QDSYNC: closing previous file %s", xlogfilename); if (xlogfilefd >= 0) { close(xlogfilefd); xlogfilefd = -1; xlogfileoffset = -1; } xlogid = wlogid; xseg = wseg; openXlogNextFile(); /* * Assume caller knows where to write. */ xlogfileoffset = woffset; } /* * Validate we are appending or overwritting previous block */ currentBlockOffset = (xlogfileoffset / XLOG_BLCKSZ) * XLOG_BLCKSZ; if (woffset != currentBlockOffset && woffset + XLOG_BLCKSZ != currentBlockOffset) { elog(ERROR,"QDSYNC: not appending to end (primary: 0x%X, standby: 0x%X)", woffset, xlogfileoffset); } /* * no validation checking on xlog. xlog sync is by block and may repeat * the same block, so we do not have any way to check it now. we will rely * on tmlog checking for now. */ ensureBufferSize(); readLogMessage(buf, wlen); if ((wlen / XLOG_BLCKSZ) * XLOG_BLCKSZ != wlen) { int roundedUp; int padLen; /* * Pad buffer out with zeros. */ roundedUp = ((wlen + XLOG_BLCKSZ - 1) / XLOG_BLCKSZ) * XLOG_BLCKSZ; Assert(buflen >= roundedUp); padLen = roundedUp - wlen; elog((Debug_print_qd_mirroring ? LOG : DEBUG5), "QDSYNC: padding buffer with %d zeros (wlen %d, roundedUp %d)", padLen, wlen, roundedUp); memset(&((char*) buf)[wlen], 0, padLen); wlen = roundedUp; } writeLoc.xlogid = wlogid; writeLoc.xrecoff = wseg * XLogSegSize + woffset; syncWriteLog(xlogfilefd, buf, woffset, wlen); elog((Debug_print_qd_mirroring ? LOG : DEBUG5), "QDSYNC: wrote location %s len 0x%X", XLogLocationToString(&writeLoc), wlen); xlogfileoffset = woffset + wlen; }