Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
roomforthetuna
Mar 22, 2005

I don't need to know anything about virii! My CUSTOM PROGRAM keeps me protected! It's not like they'll try to come in through the Internet or something!

Xarn posted:

Orrrr you can use std::lock, which afaik guarantees no deadlocks when acquiring multiple mutexes.
By crashing at runtime. The annotations tell you "stop it, you're doing this wrong" at compile time.

Adbot
ADBOT LOVES YOU

Foxfire_
Nov 8, 2010

No? std::lock() is "repeatedly lock(), unlock(), and try_lock() in some unspecified order until you have all the locks".

Practical implementation is like:

while you don't have all the locks:
- try_lock() them until you either have them all or one fails
- if you have them all, return
- release all the ones you did get
- do a blocking lock() for the one that was unavailable

It fills a different purpose than a naive "Lock #1, do work, lock #2, do more work, unlock #2, unlock #1", but it won't crash or deadlock

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You do have to design around being to use std::lock — it acquires all the locks simultaneously — so it wouldn’t work on the wrapper; you’d need a variadic with function.

baby puzzle
Jun 3, 2011

I'll Sequence your Storm.
Does visual studio have those annotations? I think that would be great for me to learn.

Xerophyte
Mar 17, 2008

This space intentionally left blank

baby puzzle posted:

Does visual studio have those annotations? I think that would be great for me to learn.

MSVC as a compiler does have a concurrency analyzer with a similar (E: but more limited, to be clear) set of annotations to gcc and clang's __attribute__((acquired_before(...))) and co. This blogpost was the best reference for it I could find. Not sure if MS are hiding a better overview somewhere else.

If you just mean Visual Studio as an IDE then their clang support is reportedly OK nowadays. There's a "clang tools for windows" option in the installer, that should get you a sufficiently recent version of clang that the attributes just work. I have no idea how well the debugging and inspection works compared to "native" MSVC, never used it myself. Also I expect that a fair few libraries will check the wrong #define, assume that you're compiling with MSVC anyhow, and explode in fun and interesting ways.

chglcu
May 17, 2007

I'm so bored with the USA.
Apart from a few incorrect analyzer intellisense warnings - a squiggly warning about throwing with exceptions disabled when they’re not being disabled anywhere, for example - the clang toolchain works well in VS in my experience. The debugger works fine and all that.

drilldo squirt
Aug 18, 2006

a beautiful, soft meat sack
Clapping Larry
So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that?

cheetah7071
Oct 20, 2010

honk honk
College Slice

drilldo squirt posted:

So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that?

are they delimited by a character or fixed width? If it's the former, the readline function in the standard library lets you specify a delimiter other than the newline character. If it's the latter, just doing index math is probably the easiest.

Sweeper
Nov 29, 2007
The Joe Buck of Posting
Dinosaur Gum

drilldo squirt posted:

So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that?

C or C++?

C++:
https://en.cppreference.com/w/cpp/string/basic_string/stol and a vector?

C:
strtol and realloc?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Does anybody have a recommendation for a C (not C++) container library that has:

1. Containers for vector (or arraylist depending on back group), a hash table/map, and doubly-linked lists
2. Ability to specify custom allocator/free
3. A permissive license where we don't have to release source code

There's a bunch out there and I was going to just check a few out by default, but I figured I'd ask and see if I can whittle it down.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rocko Bonaparte posted:

Does anybody have a recommendation for a C (not C++) container library that has:

1. Containers for vector (or arraylist depending on back group), a hash table/map, and doubly-linked lists
2. Ability to specify custom allocator/free
3. A permissive license where we don't have to release source code

There's a bunch out there and I was going to just check a few out by default, but I figured I'd ask and see if I can whittle it down.

stb

Nalin
Sep 29, 2007

Hair Elf

drilldo squirt posted:

So I put an entire text file of numbers into a string and want to take those numbers out of the string and put it into an array. Is their an easy way of doing that?

If C++ and space delimited and only includes numbers, you could just use an istream to read stuff in. Should reduce supporting code.

C++ code:
#include <cstdint>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>

int main() {
    std::string my_string{ "123 456 789" };

    std::istringstream stream{ my_string };

    // You can move in C++20 to avoid a copy.
    // std::istringstream stream{ std::move(my_string) };

    // Construct numbers using an istream_iterator.
    // Need an empty one for the end because the constructor can't handle a default_sentinel.
    std::vector<int64_t> numbers{ std::istream_iterator<int64_t>{stream}, std::istream_iterator<int64_t>{} };

    return 0;
}
https://godbolt.org/z/oj5vGWafM

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!

Thanks.

Colostomy Bag
Jan 11, 2016

:lesnick: C-Bangin' it :lesnick:

Any of you fine folks have any recommendations for implementing debug messages such as some lightweight (haha) header library? Something along the lines of "categories" I guess where I want x or y or z type events to output or just x for example. Standard output is fine, I don't need to log this stuff into a DB.

qsvui
Aug 23, 2003
some crazy thing
Maybe spdlog might help?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


