public static long strtol(sbyte *start, sbyte **end, int radix) { // First step - determine length var length = 0; sbyte *ptr = start; while (numbers.IndexOf((char)*ptr) != -1) { ++ptr; ++length; } long result = 0; // Now build up the number ptr = start; while (length > 0) { long num = numbers.IndexOf((char)*ptr); long pow = (long)Math.Pow(10, length - 1); result += num * pow; ++ptr; --length; } if (end != null) { *end = ptr; } return(result); }
/// <summary> /// Relay the returned result from sqlite3 callback to the callback func specified /// when Execute() is called /// </summary> /// <param name="pArg">Not used</param> /// <param name="argc">Number of columns in argv</param> /// <param name="argv">The column data in this row</param> /// <param name="columnNames">The column names</param> internal unsafe int CallBack(IntPtr pArg, int argc, sbyte **argv, sbyte **columnNames) { List <string> ar = new List <string>(argc); // First time in? Add column names if (this.column_names == null) { for (int i = 0; i < argc; ++i) { ar.Add(SqliteString.PointerToString(columnNames[i])); } } column_names = ar.ToArray(); // Go through this rows data ar.Clear(); for (int i = 0; i < argc; ++i) { if (argv[i] == ((sbyte *)0)) { ar.Add(null); } //ar[i] = null; else { ar.Add(SqliteString.PointerToString(argv[i])); } //ar[i] = SqliteString.PointerToString(argv[i]); } return(callbackfunc(param, column_names, ar.ToArray())); }
public static extern CXTranslationUnitImpl *clang_createTranslationUnitFromSourceFile( CXIndexImpl *CIdx, sbyte *source_filename, int num_clang_command_line_args, sbyte **clang_command_line_args, uint num_unsaved_files, CXUnsavedFile *unsaved_files);
public void readName(sbyte **name) { physx.PxDeserializationContextPtr pvk_in_this = this; sbyte **pvk_in_name = name; void_PxDeserializationContextPtr_readNamePtr_sbyte_(pvk_in_this, pvk_in_name); }
public void Fill(sbyte **pDestination) { for (int i = 0; i < Count; i++) { pDestination[i] = Values[i]; } }
public unsafe TrainValInfo getInfo(void *param) { TrainValInfo info = new TrainValInfo(); sbyte * p = (sbyte *)param; info.iterNum = *(int *)p; p += 4; info.numOutput = *(int *)p; p += 4; float *values = *(float **)p; p += sizeof(void *); if (info.numOutput > 0) { info.values = new float[info.numOutput]; for (int i = 0; i < info.numOutput; ++i) { info.values[i] = values[i]; } sbyte **names = *(sbyte ***)(p); info.outputNames = new string[info.numOutput]; for (int i = 0; i < info.numOutput; ++i) { info.outputNames[i] = new string(names[i]); } } return(info); }
/// <summary> /// Callback which populates the result set from the queries results /// </summary> /// <param name="pArg">Not used</param> /// <param name="argc">Number of columns in argv</param> /// <param name="argv">The column data in this row</param> /// <param name="columnNames">The column names</param> internal unsafe int CallBack(IntPtr pArg, int argc, sbyte **argv, sbyte **columnNames) { // First time in? Add column names if (this.columnNames.Count == 0) { for (int i = 0; i < argc; ++i) { this.columnNames.Add(new String(columnNames[i])); } } ArrayList row = new ArrayList(); // Go through this rows data for (int i = 0; i < argc; ++i) { if (argv[i] == ((sbyte *)0)) { row.Add(null); } else { row.Add(new String(argv[i])); } } this.rowData.Add(row); return(0); }
public void GetActiveNames() { unsafe { // I use 100 here as an artificial number. This may not be a reasonable // assumption, but I don't know how the actual GetActiveNames works sbyte **names = (sbyte **)Marshal.AllocHGlobal(100).ToPointer(); try { GetActiveNames(names); // fill the ActiveNames property ActiveNames = new string[100]; for (int i = 0; i < 100; ++i) { ActiveNames[i] = new string(names[i]); } } finally { // deallocate the unmanaged names memory Marshal.FreeHGlobal(IntPtr((void *)names)); } } }
public virtual IEnumerable <string> GetAllKeys() { int count = 0; sbyte ** ch = nsjs_localvalue_object_getallkeys(this.Handle, ref count); ISet <string> r = new HashSet <string>(); if (ch != null) { for (int i = 0; i < count; i++) { sbyte *s = ch[i]; string key = new string(s); if (s != null) { NSJSMemoryManagement.Free(s); } if (string.IsNullOrEmpty(key)) { continue; } r.Add(key); } NSJSMemoryManagement.Free(ch); } return(r); }
public static extern CXTranslationUnitImpl *clang_parseTranslationUnit( CXIndexImpl *CIdx, sbyte *source_filename, sbyte **command_line_args, int num_command_line_args, CXUnsavedFile *unsaved_files, uint num_unsaved_files, uint options);
public static extern void clang_getDefinitionSpellingAndExtent( CXCursor arg1, sbyte **startBuf, sbyte **endBuf, uint *startLine, uint *startColumn, uint *endLine, uint *endColumn);
internal static unsafe void InitializeCommandLineArgs(int argc, sbyte **argv) { string[] args = new string[argc]; for (int i = 0; i < argc; ++i) { args[i] = new string(argv[i]); } Environment.SetCommandLineArgs(args); }
public static extern CXErrorCode clang_parseTranslationUnit2FullArgv( CXIndexImpl *CIdx, sbyte *source_filename, sbyte **command_line_args, int num_command_line_args, CXUnsavedFile *unsaved_files, uint num_unsaved_files, uint options, CXTranslationUnitImpl **out_TU);
public void Fill(sbyte **pDestination) { if (_values != null) { for (var i = 0; i < _values.Length; i++) { pDestination[i] = Values[i]; } } }
unsafe static object GetFromReference(sbyte **str) { if (str == (sbyte **)null) { return(null); } else { return(new string((sbyte *)*str)); } }
unsafe static string GetStringFromReference(sbyte **str) { var o = GetFromReference(str); if (o == null) { return("(null)"); } else { return(string.Format("\"{0}\"", o as string)); } }
public static extern int clang_indexSourceFileFullArgv( CXIndexActionImpl *arg1, CXClientDataImpl *client_data, IndexerCallbacks *index_callbacks, uint index_callbacks_size, uint index_options, sbyte *source_filename, sbyte **command_line_args, int num_command_line_args, CXUnsavedFile *unsaved_files, uint num_unsaved_files, CXTranslationUnitImpl **out_TU, uint TU_options);
public void Dispose() { if (pointer != null) { for (int i = 0; i < count; i++) { Marshal.FreeCoTaskMem((IntPtr)pointer[i]); } Marshal.FreeCoTaskMem((IntPtr)pointer); pointer = null; count = 0; } }
/// <summary> /// /// </summary> public void Dispose() { unsafe { if (_attr != null) { for (int i = 0; _attr[i] != null; i++) { Marshal.FreeHGlobal(new IntPtr(_attr[i])); } Marshal.FreeHGlobal(new IntPtr(_attr)); _attr = null; } } }
static unsafe IntPtr _libsvnsharp_commit_log_func( sbyte **logMsg, sbyte **tmpFile, IntPtr commitItemsPtr, IntPtr baton, IntPtr pool) { var client = AprBaton <SvnClientContext> .Get(baton); var tmpPool = new AprPool(pool, false); var commit_items = apr_array_header_t.__CreateInstance(commitItemsPtr); var ea = new SvnCommittingEventArgs(commit_items, client.CurrentCommandArgs.CommandType, tmpPool); *logMsg = null; *tmpFile = null; try { client.HandleClientCommitting(ea); if (ea.Cancel) { return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Operation canceled from OnCommitting").__Instance); } else if (ea.LogMessage != null) { *logMsg = tmpPool.AllocUnixString(ea.LogMessage); } else if (!client._noLogMessageRequired) { return(svn_error.svn_error_create((int)SvnErrorCode.SVN_ERR_CANCELLED, null, "Commit canceled: A logmessage is required").__Instance); } else { *logMsg = tmpPool.AllocString(""); } return(IntPtr.Zero); } catch (Exception e) { return(SvnException.CreateExceptionSvnError("Commit log", e).__Instance); } finally { ea.Detach(false); tmpPool.Dispose(); } }
public IppLibraryVersion(int *p) { major = *p; p++; minor = *p; p++; majorBuild = *p; p++; build = *p; p++; targetCpu = new string((sbyte *)p, 0, 4); p++; if (8 == IntPtr.Size) { p++; } sbyte **s = (sbyte **)p; Name = new string(*s); s++; Version = new string(*s); s++; BuildDate = new string(*s); }
public StringArray(string[] array) { count = array.Length; pointer = (sbyte **)Marshal.AllocCoTaskMem(count * sizeof(sbyte *)); for (int i = 0; i < count; i++) { fixed(char *p = array[i]) { int len = Encoding.ASCII.GetByteCount(array[i]); pointer[i] = (sbyte *)Marshal.AllocCoTaskMem(len + 1); // Zero final byte Encoding.ASCII.GetBytes(p, len, (byte *)pointer[i], len); pointer[i][len] = 0; // Final zero } } }
private FFmpegMediaFrame CreateMediaFrameFromDecodedPictureHolder() { // Create the output picture. Once the DecodeFrameHolder has the frame in YUV, the SWS API is // then used to convert to BGR24 and display on the screen. var outputPicture = (AVPicture *)ffmpeg.av_frame_alloc(); var outputPictureBuffer = (sbyte *)ffmpeg.av_malloc((uint)OutputPictureBufferLength); ffmpeg.avpicture_fill(outputPicture, outputPictureBuffer, Constants.VideoOutputPixelFormat, VideoFrameWidth, VideoFrameHeight); // convert the colorspace from (typically) YUV to BGR24 sbyte **sourceScan0 = &DecodedPictureHolder->data0; sbyte **targetScan0 = &outputPicture->data0; ffmpeg.sws_scale( VideoResampler, sourceScan0, DecodedPictureHolder->linesize, 0, VideoFrameHeight, targetScan0, outputPicture->linesize); // Compute data size and data pointer (stride and scan0, respectively) var imageStride = outputPicture->linesize[0]; var imageDataSize = Convert.ToUInt32(VideoFrameHeight * imageStride); var imageDataPtr = new IntPtr(outputPicture->data0); // Create a MediaFrame object with the info we have -- we will return this var mediaFrame = new FFmpegMediaFrame() { Picture = outputPicture, PictureBuffer = outputPictureBuffer, PictureBufferPtr = imageDataPtr, PictureBufferLength = imageDataSize, StartTime = Helper.TimestampToSeconds(DecodedPictureHolder->best_effort_timestamp, InputVideoStream->time_base), Flags = (FFmpegMediaFrameFlags)DecodedPictureHolder->flags, PictureType = (FFmpegPictureType)DecodedPictureHolder->pict_type, CodedPictureNumber = DecodedPictureHolder->coded_picture_number, Duration = Helper.TimestampToSeconds(DecodedPictureHolder->pkt_duration, InputVideoStream->time_base), Timestamp = DecodedPictureHolder->best_effort_timestamp, Type = MediaFrameType.Video, StreamIndex = InputVideoStream->index }; return(mediaFrame); }
private unsafe IntPtr FindArchitectureLibrary(string architecture) { var libraries = Directory.GetFiles(".", "opcodes-*.dll"); foreach (string libName in libraries) { List <string> archList = new List <string>(); IntPtr hLib = NativeLibrary.Load(libName); IntPtr bfd_scan_arch = NativeLibrary.GetExport(hLib, "bfd_scan_arch"); IntPtr bfd_arch_list = NativeLibrary.GetExport(hLib, "bfd_arch_list"); BfdScanArchDelegate scanArchFn = Marshal.GetDelegateForFunctionPointer <BfdScanArchDelegate>(bfd_scan_arch); BfdArchListDelegate archListFn = Marshal.GetDelegateForFunctionPointer <BfdArchListDelegate>(bfd_arch_list); sbyte **archListPtr = (sbyte **)archListFn(); if (archListPtr != null) { for (sbyte **sptr = archListPtr; *sptr != null; sptr++) { IntPtr strPtr = new IntPtr(*sptr); string?arch = Marshal.PtrToStringAnsi(strPtr); archList.Add(arch ?? "(null)"); } } // populate local list // ($TODO: should be done in another function to make this function stateless) libToArches[libName] = archList; IntPtr res = scanArchFn(architecture); if (res != IntPtr.Zero) { return(hLib); } NativeLibrary.Free(hLib); } return(IntPtr.Zero); }
unsafe private static int OpalGetActiveProjects( ushort allocatedProjects, ushort *numProjects, ushort allocatedModels, ushort *numModels, ushort allocatedProjectsPathLen, ushort *maxProjectPathLen, ushort allocatedModelPathLen, ushort *maxModelPathLen, ushort allocatedMachineNameLen, ushort *maxMachineNameLen, ushort allocatedIpLen, ushort *maxIpLen, sbyte **projectPaths, ushort *instanceIDs, sbyte **machineNames, sbyte **controllerIPs, sbyte **modelPaths, ushort *numModelsPerProject, ushort *modelIDs, ushort *modelStates );
public static partial int mi_dupenv_s(sbyte **buf, nuint *size, sbyte *name) { if ((buf == null) || (name == null)) { return(EINVAL); } if (size != null) { *size = 0; } // mscver warning 4996 sbyte *p = getenv(name); if (p == null) { *buf = null; } else { *buf = mi_strdup(p); if (*buf == null) { return(ENOMEM); } if (size != null) { *size = strlen(p); } } return(0); }
public static extern int swr_convert(SwrContext * @s, sbyte ** @out, int @out_count, sbyte ** @in, int @in_count);
public static unsafe int CreateFunction(DataStructure *data) { CreateFunctionInput *inputPtr = (CreateFunctionInput *)data->inputs; Int64 *outputPtr = (Int64 *)data->outputs; string name = BytesToString((sbyte *)inputPtr->namePointer); string code = BytesToString((sbyte *)inputPtr->codePointer); string clrPath = BytesToString((sbyte *)inputPtr->clrPath); sbyte **c_usings = (sbyte **)inputPtr->usingsPointer; var usings = new List <string>(); while (*c_usings != null) { usings.Add(BytesToString(*c_usings)); c_usings++; } sbyte **c_dependencies = (sbyte **)inputPtr->dependenciesPointer; var dependencies = new List <string>(); while (*c_dependencies != null) { dependencies.Add(BytesToString(*c_dependencies)); c_dependencies++; } string text = ""; MethodInfo meth; try { meth = DynamicFunction.CreateFunction(name, code, usings.ToArray(), dependencies.ToArray(), clrPath); } catch (Exception exc) { meth = null; text = exc.ToString(); text = string.Format("Unable to compile function '{0}' due to {1}\n---CODE---\n{2}\n---USINGS---\n{3}\n---DEPENDENCIES---\n{4}\n---", name, exc.ToString(), code, string.Join("\n", usings), string.Join("\n", dependencies)); } if (meth != null) { try { text = DynamicFunction.MethodSignature(meth); } catch (Exception exc) { meth = null; text = string.Format("Unable to get the signature due to: {0}.", exc.ToString()); } } else if (string.IsNullOrEmpty(text)) { text = string.Format("Method '{0}' is null\n---CODE---\n{1}\n---USINGS---\n{2}\n---DEPENDENCIES---\n{3}\n---", name, code, string.Join("\n", usings), string.Join("\n", dependencies)); } *outputPtr = meth == null ? -1 : ObjectStorage.Inst.AddIncref(meth); if (meth == null) { text = text.Replace("\r", "").Replace("\n\n", "\n"); } var raw = StringToNullTerminatedBytesUTF8(text); NativeAllocation allocate = MarshalDelegate <NativeAllocation>(data->allocate_fct); allocate(raw.Length, out data->exc); Marshal.Copy(raw, 0, (IntPtr)data->exc, raw.Length); return(0); }
public static void LibpostalExpansionArrayDestroy(sbyte **expansions, ulong n) { __Internal.LibpostalExpansionArrayDestroy(expansions, n); }
internal static extern void LibpostalExpansionArrayDestroy(sbyte **expansions, ulong n);
/// <summary> /// /// </summary> public void Dispose() { unsafe { if (_attr != null) { for (int i = 0; _attr[i] != null; i++) { Marshal.FreeHGlobal(new IntPtr(_attr[i])); } Marshal.FreeHGlobal(new IntPtr(_attr)); _attr = null; } } }