log4cxx

Wipfmetz
Oct 12, 2007

Sitzen ein oder mehrere Wipfe in einer Lore, so kann man sie ueber den Rand der Lore hinausschauen sehen.
I'm coding a small game as a hobby project, where buildings produce and distribute goods between eachother.
The player can inspect several reports based on that data.

Those transactions between buildings are stored as structs and gathered in a big bad std::vector. A report then "queries" that data by running a visitor function over that vector.

Whenever I build a new report, I write a new function and often a whole new class and stuff.
I'd just like to throw an SQL-Query at that data instead.
But, as said, it's just a simple vector full of structs.

In C# i'd look into LINQ. Any suggestions for something similar in C++?

I'm not completly sure if this is the right place, just tell me to go away if it isn't.

Wipfmetz fucked around with this message at 13:19 on Jan 31, 2022

csammis
Aug 26, 2003

Mental Institution
It’s been a long time since I used LINQ but if I remember right, at the end of the day LINQ is about creating anonymous functions (lambdas) to do the work and applying them over the collection you give it. Are you looking for nicer syntax than what you’ve got today or better functionality around aggregate functions and grouping?

ynohtna
Feb 16, 2007

backwoods compatible
Illegal Hen
You could just go whole hog and integrate SQLite?

Wipfmetz
Oct 12, 2007

Sitzen ein oder mehrere Wipfe in einer Lore, so kann man sie ueber den Rand der Lore hinausschauen sehen.

csammis posted:

It’s been a long time since I used LINQ but if I remember right, at the end of the day LINQ is about creating anonymous functions (lambdas) to do the work and applying them over the collection you give it. Are you looking for nicer syntax than what you’ve got today or better functionality around aggregate functions and grouping?
Both.

I'd prefer a nicer syntax since to actually convey what I'm doing with the data in a concise matter, and SQL-ey syntax is good at that.
And that would include aggregating and grouping.

ynohtna posted:

You could just go whole hog and integrate SQLite?

"SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.".
Hm, sounds interesting and worth a shot, thank you.
I'd see this as a "go whole hog"-option, which I'll go to if/when I see more things where I'd want to throw SQL at.

Wipfmetz fucked around with this message at 16:17 on Jan 31, 2022

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Wipfmetz posted:

In C# i'd look into LINQ. Any suggestions for something similar in C++?

I'm not completly sure if this is the right place, just tell me to go away if it isn't.

i don't think you're going to find something with the same flexibility as linq to objects in C#. i think the choices are either suck it up and just write the code, or not use c++ for that portion of the game - you could just have the report be a webview (and use something like chrome embedded framework to embed it in your game.)

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
There are almost certainly ways to make writing the functions feel less laborious, though, if that’s the problem. You’re probably duplicating a ton of code instead of extracting out little composable operations that you can re-use for different queries.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
I was trying to use that std_ds.h for dynamic arrays and hashtables for some Linux kernel code. I had to replace the default memory management with my own realloc and free so it would use vmalloc and vfree. That was the easy part. The hard part came in trying to copying the old data into the newer buffer. I just have the pointer to the old buffer without knowing how large it is, so I don't know how much to copy over, and using the new size is going to blow a hole in my foot if it's larger. Since I have multiples of these data structures, I can't just assume any particular size. Is there anything I can use to determine the size of the allocated pointer given the base address?

I see in vmalloc.h find_vm_area, but I don't know if that symbol is actually exported for kernel modules. I couldn't seem to link to it despite starting right at the header my target kernel is using.

The std_ds.h file has some notion of an unused context variable it's passing around to these calls but it's just NULL for now. I could try to do something with it if I had to, but that's going to be some serious surgery and I'd rather avoid it if I could.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
It's a good bet that any system for dynamically-sized arrays will be stashing both the current size and the capacity of the current allocation somewhere, so that it knows when it's going to need to realloc. Why not just use that information instead of trying to track the size of your current memory allocation separately?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
The implementation is not my own and the hook I have is for changing realloc and free. I wanted to try to stay in that lane first before ripping the file apart to try to pass in more info.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If you're using the same stb_ds.h that I found, the pointer it passes to realloc literally points to a header struct containing the existing size and capacity.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Yeah it's that and yes it looks like I have to just play with that header. Having slept on it, I went on a grepping spree in vmalloc and found nothing that I think I could use to get the length. There's some stuff in the vmalloc header but none of it is actually exported outside of the file (no EXPORT_SYMBOL macros for them).

So don't mind me everybody, and apologies in advance if a stray fragment of a concrete block comes flying out of the monitor. That's just me over here with a wrecking ball, messing with that header muahahaha.

pseudorandom name
May 6, 2007

Why aren’t you using the kernel’s existing hash tables and dynamic arrays?

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
It's a fair question. I want alternative versions that also work in userspace so I can run a lot of my testing in normal userspace unit testing frameworks. I originally actually was using the linked list and hash tables that way. However, I had hence modified kernel code and that put me in an LGPL quagmire with my workplace, so I needed to start from a less restrictive license. Also, I hate my life.

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.
Using GNU autotools, what is the best practice for managing config.sub and config.guess? Should they be checked into the repository at all?

I'm updating a project that uses GNU autotools so that it will build and run on the new macs. It has config.guess and config.sub checked into the project, but running autoreconf -fi did not do anything to update them. I'm coming at this with very little existing autotools knowledge, so basically all that I know is that these scripts are used to standardize strings about the specific platform and architecture, and older versions won't have any knowledge of aarch64 Macs.

I hacked through this by copying in the copies of config.guess and config.sub that were installed with my system automake, at /opt/homebrew/Cellar/automake/1.16.5/share/automake-1.16/ because I installed autotools with homebrew.

Is there some way to set up autotools to use the system config.sub and config.guess instead of checking it into the project?

This is basically all that I can find as far as official documentation: https://www.gnu.org/software/gettext/manual/html_node/config_002eguess.html

Twerk from Home fucked around with this message at 17:32 on Feb 11, 2022

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
There don't appear to have been any apple silicon-related changes to config.sub or config.guess.

The intended use of autotools is that building the project doesn't require having autotools installed, and the project should include all of the generated files in its distribution package. If the git repository is the primary way for users to get the project, that implies they should be committed to the repository.

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.

Plorkyeran posted:

There don't appear to have been any apple silicon-related changes to config.sub or config.guess.

The intended use of autotools is that building the project doesn't require having autotools installed, and the project should include all of the generated files in its distribution package. If the git repository is the primary way for users to get the project, that implies they should be committed to the repository.

Interesting that it's not Apple silicon related, when I ran ./configure without replacing the config.sub and config.guess, I saw this:

pre:
checking build system type... configure: error: /bin/sh ./config.sub -apple-darwin21.3.0 failed
and when I ran config.sub directly to see why this was failing, I see:

pre:
$ src/config.sub -apple-darwin21.3.0 
config.sub: invalid option -apple-darwin21.3.0
Try `config.sub --help' for more information.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
That was incidentally fixed by a change in 2004 which made it no longer have a hardcoded list of possible processors.

autoreconf -ivf should be overwriting the existing config.guess and config.sub files with the up-to-date ones. If it's not, you can also try running automake --add-missing --copy --force-missing directly. Copying them over manually is fine too if you don't feel like trying to debug why autotools isn't doing the right thing (but you probably will need to regenerate the configure script with a modern version of autoconf and if automake isn't working that might not be either).

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.

Plorkyeran posted:

That was incidentally fixed by a change in 2004 which made it no longer have a hardcoded list of possible processors.

autoreconf -ivf should be overwriting the existing config.guess and config.sub files with the up-to-date ones. If it's not, you can also try running automake --add-missing --copy --force-missing directly. Copying them over manually is fine too if you don't feel like trying to debug why autotools isn't doing the right thing (but you probably will need to regenerate the configure script with a modern version of autoconf and if automake isn't working that might not be either).

Sweet! I had run autoreconf -ivf and it did not replace them. It did update the configure script, and put me into a state where I had a new configure script and old, broken config.sub and .guess.

Thanks!

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
It looks like I'll be trying to retrofit a cmake project to work with an older version and I'm pretty new to the tool. I already see some stuff that came up running against an older version of the tool that is pretty inside-baseball to me. Is there a good resource for doing the basics while not necessarily hiding the whats and where of certain details? I was going to default to the online Mastering CMake c/o https://cmake.org/cmake/help/book/mastering-cmake/, but I can also hit O'Reilly stuff through work for free.

qsvui
Aug 23, 2003
some crazy thing
There are several guides listed in the docs and Professional CMake is pretty much the CMake bible imo

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Trying to port a nontrivial cmake project to an older version of cmake sounds like a very horrifying project and I would try very hard to find any other possible solution.

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Plorkyeran posted:

Trying to port a nontrivial cmake project to an older version of cmake sounds like a very horrifying project and I would try very hard to find any other possible solution.

:same:

Xarn
Jun 26, 2015

Plorkyeran posted:

Trying to port a nontrivial cmake project to an older version of cmake sounds like a very horrifying project and I would try very hard to find any other possible solution.

This is 99% correct, the remaining 1% is if it is one of those cases where the cmake_minimum_required or w/e was just set to latest and doesn't actually need it.

Adbot
ADBOT LOVES YOU

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
Point taken. I may be able to get around it but at this point I'm dumber than a brick with CMake. I think either way that I'd have to modify this build environment no matter what I do and I can't even add a library dependency yet out of just ignorance. If trying to backport to an old version ends up like this after the first pass then I need to step back and consider some other method.


qsvui posted:

There are several guides listed in the docs and Professional CMake is pretty much the CMake bible imo

I'll see about getting Profession CMake. The tutorial was doing a decent job of the basic syntax but wasn't getting my into the grit with some of the magic stuff they were setting and what it meant. Like, I was able to Google what they were but couldn't understand what they meant from that, so I needed to back up a bit.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply